diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3ab87d5..b08c6b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,11 +1,12 @@ name: build-cpp on: - push: - pull_request: - + push: + branches: [compile] + pull_request: + branches: [compile] jobs: - build: + compile: strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -15,20 +16,21 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install compiler (Linux) - if: matrix.os == 'ubuntu-latest' - run: sudo apt-get update && sudo apt-get install -y g++ + # - name: Install compiler (Linux) + # if: matrix.os == 'ubuntu-latest' + #run: sudo apt-get update && sudo apt-get install -y g++ - name: Compile run: | - if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - g++ cppsp_compiler.cpp -Os -s -std=c++17 -o cppsp_compiler_linux + if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + g++ cppsp_compiler.cpp -Os -s -std=c++17 -o cppsp_compiler_linux -static else - clang++ cppsp_compiler.cpp -Os -s -std=c++17 -o cppsp_compiler_mac - fi + clang++ cppsp_compiler.cpp -Os -std=c++17 -o cppsp_compiler_mac + fi + - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: ${{ matrix.os }}-binary + name: ${{ matrix.os }}-binary path: cppsp_compiler_* diff --git a/cppsp_compiler.cpp b/cppsp_compiler.cpp index 8ee2c99..4f427f8 100644 --- a/cppsp_compiler.cpp +++ b/cppsp_compiler.cpp @@ -8,7 +8,14 @@ #include #include #include - +bool isWindows=false;bool isMac=false;bool isLinux =false; + #if defined(_WIN32) || defined(_WIN64) + #define isWindows 1 + #elif defined(__APPLE__) && defined(__MACH__) + #define isMac 1 + #elif defined(__linux__) + #define isLinux 1 + #endif //檢查dll依賴:objdump -p cppsp_compiler.exe | findstr ".dll" namespace fs = std::filesystem; @@ -200,16 +207,18 @@ std::string parseIni(const std::string& path, const std::string& flag) { std::ifstream infile(path); if (!infile) return ""; - std::string line; - std::getline(infile, line); + std::string line; + std::string result; + while(std::getline(infile, line)){ std::stringstream ss(line); std::string token; - std::string result; while (std::getline(ss, token, ',')) { if (!token.empty()) { - result += flag + "\"" + token + "\" "; + result += flag+ "\"" + token + "\" "; } } + + } return result; } // 判斷字串是否為布林值 @@ -248,6 +257,7 @@ int main(int argc, char* argv[]) { double iorf = std::stod(cur); if (iorf == (int)iorf) out += "{ int _t = " + cur + "; printf(\"%d\", _t); }\n"; else out += "{ double _t = " + cur + "; printf(\"%g\", _t); }\n"; } + else if(cur[0]== 'L') out +=(Ifiostream)? "std::wcout<<"+cur+";\n" :"wprintf("+cur+");\n"; else if(Ifiostream==true) out +="std::cout<<"+cur+";\n"; else { out += "printf(" + cur + ");\n";} } @@ -367,8 +377,8 @@ if (!comment && importline.find("import ") != std::string::npos) { outfile << "\nreturn 0;\n}\n"; if(enableoverwrite) outfile << "*/"; outfile.close(); - - fs::path exePath = cpsPath.parent_path() / (cpsPath.stem().string() );// .exe後綴 : + ".exe"); +std::string local=(isMac || isLinux)? "./":""; + fs::path exePath = cpsPath.parent_path() / (local+cpsPath.stem().string() );// .exe後綴 : + ".exe"); // 讀 include.ini 和 lib.ini std::string includeFlags = parseIni("include.ini", "-I"); diff --git a/cppsp_compiler.exe b/cppsp_compiler.exe index ea337c3..7a93667 100644 Binary files a/cppsp_compiler.exe and b/cppsp_compiler.exe differ