Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. mibcc.cpp
  5. Abstract:
  6. SMI compiler backend for MIB database.
  7. Author:
  8. Florin Teodorescu (florint) 26-Jan-1998
  9. --*/
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // //
  12. // Include files //
  13. // //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include <stdarg.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <assert.h>
  19. #include <io.h>
  20. #include <iostream.h>
  21. #include <fstream.h>
  22. #include <afx.h>
  23. #include <afxtempl.h>
  24. #include <objbase.h>
  25. #include <afxwin.h>
  26. #include <afxole.h>
  27. #include <afxmt.h>
  28. #include <wchar.h>
  29. #include <process.h>
  30. #include <objbase.h>
  31. #include <initguid.h>
  32. #include <bool.hpp>
  33. #include <nString.hpp>
  34. #include <ui.hpp>
  35. #include <symbol.hpp>
  36. #include <type.hpp>
  37. #include <value.hpp>
  38. #include <valueRef.hpp>
  39. #include <typeRef.hpp>
  40. #include <oidValue.hpp>
  41. #include <objType.hpp>
  42. #include <objTypV1.hpp>
  43. #include <objTypV2.hpp>
  44. #include <objId.hpp>
  45. #include <trapType.hpp>
  46. #include <notType.hpp>
  47. #include <group.hpp>
  48. #include <notGroup.hpp>
  49. #include <module.hpp>
  50. #include <sValues.hpp>
  51. #include <lex_yy.hpp>
  52. #include <ytab.hpp>
  53. #include <errorMsg.hpp>
  54. #include <errorCon.hpp>
  55. #include <scanner.hpp>
  56. #include <parser.hpp>
  57. #include <apTree.hpp>
  58. #include <oidTree.hpp>
  59. #include <pTree.hpp>
  60. #include "Debug.hpp"
  61. #include "OidToF.hpp"
  62. #include "Configs.hpp"
  63. // error container defined in debug.cpp
  64. extern SIMCErrorContainer errorContainer;
  65. extern Configs theConfigs;
  66. int InitTree(SIMCParseTree &theTree, int argc, char *argv[])
  67. {
  68. UINT uFileCount;
  69. UINT uFileNameLen;
  70. UINT uErrLevel;
  71. UINT uSMIVersion;
  72. /* process command line options */
  73. --argc;
  74. ++argv;
  75. while ((argc > 0) && ((argv[0][0] == '-') || (argv[0][0] == '/')))
  76. {
  77. switch (argv[0][1])
  78. {
  79. case '?':
  80. case 'h':
  81. case 'H':
  82. cout << "usage: mibcc [-?] [-e] [-l] [-n] [-o] [-t] -[w] [files...]\n";
  83. cout << " MibCC compiles the specified SNMP MIB files.\n";
  84. cout << " -? usage.\n";
  85. cout << " -eX stop after X Errors. (default = 10)\n";
  86. cout << " -l do not print Logo.\n";
  87. cout << " -n print each Node as it is added.\n";
  88. cout << " -o[file] output file name. (no file by default)\n";
  89. cout << " -t print the mib Tree when finished.\n";
  90. cout << " -wX set Warning level.\n";
  91. cout << " 0=silent; 1=errors only; 2=warnings only; 3=both\n";
  92. cout << " (default = 0)\n";
  93. exit (0);
  94. break;
  95. case 'e':
  96. case 'E':
  97. theConfigs.m_nMaxErrors = atoi(argv[0]+2);
  98. break;
  99. case 'l':
  100. case 'L':
  101. theConfigs.m_dwFlags &= ~CFG_PRINT_LOGO;
  102. break;
  103. case 'n':
  104. case 'N':
  105. theConfigs.m_dwFlags |= CFG_PRINT_NODE;
  106. break;
  107. case 'o':
  108. case 'O':
  109. uFileNameLen = strlen(argv[0]+2);
  110. if (uFileNameLen == 0)
  111. {
  112. if (theConfigs.m_pszOutputFilename != NULL)
  113. delete theConfigs.m_pszOutputFilename;
  114. theConfigs.m_pszOutputFilename = NULL;
  115. }
  116. else
  117. {
  118. if (theConfigs.m_pszOutputFilename != NULL)
  119. delete (theConfigs.m_pszOutputFilename);
  120. theConfigs.m_pszOutputFilename = new char[uFileNameLen+1];
  121. _ASSERT(theConfigs.m_pszOutputFilename != NULL, "Memory Allocation error!", NULL);
  122. strcpy(theConfigs.m_pszOutputFilename, argv[0]+2);
  123. }
  124. break;
  125. case 't':
  126. case 'T':
  127. theConfigs.m_dwFlags |= CFG_PRINT_TREE;
  128. break;
  129. case 'w':
  130. case 'W':
  131. uErrLevel = atoi(argv[0]+2);
  132. theConfigs.m_dwFlags |= (uErrLevel == 1 || uErrLevel == 3 ? CFG_VERB_ERROR : 0) |
  133. (uErrLevel == 2 || uErrLevel == 3 ? CFG_VERB_WARNING : 0);
  134. break;
  135. case 'v':
  136. case 'V':
  137. uSMIVersion = atoi(argv[0]+2);
  138. if (uSMIVersion > 2)
  139. cout << "mibcc: wrong value for -v option; ignored\n";
  140. else
  141. theTree.SetSnmpVersion(uSMIVersion);
  142. break;
  143. default:
  144. cout << "mibcc: unrecognized option '" << argv[0] << "'\n";
  145. cout << "mibcc -? for usage\n";
  146. exit (-1);
  147. break;
  148. }
  149. --argc;
  150. ++argv;
  151. }
  152. if (theConfigs.m_dwFlags & CFG_PRINT_LOGO)
  153. {
  154. cout << "Microsoft (R) SNMP MIB Compiler Version 2.00\n";
  155. cout << "Copyright (c) Microsoft Corporation 1998. All rights reserved.\n";
  156. }
  157. for(uFileCount = 0; argc>0; argc--, argv++)
  158. {
  159. struct _finddata_t findData;
  160. intptr_t handle;
  161. // check snmp syntax
  162. handle = _findfirst(argv[0], &findData);
  163. if (handle != -1)
  164. {
  165. do
  166. {
  167. if (theConfigs.m_dwFlags & CFG_PRINT_LOGO)
  168. {
  169. cout << "mibcc: parsing " << findData.name << "\n";
  170. cout.flush();
  171. }
  172. uFileCount++;
  173. _ASSERT(theTree.CheckSyntax(findData.name), "CheckSyntax() failed!", dumpOnBuild);
  174. }while(_findnext(handle, &findData) != -1);
  175. }
  176. }
  177. if (theConfigs.m_dwFlags & CFG_PRINT_LOGO)
  178. {
  179. // do not print anything further if no files processed
  180. if (uFileCount == 0)
  181. theConfigs.m_dwFlags &= ~CFG_PRINT_LOGO;
  182. cout << "mibcc: total files processed: " << uFileCount << "\n";
  183. }
  184. cout.flush();
  185. return 0;
  186. }
  187. ///////////////////////////////////////////////////////////////////////////////
  188. // //
  189. // Entry point //
  190. // //
  191. ///////////////////////////////////////////////////////////////////////////////
  192. INT
  193. __cdecl
  194. main(
  195. IN INT argc,
  196. IN LPSTR argv[]
  197. )
  198. /*++
  199. Routine Description:
  200. Program entry point.
  201. Arguments:
  202. argc - number of command line arguments.
  203. argv - pointer to array of command line arguments.
  204. Return Values:
  205. Returns 0 if successful.
  206. --*/
  207. {
  208. SIMCParseTree theTree(&errorContainer);
  209. SIMCOidTree *pTheOidTree;
  210. OidToFile oidDumpTree;
  211. _ASSERT(InitTree(theTree, argc, argv)==0, "InitTree() failed!", dumpOnBuild);
  212. // resolve symbols
  213. _ASSERT(theTree.Resolve(FALSE), "Resolve() failed!", dumpOnBuild);
  214. // check semantics
  215. _ASSERT(theTree.CheckSemantics(), "CheckSemantics() failed!", dumpOnBuild);
  216. // retrieve the Oid Tree
  217. pTheOidTree = (SIMCOidTree *)theTree.GetOidTree();
  218. _ASSERT(pTheOidTree != NULL, "Oid Tree is NULL", NULL);
  219. oidDumpTree.SetOidTree(pTheOidTree);
  220. _ASSERT(oidDumpTree.SetMibFilename(theConfigs.m_pszOutputFilename)==0, "SetMibFilename failed!", NULL);
  221. _ASSERT(oidDumpTree.MergeBuiltIn()==0, "MergeBuiltIn failed!", NULL);
  222. _ASSERT(oidDumpTree.Scan()==0, "Oid Scan() failed", NULL);
  223. if (theConfigs.m_dwFlags & CFG_PRINT_LOGO)
  224. {
  225. if (theConfigs.m_dwFlags & CFG_PRINT_NODE)
  226. cout << '\n';
  227. if (theConfigs.m_pszOutputFilename != NULL)
  228. cout << "mibcc: writing compiled file '" << theConfigs.m_pszOutputFilename << "'\n";
  229. else
  230. cout << "mibcc: no output file generated" << "\n";
  231. }
  232. return 0;
  233. }