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.

818 lines
32 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 definitions
  12. //
  13. // Author:
  14. //
  15. // Sunil G.V.N. Murali ([email protected]) 1-Sep-2000
  16. //
  17. // Revision History:
  18. //
  19. // Sunil G.V.N. Murali ([email protected]) 1-Sep-2000 : Created It.
  20. //
  21. // *********************************************************************************
  22. #ifndef __CMDLINE_H
  23. #define __CMDLINE_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. // //
  29. // COMMON FUNCTIONALITY //
  30. // //
  31. ///////////////////////////////////////////////////////////////////////////////////
  32. //
  33. // custom macros ( for trapping memory leaks )
  34. //
  35. #ifdef _DEBUG
  36. #define __malloc( size ) \
  37. _malloc_dbg( size, _NORMAL_BLOCK, __FILE__, __LINE__ )
  38. #define __calloc( count, size ) \
  39. _calloc_dbg( count, size, _NORMAL_BLOCK, __FILE__, __LINE__ )
  40. #define __free( block ) \
  41. if ( (block) != NULL ) \
  42. { \
  43. _free_dbg( (block), _NORMAL_BLOCK ); \
  44. (block) = NULL; \
  45. } \
  46. 1
  47. #define __realloc( block, size ) \
  48. (((block) != NULL) ? \
  49. _realloc_dbg( (block), size, _NORMAL_BLOCK, __FILE__, __LINE__ ) : __malloc( size ))
  50. #else
  51. #define __malloc( size ) \
  52. malloc( size )
  53. #define __calloc( count, size ) \
  54. calloc( count, size )
  55. #define __free( block ) \
  56. if ( (block) != NULL ) \
  57. { \
  58. free( (block) ); \
  59. (block) = NULL; \
  60. } \
  61. 1
  62. #define __realloc( block, size ) \
  63. (((block) != NULL) ? realloc( block, size ) : __malloc( size ))
  64. #endif
  65. //
  66. // custom macros ( for NULL pointer assignments handling )
  67. //
  68. #define CHECK_NULL( statement, value ) \
  69. if ( ( statement ) == NULL ) \
  70. { \
  71. return value; \
  72. } \
  73. 1
  74. // wrappers for quote meta
  75. #define _X( text ) QuoteMeta( text, 1 )
  76. #define _X1( text ) QuoteMeta( text, 1 )
  77. #define _X2( text ) QuoteMeta( text, 2 )
  78. #define _X3( text ) QuoteMeta( text, 3 )
  79. //
  80. // function re-defs
  81. //
  82. #ifdef UNICODE
  83. #define GetCompatibleStringFromMultiByte GetAsUnicodeStringEx
  84. #define GetCompatibleStringFromUnicode GetAsUnicodeString
  85. #else
  86. #define GetCompatibleStringFromMultiByte GetAsMultiByteString
  87. #define GetCompatibleStringFromUnicode GetAsMultiByteStringEx
  88. #endif // UNICODE
  89. //
  90. // error codes
  91. //
  92. #define E_LOCAL_CREDENTIALS 0xA0010001 // 1010 0000 0000 0001 0000 0000 0000 0001
  93. #define I_NO_CLOSE_CONNECTION 0x50010001 // 0101 0000 0000 0001 0000 0000 0000 0001
  94. //
  95. // macros
  96. //
  97. #define SIZE_OF_ARRAY( array ) ( sizeof( array ) / sizeof( array[ 0 ] ) )
  98. #define TAG_ERROR GetResString( IDS_TAG_ERROR )
  99. #define TAG_WARNING GetResString( IDS_TAG_WARNING )
  100. #define TAG_SUCCESS GetResString( IDS_TAG_SUCCESS )
  101. #define TAG_INFORMATION GetResString( IDS_TAG_INFORMATION )
  102. #define SHOW_RESULT_MESSAGE( server, tag, message ) \
  103. if ( IsLocalSystem( server ) == TRUE ) \
  104. { \
  105. DISPLAY_MESSAGE2( stderr, szBuffer, _T( "%s %s" ), tag, message ); \
  106. } \
  107. else \
  108. { \
  109. DISPLAY_MESSAGE3( stderr, szBuffer, _T( "%s %s: %s" ), tag, server, message ); \
  110. } \
  111. 1
  112. //
  113. // string formatting stubs
  114. #define FORMAT_STRING( buffer, format, value ) \
  115. wsprintf( buffer, format, value )
  116. #define FORMAT_STRING2( buffer, format, value1, value2 ) \
  117. wsprintf( buffer, format, value1, value2 )
  118. #define FORMAT_STRING3( buffer, format, value1, value2, value3 ) \
  119. wsprintf( buffer, format, value1, value2, value3 )
  120. #define FORMAT_STRING_EX( buffer, format, value, length, alignflag ) \
  121. wsprintf( buffer, format, value ); \
  122. AdjustStringLength( buffer, length, alignflag )
  123. #define FORMAT_STRING_EX2( buffer, format, value1, value2, length, alignflag ) \
  124. wsprintf( buffer, format, value1, value2 ); \
  125. AdjustStringLength( buffer, length, alignflag )
  126. #define FORMAT_STRING_EX3( buffer, format, value1, value2, value3, length, alignflag ) \
  127. wsprintf( buffer, format, value1, value2, value3 ); \
  128. AdjustStringLength( buffer, length, alignflag )
  129. //
  130. // stubs for 'displaying'
  131. #define DISPLAY_MESSAGE( file, message ) \
  132. ShowMessage( file, message )
  133. #define DISPLAY_MESSAGE1( file, buffer, format, value1 ) \
  134. FORMAT_STRING( buffer, format, value1 ); \
  135. ShowMessage( file, buffer )
  136. #define DISPLAY_MESSAGE2( file, buffer, format, value1, value2 ) \
  137. FORMAT_STRING2( buffer, format, value1, value2 ); \
  138. ShowMessage( file, buffer )
  139. #define DISPLAY_MESSAGE3( file, buffer, format, value1, value2, value3 ) \
  140. FORMAT_STRING3( buffer, format, value1, value2, value3 ); \
  141. ShowMessage( file, buffer )
  142. //
  143. // display messages from resource file's string table ( stubs )
  144. #define DISPLAY_RES_MESSAGE( file, id ) \
  145. ShowResMessage( file, id )
  146. #define DISPLAY_RES_MESSAGE1( file, buffer, id, value1 ) \
  147. FORMAT_STRING( buffer, GetResString( id ), value1 ); \
  148. ShowMessage( file, buffer )
  149. #define DISPLAY_RES_MESSAGE2( file, buffer, id, value1, value2 ) \
  150. FORMAT_STRING2( buffer, GetResString( id ), value1, value2 ); \
  151. ShowMessage( file, buffer )
  152. #define DISPLAY_RES_MESSAGE3( file, buffer, id, value1, value2, value3 ) \
  153. FORMAT_STRING3( buffer, GetResString( id ), value1, value2, value3 ); \
  154. ShowMessage( file, buffer )
  155. //
  156. // constants / defines / enumerations
  157. //
  158. #define _DEFAULT_CODEPAGE CP_OEMCP
  159. #define BACK_SPACE 0x08
  160. #define BLANK_CHAR 0x00
  161. #define CARRIAGE_RETURN 0x0D
  162. #define ASTERIX _T( "*" )
  163. #define BEEP_SOUND _T( "\a" )
  164. #define MAX_RES_STRING 254
  165. #define MAX_STRING_LENGTH 254
  166. #define MAX_USERNAME_LENGTH 64
  167. #define MAX_PASSWORD_LENGTH 64
  168. #define TRIM_LEFT 0x00000001
  169. #define TRIM_RIGHT 0x00000002
  170. #define TRIM_ALL 0x00000003
  171. #define NULL_CHAR _T( '\0' )
  172. #define NULL_STRING _T( "\0" )
  173. #define FULL_SUCCESS 0
  174. #define PARTIALLY_SUCCESS 128
  175. #define COMPLETELY_FAILED 255
  176. #define V_NOT_AVAILABLE GetResString( IDS_V_NOT_AVAILABLE )
  177. #define ERROR_OS_INCOMPATIBLE GetResString( IDS_ERROR_OS_INCOMPATIBLE )
  178. //
  179. // type definitions
  180. //
  181. typedef TCHAR __STRING_32[ 32 ];
  182. typedef TCHAR __STRING_64[ 64 ];
  183. typedef TCHAR __STRING_128[ 128 ];
  184. typedef TCHAR __STRING_256[ 256 ];
  185. typedef TCHAR __STRING_512[ 512 ];
  186. typedef TCHAR __STRING_1024[ 1024 ];
  187. typedef TCHAR __STRING_2048[ 2048 ];
  188. typedef TCHAR __STRING_4096[ 4096 ];
  189. typedef TCHAR __RESOURCE_STRING [ MAX_RES_STRING + 1 ];
  190. typedef TCHAR __MAX_SIZE_STRING[ MAX_STRING_LENGTH + 1 ];
  191. //
  192. // structs
  193. //
  194. typedef struct tagConnectionInfo
  195. {
  196. DWORD dwFlags; // flags
  197. LPCTSTR pszServer; // server name
  198. LPTSTR pszUserName; // user name
  199. DWORD dwUserLength; // max. no. of characters allowed for user name
  200. LPTSTR pszPassword; // password
  201. DWORD dwPasswordLength; // max. no. of characters allowed for password
  202. LPCTSTR pszShare; // tells the custom share name
  203. LPVOID lpReserved1; // reserved for future use
  204. LPVOID lpReserved2; // reserved for future use
  205. LPVOID lpReserved3; // reserved for future use
  206. } TCONNECTIONINFO, *PTCONNECTIONINFO;
  207. //
  208. // connection info flags
  209. //
  210. // general flags
  211. #define CI_ACCEPT_PASSWORD 0x00000001 // 0000 0001
  212. // share
  213. #define CI_SHARE_NONE 0x00000000 // 0000 0000 0000 XXXX XXXX ( default )
  214. #define CI_SHARE_IPC 0x00000010 // 0000 0000 0001 XXXX XXXX
  215. #define CI_SHARE_ADMIN 0x00000020 // 0000 0000 0010 XXXX XXXX
  216. #define CI_SHARE_CDRIVE 0x00000040 // 0000 0000 0100 XXXX XXXX
  217. #define CI_SHARE_DDRIVE 0x00000080 // 0000 0000 1000 XXXX XXXX
  218. #define CI_SHARE_CUSTOM 0x00000100 // 0000 0001 0000 XXXX XXXX
  219. // extra flag used while closing connection
  220. #define CI_CLOSE_BY_FORCE 0x10000000
  221. //
  222. // function prototypes
  223. //
  224. //
  225. // remote connectivity related function prototypes
  226. BOOL SetOsVersion( DWORD dwMajor, DWORD dwMinor, WORD wServicePackMajor );
  227. BOOL IsWin2KOrLater();
  228. DWORD GetTargetVersion( LPCTSTR pszServer );
  229. BOOL IsCompatibleOperatingSystem( DWORD dwVersion );
  230. BOOL IsValidServer( LPCTSTR pszServer );
  231. BOOL IsValidIPAddress( LPCTSTR pszAddress );
  232. DWORD CloseConnection( LPCTSTR szServer );
  233. DWORD ConnectServer( LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword );
  234. BOOL IsUNCFormat( LPCTSTR pszServer );
  235. BOOL IsLocalSystem( LPCTSTR pszServer );
  236. LPCTSTR QuoteMeta( LPCTSTR pszText, DWORD dwQuoteIndex );
  237. LPCTSTR FindChar( LPCTSTR pszTemp, TCHAR ch, DWORD dwFrom );
  238. LPCTSTR FindOneOf( LPCTSTR pszText, LPCTSTR pszTextToFind, DWORD dwFrom );
  239. LPCTSTR FindString( LPCTSTR pszText, LPCTSTR pszTextToFind, DWORD dwFrom );
  240. BOOL GetHostByIPAddr( LPCTSTR pszServer, LPTSTR pszHostName, BOOL bNeedFQDN );
  241. BOOL EstablishConnection( LPCTSTR szServer, LPTSTR szUserName, DWORD dwUserLength,
  242. LPTSTR szPassword, DWORD dwPasswordLength, BOOL bNeedPassword );
  243. ///////////////////////
  244. // stubs
  245. #define CleanExit( dwExitCode ) ExitProcess( dwExitCode )
  246. ///////////////////////////////////////////////////////////////////////////////////
  247. // COMING UP *** DO NOT USE UNLESS INTIMATED //
  248. ///////////////////////////////////////////////////////////////////////////////////
  249. BOOL EstablishConnectionEx( PTCONNECTIONINFO pci );
  250. DWORD ConnectServer2( LPCTSTR szServer,
  251. LPCTSTR szUser, LPCTSTR szPassword, LPCTSTR pszShare );
  252. DWORD CloseConnection2( LPCTSTR szServer, LPCTSTR pszShare, DWORD dwFlags );
  253. ///////////////////////////////////////////////////////////////////////////////////
  254. //
  255. // other(s)
  256. LPCTSTR GetReason();
  257. VOID SaveLastError();
  258. VOID ReleaseGlobals();
  259. DWORD WNetSaveLastError();
  260. VOID ShowLastError( FILE* fp );
  261. LPCTSTR GetResString( UINT uID );
  262. double AsFloat( LPCTSTR szValue );
  263. LPTSTR GetResStringEx( UINT uID );
  264. VOID SetReason( LPCTSTR szReason );
  265. DWORD WNetShowLastError( FILE* fp );
  266. BOOL IsFloatingPoint( LPCTSTR szValue );
  267. VOID ShowResMessage( FILE* fp, UINT uID );
  268. LONG AsLong( LPCTSTR szValue, DWORD dwBase );
  269. VOID ShowMessage( FILE* fp, LPCTSTR szMessage );
  270. LPTSTR TrimString( LPTSTR lpsz, DWORD dwFlags );
  271. BOOL IsNumeric( LPCTSTR szValue, DWORD dwBase, BOOL bSigned );
  272. BOOL GetPassword( LPTSTR pszPassword, DWORD dwMaxPasswordSize );
  273. LPTSTR Replicate( LPTSTR pszBuffer, LPCTSTR szChar, DWORD dwCount );
  274. BOOL InString( LPCTSTR szString, LPCTSTR szList, BOOL bIgnoreCase );
  275. DWORD LoadResString( UINT uID, LPTSTR pszValue, DWORD dwBufferMax );
  276. LONG StringLengthInBytes( LPCTSTR pszText );
  277. LPTSTR AdjustStringLength( LPTSTR szValue, DWORD dwLength, BOOL bPadLeft );
  278. LPSTR GetAsMultiByteString( LPCTSTR pszSource, LPSTR pszDestination, DWORD dwLength );
  279. LPSTR GetAsMultiByteStringEx( LPCWSTR pwszSource, LPSTR pszDestination, DWORD dwLength );
  280. LPWSTR GetAsUnicodeString( LPCTSTR pszSource, LPWSTR pwszDestination, DWORD dwLength );
  281. LPWSTR GetAsUnicodeStringEx( LPCSTR pszSource, LPWSTR pwszDestination, DWORD dwLength );
  282. LONG StringCompare( LPCTSTR szString1, LPCTSTR szString2, BOOL bIgnoreCase, DWORD dwCount );
  283. ///////////////////////////////////////////////////////////////////////////////////
  284. // //
  285. // MULTI-DIMENSIONAL MULTI-TYPE DYNAMIC ARRAYS //
  286. // //
  287. ///////////////////////////////////////////////////////////////////////////////////
  288. //
  289. // constants / defines / enumerations
  290. //
  291. // item types supported by dynamic array
  292. #define DA_TYPE_NONE 0x00000000
  293. #define DA_TYPE_GENERAL 0x00010000
  294. #define DA_TYPE_STRING 0x00020000
  295. #define DA_TYPE_LONG 0x00030000
  296. #define DA_TYPE_DWORD 0x00040000
  297. #define DA_TYPE_BOOL 0x00050000
  298. #define DA_TYPE_FLOAT 0x00060000
  299. #define DA_TYPE_DOUBLE 0x00070000
  300. #define DA_TYPE_ARRAY 0x00080000
  301. #define DA_TYPE_HANDLE 0x00090000
  302. #define DA_TYPE_SYSTEMTIME 0x000A0000
  303. #define DA_TYPE_FILETIME 0x000B0000
  304. //
  305. // type definitions
  306. //
  307. typedef VOID* TARRAY;
  308. typedef TARRAY* PTARRAY;
  309. //
  310. // public function prototypes
  311. //
  312. //
  313. // array pointer validation function(s)
  314. BOOL IsValidArray( TARRAY pArray );
  315. //
  316. // dynamic array creation / destraction functions
  317. TARRAY CreateDynamicArray();
  318. VOID DestroyDynamicArray( PTARRAY pArray );
  319. //
  320. // general helper function(s)
  321. DWORD DynArrayGetCount( TARRAY pArray );
  322. DWORD DynArrayGetCount2( TARRAY pArray, DWORD dwRow );
  323. DWORD DynArrayGetItemType( TARRAY pArray, DWORD dwIndex );
  324. DWORD DynArrayGetItemType2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  325. //
  326. // adding columns
  327. DWORD DynArrayAddColumns( TARRAY pArray, DWORD dwColumns );
  328. DWORD DynArrayInsertColumns( TARRAY pArray, DWORD dwIndex, DWORD dwColumns );
  329. //
  330. // array append function(s) ( for one-dimensional array )
  331. LONG DynArrayAppend( TARRAY pArray, LPVOID pValue );
  332. LONG DynArrayAppendLong( TARRAY pArray, LONG lValue );
  333. LONG DynArrayAppendBOOL( TARRAY pArray, BOOL bValue );
  334. LONG DynArrayAppendDWORD( TARRAY pArray, DWORD dwValue );
  335. LONG DynArrayAppendFloat( TARRAY pArray, float dwValue );
  336. LONG DynArrayAppendDouble( TARRAY pArray, double dwValue );
  337. LONG DynArrayAppendString( TARRAY pArray, LPCTSTR szValue, DWORD dwLength );
  338. LONG DynArrayAppendHandle( TARRAY pArray, HANDLE hValue );
  339. LONG DynArrayAppendSystemTime( TARRAY pArray, SYSTEMTIME stValue );
  340. LONG DynArrayAppendFileTime( TARRAY pArray, FILETIME ftValue );
  341. // helper to append 2-dimensional array
  342. LONG DynArrayAppendRow( TARRAY pArray, DWORD dwColumns );
  343. // ( for two-dimensional array )
  344. LONG DynArrayAppend2( TARRAY pArray, DWORD dwRow, LPVOID pValue );
  345. LONG DynArrayAppendLong2( TARRAY pArray, DWORD dwRow, LONG lValue );
  346. LONG DynArrayAppendBOOL2( TARRAY pArray, DWORD dwRow, BOOL bValue );
  347. LONG DynArrayAppendDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwValue );
  348. LONG DynArrayAppendFloat2( TARRAY pArray, DWORD dwRow, float dwValue );
  349. LONG DynArrayAppendDouble2( TARRAY pArray, DWORD dwRow, double dwValue );
  350. LONG DynArrayAppendString2( TARRAY pArray, DWORD dwRow, LPCTSTR szValue, DWORD dwLength );
  351. LONG DynArrayAppendHandle2( TARRAY pArray, DWORD dwRow, HANDLE hValue );
  352. LONG DynArrayAppendSystemTime2( TARRAY pArray, DWORD dwRow, SYSTEMTIME stValue );
  353. LONG DynArrayAppendFileTime2( TARRAY pArray, DWORD dwRow, FILETIME ftValue );
  354. //
  355. // array insert function(s) ( for one-dimensional array )
  356. LONG DynArrayInsert( TARRAY pArray, DWORD dwIndex, LPVOID pValue );
  357. LONG DynArrayInsertLong( TARRAY pArray, DWORD dwIndex, LONG lValue );
  358. LONG DynArrayInsertBOOL( TARRAY pArray, DWORD dwIndex, BOOL bValue );
  359. LONG DynArrayInsertDWORD( TARRAY pArray, DWORD dwIndex, DWORD dwValue );
  360. LONG DynArrayInsertFloat( TARRAY pArray, DWORD dwIndex, float dwValue );
  361. LONG DynArrayInsertDouble( TARRAY pArray, DWORD dwIndex, double dwValue );
  362. LONG DynArrayInsertString( TARRAY pArray, DWORD dwIndex, LPCTSTR szValue, DWORD dwLength );
  363. LONG DynArrayInsertHandle( TARRAY pArray, DWORD dwIndex, HANDLE hValue );
  364. LONG DynArrayInsertSystemTime( TARRAY pArray, DWORD dwIndex, SYSTEMTIME stValue );
  365. LONG DynArrayInsertFileTime( TARRAY pArray, DWORD dwIndex, FILETIME ftValue );
  366. // helper to insert 2-dimensional array
  367. LONG DynArrayInsertRow( TARRAY pArray, DWORD dwIndex, DWORD dwColumns );
  368. // ( for two-dimensional array )
  369. LONG DynArrayInsert2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, LPVOID pValue );
  370. LONG DynArrayInsertLong2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, LONG lValue );
  371. LONG DynArrayInsertBOOL2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, BOOL bValue );
  372. LONG DynArrayInsertDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, DWORD dwValue );
  373. LONG DynArrayInsertFloat2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, float dwValue );
  374. LONG DynArrayInsertDouble2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, double dwValue );
  375. LONG DynArrayInsertString2( TARRAY pArray, DWORD dwRow,
  376. DWORD dwColIndex, LPCTSTR szValue, DWORD dwLength );
  377. LONG DynArrayInsertHandle2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, HANDLE hValue );
  378. LONG DynArrayInsertSystemTime2( TARRAY pArray, DWORD dwRow,
  379. DWORD dwColIndex, SYSTEMTIME stValue );
  380. LONG DynArrayInsertFileTime2( TARRAY pArray, DWORD dwRow,
  381. DWORD dwColIndex, FILETIME ftValue );
  382. //
  383. // item value set function(s) ( for one-dimensional array )
  384. BOOL DynArraySet( TARRAY pArray, DWORD dwIndex, LPVOID pValue );
  385. BOOL DynArraySetLong( TARRAY pArray, DWORD dwIndex, LONG lValue );
  386. BOOL DynArraySetBOOL( TARRAY pArray, DWORD dwIndex, BOOL bValue );
  387. BOOL DynArraySetDWORD( TARRAY pArray, DWORD dwIndex, DWORD dwValue );
  388. BOOL DynArraySetFloat( TARRAY pArray, DWORD dwIndex, float dwValue );
  389. BOOL DynArraySetDouble( TARRAY pArray, DWORD dwIndex, double dwValue );
  390. BOOL DynArraySetString( TARRAY pArray, DWORD dwIndex, LPCTSTR szValue, DWORD dwLength );
  391. BOOL DynArraySetHandle( TARRAY pArray, DWORD dwIndex, HANDLE hValue );
  392. BOOL DynArraySetSystemTime( TARRAY pArray, DWORD dwIndex, SYSTEMTIME stValue );
  393. BOOL DynArraySetFileTime( TARRAY pArray, DWORD dwIndex, FILETIME ftValue );
  394. // ( for two-dimensional array )
  395. BOOL DynArraySet2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, LPVOID pValue );
  396. BOOL DynArraySetLong2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, LONG lValue );
  397. BOOL DynArraySetBOOL2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, BOOL bValue );
  398. BOOL DynArraySetDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, DWORD dwValue );
  399. BOOL DynArraySetFloat2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, float dwValue );
  400. BOOL DynArraySetDouble2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, double dwValue );
  401. BOOL DynArraySetString2( TARRAY pArray, DWORD dwRow,
  402. DWORD dwColumn, LPCTSTR szValue, DWORD dwLength );
  403. BOOL DynArraySetHandle2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, HANDLE hValue );
  404. BOOL DynArraySetSystemTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, SYSTEMTIME stValue );
  405. BOOL DynArraySetFileTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, FILETIME ftValue );
  406. //
  407. // item value get function(s) ( for one-dimensional array )
  408. LPVOID DynArrayItem( TARRAY pArray, DWORD dwIndex );
  409. LONG DynArrayItemAsLong( TARRAY pArray, DWORD dwIndex );
  410. BOOL DynArrayItemAsBOOL( TARRAY pArray, DWORD dwIndex );
  411. DWORD DynArrayItemAsDWORD( TARRAY pArray, DWORD dwIndex );
  412. float DynArrayItemAsFloat( TARRAY pArray, DWORD dwIndex );
  413. double DynArrayItemAsDouble( TARRAY pArray, DWORD dwIndex );
  414. LPCTSTR DynArrayItemAsString( TARRAY pArray, DWORD dwIndex );
  415. HANDLE DynArrayItemAsHandle( TARRAY pArrray, DWORD dwIndex );
  416. SYSTEMTIME DynArrayItemAsSystemTime( TARRAY pArray, DWORD dwIndex );
  417. FILETIME DynArrayItemAsFileTime( TARRAY pArray, DWORD dwIndex );
  418. DWORD DynArrayItemAsStringEx( TARRAY pArray, DWORD dwIndex, LPTSTR szBuffer, DWORD dwLength );
  419. // ( for two-dimensional array )
  420. LPVOID DynArrayItem2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  421. LONG DynArrayItemAsLong2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  422. BOOL DynArrayItemAsBOOL2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  423. DWORD DynArrayItemAsDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  424. float DynArrayItemAsFloat2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  425. double DynArrayItemAsDouble2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  426. LPCTSTR DynArrayItemAsString2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  427. HANDLE DynArrayItemAsHandle2( TARRAY pArrray, DWORD dwRow, DWORD dwColumn );
  428. SYSTEMTIME DynArrayItemAsSystemTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  429. FILETIME DynArrayItemAsFileTime2( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  430. DWORD DynArrayItemAsStringEx2( TARRAY pArray,
  431. DWORD dwRow, DWORD dwColumn, LPTSTR szBuffer, DWORD dwLength );
  432. //
  433. // array item removal function(s) ( for one-dimensional array )
  434. VOID DynArrayRemoveAll( TARRAY pArray );
  435. BOOL DynArrayRemove( TARRAY pArray, DWORD dwIndex );
  436. // ( for two-dimensional array )
  437. BOOL DynArrayRemoveColumn( TARRAY pArray, DWORD dwRow, DWORD dwColumn );
  438. //
  439. // find value function(s) ( for one-dimensional array )
  440. LONG DynArrayFindLong( TARRAY pArray, LONG lValue );
  441. LONG DynArrayFindDWORD( TARRAY pArray, DWORD dwValue );
  442. LONG DynArrayFindString( TARRAY pArray, LPCTSTR szValue, BOOL bIgnoreCase, DWORD dwCount );
  443. LONG DynArrayFindFloat( TARRAY pArray, float fValue );
  444. LONG DynArrayFindDouble( TARRAY pArray, double dblValue );
  445. LONG DynArrayFindHandle( TARRAY pArray, HANDLE hValue );
  446. LONG DynArrayFindSystemTime( TARRAY pArray, SYSTEMTIME stValue );
  447. LONG DynArrayFindFileTime( TARRAY pArray, FILETIME ftValue );
  448. // ( for two-dimensional array )
  449. LONG DynArrayFindLong2( TARRAY pArray, DWORD dwRow, LONG lValue );
  450. LONG DynArrayFindDWORD2( TARRAY pArray, DWORD dwRow, DWORD dwValue );
  451. LONG DynArrayFindString2( TARRAY pArray, DWORD dwRow,
  452. LPCTSTR szValue, BOOL bIgnoreCase, DWORD dwCount );
  453. LONG DynArrayFindFloat2( TARRAY pArray, DWORD dwRow, float fValue );
  454. LONG DynArrayFindDouble2( TARRAY pArray, DWORD dwRow, double dblValue );
  455. LONG DynArrayFindHandle2( TARRAY pArray, DWORD dwRow, HANDLE hValue );
  456. LONG DynArrayFindSystemTime2( TARRAY pArray, DWORD dwRow, SYSTEMTIME stValue );
  457. LONG DynArrayFindFileTime2( TARRAY pArray, DWORD dwRow, FILETIME ftValue );
  458. // ( for two-dimensional array ... column wise searching )
  459. LONG DynArrayFindLongEx( TARRAY pArray, DWORD dwColumn, LONG lValue );
  460. LONG DynArrayFindDWORDEx( TARRAY pArray, DWORD dwColumn, DWORD dwValue );
  461. LONG DynArrayFindStringEx( TARRAY pArray, DWORD dwColumn,
  462. LPCTSTR szValue, BOOL bIgnoreCase, DWORD dwCount );
  463. LONG DynArrayFindFloatEx( TARRAY pArray, DWORD dwColumn, float fValue );
  464. LONG DynArrayFindDoubleEx( TARRAY pArray, DWORD dwColumn, double dblValue );
  465. LONG DynArrayFindHandleEx( TARRAY pArray, DWORD dwColumn, HANDLE hValue );
  466. LONG DynArrayFindSystemTimeEx( TARRAY pArray, DWORD dwColumn, SYSTEMTIME ftValue );
  467. LONG DynArrayFindFileTimeEx( TARRAY pArray, DWORD dwColumn, FILETIME ftValue );
  468. //
  469. // array attachment helpers ( one-dimensional )
  470. LONG DynArrayAppendEx( TARRAY pArray, TARRAY pArrItem );
  471. LONG DynArrayInsertEx( TARRAY pArray, DWORD dwIndex, TARRAY pArrItem );
  472. BOOL DynArraySetEx( TARRAY pArray, DWORD dwIndex, TARRAY pArrItem );
  473. // ( for two-dimensional array )
  474. LONG DynArrayAppendEx2( TARRAY pArray, DWORD dwRow, TARRAY pArrItem );
  475. LONG DynArrayInsertEx2( TARRAY pArray, DWORD dwRow, DWORD dwColIndex, TARRAY pArrItem );
  476. BOOL DynArraySetEx2( TARRAY pArray, DWORD dwRow, DWORD dwColumn, TARRAY pArrItem );
  477. ///////////////////////////////////////////////////////////////////////////////////
  478. // //
  479. // COMMONAND LINE PARSING //
  480. // //
  481. ///////////////////////////////////////////////////////////////////////////////////
  482. //
  483. // constants / definitions / enumerations
  484. //
  485. #define CP_TYPE_TEXT 0x00000001 // 0000 0001
  486. #define CP_TYPE_NUMERIC 0x00000002 // 0000 0010
  487. #define CP_TYPE_UNUMERIC 0x00000003 // 0000 0011
  488. #define CP_TYPE_DATE 0x00000004 // 0000 0100
  489. #define CP_TYPE_TIME 0x00000005 // 0000 0101
  490. #define CP_TYPE_DATETIME 0x00000006 // 0000 0110
  491. #define CP_TYPE_FLOAT 0x00000007 // 0000 0111
  492. #define CP_TYPE_DOUBLE 0x00000008 // 0000 1000
  493. #define CP_TYPE_CUSTOM 0x00000009 // 0000 1001
  494. #define CP_TYPE_MASK 0x000000FF // 1111 1111
  495. #define CP_MODE_ARRAY 0x00000100 // 0001 XXXX XXXX
  496. #define CP_MODE_VALUES 0x00000200 // 0010 XXXX XXXX
  497. #define CP_MODE_MASK 0x00000F00 // 1111 XXXX XXXX
  498. #define CP_VALUE_OPTIONAL 0x00001000 // 0001 XXXX XXXX XXXX
  499. #define CP_VALUE_MANDATORY 0x00002000 // 0010 XXXX XXXX XXXX
  500. #define CP_VALUE_NODUPLICATES 0x00004000 // 0100 XXXX XXXX XXXX
  501. #define CP_VALUE_MASK 0x0000F000 // 1111 XXXX XXXX XXXX
  502. #define CP_MAIN_OPTION 0x00010000 // 0000 0000 0001 XXXX XXXX XXXX XXXX
  503. #define CP_USAGE 0x00020000 // 0000 0000 0010 XXXX XXXX XXXX XXXX
  504. #define CP_DEFAULT 0x00040000 // 0000 0000 0100 XXXX XXXX XXXX XXXX
  505. #define CP_MANDATORY 0x00080000 // 0000 0000 1000 XXXX XXXX XXXX XXXX
  506. #define CP_CASESENSITIVE 0x00100000 // 0000 0001 0000 XXXX XXXX XXXX XXXX
  507. #define CP_IGNOREVALUE 0x00200000 // 0000 0010 0000 XXXX XXXX XXXX XXXX
  508. #define CP_MASK 0x0FFF0000 // 1111 1111 1111 XXXX XXXX XXXX XXXX
  509. //
  510. // user defined types
  511. //
  512. typedef TCHAR OPTION[ 256 ];
  513. typedef TCHAR OPTVALUE[ 256 ];
  514. // custom value validation routine prototype
  515. typedef BOOL ( *PARSERFUNC )( LPCTSTR pszOption, LPCTSTR pszValue, LPVOID pData );
  516. typedef struct __tagCmdParser
  517. {
  518. OPTION szOption; // options
  519. DWORD dwFlags; // flags ( specifies the type etc )
  520. DWORD dwCount; // tells the no. of times the option can repeat
  521. DWORD dwActuals; // no. of times the option actually repeated
  522. LPVOID pValue; // pointer to the option value
  523. OPTVALUE szValues; // to hold valid value in case flag = CP_MODE_VALUES
  524. PARSERFUNC pFunction; // pointer to custom value validation function
  525. LPVOID pFunctionData; // extra data that will be passed to custom function
  526. } TCMDPARSER;
  527. typedef TCMDPARSER* PTCMDPARSER;
  528. //
  529. // public function prototypes
  530. //
  531. DWORD GetOptionCount( LPCTSTR szOption, DWORD dwCount, PTCMDPARSER pcmdOptions );
  532. BOOL DoParseParam( DWORD dwCount,
  533. LPCTSTR argv[],
  534. DWORD dwOptionsCount,
  535. PTCMDPARSER pcmdOptions );
  536. ///////////////////////////////////////////////////////////////////////////////////
  537. // //
  538. // VALIDATING AND FILTERING RESULTS //
  539. // //
  540. ///////////////////////////////////////////////////////////////////////////////////
  541. //
  542. // constants / definitions / enumerations
  543. //
  544. // types
  545. #define F_TYPE_TEXT 0x00000001 // 0000 0000 0001
  546. #define F_TYPE_NUMERIC 0x00000002 // 0000 0000 0010
  547. #define F_TYPE_UNUMERIC 0x00000003 // 0000 0000 0011
  548. #define F_TYPE_DATE 0x00000004 // 0000 0000 0100
  549. #define F_TYPE_TIME 0x00000005 // 0000 0000 0101
  550. #define F_TYPE_DATETIME 0x00000006 // 0000 0000 0110
  551. #define F_TYPE_FLOAT 0x00000007 // 0000 0000 0111
  552. #define F_TYPE_DOUBLE 0x00000008 // 0000 0000 1000
  553. #define F_TYPE_CUSTOM 0x00000009 // 0000 0000 1001
  554. #define F_TYPE_MASK 0x00000FFF // 1111 1111 1111
  555. // modes
  556. #define F_MODE_VALUES 0x00001000 // 0001 XXXX XXXX XXXX
  557. #define F_MODE_PATTERN 0x00002000 // 0010 XXXX XXXX XXXX
  558. #define F_MODE_ARRAY 0x00004000 // 0100 XXXX XXXX XXXX
  559. // custom filter data validation result
  560. #define F_FILTER_INVALID 0x00000000
  561. #define F_FILTER_VALID 0x00000001
  562. #define F_RESULT_KEEP 0x000000FF
  563. #define F_RESULT_REMOVE 0x00000000
  564. //
  565. // Bit no. 2 is '='
  566. // Bit no. 3 is '<'
  567. // Bit no. 4 is '>'
  568. //
  569. // 7654 3210
  570. // EQ 0000 0010 0x02
  571. // NE 1111 XX0X 0xFD
  572. // LT 0000 0100 0x04
  573. // GT 0000 1000 0x08
  574. // LE 0000 0110 0x06
  575. // GE 0000 1010 0x0A
  576. //
  577. #define MASK_EQ 0x00000002
  578. #define MASK_NE 0x000000FC
  579. #define MASK_LT 0x00000004
  580. #define MASK_GT 0x00000008
  581. #define MASK_LE 0x00000006
  582. #define MASK_GE 0x0000000A
  583. #define MASK_ALL 0x000000FF
  584. // mathematical operators
  585. #define MATH_EQ _T( "=" )
  586. #define MATH_NE _T( "!=" )
  587. #define MATH_LT _T( "<" )
  588. #define MATH_GT _T( ">" )
  589. #define MATH_LE _T( "<=" )
  590. #define MATH_GE _T( ">=" )
  591. // parsed filters information
  592. #define F_PARSED_INDEX_FILTER 0
  593. #define F_PARSED_INDEX_PROPERTY 1
  594. #define F_PARSED_INDEX_OPERATOR 2
  595. #define F_PARSED_INDEX_VALUE 3
  596. #define F_PARSED_INFO_COUNT 4
  597. //
  598. // structures / user defined data types
  599. //
  600. typedef TCHAR OPERATORS[ 101 ];
  601. typedef TCHAR FILTERVALUES[ 256 ];
  602. typedef TCHAR FILTERPROPERTY[ 256 ];
  603. // custom value validation routine prototype
  604. typedef DWORD ( *FILTERFUNC )( LPCTSTR pszProperty, LPCTSTR pszOperator,
  605. LPCTSTR pszValue, LPVOID pData, TARRAY arrRow );
  606. typedef struct __tagFilterConfig
  607. {
  608. DWORD dwColumn; // mapping from filter to column in data
  609. FILTERPROPERTY szProperty; // filter property
  610. OPERATORS szOperators; // valid operators for the filter
  611. DWORD dwFlags; // flags ( specifies the valid type for the filter )
  612. FILTERVALUES szValues; // to hold valid value in case flag = F_MODE_VALUES
  613. FILTERFUNC pFunction; // pointer to custom value validation function
  614. LPVOID pFunctionData; // extra data that will be passed to custom function
  615. } TFILTERCONFIG;
  616. typedef TFILTERCONFIG *PTFILTERCONFIG;
  617. //
  618. // public function prototypes
  619. //
  620. LPCTSTR FindOperator( LPCTSTR szOperator );
  621. BOOL ParseAndValidateFilter( DWORD dwCount,
  622. PTFILTERCONFIG pfilterConfigs,
  623. TARRAY arrFiltersArgs, PTARRAY parrParsedFilters );
  624. BOOL CanFilterRecord( DWORD dwCount,
  625. TFILTERCONFIG filterConfigs[],
  626. TARRAY arrRecord, TARRAY arrParsedFilters );
  627. DWORD FilterResults( DWORD dwCount,
  628. TFILTERCONFIG arrFilters[],
  629. TARRAY arrData, TARRAY arrParsedFilters );
  630. ///////////////////////////////////////////////////////////////////////////////////
  631. // //
  632. // DISPLAYING RESULTS //
  633. // //
  634. ///////////////////////////////////////////////////////////////////////////////////
  635. //
  636. // constants / definitions / enumerations
  637. //
  638. // formats
  639. #define SR_FORMAT_LIST 0x00000001 // 0000 0001
  640. #define SR_FORMAT_TABLE 0x00000002 // 0000 0010
  641. #define SR_FORMAT_CSV 0x00000003 // 0000 0011
  642. #define SR_FORMAT_MASK 0x0000000F // 1111 1111
  643. // column types
  644. #define SR_TYPE_NONE 0x00000000 // 0000 0000 0000 0000 XXXX XXXX
  645. #define SR_TYPE_STRING 0x00000010 // 0000 0000 0000 0001 XXXX XXXX
  646. #define SR_TYPE_NUMERIC 0x00000020 // 0000 0000 0000 0010 XXXX XXXX
  647. #define SR_TYPE_FLOAT 0x00000030 // 0000 0000 0000 0011 XXXX XXXX
  648. #define SR_TYPE_DOUBLE 0x00000040 // 0000 0000 0000 0100 XXXX XXXX
  649. #define SR_TYPE_DATE 0x00000050 // 0000 0000 0000 0101 XXXX XXXX
  650. #define SR_TYPE_TIME 0x00000060 // 0000 0000 0000 0110 XXXX XXXX
  651. #define SR_TYPE_DATETIME 0x00000070 // 0000 0000 0000 0111 XXXX XXXX
  652. #define SR_TYPE_CUSTOM 0x00000080 // 0000 0000 0000 1000 XXXX XXXX
  653. #define SR_TYPE_MASK 0x00000FF0 // 1111 1111 1111 1111 XXXX XXXX
  654. // flags ( global level )
  655. #define SR_NOHEADER 0x00001000 // 0000 0001 XXXX XXXX XXXX XXXX XXXX XXXX
  656. // flags ( column level )
  657. #define SR_HIDECOLUMN 0x00001000 // 0000 0000 0001 XXXX XXXX XXXX XXXX XXXX XXXX
  658. #define SR_VALUEFORMAT 0x00002000 // 0000 0000 0010 XXXX XXXX XXXX XXXX XXXX XXXX
  659. #define SR_ARRAY 0x00004000 // 0000 0000 0100 XXXX XXXX XXXX XXXX XXXX XXXX
  660. #define SR_WORDWRAP 0x00008000 // 0000 0000 1000 XXXX XXXX XXXX XXXX XXXX XXXX
  661. #define SR_ALIGN_LEFT 0x00010000 // 0000 0001 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  662. #define SR_ALIGN_RIGHT 0x00020000 // 0000 0010 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  663. #define SR_ALIGN_CENTER 0x00040000 // 0000 0100 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  664. #define SR_NO_TRUNCATION 0x00088000 // 0000 1000 1000 XXXX XXXX XXXX XXXX XXXX XXXX
  665. #define SR_SHOW_NA_WHEN_BLANK 0x00100000 // 0001 0000 0000 XXXX XXXX XXXX XXXX XXXX XXXX
  666. //
  667. // user defined types
  668. //
  669. // custom value formatter
  670. typedef TCHAR COLHEADER[ 256 ];
  671. typedef TCHAR COLFORMAT[ 65 ];
  672. typedef VOID ( *FORMATFUNC )( DWORD dwColumn, TARRAY arrData, LPVOID pData, LPTSTR szValue );
  673. typedef struct __tagColumns
  674. {
  675. COLHEADER szColumn; // column header name
  676. DWORD dwWidth; // width of each field
  677. DWORD dwFlags; // flags ( specifies the type etc )
  678. COLFORMAT szFormat; // custom format
  679. FORMATFUNC pFunction; // formatter function
  680. LPVOID pFunctionData; // function data
  681. } TCOLUMNS;
  682. typedef TCOLUMNS* PTCOLUMNS;
  683. //
  684. // public functions
  685. //
  686. VOID ShowResults( DWORD dwColumns, PTCOLUMNS pColumns, DWORD dwFlags, TARRAY arrData );
  687. ///////////////////////////////////////////////////////////////////////////////////
  688. // COMING UP *** DO NOT USE UNLESS INTIMATED //
  689. ///////////////////////////////////////////////////////////////////////////////////
  690. VOID ShowResults2( FILE* fp, DWORD dwColumns, PTCOLUMNS pColumns, DWORD dwFlags, TARRAY arrData );
  691. ///////////////////////////////////////////////////////////////////////////////////
  692. #ifdef __cplusplus
  693. }
  694. #endif
  695. #endif // __CMDLINE_H