Leaked source code of windows server 2003
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.

221 lines
6.3 KiB

  1. /*****************************************************************************\
  2. Author: Corey Morgan (coreym)
  3. Copyright (c) 1998-2001 Microsoft Corporation
  4. \*****************************************************************************/
  5. #ifndef _VARG_H_012599_
  6. #define _VARG_H_012599_
  7. #define MAXSTR 1025
  8. #define NETDOM_MAX_CMDLINE 2048
  9. //Class CToken
  10. //It represents a Single Token.
  11. class CToken
  12. {
  13. public:
  14. CToken(PCWSTR psz, BOOL bQuote);
  15. CToken();
  16. ~CToken();
  17. BOOL Init(PCWSTR psz, BOOL bQuote);
  18. PWSTR GetToken() const;
  19. BOOL IsSwitch() const;
  20. BOOL IsSlash() const;
  21. private:
  22. LPWSTR m_pszToken;
  23. BOOL m_bInitQuote;
  24. };
  25. typedef CToken * LPTOKEN;
  26. #define ARG_TYPE_INT 0
  27. #define ARG_TYPE_BOOL 1
  28. #define ARG_TYPE_STR 2
  29. #define ARG_TYPE_HELP 3
  30. #define ARG_TYPE_DEBUG 4
  31. #define ARG_TYPE_MSZ 5
  32. #define ARG_TYPE_INTSTR 6
  33. #define ARG_TYPE_VERB 7 // Verbs are not preceeded by a switch character
  34. #define ARG_TYPE_LAST 8
  35. #define ARG_FLAG_OPTIONAL 0x00000001
  36. #define ARG_FLAG_REQUIRED 0x00000002
  37. #define ARG_FLAG_DEFAULTABLE 0x00000004
  38. //#define ARG_FLAG_NOFLAG 0x00000008 // unused.
  39. #define ARG_FLAG_HIDDEN 0x00000010
  40. #define ARG_FLAG_VERB 0x00000020 // For operation and sub-operation params that do not have a switch char.
  41. // Verbs are two state: present or not present; they do not have qualifers such as a user-entered string.
  42. #define ARG_FLAG_STDIN 0x00000040 // This must be Required. If not sepcified read from standard input
  43. #define ARG_FLAG_ATLEASTONE 0x00000080 // If this flag is specified on one or more switch, at
  44. // least one of those switches must be defined
  45. #define ARG_FLAG_OBJECT 0x00000100 // The object arg is the 3rd param for most commands.
  46. #define ARG_TERMINATOR 0,NULL,0,NULL,ARG_TYPE_LAST,0,(CMD_TYPE)0,FALSE,NULL
  47. #define ID_ARG2_NULL (LONG)-1
  48. #define CMD_TYPE void*
  49. typedef struct _ARG_RECORD
  50. {
  51. LONG idArg1;
  52. LPTSTR strArg1;
  53. LONG idArg2;
  54. LPTSTR strArg2;
  55. int fType;
  56. DWORD fFlag;
  57. union{
  58. void* vValue;
  59. LPTSTR strValue;
  60. int nValue;
  61. BOOL bValue;
  62. };
  63. BOOL bDefined;
  64. DWORD (*fntValidation)(PVOID pArg);
  65. } ARG_RECORD, *PARG_RECORD;
  66. //Error Source
  67. #define ERROR_FROM_PARSER 1
  68. #define ERROR_FROM_VLDFN 2
  69. #define ERROR_WIN32_ERROR 3
  70. //Parse Errors for when ERROR_SOURCE is ERROR_FROM_PARSER
  71. /*
  72. SWITCH value is incorrect.
  73. ArgRecIndex is index of record.
  74. ArgvIndex is index of token.
  75. */
  76. #define PARSE_ERROR_SWITCH_VALUE 1
  77. /*No Value is given for a swich when one is expected.
  78. ArgRecIndex is index of record.
  79. ArgvIndex is -1.
  80. */
  81. #define PARSE_ERROR_SWICH_NO_VALUE 2
  82. /*
  83. Invalid Input
  84. ArgRecIndex is -1,
  85. ArgvIndex is index of token.
  86. */
  87. #define PARSE_ERROR_UNKNOWN_INPUT_PARAMETER 3
  88. /*
  89. Required switch is not defined.
  90. ArgRecIndex is index of record.
  91. ArgvIndex is -1.
  92. */
  93. #define PARSE_ERROR_SWITCH_NOTDEFINED 4
  94. /*
  95. Switch or Parameter is defined twice.
  96. ArgRecIndex is index of record.
  97. ArgvIndex is -1
  98. */
  99. #define PARSE_ERROR_MULTIPLE_DEF 5
  100. /*
  101. Error Reading From STDIN.
  102. ArgRecIndex is -1.
  103. ArgvIndex is -1.
  104. */
  105. #define ERROR_READING_FROM_STDIN 6
  106. /*
  107. Parser Encountered Help Switch
  108. ArgRecIndex is index of record.
  109. ArgvIndex is -1
  110. */
  111. #define PARSE_ERROR_HELP_SWITCH 7
  112. /*
  113. The ARG_FLAG_ATLEASTONE flag was
  114. defined on one or more switch yet
  115. none of these switches were defined
  116. ArgRecIndex is -1
  117. ArgvIndex is -1
  118. */
  119. #define PARSE_ERROR_ATLEASTONE_NOTDEFINED 8
  120. /*
  121. Parser Encountered Expert Help Switch
  122. ArgRecIndex is index of record.
  123. ArgvIndex is -1
  124. */
  125. #define PARSE_ERROR_EXPERT_HELP_SWITCH 9
  126. //Parse Errors for when ERROR_SOURCE is VLDFN
  127. /*
  128. Use this error code when Validation Function has handled the error and
  129. Shown appropriate error message.
  130. */
  131. #define VLDFN_ERROR_NO_ERROR 1
  132. //Error is returned by Parser in PARSE_ERROR structure
  133. //ErrorSource: Source of Error. Parser or Validation Function
  134. //Error This is the actual error code. Its value depend on ErrorSource value.
  135. // if( ErrorSource == PARSE_ERROR )
  136. // possible values are ERROR_FROM_PARSER ERROR_FROM_VLDFN
  137. // if( ErrorSource == ERROR_FROM_VLDFN )
  138. // depends on the function
  139. // ArgRecIndex is appropriate index in the ARG_RECORD, if applicable else -1
  140. // ArgvIndex is approproate index in the agrv array, if applicable else -1
  141. typedef struct _PARSE_ERROR
  142. {
  143. INT ErrorSource;
  144. DWORD Error;
  145. INT ArgRecIndex;
  146. INT ArgvIndex;
  147. } PARSE_ERROR, *PPARSE_ERROR;
  148. BOOL ParseCmd(IN ARG_RECORD *Commands,
  149. IN int argc,
  150. IN CToken *pToken,
  151. IN bool fSkipObject,
  152. OUT PPARSE_ERROR pError,
  153. IN BOOL bValidate = FALSE);
  154. void FreeCmd(ARG_RECORD *Commands);
  155. DWORD GetCommandInput(OUT int *pargc, //Number of Tokens
  156. OUT LPTOKEN *ppToken); //Array of CToken
  157. BOOL LoadCmd(ARG_RECORD *Commands);
  158. DWORD Tokenize(IN LPWSTR pBuf,
  159. IN LONG BufLen,
  160. IN LPWSTR pszDelimiters,
  161. OUT CToken **ppToken,
  162. OUT int *argc,
  163. IN LPWSTR pszAltDelimiters = NULL);
  164. LONG GetToken(IN LPWSTR pBuf,
  165. IN LONG BufLen,
  166. IN LPWSTR pszDelimiters,
  167. OUT BOOL *bQuote,
  168. OUT LPWSTR *ppToken);
  169. // Checks if the Standard Handle has been redirected
  170. BOOL FileIsConsole( HANDLE fp );
  171. //Function to display string to STDOUT, appending newline
  172. VOID DisplayOutput(IN LPWSTR pszOut);
  173. //Function to display string to STDOUT, without newline
  174. VOID DisplayOutputNoNewline(IN LPWSTR pszOut);
  175. // Reads user input, caller must do a LocalFree on ppBuffer
  176. LONG ReadFromIn(PWSTR *ppBuffer);
  177. // Copied from JSchwart on 2/19/2001
  178. void
  179. MyWriteConsole(
  180. HANDLE fp,
  181. LPWSTR lpBuffer,
  182. DWORD cchBuffer
  183. );
  184. void
  185. WriteStandardOut(PCWSTR pszFormat, ...);
  186. #endif //_VARG_H_012599_