X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Ftools%2Fhpp%2Fhpp.c;fp=reactos%2Ftools%2Fhpp%2Fhpp.c;h=1591e4881e60f7dbda3e0c5c154d396d576a8834;hp=ef751989419367c138a27037e2fe384715df025b;hb=cbdf28bb6ace5e3faec494c5743371d7288f191c;hpb=347f68539b0884f6adfc5d986b2cb8c07c8df4bb diff --git a/reactos/tools/hpp/hpp.c b/reactos/tools/hpp/hpp.c index ef751989419..1591e4881e6 100644 --- a/reactos/tools/hpp/hpp.c +++ b/reactos/tools/hpp/hpp.c @@ -12,6 +12,8 @@ #include #include +//#define DBG 1 + #if DBG #define trace printf #else @@ -70,24 +72,40 @@ LoadFile(const char* pszFileName, size_t* pFileSize) { FILE* file; void* pFileData = NULL; + int iFileSize; + + trace("Loading file..."); file = fopen(pszFileName, "rb"); - if (file != NULL) + if (!file) { - fseek(file, 0L, SEEK_END); - *pFileSize = ftell(file); - fseek(file, 0L, SEEK_SET); - pFileData = malloc(*pFileSize); - if (pFileData != NULL) - { - if (*pFileSize != fread(pFileData, 1, *pFileSize, file)) - { - free(pFileData); - pFileData = NULL; - } - } - fclose(file); + trace("Could not open file\n"); + return NULL; } + + fseek(file, 0L, SEEK_END); + iFileSize = ftell(file); + fseek(file, 0L, SEEK_SET); + *pFileSize = iFileSize; + trace("ok. Size is %d\n", iFileSize); + + pFileData = malloc(iFileSize + 1); + + if (pFileData != NULL) + { + if (iFileSize != fread(pFileData, 1, iFileSize, file)) + { + free(pFileData); + pFileData = NULL; + } + } + else + { + trace("Could not allocate memory for file\n"); + } + + fclose(file); + return pFileData; } @@ -452,6 +470,9 @@ ParseInputFile(const char *pszInFile, FILE *fileOut) /* Restore the global file name */ gpszCurFile = pszInFile; + + /* Restore the zeroed character */ + *p2 = ')'; if (ret == -1) { @@ -481,6 +502,8 @@ ParseInputFile(const char *pszInFile, FILE *fileOut) /* Free the file data */ free(pInputData); + trace("Done with file.\n\n"); + return 0; } @@ -494,7 +517,7 @@ main(int argc, char* argv[]) if (argc != 3) { - error("Usage: hc \n"); + error("Usage: hpp \n"); exit(1); }