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

📄 smseq.c

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright 1992 SynOptics Communications, Inc.  All Rights Reserved.
 * SynOptics grants a non-exclusive license to use, copy, modify, and
 * distribute this software for any purpose and without fee, provided
 * that this copyright notice and license appear on all copies and
 * supporting documentation.
 * SynOptics makes no representations about the suitability of this
 * software for any particular purpose.  The software is supplied
 * "AS IS", and SynOptics makes no warranty, either express or implied,
 * as to the use, operation, condition, or performance of the software.
 * SynOptics retains all title and ownership in the software.
 *
 * file: SMSEQ.C - SEQUENCE functions
 *
 * $Revision:   1.4  $ $Date:   08 Jul 1992 17:37:10  $
 * $Log:   R:/MIBTOOLS/V1.0/SMIC/SRC/SMSEQ.C_V  $
 * 
 *    Rev 1.4   08 Jul 1992 17:37:10   gfoster
 * Removed unnecessary revision comment lines added by
 * PVCS to make revision history easier to read.
 * 
 *    Rev 1.3   08 Jul 1992 16:54:44   gfoster
 * Fixed use of the /E and /W options.
 * 
 *    Rev 1.2   29 Jun 1992 21:04:14   gfoster
 * Fixed check for enumerated textual convention
 * syntax type.
 * 
 *    Rev 1.1   19 Jun 1992 16:29:02   gfoster
 * Copyright text was reformated.
 * 
 * Added check so that mismatch is not reported when
 * item in sequence has bad syntax.
 * 
 * Fixed error message for item not a child of row.
 * 
 *    Rev 1.0   27 May 1992 16:06:24   gfoster
 * Initial revision.
 *
*/

#include <stdio.h>

#ifdef MS_DOS
#include <stdlib.h>
#endif /* MS_DOS */

#include <string.h>
#include <ctype.h>

#include "tds.h"
#include "smscdefs.h"
#include "smstdefs.h"
#include "smsydefs.h"
#include "smic.h"


/** addSEQname - add sequence
*
* call with:
*   pNa - new Sequence
*   pMod - containing module
*
* returns:
*   ptr to SEQor NULL if error
*/
    MIBSYM *
#ifdef __STDC__
addSEQname(STRTAB *pNa, MIBSYM *pMod)
#else
addSEQname(pNa, pMod)
    STRTAB *pNa;
    MIBSYM *pMod;
#endif /* __STDC__ */
{
    MIBSYM *pSym;
    MIBSYM *pSeq;

    /* check if item already defined */
    pSym = pNa->pSym;
    if ((pSym != NULL) && (pSym->pMod == pMod)) {
        /* item already defined */
        /* check if forward reference */
        pSeq = pSym;
        if (pSym->usType != (MIBSYMFR|MIBSYMseq)) {
            yyerror("\"%s\" already defined in current module",
                    pSym->pszName);
#ifdef OLD
            yyterm();
#endif
            return(NULL);
        }
    } else {
        /* item not defined */
        /* allocate new symbol */
        pSeq = newSEQ(pNa, pMod);
    }

    /* mark as SEQ, forward reference, and being defined */
    pSeq->usType |= MIBSYMseq | MIBSYMFR | MIBSYMDF;

    return(pSeq);

} /* addSEQname */


/** finishSEQ - finish definition of SEQUENCE
*
* NOTE: the checking of the sequence elements must be done
*       later after all the objects are defined
*
* call with:
*   pSeq - sequence
*
* returns:
*   ptr to sequence or NULL for error
*/
    MIBSYM *
#ifdef __STDC__
finishSEQ(MIBSYM *pSeq)
#else
finishSEQ(pSeq)
    MIBSYM *pSeq;
#endif /* __STDC__ */
{

    pSeq->usType = MIBSYMseq;

    return(pSeq);

} /* finishSEQ */


