From dd0d188657ff0df28ab5ea46d22d0910a73528a3 Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 8 May 2024 02:19:56 +0000 Subject: [PATCH] format git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@128 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- Tool/config.c | 2 +- WinBuild/dirent.h | 305 ++++++++++++++++---------------------------- WinBuild/winbuild.c | 146 ++++++++++----------- 3 files changed, 184 insertions(+), 269 deletions(-) diff --git a/Tool/config.c b/Tool/config.c index 7070f60..74f4665 100644 --- a/Tool/config.c +++ b/Tool/config.c @@ -41,7 +41,7 @@ int main(int argc, char** argv) { #endif #endif printf("\n"); - } else if(strcmp(argv[1], "reqobjs") == 0){ + } else if(strcmp(argv[1], "reqobjs") == 0) { printf("interpreter.o parser.o run.o util.o\n"); } else if(strcmp(argv[1], "objs") == 0) { #ifdef HAS_FFI_SUPPORT diff --git a/WinBuild/dirent.h b/WinBuild/dirent.h index de75def..0b76e29 100644 --- a/WinBuild/dirent.h +++ b/WinBuild/dirent.h @@ -33,9 +33,9 @@ SOFTWARE. extern "C" { #endif /* __cplusplus */ -#include -#include #include +#include +#include #include @@ -97,7 +97,7 @@ extern "C" { #define _DIRENT_HAVE_D_OFF 1 #endif /* _DIRENT_HAVE_D_OFF */ -#ifndef _DIRENT_HAVE_D_TYPE +#ifndef _DIRENT_HAVE_D_TYPE #define _DIRENT_HAVE_D_TYPE 1 #endif /* _DIRENT_HAVE_D_TYPE */ @@ -115,14 +115,12 @@ extern "C" { typedef void* DIR; -typedef struct ino_t -{ +typedef struct ino_t { unsigned long long serial; unsigned char fileid[16]; } __ino_t; -struct dirent -{ +struct dirent { __ino_t d_ino; off_t d_off; unsigned short d_reclen; @@ -131,111 +129,87 @@ struct dirent char d_name[NAME_MAX]; }; -struct __dir -{ +struct __dir { struct dirent* entries; intptr_t fd; long int count; long int index; }; -static int closedir(DIR* dirp) -{ +static int closedir(DIR* dirp) { struct __dir* data = NULL; - if (!dirp) { + if(!dirp) { errno = EBADF; return -1; } - data = (struct __dir*) dirp; + data = (struct __dir*)dirp; CloseHandle((HANDLE)data->fd); free(data->entries); free(data); return 0; } -static void __seterrno(int value) -{ +static void __seterrno(int value) { #ifdef _MSC_VER _set_errno(value); -#else /* _MSC_VER */ +#else /* _MSC_VER */ errno = value; #endif /* _MSC_VER */ } -static int __islink(const wchar_t * name, char * buffer) -{ +static int __islink(const wchar_t* name, char* buffer) { DWORD io_result = 0; DWORD bytes_returned = 0; - HANDLE hFile = CreateFileW(name, 0, 0, NULL, OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0); - if (hFile == INVALID_HANDLE_VALUE) - return 0; + HANDLE hFile = CreateFileW(name, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0); + if(hFile == INVALID_HANDLE_VALUE) return 0; - io_result = DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, NULL, 0, - buffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &bytes_returned, NULL); + io_result = DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &bytes_returned, NULL); CloseHandle(hFile); - if (io_result == 0) - return 0; + if(io_result == 0) return 0; return ((REPARSE_GUID_DATA_BUFFER*)buffer)->ReparseTag == IO_REPARSE_TAG_SYMLINK; } #pragma pack(push, 1) -typedef struct dirent_FILE_ID_128 -{ +typedef struct dirent_FILE_ID_128 { BYTE Identifier[16]; -} -dirent_FILE_ID_128; +} dirent_FILE_ID_128; -typedef struct _dirent_FILE_ID_INFO -{ +typedef struct _dirent_FILE_ID_INFO { ULONGLONG VolumeSerialNumber; dirent_FILE_ID_128 FileId; -} -dirent_FILE_ID_INFO; +} dirent_FILE_ID_INFO; #pragma pack(pop) -typedef enum dirent_FILE_INFO_BY_HANDLE_CLASS -{ dirent_FileIdInfo = 18 } -dirent_FILE_INFO_BY_HANDLE_CLASS; +typedef enum dirent_FILE_INFO_BY_HANDLE_CLASS { dirent_FileIdInfo = 18 } dirent_FILE_INFO_BY_HANDLE_CLASS; -static __ino_t __inode(const wchar_t* name) -{ - __ino_t value = { 0 }; +static __ino_t __inode(const wchar_t* name) { + __ino_t value = {0}; BOOL result; dirent_FILE_ID_INFO fileid; BY_HANDLE_FILE_INFORMATION info; - typedef BOOL (__stdcall* pfnGetFileInformationByHandleEx)(HANDLE hFile, - dirent_FILE_INFO_BY_HANDLE_CLASS FileInformationClass, - LPVOID lpFileInformation, DWORD dwBufferSize); + typedef BOOL(__stdcall * pfnGetFileInformationByHandleEx)(HANDLE hFile, dirent_FILE_INFO_BY_HANDLE_CLASS FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize); HANDLE hKernel32 = GetModuleHandleW(L"kernel32.dll"); - if (!hKernel32) - return value; + if(!hKernel32) return value; - pfnGetFileInformationByHandleEx fnGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx) GetProcAddress(hKernel32, "GetFileInformationByHandleEx"); - if (!fnGetFileInformationByHandleEx) - return value; + pfnGetFileInformationByHandleEx fnGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx)GetProcAddress(hKernel32, "GetFileInformationByHandleEx"); + if(!fnGetFileInformationByHandleEx) return value; HANDLE hFile = CreateFileW(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); - if (hFile == INVALID_HANDLE_VALUE) - return value; + if(hFile == INVALID_HANDLE_VALUE) return value; result = fnGetFileInformationByHandleEx(hFile, dirent_FileIdInfo, &fileid, sizeof(fileid)); - if (result) - { + if(result) { value.serial = fileid.VolumeSerialNumber; memcpy(value.fileid, fileid.FileId.Identifier, 16); - } - else - { + } else { result = GetFileInformationByHandle(hFile, &info); - if(result) - { + if(result) { value.serial = info.dwVolumeSerialNumber; memcpy(value.fileid + 8, &info.nFileIndexHigh, 4); memcpy(value.fileid + 12, &info.nFileIndexLow, 4); @@ -245,16 +219,15 @@ static __ino_t __inode(const wchar_t* name) return value; } -static DIR* __internal_opendir(wchar_t* wname, int size) -{ +static DIR* __internal_opendir(wchar_t* wname, int size) { struct __dir* data = NULL; - struct dirent *tmp_entries = NULL; + struct dirent* tmp_entries = NULL; static char default_char = '?'; static wchar_t* prefix = L"\\\\?\\"; static wchar_t* suffix = L"\\*.*"; static int extra_prefix = 4; /* use prefix "\\?\" to handle long file names */ static int extra_suffix = 4; /* use suffix "\*.*" to find everything */ - WIN32_FIND_DATAW w32fd = { 0 }; + WIN32_FIND_DATAW w32fd = {0}; HANDLE hFindFile = INVALID_HANDLE_VALUE; static int grow_factor = 2; char* buffer = NULL; @@ -264,42 +237,36 @@ static DIR* __internal_opendir(wchar_t* wname, int size) memcpy(wname + size - 1, suffix, sizeof(wchar_t) * extra_suffix); wname[size + extra_suffix - 1] = 0; - if (relative) { + if(relative) { wname += extra_prefix; size -= extra_prefix; } hFindFile = FindFirstFileW(wname, &w32fd); - if (INVALID_HANDLE_VALUE == hFindFile) - { + if(INVALID_HANDLE_VALUE == hFindFile) { __seterrno(ENOENT); return NULL; } - data = (struct __dir*) malloc(sizeof(struct __dir)); - if (!data) - goto out_of_memory; + data = (struct __dir*)malloc(sizeof(struct __dir)); + if(!data) goto out_of_memory; wname[size - 1] = 0; data->fd = (intptr_t)CreateFileW(wname, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); wname[size - 1] = L'\\'; data->count = 16; data->index = 0; - data->entries = (struct dirent*) malloc(sizeof(struct dirent) * data->count); - if (!data->entries) - goto out_of_memory; + data->entries = (struct dirent*)malloc(sizeof(struct dirent) * data->count); + if(!data->entries) goto out_of_memory; buffer = malloc(MAXIMUM_REPARSE_DATA_BUFFER_SIZE); - if (!buffer) - goto out_of_memory; - do - { + if(!buffer) goto out_of_memory; + do { WideCharToMultiByte(CP_UTF8, 0, w32fd.cFileName, -1, data->entries[data->index].d_name, NAME_MAX, &default_char, NULL); memcpy(wname + size, w32fd.cFileName, sizeof(wchar_t) * NAME_MAX); - if (((w32fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == FILE_ATTRIBUTE_REPARSE_POINT) && __islink(wname, buffer)) - data->entries[data->index].d_type = DT_LNK; - else if ((w32fd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) == FILE_ATTRIBUTE_DEVICE) + if(((w32fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == FILE_ATTRIBUTE_REPARSE_POINT) && __islink(wname, buffer)) data->entries[data->index].d_type = DT_LNK; + else if((w32fd.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) == FILE_ATTRIBUTE_DEVICE) data->entries[data->index].d_type = DT_CHR; - else if ((w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) + else if((w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) data->entries[data->index].d_type = DT_DIR; else data->entries[data->index].d_type = DT_REG; @@ -309,15 +276,13 @@ static DIR* __internal_opendir(wchar_t* wname, int size) data->entries[data->index].d_namelen = (unsigned char)wcslen(w32fd.cFileName); data->entries[data->index].d_off = 0; - if (++data->index == data->count) { - tmp_entries = (struct dirent*) realloc(data->entries, sizeof(struct dirent) * data->count * grow_factor); - if (!tmp_entries) - goto out_of_memory; + if(++data->index == data->count) { + tmp_entries = (struct dirent*)realloc(data->entries, sizeof(struct dirent) * data->count * grow_factor); + if(!tmp_entries) goto out_of_memory; data->entries = tmp_entries; data->count *= grow_factor; } - } - while (FindNextFileW(hFindFile, &w32fd) != 0); + } while(FindNextFileW(hFindFile, &w32fd) != 0); free(buffer); FindClose(hFindFile); @@ -326,41 +291,33 @@ static DIR* __internal_opendir(wchar_t* wname, int size) data->index = 0; return (DIR*)data; out_of_memory: - if (data) - { - if (INVALID_HANDLE_VALUE != (HANDLE)data->fd) - CloseHandle((HANDLE)data->fd); + if(data) { + if(INVALID_HANDLE_VALUE != (HANDLE)data->fd) CloseHandle((HANDLE)data->fd); free(data->entries); } free(buffer); free(data); - if (INVALID_HANDLE_VALUE != hFindFile) - FindClose(hFindFile); + if(INVALID_HANDLE_VALUE != hFindFile) FindClose(hFindFile); __seterrno(ENOMEM); return NULL; } -static wchar_t* __get_buffer() -{ +static wchar_t* __get_buffer() { wchar_t* name = malloc(sizeof(wchar_t) * (NTFS_MAX_PATH + NAME_MAX + 8)); - if (name) - memcpy(name, L"\\\\?\\", sizeof(wchar_t) * 4); + if(name) memcpy(name, L"\\\\?\\", sizeof(wchar_t) * 4); return name; } -static DIR* opendir(const char* name) -{ +static DIR* opendir(const char* name) { DIR* dirp = NULL; wchar_t* wname = __get_buffer(); int size = 0; - if (!wname) - { + if(!wname) { errno = ENOMEM; return NULL; } size = MultiByteToWideChar(CP_UTF8, 0, name, -1, wname + 4, NTFS_MAX_PATH); - if (0 == size) - { + if(0 == size) { free(wname); return NULL; } @@ -369,19 +326,16 @@ static DIR* opendir(const char* name) return dirp; } -static DIR* _wopendir(const wchar_t* name) -{ +static DIR* _wopendir(const wchar_t* name) { DIR* dirp = NULL; wchar_t* wname = __get_buffer(); int size = 0; - if (!wname) - { + if(!wname) { errno = ENOMEM; return NULL; } size = (int)wcslen(name); - if (size > NTFS_MAX_PATH) - { + if(size > NTFS_MAX_PATH) { free(wname); return NULL; } @@ -391,36 +345,30 @@ static DIR* _wopendir(const wchar_t* name) return dirp; } -static DIR* fdopendir(intptr_t fd) -{ +static DIR* fdopendir(intptr_t fd) { DIR* dirp = NULL; wchar_t* wname = __get_buffer(); - typedef DWORD (__stdcall * pfnGetFinalPathNameByHandleW)( - HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); + typedef DWORD(__stdcall * pfnGetFinalPathNameByHandleW)(HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); HANDLE hKernel32 = GetModuleHandleW(L"kernel32.dll"); - if (!hKernel32) - { + if(!hKernel32) { errno = EINVAL; return NULL; } - pfnGetFinalPathNameByHandleW fnGetFinalPathNameByHandleW = (pfnGetFinalPathNameByHandleW) GetProcAddress(hKernel32, "GetFinalPathNameByHandleW"); - if (!fnGetFinalPathNameByHandleW) - { + pfnGetFinalPathNameByHandleW fnGetFinalPathNameByHandleW = (pfnGetFinalPathNameByHandleW)GetProcAddress(hKernel32, "GetFinalPathNameByHandleW"); + if(!fnGetFinalPathNameByHandleW) { errno = EINVAL; return NULL; } int size = 0; - if (!wname) - { + if(!wname) { errno = ENOMEM; return NULL; } - size = fnGetFinalPathNameByHandleW((HANDLE) fd, wname + 4, NTFS_MAX_PATH, FILE_NAME_NORMALIZED); - if (0 == size) - { + size = fnGetFinalPathNameByHandleW((HANDLE)fd, wname + 4, NTFS_MAX_PATH, FILE_NAME_NORMALIZED); + if(0 == size) { free(wname); errno = ENOTDIR; return NULL; @@ -430,113 +378,88 @@ static DIR* fdopendir(intptr_t fd) return dirp; } -static struct dirent* readdir(DIR* dirp) -{ - struct __dir* data = (struct __dir*) dirp; - if (!data) { +static struct dirent* readdir(DIR* dirp) { + struct __dir* data = (struct __dir*)dirp; + if(!data) { errno = EBADF; return NULL; } - if (data->index < data->count) - { + if(data->index < data->count) { return &data->entries[data->index++]; } return NULL; } -static int readdir_r(DIR* dirp, struct dirent* entry, struct dirent**result) -{ - struct __dir* data = (struct __dir*) dirp; - if (!data) { +static int readdir_r(DIR* dirp, struct dirent* entry, struct dirent** result) { + struct __dir* data = (struct __dir*)dirp; + if(!data) { return EBADF; } - if (data->index < data->count) - { - if (entry) - memcpy(entry, &data->entries[data->index++], sizeof(struct dirent)); - if (result) - *result = entry; - } - else if (result) + if(data->index < data->count) { + if(entry) memcpy(entry, &data->entries[data->index++], sizeof(struct dirent)); + if(result) *result = entry; + } else if(result) *result = NULL; return 0; } -static void seekdir(DIR* dirp, long int offset) -{ - if (dirp) - { - struct __dir* data = (struct __dir*) dirp; +static void seekdir(DIR* dirp, long int offset) { + if(dirp) { + struct __dir* data = (struct __dir*)dirp; data->index = (offset < data->count) ? offset : data->index; } } -static void rewinddir(DIR* dirp) -{ - seekdir(dirp, 0); -} +static void rewinddir(DIR* dirp) { seekdir(dirp, 0); } -static long int telldir(DIR* dirp) -{ - if (!dirp) { +static long int telldir(DIR* dirp) { + if(!dirp) { errno = EBADF; return -1; } return ((struct __dir*)dirp)->count; } -static intptr_t dirfd(DIR * dirp) -{ - if (!dirp) { +static intptr_t dirfd(DIR* dirp) { + if(!dirp) { errno = EINVAL; return -1; } return ((struct __dir*)dirp)->fd; } -static int scandir(const char* dirp, struct dirent*** namelist, - int (*filter)(const struct dirent*), - int (*compar)(const struct dirent**, const struct dirent**)) -{ - struct dirent ** entries = NULL, ** tmp_entries = NULL; +static int scandir(const char* dirp, struct dirent*** namelist, int (*filter)(const struct dirent*), int (*compar)(const struct dirent**, const struct dirent**)) { + struct dirent **entries = NULL, **tmp_entries = NULL; long int i = 0, index = 0, count = 16; - DIR * d = opendir(dirp); - struct __dir* data = (struct __dir*) d; - if (!data) { + DIR* d = opendir(dirp); + struct __dir* data = (struct __dir*)d; + if(!data) { closedir(d); __seterrno(ENOENT); return -1; } - entries = (struct dirent**) malloc(sizeof(struct dirent*) * count); - if (!entries) - { + entries = (struct dirent**)malloc(sizeof(struct dirent*) * count); + if(!entries) { closedir(d); __seterrno(ENOMEM); return -1; } - for (i = 0; i < data->count; ++i) - { - if (!filter || filter(&data->entries[i])) - { - entries[index] = (struct dirent*) malloc(sizeof(struct dirent)); - if (!entries[index]) - { + for(i = 0; i < data->count; ++i) { + if(!filter || filter(&data->entries[i])) { + entries[index] = (struct dirent*)malloc(sizeof(struct dirent)); + if(!entries[index]) { closedir(d); - for (i = 0; i < index; ++i) - free(entries[index]); + for(i = 0; i < index; ++i) free(entries[index]); free(entries); __seterrno(ENOMEM); return -1; } memcpy(entries[index], &data->entries[i], sizeof(struct dirent)); - if (++index == count) - { + if(++index == count) { tmp_entries = (struct dirent**)realloc(entries, sizeof(struct dirent*) * count * 2); - if (!tmp_entries) - { + if(!tmp_entries) { closedir(d); - for (i = 0; i < index; ++i) - free(entries[index - 1]); + for(i = 0; i < index; ++i) free(entries[index - 1]); free(entries); __seterrno(ENOMEM); return -1; @@ -548,30 +471,22 @@ static int scandir(const char* dirp, struct dirent*** namelist, } qsort(entries, index, sizeof(struct dirent*), compar); entries[index] = NULL; - if (namelist) - *namelist = entries; + if(namelist) *namelist = entries; closedir(d); return 0; } -int alphasort(const void* a, const void* b) -{ - struct dirent** dira = (struct dirent**)a, **dirb = (struct dirent**)b; - if (!dira || !dirb) - return 0; +int alphasort(const void* a, const void* b) { + struct dirent **dira = (struct dirent**)a, **dirb = (struct dirent**)b; + if(!dira || !dirb) return 0; return strcoll((*dira)->d_name, (*dirb)->d_name); } -static int __strverscmp(const char* s1, const char* s2) -{ - return alphasort(s1, s2); -} +static int __strverscmp(const char* s1, const char* s2) { return alphasort(s1, s2); } -int versionsort(const void* a, const void* b) -{ - struct dirent** dira = (struct dirent**)a, ** dirb = (struct dirent**)b; - if (!dira || !dirb) - return 0; +int versionsort(const void* a, const void* b) { + struct dirent **dira = (struct dirent**)a, **dirb = (struct dirent**)b; + if(!dira || !dirb) return 0; return __strverscmp((*dira)->d_name, (*dirb)->d_name); } diff --git a/WinBuild/winbuild.c b/WinBuild/winbuild.c index e950d56..2adc5c2 100644 --- a/WinBuild/winbuild.c +++ b/WinBuild/winbuild.c @@ -1,8 +1,8 @@ /* $Id$ */ +#include "dirent.h" #include #include #include -#include "dirent.h" #ifdef _MSC_VER #include @@ -26,87 +26,87 @@ char* dynstrcat(const char* str1, const char* str2) { return str; } -char* dynstrcat3(const char* str1, const char* str2, const char* str3){ - char* tmp = dynstrcat(str1, str2); - char* str = dynstrcat(tmp, str3); - free(tmp); - return str; +char* dynstrcat3(const char* str1, const char* str2, const char* str3) { + char* tmp = dynstrcat(str1, str2); + char* str = dynstrcat(tmp, str3); + free(tmp); + return str; } -int main(){ +int main() { #ifdef _MSC_VER - if(access("..\\Tool", 0) != 0){ + if(access("..\\Tool", 0) != 0) { #else - if(access("..\\Tool", F_OK) != 0){ + if(access("..\\Tool", F_OK) != 0) { #endif - fprintf(stderr, "Run me from the WinBuild directory\n"); - return 1; - } + fprintf(stderr, "Run me from the WinBuild directory\n"); + return 1; + } #ifdef _MSC_VER - if(access("..\\Serenade", 0) != 0){ + if(access("..\\Serenade", 0) != 0) { #else - if(access("..\\Serenade", F_OK) != 0){ + if(access("..\\Serenade", F_OK) != 0) { #endif - fprintf(stderr, "Run me from the WinBuild directory\n"); - return 1; - } - printf("WinBuild - Serenade build script for MSVC %d\n", _MSC_FULL_VER); - system("cl /nologo /Fe:..\\Tool\\configgen.exe ..\\Tool\\configgen.c"); - FILE* f = fopen("..\\config.h", "r"); - if(f != NULL){ - printf("config.h already exists, remove it to generate it again.\n"); - fclose(f); - }else{ - system("..\\Tool\\configgen.exe ..\\config.h"); - } - system("cl /nologo /Fe:..\\Tool\\config.exe ..\\Tool\\config.c"); - system("..\\Tool\\config.exe reqobjs Windows >buildobjs"); - system("..\\Tool\\config.exe objs Windows >>buildobjs"); - f = fopen("buildobjs", "r"); - if(f != NULL){ - chdir("..\\Serenade"); - char* cbuf = malloc(2); - cbuf[1] = 0; - char* buf = malloc(1); - char* objs = malloc(1); - objs[0] = 0; - buf[0] = 0; - while(1){ - fread(cbuf, 1, 1, f); - if(feof(f)) break; - if(cbuf[0] == '\n' || cbuf[0] == '\r' || cbuf[0] == ' '){ - if(strlen(buf) > 0){ - char* objstmp = objs; - objs = dynstrcat3(objstmp, " ", buf); - char* cfile = dynstrdup(buf); - cfile[strlen(cfile) - 1] = 'c'; - char* argtmp1 = dynstrcat("cl /nologo /c /D _AMD64_ /Fo:", buf); - char* argtmp2 = dynstrcat(argtmp1, " "); - char* arg = dynstrcat(argtmp2, cfile); - system(arg); - free(arg); - free(argtmp1); - free(argtmp2); - free(cfile); - } - free(buf); - buf = malloc(1); - buf[0] = 0; - }else{ - char* tmp = buf; - buf = dynstrcat(tmp, cbuf); - free(tmp); - } - } - free(buf); + fprintf(stderr, "Run me from the WinBuild directory\n"); + return 1; + } + printf("WinBuild - Serenade build script for MSVC %d\n", _MSC_FULL_VER); + system("cl /nologo /Fe:..\\Tool\\configgen.exe ..\\Tool\\configgen.c"); + FILE* f = fopen("..\\config.h", "r"); + if(f != NULL) { + printf("config.h already exists, remove it to generate it again.\n"); + fclose(f); + } else { + system("..\\Tool\\configgen.exe ..\\config.h"); + } + system("cl /nologo /Fe:..\\Tool\\config.exe ..\\Tool\\config.c"); + system("..\\Tool\\config.exe reqobjs Windows >buildobjs"); + system("..\\Tool\\config.exe objs Windows >>buildobjs"); + f = fopen("buildobjs", "r"); + if(f != NULL) { + chdir("..\\Serenade"); + char* cbuf = malloc(2); + cbuf[1] = 0; + char* buf = malloc(1); + char* objs = malloc(1); + objs[0] = 0; + buf[0] = 0; + while(1) { + fread(cbuf, 1, 1, f); + if(feof(f)) break; + if(cbuf[0] == '\n' || cbuf[0] == '\r' || cbuf[0] == ' ') { + if(strlen(buf) > 0) { + char* objstmp = objs; + objs = dynstrcat3(objstmp, " ", buf); + char* cfile = dynstrdup(buf); + cfile[strlen(cfile) - 1] = 'c'; + char* argtmp1 = dynstrcat("cl /nologo /c /D _AMD64_ /Fo:", buf); + char* argtmp2 = dynstrcat(argtmp1, " "); + char* arg = dynstrcat(argtmp2, cfile); + system(arg); + free(arg); + free(argtmp1); + free(argtmp2); + free(cfile); + } + free(buf); + buf = malloc(1); + buf[0] = 0; + } else { + char* tmp = buf; + buf = dynstrcat(tmp, cbuf); + free(tmp); + } + } + free(buf); - char* cmd = dynstrcat("cl /nologo /Fe:serenade.exe ", objs); - system(cmd); - free(cmd); + char* cmd = dynstrcat("cl /nologo /Fe:serenade.exe ", objs); + system(cmd); + free(cmd); - free(objs); + free(objs); - chdir("WinBuild"); - } - fclose(f); + chdir("WinBuild"); + } + fclose(f); } -- 2.43.0