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

📄 smoid.c

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * 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: SMOID.C - OID functions
 *
 * $Revision:   1.2  $ $Date:   27 Jul 1992 19:57:02  $
 * $Log:   R:/MIBTOOLS/V1.0/SMIC/SRC/SMOID.C_V  $
 * 
 *    Rev 1.2   27 Jul 1992 19:57:02   gfoster
 * Changed the variable name fNoCheckIndxSeq
 * to fCheckIndxSeq to accommodate the -7
 * option providing stricter index item checking
 * instead of looser checking.
 * 
 *    Rev 1.1   19 Jun 1992 16:13:26   gfoster
 * Copyright text was reformated.
 * 
 * Fixed bug so that situation is correctly reported when
 * duplicate OID objects are defined.
 * 
 *    Rev 1.0   27 May 1992 16:01:18   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"


/** checkOIDcomp - check if OID component is valid
*
* NOTE: no forward references are allowed
*
* call with:
*   pPar - ptr to parent (or NULL)
*   pNa - component name (or NULL)
*   ulVal - component value (or -1 if not present)
*   pMod - module containing component use
*
* returns:
*   ptr to component or NULL if error
*/
    MIBSYM *
#ifdef __STDC__
checkOIDcomp(MIBSYM *pPar, STRTAB *pNa, ULONG ulVal, MIBSYM *pMod)
#else
checkOIDcomp(pPar, pNa, ulVal, pMod)
    MIBSYM *pPar;
    STRTAB *pNa;
    ULONG ulVal;
    MIBSYM *pMod;
#endif
{
    MIBSYM *pComp;
    MIBSYM *pT;


    /* check if name specified */
    if (pNa != NULL) {
        /* name present, check if item defined */
        pComp = pNa->pSym;
        if (pComp == NULL) {
            /* item not defined */
            yyerror("component \"%s\" is not defined",
                    pComp->pszName);
#ifdef OLD
            yyterm();
#endif
            return(NULL);
        }
        if (pComp->pMod != pMod) {
            /* item not defined */
            yyerror("component \"%s\" is not defined in the current module",
                    pComp->pszName);
#ifdef OLD
            yyterm();
#endif
            return(NULL);
        }

        /* check if import */
        if (pComp->usType == MIBSYMimp) {
            pComp->ut.imp.cUse++;
            pComp = pComp->ut.imp.pImpSym;
        }

        /* check if OID type */
        if ((pComp->usType & MIBSYMmask) != MIBSYMoid) {
            yyerror("component \"%s\" must be an item having an OID value",
                    pComp->pszName);
#ifdef OLD
            yyterm();
#endif
            return(NULL);
        }

        /* check for valid data structures */
        if (pComp->ut.oid.pPar == NULL) {
#ifdef OLD
            yyerror("checkOIDcomp: internal error - bad data structure for \"%s\"",
                    pComp->pszName);
            yyterm();
#endif
            return(NULL);
        }

        /* check for matching parents */
        if (pPar == NULL) {
            /* no parent given */
            /* get parent from component */
            pPar = pComp->ut.oid.pPar;
        } else {
            /* parent specified */
            /* check if same parent */
            if (pComp->ut.oid.pPar != pPar) {
                if ((pComp->ut.oid.pPar)->pMod != pMod)
                    yyerror("\"%s\" already defined with parent \"%s\" from module \"%s\" and not \"%s\"",
                            pComp->pszName, (pComp->ut.oid.pPar)->pszName,
                            ((pComp->ut.oid.pPar)->pMod)->pszName,
                            pPar->pszName);
                else
                    yyerror("\"%s\" already defined with parent \"%s\" and not \"%s\"",
                            pComp->pszName, (pComp->ut.oid.pPar)->pszName,
                            pPar->pszName);
#ifdef OLD
                yyterm();
#endif
                return(NULL);
            }
        }

        /* check if number present */
        if (ulVal != -1L) {
            /* check if component has same value */
            if (pComp->ut.oid.ulVal != ulVal) {
                /* mismatch of values */
                yyerror("component \"%s\" already assigned value %lu, and can not be changed to %lu",
                        pComp->pszName, pComp->ut.oid.ulVal, ulVal);
#ifdef OLD
                yyterm();
#endif
                return(NULL);
            }
        }
        /* all done */
        return(pComp);
    }
    
    
    /* just a number specified */
    /* check if parent has value */
    if (pPar == NULL)
        return(NULL);
    for (pT = pPar->ut.oid.pChild; pT != NULL; pT = pT->ut.oid.pSib) {
        if (ulVal == pT->ut.oid.ulVal) {
            /* found match, all done */
            return(pT);
        }
        if (ulVal < pT->ut.oid.ulVal) {
            /* found place it should be */
            break;
        }
    }

    /* value not defined */
    yyerror("No item found for \"%s\" with OID value %lu",
            pPar->pszName, ulVal);
#ifdef OLD
    yyterm();
#endif
    return(NULL);


} /* checkOIDcomp */


