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.

1101 lines
50 KiB

  1. // ****************************************************************************
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // Cmdline.h
  8. //
  9. // Abstract:
  10. //
  11. // This modules contains the common functionality file headers and type
  12. // definitions
  13. //
  14. // Author:
  15. //
  16. // Sunil G.V.N. Murali ([email protected]) 1-Sep-2000
  17. //
  18. // Revision History:
  19. //
  20. // Sunil G.V.N. Murali ([email protected]) 1-Sep-2000 : Created It.
  21. //
  22. // ****************************************************************************
  23. #ifndef __CMDLINE_H
  24. #define __CMDLINE_H
  25. #ifndef CMDLINE_VERSION
  26. #define CMDLINE_VERSION 100
  27. #endif
  28. #ifndef UNICODE
  29. #error this library can be compiled only in UNICODE environment
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. // constants / defines
  35. #define MAX_RES_STRING 254
  36. #define MAX_STRING_LENGTH 254
  37. // stubs for 'displaying'
  38. #define DISPLAY_MESSAGE( file, message ) ShowMessage( file, message )
  39. #if CMDLINE_VERSION == 100
  40. // ****************************************************************************
  41. // all the below stuff in deprecated in cmdline library version
  42. // greater that 1.0
  43. // ****************************************************************************
  44. //
  45. // custom macros ( for trapping memory leaks )
  46. //
  47. #ifdef _DEBUG
  48. #define __malloc( size ) \
  49. _malloc_dbg( size, _NORMAL_BLOCK, __FILE__, __LINE__ )
  50. #define __calloc( count, size ) \
  51. _calloc_dbg( count, size, _NORMAL_BLOCK, __FILE__, __LINE__ )
  52. #define __free( block ) \
  53. if ( (block) != NULL ) \
  54. { \
  55. _free_dbg( (block), _NORMAL_BLOCK ); \
  56. (block) = NULL; \
  57. } \
  58. 1
  59. #define __realloc( block, size ) \
  60. (((block) != NULL) ? \
  61. _realloc_dbg( (block), size, \
  62. _NORMAL_BLOCK, __FILE__, __LINE__ ) : \
  63. __malloc( size ))
  64. #else // #ifdef _DEBUG
  65. #define __malloc( size ) malloc( size )
  66. #define __calloc( count, size ) calloc( count, size )
  67. #define __free( block ) \
  68. if ( (block) != NULL ) \
  69. { \
  70. free( (block) ); \
  71. (block) = NULL; \
  72. } \
  73. 1
  74. #define __realloc( block, size ) \
  75. (((block) != NULL) ? realloc( block, size ) : __malloc( size ))
  76. #endif // #ifdef _DEBUG
  77. //
  78. // custom macros
  79. //
  80. #define CHECK_NULL( statement, value ) \
  81. if ( ( statement ) == NULL ) \
  82. { \
  83. return value; \
  84. } \
  85. 1
  86. #define SHOW_RESULT_MESSAGE( server, tag, message ) \
  87. if ( IsLocalSystem( server ) == TRUE ) \
  88. { \
  89. DISPLAY_MESSAGE2( stderr, szBuffer, \
  90. _T( "%s %s" ), tag, message ); \
  91. } \
  92. else \
  93. { \
  94. DISPLAY_MESSAGE3( stderr, szBuffer, \
  95. _T( "%s %s: %s" ), tag, server, message ); \
  96. } \
  97. 1
  98. //
  99. // string formatting stubs
  100. #define FORMAT_STRING( buffer, format, value ) \
  101. swprintf( buffer, format, value )
  102. #define FORMAT_STRING2( buffer, format, value1, value2 ) \
  103. swprintf( buffer, format, value1, value2 )
  104. #define FORMAT_STRING3( buffer, format, value1, value2, value3 ) \
  105. swprintf( buffer, format, value1, value2, value3 )
  106. #define FORMAT_STRING_EX( buffer, format, value, length, alignflag ) \
  107. swprintf( buffer, format, value ); \
  108. AdjustStringLength( buffer, length, alignflag )
  109. #define FORMAT_STRING_EX2( buffer, format, value1, value2, length, alignflag ) \
  110. swprintf( buffer, format, value1, value2 ); \
  111. AdjustStringLength( buffer, length, alignflag )
  112. #define FORMAT_STRING_EX3( buffer, format, value1, value2, value3, length, alignflag ) \
  113. swprintf( buffer, format, value1, value2, value3 ); \
  114. AdjustStringLength( buffer, length, alignflag )
  115. //
  116. // stubs for 'displaying'
  117. #define DISPLAY_MESSAGE( file, message ) \
  118. ShowMessage( file, message )
  119. #define DISPLAY_MESSAGE1( file, buffer, format, value1 ) \
  120. FORMAT_STRING( buffer, format, value1 ); \
  121. ShowMessage( file, buffer )
  122. #define DISPLAY_MESSAGE2( file, buffer, format, value1, value2 ) \
  123. FORMAT_STRING2( buffer, format, value1, value2 ); \
  124. ShowMessage( file, buffer )
  125. #define DISPLAY_MESSAGE3( file, buffer, format, value1, value2, value3 ) \
  126. FORMAT_STRING3( buffer, format, value1, value2, value3 ); \
  127. ShowMessage( file, buffer )
  128. //
  129. // display messages from resource file's string table ( stubs )
  130. #define DISPLAY_RES_MESSAGE( file, id ) \
  131. ShowResMessage( file, id )
  132. #define DISPLAY_RES_MESSAGE1( file, buffer, id, value1 ) \
  133. FORMAT_STRING( buffer, GetResString( id ), value1 ); \
  134. ShowMessage( file, buffer )
  135. #define DISPLAY_RES_MESSAGE2( file, buffer, id, value1, value2 ) \
  136. FORMAT_STRING2( buffer, GetResString( id ), value1, value2 ); \
  137. ShowMessage( file, buffer )
  138. #define DISPLAY_RES_MESSAGE3( file, buffer, id, value1, value2, value3 ) \
  139. FORMAT_STRING3( buffer, GetResString( id ), value1, value2, value3 ); \
  140. ShowMessage( file, buffer )
  141. #define MAX_USERNAME_LENGTH 64
  142. #define MAX_PASSWORD_LENGTH 64
  143. #define FULL_SUCCESS 0
  144. #define PARTIALLY_SUCCESS 128
  145. #define COMPLETELY_FAILED 255
  146. //
  147. // type definitions
  148. //
  149. typedef TCHAR __STRING_32[ 32 ];
  150. typedef TCHAR __STRING_64[ 64 ];
  151. typedef TCHAR __STRING_128[ 128 ];
  152. typedef TCHAR __STRING_256[ 256 ];
  153. typedef TCHAR __STRING_512[ 512 ];
  154. typedef TCHAR __STRING_1024[ 1024 ];
  155. typedef TCHAR __STRING_2048[ 2048 ];
  156. typedef TCHAR __STRING_4096[ 4096 ];
  157. typedef TCHAR __RESOURCE_STRING [ MAX_RES_STRING + 1 ];
  158. typedef TCHAR __MAX_SIZE_STRING[ MAX_STRING_LENGTH + 1 ];
  159. // string manipulation macros
  160. #define STRING_COPY_STATIC( destination, source ) \
  161. StringCopy( destination, source, SIZE_OF_ARRAY( destination ) )
  162. #define STRING_COPY_DYNAMIC( destination, source ) \
  163. StringCopyEx( destination, source )
  164. #define STRING_CONCAT_STATIC( destination, source ) \
  165. StringConcat( destination, source, SIZE_OF_ARRAY( destination ) )
  166. #define STRING_CONCAT_DYNAMIC( destination, source ) \
  167. StringConcatEx( destination, source )
  168. #define STRING_COPY( destination, source ) \
  169. if ( destination != NULL && _msize( destination ) != -1 ) \
  170. { \
  171. STRING_COPY_DYNAMIC( destination, source ); \
  172. } \
  173. else \
  174. { \
  175. STRING_COPY_STATIC( destination, source ); \
  176. } \
  177. 1
  178. #define STRING_CONCAT( destination, source ) \
  179. if ( destination != NULL && _msize( destination ) != -1 ) \
  180. { \
  181. STRING_CONCAT_DYNAMIC( destination, source ); \
  182. } \
  183. else \
  184. { \
  185. STRING_CONCAT_STATIC( destination, source ); \
  186. } \
  187. 1
  188. //
  189. // function re-defs
  190. //
  191. #ifdef UNICODE
  192. #define GetCompatibleStringFromMultiByte GetAsUnicodeStringEx
  193. #define GetCompatibleStringFromUnicode GetAsUnicodeString
  194. #else
  195. #define GetCompatibleStringFromMultiByte GetAsMultiByteString
  196. #define GetCompatibleStringFromUnicode GetAsMultiByteStringEx
  197. #endif // UNICODE
  198. /////////
  199. // conversion functions
  200. // old legacy functions -- these are made obsolete
  201. LPSTR GetAsMultiByteString( LPCWSTR pszSource,
  202. LPSTR pszDestination, DWORD dwLength );
  203. LPWSTR GetAsUnicodeStringEx( LPCSTR pszSource,
  204. LPWSTR pwszDestination, DWORD dwLength );
  205. /////////
  206. // this function is mapped to the StringCopyW
  207. // LPWSTR GetAsUnicodeString( LPCWSTR pszSource,
  208. // LPWSTR pwszDestination,
  209. // DWORD dwLength );
  210. #define GetAsUnicodeString( source, \
  211. destination, \
  212. length ) StringCopyW( destination, \
  213. source, \
  214. length )
  215. /////////
  216. // this function is mapped to its another function which is of similar type
  217. // LPSTR GetAsMultiByteStringEx( LPCWSTR pwszSource,
  218. // LPSTR pszDestination, DWORD dwLength );
  219. #define GetAsMultiByteStringEx GetAsMultiByteString
  220. // ****************************************************************************
  221. // all the above stuff is deprecated in cmdline library version
  222. // greater that 1.0
  223. // ****************************************************************************
  224. #endif // CMDLINE_VERSION == 100
  225. ///////////////////////////////////////////////////////////////////////////////
  226. // //
  227. // COMMON FUNCTIONALITY //
  228. // //
  229. ///////////////////////////////////////////////////////////////////////////////
  230. // wrappers for quote meta
  231. #define _X( text ) text
  232. #define _X1( text ) text
  233. #define _X2( text ) text
  234. #define _X3( text ) text
  235. //
  236. // macros
  237. //
  238. #define TAG_ERROR GetResString( IDS_TAG_ERROR )
  239. #define TAG_WARNING GetResString( IDS_TAG_WARNING )
  240. #define TAG_SUCCESS GetResString( IDS_TAG_SUCCESS )
  241. #define TAG_INFORMATION GetResString( IDS_TAG_INFORMATION )
  242. #define SIZE_OF_ARRAY( array ) ( sizeof( array ) / sizeof( array[ 0 ] ) )
  243. //
  244. // constants / defines / enumerations
  245. //
  246. #define _DEFAULT_CODEPAGE CP_OEMCP
  247. #define BACK_SPACE 0x08
  248. #define BLANK_CHAR 0x00
  249. #define CARRIAGE_RETURN 0x0D
  250. #define ASTERIX _T( "*" )
  251. #define BEEP_SOUND _T( "\a" )
  252. #define TRIM_LEFT 0x00000001
  253. #define TRIM_RIGHT 0x00000002
  254. #define TRIM_ALL 0x00000003
  255. extern const WCHAR cwchNullChar;
  256. extern const WCHAR cwszNullString[ 2 ];
  257. #if CMDLINE_VERSION == 100
  258. #define NULL_CHAR L'\0'
  259. #define NULL_STRING L"\0"
  260. #endif
  261. #define V_NOT_AVAILABLE GetResString( IDS_V_NOT_AVAILABLE )
  262. #define ERROR_OS_INCOMPATIBLE GetResString( IDS_ERROR_OS_INCOMPATIBLE )
  263. #define ERROR_REMOTE_INCOMPATIBLE GetResString( IDS_ERROR_REMOTE_INCOMPATIBLE )
  264. // macros for copy or concatenation ansi/unicode strings
  265. #ifdef UNICODE
  266. #define StringCopy StringCopyW
  267. #define StringCopyEx StringCopyExW
  268. #define StringConcat StringConcatW
  269. #define StringConcatEx StringConcatExW
  270. #define StringLength StringLengthW
  271. #define StringCompare StringCompareW
  272. #define StringCompareEx StringCompareExW
  273. #else
  274. #define StringCopy StringCopyA
  275. #define StringCopyEx StringCopyExA
  276. #define StringConcat StringConcatA
  277. #define StringConcatEx StringConcatExA
  278. #define StringLength StringLengthA
  279. #define StringCompare StringCompareA
  280. #define StringCompareEx StringCompareExA
  281. #endif
  282. //
  283. // flags -- specific to ShowLastErrorEx
  284. #define SLE_TYPE_ERROR 0x00000001
  285. #define SLE_TYPE_INFO 0x00000002
  286. #define SLE_TYPE_WARNING 0x00000004
  287. #define SLE_TYPE_SUCCESS 0x00000008
  288. #define SLE_SYSTEM 0x00010000
  289. #define SLE_INTERNAL 0x00020000
  290. #define SLE_MASK 0x000F0000
  291. //
  292. // pattern matching flags
  293. #define PATTERN_LOCALE_USENGLISH 0x00000001
  294. #define PATTERN_NOPARSING 0x00000002
  295. #define PATTERN_COMPARE_IGNORECASE 0x00000100
  296. #define PATTERN_COMPARE_IGNOREKANATYPE 0x00000200
  297. #define PATTERN_COMPARE_IGNORENONSPACE 0x00000400
  298. #define PATTERN_COMPARE_IGNORESYMBOLS 0x00000800
  299. #define PATTERN_COMPARE_IGNOREWIDTH 0x00001000
  300. #define PATTERN_COMPARE_STRINGSORT 0x00002000
  301. //
  302. // function prototypes
  303. //
  304. BOOL InitGlobals();
  305. LPCWSTR GetReason();
  306. BOOL SetReason( LPCWSTR pwszReason );
  307. BOOL SetReason2( DWORD dwCount, LPCWSTR pwszFormat, ... );
  308. BOOL SaveLastError();
  309. DWORD WNetSaveLastError();
  310. BOOL ShowLastError( FILE* fp );
  311. BOOL ShowLastErrorEx( FILE* fp, DWORD dwFlags );
  312. BOOL ReleaseGlobals();
  313. BOOL IsWin2KOrLater();
  314. BOOL IsCompatibleOperatingSystem( DWORD dwVersion );
  315. BOOL SetOsVersion( DWORD dwMajor, DWORD dwMinor, WORD wServicePackMajor );
  316. LPCWSTR GetResString( UINT uID );
  317. LPCWSTR GetResString2( UINT uID, DWORD dwIndexNumber );
  318. double AsFloat( LPCWSTR pwszValue );
  319. BOOL IsFloatingPoint( LPCWSTR pwszValue );
  320. LONG AsLong( LPCWSTR pwszValue, DWORD dwBase );
  321. BOOL IsNumeric( LPCWSTR pwszValue, DWORD dwBase, BOOL bSigned );
  322. LPCWSTR FindChar( LPCWSTR pwszString, WCHAR wch, DWORD dwFrom );
  323. LONG FindChar2( LPCWSTR pwszString, WCHAR wch, BOOL bIgnoreCase, DWORD dwFrom );
  324. BOOL InString( LPCWSTR pwszString, LPCWSTR pwszList, BOOL bIgnoreCase );
  325. LPCWSTR FindOneOf( LPCWSTR pwszText, LPCWSTR pwszTextToFind, DWORD dwFrom );
  326. LONG FindOneOf2( LPCWSTR pwszText, LPCWSTR pwszTextToFind, BOOL bIgnoreCase, DWORD dwFrom );
  327. LPCWSTR FindString( LPCWSTR pwszText, LPCWSTR pwszTextToFind, DWORD dwFrom );
  328. LONG FindString2( LPCWSTR pwszText, LPCWSTR pwszTextToFind, BOOL bIgnoreCase, DWORD dwFrom );
  329. LONG StringLengthInBytes( LPCWSTR pwszText );
  330. LPCWSTR TrimString( LPWSTR pwszString, DWORD dwFlags );
  331. LPCWSTR TrimString2( LPWSTR pwszString, LPCWSTR pwszTrimChars, DWORD dwFlags );
  332. LPCWSTR QuoteMeta( LPCWSTR pwszText, DWORD dwQuoteIndex );
  333. LPCWSTR AdjustStringLength( LPWSTR pwszValue, DWORD dwLength, BOOL bPadLeft );
  334. LPCWSTR Replicate( LPWSTR pwszBuffer,
  335. LPCWSTR pwszText, DWORD dwCount, DWORD dwLength );
  336. BOOL IsConsoleFile( FILE* fp );
  337. LCID GetSupportedUserLocale( BOOL* pbLocaleChanged );
  338. BOOL StringCopyExA( LPSTR pszDest, LPCSTR pszSource );
  339. BOOL StringConcatExA( LPSTR pszDest, LPCSTR pszSource );
  340. BOOL StringCopyExW( LPWSTR pwszDest, LPCWSTR pwszSource );
  341. BOOL StringConcatExW( LPWSTR pwszDest, LPCWSTR pwszSource );
  342. BOOL StringCopyA( LPSTR pszDest, LPCSTR pszSource, LONG lSize );
  343. BOOL StringConcatA( LPSTR pszDest, LPCSTR pszSource, LONG lSize );
  344. BOOL StringCopyW( LPWSTR pwszDest, LPCWSTR pwszSource, LONG lSize );
  345. BOOL StringConcatW( LPWSTR pwszDest, LPCWSTR pwszSource, LONG lSize );
  346. DWORD StringLengthA( LPCSTR pszSource, DWORD dwReserved );
  347. DWORD StringLengthW( LPCWSTR pwszSource, DWORD dwReserved );
  348. LONG StringCompareW( LPCWSTR pwszString1,
  349. LPCWSTR pwszString2, BOOL bIgnoreCase, DWORD dwCount );
  350. LONG StringCompareA( LPCSTR pwszString1,
  351. LPCSTR pwszString2, BOOL bIgnoreCase, DWORD dwCount );
  352. LONG StringCompareExW( LPCWSTR pwszString1,
  353. LPCWSTR pwszString2, BOOL bIgnoreCase, DWORD dwCount );
  354. LONG StringCompareExA( LPCSTR pwszString1,
  355. LPCSTR pwszString2, BOOL bIgnoreCase, DWORD dwCount );
  356. BOOL ShowResMessage( FILE* fp, UINT uID );
  357. BOOL ShowMessage( FILE* fp, LPCWSTR pwszMessage );
  358. BOOL ShowMessageEx( FILE* fp, DWORD dwCount, BOOL bStyle, LPCWSTR pwszFormat, ... );
  359. BOOL GetAsUnicodeString2( LPCSTR pszSource, LPWSTR pwszDestination, DWORD* pdwLength );
  360. BOOL GetAsMultiByteString2( LPCWSTR pwszSource, LPSTR pszDestination, DWORD* pdwLength );
  361. BOOL GetPassword( LPWSTR pwszPassword, DWORD dwMaxPasswordSize );
  362. BOOL MatchPattern( LPWSTR pwszPattern, LPWSTR pwszText );
  363. LPCWSTR ParsePattern( LPCWSTR pwszPattern );
  364. BOOL MatchPatternEx( LPCWSTR pwszText, LPCWSTR pwszPattern, DWORD dwFlags );
  365. BOOL FreeMemory( LPVOID* ppv );
  366. BOOL CheckMemory( LPVOID pv );
  367. LPVOID AllocateMemory( DWORD dwBytes );
  368. BOOL ReallocateMemory( LPVOID* ppv, DWORD dwBytesNew );
  369. LONG GetBufferSize( LPVOID pv );
  370. ///////////////////////////////////////////////////////////////////////////////
  371. // //
  372. // REMOTE CONNECTIVITY //
  373. // //
  374. ///////////////////////////////////////////////////////////////////////////////
  375. //
  376. // error codes
  377. //
  378. #define E_LOCAL_CREDENTIALS 0xA0010001 // 1010 0000 0000 0001 0000 0000 0000 0001
  379. #define I_NO_CLOSE_CONNECTION 0x50010001 // 0101 0000 0000 0001 0000 0000 0000 0001
  380. //
  381. // structs
  382. //
  383. typedef struct tagConnectionInfo
  384. {
  385. DWORD dwFlags; // flags
  386. LPCTSTR pszServer; // server name
  387. LPTSTR pszUserName; // user name
  388. DWORD dwUserLength; // max. no. of characters allowed for user name
  389. LPTSTR pszPassword; // password
  390. DWORD dwPasswordLength; // max. no. of characters allowed for password
  391. LPCTSTR pszShare; // tells the custom share name
  392. LPVOID lpReserved1; // reserved for future use
  393. LPVOID lpReserved2; // reserved for future use
  394. LPVOID lpReserved3; // reserved for future use
  395. } TCONNECTIONINFO, *PTCONNECTIONINFO;
  396. //
  397. // connection info flags
  398. //
  399. // general flags
  400. #define CI_ACCEPT_PASSWORD 0x00000001 // 0000 0001
  401. // share (if nothing specified, default will be assumed as IPC$ )
  402. #define CI_SHARE_IPC 0x00000010 // 0000 0000 0001 XXXX XXXX
  403. #define CI_SHARE_ADMIN 0x00000020 // 0000 0000 0010 XXXX XXXX
  404. #define CI_SHARE_CUSTOM 0x00000040 // 0000 0001 0000 XXXX XXXX
  405. // extra flag used while closing connection
  406. #define CI_CLOSE_BY_FORCE 0x10000000
  407. //
  408. // function prototypes
  409. //
  410. BOOL IsUserAdmin();
  411. BOOL IsUNCFormat( LPCWSTR pwszServer );
  412. BOOL IsLocalSystem( LPCWSTR pwszServer );
  413. BOOL IsValidServer( LPCWSTR pwszServer );
  414. BOOL IsValidIPAddress( LPCWSTR pwszAddress );
  415. BOOL GetHostByIPAddr( LPCWSTR pwszServer,
  416. LPWSTR pwszHostName,
  417. DWORD* pdwHostNameLength, BOOL bNeedFQDN );
  418. DWORD GetTargetVersion( LPCWSTR pwszServer );
  419. DWORD ConnectServer( LPCWSTR pwszServer, LPCWSTR pwszUser, LPCWSTR pwszPassword );
  420. DWORD ConnectServer2( LPCWSTR pwszServer, LPCWSTR pwszUser,
  421. LPCWSTR pwszPassword, LPCWSTR pwszShare );
  422. DWORD CloseConnection( LPCWSTR pwszServer );
  423. DWORD CloseConnection2( LPCWSTR pwszServer, LPCWSTR pwszShare, DWORD dwFlags );
  424. BOOL EstablishConnectionEx( PTCONNECTIONINFO pci );
  425. BOOL EstablishConnection( LPCWSTR pwszServer,
  426. LPWSTR pwszUserName, DWORD dwUserLength,
  427. LPWSTR pwszPassword, DWORD dwPasswordLength, BOOL bNeedPassword );
  428. ///////////////////////////////////////////////////////////////////////////////
  429. // //
  430. // MULTI-DIMENSIONAL MULTI-TYPE DYNAMIC ARRAYS //
  431. // //
  432. ///////////////////////////////////////////////////////////////////////////////
  433. //
  434. // constants / defines / enumerations
  435. //
  436. // item types supported by dynamic array
  437. #define DA_TYPE_NONE 0x00000000
  438. #define DA_TYPE_GENERAL 0x00010000
  439. #define DA_TYPE_STRING 0x00020000
  440. #define DA_TYPE_LONG 0x00030000
  441. #define DA_TYPE_DWORD 0x00040000
  442. #define DA_TYPE_BOOL 0x00050000
  443. #define DA_TYPE_FLOAT 0x00060000
  444. #define DA_TYPE_DOUBLE 0x00070000
  445. #define DA_TYPE_ARRAY 0x00080000
  446. #define DA_TYPE_HANDLE 0x00090000
  447. #define DA_TYPE_SYSTEMTIME 0x000A0000
  448. #define DA_TYPE_FILETIME 0x000B0000
  449. //
  450. // type definitions
  451. //
  452. typedef VOID* TARRAY;
  453. typedef TARRAY* PTARRAY;
  454. //
  455. // public function prototypes
  456. //
  457. //
  458. // array pointer validation function(s)
  459. BOOL IsValidArray( TARRAY pArray );
  460. //
  461. // dynamic array creation / destraction functions
  462. TARRAY CreateDynamicArray();
  463. VOID DestroyDynamicArray( PTARRAY pArray );
  464. //
  465. // general helper function(s)
  466. DWORD DynArrayGetCount( TARRAY pArray );
  467. DWORD DynArrayGetCount2( TARRAY pArray, DWORD dwRow );
  468. DWORD DynArrayGetItemType( TARRAY pArray, DWORD dwIndex );
  469. DWORD DynArrayGetItemType2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  470. //
  471. // adding columns
  472. LONG DynArrayAddColumns( TARRAY pArray, DWORD dwColumns );
  473. LONG DynArrayInsertColumns( TARRAY pArray, DWORD dwIndex, DWORD dwColumns );
  474. //
  475. // array append function(s) ( for one-dimensional array )
  476. LONG DynArrayAppend( TARRAY pArray, LPVOID pValue );
  477. LONG DynArrayAppendLong( TARRAY pArray, LONG lValue );
  478. LONG DynArrayAppendBOOL( TARRAY pArray, BOOL bValue );
  479. LONG DynArrayAppendDWORD( TARRAY pArray, DWORD dwValue );
  480. LONG DynArrayAppendFloat( TARRAY pArray, float dwValue );
  481. LONG DynArrayAppendDouble( TARRAY pArray, double dwValue );
  482. LONG DynArrayAppendString( TARRAY pArray, LPCTSTR szValue, DWORD dwLength );
  483. LONG DynArrayAppendHandle( TARRAY pArray, HANDLE hValue );
  484. LONG DynArrayAppendSystemTime( TARRAY pArray, SYSTEMTIME stValue );
  485. LONG DynArrayAppendFileTime( TARRAY pArray, FILETIME ftValue );
  486. // helper to append 2-dimensional array
  487. LONG DynArrayAppendRow( TARRAY pArray, DWORD dwColumns );
  488. // ( for two-dimensional array )
  489. LONG DynArrayAppend2( TARRAY pArray, DWORD dwRow, LPVOID pValue );
  490. LONG DynArrayAppendLong2( TARRAY pArray, DWORD dwRow, LONG lValue );
  491. LONG DynArrayAppendBOOL2( TARRAY pArray, DWORD dwRow, BOOL bValue );
  492. LONG DynArrayAppendDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwValue );
  493. LONG DynArrayAppendFloat2( TARRAY pArray, DWORD dwRow, float dwValue );
  494. LONG DynArrayAppendDouble2( TARRAY pArray, DWORD dwRow, double dwValue );
  495. LONG DynArrayAppendString2( TARRAY pArray, DWORD dwRow, LPCTSTR szValue, DWORD dwLength );
  496. LONG DynArrayAppendHandle2( TARRAY pArray, DWORD dwRow, HANDLE hValue );
  497. LONG DynArrayAppendSystemTime2( TARRAY pArray, DWORD dwRow, SYSTEMTIME stValue );
  498. LONG DynArrayAppendFileTime2( TARRAY pArray, DWORD dwRow, FILETIME ftValue );
  499. //
  500. // array insert function(s) ( for one-dimensional array )
  501. LONG DynArrayInsert( TARRAY pArray, DWORD dwIndex, LPVOID pValue );
  502. LONG DynArrayInsertLong( TARRAY pArray, DWORD dwIndex, LONG lValue );
  503. LONG DynArrayInsertBOOL( TARRAY pArray, DWORD dwIndex, BOOL bValue );
  504. LONG DynArrayInsertDWORD( TARRAY pArray, DWORD dwIndex, DWORD dwValue );
  505. LONG DynArrayInsertFloat( TARRAY pArray, DWORD dwIndex, float dwValue );
  506. LONG DynArrayInsertDouble( TARRAY pArray, DWORD dwIndex, double dwValue );
  507. LONG DynArrayInsertString( TARRAY pArray, DWORD dwIndex, LPCTSTR szValue, DWORD dwLength );
  508. LONG DynArrayInsertHandle( TARRAY pArray, DWORD dwIndex, HANDLE hValue );
  509. LONG DynArrayInsertSystemTime( TARRAY pArray, DWORD dwIndex, SYSTEMTIME stValue );
  510. LONG DynArrayInsertFileTime( TARRAY pArray, DWORD dwIndex, FILETIME ftValue );
  511. // helper to insert 2-dimensional array
  512. LONG DynArrayInsertRow( TARRAY pArray, DWORD dwIndex, DWORD dwColumns );
  513. // ( for two-dimensional array )
  514. LONG DynArrayInsert2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, LPVOID pValue );
  515. LONG DynArrayInsertLong2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, LONG lValue );
  516. LONG DynArrayInsertBOOL2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, BOOL bValue );
  517. LONG DynArrayInsertDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, DWORD dwValue );
  518. LONG DynArrayInsertFloat2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, float dwValue );
  519. LONG DynArrayInsertDouble2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, double dwValue );
  520. LONG DynArrayInsertString2( TARRAY pArray, DWORD dwRow,
  521. DWORD dwColIndex, LPCTSTR szValue, DWORD dwLength );
  522. LONG DynArrayInsertHandle2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, HANDLE hValue );
  523. LONG DynArrayInsertSystemTime2( TARRAY pArray, DWORD dwRow,
  524. DWORD dwColIndex, SYSTEMTIME stValue );
  525. LONG DynArrayInsertFileTime2( TARRAY pArray, DWORD dwRow,
  526. DWORD dwColIndex, FILETIME ftValue );
  527. //
  528. // item value set function(s) ( for one-dimensional array )
  529. BOOL DynArraySet( TARRAY pArray, DWORD dwIndex, LPVOID pValue );
  530. BOOL DynArraySetLong( TARRAY pArray, DWORD dwIndex, LONG lValue );
  531. BOOL DynArraySetBOOL( TARRAY pArray, DWORD dwIndex, BOOL bValue );
  532. BOOL DynArraySetDWORD( TARRAY pArray, DWORD dwIndex, DWORD dwValue );
  533. BOOL DynArraySetFloat( TARRAY pArray, DWORD dwIndex, float dwValue );
  534. BOOL DynArraySetDouble( TARRAY pArray, DWORD dwIndex, double dwValue );
  535. BOOL DynArraySetString( TARRAY pArray, DWORD dwIndex, LPCTSTR szValue, DWORD dwLength );
  536. BOOL DynArraySetHandle( TARRAY pArray, DWORD dwIndex, HANDLE hValue );
  537. BOOL DynArraySetSystemTime( TARRAY pArray, DWORD dwIndex, SYSTEMTIME stValue );
  538. BOOL DynArraySetFileTime( TARRAY pArray, DWORD dwIndex, FILETIME ftValue );
  539. // ( for two-dimensional array )
  540. BOOL DynArraySet2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, LPVOID pValue );
  541. BOOL DynArraySetLong2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, LONG lValue );
  542. BOOL DynArraySetBOOL2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, BOOL bValue );
  543. BOOL DynArraySetDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, DWORD dwValue );
  544. BOOL DynArraySetFloat2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, float dwValue );
  545. BOOL DynArraySetDouble2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, double dwValue );
  546. BOOL DynArraySetString2( TARRAY pArray, DWORD dwRow,
  547. DWORD dwColumn, LPCTSTR szValue, DWORD dwLength );
  548. BOOL DynArraySetHandle2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, HANDLE hValue );
  549. BOOL DynArraySetSystemTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, SYSTEMTIME stValue );
  550. BOOL DynArraySetFileTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, FILETIME ftValue );
  551. //
  552. // item value get function(s) ( for one-dimensional array )
  553. LPVOID DynArrayItem( TARRAY pArray, DWORD dwIndex );
  554. LONG DynArrayItemAsLong( TARRAY pArray, DWORD dwIndex );
  555. BOOL DynArrayItemAsBOOL( TARRAY pArray, DWORD dwIndex );
  556. DWORD DynArrayItemAsDWORD( TARRAY pArray, DWORD dwIndex );
  557. float DynArrayItemAsFloat( TARRAY pArray, DWORD dwIndex );
  558. double DynArrayItemAsDouble( TARRAY pArray, DWORD dwIndex );
  559. LPCTSTR DynArrayItemAsString( TARRAY pArray, DWORD dwIndex );
  560. HANDLE DynArrayItemAsHandle( TARRAY pArrray, DWORD dwIndex );
  561. SYSTEMTIME DynArrayItemAsSystemTime( TARRAY pArray, DWORD dwIndex );
  562. FILETIME DynArrayItemAsFileTime( TARRAY pArray, DWORD dwIndex );
  563. DWORD DynArrayItemAsStringEx( TARRAY pArray, DWORD dwIndex, LPTSTR szBuffer, DWORD dwLength );
  564. // ( for two-dimensional array )
  565. LPVOID DynArrayItem2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  566. LONG DynArrayItemAsLong2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  567. BOOL DynArrayItemAsBOOL2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  568. DWORD DynArrayItemAsDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  569. float DynArrayItemAsFloat2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  570. double DynArrayItemAsDouble2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  571. LPCTSTR DynArrayItemAsString2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  572. HANDLE DynArrayItemAsHandle2( TARRAY pArrray, DWORD dwRow, DWORD dwColumn );
  573. SYSTEMTIME DynArrayItemAsSystemTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  574. FILETIME DynArrayItemAsFileTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  575. DWORD DynArrayItemAsStringEx2( TARRAY pArray,
  576. DWORD dwRow, DWORD dwColumn, LPTSTR szBuffer, DWORD dwLength );
  577. //
  578. // array item removal function(s) ( for one-dimensional array )
  579. VOID DynArrayRemoveAll( TARRAY pArray );
  580. BOOL DynArrayRemove( TARRAY pArray, DWORD dwIndex );
  581. // ( for two-dimensional array )
  582. BOOL DynArrayRemoveColumn( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  583. //
  584. // find value function(s) ( for one-dimensional array )
  585. LONG DynArrayFindLong( TARRAY pArray, LONG lValue );
  586. LONG DynArrayFindDWORD( TARRAY pArray, DWORD dwValue );
  587. LONG DynArrayFindString( TARRAY pArray, LPCTSTR szValue, BOOL bIgnoreCase, DWORD dwCount );
  588. LONG DynArrayFindFloat( TARRAY pArray, float fValue );
  589. LONG DynArrayFindDouble( TARRAY pArray, double dblValue );
  590. LONG DynArrayFindHandle( TARRAY pArray, HANDLE hValue );
  591. LONG DynArrayFindSystemTime( TARRAY pArray, SYSTEMTIME stValue );
  592. LONG DynArrayFindFileTime( TARRAY pArray, FILETIME ftValue );
  593. // ( for two-dimensional array )
  594. LONG DynArrayFindLong2( TARRAY pArray, DWORD dwRow, LONG lValue );
  595. LONG DynArrayFindDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwValue );
  596. LONG DynArrayFindString2( TARRAY pArray, DWORD dwRow,
  597. LPCTSTR szValue, BOOL bIgnoreCase, DWORD dwCount );
  598. LONG DynArrayFindFloat2( TARRAY pArray, DWORD dwRow, float fValue );
  599. LONG DynArrayFindDouble2( TARRAY pArray, DWORD dwRow, double dblValue );
  600. LONG DynArrayFindHandle2( TARRAY pArray, DWORD dwRow, HANDLE hValue );
  601. LONG DynArrayFindSystemTime2( TARRAY pArray, DWORD dwRow, SYSTEMTIME stValue );
  602. LONG DynArrayFindFileTime2( TARRAY pArray, DWORD dwRow, FILETIME ftValue );
  603. // ( for two-dimensional array ... column wise searching )
  604. LONG DynArrayFindLongEx( TARRAY pArray, DWORD dwColumn, LONG lValue );
  605. LONG DynArrayFindDWORDEx( TARRAY pArray, DWORD dwColumn, DWORD dwValue );
  606. LONG DynArrayFindStringEx( TARRAY pArray, DWORD dwColumn,
  607. LPCTSTR szValue, BOOL bIgnoreCase, DWORD dwCount );
  608. LONG DynArrayFindFloatEx( TARRAY pArray, DWORD dwColumn, float fValue );
  609. LONG DynArrayFindDoubleEx( TARRAY pArray, DWORD dwColumn, double dblValue );
  610. LONG DynArrayFindHandleEx( TARRAY pArray, DWORD dwColumn, HANDLE hValue );
  611. LONG DynArrayFindSystemTimeEx( TARRAY pArray, DWORD dwColumn, SYSTEMTIME ftValue );
  612. LONG DynArrayFindFileTimeEx( TARRAY pArray, DWORD dwColumn, FILETIME ftValue );
  613. //
  614. // array attachment helpers ( one-dimensional )
  615. LONG DynArrayAppendEx( TARRAY pArray, TARRAY pArrItem );
  616. LONG DynArrayInsertEx( TARRAY pArray, DWORD dwIndex, TARRAY pArrItem );
  617. BOOL DynArraySetEx( TARRAY pArray, DWORD dwIndex, TARRAY pArrItem );
  618. // ( for two-dimensional array )
  619. LONG DynArrayAppendEx2( TARRAY pArray, DWORD dwRow, TARRAY pArrItem );
  620. LONG DynArrayInsertEx2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, TARRAY pArrItem );
  621. BOOL DynArraySetEx2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, TARRAY pArrItem );
  622. ///////////////////////////////////////////////////////////////////////////////
  623. // //
  624. // COMMONAND LINE PARSING //
  625. // //
  626. ///////////////////////////////////////////////////////////////////////////////
  627. //
  628. // constants / definitions / enumerations
  629. //
  630. // type ( dwType )
  631. #define CP_TYPE_TEXT 0x00000001 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0001
  632. #define CP_TYPE_NUMERIC 0x00000002 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0010
  633. #define CP_TYPE_UNUMERIC 0x00000003 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0011
  634. #define CP_TYPE_DATE 0x00000004 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0100
  635. #define CP_TYPE_TIME 0x00000005 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0101
  636. #define CP_TYPE_DATETIME 0x00000006 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0110
  637. #define CP_TYPE_FLOAT 0x00000007 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 0111
  638. #define CP_TYPE_DOUBLE 0x00000008 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 1000
  639. #define CP_TYPE_CUSTOM 0x00000009 // XXXX XXXX XXXX XXXX XXXX XXXX 0000 1001
  640. #define CP_TYPE_BOOLEAN 0x0000000A // XXXX XXXX XXXX XXXX XXXX XXXX 0000 1010
  641. #define CP_TYPE_MASK 0x000000FF // XXXX XXXX XXXX XXXX XXXX XXXX 1111 1111
  642. //
  643. // version 1
  644. //
  645. #define CP_MODE_ARRAY 0x00000100 // 0001 XXXX XXXX
  646. #define CP_MODE_VALUES 0x00000200 // 0010 XXXX XXXX
  647. #define CP_MODE_MASK 0x00000F00 // 1111 XXXX XXXX
  648. #define CP_VALUE_OPTIONAL 0x00001000 // 0001 XXXX XXXX XXXX
  649. #define CP_VALUE_MANDATORY 0x00002000 // 0010 XXXX XXXX XXXX
  650. #define CP_VALUE_NODUPLICATES 0x00004000 // 0100 XXXX XXXX XXXX
  651. #define CP_VALUE_NOLENGTHCHECK 0x00008000 // 1000 XXXX XXXX XXXX
  652. #define CP_VALUE_MASK 0x0000F000 // 1111 XXXX XXXX XXXX
  653. #define CP_MAIN_OPTION 0x00010000 // 0000 0000 0001 XXXX XXXX XXXX XXXX
  654. #define CP_USAGE 0x00020000 // 0000 0000 0010 XXXX XXXX XXXX XXXX
  655. #define CP_DEFAULT 0x00040000 // 0000 0000 0100 XXXX XXXX XXXX XXXX
  656. #define CP_MANDATORY 0x00080000 // 0000 0000 1000 XXXX XXXX XXXX XXXX
  657. #define CP_CASESENSITIVE 0x00100000 // 0000 0001 0000 XXXX XXXX XXXX XXXX
  658. #define CP_IGNOREVALUE 0x00200000 // 0000 0010 0000 XXXX XXXX XXXX XXXX
  659. #define CP_MASK 0x0FFF0000 // 1111 1111 1111 XXXX XXXX XXXX XXXX
  660. //
  661. // version 2
  662. //
  663. #define CP2_MODE_ARRAY 0x00000001 // XXXX XXXX XXXX XXXX XXXX XXXX XXXX 0001
  664. #define CP2_MODE_VALUES 0x00000002 // XXXX XXXX XXXX XXXX XXXX XXXX XXXX 0010
  665. #define CP2_MODE_MASK 0x0000000F // XXXX XXXX XXXX XXXX XXXX XXXX XXXX 1111
  666. #define CP2_VALUE_OPTIONAL 0x00000010 // XXXX XXXX XXXX XXXX 0000 0000 0001 XXXX
  667. #define CP2_VALUE_NODUPLICATES 0x00000020 // XXXX XXXX XXXX XXXX 0000 0000 0010 XXXX
  668. #define CP2_VALUE_TRIMINPUT 0x00000040 // XXXX XXXX XXXX XXXX 0000 0000 0100 XXXX
  669. #define CP2_VALUE_NONULL 0x00000080 // XXXX XXXX XXXX XXXX 0000 0000 1000 XXXX
  670. #define CP2_VALUE_MASK 0x0000FFF0 // XXXX XXXX XXXX XXXX 1111 1111 1111 XXXX
  671. #define CP2_ALLOCMEMORY 0x00010000 // XXXX 0000 0000 0001 XXXX XXXX XXXX XXXX
  672. #define CP2_USAGE 0x00020000 // XXXX 0000 0000 0010 XXXX XXXX XXXX XXXX
  673. #define CP2_DEFAULT 0x00040000 // XXXX 0000 0000 0100 XXXX XXXX XXXX XXXX
  674. #define CP2_MANDATORY 0x00080000 // XXXX 0000 0000 1000 XXXX XXXX XXXX XXXX
  675. #define CP2_CASESENSITIVE 0x00100000 // XXXX 0000 0001 0000 XXXX XXXX XXXX XXXX
  676. #define CP2_MASK 0x0FFF0000 // XXXX 1111 1111 1111 XXXX XXXX XXXX XXXX
  677. //
  678. // user defined types
  679. //
  680. typedef TCHAR OPTION[ 256 ];
  681. typedef TCHAR OPTVALUE[ 256 ];
  682. // custom value validation routine prototype
  683. typedef BOOL ( *PARSERFUNC )( LPCWSTR pwszOption, LPCWSTR pwszValue, LPVOID pData );
  684. typedef BOOL ( *PARSERFUNC2 )( LPCWSTR pwszOption, LPCWSTR pwszValue, LPVOID pData, DWORD* pdwIncrement );
  685. // command line parser -- version 1
  686. typedef struct __tagCmdParser
  687. {
  688. OPTION szOption; // options
  689. DWORD dwFlags; // flags ( specifies the type etc )
  690. DWORD dwCount; // tells the no. of times the option can repeat
  691. DWORD dwActuals; // no. of times the option actually repeated
  692. LPVOID pValue; // pointer to the option value
  693. OPTVALUE szValues; // to hold valid value in case flag = CP_MODE_VALUES
  694. PARSERFUNC pFunction; // pointer to custom value validation function
  695. LPVOID pFunctionData; // extra data that will be passed to custom function
  696. } TCMDPARSER;
  697. typedef TCMDPARSER* PTCMDPARSER;
  698. extern const CHAR cszParserSignature[ 8 ];
  699. // command line parser version 2
  700. typedef struct __tagCmdParser2
  701. {
  702. CHAR szSignature[ 8 ]; // should always be "PARSER2\0"
  703. DWORD dwType; // type of the argument
  704. DWORD64 dwFlags; // flags
  705. DWORD dwCount; // tells the no. of times the option can repeat
  706. DWORD dwActuals; // no. of times the option actually repeated
  707. LPCWSTR pwszOptions; // options
  708. LPCWSTR pwszFriendlyName; // specifies friendly name for the option
  709. LPCWSTR pwszValues; // to hold valid value in case flag = CP_MODE_VALUES
  710. // format that can be used for this
  711. // CP_TYPE_TEXT apple|orange|banana
  712. // ********************************************
  713. // CP_TYPE_NUMERIC 1,100;105;200,256;1000,
  714. // CP_TYPE_UNUMERIC (this example tells
  715. // argument can be any
  716. // number from 1 to 100
  717. // or 105 or 200 or
  718. // 256 or any value
  719. // greater than or
  720. // equal to 1000
  721. LPVOID pValue; // pointer to the option value
  722. DWORD dwLength; // max. length of argument value that can be stored
  723. // valid only for CP_TYPE_TEXT
  724. PARSERFUNC2 pFunction; // pointer to custom value validation function
  725. LPVOID pFunctionData; // extra data that will be passed to custom function
  726. DWORD dwReserved; // reserver for future use
  727. LPVOID pReserved1; // reserved for future use
  728. LPVOID pReserved2; // reserved for future use
  729. LPVOID pReserved3; // reserved for future use
  730. } TCMDPARSER2;
  731. typedef TCMDPARSER2* PTCMDPARSER2;
  732. BOOL DoParseParam2( DWORD dwCount,
  733. LPCWSTR argv[],
  734. LONG lSubOptionIndex,
  735. DWORD dwOptionsCount,
  736. PTCMDPARSER2 pcmdOptions,
  737. DWORD dwReserved );
  738. //
  739. // public function prototypes
  740. //
  741. LONG GetOptionCount( LPCTSTR szOption,
  742. DWORD dwCount, PTCMDPARSER pcmdOptions );
  743. BOOL DoParseParam( DWORD dwCount,
  744. LPCTSTR argv[],
  745. DWORD dwOptionsCount,
  746. PTCMDPARSER pcmdOptions );
  747. ///////////////////////////////////////////////////////////////////////////////
  748. // //
  749. // VALIDATING AND FILTERING RESULTS //
  750. // //
  751. ///////////////////////////////////////////////////////////////////////////////
  752. //
  753. // constants / definitions / enumerations
  754. //
  755. // types
  756. #define F_TYPE_TEXT 0x00000001 // 0000 0000 0001
  757. #define F_TYPE_NUMERIC 0x00000002 // 0000 0000 0010
  758. #define F_TYPE_UNUMERIC 0x00000003 // 0000 0000 0011
  759. #define F_TYPE_DATE 0x00000004 // 0000 0000 0100
  760. #define F_TYPE_TIME 0x00000005 // 0000 0000 0101
  761. #define F_TYPE_DATETIME 0x00000006 // 0000 0000 0110
  762. #define F_TYPE_FLOAT 0x00000007 // 0000 0000 0111
  763. #define F_TYPE_DOUBLE 0x00000008 // 0000 0000 1000
  764. #define F_TYPE_CUSTOM 0x00000009 // 0000 0000 1001
  765. #define F_TYPE_MASK 0x00000FFF // 1111 1111 1111
  766. // modes
  767. #define F_MODE_VALUES 0x00001000 // 0001 XXXX XXXX XXXX
  768. #define F_MODE_PATTERN 0x00002000 // 0010 XXXX XXXX XXXX
  769. #define F_MODE_ARRAY 0x00004000 // 0100 XXXX XXXX XXXX
  770. // custom filter data validation result
  771. #define F_FILTER_INVALID 0x00000000
  772. #define F_FILTER_VALID 0x00000001
  773. #define F_RESULT_KEEP 0x000000FF
  774. #define F_RESULT_REMOVE 0x00000000
  775. //
  776. // Bit no. 2 is '='
  777. // Bit no. 3 is '<'
  778. // Bit no. 4 is '>'
  779. //
  780. // 7654 3210
  781. // EQ 0000 0010 0x02
  782. // NE 1111 XX0X 0xFD
  783. // LT 0000 0100 0x04
  784. // GT 0000 1000 0x08
  785. // LE 0000 0110 0x06
  786. // GE 0000 1010 0x0A
  787. //
  788. #define MASK_EQ 0x00000002
  789. #define MASK_NE 0x000000FC
  790. #define MASK_LT 0x00000004
  791. #define MASK_GT 0x00000008
  792. #define MASK_LE 0x00000006
  793. #define MASK_GE 0x0000000A
  794. #define MASK_ALL 0x000000FF
  795. // mathematical operators
  796. #define MATH_EQ _T( "=" )
  797. #define MATH_NE _T( "!=" )
  798. #define MATH_LT _T( "<" )
  799. #define MATH_GT _T( ">" )
  800. #define MATH_LE _T( "<=" )
  801. #define MATH_GE _T( ">=" )
  802. // parsed filters information
  803. #define F_PARSED_INDEX_FILTER 0
  804. #define F_PARSED_INDEX_PROPERTY 1
  805. #define F_PARSED_INDEX_OPERATOR 2
  806. #define F_PARSED_INDEX_VALUE 3
  807. #define F_PARSED_INFO_COUNT 4
  808. //
  809. // structures / user defined data types
  810. //
  811. typedef TCHAR OPERATORS[ 101 ];
  812. typedef TCHAR FILTERVALUES[ 256 ];
  813. typedef TCHAR FILTERPROPERTY[ 256 ];
  814. // custom value validation routine prototype
  815. typedef DWORD ( *FILTERFUNC )( LPCTSTR pszProperty, LPCTSTR pszOperator,
  816. LPCTSTR pszValue, LPVOID pData, TARRAY arrRow );
  817. typedef struct __tagFilterConfig
  818. {
  819. DWORD dwColumn; // mapping from filter to column in data
  820. FILTERPROPERTY szProperty; // filter property
  821. OPERATORS szOperators; // valid operators for the filter
  822. DWORD dwFlags; // flags ( specifies the valid type for the filter )
  823. FILTERVALUES szValues; // to hold valid value in case flag = F_MODE_VALUES
  824. FILTERFUNC pFunction; // pointer to custom value validation function
  825. LPVOID pFunctionData; // extra data that will be passed to custom function
  826. } TFILTERCONFIG;
  827. typedef TFILTERCONFIG *PTFILTERCONFIG;
  828. //
  829. // public function prototypes
  830. //
  831. LPCTSTR FindOperator( LPCTSTR szOperator );
  832. BOOL ParseAndValidateFilter( DWORD dwCount,
  833. PTFILTERCONFIG pfilterConfigs,
  834. TARRAY arrFiltersArgs, PTARRAY parrParsedFilters );
  835. BOOL CanFilterRecord( DWORD dwCount,
  836. TFILTERCONFIG filterConfigs[],
  837. TARRAY arrRecord, TARRAY arrParsedFilters );
  838. DWORD FilterResults( DWORD dwCount,
  839. TFILTERCONFIG arrFilters[],
  840. TARRAY arrData, TARRAY arrParsedFilters );
  841. ///////////////////////////////////////////////////////////////////////////////
  842. // //
  843. // DISPLAYING RESULTS //
  844. // //
  845. ///////////////////////////////////////////////////////////////////////////////
  846. //
  847. // constants / definitions / enumerations
  848. //
  849. // formats
  850. #define SR_FORMAT_LIST 0x00000001 // 0000 0001
  851. #define SR_FORMAT_TABLE 0x00000002 // 0000 0010
  852. #define SR_FORMAT_CSV 0x00000003 // 0000 0011
  853. #define SR_FORMAT_MASK 0x0000000F // 1111 1111
  854. // column types
  855. #define SR_TYPE_NONE 0x00000000 // 0000 0000 0000 0000 XXXX XXXX
  856. #define SR_TYPE_STRING 0x00000010 // 0000 0000 0000 0001 XXXX XXXX
  857. #define SR_TYPE_NUMERIC 0x00000020 // 0000 0000 0000 0010 XXXX XXXX
  858. #define SR_TYPE_FLOAT 0x00000030 // 0000 0000 0000 0011 XXXX XXXX
  859. #define SR_TYPE_DOUBLE 0x00000040 // 0000 0000 0000 0100 XXXX XXXX
  860. #define SR_TYPE_DATE 0x00000050 // 0000 0000 0000 0101 XXXX XXXX
  861. #define SR_TYPE_TIME 0x00000060 // 0000 0000 0000 0110 XXXX XXXX
  862. #define SR_TYPE_DATETIME 0x00000070 // 0000 0000 0000 0111 XXXX XXXX
  863. #define SR_TYPE_CUSTOM 0x00000080 // 0000 0000 0000 1000 XXXX XXXX
  864. #define SR_TYPE_MASK 0x00000FF0 // 1111 1111 1111 1111 XXXX XXXX
  865. // flags ( global level )
  866. #define SR_NOHEADER 0x00001000 // 0000 0001 XXXX XXXX XXXX XXXX XXXX XXXX
  867. // flags ( column level )
  868. #define SR_HIDECOLUMN 0x00001000 // 0000 0000 0001 XXXX XXXX XXXX XXXX XXXX XXXX
  869. #define SR_VALUEFORMAT 0x00002000 // 0000 0000 0010 XXXX XXXX XXXX XXXX XXXX XXXX
  870. #define SR_ARRAY 0x00004000 // 0000 0000 0100 XXXX XXXX XXXX XXXX XXXX XXXX
  871. #define SR_WORDWRAP 0x00008000 // 0000 0000 1000 XXXX XXXX XXXX XXXX XXXX XXXX
  872. #define SR_ALIGN_LEFT 0x00010000 // 0000 0001 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  873. #define SR_ALIGN_RIGHT 0x00020000 // 0000 0010 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  874. #define SR_ALIGN_CENTER 0x00040000 // 0000 0100 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  875. #define SR_NO_TRUNCATION 0x00088000 // 0000 1000 1000 XXXX XXXX XXXX XXXX XXXX XXXX
  876. #define SR_SHOW_NA_WHEN_BLANK 0x00100000 // 0001 0000 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  877. //
  878. // user defined types
  879. //
  880. // custom value formatter
  881. typedef TCHAR COLHEADER[ 256 ];
  882. typedef TCHAR COLFORMAT[ 65 ];
  883. typedef VOID ( *FORMATFUNC )( DWORD dwColumn, TARRAY arrData, LPVOID pData, LPTSTR szValue );
  884. typedef struct __tagColumns
  885. {
  886. COLHEADER szColumn; // column header name
  887. DWORD dwWidth; // width of each field
  888. DWORD dwFlags; // flags ( specifies the type etc )
  889. COLFORMAT szFormat; // custom format
  890. FORMATFUNC pFunction; // formatter function
  891. LPVOID pFunctionData; // function data
  892. } TCOLUMNS;
  893. typedef TCOLUMNS* PTCOLUMNS;
  894. //
  895. // public functions
  896. //
  897. VOID ShowResults( DWORD dwColumns, PTCOLUMNS pColumns, DWORD dwFlags, TARRAY arrData );
  898. ///////////////////////////////////////////////////////////////////////////////////
  899. // COMING UP *** DO NOT USE UNLESS INTIMATED //
  900. ///////////////////////////////////////////////////////////////////////////////////
  901. VOID ShowResults2( FILE* fp, DWORD dwColumns, PTCOLUMNS pColumns, DWORD dwFlags, TARRAY arrData );
  902. ///////////////////////////////////////////////////////////////////////////////////
  903. #ifdef __cplusplus
  904. }
  905. #endif
  906. #endif // __CMDLINE_H