Exemplo n.º 1
0
void _pushFileStack(char *fileName) {
    int i;

    if (fileStackLevel >= 0) {
        for (i = 0; i < g_tlang.numOfOutFiles; i++) {
            g_tlang.outputCurrLine(i, 0);
            if (CURR_OUTPUT(i) != NULL) {
                wicFclose(CURR_OUTPUT(i));
            }
        }
    }
    fileStackLevel++;

    if (fileStackLevel >= MAX_INCLUDE_NEST) {
        fileStackLevel--;
        reportError(ERR_NEST_INCLUDE);
        return;
    } else {
        FDReadInd entry;
        pFDReadInd incFile;
        initFDReadInd(&entry,  fileName, 0);
        incFile = findHTableElem(g_fileTable, &entry);
        assert(incFile != NULL);

        assert(fileName != NULL);
        for (i = 0; i < g_tlang.numOfOutFiles; i++) {
            setNewFileExt(CURR_FILE_NAME(i), fileName, g_tlang.extension[i]);
            if (incFile->readOnly) {
                CURR_OUTPUT(i) = NULL;
            } else {
                CURR_OUTPUT(i) = wicFopen(CURR_FILE_NAME(i), "wt");
                if (CURR_OUTPUT(i) == NULL) {
                    int j;
                    for (j = i-1; j >= 0; j--) {
                        wicFclose(CURR_OUTPUT(j));
                        CURR_OUTPUT(j) = NULL;
                    }
                    // fileStackLevel--;
                    return;
                }
            }

            CURR_LAST_CHAR(i) = 0;
            CURR_LINE_LEN(i) = 0;
            CURR_LINE(i)[0] = 0;
            CURR_LINE_FLAGS(i) = g_tlang.lfInitFlags;
        }
    }
}
Exemplo n.º 2
0
static void restoreTokFile(void) {
    currTokF--;
    if (currTokF >= 0) {
        g_currFileName = TOK_FILE_NAME;
        g_currLineNum = LINE_NUM;
        g_currColNum = COL_NUM;
        TOK_FILE = wicFopen(TOK_FILE_NAME, "r");
        if (TOK_FILE == NULL) {
            reportError(ERR_OPEN_FILE, TOK_FILE_NAME, strerror(errno));
            reportError(FATAL_DIE);
        }
        if (fseek(TOK_FILE, CURR_FILE_POS, SEEK_SET) != 0) {
            reportError(ERR_COULD_NOT_SEEK, TOK_FILE_NAME, strerror(errno));
            reportError(FATAL_DIE);
        }
    }
}
Exemplo n.º 3
0
static FILE *_openIncludeFile(char *fname, char **newAllocName) {
    FILE *file = NULL;
    char fullName[_MAX_PATH];
    pFDReadInd dir = NULL;
    char *fullNameCopy;

    strcpy(fullName, fname);
    rewindCurrSLListPos(g_opt.incPathList);
    do {
        setDefaultExt(fullName, "h");
        if (fileReadable(fullName)) {
            file = wicFopen(fullName, "r");
            if (file != NULL) {
                pFDReadInd newElem;
                fullNameCopy = wicStrdup(fullName);
                newElem = createFDReadInd(fullNameCopy,
                            dir == NULL ? 0 : dir->readOnly);
                if (!addHTableElem(g_fileTable, newElem)) {
                    reportError(ERR_FILE_WAS_INCLUDED, fullNameCopy);
                    wicFclose(file);
                    zapFDReadInd(newElem);
                    file = NULL;
                }
                break;
            }
        }
        if (!getCurrSLListPosElem(g_opt.incPathList, &dir)) {
            strcpy(fullName, fname);
            setDefaultExt(fullName, "h");
            reportError(ERR_INC_FILE_NOT_FOUND, fullName);
            break;
        }
        sprintf(fullName, "%s\\%s", dir->name, fname);
        incCurrSLListPos(g_opt.incPathList);
    } while (1);

    if (file == NULL) {
        *newAllocName = NULL;
    } else {
        *newAllocName = fullNameCopy;
    }
    return file;
}
Exemplo n.º 4
0
void _popFileStack(void) {
    int i;
    assert(fileStackLevel >= 0);
    for (i = 0; i < g_tlang.numOfOutFiles; i++) {
        g_tlang.outputCurrLine(i, 0);
        if (CURR_OUTPUT(i) != NULL) {
            wicFclose(CURR_OUTPUT(i));
        }
    }
    fileStackLevel--;
    if (fileStackLevel >= 0) {
        for (i = 0; i < g_tlang.numOfOutFiles; i++) {
            CURR_OUTPUT(i) = wicFopen(CURR_FILE_NAME(i), "at");
            if (CURR_OUTPUT(i) == NULL) {
                reportError(ERR_OPEN_FILE, CURR_FILE_NAME(i), strerror(errno));
                reportError(FATAL_DIE);
            }
        }
    }
}