diff --git a/CMakeLists.txt b/CMakeLists.txt index 732319580..e8b5dd2ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ if(UNIX) ) message(STATUS "linking to llvm libs ${llvm_libs} ${lld_libs}") endif() + add_library(c3c_wrappers STATIC wrapper/src/wrapper.cpp) add_executable(c3c diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index 556fcdfb1..69c1f98e6 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -14,10 +14,12 @@ #endif #ifndef _MSC_VER + #include #include #include #include + #else #include "utils/dirent.h" #define PATH_MAX 260 @@ -47,25 +49,28 @@ * If that is an issue, I think dirent will have to be replaced or the dirent * port in use will have to be replaced. */ -char* strip_drive_prefix(char* path) { - if ((*path == 'c' || *path == 'C') && path[1] == ':') { +char *strip_drive_prefix(char *path) +{ + if ((*path == 'c' || *path == 'C') && path[1] == ':') + { return path + 2; // remove first two characters } - else if (path[1] == ':' && (path[2] == '/' || path[2] == '\\')) { // I don't *think* a relative path can start with '[char]:/' ? right? + + if (path[1] == ':' && (path[2] == '/' || path[2] == '\\')) + { // I don't *think* a relative path can start with '[char]:/' ? right? // nothing can be done about this currently - error_exit("Illegal path %s - absolute path must start with /, \\, c:, or C: (file a github issue if this is a problem)"); - } - else { - // path is ok - return path; + error_exit("Illegal path %s - absolute path must start with /, \\, " + "c:, or C: (file a github issue if this is a problem)"); } + + // path is ok + return path; } #endif - -const char* expand_path(const char* path) +const char *expand_path(const char *path) { if (path[0] == '~' && path[1] == '/') { @@ -79,7 +84,6 @@ const char* expand_path(const char* path) } - char *read_file(const char *path, size_t *return_size) { FILE *file = fopen(path, "rb"); @@ -112,7 +116,7 @@ char *read_file(const char *path, size_t *return_size) return buffer; } -const char* find_lib_dir(void) +const char *find_lib_dir(void) { const char *path = find_executable_path(); @@ -188,7 +192,8 @@ void file_find_top_dir() char new_path[PATH_MAX + 1]; getcwd(new_path, PATH_MAX); if (strcmp(new_path, start_path) != 0) continue; - error_exit("The root build directory containing %s could not be found. Did you use the correct directory?", PROJECT_TOML); + error_exit("The root build directory containing %s could not be found. Did you use the correct directory?", + PROJECT_TOML); } } @@ -197,7 +202,7 @@ void file_add_wildcard_files(const char ***files, const char *path, bool recursi #ifdef _MSC_VER DIR *dir = opendir(strip_drive_prefix(path)); #else - DIR* dir = opendir(path); + DIR *dir = opendir(path); #endif bool path_ends_with_slash = path[strlen(path) - 1] == '/'; if (!dir) diff --git a/src/utils/find_msvc.c b/src/utils/find_msvc.c index b0fa1d9de..178adef75 100644 --- a/src/utils/find_msvc.c +++ b/src/utils/find_msvc.c @@ -1,4 +1,5 @@ #include "utils/common.h" + #ifdef _MSC_VER #include "utils/find_msvc.h" @@ -11,69 +12,74 @@ #define WINKIT_BASE_PATH "/Program Files (x86)/Windows Kits/" -int is_numeric(const struct dirent* ent) { - return atoi(ent->d_name); // don't use this function if you expect a file named "0" ? +int is_numeric(const struct dirent *ent) +{ + return atoi(ent->d_name); // don't use this function if you expect a file named "0" ? } -char* get_highest_ver(char* directory, int (*filter)(const struct dirent*)) { - struct dirent** files; - int num_files = scandir(directory, &files, filter, versionsort); - if (num_files < 0) { - error_exit("ERROR - Failed to autodetect MSVC libpaths\n"); - } - char* path_ret = (char*)malloc(260); - strcpy_s(path_ret, 260, files[num_files - 1]->d_name); - for (int i = 0; i < num_files; i++) free(files[i]); - free(files); - return path_ret; +char *get_highest_ver(char *directory, int (*filter)(const struct dirent *)) +{ + struct dirent **files; + int num_files = scandir(directory, &files, filter, versionsort); + if (num_files < 0) + { + error_exit("ERROR - Failed to autodetect MSVC libpaths\n"); + } + char *path_ret = (char *)malloc(260); + strcpy_s(path_ret, 260, files[num_files - 1]->d_name); + for (int i = 0; i < num_files; i++) free(files[i]); + free(files); + return path_ret; } /** * @returns PathPair containing paths to .../MSVC/[version]/lib/x64 and .../MSVC/[v]/atlmfc/lib/x64 */ -PathPair get_latest_available_vs_path() { - char ver_name[16] = ""; +PathPair get_latest_available_vs_path() +{ + char ver_name[16] = ""; - char* highest_ver = get_highest_ver(MSVC_BASE_PATH, is_numeric); - strncpy_s(ver_name, 16, highest_ver, 4); - free(highest_ver); + char *highest_ver = get_highest_ver(MSVC_BASE_PATH, is_numeric); + strncpy_s(ver_name, 16, highest_ver, 4); + free(highest_ver); - char newpath[260]; - snprintf(newpath, 260, "%s%s/BuildTools/VC/Tools/MSVC/", MSVC_BASE_PATH, ver_name); + char newpath[260]; + snprintf(newpath, 260, "%s%s/BuildTools/VC/Tools/MSVC/", MSVC_BASE_PATH, ver_name); - highest_ver = get_highest_ver(newpath, NULL); - strcat_s(newpath, 260, highest_ver); - free(highest_ver); + highest_ver = get_highest_ver(newpath, NULL); + strcat_s(newpath, 260, highest_ver); + free(highest_ver); - PathPair ret = { 0 }; - snprintf(ret.first, 260, "%s/lib/x64", newpath); - snprintf(ret.second, 260, "%s/atlmfc/lib/x64", newpath); + PathPair ret = { 0 }; + snprintf(ret.first, 260, "%s/lib/x64", newpath); + snprintf(ret.second, 260, "%s/atlmfc/lib/x64", newpath); - return ret; + return ret; } /** * @returns PathPair containing paths to /Program Files (x86)/Windows Kits/[version]/Lib/[version]/ucrt/x64 and .../[version]/um/x64 */ -PathPair find_winkit_path() { - // windows version - char win_ver_major[16] = ""; - char* highest_ver = get_highest_ver(WINKIT_BASE_PATH, is_numeric); - strcpy_s(win_ver_major, 16, highest_ver); - free(highest_ver); +PathPair find_winkit_path() +{ + // windows version + char win_ver_major[16] = ""; + char *highest_ver = get_highest_ver(WINKIT_BASE_PATH, is_numeric); + strcpy_s(win_ver_major, 16, highest_ver); + free(highest_ver); - // windows kit version? or something - char newpath[260] = ""; - sprintf_s(newpath, 260, "%s%s/Lib/", WINKIT_BASE_PATH, win_ver_major); - highest_ver = get_highest_ver(newpath, NULL); - strcat_s(newpath, 260, highest_ver); - free(highest_ver); + // windows kit version? or something + char newpath[260] = ""; + sprintf_s(newpath, 260, "%s%s/Lib/", WINKIT_BASE_PATH, win_ver_major); + highest_ver = get_highest_ver(newpath, NULL); + strcat_s(newpath, 260, highest_ver); + free(highest_ver); - PathPair ret = { 0 }; - snprintf(ret.first, 260, "%s/ucrt/x64", newpath); - snprintf(ret.second, 260, "%s/um/x64", newpath); + PathPair ret = { 0 }; + snprintf(ret.first, 260, "%s/ucrt/x64", newpath); + snprintf(ret.second, 260, "%s/um/x64", newpath); - return ret; + return ret; } #endif //defined(_MSC_VER) \ No newline at end of file diff --git a/test/test_suite/strings/multiline_strings.c3t b/test/test_suite/strings/multiline_strings.c3t index 525224853..c8e16e144 100644 --- a/test/test_suite/strings/multiline_strings.c3t +++ b/test/test_suite/strings/multiline_strings.c3t @@ -21,6 +21,7 @@ char *messages = """ \s total """; +// This will depend on platform source file line endings char *message2 = ` ``oh`` superman where are you now?