#define MIBSCKok 1              /* syntax matches */
#define MIBSCKcn 2              /* syntax is conflicting */
#define MIBSCKis 3              /* incompatible size */
#define MIBSCKir 4              /* incompatible range */
#define MIBSCKgr 5              /* gratuitous range */
#define MIBSCKgs 6              /* gratuitous size */
#define MIBSCKec 7              /* TC for enumerated with integer specified */
#define MIBSCKtc 8              /* seq item has base type, but obj has TC */


/** checkCompatiblity - check that syntax for sequence item
*                       matches syntax of object
*
* call with:
*   pI - item
*
* returns:
*   check result (SEE MIBSCKxxx)
*/
    USHORT
#ifdef __STDC__
checkCompatibility(MIBSEQI *pI)
#else
checkCompatibility(pI)
    MIBSEQI *pI;
#endif /* __STDC__ */
{
    MIBSYM *pOid;
    USHORT usRt;
    MIBSYN *pS;


    pOid = pI->pOid;

    /* check for bad syntax */
    if ((pOid->ut.oid.syn.usSyntax == MIBSYNbad) ||
            (pI->syn.usSyntax == MIBSYNbad))
        return(MIBSCKok);

    /* check for matching syntax */
    if (pOid->ut.oid.syn.usSyntax != pI->syn.usSyntax) {
        /* check for enumerated */
        if (pOid->ut.oid.rsyn.usSyntax == MIBSYNenum) {
            /* enumerated */
            if ((pI->syn.usSyntax == MIBSYNint) &&
                    (pI->syn.usSizeRange == MIBSRno)) {
                if (pOid->ut.oid.syn.usSyntax == MIBSYNenum)
                    /* syntax matches */
                    return(MIBSCKok);
                else;
                    /* TC for enum with integer specified */
                    return(MIBSCKec);
            } else {
                /* an error - conflicting syntax */
                return(MIBSCKcn);
            }
        }

        /* check for resolved match */
        if (pOid->ut.oid.rsyn.usSyntax != pI->syn.usSyntax) {
            /* an error - conflicting syntax */
            return(MIBSCKcn);
        } else {
            /* "resolved" syntax matches, so far */
            usRt = MIBSCKtc;
            pS = &(pOid->ut.oid.rsyn);
        }
    } else {
        usRt = MIBSCKok;
        pS = &(pOid->ut.oid.syn);
    }

    /* check for TC's */
    if (pS->usSyntax == MIBSYNtc) {
        /* textual convention */
        if (pS->usi.pTC != pI->syn.usi.pTC) {
            /* an error - conflicting syntax */
            return(MIBSCKcn);
        }
    }

    /* check if size/range specified for item */
    if (pI->syn.usSizeRange == MIBSRno) {
        /* everything OK */
        return(usRt);
    }

    /* seq item has size/range - check if compatible with object */
    if (pS->usSizeRange == pI->syn.usSizeRange) {
        switch (pS->usSizeRange) {
        case MIBSRfs:       /* fixed size */
        case MIBSRvs:       /* variable size */
            if ((pS->usr.usSize[0] == pI->syn.usr.usSize[0]) &&
                    (pS->usr.usSize[1] == pI->syn.usr.usSize[1])) {
                /* gratuitous size */
                if (!fNoSeqTcErr || fCheckSEQ)
                    return(MIBSCKgs);
                else
                    return(usRt);
            }
            break;
                
        case MIBSRpp:       /* positive to positive range */
        case MIBSRnp:       /* negative to positive range */
        case MIBSRnn:       /* negative to negative range */
            if ((pS->usr.ulRange[0] == pI->syn.usr.ulRange[0]) &&
                    (pS->usr.ulRange[1] == pI->syn.usr.ulRange[1])) {
                /* gratuitous range */
                if (!fNoSeqTcErr || fCheckSEQ)
                    return(MIBSCKgr);
                else
                    return(usRt);
            }
            break;
        }
    }

⌨️ 快捷键说明

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