/** addOIDname - add pure OID
*
* call with:
*   pNa - new OID
*   pNaPar - name of parent (if NULL, then defining top items)
*   ulVal - component value
*   pMod - containing module
*
* returns:
*   ptr to OID or NULL if error
*/
    MIBSYM *
#ifdef __STDC__
addOIDname(STRTAB *pNa, STRTAB *pNaPar, ULONG ulVal, MIBSYM *pMod)
#else
addOIDname(pNa, pNaPar, ulVal, pMod)
    STRTAB *pNa;
    STRTAB *pNaPar;
    ULONG ulVal;
    MIBSYM *pMod;
#endif /* __STDC__ */
{
    MIBSYM *pSym;
    MIBSYM *pOid;
    MIBSYM *pPar;
    MIBSYM *pSymPar;
    MIBSYM *pT;
    MIBSYM *pOT;
    BOOL fCheckCirc = FALSE;


    /* check is self defining */
    if (pNa == pNaPar) {
        yyerror("OID \"%s\" can not be used to define itself\n",
                pNa->pszVal);
#ifdef OLD
        yyterm();
#endif
        return(NULL);
    }

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

    /* if parent is specified */
    if (pNaPar != NULL) {
        /* check if parent already defined */
        pSymPar = pNaPar->pSym;
        if ((pSymPar != NULL) && (pSymPar->pMod == pMod)) {
            /* parent defined */
            /* check if import */
            if (pSymPar->usType == MIBSYMimp) {
                pSymPar->ut.imp.cUse++;
                pSymPar = pSymPar->ut.imp.pImpSym;
            } else
                fCheckCirc = TRUE;

            /* check if parent is an OID type */
            if ((pSymPar->usType & MIBSYMmask) != MIBSYMoid) {
                yyerror("parent \"%s\" of \"%s\" must be OID object",
                    pSymPar->pszName, pNa->pszVal);
#ifdef OLD
                yyterm();
#endif
                return(NULL);
            }
            pPar = (MIBSYM *)pSymPar;
        } else {
            /* parent not defined, allocate one */
            pPar = newOID(pNaPar, pMod);
        }
    } else {
        pPar = &OidRoot;
    }

    /* if not forward reference, then allocate */
    if (pOid == NULL) {
        /* new symbol */
        pOid = newOID(pNa, pMod);
    } else {
        /* forward reference */
        if (fCheckCirc) {
            /* parent already defined and not import */
            /* check for circular reference */
            for (pT = pPar; pT != NULL; pT = pT->ut.oid.pPar) {
                if (pT == pOid) {
                    yyerror("\"%s\" is circular defined", pOid->pszName);
#ifdef OLD
                    yyterm();
#endif
                    return(NULL);
                }
            }
        }
    }

    /* store values */
    pOid->usType = MIBSYMoid;
    pOid->ut.oid.ulVal = ulVal;
    pOid->ut.oid.usOType = MIBOToid;
    pOid->ut.oid.pPar = pPar;
    /* insert in children list for parent */
    for (pOT = NULL, pT = pPar->ut.oid.pChild; pT != NULL;
            pOT = pT, pT = pT->ut.oid.pSib) {
        if (ulVal < pT->ut.oid.ulVal) {
            /* found place to insert */
            break;
        }
        if (ulVal == pT->ut.oid.ulVal) {
            /* duplicate values */
            if (pT->pMod == pMod) {
                if (strcmp(pOid->pszName, pT->pszName) == 0)
                    yyerror("\"%s\" is already defined",
                            pOid->pszName);
                else
                    yyerror("\"%s\" and \"%s\" have same registration value",
                            pOid->pszName, pT->pszName);
            } else {
                if (strcmp(pOid->pszName, pT->pszName) == 0)
                    yyerror("\"%s\" is already defined in module \"%s\"",
                            pT->pszName, (pT->pMod)->pszName);
                else

⌨️ 快捷键说明

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