📄 smic.c
字号:
USHORT usOpt;
PSZ pszArg;
BOOL fSameFile = FALSE;
/* check out the options */
for (i = 1; i < argc; i++) {
pszArg = argv[i];
if ((pszArg[0] != '-') && (pszArg[0] != '/')) {
break;
}
if (strlen(pszArg) != 2) {
fprintf(fhMsg, "Illegal option: \"%s\"\n",
pszArg);
return(FALSE);
}
usOpt = toupper(pszArg[1]);
switch(usOpt) {
case '0': /* set the message file to be the same
as the output file */
fSameFile = TRUE;
break;
case '1': /* print version and copyright */
prVer();
prCpyrt();
exit(0);
break;
case '2': /* print version */
prVer();
break;
case '3': /* allow INDEX clause on leaf objects */
fAllowIndx = TRUE;
break;
case '4': /* allow non-std access on leaf objects */
fAllowAccess = TRUE;
break;
case '5': /* allow "optional" status */
fAllowOpt = TRUE;
break;
case '6': /* no check that table, row, seq have related names */
fNoCheckTab = TRUE;
break;
case '7': /* check that all index items for a row are in seq */
fCheckIndxSeq = TRUE;
break;
case '8': /* output in mosy format */
fDumpMosy = TRUE;
break;
case '9': /* output in Extended mosy format */
fDumpExtMosy = TRUE;
break;
case 'A': /* dump alias names */
fDebugAL = TRUE;
break;
case 'B': /* strong check size/range of index items */
fCheckISR = TRUE;
break;
case 'C': /* check size/range */
fCheckSR = TRUE;
break;
case 'D': /* dump all */
fDebugStrTab = TRUE;
fDebugMOD = TRUE;
fDebugOID = TRUE;
fDebugOIDtree = TRUE;
fDebugName = TRUE;
fDebugIMP = TRUE;
fDebugAL = TRUE;
fDebugSMI = TRUE;
fDebugTRAP = TRUE;
fDebugTC = TRUE;
fDebugSEQ = TRUE;
fDebugStats = TRUE;
break;
case 'E': /* no exact syntax match for TCs in seq */
fNoSeqTcErr = TRUE;
break;
case 'F': /* name of output file */
/* check for filename */
if (((i+1) < argc) && (*(argv[i+1]) != '/') &&
(*(argv[i+1]) != '-')) {
/* get filename */
i++;
fhOut = fopen(argv[i], "w");
if (fhOut == NULL) {
fprintf(fhMsg, "Error opening file \"%s\"\n", argv[i]);
return(FALSE);
}
} else {
fprintf(fhMsg, "Name of output file expected\n");
return(FALSE);
}
break;
case 'G': /* no warnings for unused Imports and TCs */
fNoUnUsedWarn = TRUE;
break;
case 'I': /* print include file names */
fPrintIname = TRUE;
break;
case 'J': /* allow DEFVAL for counters and gauges */
fAllowDV = TRUE;
break;
case 'K': /* dump SMI names */
fDebugSMI = TRUE;
break;
case 'L': /* dump OID item names */
fDebugName = TRUE;
break;
case 'M': /* dump module names */
fDebugMOD = TRUE;
break;
case 'N': /* dump OID tree */
fDebugOIDtree = TRUE;
break;
case 'O': /* dump OID table */
fDebugOID = TRUE;
break;
case 'P': /* dump Trap names */
fDebugTRAP = TRUE;
break;
case 'Q': /* dump Sequences */
fDebugSEQ = TRUE;
break;
case 'R': /* check index objs for read-only */
fCheckRoIndx = TRUE;
break;
case 'S': /* dump string table */
fDebugStrTab = TRUE;
break;
case 'T': /* dump IMPORT names */
fDebugIMP = TRUE;
break;
case 'U': /* dump resource usage statistics */
fDebugStats = TRUE;
break;
case 'V': /* dump Textual conventions */
fDebugTC = TRUE;
break;
case 'W': /* strong check of sequence items syntax */
fCheckSEQ = TRUE;
break;
case 'X': /* suppress strings in scanner */
fNoStr = TRUE;
break;
case 'Z': /* output in intermediate format */
fDumpInterm = TRUE;
break;
default:
fprintf(fhMsg, "Unknown option: \"%s\"\n",
pszArg);
return(FALSE);
}
}
/* check for valid number of parameters */
if (i >= argc) {
fprintf(fhMsg, "Need file name\n");
return(FALSE);
}
/* open filename and check for errors */
pszInFile = argv[i];
pszBaseFile = pszInFile;
fhIn = fopen(pszInFile, "rb");
if (fhIn == NULL) {
fprintf(fhMsg, "Error opening file \"%s\"\n", pszInFile);
return(FALSE);
}
/* check if message file should be mapped to output file */
if (fSameFile)
fhMsg = fhOut;
/* everything OK */
return(TRUE);
} /* GetArgs */
#if 0
int main(void)
{
int err = 0;
int err_count = 0;
err = SMICCompiler("mibi", "ExtMosy-N.out", "Errors.out");
return err;
}
#endif
int SMICCompiler(char *theInFileName, char *theOutFileName, char *theErrFileName)
{
int err;
int i;
err = 0;
/* dump OID tree */
fDebugOIDtree = TRUE;
/* output in Extended mosy format */
fDumpExtMosy = TRUE;
/* allow OPTIONAL status */
fAllowOpt = TRUE;
/* initialize file pointers */
fhIn = NULL;
fhOut = NULL;
fhMsg = NULL;
#if 0
/* get ptr to environment variable for include files */
pszSmicIncl = getenv(SMICINCL);
#endif
/* initialize memory allocated linked list */
AllocMemInit();
/* open all files */
pszInFile = theInFileName;
pszBaseFile = pszInFile;
if ((fhIn = fopen(pszInFile, "rb")) == NULL)
{
err = 10;
}
else if ((fhOut = fopen(theOutFileName, "wb")) == NULL)
{
err = 2;
}
else if ((fhMsg = fopen(theErrFileName, "wb")) == NULL)
{
err = 3;
}
/* init scanner */
else if (!yylexinit())
{
fprintf(fhMsg, "Scanner Initialization error\n");
err = 4;
}
else
{
/* init root of OID tree */
initOIDroot();
/* parse the MIB file */
if (yyparse() != 0)
{
fprintf(fhMsg, "Unsuccessful parsing\n");
err = 5;
}
else
{
if (cErr)
{
err = 6;
fprintf(fhMsg, "\n*** %s parsed with %u error%s and %u warning%s\n",
pszInFile, cErr, (cErr != 1) ? "s" : "",
cWarn, (cWarn != 1) ? "s" : "");
}
else
{
fprintf(fhMsg, "%s parsed successfully\n", pszInFile);
dumpOIDtree();
dumpExtMosy();
}
}
}
/* close all files */
if (fhIn != NULL)
{
fclose(fhIn);
}
if (fhOut != NULL)
{
fclose(fhOut);
}
/* free allocated resources */
for (i = 0; i < cStrSpace; i++)
{
free(apbStrSpace[i]);
}
AllocMemDestroy();
if (fhMsg != NULL)
{
fclose(fhMsg);
}
return err;
} /* end of SMICCompiler */
/* end of file: SMIC.C */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -