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.

271 lines
8.6 KiB

  1. /*****************************************************************************\
  2. Author: Corey Morgan (coreym)
  3. Copyright (c) Microsoft Corporation. All rights reserved.
  4. \*****************************************************************************/
  5. #ifndef _VARG_H_012599_
  6. #define _VARG_H_012599_
  7. #define MAXSTR 1024
  8. #define VARG_HELP_ALL (-1)
  9. #define VARG_TYPE_INT 0
  10. #define VARG_TYPE_BOOL 1
  11. #define VARG_TYPE_STR 2
  12. #define VARG_TYPE_HELP 3
  13. #define VARG_TYPE_DEBUG 4
  14. #define VARG_TYPE_MSZ 5
  15. #define VARG_TYPE_LAST 6
  16. #define VARG_TYPE_INI 7
  17. #define VARG_TYPE_TIME 8
  18. #define VARG_TYPE_DATE 9
  19. #define VARG_FLAG_OPTIONAL 0x00000001
  20. #define VARG_FLAG_REQUIRED 0x00000002
  21. #define VARG_FLAG_DEFAULTABLE 0x00000004
  22. #define VARG_FLAG_NOFLAG 0x00000008
  23. #define VARG_FLAG_HIDDEN 0x00000010
  24. #define VARG_FLAG_VERB 0x00000020
  25. #define VARG_FLAG_EXPANDFILES 0x00000040
  26. #define VARG_FLAG_EXHELP 0x00000080
  27. #define VARG_FLAG_DARKEN 0x00000100
  28. #define VARG_FLAG_FLATHELP 0x00000200
  29. #define VARG_FLAG_CHOMP 0x00000400
  30. #define VARG_FLAG_LITERAL 0x00000800
  31. #define VARG_FLAG_ARG_DEFAULT 0x00001000
  32. #define VARG_FLAG_ARG_FILENAME 0x00002000
  33. #define VARG_FLAG_ARG_DATE 0x00004000
  34. #define VARG_FLAG_ARG_TIME 0x00008000
  35. #define VARG_FLAG_NEGATE 0x00010000
  36. #define VARG_FLAG_RCDEFAULT 0x00020000
  37. #define VARG_FLAG_ADVERB 0x00100000
  38. #define VARG_FLAG_OPT_ADV 0x00200000
  39. #define VARG_FLAG_REQ_ADV 0x00400000
  40. #define VARG_FLAG_DODEFAULT 0x01000000
  41. #define VARG_FLAG_BADSYNTAX 0x02000000
  42. #define VARG_FLAG_ALLOCSTR 0x80000000
  43. #define VARG_CF_OVERWRITE 0x00000001
  44. #define VARG_CF_EXISTS 0x00000002
  45. #define VARG_CF_PROMPT 0x00000004
  46. #define IDS_PROGRAM_DESCRIPTION 500
  47. #define IDS_PARAM_DEBUG 501
  48. #define IDS_PARAM_HELP 502
  49. #define IDS_PARAM_SETTINGS 511
  50. #define IDS_ARG_DEFAULT 503
  51. #define IDS_ARG_FILENAME 504
  52. #define IDS_ARG_TIME 505
  53. #define IDS_ARG_DATE 506
  54. #define IDS_ARG_TOKEN 507
  55. #define IDS_ARG_PREFIX 508
  56. #define IDS_ARG_YES 512
  57. #define IDS_VERB_PREFIX 509
  58. #define IDS_MESSAGE_ARG_DUP 550
  59. #define IDS_MESSAGE_BADSYNTAX 551
  60. #define IDS_MESSAGE_UNKNOWNPARAM 552
  61. #define IDS_MESSAGE_AND 553
  62. #define IDS_MESSAGE_REQUIRES 554
  63. #define IDS_MESSAGE_MISSING 555
  64. #define IDS_MESSAGE_NOVERB 556
  65. #define IDS_MESSAGE_UNKNOWN 557
  66. #define IDS_MESSAGE_ERROR 558
  67. #define IDS_MESSAGE_EXCLUSIVE 559
  68. #define IDS_MESSAGE_VERB 560
  69. #define IDS_MESSAGE_VERBS 561
  70. #define IDS_MESSAGE_LINEOPT 562
  71. #define IDS_MESSAGE_PARAMETERS 563
  72. #define IDS_MESSAGE_OPTIONS 564
  73. #define IDS_MESSAGE_INISYNT 565
  74. #define IDS_MESSAGE_USAGE 566
  75. #define IDS_MESSAGE_BADTIME 567
  76. #define IDS_MESSAGE_INCORRECT 568
  77. #define IDS_CF_OVERWRITE 569
  78. #define IDS_MESSAGE_MSR 570
  79. #define IDS_MESSAGE_SUCCESS 571
  80. #define IDS_MESSAGE_DEFAULT 572
  81. #define IDS_MESSAGE_NEGATE 573
  82. #define IDS_MESSAGE_HELPTEXT 574
  83. #define IDS_MESSAGE_ERROR_DBG 575
  84. #define IDS_MESSAGE_WARNING_DBG 576
  85. #define IDS_MESSAGE_WARNING 577
  86. #define IDS_MESSAGE_EXAMPLES 578
  87. #define VARG_BOOL( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_BOOL, flags, (CMD_TYPE)value, 0,0,0,NULL,
  88. #define VARG_STR( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_STR, flags, (CMD_TYPE)value, 0,0,0,NULL,
  89. #define VARG_MSZ( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_MSZ, flags, (CMD_TYPE)value, 0,0,0,NULL,
  90. #define VARG_TIME( id, flags ) id,0,0, NULL,NULL,NULL, VARG_TYPE_TIME, flags, (CMD_TYPE)0, 0,0,0,NULL,
  91. #define VARG_DATE( id, flags ) id,0,0, NULL,NULL,NULL, VARG_TYPE_DATE, flags, (CMD_TYPE)0, 0,0,0,NULL,
  92. #define VARG_INT( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_INT, flags, (CMD_TYPE)value, 0,0,0,NULL,
  93. #define VARG_INI( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_INI, flags|VARG_FLAG_ARG_FILENAME|VARG_FLAG_CHOMP, (CMD_TYPE)value, 0,0,0,NULL,
  94. #define VARG_DEBUG( flags ) IDS_PARAM_DEBUG,0,0, NULL,NULL,NULL, VARG_TYPE_DEBUG, flags, (CMD_TYPE)0, 0,0,0,NULL,
  95. #define VARG_HELP( flags ) IDS_PARAM_HELP,0,0, NULL,NULL,NULL, VARG_TYPE_HELP, flags, (CMD_TYPE)FALSE, 0,0,0,NULL,
  96. #define VARG_TERMINATOR 0,0,0, NULL,NULL,NULL, VARG_TYPE_LAST, 0, (CMD_TYPE)0, 0,0,0,NULL
  97. #define VARG_ADJECTIVE 0xFFFF0000
  98. #define VARG_EXCLUSIVE 0x000000FF
  99. #define VARG_INCLUSIVE 0x0000FF00
  100. #define VARG_CONDITION 0x00FF0000
  101. #define VARG_GROUPEXCL 0xFF000000
  102. #define VARG_EXCL( x ) ((DWORD)(x))
  103. #define VARG_INCL( x ) ((DWORD)((x) << 8 ))
  104. #define VARG_COND( x ) ((DWORD)((x) << 16))
  105. #define VARG_GRPX( i, x ) ((DWORD)(((i<<4)|x) << 24))
  106. #define VARG_DECLARE_COMMANDS VARG_RECORD Commands[] = {
  107. #define VARG_DECLARE_NAMES VARG_TERMINATOR }; typedef enum _Commands {
  108. #define VARG_DECLARE_FORMAT };void VArgDeclareFormat() {
  109. #define VARG_DECLARE_END }
  110. #define VARG_VERB( e, v ) Commands[e].dwVerb = (v & 0x0000FFFF);
  111. #define VARG_GROUP( e, g ) Commands[e].dwSet |= g;
  112. #define VARG_ADVERB( e, v, a ) Commands[e].dwVerb = ( v & 0x0000FFFF) | (a<<16);
  113. #define VARG_EXHELP( e, rc ) Commands[e].fFlag |= VARG_FLAG_EXHELP; Commands[e].idExHelp = rc;
  114. #define ASSIGN_STRING( dest, src ) dest = varg_strdup( src )
  115. #ifdef UNICODE
  116. #define MultiByteToChar( a, c ) if(! MultiByteToWideChar( _getmbcp(), 0, (LPCSTR)&a, 1, &c, 1 ) ){ c = _T('\0'); }
  117. #else
  118. #define MultiByteToChar( a, c ) a = c
  119. #endif
  120. #define VARG_ALLOC( s ) HeapAlloc( GetProcessHeap(), 0, s )
  121. #define VARG_FREE( s ) if( s != NULL ) { HeapFree( GetProcessHeap(), 0, s ); }
  122. #define VARG_REALLOC( p, s ) HeapReAlloc( GetProcessHeap(), 0, p, s )
  123. #ifdef __cplusplus
  124. extern "C"
  125. {
  126. #endif
  127. #define CMD_TYPE void*
  128. #pragma warning ( disable : 4201 )
  129. typedef struct _VARG_RECORD
  130. {
  131. LONG idParam;
  132. LONG idExHelp;
  133. DWORD dwSet;
  134. LPTSTR strArg1;
  135. LPTSTR strArg2;
  136. LPTSTR strParam;
  137. int fType;
  138. DWORD fFlag;
  139. union{
  140. void* vValue;
  141. LPTSTR strValue;
  142. ULONG nValue;
  143. BOOL bValue;
  144. SYSTEMTIME stValue;
  145. };
  146. BOOL bDefined;
  147. BOOL bNegated;
  148. DWORD dwVerb;
  149. void (*fntValidation)(int);
  150. } VARG_RECORD, *PVARG_RECORD;
  151. #pragma warning ( default : 4201 )
  152. LPTSTR varg_strdup( LPTSTR src );
  153. DWORD varg_cmdStringAddMsz( int id, LPTSTR src );
  154. DWORD varg_cmdStringAssign( int id, LPTSTR src );
  155. DWORD varg_cmdStringFree( int id );
  156. int varg_printf( WORD color, LPCTSTR mask, ... );
  157. void ParseCmd(int argc, LPTSTR argv[] );
  158. void VArgDeclareFormat();
  159. void DisplayCommandLineHelp();
  160. void DisplayDebugInfo();
  161. ULONG MszStrLen( LPTSTR mszBuffer );
  162. LPWSTR
  163. PaddedString(
  164. LPWSTR sz,
  165. LPWSTR buffer,
  166. ULONG cchBufferSize,
  167. ULONG cchPadSize
  168. );
  169. HRESULT AddStringToMsz( LPTSTR* mszBuffer, LPTSTR strValue );
  170. HRESULT ValidateCommands();
  171. void PrintError( HRESULT hr );
  172. void PrintErrorEx( HRESULT hr, LPTSTR strModule, ... );
  173. void PrintDate( SYSTEMTIME* st );
  174. int PrintDateEx( SHORT color, SYSTEMTIME* st );
  175. LANGID WINAPI
  176. VSetThreadUILanguage(
  177. WORD wReserved
  178. );
  179. int PrintMessage( WORD color, LONG id, ... );
  180. void Chomp(LPTSTR pszLine);
  181. HRESULT GetUserInput(
  182. LPTSTR strBuffer,
  183. ULONG lSize,
  184. BOOL bEcho
  185. );
  186. HRESULT
  187. ParseTime(
  188. LPTSTR strTime,
  189. SYSTEMTIME* pstTime,
  190. BOOL bDate
  191. );
  192. HRESULT
  193. ExpandFiles(
  194. LPTSTR* mszFiles,
  195. BOOL bMultiple
  196. );
  197. DWORD
  198. CheckFile(
  199. LPTSTR strFile,
  200. DWORD dwFlags
  201. );
  202. void FreeCmd();
  203. extern VARG_RECORD Commands[];
  204. extern WORD g_debug;
  205. extern WORD g_light;
  206. extern WORD g_dark;
  207. extern WORD g_normal;
  208. #ifdef DBG
  209. #define ASSERT( x ) \
  210. if( !(x) ){ \
  211. WCHAR buffer[MAXSTR]; \
  212. StringCchPrintfW( buffer, MAXSTR, L"VARG Assert: File: %S Line: %d\n", __FILE__, __LINE__ ); \
  213. OutputDebugStringW( buffer ); \
  214. }
  215. #else
  216. #define ASSERT( x )
  217. #endif
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. #endif //_VARG_H_012599_