20#define trace if (0) printf
44 newpath =
strdup(origpath);
47 while (newpath[
i] != 0)
50 if (newpath[
i] ==
'\\')
56 if (newpath[
i] ==
'/')
77 void* pFileData =
NULL;
80 trace(
"Loading file...");
85 trace(
"Could not open file\n");
92 *pFileSize = iFileSize;
93 trace(
"ok. Size is %d\n", iFileSize);
95 pFileData =
malloc(iFileSize + 1);
97 if (pFileData !=
NULL)
99 if (iFileSize !=
fread(pFileData, 1, iFileSize,
file))
107 trace(
"Could not allocate memory for file\n");
130 while (*psz ==
' ' || *psz ==
'\t') psz++;
138 while (*pszLine != 13 && *pszLine != 10 && *pszLine != 0) pszLine++;
141 if (pszLine[0] == 13 && pszLine[1] == 10)
143 else if (pszLine[0] == 13 || pszLine[0] == 10)
158 while (
isalnum(*psz) || *psz ==
'_')
188 pDefine = pDefine->
pNext;
196 char *
pch, *pchLineEnd, *pchVariable;
200 pchLineEnd =
strchr(pchLine,
'\n');
204 len = pchLineEnd - pchLine + 1;
211 if (pchVariable && (pchVariable < pchLineEnd))
226 error(
"Could not find variable '%.*s'\n",
len, pchVariable);
227 fwrite(pchVariable, 1,
pch - pchVariable, fileOut);
230 len = pchLineEnd -
pch + 1;
256 int inv, thisval,
val = 0;
258 trace(
"evaluating expression\n");
263 error(
"Parse error: expected '(' \n");
271 if ((
p[0] ==
'&' &&
p[1] ==
'&') ||
272 (
p[0] ==
'|' &&
p[1] ==
'|'))
296 trace(
"found a num: %d\n", thisval);
304 error(
"..Parse error, expected '(' or constant in line %d\n",
313 if (pstart[0] ==
'(')
317 else if (pstart[0] ==
'&' && pstart[1] ==
'&')
321 else if (pstart[0] ==
'&' && pstart[1] !=
'&')
325 else if (pstart[0] ==
'|' && pstart[1] ==
'|')
327 trace(
"found || val = %d, thisval = %d\n",
val, thisval);
330 else if (pstart[0] ==
'|' && pstart[1] !=
'|')
334 else if (pstart[0] ==
'+')
340 error(
"+Parse error: expected '(' or operator in Line %d, got %c\n",
367 char* pInputData, *pCurrentLine, *p1, *p2;
368 size_t cbInFileLenth;
369 int iIfLevel, iCopyLevel;
371 trace(
"parsing input file: %s\n", pszInFile);
377 pInputData =
LoadFile(pszInFile, &cbInFileLenth);
380 error(
"Could not load input file %s\n", pszInFile);
385 pInputData[cbInFileLenth] = 0;
387 pCurrentLine = pInputData;
389 iCopyLevel = iIfLevel = 0;
397 if (pCurrentLine[0] !=
'$')
400 if (iCopyLevel == iIfLevel)
413 if (
strncmp(pCurrentLine,
"$endif", 6) == 0)
415 trace(
"found $endif\n");
418 error(
"Parse error: $endif without $if in %s:%d\n", pszInFile,
iLine);
421 if (iCopyLevel == iIfLevel)
432 if (iCopyLevel < iIfLevel)
441 if (
strncmp(pCurrentLine,
"$define", 7) == 0)
444 char *pchName, *pchValue;
447 trace(
"found $define\n");
451 error(
"Parse error: expected '(' at %s:%d\n",
463 trace(
"found $define with assignment\n");
478 error(
"Failed to allocate %u bytes\n",
509 error(
"Parse error: expected ')' at %s:%d\n",
516 else if (
strncmp(pCurrentLine,
"$if", 3) == 0)
520 trace(
"found $if\n");
532 iCopyLevel = iIfLevel;
542 else if (
strncmp(pCurrentLine,
"$include", 8) == 0)
546 trace(
"found $include\n");
550 error(
"Parse error: expected '(' at %s:%d, found '%c'\n",
551 pszInFile,
iLine, *p1);
574 else if (
strncmp(pCurrentLine,
"$$", 2) == 0)
576 trace(
"$$ ignored\n");
583 trace(
"wot:%s\n", pCurrentLine);
595 trace(
"Done with file.\n\n");
604 char *pszInFile, *pszOutFile;
610 error(
"Usage: hpp <inputfile> <outputfile>\n");
617 fileOut =
fopen(pszOutFile,
"wb");
620 error(
"Cannot open output file %s", pszOutFile);
__msvcrt_long CDECL ftell(FILE *file)
int CDECL fclose(FILE *file)
int CDECL fseek(FILE *file, __msvcrt_long offset, int whence)
size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE *file)
int CDECL vfprintf(FILE *file, const char *format, va_list valist)
FILE *CDECL fopen(const char *path, const char *mode)
size_t CDECL fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
_ACRTIMP double __cdecl strtod(const char *, char **)
_ACRTIMP char *__cdecl strchr(const char *, int)
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
static char * strdup(const char *buf)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
char * convert_path(const char *origpath)
char * GetNextLine(char *pszLine)
void WriteLine(char *pchLine, FILE *fileOut)
int ParseInputFile(const char *pszInFile, FILE *fileOut)
int EvaluateExpression(char *pExpression, char **pNext)
void * LoadFile(const char *pszFileName, size_t *pFileSize)
int strxlen(const char *psz)
char * GetNextChar(const char *psz)
PDEFINE FindDefine(const char *p, char **pNext)
int EvaluateConstant(const char *p, char **pNext)
char * GetFolder(const char *pszFullPath)
WORD WORD PSZ PSZ pszFileName
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName