Allow using - to indicate input from stdin

This commit is contained in:
Jakub Kądziołka
2019-03-03 23:27:53 +01:00
parent 3cd1d46a1b
commit 20f9492899

View File

@@ -405,23 +405,25 @@ void fstk_RunRept(uint32_t count)
/* /*
* Initialize the filestack routines * Initialize the filestack routines
*/ */
void fstk_Init(char *s) void fstk_Init(char *pFileName)
{ {
char tzFileName[_MAX_PATH + 1];
char tzSymFileName[_MAX_PATH + 1 + 2]; char tzSymFileName[_MAX_PATH + 1 + 2];
snprintf(tzSymFileName, sizeof(tzSymFileName), "\"%s\"", s); snprintf(tzSymFileName, sizeof(tzSymFileName), "\"%s\"", pFileName);
sym_AddString("__FILE__", tzSymFileName); sym_AddString("__FILE__", tzSymFileName);
strcpy(tzFileName, s);
pFileStack = NULL; pFileStack = NULL;
pCurrentFile = fopen(tzFileName, "rb"); if (strcmp(pFileName, "-") == 0) {
pCurrentFile = stdin;
} else {
pCurrentFile = fopen(pFileName, "rb");
if (pCurrentFile == NULL) if (pCurrentFile == NULL)
err(1, "Unable to open file '%s'", tzFileName); err(1, "Unable to open file '%s'", pFileName);
}
nMacroCount = 0; nMacroCount = 0;
nCurrentStatus = STAT_isInclude; nCurrentStatus = STAT_isInclude;
snprintf(tzCurrentFileName, _MAX_PATH + 1, "%s", tzFileName); snprintf(tzCurrentFileName, _MAX_PATH + 1, "%s", pFileName);
CurrentFlexHandle = yy_create_buffer(pCurrentFile); CurrentFlexHandle = yy_create_buffer(pCurrentFile);
yy_switch_to_buffer(CurrentFlexHandle); yy_switch_to_buffer(CurrentFlexHandle);
nLineNo = 1; nLineNo = 1;