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.

117 lines
4.1 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_TYPES;
  33. // Structure to hold spec for a switch.
  34. typedef struct tagSWITCH_SPEC {
  35. TCHAR wchSwitch; // Switch character
  36. SWITCH_TYPES switchType; // What type is it.
  37. void *pSwitch; // Where to put results.
  38. } SWITCH_SPEC;
  39. ////////////////////////////////////////////////////////////////////////////////
  40. // Declerations relating to command line arguments.
  41. ////////////////////////////////////////////////////////////////////////////////
  42. // Magic names to use for standard IO files.
  43. #define ARG_STDIN _T("<stdin>")
  44. #define ARG_STDOUT _T("<stdout>")
  45. #define ARG_STDERR _T("<stderr>")
  46. // Types of arguments supported.
  47. // EXTEND: You can add more argument types here.
  48. typedef enum tagARG_TYPES {
  49. ARG_STRING, // Any old string
  50. ARG_FILE, // File to open with specified mode.
  51. ARG_FILE_UTIL, // File to open with UtilOpen
  52. ARG_UNSIGNED, // An unsigned integer value.
  53. } ARG_TYPES;
  54. // Struct to hold spec for an argument.
  55. typedef struct tagARG_SPEC {
  56. TCHAR *pName; // Argument name, used in log file.
  57. ARG_TYPES argType; // Type of argument.
  58. TCHAR *pMode; // Mode for file opens.
  59. TCHAR *pDefault; // Optional default value.
  60. TCHAR **ppText; // Where to put text of argument.
  61. void *pValue; // Where to put value (if needed).
  62. } ARG_SPEC;
  63. ////////////////////////////////////////////////////////////////////////////////
  64. // Public interface types and functions.
  65. ////////////////////////////////////////////////////////////////////////////////
  66. // Structure to pull togather all the configuration pieces so that we only
  67. // have to pass one thing to the functions.
  68. typedef struct tagPARSE_INFO {
  69. int cUsageStrings; // Number of usage strings.
  70. TCHAR const * const *ppUsageStrings; // Text for usage message.
  71. int cSwitchSpecs; // Number of switch spec.
  72. SWITCH_SPEC const *pSwitchSpecs; // Switch specifications.
  73. int cArgSpecs; // Number of program arguments.
  74. ARG_SPEC const *pArgSpecs; // Argument specifications.
  75. FILE **ppLogFile; // File to log output too.
  76. } PARSE_INFO;
  77. // Actually parses command line.
  78. BOOL ToolMainParseArguments(
  79. PARSE_INFO const *pParseInfo,
  80. int argc,
  81. TCHAR **argv
  82. );
  83. // Print out usage message.
  84. void ToolMainUsage(PARSE_INFO const *pParseInfo);
  85. // Log standard header information.
  86. void ToolMainLogHeader(
  87. PARSE_INFO const *pParseInfo,
  88. int argc,
  89. TCHAR **argv
  90. );
  91. // Log standard trailer information
  92. void ToolMainLogTrailer(PARSE_INFO const *pParseInfo);
  93. // Cleanup, close files etc.
  94. BOOL ToolMainCleanup(
  95. PARSE_INFO const *pParseInfo
  96. );
  97. #ifdef __cplusplus
  98. }
  99. #endif