⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preproc.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 4 页
字号:
            return incldepth == 0;
        if (*lptr++ != '=')
        {
            generror(ERR_ILLCHAR,  *lptr, 0);
            return incldepth == 0;
        }
        ++global_flag;
        if (!getauxname(lptr, &alias))
        {
            --global_flag;
            return incldepth == 0;
        }

        sp = gsearch(name);
        if (sp)
            sp->alias = alias;
        output_alias(name, alias);

        newaux = xalloc(sizeof(AUXLIST));
        newaux->link = auxlist;
        newaux->name = name;
        newaux->alias = alias;
        auxlist = newaux;

        --global_flag;
        return incldepth == 0;

    }
    #ifdef i386
        else if (!strcmp(unmangid, "farkeyword"))
        {
            extern int prm_farkeyword;
            while (isspace(*lptr))
                lptr++;
            prm_farkeyword =  *lptr == '1';
            return incldepth == 0;
        }
    #endif 
    else
        return incldepth == 0;

    /* if we get here it was either a startup or rundown pragma */
    if (prm_cmangle)
        *p++ = '_';
    while (isalnum(*lptr) ||  *lptr == '_')
        *p++ =  *lptr++;
    *p = 0;
    while (*lptr && (*lptr == ' ' ||  *lptr == '\t' ||  *lptr == ','))
        lptr++;
    if (*lptr &&  *lptr != '\n' && !isdigit(*lptr))
    {
        generror(ERR_ILLCHAR,  *lptr, 0);
        while (*lptr)
            lptr++;
    }

    if (isdigit(*lptr))
    while (isdigit(*lptr))
    {
        val *= 10;
        val += (*lptr++) - '0';
    }
    else
        val = 64;
    ++global_flag;
    a = xalloc(sizeof(STARTUPS));
    a->name = litlate(buf);
    a->prio = val;
    if (sflag)
    {
        a->link = startuplist;
        startuplist = a;
    }
    else
    {
        a->link = rundownlist;
        rundownlist = a;
    }
    --global_flag;
    while (*lptr && (*lptr == ' ' ||  *lptr == '\t'))
        lptr++;
    if (*lptr &&  *lptr != '\n')
        generror(ERR_ILLCHAR,  *lptr, 0);
    return incldepth == 0;
}

// parses the _Pragma directive
void Compile_Pragma(void)
{
    short buf[MACRO_REPLACE_SIZE],  *q = buf;
    int chhold;
    enum e_sym symold;
    short *lpold;
    getsym();
    needpunc(openpa, 0);
    if (lastst == sconst)
    {
        char *p = laststr;
        while (*p)
        {
            if (*p == '\\')
            if (*(p + 1) == '"')
            {
                *q++ = '"';
                p += 2;
                continue;
            } 
            else if (*(p + 1) == '\\')
            {
                *q++ = '\\';
                p += 2;
                continue;
            }
            *q++ =  *p++;
        }
        *q = 0;
    }
    else if (lastst == lsconst)
    {
        short *p = laststr;
        while (*p)
        {
            if (*p == '\\')
            if (*(p + 1) == '"')
            {
                *q++ = '"';
                p += 2;
                continue;
            }
            else if (*(p + 1) == '\\')
            {
                *q++ = '\\';
                p += 2;
                continue;
            }
            *q++ =  *p++;
        }
        *q = 0;

    }
    else
    {
        getsym();
        generror(ERR_NEEDSTRING, 0, 0);
        needpunc(closepa, 0);
        return ;
    }
    chhold = lastch;
    symold = lastst;
    lpold = lptr;
    lptr = buf;
    getch();
    dopragma();
    lptr = lpold;
    lastst = symold;
    lastch = chhold;
    getsym();
    needpunc(closepa, 0);
}

//-------------------------------------------------------------------------

void setalias(SYM *sp)
{
    AUXLIST *s = auxlist;
    while (s)
    {
        if (!strcmp(s->name, sp->name))
        {
            sp->alias = s->alias;
            return ;
        }
        s = s->link;
    }
}

//-------------------------------------------------------------------------

void dumpstartups(void)
/*
 * Dump references to startup/rundown code
 */
{
    SYM *s;
    if (startuplist)
    {
        startupseg();
        while (startuplist)
        {
            s = search(startuplist->name, gsyms);
            if (!s || s->tp->type != bt_ifunc)
                gensymerror(ERR_UPDOWN, startuplist->name);
            else
            {
                gensrref(s, startuplist->prio);
                s->tp->uflags |= UF_USED;
            }
            startuplist = startuplist->link;
        }
    }
    if (rundownlist)
    {
        rundownseg();
        while (rundownlist)
        {
            s = search(rundownlist->name, gsyms);
            if (!s || s->tp->type != bt_ifunc)
                gensymerror(ERR_UPDOWN, rundownlist->name);
            else
            {
                gensrref(s, rundownlist->prio);
                s->tp->uflags |= UF_USED;
            }
            rundownlist = rundownlist->link;
        }
    }
}

//-------------------------------------------------------------------------

int doline(void)
/*
 * Handle #line directive
 */
{
    int n;
    if (ifskip)
        return incldepth == 0;
    getsym();
    if (lastst != iconst)
        gensymerror(ERR_PREPROCID, "#line");
    else
    {
        n = ival;
        getsym();
        if (lastst != sconst)
            gensymerror(ERR_PREPROCID, "#line");
        else
        {
            errfile = litlate(laststr);
            errlineno = n - 1;
        }
    }
    return incldepth == 0;
}

/* this ditty takes care of the fact that on DOS
 * (and on dos shells under NT/XP)
 * the filenames are limited to 8.3 notation
 * which is a problem because the C++ runtime has long file names
 * while we could add RTL support for long filenamse on DOS, that doesn't help on XP/NT
 *
 * so first we search for the full filename, if that fails for the ~1 version, and if that
 * fails for the truncated 8.3 version
 */
int srchpth2(char *name, char *path, int attrib)
{
    char buf[256],  *p;
    int rv = SearchPath(name, path, attrib);
    #ifdef WIN32
        return rv;
    #else 
        if (rv !=  - 1)
            return rv;
        p = strrchr(name, '.');
        if (!p)
            p = name + strlen(name);
        if (p - name < 9)
            return rv;
        strcpy(buf, name);
        strcpy(buf + 6, "~1");
        strcpy(buf + 8, p);
        rv = SearchPath(buf, path, attrib);
        if (rv !=  - 1)
        {
            strcpy(name, buf);
            return rv;
        }
        strcpy(buf, name);
        strcpy(buf + 8, p);
        rv = SearchPath(name, path, attrib);
        if (rv !=  - 1)
        {
            strcpy(name, buf);
            return rv;
        }
        return  - 1;
    #endif 
}

//-------------------------------------------------------------------------

int srchpth(char *name, char *path, int attrib, int sys)
{
    int rv = srchpth2(name, path, attrib);
    char buf[265],  *p;
    if (rv !=  - 1 || !sys)
        return rv;
    strcpy(buf, name);
    p = strrchr(buf, '.');
    if (p && !stricmp(p, ".h"))
    {
        *p = 0;
        rv = srchpth2(buf, path, attrib);
        if (rv !=  - 1)
            strcpy(name, buf);
    }
    return rv;
}

//-------------------------------------------------------------------------

int doinclude(void)
/*
 * HAndle include files
 */
{
    int rv;
    int oldsysinc = sys_inc;
    int oldfile = inputFile;
    incconst = TRUE;
    sys_inc = FALSE;
    getsym(); /* get file to include */
    incconst = FALSE;
    if (ifskip)
        return incldepth == 0;
    if (lastst != sconst)
    {
        gensymerror(ERR_INCLFILE, "include");
        return incldepth == 0;
    }
    if (incldepth >= INCL_LEVEL_MAX)
    {
        generror(ERR_PREPROCID, 0, 0);
        return incldepth == 0;
    }
    if (!sys_inc)
        inputFile = srchpth(laststr, prm_searchpath, O_RDONLY | O_BINARY, FALSE)
            ;
    if (sys_inc || inputFile ==  - 1)
    {
        inputFile = srchpth(laststr, sys_searchpath, O_RDONLY | O_BINARY, TRUE);
        if (inputFile ==  - 1 && sys_inc)
            inputFile = srchpth(laststr, prm_searchpath, O_RDONLY | O_BINARY,
                FALSE);
    }
    if (inputFile ==  - 1)
    {
        gensymerror(ERR_CANTOPEN, laststr);
        inputFile = oldfile;
        rv = incldepth == 0;
    }
    else
    {
        LIST *list;
        int i;
        ansieol();
        pushif();
        ifshold[incldepth] = ifs;
        elsetaken = 0;
        ifskip = 0;
        ifs = 0;
        if (!incldata[incldepth])
            incldata[incldepth] = malloc(sizeof(inputbuffer));
        if (!incldata[incldepth]) {
            printf("out of memory");
            exit(1);
        }
        memcpy(incldata[incldepth], inputbuffer, sizeof(inputbuffer));
        inclpos[incldepth] = inputlen;
        inclptr[incldepth] = ibufPtr;
        inputlen = 0;
        inclline[incldepth] = lineno;
        inclfile[incldepth] = oldfile; /* push current input file */
        inclcurrent[incldepth] = currentfile;
        inclsysflags[incldepth] = oldsysinc;
        inclfname[incldepth++] = infile;
        global_flag++;
        infile = litlate(laststr);
        for (i = 1, list = incfiles; list; i++, list = list->link)
            if (!strcmp(list->data, laststr))
                break;
        if (list)
            currentfile = i;
        else
        {
            list = xalloc(sizeof(FILELIST));
            list->data = infile;
            list->link = 0;
            if (incfiles)
                lastinc = lastinc->link = list;
            else
                incfiles = lastinc = list;
            currentfile = i;
        }
        browse_startfile(infile);
        errfile = infile;
        errlineno = 0;
        global_flag--;
        rv = incldepth == 1;
        lineno = 0;
    }
    return rv;
}

//-------------------------------------------------------------------------

short *plitlate(short *string)
{
    short *temp = xalloc(pstrlen(string) *sizeof(short) + sizeof(short));
    pstrcpy(temp, string);
    return temp;
}

//-------------------------------------------------------------------------

void glbdefine(char *name, char *value)
{
    {
        SYM *sp;
        short *p;
        DEFSTRUCT *def;
        if ((sp = basesearch(name, &defsyms, 0)) != 0)
            return ;
        ++global_flag; /* always do #define as globals */
        sp = makesym(sc_static);
        sp->name = litlate(name);
        def = xalloc(sizeof(DEFSTRUCT));
        def->args = 0;
        def->argcount = 0;
        def->string = p = xalloc((strlen(value) + 1) *sizeof(short));
        while (*value)
            *p++ =  *value++;
        *p++ = 0;
        sp->value.s = (char*)def;
        insert(sp, &defsyms);
        --global_flag;
        return ;
    }
}

/* Handle #defines
 * Doesn't check for redefine with different value
 * Does handle ANSI macros
 */
int dodefine(void)
{
    SYM *sp,  *spo = 0;
    DEFSTRUCT *def;
    short *args[40], count = 0;
    short *olptr;
    int p,i,j;
    int defline = lineno;
    if (ifskip)
        return incldepth == 0;
    getch();
    while (isspace(lastch))
        getch();
    if (!isstartchar(lastch))
    {
        generror(ERR_IDEXPECT, 0, 0);
        return incldepth == 0;
    }
    else
        getid();
    olptr = lptr;
    if (lastst != id)
    {
        generror(ERR_IDEXPECT, 0, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -