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.

261 lines
6.9 KiB

  1. /*****************************************************************************\
  2. Author: Corey Morgan (coreym)
  3. Copyright (c) 1998-2000 Microsoft Corporation
  4. \*****************************************************************************/
  5. #ifndef _VARG_H_012599_
  6. #define _VARG_H_012599_
  7. #define MAXSTR 1025
  8. //Class CToken
  9. //It represents a Single Token.
  10. class CToken
  11. {
  12. public:
  13. CToken();
  14. ~CToken();
  15. DWORD Init(LPWSTR psz, BOOL bQuote);
  16. LPWSTR GetToken();
  17. BOOL IsSwitch();
  18. BOOL IsSlash();
  19. private:
  20. LPWSTR m_pszToken;
  21. BOOL m_bInitQuote;
  22. };
  23. typedef CToken * LPTOKEN;
  24. #define ARG_TYPE_INT 0
  25. #define ARG_TYPE_BOOL 1
  26. #define ARG_TYPE_STR 2
  27. #define ARG_TYPE_HELP 3
  28. #define ARG_TYPE_DEBUG 4
  29. #define ARG_TYPE_MSZ 5
  30. #define ARG_TYPE_INTSTR 6
  31. #define ARG_TYPE_PASSWORD 7 //Password is input at commandline as string. It is
  32. //stored in ARG_RECORD in vValue member where vValue
  33. //is a pointer to encrypted data_blob
  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 //For parameters like target name
  39. #define ARG_FLAG_HIDDEN 0x00000010
  40. #define ARG_FLAG_VERB 0x00000020
  41. #define ARG_FLAG_STDIN 0x00000040 //This must be Required. If not sepcified read from standard input
  42. #define ARG_FLAG_ATLEASTONE 0x00000080 //If this flag is specified on one or more switch, at
  43. //least one of those switches must be defined
  44. #define ARG_FLAG_DN 0x00000100 //JonN 4/26/01 256583 add ADSI escaping
  45. #define ARG_TERMINATOR 0,NULL,0,NULL,ARG_TYPE_LAST,0,(CMD_TYPE)0,FALSE,NULL
  46. #define ID_ARG2_NULL (LONG)-1
  47. #define CMD_TYPE void*
  48. typedef struct _ARG_RECORD
  49. {
  50. LONG idArg1;
  51. LPTSTR strArg1;
  52. LONG idArg2;
  53. LPTSTR strArg2;
  54. int fType;
  55. DWORD fFlag;
  56. union{
  57. void* vValue;
  58. LPTSTR strValue;
  59. int nValue;
  60. BOOL bValue;
  61. DATA_BLOB encryptedDataBlob;
  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. The value read from STDIN appears to be
  122. in UNICODE, but the -uc and -uci switches
  123. were not defined.
  124. */
  125. #define PARSE_ERROR_UNICODE_NOTDEFINED 9
  126. /*
  127. The value read from STDIN appears to be
  128. in ANSI, but the -uc and/or -uci switches
  129. were defined.
  130. */
  131. #define PARSE_ERROR_UNICODE_DEFINED 10
  132. // 603157-2002/04/23-JonN
  133. /*
  134. A parse error occurred which has already
  135. been reported.
  136. */
  137. #define PARSE_ERROR_ALREADY_DISPLAYED 11
  138. //Parse Errors for when ERROR_SOURCE is VLDFN
  139. /*
  140. Use this error code when Validation Function has handled the error and
  141. Shown appropriate error message.
  142. */
  143. #define VLDFN_ERROR_NO_ERROR 1
  144. //Error is returned by Parser in PARSE_ERROR structure
  145. //ErrorSource: Source of Error. Parser or Validation Function
  146. //Error This is the actual error code. Its value depend on ErrorSource value.
  147. // if( ErrorSource == PARSE_ERROR )
  148. // possible values are ERROR_FROM_PARSER ERROR_FROM_VLDFN
  149. // if( ErrorSource == ERROR_FROM_VLDFN )
  150. // depends on the function
  151. // ArgRecIndex is appropriate index in the ARG_RECORD, if applicable else -1
  152. // ArgvIndex is approproate index in the agrv array, if applicable else -1
  153. typedef struct _PARSE_ERROR
  154. {
  155. INT ErrorSource;
  156. DWORD Error;
  157. INT ArgRecIndex;
  158. INT ArgvIndex;
  159. BOOL MessageShown;
  160. } PARSE_ERROR, *PPARSE_ERROR;
  161. extern BOOL g_fUnicodeInput;
  162. extern BOOL g_fUnicodeOutput;
  163. BOOL ParseCmd(IN LPCTSTR pszCommandName,
  164. IN ARG_RECORD *Commands,
  165. IN int argc,
  166. IN CToken *pToken,
  167. IN UINT* pUsageMessageTable,
  168. OUT PPARSE_ERROR pError,
  169. IN BOOL bValidate = TRUE);
  170. void FreeCmd(ARG_RECORD *Commands);
  171. DWORD GetCommandInput(OUT int *pargc, //Number of Tokens
  172. OUT LPTOKEN *ppToken); //Array of CToken
  173. DWORD Tokenize(IN LPWSTR pBuf,
  174. IN LONG BufLen,
  175. IN LPWSTR pszDelimiters,
  176. OUT CToken **ppToken,
  177. OUT int *argc);
  178. LONG GetToken(IN LPWSTR pBuf,
  179. IN LONG BufLen,
  180. IN LPWSTR pszDelimiters,
  181. OUT BOOL *bQuote,
  182. OUT LPWSTR *ppToken);
  183. BOOL DisplayParseError(IN LPCTSTR pszCommandName,
  184. IN PPARSE_ERROR pError,
  185. IN ARG_RECORD *Commands,
  186. IN CToken *pToken);
  187. //Function to display string to STDERR
  188. VOID DisplayError(IN LPWSTR pszError);
  189. //Function to display string to STDOUT, appending newline
  190. VOID DisplayOutput(IN LPWSTR pszOut);
  191. //Function to display string to STDOUT, without newline
  192. VOID DisplayOutputNoNewline(IN LPWSTR pszOut);
  193. //Function to display Usage Message .
  194. VOID DisplayMessage(UINT *pUsageTable,
  195. BOOL bUseStdOut = FALSE);
  196. #define USAGE_END 0xffffffff
  197. // Copied from JSchwart on 2/19/2001
  198. void
  199. MyWriteConsole(
  200. HANDLE fp,
  201. LPWSTR lpBuffer,
  202. DWORD cchBuffer
  203. );
  204. void
  205. WriteStandardOut(PCWSTR pszFormat, ...);
  206. void
  207. WriteStandardError(PCWSTR pszFormat, ...);
  208. BOOL
  209. IsTokenHelpSwitch(LPTOKEN pToken);
  210. void
  211. DisplayUsageHelp( LPCWSTR pszCommand);
  212. #endif //_VARG_H_012599_