📄 smparcom.c
字号:
*
* call with:
* pNa - name of tc object
* pMod - module containing object
*
* returns:
* ptr to tc object or NULL if error
*/
MIBSYM *
#ifdef __STDC__
newTC(STRTAB *pNa, MIBSYM *pMod)
#else
newTC(pNa, pMod)
STRTAB *pNa;
MIBSYM *pMod;
#endif /* __STDC__ */
{
MIBSYM *pT;
MIBSYM *pTc;
USHORT i;
/* check if any available */
if (pTcAvail == NULL) {
/* none avail - so allocate some */
pTcAvail = (MIBSYM *)malloc(sizeof(MIBSYM)*MIBTCACT);
if (pTcAvail == NULL) {
yyerror("newTC: out of heap memory");
yystats();
yyterm();
return(NULL);
}
cTcAlloc += MIBTCACT;
/* put tc objects in list */
for (pT = pTcAvail, i = 1; i < MIBTCACT; i++, pT++) {
pT->pNext = pT+1;
}
pT->pNext = NULL;
}
/* get tc object from list */
pTc = pTcAvail;
pTcAvail = pTcAvail->pNext;
cTcUsed++;
/* init fields */
pTc->usType = MIBSYMtc;
pTc->pSym = pNa->pSym;
pNa->pSym = pTc;
pTc->pMod = pMod;
pTc->pAlist = NULL;
pTc->pszName = pNa->pszVal;
pTc->usStatus = MIBSTAnu;
pTc->usNeed = MIBIEns;
pTc->pBKEdata = NULL;
pTc->pszDesc = NULL;
pTc->pszRefer = NULL;
pTc->pNext = NULL;
memset(&(pTc->ut.tc.syn), 0, sizeof(MIBSYN));
memset(&(pTc->ut.tc.rsyn), 0, sizeof(MIBSYN));
pTc->ut.tc.cUse = 0;
/* link to end of global list of tc objects */
if (pTcGHL == NULL) {
/* list empty */
pTcGHL = pTc;
} else {
/* add to end */
pTcGTL->pNext = pTc;
}
pTcGTL = pTc;
return(pTc);
} /* newTC */
/** finishTC - finish definition of a textual convention
*
* call with:
* pTc - tc object
* pSyn - syntax info
*
* returns:
* ptr to tc or NULL for error
*/
MIBSYM *
#ifdef __STDC__
finishTC(MIBSYM *pTc, MIBSYN *pSyn)
#else
finishTC(pTc, pSyn)
MIBSYM *pTc;
MIBSYN *pSyn;
#endif /* __STDC__ */
{
/* store values */
pTc->usType = MIBSYMtc;
pTc->ut.tc.syn = *pSyn; /* copy syntax info */
/* get resolved syntax */
if (pSyn->usSyntax == MIBSYNtc) {
/* a TC, so get resolved syntax from TC's resolved syntax */
pTc->ut.tc.rsyn = (pSyn->usi.pTC)->ut.tc.rsyn;
/* add size/range if present */
if ((pSyn->usSizeRange != MIBSRno) &&
(pSyn->usSizeRange != MIBSRbad)) {
pTc->ut.tc.rsyn.usSizeRange = pSyn->usSizeRange;
pTc->ut.tc.rsyn.usr = pSyn->usr;
}
} else
pTc->ut.tc.rsyn = *pSyn; /* syntax and resolved syntax are the same */
return(pTc);
} /* finishTC */
/** newSEQ - allocate a new seq object
*
* ??NOTE: change to allocate only space needed
*
* call with:
* pNa - name of seq object
* pMod - module containing sequence
*
* returns:
* ptr to seq object or NULL if error
*/
MIBSYM *newSEQ(STRTAB *pNa, MIBSYM *pMod)
{
MIBSYM *pSeq;
int err;
pSeq = (MIBSYM *)malloc(sizeof(MIBSYM));
if (pSeq != NULL)
{
err = AllocMemAdd(pSeq);
if (err)
{
free(pSeq);
pSeq = NULL;
}
else
{
cSeqUsed++;
/* init fields */
pSeq->usType = MIBSYMseq | MIBSYMFR; /* make forward reference */
pSeq->pSym = pNa->pSym;
pNa->pSym = pSeq;
pSeq->pMod = pMod;
pSeq->pAlist = NULL;
pSeq->pszName = pNa->pszVal;
pSeq->usStatus = MIBSTAnu;
pSeq->usNeed = MIBIEns;
pSeq->pBKEdata = NULL;
pSeq->pszDesc = NULL;
pSeq->pszRefer = NULL;
pSeq->pNext = NULL;
pSeq->ut.seq.pSeqIL = NULL;
pSeq->ut.seq.cSeqi = 0;
pSeq->ut.seq.cUse = 0;
pSeq->ut.seq.pRow = NULL;
/* link to end of global list of sequences */
if (pSeqGHL == NULL)
{
/* list empty */
pSeqGHL = pSeq;
}
else
{
/* add to end */
pSeqGTL->pNext = pSeq;
}
pSeqGTL = pSeq;
}
}
return(pSeq);
}
#if 0
MIBSYM *
#ifdef __STDC__
newSEQ(STRTAB *pNa, MIBSYM *pMod)
#else
newSEQ(pNa, pMod)
STRTAB *pNa;
MIBSYM *pMod;
#endif /* __STDC__ */
{
MIBSYM *pT;
MIBSYM *pSeq;
USHORT i;
/* check if any available */
if (pSeqAvail == NULL) {
/* none avail - so allocate some */
pSeqAvail = (MIBSYM *)malloc(sizeof(MIBSYM)*MIBSEQACT);
if (pSeqAvail == NULL) {
yyerror("newSEQ: out of heap memory");
yystats();
yyterm();
return(NULL);
}
cSeqAlloc += MIBSEQACT;
/* put seq objects in list */
for (pT = pSeqAvail, i = 1; i < MIBSEQACT; i++, pT++) {
pT->pNext = pT+1;
}
pT->pNext = NULL;
}
/* get seq object from list */
pSeq = pSeqAvail;
pSeqAvail = pSeqAvail->pNext;
cSeqUsed++;
/* init fields */
pSeq->usType = MIBSYMseq | MIBSYMFR; /* make forward reference */
pSeq->pSym = pNa->pSym;
pNa->pSym = pSeq;
pSeq->pMod = pMod;
pSeq->pAlist = NULL;
pSeq->pszName = pNa->pszVal;
pSeq->usStatus = MIBSTAnu;
pSeq->usNeed = MIBIEns;
pSeq->pBKEdata = NULL;
pSeq->pszDesc = NULL;
pSeq->pszRefer = NULL;
pSeq->pNext = NULL;
pSeq->ut.seq.pSeqIL = NULL;
pSeq->ut.seq.cSeqi = 0;
pSeq->ut.seq.cUse = 0;
pSeq->ut.seq.pRow = NULL;
/* link to end of global list of sequences */
if (pSeqGHL == NULL) {
/* list empty */
pSeqGHL = pSeq;
} else {
/* add to end */
pSeqGTL->pNext = pSeq;
}
pSeqGTL = pSeq;
return(pSeq);
} /* newSEQ */
#endif
/** newSEQI - allocate a Sequence item
*
* call with:
* pSeq - sequence containing item
* pOid - sequence item
* pSyn - syntax
*
* returns:
* ptr to new item or NULL if error
*/
MIBSEQI *newSEQI(MIBSYM *pSeq, MIBSYM *pOid, MIBSYN *pSyn)
{
MIBSEQI *pT;
MIBSEQI *pOT;
MIBSEQI *pSeqi;
SHORT rt;
int err;
pSeqi = (MIBSEQI *)malloc(sizeof(MIBSEQI));
if (pSeqi != NULL)
{
err = AllocMemAdd(pSeqi);
if (err)
{
free(pSeqi);
pSeqi = NULL;
}
else
{
cSeqiUsed++;
++(pSeq->ut.seq.cSeqi);
/* init fields */
pSeqi->pOid = pOid;
pSeqi->syn = *pSyn;
/* insert at end of list after checking for dups */
for (pOT = NULL, pT = pSeq->ut.seq.pSeqIL; pT != NULL;
pOT = pT, pT = pT->pNext)
{
if ((rt = strcmp((pSeqi->pOid)->pszName, (pT->pOid)->pszName)) == 0)
{
/* duplicate name */
fprintf(fhMsg, "duplicate name \"%s\" in SEQUENCE",
(pSeqi->pOid)->pszName);
free(pSeqi);
yyterm();
return(NULL);
}
}
if (pOT == NULL)
{
/* insert at beginning of list */
pSeq->ut.seq.pSeqIL = pSeqi;
}
else
{
/* insert at end of list */
pOT->pNext = pSeqi;
}
pSeqi->pNext = pT;
}
}
return(pSeqi);
}
#if 0
MIBSEQI *
#ifdef __STDC__
newSEQI(MIBSYM *pSeq, MIBSYM *pOid, MIBSYN *pSyn)
#else
newSEQI(pSeq, pOid, pSyn)
MIBSYM *pSeq;
MIBSYM *pOid;
MIBSYN *pSyn;
#endif /* __STDC__ */
{
MIBSEQI *pT;
MIBSEQI *pOT;
MIBSEQI *pSeqi;
USHORT i;
SHORT rt;
/* check if any available */
if (pSeqiAvail == NULL) {
/* none avail - so allocate some */
pSeqiAvail = (MIBSEQI *)malloc(sizeof(MIBSEQI)*MIBSEQIACT);
if (pSeqiAvail == NULL) {
yyerror("newSEQI: out of heap memory");
yystats();
yyterm();
return(NULL);
}
cSeqiAlloc += MIBSEQIACT;
/* put items in list */
for (pT = pSeqiAvail, i = 1; i < MIBSEQIACT; i++, pT++) {
pT->pNext = pT+1;
}
pT->pNext = NULL;
}
/* get sequence item from list */
pSeqi = pSeqiAvail;
pSeqiAvail = pSeqiAvail->pNext;
cSeqiUsed++;
++(pSeq->ut.seq.cSeqi);
/* init fields */
pSeqi->pOid = pOid;
pSeqi->syn = *pSyn;
/* insert at end of list after checking for dups */
for (pOT = NULL, pT = pSeq->ut.seq.pSeqIL; pT != NULL;
pOT = pT, pT = pT->pNext) {
if ((rt = strcmp((pSeqi->pOid)->pszName,
(pT->pOid)->pszName)) == 0) {
/* duplicate name */
yyerror("duplicate name \"%s\" in SEQUENCE",
(pSeqi->pOid)->pszName);
yyterm();
return(NULL);
}
}
if (pOT == NULL) {
/* insert at beginning of list */
pSeq->ut.seq.pSeqIL = pSeqi;
} else {
/* insert at end of list */
pOT->pNext = pSeqi;
}
pSeqi->pNext = pT;
return(pSeqi);
} /* newSEQI */
#endif
/** addSEQitem - add item to sequence
*
* NOTE: can not determine if item is the proper type
* at this point in time.
* MUST check later!!
*
* call with:
* pSeq - sequence
* pNa - item
* pSyn - syntax of item
* pMod - current module
*
* returns:
* TRUE - no errors
* FALSE - an error
*/
BOOL
#ifdef __STDC__
addSEQitem(MIBSYM *pSeq, STRTAB *pNa, MIBSYN *pSyn, MIBSYM *pMod)
#else
addSEQitem(pSeq, pNa, pSyn, pMod)
MIBSYM *pSeq;
STRTAB *pNa;
MIBSYN *pSyn;
MIBSYM *pMod;
#endif /* __STDC__ */
{
MIBSYM *pSym;
MIBSYM *pOid;
MIBSEQI *pSeqi;
/* check if item already defined */
pSym = pNa->pSym;
if ((pSym != NULL) && (pSym->pMod == pMod)) {
/* item already defined */
/* check if import */
if (pSym->usType == MIBSYMimp) {
pSym->ut.imp.cUse++;
pSym = pSym->ut.imp.pImpSym;
}
/* check if OID type (ignore real checks) */
if ((pSym->usType & MIBSYMmask) != MIBSYMoid) {
yyerror("\"%s\" is not valid type for sequence member",
pSym->pszName);
yyterm();
return(FALSE);
}
pOid = pSym;
} else {
/* item not defined */
/* allocate new symbol */
pOid = newOID(pNa, pMod);
}
/* allocate new sequence item */
pSeqi = newSEQI(pSeq, pOid, pSyn);
return(TRUE);
} /* addSEQitem */
/** addOTname - add snmp object (start definition)
*
* call with:
* pNa - object name
* pMod - containing module
*
* returns:
* ptr to object or NULL if error
*/
MIBSYM *
#ifdef __STDC__
addOTname(STRTAB *pNa, MIBSYM *pMod)
#else
addOTname(pNa, pMod)
STRTAB *pNa;
MIBSYM *pMod;
#endif /* __STDC__ */
{
MIBSYM *pSym;
MIBSYM *pOid;
/* check if item already defined */
pSym = pNa->pSym;
if ((pSym != NULL) && (pSym->pMod == pMod)) {
/* item already defined */
/* check if forward reference */
if (pSym->usType != (MIBSYMFR|MIBSYMoid)) {
yyerror("\"%s\" already defined in current module",
pSym->pszName);
#ifdef OLD
yyterm();
#endif
return(NULL);
}
pOid = pSym;
} else {
/* item not defined */
/* allocate new symbol */
pOid = newOID(pNa, pMod);
}
/* mark as OID, forward reference, and being defined */
pOid->usType |= MIBSYMoid | MIBSYMFR | MIBSYMDF;
return(pOid);
} /* addOTname */
/** addENUMitem - add enumerated item to syntax
*
* call with:
* pNa - name of value
* ulValue - value
* pSyn - syntax to add item
*
* returns:
* TRUE - no error
* FALSE - an error
*/
BOOL addENUMitem(STRTAB *pNa, ULONG ulVal, MIBSYN *pSyn)
{
MIBENUM *pT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -