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.

259 lines
9.1 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_CF_OVERWRITE 0x00000001
  43. #define VARG_CF_EXISTS 0x00000002
  44. #define VARG_CF_PROMPT 0x00000004
  45. #define IDS_PROGRAM_DESCRIPTION 500
  46. #define IDS_PARAM_DEBUG 501
  47. #define IDS_PARAM_HELP 502
  48. #define IDS_PARAM_SETTINGS 511
  49. #define IDS_ARG_DEFAULT 503
  50. #define IDS_ARG_FILENAME 504
  51. #define IDS_ARG_TIME 505
  52. #define IDS_ARG_DATE 506
  53. #define IDS_ARG_TOKEN 507
  54. #define IDS_ARG_PREFIX 508
  55. #define IDS_ARG_YES 512
  56. #define IDS_VERB_PREFIX 509
  57. #define IDS_MESSAGE_ARG_DUP 550
  58. #define IDS_MESSAGE_BADSYNTAX 551
  59. #define IDS_MESSAGE_UNKNOWNPARAM 552
  60. #define IDS_MESSAGE_AND 553
  61. #define IDS_MESSAGE_REQUIRES 554
  62. #define IDS_MESSAGE_MISSING 555
  63. #define IDS_MESSAGE_NOVERB 556
  64. #define IDS_MESSAGE_UNKNOWN 557
  65. #define IDS_MESSAGE_ERROR 558
  66. #define IDS_MESSAGE_EXCLUSIVE 559
  67. #define IDS_MESSAGE_VERB 560
  68. #define IDS_MESSAGE_VERBS 561
  69. #define IDS_MESSAGE_LINEOPT 562
  70. #define IDS_MESSAGE_PARAMETERS 563
  71. #define IDS_MESSAGE_OPTIONS 564
  72. #define IDS_MESSAGE_INISYNT 565
  73. #define IDS_MESSAGE_USAGE 566
  74. #define IDS_MESSAGE_BADTIME 567
  75. #define IDS_MESSAGE_INCORRECT 568
  76. #define IDS_CF_OVERWRITE 569
  77. #define IDS_MESSAGE_MSR 570
  78. #define IDS_MESSAGE_SUCCESS 571
  79. #define IDS_MESSAGE_DEFAULT 572
  80. #define IDS_MESSAGE_NEGATE 573
  81. #define IDS_MESSAGE_HELPTEXT 574
  82. #define IDS_MESSAGE_ERROR_DBG 575
  83. #define IDS_MESSAGE_WARNING_DBG 576
  84. #define IDS_MESSAGE_WARNING 577
  85. #define IDS_MESSAGE_EXAMPLES 578
  86. #define VARG_BOOL( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_BOOL, flags, (CMD_TYPE)value, 0,0,0,NULL,
  87. #define VARG_STR( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_STR, flags, (CMD_TYPE)value, 0,0,0,NULL,
  88. #define VARG_MSZ( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_MSZ, flags, (CMD_TYPE)value, 0,0,0,NULL,
  89. #define VARG_TIME( id, flags ) id,0,0, NULL,NULL,NULL, VARG_TYPE_TIME, flags, (CMD_TYPE)0, 0,0,0,NULL,
  90. #define VARG_DATE( id, flags ) id,0,0, NULL,NULL,NULL, VARG_TYPE_DATE, flags, (CMD_TYPE)0, 0,0,0,NULL,
  91. #define VARG_INT( id, flags, value ) id,0,0, NULL,NULL,NULL, VARG_TYPE_INT, flags, (CMD_TYPE)value, 0,0,0,NULL,
  92. #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,
  93. #define VARG_DEBUG( flags ) IDS_PARAM_DEBUG,0,0, NULL,NULL,NULL, VARG_TYPE_DEBUG, flags, (CMD_TYPE)0, 0,0,0,NULL,
  94. #define VARG_HELP( flags ) IDS_PARAM_HELP,0,0, NULL,NULL,NULL, VARG_TYPE_HELP, flags, (CMD_TYPE)FALSE, 0,0,0,NULL,
  95. #define VARG_TERMINATOR 0,0,0, NULL,NULL,NULL, VARG_TYPE_LAST, 0, (CMD_TYPE)0, 0,0,0,NULL
  96. #define VARG_ADJECTIVE 0xFFFF0000
  97. #define VARG_EXCLUSIVE 0x000000FF
  98. #define VARG_INCLUSIVE 0x0000FF00
  99. #define VARG_CONDITION 0x00FF0000
  100. #define VARG_GROUPEXCL 0xFF000000
  101. #define VARG_EXCL( x ) ((DWORD)(x))
  102. #define VARG_INCL( x ) ((DWORD)((x) << 8 ))
  103. #define VARG_COND( x ) ((DWORD)((x) << 16))
  104. #define VARG_GRPX( i, x ) ((DWORD)(((i<<4)|x) << 24))
  105. #define VARG_DECLARE_COMMANDS VARG_RECORD Commands[] = {
  106. #define VARG_DECLARE_NAMES VARG_TERMINATOR }; typedef enum _Commands {
  107. #define VARG_DECLARE_FORMAT };void VArgDeclareFormat() {
  108. #define VARG_DECLARE_END }
  109. #define VARG_VERB( e, v ) Commands[e].dwVerb = (v & 0x0000FFFF);
  110. #define VARG_GROUP( e, g ) Commands[e].dwSet |= g;
  111. #define VARG_ADVERB( e, v, a ) Commands[e].dwVerb = ( v & 0x0000FFFF) | (a<<16);
  112. #define VARG_EXHELP( e, rc ) Commands[e].fFlag |= VARG_FLAG_EXHELP; Commands[e].idExHelp = rc;
  113. #define ASSIGN_STRING_RC( dest, src, c ) \
  114. if( IsEmpty( src ) || _tcscmp( src, c )==0 ){ \
  115. ASSIGN_STRING( dest, NULL ); \
  116. }else{ \
  117. ASSIGN_STRING( dest, src ); \
  118. } \
  119. #define ASSIGN_STRING( dest, src ) \
  120. if( !IsEmpty(src) ){ \
  121. LPTSTR s = src; /*in case dest==src*/ \
  122. DWORD dwSize = (_tcslen(src)+2)*sizeof(TCHAR); \
  123. dest = (LPTSTR)VARG_ALLOC( dwSize ); \
  124. if( NULL != dest ){ \
  125. ZeroMemory( dest, dwSize ); \
  126. _tcscpy( dest, s ); \
  127. } \
  128. }else{ \
  129. dest = (LPTSTR)VARG_ALLOC( 2*sizeof(TCHAR) ); \
  130. if( NULL != dest ){ \
  131. _tcscpy(dest, _T("") ); \
  132. } \
  133. } \
  134. #ifdef UNICODE
  135. #define MultiByteToChar( a, c ) MultiByteToWideChar( _getmbcp(), 0, (LPCSTR)&a, 1, &c, 1 )
  136. #else
  137. #define MultiByteToChar( a, c ) a = c
  138. #endif
  139. #define VARG_ALLOC( s ) HeapAlloc( GetProcessHeap(), 0, s )
  140. #define VARG_FREE( s ) if( s != NULL ) { HeapFree( GetProcessHeap(), 0, s ); }
  141. #define VARG_REALLOC( p, s ) HeapReAlloc( GetProcessHeap(), 0, p, s )
  142. #ifdef __cplusplus
  143. extern "C"
  144. {
  145. #endif
  146. #define CMD_TYPE void*
  147. #pragma warning ( disable : 4201 )
  148. typedef struct _VARG_RECORD
  149. {
  150. LONG idParam;
  151. LONG idExHelp;
  152. DWORD dwSet;
  153. LPTSTR strArg1;
  154. LPTSTR strArg2;
  155. LPTSTR strParam;
  156. int fType;
  157. DWORD fFlag;
  158. union{
  159. void* vValue;
  160. LPTSTR strValue;
  161. ULONG nValue;
  162. BOOL bValue;
  163. SYSTEMTIME stValue;
  164. };
  165. BOOL bDefined;
  166. BOOL bNegated;
  167. DWORD dwVerb;
  168. void (*fntValidation)(int);
  169. } VARG_RECORD, *PVARG_RECORD;
  170. #pragma warning ( default : 4201 )
  171. void ParseCmd(int argc, LPTSTR argv[] );
  172. void VArgDeclareFormat();
  173. void DisplayCommandLineHelp();
  174. void DisplayDebugInfo();
  175. ULONG MszStrLen( LPTSTR mszBuffer );
  176. HRESULT AddStringToMsz( LPTSTR* mszBuffer, LPTSTR strValue );
  177. HRESULT ValidateCommands();
  178. void PrintError( HRESULT hr );
  179. void PrintErrorEx( HRESULT hr, LPTSTR strModule, ... );
  180. void PrintDate( SYSTEMTIME* st );
  181. int PrintDateEx( SHORT color, SYSTEMTIME* st );
  182. LANGID WINAPI
  183. VSetThreadUILanguage(
  184. WORD wReserved
  185. );
  186. int PrintMessage( WORD color, LONG id, ... );
  187. void Chomp(LPTSTR pszLine);
  188. HRESULT GetUserInput(
  189. LPTSTR strBuffer,
  190. ULONG lSize,
  191. BOOL bEcho
  192. );
  193. HRESULT
  194. ParseTime(
  195. LPTSTR strTime,
  196. SYSTEMTIME* pstTime,
  197. BOOL bDate
  198. );
  199. HRESULT
  200. ExpandFiles(
  201. LPTSTR* mszFiles,
  202. BOOL bMultiple
  203. );
  204. HRESULT
  205. CheckFile(
  206. LPTSTR strFile,
  207. DWORD dwFlags
  208. );
  209. void FreeCmd();
  210. extern VARG_RECORD Commands[];
  211. extern WORD g_debug;
  212. extern WORD g_light;
  213. extern WORD g_dark;
  214. extern WORD g_normal;
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif //_VARG_H_012599_