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);
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
char * strchr(const char *String, int ch)
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)
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ double __cdecl strtod(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr)
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
WORD WORD PSZ PSZ pszFileName
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName