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

📄 smscan.c

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (usStat & KWSTdef) {
        *pusIndx = i;
        return(SMISTad);
    }

    *pusIndx = i;
    return(SMISTsmi);

} /* checkSMIname */


/** getKWuse - get use count for keyword
*
* call with:
*   iKW - index of keyword
*
* returns:
*   use count
*/
    USHORT
#ifdef __STDC__
getKWuse(USHORT iKW)
#else
getKWuse(iKW)
    USHORT iKW;
#endif /* __STDC__ */
{
    return(keyWordName[iKW].cUse);

} /* getKWuse */


/** yylexinit - initialize lexical analyser
*
* returns:
*   TRUE - success
*   FALSE - failure
*
*/
    BOOL
#ifdef __STDC__
yylexinit(VOID)
#else
yylexinit()
#endif /* __STDC__ */
{
    bldKWhash();                /* init hash table */
    usInclLevel = 0;            /* not in INCLUDE file */
    usLineNo = 1;               /* on first line */
    usColNo = 0;                /* before first character */
    cStrSpace = 0;              /* haven't allocated string space yet */

    if (!allocStrSp())          /* allocate string space */
        return(FALSE);

    return(TRUE);

} /* yylexinit */


/** openUsingIncl - open a file using the value of
*                   the include file environment variable
*
* call with:
*   pszNa - name of file
*
* returns:
*   NULL if error
*   or file handle
*/
    FILE *
#ifdef __STDC__
openUsingIncl(PSZ pszNa)
#else
openUsingIncl(pszNa)
    PSZ pszNa;
#endif /* __STDC__ */
{
    FILE *fhIn;
    PSZ pszDirS;
    PSZ pszDirE;
    USHORT cDir;
    USHORT cNa;
    PSZ pszNewNa;


    fhIn = fopen(pszNa, "rb");
    if ((pszSmicIncl == NULL) || (fhIn != NULL) ||
            (*pszNa == chDirChar))
        /* no Include path or file opened or name is absolute */
        return(fhIn);

    cNa = strlen(pszNa);
    /* for each directory in include path, try openning file */
    for (pszDirS = pszSmicIncl; *pszDirS != 0;) {
        /* find start of a directory name */
        /* skip spaces */
        while (*pszDirS == ' ') {
            pszDirS++;
        }
        if (*pszDirS == 0)
            return(NULL);

        /* find end of directory name */
        pszDirE = pszDirS;
        while ((*pszDirE != 0) && (*pszDirE != chSepChar) &&
                (*pszDirE != ' ')) {
            pszDirE++;
        }

        /* compute length of dir name */
        cDir = pszDirE - pszDirS;
        if (cDir != 0) {
            /* allocate space for filename */
            pszNewNa = (CHAR *)malloc(cDir+1+cNa+1);
            if (pszNewNa == NULL)
                return(NULL);

            /* build file name */
            memcpy(pszNewNa, pszDirS, cDir);
            pszNewNa[cDir] = chDirChar;
            memcpy(&(pszNewNa[cDir+1]), pszNa, cNa);
            pszNewNa[cDir+1+cNa] = 0;

            /* open the file */
            fhIn = fopen(pszNewNa, "rb");
            free(pszNewNa);
            if (fhIn != NULL)
                return(fhIn);
        }
        if (*pszDirE == 0)
            return(NULL);
        pszDirS = pszDirE+1;
    }
    return(NULL);

} /* openUsingIncl */


/** openInclude - open include file
*
* call with:
*   pNa - include file name
*
* returns:
*   TRUE - file opened OK
*   FALSE - error opening file
*/
    BOOL
#ifdef __STDC__
openInclude(STRTAB *pNa)
#else
openInclude(pNa)
    STRTAB *pNa;
#endif /* __STDC__ */
{

    /* An include file */
    /* check if already in an include file */
    if (usInclLevel >= MXLV) {
        yyerror("Include file nested too deeply");
        return(FALSE);
    }

    apszInFile[usInclLevel] = pszInFile;    /* save current file name */
    afhIn[usInclLevel] = fhIn;              /* save current file handle */

    /* try to open include file */
    fhIn = openUsingIncl(pNa->pszVal);
    if (fhIn == NULL) {
        yyerror("Error opening Include file \"%s\"", pNa->pszVal);
        fhIn = afhIn[usInclLevel]; /* restore file handle */

        return(FALSE);
    }
    pszInFile = pNa->pszVal;
    yylval.strval.pszFn = pNa->pszVal;

    /* save state of current file */
    ausLineNo[usInclLevel] = usLineNo;
    ausColNo[usInclLevel] = usColNo;
    aLexChar[usInclLevel] = LexChar;

    /* set new state */
    usLineNo = 1;
    usColNo = 0;
    usTokLineNo = 0;
    usTokColNo = 0;
    LexChar = ' ';
    usInclLevel++;

    if (fPrintIname)
        fprintf(fhMsg, "In file: %s\n", pNa->pszVal);

    return(TRUE);

} /* openInclude */


/* Char types */
#define CTeof   0               /* end of file */
#define CTspace 1               /* horizontal space */
#define CTquote 2               /* the " char */
#define CTback  3               /* the \ char */
#define CTline  4               /* the newline char */
#define CTat    5               /* the @ char */
#define CTalnum 6               /* alpha numeric chars */
#define CTminus 7               /* the - char */
#define CTaps   8               /* the ' char */
#define CTubar  9               /* the _ char */
#define CTpound 10              /* the # char */
#define CTlcb   11              /* the { char */
#define CTrcb   12              /* the } char */
#define CTlpr   13              /* the ( char */
#define CTrpr   14              /* the ) char */
#define CTsemi  15              /* the ; char */
#define CTcomma 16              /* the , char */
#define CTdot   17              /* the . char */
#define CTcolon 18              /* the : char */
#define CTeq    19              /* the = char */
#define CTother 20              /* everything else */

/* char type table */
UCHAR  ucCT[257] = {
/*  -1 */    CTeof,
/*           NUL      SOH      STX      ETX      EOT */
/*   0 */    CTother, CTother, CTother, CTother, CTother,
/*           ENQ      ACK      BEL      BS       HT */
/*   5 */    CTother, CTother, CTother, CTother, CTspace,
/*           LF       VT       FF       CR       SO */
/*  10 */    CTline,  CTspace, CTspace, CTspace, CTother,
/*           SI       DLE      DC1      DC2      DC3 */ 
/*  15 */    CTother, CTother, CTother, CTother, CTother,
/*           DC4      NAK      SYN      ETB      CAN */
/*  20 */    CTother, CTother, CTother, CTother, CTother,
/*           EM       SUB      ESC      FS       GS */
/*  25 */    CTother, CTother, CTother, CTother, CTother,
/*           RS       US       blank    !        "  */
/*  30 */    CTother, CTother, CTspace, CTother, CTquote,
/*           #        $        %        &        '  */
/*  35 */    CTpound, CTother, CTother, CTother, CTaps,
/*           (        )        *        +        ,  */
/*  40 */    CTlpr,   CTrpr,   CTother, CTother, CTcomma,
/*           -        .        /        0        1  */
/*  45 */    CTminus, CTdot,   CTother, CTalnum, CTalnum,
/*           2        3        4        5        6  */
/*  50 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           7        8        9        :        ;  */
/*  55 */    CTalnum, CTalnum, CTalnum, CTcolon, CTsemi,
/*           <        =        >        ?        @  */
/*  60 */    CTother, CTeq,    CTother, CTother, CTat,
/*           A        B        C        D        E  */
/*  65 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           F        G        H        I        J  */
/*  70 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           K        L        M        N        O  */
/*  75 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           P        Q        R        S        T  */
/*  80 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           U        V        W        X        Y  */
/*  85 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           Z        [        \        ]        ^  */
/*  90 */    CTalnum, CTother, CTback,  CTother, CTother,
/*           _        `        a        b        c  */ 
/*  95 */    CTubar,  CTother, CTalnum, CTalnum, CTalnum,
/*           d        e        f        g        h  */
/* 100 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           i        j        k        l        m  */
/* 105 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           n        o        p        q        r  */
/* 110 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           s        t        u        v        w  */
/* 115 */    CTalnum, CTalnum, CTalnum, CTalnum, CTalnum,
/*           x        y        z        {        |  */
/* 120 */    CTalnum, CTalnum, CTalnum, CTlcb,   CTother,
/*           }        ~        DEL */     
/* 125 */    CTrcb,   CTother, CTother, CTother, CTother,
/* 130 */    CTother, CTother, CTother, CTother, CTother,
/* 135 */    CTother, CTother, CTother, CTother, CTother,
/* 140 */    CTother, CTother, CTother, CTother, CTother,
/* 145 */    CTother, CTother, CTother, CTother, CTother,
/* 150 */    CTother, CTother, CTother, CTother, CTother,
/* 155 */    CTother, CTother, CTother, CTother, CTother,
/* 160 */    CTother, CTother, CTother, CTother, CTother,
/* 165 */    CTother, CTother, CTother, CTother, CTother,
/* 170 */    CTother, CTother, CTother, CTother, CTother,
/* 175 */    CTother, CTother, CTother, CTother, CTother,
/* 180 */    CTother, CTother, CTother, CTother, CTother,
/* 185 */    CTother, CTother, CTother, CTother, CTother,
/* 190 */    CTother, CTother, CTother, CTother, CTother,
/* 195 */    CTother, CTother, CTother, CTother, CTother,
/* 200 */    CTother, CTother, CTother, CTother, CTother,
/* 205 */    CTother, CTother, CTother, CTother, CTother,
/* 210 */    CTother, CTother, CTother, CTother, CTother,
/* 215 */    CTother, CTother, CTother, CTother, CTother,
/* 220 */    CTother, CTother, CTother, CTother, CTother,
/* 225 */    CTother, CTother, CTother, CTother, CTother,
/* 230 */    CTother, CTother, CTother, CTother, CTother,
/* 235 */    CTother, CTother, CTother, CTother, CTother,
/* 240 */    CTother, CTother, CTother, CTother, CTother,
/* 245 */    CTother, CTother, CTother, CTother, CTother,
/* 250 */    CTother, CTother, CTother, CTother, CTother,
/* 255 */    CTother};

/** yylex - lexical analyser
*
* returns:
*   token type (also sets global yylval)
*
* NOTE: This is a quick and dirty implementation,
*       don't use this an an example of efficiency
*
*/
    INT
#ifdef __STDC__
yylex(void)
#else
yylex()
#endif /* __STDC__ */
{
#if 0
    register INT rLexChar;
    register INT rClass;
#endif
	INT rLexChar;
   INT rClass;
    SHORT i;
    STRTAB *pStrTab;


    rLexChar = LexChar;
    yylval.strval.pszFn = pszInFile;

    for (;;) {

    /* skip white space */
    while(((rClass = ucCT[rLexChar+1]) == CTspace) || (rClass == CTline)) {
        rLexChar = yylexin();
    }

    /* save info on current token */
    yylval.strval.usLineNo = (usTokLineNo = usLineNo);
    yylval.strval.usColNo = (usTokColNo = usColNo);

    switch(rClass) {

    case CTeof:
        /* END OF FILE */
        if (usInclLevel == 0) {
            /* not in include file */
            ausStrSpaceSz[cStrSpace-1] = usStrSpaceIndx;
            LexChar = rLexChar;
            return(sTokType = tokEOF);
        }

        /* in Include file, restore original position */
        fclose(fhIn);
        usInclLevel--;
        fhIn = afhIn[usInclLevel];
        pszInFile = apszInFile[usInclLevel];
        yylval.strval.pszFn = pszInFile;
        if (fPrintIname)
            fprintf(fhMsg, "In file: %s\n", pszInFile);
        usLineNo = ausLineNo[usInclLevel];
        usColNo = ausColNo[usInclLevel];
        rLexChar = aLexChar[usInclLevel];

        /* start skipping white space */
        continue;

    case CTquote:
        /* A string */
        /* Trim leading spaces after a newline upto start column of string */
        /* Note: two quotes are used to embed a quote, or \" can be used */
        {
            register BOOL fEOLtrim;


            pszTokVal = (PSZ)&(pbStrSpace[usStrSpaceIndx]);
            usStrSpaceTokIndx = usStrSpaceIndx;
            fEOLtrim = FALSE;

            for(;;) {
                rLexChar = yylexin();

                switch (ucCT[rLexChar+1]) {

                case CTeof:
                    /* EOF in string */
                    yyerror("EOF inside a string");
                    goto finish_str;

                case CTquote:
                    /* check for embedded quotes or end of quote */
                    rLexChar = yylexin();
                    if (rLexChar != '\"')
                        goto finish_str;    /* all done */

                    if (!fNoStr)
                        yylexout('\"');
                    fEOLtrim = FALSE;
                    break;

                case CTback:
                    /* a '\' */
                    fEOLtrim = FALSE;
                    rLexChar = yylexin();
                    if (rLexChar == '\"') {
                        if (!fNoStr)
                            yylexout('\"'); /* embedded quote */
                    } else {
                        /* unknown char after '\' - output both */
                        if (!fNoStr) {
                            yylexout('\\');
                            yylexout(rLexChar);
                        }
                    }
                    break;

                case CTline:
                    /* a new line - add it to string */
                    if (!fNoStr)
                        yylexout('\n');
                    fEOLtrim = TRUE;    /* eat leading spaces */
                    break;

                case CTspace:
                    /* check for trimming after EOL */
                    if ((!fEOLtrim) || (usColNo >= usTokColNo)) {
                        fEOLtrim = FALSE;
                        /* output space */
                        if (!fNoStr)
                            yylexout(' ');
                    }
                    break;

                default:
                    fEOLtrim = FALSE;
                    if (!fNoStr)
                        yylexout(rLexChar);
                    break;
                }
            } /* for(;;) */

            /* finished with string */
finish_str:
            yylexout(0);
            sTokType = tokSTRING;
            pStrTab = StrTabInsert(pszTokVal);
            if (pStrTab->pszVal != pszTokVal) {
                /* string already in string table */
                /* so don't need another copy */
                usStrSpaceIndx = usStrSpaceTokIndx;
                pszTokVal = pStrTab->pszVal;
            }
            yylval.strval.pStr = pStrTab;
        }
        break;

    case CTaps:
        /* A hex or binary string */

        pszTokVal = (PSZ)&(pbStrSpace[usStrSpaceIndx]);

⌨️ 快捷键说明

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