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.

140 lines
4.8 KiB

  1. /******************************************************************************
  2. * FILE: toolmain.h
  3. *
  4. * This is a header for the code that provides a standard main and argument
  5. * parsing for command line tools. To use this, you need to copy toolmain.c
  6. * from \hwx\common\template and edit it to specify the parameters needed by
  7. * your application. You will also need to call your main function ToolMain
  8. * (as declared below) so that the standard code can call it.
  9. *
  10. * NOTE: It may be necessary to support additional switch and argument types.
  11. * To do this, you will need to edit this file and toolprs.c. See comments
  12. * with "EXTEND:" in them for notes on where to do this.
  13. ******************************************************************************/
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Stuff tool code needs to provide.
  19. ////////////////////////////////////////////////////////////////////////////////
  20. // Decleration for the main processing the tool does.
  21. extern BOOL ToolMain(void);
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // Declerations relating to command line switches.
  24. ////////////////////////////////////////////////////////////////////////////////
  25. // Types of switches supported.
  26. // EXTEND: You can add more switch types here.
  27. typedef enum tagSWITCH_TYPES {
  28. SWITCH_HELP, // Print out help message and exit.
  29. SWITCH_BOOL, // Boolean, set to TRUE if specified.
  30. SWITCH_STRING, // A string.
  31. SWITCH_UNSIGNED, // An unsigned integer value.
  32. SWITCH_INT, // An integer value,
  33. SWITCH_DOUBLE, // A floating point value stored in a double.
  34. } SWITCH_TYPES;
  35. // Structure to hold spec for a switch.
  36. typedef struct tagSWITCH_SPEC {
  37. wchar_t wchSwitch; // Switch character
  38. SWITCH_TYPES switchType; // What type is it.
  39. void *pSwitch; // Where to put results.
  40. } SWITCH_SPEC;
  41. ////////////////////////////////////////////////////////////////////////////////
  42. // Declerations relating to command line arguments.
  43. ////////////////////////////////////////////////////////////////////////////////
  44. // Magic names to use for standard IO files.
  45. #define ARG_STDIN L"<stdin>"
  46. #define ARG_STDOUT L"<stdout>"
  47. #define ARG_STDERR L"<stderr>"
  48. // Types of arguments supported.
  49. // EXTEND: You can add more argument types here.
  50. typedef enum tagARG_TYPES {
  51. ARG_STRING, // Any old string
  52. ARG_FILE, // File to open with specified mode.
  53. ARG_FILE_UTIL, // File to open with UtilOpen
  54. ARG_UNSIGNED, // An unsigned integer value.
  55. ARG_DOUBLE, // A floating point value stored in a double.
  56. } ARG_TYPES;
  57. // Struct to hold spec for an argument.
  58. typedef struct tagARG_SPEC {
  59. wchar_t *pName; // Argument name, used in log file.
  60. ARG_TYPES argType; // Type of argument.
  61. wchar_t *pMode; // Mode for file opens.
  62. wchar_t *pDefault; // Optional default value.
  63. wchar_t **ppText; // Where to put text of argument.
  64. void *pValue; // Where to put value (if needed).
  65. } ARG_SPEC;
  66. ////////////////////////////////////////////////////////////////////////////////
  67. // Public interface types and functions.
  68. ////////////////////////////////////////////////////////////////////////////////
  69. // Structure to pull togather all the configuration pieces so that we only
  70. // have to pass one thing to the functions.
  71. typedef struct tagPARSE_INFO {
  72. int cUsageStrings; // Number of usage strings.
  73. wchar_t const * const *ppUsageStrings; // Text for usage message.
  74. int cSwitchSpecs; // Number of switch spec.
  75. SWITCH_SPEC const *pSwitchSpecs; // Switch specifications.
  76. int cArgSpecs; // Number of program arguments.
  77. ARG_SPEC const *pArgSpecs; // Argument specifications.
  78. FILE **ppLogFile; // File to log output too.
  79. wchar_t **ppTreeRoot; // Root of build tree
  80. wchar_t **ppConfigName; // Name of configuration directory
  81. wchar_t **ppLocale; // Locale ID
  82. } PARSE_INFO;
  83. // Actually parses command line.
  84. BOOL ToolMainParseArguments(
  85. PARSE_INFO const *pParseInfo,
  86. int argc,
  87. wchar_t **argv
  88. );
  89. // Load in locale information.
  90. BOOL ToolMainLoadLocale(
  91. PARSE_INFO const *pParseInfo,
  92. LOCRUN_INFO *pLocRunInfo,
  93. LOCTRAIN_INFO *pLocTrainInfo
  94. );
  95. // Load in locale information.
  96. BOOL ToolMainLoadLocaleEx(
  97. PARSE_INFO const *pParseInfo,
  98. LOCRUN_INFO *pLocRunInfo,
  99. LOCTRAIN_INFO *pLocTrainInfo,
  100. wchar_t *pRecognizer
  101. );
  102. // Print out usage message.
  103. void ToolMainUsage(PARSE_INFO const *pParseInfo);
  104. // Log standard header information.
  105. void ToolMainLogHeader(
  106. PARSE_INFO const *pParseInfo,
  107. int argc,
  108. wchar_t **argv
  109. );
  110. // Log standard trailer information
  111. void ToolMainLogTrailer(PARSE_INFO const *pParseInfo);
  112. // Cleanup, close files etc.
  113. BOOL ToolMainCleanup(
  114. PARSE_INFO const *pParseInfo,
  115. LOCRUN_INFO *pLocRunInfo,
  116. LOCTRAIN_INFO *pLocTrainInfo
  117. );
  118. #ifdef __cplusplus
  119. }
  120. #endif