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.

1748 lines
51 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. strings.h
  5. Abstract:
  6. Declares the string utilities implemented in common\migutil.
  7. Author:
  8. Several
  9. Revision History:
  10. See SLM log
  11. --*/
  12. #include <mbstring.h>
  13. #include <wchar.h>
  14. typedef PVOID POOLHANDLE;
  15. #pragma once
  16. #define MAX_ENCODED_RULE (256*6)
  17. //
  18. // String sizing routines and unit conversion
  19. //
  20. #define CharCountA _mbslen
  21. #define CharCountW wcslen
  22. __inline
  23. PSTR
  24. CharCountToPointerA (
  25. PCSTR String,
  26. UINT Char
  27. )
  28. {
  29. while (Char > 0) {
  30. MYASSERT (*String != 0);
  31. Char--;
  32. String = (PCSTR) _mbsinc ((const unsigned char *) String);
  33. }
  34. return (PSTR) String;
  35. }
  36. __inline
  37. PWSTR
  38. CharCountToPointerW (
  39. PCWSTR String,
  40. UINT Char
  41. )
  42. {
  43. #ifdef DEBUG
  44. UINT u;
  45. for (u = 0 ; u < Char ; u++) {
  46. MYASSERT (String[u] != 0);
  47. }
  48. #endif
  49. return (PWSTR) (&String[Char]);
  50. }
  51. __inline
  52. UINT
  53. CharCountABA (
  54. IN PCSTR Start,
  55. IN PCSTR EndPlusOne
  56. )
  57. {
  58. register UINT Count;
  59. Count = 0;
  60. while (Start < EndPlusOne) {
  61. MYASSERT (*Start != 0);
  62. Count++;
  63. Start = (PCSTR) _mbsinc ((const unsigned char *) Start);
  64. }
  65. return Count;
  66. }
  67. __inline
  68. UINT
  69. CharCountABW (
  70. IN PCWSTR Start,
  71. IN PCWSTR EndPlusOne
  72. )
  73. {
  74. #ifdef DEBUG
  75. PCWSTR p;
  76. for (p = Start ; p < EndPlusOne ; p++) {
  77. MYASSERT (*p != 0);
  78. }
  79. #endif
  80. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) : 0;
  81. }
  82. __inline
  83. UINT
  84. CharCountInByteRangeA (
  85. IN PCSTR Start,
  86. IN UINT Bytes
  87. )
  88. {
  89. register UINT Count;
  90. PCSTR EndPlusOne = (PCSTR) ((PBYTE) Start + Bytes);
  91. Count = 0;
  92. while (Start < EndPlusOne) {
  93. Count++;
  94. Start = (PCSTR) _mbsinc ((const unsigned char *) Start);
  95. }
  96. return Count;
  97. }
  98. __inline
  99. UINT
  100. CharCountInByteRangeW (
  101. IN PCWSTR Start,
  102. IN UINT Bytes
  103. )
  104. {
  105. PCWSTR EndPlusOne = (PCWSTR) ((PBYTE) Start + Bytes);
  106. if (Start < EndPlusOne) {
  107. return (EndPlusOne - Start);
  108. }
  109. MYASSERT (FALSE);
  110. return 0;
  111. }
  112. __inline
  113. UINT
  114. CharCountToBytesA (
  115. IN PCSTR Start,
  116. IN UINT CharCount
  117. )
  118. {
  119. PCSTR EndPlusOne;
  120. EndPlusOne = CharCountToPointerA (Start, CharCount);
  121. return EndPlusOne - Start;
  122. }
  123. __inline
  124. UINT
  125. CharCountToBytesW (
  126. IN PCWSTR Start,
  127. IN UINT CharCount
  128. )
  129. {
  130. return CharCount * sizeof (WCHAR);
  131. }
  132. #define CharCountToTcharsA CharCountToBytesA
  133. __inline
  134. UINT
  135. CharCountToTcharsW (
  136. IN PCWSTR Start,
  137. IN UINT CharCount
  138. )
  139. {
  140. return CharCount;
  141. }
  142. #define ByteCountA strlen
  143. #define ByteCountW(x) (wcslen(x)*sizeof(WCHAR))
  144. #define SizeOfStringA(str) (ByteCountA(str) + sizeof (CHAR))
  145. #define SizeOfStringW(str) (ByteCountW(str) + sizeof (WCHAR))
  146. __inline
  147. PSTR
  148. ByteCountToPointerA (
  149. PCSTR String,
  150. UINT BytePos
  151. )
  152. {
  153. return (PSTR)((PBYTE) String + BytePos);
  154. }
  155. __inline
  156. PWSTR
  157. ByteCountToPointerW (
  158. PCWSTR String,
  159. UINT BytePos
  160. )
  161. {
  162. return (PWSTR)((PBYTE) String + BytePos);
  163. }
  164. __inline
  165. UINT
  166. ByteCountABA (
  167. IN PCSTR Start,
  168. IN PCSTR EndPlusOne
  169. )
  170. {
  171. #ifdef DEBUG
  172. PCSTR p;
  173. for (p = Start ; p < EndPlusOne ; p = (PCSTR) _mbsinc ((const unsigned char *) p)) {
  174. MYASSERT (*p != 0);
  175. }
  176. #endif
  177. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) : 0;
  178. }
  179. __inline
  180. UINT
  181. ByteCountABW (
  182. IN PCWSTR Start,
  183. IN PCWSTR EndPlusOne
  184. )
  185. {
  186. #ifdef DEBUG
  187. PCWSTR p;
  188. for (p = Start ; p < EndPlusOne ; p++) {
  189. MYASSERT (*p != 0);
  190. }
  191. #endif
  192. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) * sizeof (WCHAR) : 0;
  193. }
  194. __inline
  195. UINT
  196. ByteCountToCharsA (
  197. IN PCSTR Start,
  198. IN UINT ByteCount
  199. )
  200. {
  201. PCSTR EndPlusOne;
  202. EndPlusOne = Start + ByteCount;
  203. return CharCountABA (Start, EndPlusOne);
  204. }
  205. __inline
  206. UINT
  207. ByteCountToCharsW (
  208. IN PCWSTR Start,
  209. IN UINT ByteCount
  210. )
  211. {
  212. #ifdef DEBUG
  213. PCWSTR p;
  214. PCWSTR EndPlusOne;
  215. EndPlusOne = (PCWSTR) ((PBYTE) Start + ByteCount);
  216. for (p = Start ; p < EndPlusOne ; p++) {
  217. MYASSERT (*p != 0);
  218. }
  219. #endif
  220. return ByteCount / sizeof (WCHAR);
  221. }
  222. __inline
  223. UINT
  224. ByteCountToTcharsA (
  225. IN PCSTR Start,
  226. IN UINT ByteCount
  227. )
  228. {
  229. #ifdef DEBUG
  230. PCSTR p;
  231. PCSTR EndPlusOne;
  232. EndPlusOne = Start + ByteCount;
  233. for (p = Start ; p < EndPlusOne ; p = (PCSTR) _mbsinc ((const unsigned char *) p)) {
  234. MYASSERT (*p != 0);
  235. }
  236. #endif
  237. return ByteCount;
  238. }
  239. #define ByteCountToTcharsW ByteCountToCharsW
  240. #define TcharCountA strlen
  241. #define TcharCountW wcslen
  242. __inline
  243. PSTR
  244. TcharCountToPointerA (
  245. PCSTR String,
  246. UINT Tchars
  247. )
  248. {
  249. #ifdef DEBUG
  250. PCSTR p;
  251. PCSTR EndPlusOne;
  252. EndPlusOne = String + Tchars;
  253. for (p = String ; p < EndPlusOne ; p = (PCSTR) _mbsinc ((const unsigned char *) p)) {
  254. MYASSERT (*p != 0);
  255. }
  256. #endif
  257. return (PSTR) (String + Tchars);
  258. }
  259. __inline
  260. PWSTR
  261. TcharCountToPointerW (
  262. PCWSTR String,
  263. UINT Tchars
  264. )
  265. {
  266. #ifdef DEBUG
  267. PCWSTR p;
  268. PCWSTR EndPlusOne;
  269. EndPlusOne = String + Tchars;
  270. for (p = String ; p < EndPlusOne ; p++) {
  271. MYASSERT (*p != 0);
  272. }
  273. #endif
  274. return (PWSTR) (String + Tchars);
  275. }
  276. #define TcharCountABA ByteCountABA
  277. __inline
  278. UINT
  279. TcharCountABW (
  280. IN PCWSTR Start,
  281. IN PCWSTR EndPlusOne
  282. )
  283. {
  284. #ifdef DEBUG
  285. PCWSTR p;
  286. for (p = Start ; p < EndPlusOne ; p++) {
  287. MYASSERT (*p != 0);
  288. }
  289. #endif
  290. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) : 0;
  291. }
  292. #define TcharCountToCharsA ByteCountToCharsA
  293. __inline
  294. UINT
  295. TcharCountToCharsW (
  296. IN PCWSTR Start,
  297. IN UINT Tchars
  298. )
  299. {
  300. #ifdef DEBUG
  301. PCWSTR p;
  302. PCWSTR EndPlusOne;
  303. EndPlusOne = Start + Tchars;
  304. for (p = Start ; p < EndPlusOne ; p++) {
  305. MYASSERT (*p != 0);
  306. }
  307. #endif
  308. return Tchars;
  309. }
  310. __inline
  311. UINT
  312. TcharCountToBytesA (
  313. IN PCSTR Start,
  314. IN UINT Tchars
  315. )
  316. {
  317. #ifdef DEBUG
  318. PCSTR p;
  319. PCSTR EndPlusOne;
  320. EndPlusOne = Start + Tchars;
  321. for (p = Start ; p < EndPlusOne ; p = (PCSTR) _mbsinc ((const unsigned char *) p)) {
  322. MYASSERT (*p != 0);
  323. }
  324. #endif
  325. return Tchars;
  326. }
  327. __inline
  328. UINT
  329. TcharCountToBytesW (
  330. IN PCWSTR Start,
  331. IN UINT Tchars
  332. )
  333. {
  334. #ifdef DEBUG
  335. PCWSTR p;
  336. PCWSTR EndPlusOne;
  337. EndPlusOne = Start + Tchars;
  338. for (p = Start ; p < EndPlusOne ; p++) {
  339. MYASSERT (*p != 0);
  340. }
  341. #endif
  342. return Tchars * sizeof (WCHAR);
  343. }
  344. #define StackStringCopyA(stackbuf,src) _mbssafecpy(stackbuf,src,sizeof(stackbuf))
  345. #define StackStringCopyW(stackbuf,src) _wcssafecpy(stackbuf,src,sizeof(stackbuf))
  346. //
  347. // String comparison routines
  348. //
  349. #define StringCompareA _mbscmp
  350. #define StringCompareW wcscmp
  351. #define StringMatchA(str1,str2) (_mbscmp(str1,str2)==0)
  352. #define StringMatchW(str1,str2) (wcscmp(str1,str2)==0)
  353. #define StringICompareA _mbsicmp
  354. #define StringICompareW _wcsicmp
  355. #define StringIMatchA(str1,str2) (_mbsicmp(str1,str2)==0)
  356. #define StringIMatchW(str1,str2) (_wcsicmp(str1,str2)==0)
  357. #define StringCompareByteCountA(str1,str2,bytes) _mbsncmp(str1,str2,ByteCountToCharsA(str1,bytes))
  358. #define StringCompareByteCountW(str1,str2,bytes) wcsncmp(str1,str2,ByteCountToCharsW(str1,bytes))
  359. #define StringMatchByteCountA(str1,str2,bytes) (strncmp(str1,str2,bytes)==0)
  360. #define StringMatchByteCountW(str1,str2,bytes) (wcsncmp(str1,str2,ByteCountToCharsW(str1,bytes))==0)
  361. #define StringICompareByteCountA(str1,str2,bytes) _mbsnicmp(str1,str2,ByteCountToCharsA(str1,bytes))
  362. #define StringICompareByteCountW(str1,str2,bytes) _wcsnicmp(str1,str2,ByteCountToCharsW(str1,bytes))
  363. #define StringIMatchByteCountA(str1,str2,bytes) (_mbsnicmp(str1,str2,ByteCountToCharsA(str1,bytes))==0)
  364. #define StringIMatchByteCountW(str1,str2,bytes) (_wcsnicmp(str1,str2,ByteCountToCharsW(str1,bytes))==0)
  365. #define StringCompareCharCountA(str1,str2,chars) _mbsncmp(str1,str2,chars)
  366. #define StringCompareCharCountW(str1,str2,chars) wcsncmp(str1,str2,chars)
  367. #define StringMatchCharCountA(str1,str2,chars) (_mbsncmp(str1,str2,chars)==0)
  368. #define StringMatchCharCountW(str1,str2,chars) (wcsncmp(str1,str2,chars)==0)
  369. #define StringICompareCharCountA(str1,str2,chars) _mbsnicmp(str1,str2,chars)
  370. #define StringICompareCharCountW(str1,str2,chars) _wcsnicmp(str1,str2,chars)
  371. #define StringIMatchCharCountA(str1,str2,chars) (_mbsnicmp(str1,str2,chars)==0)
  372. #define StringIMatchCharCountW(str1,str2,chars) (_wcsnicmp(str1,str2,chars)==0)
  373. #define StringCompareTcharCountA(str1,str2,tchars) _mbsncmp(str1,str2,TcharCountToCharsA(str1,tchars))
  374. #define StringCompareTcharCountW(str1,str2,tchars) wcsncmp(str1,str2,TcharCountToCharsW(str1,tchars))
  375. #define StringMatchTcharCountA(str1,str2,tchars) (strncmp(str1,str2,tchars)==0)
  376. #define StringMatchTcharCountW(str1,str2,tchars) (wcsncmp(str1,str2,TcharCountToCharsW(str1,tchars))==0)
  377. #define StringICompareTcharCountA(str1,str2,tchars) _mbsnicmp(str1,str2,TcharCountToCharsA(str1,tchars))
  378. #define StringICompareTcharCountW(str1,str2,tchars) _wcsnicmp(str1,str2,TcharCountToCharsW(str1,tchars))
  379. #define StringIMatchTcharCountA(str1,str2,tchars) (_mbsnicmp(str1,str2,TcharCountToCharsA(str1,tchars))==0)
  380. #define StringIMatchTcharCountW(str1,str2,tchars) (_wcsnicmp(str1,str2,TcharCountToCharsW(str1,tchars))==0)
  381. INT
  382. StringCompareABA (
  383. IN PCSTR String,
  384. IN PCSTR Start,
  385. IN PCSTR End
  386. );
  387. INT
  388. StringCompareABW (
  389. IN PCWSTR String,
  390. IN PCWSTR Start,
  391. IN PCWSTR End
  392. );
  393. #define StringMatchABA(String,Start,End) (StringCompareABA(String,Start,End)==0)
  394. #define StringMatchABW(String,Start,End) (StringCompareABW(String,Start,End)==0)
  395. // stricmp that takes an end pointer instead of a length
  396. INT
  397. StringICompareABA (
  398. IN PCSTR String,
  399. IN PCSTR Start,
  400. IN PCSTR End
  401. );
  402. INT
  403. StringICompareABW (
  404. IN PCWSTR String,
  405. IN PCWSTR Start,
  406. IN PCWSTR End
  407. );
  408. PWSTR
  409. our_lstrcpynW (
  410. OUT PWSTR Dest,
  411. IN PCWSTR Src,
  412. IN INT NumChars
  413. );
  414. #define StringIMatchABA(String,Start,End) (StringICompareABA(String,Start,End)==0)
  415. #define StringIMatchABW(String,Start,End) (StringICompareABW(String,Start,End)==0)
  416. //
  417. // String copy routines
  418. //
  419. #define StringCopyA _mbscpy
  420. #define StringCopyW wcscpy
  421. // bytes
  422. #define StringCopyByteCountA(str1,str2,bytes) lstrcpynA(str1,str2,bytes)
  423. #define StringCopyByteCountW(str1,str2,bytes) our_lstrcpynW(str1,str2,(bytes)/sizeof(WCHAR))
  424. // logical characters (IMPORTANT: logical chars != TcharCount)
  425. #define StringCopyCharCountA(str1,str2,mbchars) lstrcpynA(str1,str2,CharCountToBytesA(str2,mbchars))
  426. #define StringCopyCharCountW(str1,str2,wchars) our_lstrcpynW(str1,str2,wchars)
  427. // CHARs (A version) or WCHARs (W version)
  428. #define StringCopyTcharCountA(str1,str2,tchars) lstrcpynA(str1,str2,tchars)
  429. #define StringCopyTcharCountW(str1,str2,tchars) our_lstrcpynW(str1,str2,tchars)
  430. #define StringCopyABA(dest,stra,strb) StringCopyByteCountA((dest),(stra),((PBYTE)(strb)-(PBYTE)(stra)+(INT)sizeof(CHAR)))
  431. #define StringCopyABW(dest,stra,strb) StringCopyByteCountW((dest),(stra),((PBYTE)(strb)-(PBYTE)(stra)+(INT)sizeof(WCHAR)))
  432. //
  433. // String cat routines
  434. //
  435. #define StringCatA _mbsappend
  436. #define StringCatW _wcsappend
  437. //
  438. // Character search routines
  439. //
  440. #define GetEndOfStringA(s) strchr(s,0)
  441. #define GetEndOfStringW(s) wcschr(s,0)
  442. __inline
  443. UINT
  444. SizeOfMultiSzA (
  445. PCSTR MultiSz
  446. )
  447. {
  448. PCSTR Base;
  449. Base = MultiSz;
  450. while (*MultiSz) {
  451. MultiSz = GetEndOfStringA (MultiSz) + 1;
  452. }
  453. MultiSz++;
  454. return (PBYTE) MultiSz - (PBYTE) Base;
  455. }
  456. __inline
  457. UINT
  458. SizeOfMultiSzW (
  459. PCWSTR MultiSz
  460. )
  461. {
  462. PCWSTR Base;
  463. Base = MultiSz;
  464. while (*MultiSz) {
  465. MultiSz = GetEndOfStringW (MultiSz) + 1;
  466. }
  467. MultiSz++;
  468. return (PBYTE) MultiSz - (PBYTE) Base;
  469. }
  470. __inline
  471. UINT
  472. MultiSzSizeInCharsA (
  473. PCSTR MultiSz
  474. )
  475. {
  476. UINT Chars = 0;
  477. while (*MultiSz) {
  478. do {
  479. Chars++;
  480. MultiSz = (PCSTR) _mbsinc ((const unsigned char *) MultiSz);
  481. } while (*MultiSz);
  482. Chars++;
  483. MultiSz++;
  484. }
  485. Chars++;
  486. return Chars;
  487. }
  488. #define MultiSzSizeInCharsW(msz) (SizeOfMultiSzW(msz)/sizeof(WCHAR))
  489. PSTR
  490. GetPrevCharA (
  491. IN PCSTR StartStr,
  492. IN PCSTR CurrPtr,
  493. IN CHARTYPE SearchChar
  494. );
  495. PWSTR
  496. GetPrevCharW (
  497. IN PCWSTR StartStr,
  498. IN PCWSTR CurrPtr,
  499. IN WCHAR SearchChar
  500. );
  501. //
  502. // Pool allocation routines
  503. //
  504. PSTR
  505. RealAllocTextExA (
  506. IN POOLHANDLE Pool, OPTIONAL
  507. IN UINT ByteSize
  508. );
  509. PWSTR
  510. RealAllocTextExW (
  511. IN POOLHANDLE Pool, OPTIONAL
  512. IN UINT WcharSize
  513. );
  514. #define AllocTextExA(p,s) SETTRACKCOMMENT(PSTR,"AllocTextExA",__FILE__,__LINE__)\
  515. RealAllocTextExA(p,s)\
  516. CLRTRACKCOMMENT
  517. #define AllocTextExW(p,s) SETTRACKCOMMENT(PWSTR,"AllocTextExW",__FILE__,__LINE__)\
  518. RealAllocTextExW(p,s)\
  519. CLRTRACKCOMMENT
  520. #define AllocTextA(s) AllocTextExA(NULL,(s))
  521. #define AllocTextW(s) AllocTextExW(NULL,(s))
  522. VOID
  523. FreeTextExA (
  524. IN POOLHANDLE Pool, OPTIONAL
  525. IN PCSTR Text OPTIONAL
  526. );
  527. VOID
  528. FreeTextExW (
  529. IN POOLHANDLE Pool, OPTIONAL
  530. IN PCWSTR Text OPTIONAL
  531. );
  532. #define FreeTextA(t) FreeTextExA(NULL,t)
  533. #define FreeTextW(t) FreeTextExW(NULL,t)
  534. PSTR
  535. RealDuplicateTextExA (
  536. IN POOLHANDLE Pool, OPTIONAL
  537. IN PCSTR Text,
  538. IN UINT ExtraChars,
  539. OUT PSTR *NulChar OPTIONAL
  540. );
  541. PWSTR
  542. RealDuplicateTextExW (
  543. IN POOLHANDLE Pool, OPTIONAL
  544. IN PCWSTR Text,
  545. IN UINT ExtraChars,
  546. OUT PWSTR *NulChar OPTIONAL
  547. );
  548. #define DuplicateTextExA(p,t,c,n) SETTRACKCOMMENT(PSTR,"DuplicateTextExA",__FILE__,__LINE__)\
  549. RealDuplicateTextExA(p,t,c,n)\
  550. CLRTRACKCOMMENT
  551. #define DuplicateTextExW(p,t,c,n) SETTRACKCOMMENT(PWSTR,"DuplicateTextExW",__FILE__,__LINE__)\
  552. RealDuplicateTextExW(p,t,c,n)\
  553. CLRTRACKCOMMENT
  554. #define DuplicateTextA(text) DuplicateTextExA(NULL,text,0,NULL)
  555. #define DuplicateTextW(text) DuplicateTextExW(NULL,text,0,NULL)
  556. PSTR
  557. RealJoinTextExA (
  558. IN POOLHANDLE Pool, OPTIONAL
  559. IN PCSTR String1,
  560. IN PCSTR String2,
  561. IN PCSTR DelimeterString, OPTIONAL
  562. IN UINT ExtraChars,
  563. OUT PSTR *NulChar OPTIONAL
  564. );
  565. PWSTR
  566. RealJoinTextExW (
  567. IN POOLHANDLE Pool, OPTIONAL
  568. IN PCWSTR String1,
  569. IN PCWSTR String2,
  570. IN PCWSTR CenterString, OPTIONAL
  571. IN UINT ExtraChars,
  572. OUT PWSTR *NulChar OPTIONAL
  573. );
  574. #define JoinTextExA(p,s1,s2,cs,ec,nc) SETTRACKCOMMENT(PSTR,"JoinTextExA",__FILE__,__LINE__)\
  575. RealJoinTextExA(p,s1,s2,cs,ec,nc)\
  576. CLRTRACKCOMMENT
  577. #define JoinTextExW(p,s1,s2,cs,ec,nc) SETTRACKCOMMENT(PWSTR,"JoinTextExW",__FILE__,__LINE__)\
  578. RealJoinTextExW(p,s1,s2,cs,ec,nc)\
  579. CLRTRACKCOMMENT
  580. #define JoinTextA(str1,str2) JoinTextExA(NULL,str1,str2,NULL,0,NULL)
  581. #define JoinTextW(str1,str2) JoinTextExW(NULL,str1,str2,NULL,0,NULL)
  582. PSTR
  583. RealExpandEnvironmentTextExA (
  584. IN PCSTR InString,
  585. IN PCSTR * ExtraEnvironmentVariables OPTIONAL
  586. );
  587. PWSTR
  588. RealExpandEnvironmentTextExW (
  589. IN PCWSTR InString,
  590. IN PCWSTR * ExtraEnvironmentVariables OPTIONAL
  591. );
  592. #define ExpandEnvironmentTextExA(str,ev) SETTRACKCOMMENT(PSTR,"ExpandEnvironmentTextExA",__FILE__,__LINE__)\
  593. RealExpandEnvironmentTextExA(str,ev)\
  594. CLRTRACKCOMMENT
  595. #define ExpandEnvironmentTextExW(str,ev) SETTRACKCOMMENT(PWSTR,"ExpandEnvironmentTextExW",__FILE__,__LINE__)\
  596. RealExpandEnvironmentTextExW(str,ev)\
  597. CLRTRACKCOMMENT
  598. #define ExpandEnvironmentTextA(string) ExpandEnvironmentTextExA(string,NULL)
  599. #define ExpandEnvironmentTextW(string) ExpandEnvironmentTextExW(string,NULL)
  600. //
  601. // Function wraps IsDBCSLeadByte(), which tests ACP. Do not use
  602. // isleadbyte().
  603. //
  604. #define IsLeadByte(b) IsDBCSLeadByte(b)
  605. //
  606. // Command line routines
  607. //
  608. // Converts ANSI command line to array of args
  609. PSTR *
  610. CommandLineToArgvA (
  611. IN PCSTR CmdLine,
  612. OUT INT *NumArgs
  613. );
  614. //
  615. // Need both MBCS and UNICODE versions
  616. //
  617. // an atoi that supports decimal or hex
  618. DWORD _mbsnum (IN PCSTR szNum);
  619. DWORD _wcsnum (IN PCWSTR szNum);
  620. // a strcat that returns a pointer to the end of the string
  621. PSTR _mbsappend (OUT PSTR szDest, IN PCSTR szSrc);
  622. PWSTR _wcsappend (OUT PWSTR szDest, IN PCWSTR szSrc);
  623. // determines if an entire string is printable chars
  624. int _mbsisprint (PCSTR szStr);
  625. int _wcsisprint (PCWSTR szStr);
  626. // case-insensitive strstr
  627. PCSTR _mbsistr (PCSTR szStr, PCSTR szSubStr);
  628. PCWSTR _wcsistr (PCWSTR szStr, PCWSTR szSubStr);
  629. // copies the first character of str2 to str
  630. void _copymbchar (PSTR str1, PCSTR str2);
  631. #define _copywchar(dest,src) (*(dest)=*(src))
  632. // replaces a character in a multi-byte char string and maintains
  633. // the string integrity (may grow string by one byte)
  634. void _setmbchar (PSTR str, MBCHAR c);
  635. #define _setwchar(str,c) (*(str)=(c))
  636. // removes specified character from the end of a string, if it exists
  637. BOOL _mbsctrim (PSTR str, MBCHAR c);
  638. BOOL _wcsctrim (PWSTR str, WCHAR c);
  639. // Always adds a backslash, returns ptr to nul terminator
  640. PSTR AppendWackA (IN PSTR str);
  641. PWSTR AppendWackW (IN PWSTR str);
  642. // Adds a backslash to the end of a DOS path (unless str is empty
  643. // or is only a drive letter)
  644. PSTR AppendDosWackA (IN PSTR str);
  645. PWSTR AppendDosWackW (IN PWSTR str);
  646. // Adds a backslash unless str is empty
  647. PSTR AppendUncWackA (IN PSTR str);
  648. PWSTR AppendUncWackW (IN PWSTR str);
  649. // Adds a backslash and identifies the correct naming convention (DOS,
  650. // or UNC)
  651. PSTR AppendPathWackA (IN PSTR str);
  652. PWSTR AppendPathWackW (IN PWSTR str);
  653. // Joins two paths together, allocates string in g_PathsPool
  654. PSTR
  655. RealJoinPathsExA (
  656. IN POOLHANDLE Pool, OPTIONAL
  657. IN PCSTR PathA,
  658. IN PCSTR PathB
  659. );
  660. PWSTR
  661. RealJoinPathsExW (
  662. IN POOLHANDLE Pool, OPTIONAL
  663. IN PCWSTR PathA,
  664. IN PCWSTR PathB
  665. );
  666. #define JoinPathsExA(pool,p1,p2) SETTRACKCOMMENT(PSTR,"JoinPathsA",__FILE__,__LINE__)\
  667. RealJoinPathsExA(pool,p1,p2)\
  668. CLRTRACKCOMMENT
  669. #define JoinPathsExW(pool,p1,p2) SETTRACKCOMMENT(PWSTR,"JoinPathsW",__FILE__,__LINE__)\
  670. RealJoinPathsExW(pool,p1,p2)\
  671. CLRTRACKCOMMENT
  672. #define JoinPathsA(p1,p2) JoinPathsExA(NULL,p1,p2)
  673. #define JoinPathsW(p1,p2) JoinPathsExW(NULL,p1,p2)
  674. // Routine to allocate a 1K buffer for path manipulation, allocated in g_PathsPool
  675. PSTR RealAllocPathStringA (IN DWORD Chars);
  676. PWSTR RealAllocPathStringW (IN DWORD Chars);
  677. #define DEFSIZE 0
  678. #define AllocPathStringA(chars) SETTRACKCOMMENT(PSTR,"AllocPathStringA",__FILE__,__LINE__)\
  679. RealAllocPathStringA(chars)\
  680. CLRTRACKCOMMENT
  681. #define AllocPathStringW(chars) SETTRACKCOMMENT(PWSTR,"AllocPathStringW",__FILE__,__LINE__)\
  682. RealAllocPathStringW(chars)\
  683. CLRTRACKCOMMENT
  684. // Routine to divide path into separate strings, each allocated in g_PathsPool
  685. VOID RealSplitPathA (IN PCSTR Path, OUT PSTR *Drive, OUT PSTR *Dir, OUT PSTR *File, OUT PSTR *Ext);
  686. VOID RealSplitPathW (IN PCWSTR Path, OUT PWSTR *Drive, OUT PWSTR *Dir, OUT PWSTR *File, OUT PWSTR *Ext);
  687. #define SplitPathA(path,dv,dir,f,e) SETTRACKCOMMENT_VOID ("SplitPathA",__FILE__,__LINE__)\
  688. RealSplitPathA(path,dv,dir,f,e)\
  689. CLRTRACKCOMMENT_VOID
  690. #define SplitPathW(path,dv,dir,f,e) SETTRACKCOMMENT_VOID ("SplitPathW",__FILE__,__LINE__)\
  691. RealSplitPathW(path,dv,dir,f,e)\
  692. CLRTRACKCOMMENT_VOID
  693. // Routine to extract the file from a path
  694. PCSTR GetFileNameFromPathA (IN PCSTR Path);
  695. PCWSTR GetFileNameFromPathW (IN PCWSTR Path);
  696. // Routine to extract the file extension from a path
  697. PCSTR GetFileExtensionFromPathA (IN PCSTR Path);
  698. PCWSTR GetFileExtensionFromPathW (IN PCWSTR Path);
  699. // Routine to extract the file extension from a path, including the dot, or the
  700. // end of the string if no extension exists
  701. PCSTR GetDotExtensionFromPathA (IN PCSTR Path);
  702. PCWSTR GetDotExtensionFromPathW (IN PCWSTR Path);
  703. // Routine to duplicate a path and allocate space for cat processing
  704. PSTR RealDuplicatePathStringA (IN PCSTR Path, IN DWORD ExtraBytes);
  705. PWSTR RealDuplicatePathStringW (IN PCWSTR Path, IN DWORD ExtraBytes);
  706. #define DuplicatePathStringA(path,eb) SETTRACKCOMMENT(PSTR,"DuplicatePathStringA",__FILE__,__LINE__)\
  707. RealDuplicatePathStringA(path,eb)\
  708. CLRTRACKCOMMENT
  709. #define DuplicatePathStringW(path,eb) SETTRACKCOMMENT(PWSTR,"DuplicatePathStringW",__FILE__,__LINE__)\
  710. RealDuplicatePathStringW(path,eb)\
  711. CLRTRACKCOMMENT
  712. // Routines to enumerate the PATH variable
  713. typedef struct _PATH_ENUMA {
  714. PSTR BufferPtr;
  715. PSTR PtrNextPath;
  716. PSTR PtrCurrPath;
  717. } PATH_ENUMA, *PPATH_ENUMA;
  718. BOOL
  719. EnumFirstPathExA (
  720. OUT PPATH_ENUMA PathEnum,
  721. IN PCSTR AdditionalPath,
  722. IN PCSTR WinDir,
  723. IN PCSTR SysDir,
  724. IN BOOL IncludeEnvPath
  725. );
  726. #define EnumFirstPathA(e,a,w,s) EnumFirstPathExA(e,a,w,s,TRUE)
  727. BOOL
  728. EnumNextPathA (
  729. IN OUT PPATH_ENUMA PathEnum
  730. );
  731. BOOL
  732. EnumPathAbortA (
  733. IN OUT PPATH_ENUMA PathEnum
  734. );
  735. // Frees a string allocated in g_PathsPool
  736. VOID
  737. FreePathStringExA (
  738. IN POOLHANDLE Pool, OPTIONAL
  739. IN PCSTR Path OPTIONAL
  740. );
  741. VOID
  742. FreePathStringExW (
  743. IN POOLHANDLE Pool, OPTIONAL
  744. IN PCWSTR Path OPTIONAL
  745. );
  746. #define FreePathStringA(p) FreePathStringExA(NULL,p)
  747. #define FreePathStringW(p) FreePathStringExW(NULL,p)
  748. // Removes a trailing backslash, if it exists
  749. #define RemoveWackAtEndA(str) _mbsctrim(str,'\\')
  750. #define RemoveWackAtEndW(str) _wcsctrim(str,L'\\')
  751. // Rule encoding functions used to encode a number of syntax-related
  752. // characters (backslash, brackets, asterisk, etc)
  753. PSTR EncodeRuleCharsA (PSTR szEncRule, PCSTR szRule);
  754. PWSTR EncodeRuleCharsW (PWSTR szEncRule, PCWSTR szRule);
  755. // Rule decoding functions used to restore an encoded string
  756. MBCHAR GetNextRuleCharA (PCSTR *p_szRule, BOOL *p_bFromHex);
  757. WCHAR GetNextRuleCharW (PCWSTR *p_szRule, BOOL *p_bFromHex);
  758. PSTR DecodeRuleCharsA (PSTR szRule, PCSTR szEncRule);
  759. PWSTR DecodeRuleCharsW (PWSTR szRule, PCWSTR szEncRule);
  760. PSTR DecodeRuleCharsABA (PSTR szRule, PCSTR szEncRuleStart, PCSTR End);
  761. PWSTR DecodeRuleCharsABW (PWSTR szRule, PCWSTR szEncRuleStart, PCWSTR End);
  762. // Returns a pointer to the next non-space character (uses isspace)
  763. PCSTR SkipSpaceA (PCSTR szStr);
  764. PCWSTR SkipSpaceW (PCWSTR szStr);
  765. // Returns a pointer to the first space character at the end of a string,
  766. // or a pointer to the terminating nul if no space exists at the end of the
  767. // string. (Used for trimming space.)
  768. PCSTR SkipSpaceRA (PCSTR szBaseStr, PCSTR szStr);
  769. PCWSTR SkipSpaceRW (PCWSTR szBaseStr, PCWSTR szStr);
  770. // Truncates a string after the last non-whitepace character
  771. VOID TruncateTrailingSpaceA (IN OUT PSTR Str);
  772. VOID TruncateTrailingSpaceW (IN OUT PWSTR Str);
  773. // Returns TRUE if str matches wstrPattern. Case-sensitive, supports
  774. // multiple asterisks and question marks.
  775. BOOL IsPatternMatchA (PCSTR wstrPattern, PCSTR wstrStr);
  776. BOOL IsPatternMatchW (PCWSTR wstrPattern, PCWSTR wstrStr);
  777. // Returns TRUE if str matches wstrPattern. Case-sensitive, supports
  778. // multiple asterisks and question marks.
  779. BOOL IsPatternMatchABA (PCSTR Pattern, PCSTR Start, PCSTR End);
  780. BOOL IsPatternMatchABW (PCWSTR Pattern, PCWSTR Start, PCWSTR End);
  781. //
  782. // More powerful pattern matching
  783. //
  784. #define SEGMENTTYPE_UNKNOWN 0
  785. #define SEGMENTTYPE_EXACTMATCH 1
  786. #define SEGMENTTYPE_OPTIONAL 2
  787. #define SEGMENTTYPE_REQUIRED 3
  788. typedef struct {
  789. UINT Type;
  790. union {
  791. // exact match
  792. struct {
  793. PCSTR LowerCasePhrase;
  794. UINT PhraseBytes;
  795. } Exact;
  796. // optional
  797. struct {
  798. UINT MaxLen; // zero if any length
  799. PCSTR IncludeSet; OPTIONAL
  800. PCSTR ExcludeSet; OPTIONAL
  801. } Wildcard;
  802. };
  803. } SEGMENTA, *PSEGMENTA;
  804. typedef struct {
  805. UINT SegmentCount;
  806. PSEGMENTA Segment;
  807. } PATTERNPROPSA, *PPATTERNPROPSA;
  808. typedef struct {
  809. UINT PatternCount;
  810. POOLHANDLE Pool;
  811. PPATTERNPROPSA Pattern;
  812. } PARSEDPATTERNA, *PPARSEDPATTERNA;
  813. typedef struct {
  814. UINT Type;
  815. union {
  816. // exact match
  817. struct {
  818. PCWSTR LowerCasePhrase;
  819. UINT PhraseBytes;
  820. } Exact;
  821. // wildcard
  822. struct {
  823. UINT MaxLen; // zero if any length
  824. PCWSTR IncludeSet; OPTIONAL
  825. PCWSTR ExcludeSet; OPTIONAL
  826. } Wildcard;
  827. };
  828. } SEGMENTW, *PSEGMENTW;
  829. typedef struct {
  830. UINT SegmentCount;
  831. PSEGMENTW Segment;
  832. } PATTERNPROPSW, *PPATTERNPROPSW;
  833. typedef struct {
  834. UINT PatternCount;
  835. POOLHANDLE Pool;
  836. PPATTERNPROPSW Pattern;
  837. } PARSEDPATTERNW, *PPARSEDPATTERNW;
  838. BOOL
  839. IsPatternMatchExA (
  840. IN PCSTR Pattern,
  841. IN PCSTR Start,
  842. IN PCSTR End
  843. );
  844. BOOL
  845. IsPatternMatchExW (
  846. IN PCWSTR Pattern,
  847. IN PCWSTR Start,
  848. IN PCWSTR End
  849. );
  850. PPARSEDPATTERNA
  851. CreateParsedPatternA (
  852. IN PCSTR Pattern
  853. );
  854. PPARSEDPATTERNW
  855. CreateParsedPatternW (
  856. IN PCWSTR Pattern
  857. );
  858. BOOL
  859. TestParsedPatternA (
  860. IN PPARSEDPATTERNA ParsedPattern,
  861. IN PCSTR StringToTest
  862. );
  863. BOOL
  864. TestParsedPatternW (
  865. IN PPARSEDPATTERNW ParsedPattern,
  866. IN PCWSTR StringToTest
  867. );
  868. BOOL
  869. TestParsedPatternABA (
  870. IN PPARSEDPATTERNA ParsedPattern,
  871. IN PCSTR StringToTest,
  872. IN PCSTR EndPlusOne
  873. );
  874. BOOL
  875. TestParsedPatternABW (
  876. IN PPARSEDPATTERNW ParsedPattern,
  877. IN PCWSTR StringToTest,
  878. IN PCWSTR EndPlusOne
  879. );
  880. VOID
  881. PrintPattern (
  882. PCSTR Pattern,
  883. PPARSEDPATTERNA Struct
  884. );
  885. VOID
  886. DestroyParsedPatternA (
  887. IN PPARSEDPATTERNA ParsedPattern
  888. );
  889. VOID
  890. DestroyParsedPatternW (
  891. IN PPARSEDPATTERNW ParsedPattern
  892. );
  893. // Character counters
  894. UINT CountInstancesOfCharA (PCSTR String, MBCHAR Char);
  895. UINT CountInstancesOfCharW (PCWSTR String, WCHAR Char);
  896. UINT CountInstancesOfCharIA (PCSTR String, MBCHAR Char);
  897. UINT CountInstancesOfCharIW (PCWSTR String, WCHAR Char);
  898. //
  899. // Message Functions
  900. //
  901. // An AllocTable is an array of HLOCAL pointers that the message routines
  902. // return. This table is maintained to allow a single function to clean up
  903. // all strings at once.
  904. //
  905. // All "Ex" functions (ParseMessageEx, GetStringResourceEx, and so on)
  906. // require a valid AllocTable pointer. A caller obtains this pointer by
  907. // calling CreateAllocTable before processing any message. The caller
  908. // cleans up the entire table by calling DestroyAllocTable.
  909. //
  910. // A set of macros can be used for short-term strings. ParseMessage and
  911. // GetStringResource work the same as their Ex counterparts, but operate
  912. // on the process-wide g_ShortTermAllocTable. Short-term strings are
  913. // freed with FreeStringResource.
  914. //
  915. // A routine that calls ParseMessage and/or GetStringResource several times
  916. // in the same function wrap the calls between BeginMessageProcessing and
  917. // EndMessageProcessing. Only one thread in the process can do this at a
  918. // time, and when EndMessageProcessing is called, all strings allocated
  919. // by ParseMessage or GetResourceString in the processing section are
  920. // automatically freed.
  921. //
  922. // AllocTable creation/deletion
  923. PGROWBUFFER CreateAllocTable (VOID);
  924. VOID DestroyAllocTable (PGROWBUFFER AllocTable);
  925. // The "Ex" functions
  926. // ParseMessageEx retrieves the string resource via FormatMessage
  927. PCSTR ParseMessageExA (PGROWBUFFER AllocTable, PCSTR Template, PCSTR ArgArray[]);
  928. PCWSTR ParseMessageExW (PGROWBUFFER AllocTable, PCWSTR Template, PCWSTR ArgArray[]);
  929. // GetStringResourceEx retrives an argument-less string resource
  930. PCSTR GetStringResourceExA (PGROWBUFFER AllocTable, UINT ID);
  931. PCWSTR GetStringResourceExW (PGROWBUFFER AllocTable, UINT ID);
  932. // Frees resources allocated by ParseMessageEx, GetStringResourceEx and all macros
  933. VOID FreeStringResourceExA (PGROWBUFFER AllocTable, PCSTR String);
  934. VOID FreeStringResourceExW (PGROWBUFFER AllocTable, PCWSTR String);
  935. // Frees resources allocated by ParseMessageEx, GetStringResourceEx and all macros.
  936. // Tests String first; nulls when freed.
  937. VOID FreeStringResourcePtrExA (PGROWBUFFER AllocTable, PCSTR * String);
  938. VOID FreeStringResourcePtrExW (PGROWBUFFER AllocTable, PCWSTR * String);
  939. // Macros
  940. extern PGROWBUFFER g_ShortTermAllocTable;
  941. #define ParseMessageA(strid,args) ParseMessageExA(g_ShortTermAllocTable, strid, args)
  942. #define ParseMessageW(strid,args) ParseMessageExW(g_ShortTermAllocTable, strid, args)
  943. #define ParseMessageIDA(id,args) ParseMessageExA(g_ShortTermAllocTable, (PCSTR) (id), args)
  944. #define ParseMessageIDW(id,args) ParseMessageExW(g_ShortTermAllocTable, (PCWSTR) (id), args)
  945. #define ParseMessageIDExA(table,id,args) ParseMessageExA(table, (PCSTR) (id), args)
  946. #define ParseMessageIDExW(table,id,args) ParseMessageExW(table, (PCWSTR) (id), args)
  947. #define GetStringResourceA(id) GetStringResourceExA(g_ShortTermAllocTable, id)
  948. #define GetStringResourceW(id) GetStringResourceExW(g_ShortTermAllocTable, id)
  949. #define FreeStringResourceA(str) FreeStringResourceExA(g_ShortTermAllocTable, str)
  950. #define FreeStringResourceW(str) FreeStringResourceExW(g_ShortTermAllocTable, str)
  951. #define FreeStringResourcePtrA(str) FreeStringResourcePtrExA(g_ShortTermAllocTable, str)
  952. #define FreeStringResourcePtrW(str) FreeStringResourcePtrExW(g_ShortTermAllocTable, str)
  953. // Functions for single-threaded message-intensive processing loops
  954. BOOL BeginMessageProcessing (VOID);
  955. VOID EndMessageProcessing (VOID);
  956. //
  957. // The following message functions do not return strings, so they do not
  958. // need cleanup.
  959. //
  960. // An odd variant--obtains message ID from a window's text and replaces
  961. // it with the actual message. Useful in dialog box initialization.
  962. VOID ParseMessageInWndA (HWND hwnd, PCSTR ArgArray[]);
  963. VOID ParseMessageInWndW (HWND hwnd, PCWSTR ArgArray[]);
  964. // Displays a message box using a message string
  965. INT ResourceMessageBoxA (HWND hwndOwner, UINT ID, UINT Flags, PCSTR ArgArray[]);
  966. INT ResourceMessageBoxW (HWND hwndOwner, UINT ID, UINT Flags, PCWSTR ArgArray[]);
  967. //
  968. // Functions that don't care about UNICODE or MBCS
  969. // and realy shouldn't be in strings.h/.c
  970. //
  971. // Pushes dwError on a global error stack
  972. void PushNewError (DWORD dwError);
  973. // Pushes the return of GetLastError() on a global error stack
  974. void PushError (void);
  975. // Pops the last error from the global error stack, calls SetLastError
  976. // and returns the popped error code.
  977. DWORD PopError (void);
  978. // Returns an int value for chars 0-9, a-f, A-F, and -1 for all others
  979. int GetHexDigit (IN int c);
  980. //
  981. // Inline functions
  982. //
  983. // Returns the character at str[pos]
  984. __inline MBCHAR _mbsgetc(PCSTR str, DWORD pos) {
  985. return (MBCHAR) _mbsnextc((const unsigned char *) CharCountToPointerA ((PSTR) str, pos));
  986. }
  987. __inline WCHAR _wcsgetc(PCWSTR str, DWORD pos) {
  988. return *CharCountToPointerW ((PWSTR) str, pos);
  989. }
  990. // Sets the character at str[pos]
  991. // Multibyte version may grow string by one byte.
  992. __inline void _mbssetc(PSTR str, DWORD pos, MBCHAR c) {
  993. _setmbchar (CharCountToPointerA (str, pos), c);
  994. }
  995. __inline void _wcssetc(PWSTR str, DWORD pos, WCHAR c) {
  996. *CharCountToPointerW (str, pos) = c;
  997. }
  998. // Bug fix for C Runtime _tcsdec
  999. __inline PWSTR _wcsdec2(PCWSTR base, PCWSTR p) {
  1000. if (base >= p) {
  1001. return NULL;
  1002. }
  1003. return (PWSTR) (p-1);
  1004. }
  1005. // Bug fix for C Runtime _tcsdec
  1006. __inline PSTR _mbsdec2(PCSTR base, PCSTR p) {
  1007. if (base >= p) {
  1008. return NULL;
  1009. }
  1010. return (PSTR) _mbsdec((const unsigned char *) base, (const unsigned char *) p);
  1011. }
  1012. // A handy strncpy with forced termination
  1013. PSTR _mbsnzcpy (PSTR dest, PCSTR src, int count);
  1014. PWSTR _wcsnzcpy (PWSTR dest, PCWSTR src, int count);
  1015. // A handy strncpy used for buffer overrun containment
  1016. #define _mbssafecpy(dest,src,bufsize) _mbsnzcpy(dest,src,(bufsize)-sizeof(CHAR))
  1017. #define _wcssafecpy(dest,src,bufsize) _wcsnzcpy(dest,src,(bufsize)-sizeof(WCHAR))
  1018. // strcpyab with forced termination and termination guard
  1019. PSTR _mbsnzcpyab (PSTR Dest, PCSTR Start, PCSTR End, int count);
  1020. PWSTR _wcsnzcpyab (PWSTR Dest, PCWSTR Start, PCWSTR End, int count);
  1021. // A handy strncpyab used for buffer overrun containment
  1022. #define _mbssafecpyab(dest,start,end,bufsize) _mbsnzcpyab(dest,start,end,(bufsize)-sizeof(CHAR))
  1023. #define _wcssafecpyab(dest,start,end,bufsize) _wcsnzcpyab(dest,start,end,(bufsize)-sizeof(WCHAR))
  1024. // Routine that checks string for a prefix
  1025. #define StringPrefixA(str,prefix) StringMatchCharCountA(str,prefix,CharCountA(prefix))
  1026. #define StringIPrefixA(str,prefix) StringIMatchCharCountA(str,prefix,CharCountA(prefix))
  1027. #define StringPrefixW(str,prefix) StringMatchCharCountW(str,prefix,CharCountW(prefix))
  1028. #define StringIPrefixW(str,prefix) StringIMatchCharCountW(str,prefix,CharCountW(prefix))
  1029. //
  1030. // Sub String Replacement functions.
  1031. //
  1032. BOOL StringReplaceW (PWSTR Buffer,DWORD MaxSize,PWSTR ReplaceStartPos,PWSTR ReplaceEndPos,PCWSTR NewString);
  1033. BOOL StringReplaceA (PSTR Buffer,DWORD MaxSize,PSTR ReplaceStartPos,PSTR ReplaceEndPos,PCSTR NewString);
  1034. //
  1035. // String table population from INF section
  1036. //
  1037. typedef enum {
  1038. CALLBACK_CONTINUE,
  1039. CALLBACK_SKIP,
  1040. CALLBACK_STOP
  1041. } CALLBACK_RESULT;
  1042. typedef CALLBACK_RESULT(ADDINFSECTION_PROTOTYPEA)(PCSTR String, PVOID * DataPtr,
  1043. UINT * DataSizePtr, PVOID CallbackData);
  1044. typedef CALLBACK_RESULT(ADDINFSECTION_PROTOTYPEW)(PCWSTR String, PVOID * DataPtr,
  1045. UINT * DataSizePtr, PVOID CallbackData);
  1046. typedef ADDINFSECTION_PROTOTYPEA * ADDINFSECTION_PROCA;
  1047. typedef ADDINFSECTION_PROTOTYPEW * ADDINFSECTION_PROCW;
  1048. #if 0
  1049. BOOL AddInfSectionToStringTableA (PVOID, HINF, PCSTR, INT, ADDINFSECTION_PROCA, PVOID);
  1050. BOOL AddInfSectionToStringTableW (PVOID, HINF, PCWSTR, INT, ADDINFSECTION_PROCW, PVOID);
  1051. #endif
  1052. UINT
  1053. CountInstancesOfSubStringA (
  1054. IN PCSTR SourceString,
  1055. IN PCSTR SearchString
  1056. );
  1057. UINT
  1058. CountInstancesOfSubStringW (
  1059. IN PCWSTR SourceString,
  1060. IN PCWSTR SearchString
  1061. );
  1062. PCSTR
  1063. StringSearchAndReplaceA (
  1064. IN PCSTR SourceString,
  1065. IN PCSTR SearchString,
  1066. IN PCSTR ReplaceString
  1067. );
  1068. PCWSTR
  1069. StringSearchAndReplaceW (
  1070. IN PCWSTR SourceString,
  1071. IN PCWSTR SearchString,
  1072. IN PCWSTR ReplaceString
  1073. );
  1074. typedef struct _MULTISZ_ENUMA {
  1075. PCSTR Buffer;
  1076. PCSTR CurrentString;
  1077. } MULTISZ_ENUMA, *PMULTISZ_ENUMA;
  1078. typedef struct _MULTISZ_ENUMW {
  1079. PCWSTR Buffer;
  1080. PCWSTR CurrentString;
  1081. } MULTISZ_ENUMW, *PMULTISZ_ENUMW;
  1082. BOOL
  1083. EnumNextMultiSzA (
  1084. IN OUT PMULTISZ_ENUMA MultiSzEnum
  1085. );
  1086. BOOL
  1087. EnumNextMultiSzW (
  1088. IN OUT PMULTISZ_ENUMW MultiSzEnum
  1089. );
  1090. BOOL
  1091. EnumFirstMultiSzA (
  1092. OUT PMULTISZ_ENUMA MultiSzEnum,
  1093. IN PCSTR MultiSzStr
  1094. );
  1095. BOOL
  1096. EnumFirstMultiSzW (
  1097. OUT PMULTISZ_ENUMW MultiSzEnum,
  1098. IN PCWSTR MultiSzStr
  1099. );
  1100. VOID
  1101. ToggleWacksW (
  1102. IN OUT PWSTR String,
  1103. IN BOOL Operation
  1104. );
  1105. VOID
  1106. ToggleWacksA (
  1107. IN OUT PSTR String,
  1108. IN BOOL Operation
  1109. );
  1110. PCSTR
  1111. SanitizePathA (
  1112. IN PCSTR FileSpec
  1113. );
  1114. PCWSTR
  1115. SanitizePathW (
  1116. IN PCWSTR FileSpec
  1117. );
  1118. PCSTR
  1119. ConvertSBtoDB (
  1120. PCSTR RootPath,
  1121. PCSTR FullPath,
  1122. PCSTR Limit
  1123. );
  1124. //
  1125. // TCHAR mappings
  1126. //
  1127. #ifdef UNICODE
  1128. #define CharCount CharCountW
  1129. #define CharCountToPointer CharCountToPointerW
  1130. #define CharCountAB CharCountABW
  1131. #define CharCountInByteRange CharCountInByteRangeW
  1132. #define CharCountToBytes CharCountToBytesW
  1133. #define CharCountToTchars CharCountToTcharsW
  1134. #define ByteCount ByteCountW
  1135. #define SizeOfString SizeOfStringW
  1136. #define SizeOfMultiSz SizeOfMultiSzW
  1137. #define MultiSzSizeInChars MultiSzSizeInCharsW
  1138. #define ByteCountToPointer ByteCountToPointerW
  1139. #define ByteCountAB ByteCountABW
  1140. #define ByteCountToChars ByteCountToCharsW
  1141. #define ByteCountToTchars ByteCountToTcharsW
  1142. #define TcharCount TcharCountW
  1143. #define TcharCountToPointer TcharCountToPointerW
  1144. #define TcharCountAB TcharCountABW
  1145. #define TcharCountToChars TcharCountToCharsW
  1146. #define TcharCountToBytes TcharCountToBytesW
  1147. #define StackStringCopy StackStringCopyW
  1148. #define StringCompare StringCompareW
  1149. #define StringMatch StringMatchW
  1150. #define StringICompare StringICompareW
  1151. #define StringIMatch StringIMatchW
  1152. #define StringCompareByteCount StringCompareByteCountW
  1153. #define StringMatchByteCount StringMatchByteCountW
  1154. #define StringICompareByteCount StringICompareByteCountW
  1155. #define StringIMatchByteCount StringIMatchByteCountW
  1156. #define StringCompareCharCount StringCompareCharCountW
  1157. #define StringMatchCharCount StringMatchCharCountW
  1158. #define StringICompareCharCount StringICompareCharCountW
  1159. #define StringIMatchCharCount StringIMatchCharCountW
  1160. #define StringCompareTcharCount StringCompareTcharCountW
  1161. #define StringMatchTcharCount StringMatchTcharCountW
  1162. #define StringICompareTcharCount StringICompareTcharCountW
  1163. #define StringIMatchTcharCount StringIMatchTcharCountW
  1164. #define StringCompareAB StringCompareABW
  1165. #define StringMatchAB StringMatchABW
  1166. #define StringICompareAB StringICompareABW
  1167. #define StringIMatchAB StringIMatchABW
  1168. #define StringCopy StringCopyW
  1169. #define StringCopyByteCount StringCopyByteCountW
  1170. #define StringCopyCharCount StringCopyCharCountW
  1171. #define StringCopyTcharCount StringCopyTcharCountW
  1172. #define StringCopyAB StringCopyABW
  1173. #define StringCat StringCatW
  1174. #define GetEndOfString GetEndOfStringW
  1175. #define GetPrevChar GetPrevCharW
  1176. #define AllocTextEx AllocTextExW
  1177. #define AllocText AllocTextW
  1178. #define FreeTextEx FreeTextExW
  1179. #define FreeText FreeTextW
  1180. #define DuplicateText DuplicateTextW
  1181. #define DuplicateTextEx DuplicateTextExW
  1182. #define JoinTextEx JoinTextExW
  1183. #define JoinText JoinTextW
  1184. #define ExpandEnvironmentText ExpandEnvironmentTextW
  1185. #define ExpandEnvironmentTextEx ExpandEnvironmentTextExW
  1186. #define CommandLineToArgv CommandLineToArgvW
  1187. #define _tcsdec2 _wcsdec2
  1188. #define _copytchar _copywchar
  1189. #define _settchar _setwchar
  1190. #define _tcsgetc _wcsgetc
  1191. #define _tcssetc _wcssetc
  1192. #define _tcsnum _wcsnum
  1193. #define _tcsappend _wcsappend
  1194. #define _tcsistr _wcsistr
  1195. #define _tcsisprint _wcsisprint
  1196. #define _tcsnzcpy _wcsnzcpy
  1197. #define _tcssafecpy _wcssafecpy
  1198. #define _tcsnzcpyab _wcsnzcpyab
  1199. #define _tcssafecpyab _wcssafecpyab
  1200. #define StringPrefix StringPrefixW
  1201. #define StringIPrefix StringIPrefixW
  1202. #define _tcsctrim _wcsctrim
  1203. #define AppendWack AppendWackW
  1204. #define AppendDosWack AppendDosWackW
  1205. #define AppendUncWack AppendUncWackW
  1206. #define AppendPathWack AppendPathWackW
  1207. #define RemoveWackAtEnd RemoveWackAtEndW
  1208. #define JoinPathsEx JoinPathsExW
  1209. #define JoinPaths JoinPathsW
  1210. #define AllocPathString AllocPathStringW
  1211. #define SplitPath SplitPathW
  1212. #define GetFileNameFromPath GetFileNameFromPathW
  1213. #define GetFileExtensionFromPath GetFileExtensionFromPathW
  1214. #define GetDotExtensionFromPath GetDotExtensionFromPathW
  1215. #define DuplicatePathString DuplicatePathStringW
  1216. #define FreePathStringEx FreePathStringExW
  1217. #define FreePathString FreePathStringW
  1218. #define GetNextRuleChar GetNextRuleCharW
  1219. #define DecodeRuleChars DecodeRuleCharsW
  1220. #define DecodeRuleCharsAB DecodeRuleCharsABW
  1221. #define EncodeRuleChars EncodeRuleCharsW
  1222. #define SkipSpace SkipSpaceW
  1223. #define SkipSpaceR SkipSpaceRW
  1224. #define TruncateTrailingSpace TruncateTrailingSpaceW
  1225. #define IsPatternMatch IsPatternMatchW
  1226. #define IsPatternMatchAB IsPatternMatchABW
  1227. #define PPARSEDPATTERN PPARSEDPATTERNW
  1228. #define PARSEDPATTERN PARSEDPATTERNW
  1229. #define CreateParsedPattern CreateParsedPatternW
  1230. #define IsPatternMatchEx IsPatternMatchExW
  1231. #define TestParsedPattern TestParsedPatternW
  1232. #define TestParsedPatternAB TestParsedPatternABW
  1233. #define DestroyParsedPattern DestroyParsedPatternW
  1234. #define CountInstancesOfChar CountInstancesOfCharW
  1235. #define CountInstancesOfCharI CountInstancesOfCharIW
  1236. #define StringReplace StringReplaceW
  1237. #define CountInstancesOfSubString CountInstancesOfSubStringW
  1238. #define StringSearchAndReplace StringSearchAndReplaceW
  1239. #define MULTISZ_ENUM MULTISZ_ENUMW
  1240. #define EnumFirstMultiSz EnumFirstMultiSzW
  1241. #define EnumNextMultiSz EnumNextMultiSzW
  1242. #define ParseMessage ParseMessageW
  1243. #define ParseMessageEx ParseMessageExW
  1244. #define ParseMessageID ParseMessageIDW
  1245. #define ParseMessageIDEx ParseMessageIDExW
  1246. #define GetStringResource GetStringResourceW
  1247. #define GetStringResourceEx GetStringResourceExW
  1248. #define FreeStringResource FreeStringResourceW
  1249. #define ParseMessageInWnd ParseMessageInWndW
  1250. #define ResourceMessageBox ResourceMessageBoxW
  1251. #if 0
  1252. #define AddInfSectionToStringTable AddInfSectionToStringTableW
  1253. #endif
  1254. #define ADDINFSECTION_PROC ADDINFSECTION_PROCW
  1255. #define ReplaceWacks(f) ToggleWacksW(f,FALSE)
  1256. #define RestoreWacks(f) ToggleWacksW(f,TRUE)
  1257. #define SanitizePath SanitizePathW
  1258. #else
  1259. #define CharCount CharCountA
  1260. #define CharCountToPointer CharCountToPointerA
  1261. #define CharCountAB CharCountABA
  1262. #define CharCountInByteRange CharCountInByteRangeA
  1263. #define CharCountToBytes CharCountToBytesA
  1264. #define CharCountToTchars CharCountToTcharsA
  1265. #define ByteCount ByteCountA
  1266. #define SizeOfString SizeOfStringA
  1267. #define SizeOfMultiSz SizeOfMultiSzA
  1268. #define MultiSzSizeInChars MultiSzSizeInCharsA
  1269. #define ByteCountToPointer ByteCountToPointerA
  1270. #define ByteCountAB ByteCountABA
  1271. #define ByteCountToChars ByteCountToCharsA
  1272. #define ByteCountToTchars ByteCountToTcharsA
  1273. #define TcharCount TcharCountA
  1274. #define TcharCountToPointer TcharCountToPointerA
  1275. #define TcharCountAB TcharCountABA
  1276. #define TcharCountToChars TcharCountToCharsA
  1277. #define TcharCountToBytes TcharCountToBytesA
  1278. #define StackStringCopy StackStringCopyA
  1279. #define StringCompare StringCompareA
  1280. #define StringMatch StringMatchA
  1281. #define StringICompare StringICompareA
  1282. #define StringIMatch StringIMatchA
  1283. #define StringCompareByteCount StringCompareByteCountA
  1284. #define StringMatchByteCount StringMatchByteCountA
  1285. #define StringICompareByteCount StringICompareByteCountA
  1286. #define StringIMatchByteCount StringIMatchByteCountA
  1287. #define StringCompareCharCount StringCompareCharCountA
  1288. #define StringMatchCharCount StringMatchCharCountA
  1289. #define StringICompareCharCount StringICompareCharCountA
  1290. #define StringIMatchCharCount StringIMatchCharCountA
  1291. #define StringCompareTcharCount StringCompareTcharCountA
  1292. #define StringMatchTcharCount StringMatchTcharCountA
  1293. #define StringICompareTcharCount StringICompareTcharCountA
  1294. #define StringIMatchTcharCount StringIMatchTcharCountA
  1295. #define StringCompareAB StringCompareABA
  1296. #define StringMatchAB StringMatchABA
  1297. #define StringICompareAB StringICompareABA
  1298. #define StringIMatchAB StringIMatchABA
  1299. #define StringCopy StringCopyA
  1300. #define StringCopyByteCount StringCopyByteCountA
  1301. #define StringCopyCharCount StringCopyCharCountA
  1302. #define StringCopyTcharCount StringCopyTcharCountA
  1303. #define StringCopyAB StringCopyABA
  1304. #define StringCat StringCatA
  1305. #define GetEndOfString GetEndOfStringA
  1306. #define GetPrevChar GetPrevCharA
  1307. #define AllocTextEx AllocTextExA
  1308. #define AllocText AllocTextA
  1309. #define FreeTextEx FreeTextExA
  1310. #define FreeText FreeTextA
  1311. #define DuplicateText DuplicateTextA
  1312. #define DuplicateTextEx DuplicateTextExA
  1313. #define JoinTextEx JoinTextExA
  1314. #define JoinText JoinTextA
  1315. #define ExpandEnvironmentText ExpandEnvironmentTextA
  1316. #define ExpandEnvironmentTextEx ExpandEnvironmentTextExA
  1317. #define CommandLineToArgv CommandLineToArgvA
  1318. #define _tcsdec2 _mbsdec2
  1319. #define _copytchar _copymbchar
  1320. #define _settchar _setmbchar
  1321. #define _tcsgetc _mbsgetc
  1322. #define _tcssetc _mbssetc
  1323. #define _tcsnum _mbsnum
  1324. #define _tcsappend _mbsappend
  1325. #define _tcsistr _mbsistr
  1326. #define _tcsisprint _mbsisprint
  1327. #define _tcsnzcpy _mbsnzcpy
  1328. #define _tcssafecpy _mbssafecpy
  1329. #define _tcsnzcpyab _mbsnzcpyab
  1330. #define _tcssafecpyab _mbssafecpyab
  1331. #define StringPrefix StringPrefixA
  1332. #define StringIPrefix StringIPrefixA
  1333. #define _tcsctrim _mbsctrim
  1334. #define AppendWack AppendWackA
  1335. #define AppendDosWack AppendDosWackA
  1336. #define AppendUncWack AppendUncWackA
  1337. #define AppendPathWack AppendPathWackA
  1338. #define RemoveWackAtEnd RemoveWackAtEndA
  1339. #define JoinPathsEx JoinPathsExA
  1340. #define JoinPaths JoinPathsA
  1341. #define AllocPathString AllocPathStringA
  1342. #define SplitPath SplitPathA
  1343. #define GetFileNameFromPath GetFileNameFromPathA
  1344. #define GetFileExtensionFromPath GetFileExtensionFromPathA
  1345. #define GetDotExtensionFromPath GetDotExtensionFromPathA
  1346. #define DuplicatePathString DuplicatePathStringA
  1347. #define PATH_ENUM PATH_ENUMA
  1348. #define PPATH_ENUM PPATH_ENUMA
  1349. #define EnumFirstPathEx EnumFirstPathExA
  1350. #define EnumFirstPath EnumFirstPathA
  1351. #define EnumNextPath EnumNextPathA
  1352. #define EnumPathAbort EnumPathAbortA
  1353. #define FreePathStringEx FreePathStringExA
  1354. #define FreePathString FreePathStringA
  1355. #define GetNextRuleChar GetNextRuleCharA
  1356. #define DecodeRuleChars DecodeRuleCharsA
  1357. #define DecodeRuleCharsAB DecodeRuleCharsABA
  1358. #define EncodeRuleChars EncodeRuleCharsA
  1359. #define SkipSpace SkipSpaceA
  1360. #define SkipSpaceR SkipSpaceRA
  1361. #define TruncateTrailingSpace TruncateTrailingSpaceA
  1362. #define IsPatternMatch IsPatternMatchA
  1363. #define IsPatternMatchAB IsPatternMatchABA
  1364. #define PPARSEDPATTERN PPARSEDPATTERNA
  1365. #define PARSEDPATTERN PARSEDPATTERNA
  1366. #define CreateParsedPattern CreateParsedPatternA
  1367. #define IsPatternMatchEx IsPatternMatchExA
  1368. #define TestParsedPattern TestParsedPatternA
  1369. #define TestParsedPatternAB TestParsedPatternABA
  1370. #define DestroyParsedPattern DestroyParsedPatternA
  1371. #define CountInstancesOfChar CountInstancesOfCharA
  1372. #define CountInstancesOfCharI CountInstancesOfCharIA
  1373. #define StringReplace StringReplaceA
  1374. #define CountInstancesOfSubString CountInstancesOfSubStringA
  1375. #define StringSearchAndReplace StringSearchAndReplaceA
  1376. #define MULTISZ_ENUM MULTISZ_ENUMA
  1377. #define EnumFirstMultiSz EnumFirstMultiSzA
  1378. #define EnumNextMultiSz EnumNextMultiSzA
  1379. #define ParseMessage ParseMessageA
  1380. #define ParseMessageEx ParseMessageExA
  1381. #define ParseMessageID ParseMessageIDA
  1382. #define ParseMessageIDEx ParseMessageIDExA
  1383. #define GetStringResource GetStringResourceA
  1384. #define GetStringResourceEx GetStringResourceExA
  1385. #define FreeStringResource FreeStringResourceA
  1386. #define ParseMessageInWnd ParseMessageInWndA
  1387. #define ResourceMessageBox ResourceMessageBoxA
  1388. #if 0
  1389. #define AddInfSectionToStringTable AddInfSectionToStringTableA
  1390. #endif
  1391. #define ADDINFSECTION_PROC ADDINFSECTION_PROCA
  1392. #define ReplaceWacks(f) ToggleWacksA(f,FALSE)
  1393. #define RestoreWacks(f) ToggleWacksA(f,TRUE)
  1394. #define SanitizePath SanitizePathA
  1395. #endif
  1396. //
  1397. // MessageBox macros
  1398. //
  1399. #define YesNoBox(hwnd,ID) ResourceMessageBox(hwnd,ID,MB_YESNO|MB_ICONQUESTION|MB_SETFOREGROUND,NULL)
  1400. #define YesNoCancelBox(hwnd,ID) ResourceMessageBox(hwnd,ID,MB_YESNOCANCEL|MB_ICONQUESTION|MB_SETFOREGROUND,NULL)
  1401. #define OkBox(hwnd,ID) ResourceMessageBox(hwnd,ID,MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND,NULL)
  1402. #define OkCancelBox(hwnd,ID) ResourceMessageBox(hwnd,ID,MB_OKCANCEL|MB_ICONQUESTION|MB_SETFOREGROUND,NULL)
  1403. #define RetryCancelBox(hwnd,ID) ResourceMessageBox(hwnd,ID,MB_RETRYCANCEL|MB_ICONQUESTION|MB_SETFOREGROUND,NULL)