📄 smot.c
字号:
/* symbol not known */
/* allocate new sequence */
pSym = newSEQ(pNa, pMod);
} else {
/* symbol in current module */
/* check for import */
if (pSym->usType == MIBSYMimp) {
/* an import */
pSym->ut.imp.cUse++;
pSym = pSym->ut.imp.pImpSym;
}
/* check symbol type */
if ((pSym->usType & MIBSYMmask) != MIBSYMseq) {
/* symbol is some other type */
yyerror("Object \"%s\" should be the name of a sequence",
pSym->pszName);
#ifdef OLD
yyterm();
return(FALSE);
#endif
pSyn->usSyntax = MIBSYNbad; /* change syntax to bad */
return(FALSE);
}
}
/* everyting OK */
pSyn->usi.pSeq = pSym;
pSym->ut.seq.cUse++;
return(TRUE);
}
/* NOTE: semantics for size/range must be checked later */
switch(usSizeRange) {
case MIBSRno: /* none */
break;
case MIBSRfs: /* fixed size */
case MIBSRvs: /* variable size */
pSyn->usr.usSize[0] = (USHORT)ulFirst;
pSyn->usr.usSize[1] = (USHORT)ulSecond;
if (ulFirst > ulSecond) {
yyerror("Invalid size values specifed, smallest greater than largest");
fOk = FALSE;
pSyn->usSizeRange = MIBSRno; /* set to no size/range */
}
if ((ulFirst == 0L) && (ulSecond == 0L)) {
yyerror("Invalid size values specifed, both sizes cannot tbe zero");
fOk = FALSE;
pSyn->usSizeRange = MIBSRno; /* set to no size/range */
}
break;
case MIBSRpp: /* positive to positive */
case MIBSRnn: /* negative to negative */
case MIBSRnp: /* negative to positive */
pSyn->usr.ulRange[0] = ulFirst;
pSyn->usr.ulRange[1] = ulSecond;
if (((usSizeRange == MIBSRpp) &&
(ulFirst > ulSecond)) ||
((usSizeRange == MIBSRnn) &&
(ulFirst < ulSecond))) {
yyerror("Invalid range values specified, smallest greater than largest");
fOk = FALSE;
pSyn->usSizeRange = MIBSRno; /* set to no size/range */
}
break;
default:
yyerror("checkSyntax: invalid size/range type of %d",
usSizeRange);
yyterm();
pSyn->usSizeRange = MIBSRno; /* set to no size/range */
return(FALSE);
}
/* check for textual convention (or sequence) */
if (usSyntax == MIBSYNtc) {
/* check if name known in current module */
pSym = pNa->pSym;
if ((pSym == NULL) || (pSym->pMod != pMod)) {
/* symbol not known */
/* textual conventions must be defined, so must be sequence */
/* But, a properly written MIB will have seq already referenced */
yyerror("Syntax \"%s\" not known in current module",
pNa->pszVal);
pSyn->usSyntax = MIBSYNbad; /* change syntax to BAD */
pSyn->usSizeRange = MIBSRno; /* change to no size/Range */
#ifdef OLD
yyterm();
#endif
return(FALSE);
}
/* symbol in current module */
/* check for import */
if (pSym->usType == MIBSYMimp) {
pSym->ut.imp.cUse++;
pSym = pSym->ut.imp.pImpSym;
}
/* check symbol type */
if ((pSym->usType & MIBSYMmask) == MIBSYMseq) {
/* sequence */
/* check for size/range */
if (usSizeRange != MIBSRno) {
yyerror("size/range must not be specified with sequence \"%s\"",
pSym->pszName);
#ifdef OLD
yyterm();
return(FALSE);
#endif
fOk = FALSE;
pSyn->usSizeRange = MIBSRno; /* change to no size/range */
}
pSyn->usSyntax = MIBSYNseq; /* change syntax to sequence */
pSyn->usi.pSeq = pSym;
pSym->ut.seq.cUse++;
return(fOk);
} else if (pSym->usType != MIBSYMtc) {
/* symbol is some other type */
yyerror("Object \"%s\" specified where a syntax should be",
pSym->pszName);
#ifdef OLD
yyterm();
#endif
pSyn->usSyntax = MIBSYNbad; /* change syntax to bad */
pSyn->usSizeRange = MIBSRno; /* change to no size/Range */
return(FALSE);
}
/* textual convention */
pSyn->usi.pTC = pSym;
pSym->ut.tc.cUse++;
/* check for compatible size/range */
if ((pSyn->usSizeRange != MIBSRno) &&
(pSym->ut.tc.rsyn.usSizeRange != MIBSRno)) {
yyerror("size/range can not be specified since \"%s\" already has this specified",
pSym->pszName);
pSyn->usSizeRange = MIBSRno; /* change to no size/range */
}
/* get size/range */
if (pSyn->usSizeRange == MIBSRno)
usSizeRange = pSym->ut.tc.rsyn.usSizeRange;
/* continue check */
usSyntax = pSym->ut.tc.rsyn.usSyntax;
}
/* check that size/range compatible with type */
if ((usSizeRange != MIBSRno) &&
(usSizeRange != MIBSRbad)) {
if (usSyntax == MIBSYNoctstr) {
/* octet string - only size valid */
if ((usSizeRange != MIBSRfs) &&
(usSizeRange != MIBSRvs)) {
yyerror("An OCTET STRING must have SIZE, not range specified");
pSyn->usSizeRange = MIBSRno; /* set to none */
fOk = FALSE;
}
} else if (usSyntax == MIBSYNint) {
/* integer - only range valid */
if ((usSizeRange != MIBSRpp) &&
(usSizeRange != MIBSRnp) &&
(usSizeRange != MIBSRnn)) {
yyerror("An INTEGER must have range, not SIZE specified");
pSyn->usSizeRange = MIBSRno; /* set to none */
fOk = FALSE;
}
} else if (usSyntax == MIBSYNopaque) {
/* an OPAQUE - only size valid */
if ((usSizeRange != MIBSRfs) &&
(usSizeRange != MIBSRvs)) {
yyerror("An Opaque must have SIZE, not range specified");
pSyn->usSizeRange = MIBSRno; /* set to none */
fOk = FALSE;
}
} else {
/* all other types, size/range not allowed */
yyerror("Given syntax type may not have SIZE or range specified");
pSyn->usSizeRange = MIBSRno; /* set to none */
fOk = FALSE;
}
}
return(fOk);
} /* checkSyntax */
/** bstrToVal - convert binary string to integer
*
* NOTE: this is a special conversion for size/ranges
*
* call with:
* pVal - value
*
* returns:
* value
*/
ULONG
#ifdef __STDC__
bstrToVal(STRTAB *pVal)
#else
bstrToVal(pVal)
STRTAB *pVal;
#endif /* __STDC__ */
{
USHORT i;
ULONG ul;
PSZ psz;
if (*(pVal->pszVal) == 0) {
yyerror("size/range should not be expressed as zero length binary string");
return(0L);
}
for (ul = 0L, psz = pVal->pszVal; *psz == '0'; psz++) {
/* skip leading zeros */
}
for (i = 0; *psz != 0; psz++) {
if (i++ == 32) {
yyerror("Binary value for size/range is too long");
return(0L);
}
ul = (ul << 1) + ((*psz == '1') ? 1L : 0L);
}
#ifdef OLD
yywarning("size/range should not be expressed as binary string");
#endif
return(ul);
} /* bstrToVal */
/** hstrToVal - convert hex string to integer
*
* NOTE: this is a special conversion for size/ranges
*
* call with:
* pVal - value
*
* returns:
* value
*/
ULONG
#ifdef __STDC__
hstrToVal(STRTAB *pVal)
#else
hstrToVal(pVal)
STRTAB *pVal;
#endif /* __STDC__ */
{
USHORT i;
ULONG ul;
PSZ psz;
USHORT us;
if (*(pVal->pszVal) == 0) {
yyerror("size/range should not be expressed as zero length hex string");
return(0L);
}
for (ul = 0L, psz = pVal->pszVal; *psz == '0'; psz++) {
/* skip leading zeros */
}
for (i = 0; *psz != 0; psz++) {
if (i++ == 8) {
yyerror("Hex value for size/range is too long");
return(0L);
}
if ((*psz >= '0') && (*psz <= '9')) {
us = *psz - '0';
} else if ((*psz >= 'A') && (*psz <= 'F')) {
us = *psz - 'A' + 10;
} else {
us = *psz - 'a' + 10;
}
ul = (ul << 4) + (ULONG)us;
}
#ifdef OLD
yywarning("size/range should not be expressed as hex string");
#endif
return(ul);
} /* bstrToVal */
/* end of file: SMOT.C */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -