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.

797 lines
23 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: NLGLib.h
  3. *
  4. * Copyright (c) 1997, Microsoft Corporation
  5. *
  6. * History:
  7. 1/26/98 DougP prefix dbgMalloc, dbgFree, and dbgRealloc with CMN_
  8. whack defs of malloc, free, and realloc
  9. \***************************************************************************/
  10. #ifndef _NLGLIB_H_
  11. #define _NLGLIB_H_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <stdio.h> // For the definition of FILE
  16. // Mapped file stuff
  17. //
  18. typedef struct _TAG_MFILE {
  19. HANDLE hFile;
  20. HANDLE hFileMap;
  21. DWORD cbSize1;
  22. DWORD cbSize2;
  23. PVOID pvMap;
  24. BOOL fSrcUnicode;
  25. BOOL fDstUnicode;
  26. union {
  27. WCHAR * pwsz;
  28. CHAR * psz;
  29. };
  30. UINT uCodePage; // codepage for conversions
  31. } MFILE, *PMFILE;
  32. // ----------------------------------------------------------------------
  33. // misc.c
  34. // ----------------------------------------------------------------------
  35. #ifdef _UNICODE
  36. #define OpenMapFile OpenMapFileW
  37. #define OpenDataFile OpenDataFileW
  38. #define OpenOutFile OpenOutFileW
  39. #else
  40. #define OpenMapFile OpenMapFileA
  41. #endif
  42. BOOL WINAPI ResetMap(PMFILE pmf);
  43. BOOL WINAPI CloseMapFile(PMFILE pmf);
  44. PMFILE WINAPI OpenMapFileA(const char *pszFileName);
  45. PVOID WINAPI GetMapLine(PVOID pv0, DWORD cbMac, PMFILE pmf);
  46. BOOL WINAPI NextMapLine(PMFILE pmf);
  47. PMFILE WINAPI OpenMapFileWorker(const WCHAR * pwszFileName, BOOL fDstUnicode);
  48. #define OpenMapFileW(pwszFileName) OpenMapFileWorker(pwszFileName, TRUE)
  49. #define OpenDataFileW(pwszFileName) OpenMapFileWorker(pwszFileName, TRUE)
  50. #define OpenOutFileW(pwszFileName) OpenMapFileWorker(pwszFileName, TRUE)
  51. // Inverse Probability Log (IPL) stuff
  52. //
  53. typedef BYTE IPL;
  54. #define IPL_UNKNOWN 0xFF
  55. // All ipl values must be strictly less than this.
  56. // This corresponds to a probability of 1 in 4 billion, so
  57. // it supports a corpus of 4 billion items (chars, words, sentences, etc.)
  58. //
  59. #define IPL_LIMIT 32
  60. // Multiplier is used to boost precision of low ipls
  61. //
  62. #define IPL_MULTIPLIER 8 // 256 divided by 32 = 8
  63. #define Ipl2Freq( ipl, cTotalFreq) ((cTotalFreq) >> (ipl))
  64. IPL WINAPI Freq2Ipl( double );
  65. DWORD WINAPI GetCRC32( IN BYTE *pb, IN DWORD cb);
  66. WORD WINAPI GetCRC16( IN BYTE *pb, IN DWORD cb);
  67. // ----------------------------------------------------------------------
  68. // mapsort.c
  69. // ----------------------------------------------------------------------
  70. // Sort and Unique stuff
  71. //
  72. #ifdef _UNICODE
  73. #define MapSort MapSortW
  74. #define MapUnique MapUniqueW
  75. #define Member MemberW
  76. #define RecordString RecordStringW
  77. #else // _UNICODE not defined
  78. #define MapSort MapSortA
  79. #define MapUnique MapUniqueA
  80. #endif // _UNICODE
  81. BOOL WINAPI MapSortW( CONST WCHAR * pszFileName);
  82. BOOL WINAPI MapSortA( CHAR * pszFileName);
  83. BOOL WINAPI MapUniqueW( CONST WCHAR * pwszFileName);
  84. BOOL WINAPI MapUniqueA( CHAR * pszFileName);
  85. // ----------------------------------------------------------------------
  86. // mcodes.c
  87. // ----------------------------------------------------------------------
  88. // WARNING WARNING WARNING
  89. // cpheme creation mode - should be consistent with T-Hammer
  90. #define CPHEME_MODE_STRICT 0x0001
  91. #define CPHEME_MODE_DUPLICATE 0x0002
  92. #define STEM_ATTR_COMPV 0x0010
  93. typedef struct _tagMETABASES {
  94. WCHAR wcOphemeBase;
  95. WCHAR wcMinTrieChar;
  96. WCHAR wcStemBase;
  97. WCHAR wcFcnBase;
  98. WCHAR wcSelBase;
  99. } METABASE, *PMETABASE;
  100. // Stem/Morph Code file stuff
  101. //
  102. void WINAPI ReadBases( METABASE *pMetaBases );
  103. void WINAPI WriteBases( METABASE *pMetaBases );
  104. void WINAPI
  105. WriteFcnCodes(
  106. WCHAR **ppwzMorphs,
  107. DWORD cMorphs,
  108. PWORD pwSelections);
  109. void WINAPI
  110. WriteCodesBin(
  111. CONST WCHAR *pwzFileName,
  112. WCHAR **ppwzMorphs,
  113. DWORD cMorphs,
  114. WCHAR **ppwzAttr1,
  115. WCHAR **ppwzAttr2,
  116. PWORD pwAttributes);
  117. BOOL WINAPI
  118. GetCodes(
  119. WCHAR *wszCodesFile,
  120. WCHAR **ppwszBuffer,
  121. WCHAR **ppwszCodes,
  122. DWORD *pcCodes,
  123. DWORD cCodesMac);
  124. BOOL WINAPI
  125. GetCodesUnsorted(
  126. WCHAR *wszCodesFile,
  127. WCHAR **ppwszBuffer,
  128. WCHAR **ppwszCodes,
  129. DWORD *pcCodes,
  130. DWORD cCodesMac);
  131. BOOL WINAPI
  132. GetCodeAttributes(
  133. WCHAR *wszCodesFile,
  134. WCHAR **ppwszCodes,
  135. DWORD cCodes,
  136. WCHAR **ppwszBuffer,
  137. WCHAR **ppwszAttr1,
  138. WCHAR **ppwszAttr2,
  139. WORD *pwAttrFlags);
  140. BOOL WINAPI
  141. LoadMCatMappingTable(
  142. WCHAR *wszCodesFile,
  143. WCHAR **ppwszCodes,
  144. DWORD cCodes,
  145. WCHAR **ppwszTBits,
  146. DWORD cTBits,
  147. WORD *pwTBitToMCat,
  148. WORD *pwSubMToMCat);
  149. BOOL WINAPI
  150. MCatFromTBit(
  151. DWORD iTBit,
  152. DWORD *piMCat,
  153. WORD *pwTBitToMCat,
  154. DWORD cTBits);
  155. BOOL WINAPI
  156. MCatFromSubM(
  157. DWORD iSubM,
  158. DWORD *piMCat,
  159. WORD *pwSubMToMCat,
  160. DWORD cCodes);
  161. BOOL WINAPI
  162. EnumSubMFromMCat(
  163. DWORD iMCat,
  164. DWORD *piSubM,
  165. WORD *pwSubMToMCat,
  166. DWORD cCodes);
  167. // ----------------------------------------------------------------------
  168. // ctplus0.c
  169. // ----------------------------------------------------------------------
  170. // Character type routines
  171. BYTE WINAPI
  172. GetCharType(WCHAR wc );
  173. // ----------------------------------------------------------------------
  174. // fileio.c
  175. // ----------------------------------------------------------------------
  176. // File I/O Wrappers
  177. //
  178. HANDLE WINAPI ThCreate( CONST WCHAR * );
  179. HANDLE WINAPI ThOpen( CONST WCHAR * );
  180. UINT WINAPI ThRead( HANDLE , LPVOID , UINT );
  181. UINT WINAPI ThWrite( HANDLE, LPCVOID , UINT );
  182. // CRT Unicode routines
  183. //
  184. int WINAPI UStrCmp(const WCHAR *pwsz1, const WCHAR *pwsz2);
  185. DWORD WINAPI MemberW(WCHAR * ,WCHAR **, DWORD);
  186. DWORD WINAPI RecordString(WCHAR *, WCHAR **, WCHAR *, DWORD *, DWORD *);
  187. void WINAPI PutLine(const WCHAR *, FILE *);
  188. WCHAR * WINAPI GetLine(WCHAR *, int , FILE *);
  189. #define PrimeHash(wOld, wNew, cBitsMax) (((wOld) + (wNew))*hashPrime[cBitsMax]&hashMask[cBitsMax])
  190. extern const unsigned int hashPrime[];
  191. extern const unsigned int hashMask[];
  192. // #include "ctplus0.h"
  193. //-----------------------------------------------------------+
  194. // memory allocation:
  195. // In the debug version, we compile in the debugging memory
  196. // allocator and aim our allocation macros at it.
  197. // In retail, the macros just use LocalAlloc
  198. //-----------------------------------------------------------+
  199. #if defined(_DEBUG)
  200. void * WINAPI dbgMalloc(size_t cb);
  201. void * WINAPI dbgCalloc(size_t c, size_t cb);
  202. void * WINAPI dbgFree(void* pv);
  203. void * WINAPI dbgRealloc(void* pv, size_t cb);
  204. void * WINAPI dbgMallocCore(size_t cb, BOOL fTrackUsage);
  205. void * WINAPI dbgFreeCore(void* pv, BOOL fTrackUsage);
  206. void * WINAPI dbgReallocCore(void* pv, size_t cb, BOOL fTrackUsage);
  207. #if 0
  208. #define malloc dbgMalloc
  209. #define free dbgFree
  210. #define realloc dbgRealloc
  211. #define calloc dbgCalloc
  212. #endif
  213. //DWORD WINAPI dbGlobalSize(HANDLE);
  214. //HANDLE WINAPI dbGlobalAlloc(UINT, DWORD);
  215. //HANDLE WINAPI dbGlobalFree(HANDLE);
  216. //HANDLE WINAPI dbGlobalReAlloc(HANDLE, DWORD, UINT);
  217. #if defined(ENABLE_DBG_HANDLES)
  218. HANDLE WINAPI dbGlobalHandle(LPCVOID);
  219. BOOL WINAPI dbGlobalUnlock(HANDLE);
  220. LPVOID WINAPI dbGlobalLock(HANDLE);
  221. #endif // ENABLE_DBG_HANDLES
  222. #define dbHeapInit InitDebugMem
  223. // it is a good idea (essential if you're MT) to call these before any mem allocs
  224. void WINAPI InitDebugMem(void);
  225. // and this after all mem allocs
  226. BOOL WINAPI FiniDebugMem(void); // returns true if not all memory released
  227. // these are alternative entrypoints
  228. BOOL WINAPI fNLGNewMemory( PVOID *ppv, ULONG cbSize);
  229. DWORD WINAPI NLGMemorySize(PVOID pvMem);
  230. BOOL WINAPI fNLGResizeMemory(PVOID *ppv, ULONG cbNew);
  231. VOID WINAPI NLGFreeMemory(PVOID pv);
  232. BOOL WINAPI fNLGHeapDestroy( VOID );
  233. #else // NOT (DEBUG)
  234. #define InitDebugMem() ((void)0)
  235. #define FiniDebugMem() (FALSE)
  236. #define dbgMalloc(cb) LocalAlloc( LMEM_FIXED, cb )
  237. void * WINAPI dbgCalloc(size_t c, size_t cb);
  238. #define dbgFree(pv) LocalFree( pv )
  239. #define dbgRealloc(pv, cb) LocalReAlloc(pv, cb, LMEM_MOVEABLE)
  240. #define fNLGHeapDestroy( ) TRUE
  241. // When fNLGNewMemory fails the passed in ptr will be side-effected to NULL
  242. #define fNLGNewMemory( ppv, cbSize) ((*(ppv) = LocalAlloc( LMEM_FIXED, cbSize )) != NULL)
  243. #define NLGFreeMemory( pv) LocalFree( pv )
  244. #endif // (DEBUG)
  245. /*************************************************
  246. Lexical Table functions
  247. implementation in lextable.c
  248. *************************************************/
  249. #define Lex_UpperFlag 0x01 /* upper case */
  250. #define Lex_LowerFlag 0x02 /* lower case */
  251. #define Lex_DigitFlag 0x04 /* decimal digits */
  252. #define Lex_SpaceFlag 0x08 /* spacing characters */
  253. #define Lex_PunctFlag 0x10 /* punctuation characters */
  254. #define Lex_ControlFlag 0x20 /* control characters */
  255. #define Lex_LexiconFlag 0x40
  256. #define Lex_VowelFlag 0x80
  257. #define NTRANSTAB 256
  258. extern const BYTE Lex_rgchKey[NTRANSTAB];
  259. extern const BYTE Lex_rgFlags[NTRANSTAB];
  260. #define INUPPERPAGES(ch) (ch & 0xff00) // this is the same as ch > 0x00ff
  261. // don't count on any of the above constants - use these functions below
  262. // The speller uses this to make equivalent classes
  263. WCHAR WINAPI fwcUpperKey(const WCHAR wc);
  264. BOOL WINAPI IsUpperPunct(const WCHAR ch);
  265. __inline WCHAR WINAPI CMN_Key(const WCHAR ch)
  266. {
  267. #if defined(_VIET_)
  268. // When we are ready for merge we should add these data to core Lex_rgFlgas.
  269. if (INUPPERPAGES(ch))
  270. {
  271. if ( (ch == 0x0102) ||
  272. (ch == 0x0110) ||
  273. (ch == 0x01A0) ||
  274. (ch == 0x01AF) )
  275. {
  276. return (ch + 1);
  277. }
  278. return fwcUpperKey(ch);
  279. }
  280. else if ( (ch == 0x00D0) ) // This seem very weird that we map it like this in NT.
  281. {
  282. return 0x0111;
  283. }
  284. else if ( (ch == 0x00C3) )
  285. {
  286. return 0x0103;
  287. }
  288. else if ( (ch == 0x00D5) )
  289. {
  290. return 0x01A1;
  291. }
  292. else if ( (ch == 0x00DD) )
  293. {
  294. return 0x01B0;
  295. }
  296. else if ( (ch == 0x00D4) ||
  297. (ch == 0x00CA) ||
  298. (ch == 0x00C2) )
  299. {
  300. return (ch + 0x0020);
  301. }
  302. else if ( (ch == 0x00f4) || // These are special case there are no key that should map to these characters.
  303. (ch == 0x00ea) ||
  304. (ch == 0x00e2) )
  305. {
  306. return ch;
  307. }
  308. else
  309. {
  310. return ((WCHAR) Lex_rgchKey[(UCHAR) ch]);
  311. }
  312. #else
  313. return (WCHAR) (INUPPERPAGES(ch) ?
  314. fwcUpperKey(ch) :
  315. (WCHAR) Lex_rgchKey[(UCHAR) ch]);
  316. #endif
  317. }
  318. __inline BOOL WINAPI CMN_IsCharUpperW(WCHAR ch)
  319. {
  320. #if defined(_VIET_)
  321. // When we are ready for merge we should add these data to core Lex_rgFlgas.
  322. if ( (ch == 0x0111) ||
  323. (ch == 0x0103) ||
  324. (ch == 0x01A1) ||
  325. (ch == 0x01B0) )
  326. {
  327. return FALSE;
  328. }
  329. else if ( (ch == 0x0102) ||
  330. (ch == 0x0110) ||
  331. (ch == 0x01A0) ||
  332. (ch == 0x01AF) ||
  333. (ch == 0x00D4) ||
  334. (ch == 0x00CA) ||
  335. (ch == 0x00D0) ||
  336. (ch == 0x00C3) ||
  337. (ch == 0x00D5) ||
  338. (ch == 0x00DD) ||
  339. (ch == 0x00C2) )
  340. {
  341. return TRUE;
  342. }
  343. else if (INUPPERPAGES(ch))
  344. {
  345. return FALSE;
  346. }
  347. else
  348. {
  349. return Lex_rgFlags[(UCHAR) ch] & Lex_UpperFlag;
  350. }
  351. #else
  352. return INUPPERPAGES(ch) ? FALSE : Lex_rgFlags[(UCHAR) ch] & Lex_UpperFlag;
  353. #endif
  354. }
  355. __inline BOOL WINAPI CMN_IsCharLowerW(WCHAR ch)
  356. {
  357. #if defined(_VIET_)
  358. // When we are ready for merge we should add these data to core Lex_rgFlgas.
  359. if ( (ch == 0x0111) ||
  360. (ch == 0x0103) ||
  361. (ch == 0x01A1) ||
  362. (ch == 0x01B0) )
  363. {
  364. return TRUE;
  365. }
  366. else if ( (ch == 0x0102) ||
  367. (ch == 0x0110) ||
  368. (ch == 0x01A0) ||
  369. (ch == 0x01AF) ||
  370. (ch == 0x00D4) ||
  371. (ch == 0x00CA) ||
  372. (ch == 0x00D0) ||
  373. (ch == 0x00C3) ||
  374. (ch == 0x00D5) ||
  375. (ch == 0x00DD) ||
  376. (ch == 0x00C2) )
  377. {
  378. return FALSE;
  379. }
  380. else if (INUPPERPAGES(ch))
  381. {
  382. return FALSE;
  383. }
  384. else
  385. {
  386. return Lex_rgFlags[(UCHAR) ch] & Lex_LowerFlag;
  387. }
  388. #else
  389. return INUPPERPAGES(ch) ? FALSE : Lex_rgFlags[(UCHAR) ch] & Lex_LowerFlag;
  390. #endif
  391. }
  392. __inline BOOL WINAPI CMN_IsCharAlphaW(WCHAR ch)
  393. {
  394. return INUPPERPAGES(ch) ? !IsUpperPunct(ch) : Lex_rgFlags[(UCHAR) ch] & (Lex_LowerFlag | Lex_UpperFlag);
  395. }
  396. __inline BOOL WINAPI CMN_IsCharAlphaNumericW(WCHAR ch)
  397. {
  398. return INUPPERPAGES(ch) ? !IsUpperPunct(ch) : Lex_rgFlags[(UCHAR) ch] & (Lex_LowerFlag | Lex_UpperFlag | Lex_DigitFlag);
  399. }
  400. __inline BOOL WINAPI CMN_IsCharDigitW(WCHAR ch)
  401. {
  402. return INUPPERPAGES(ch) ? FALSE : Lex_rgFlags[(UCHAR) ch] & Lex_DigitFlag;
  403. }
  404. __inline BOOL WINAPI CMN_IsCharStrictDigitW(WCHAR ch)
  405. { // only allows digits 0-9 - no superscripts, no fractions
  406. return (
  407. INUPPERPAGES(ch) ?
  408. FALSE :
  409. (Lex_rgFlags[(UCHAR) ch] & (Lex_DigitFlag | Lex_PunctFlag)) ==
  410. Lex_DigitFlag
  411. );
  412. }
  413. BOOL WINAPI IsUpperSpace(WCHAR ch);
  414. __inline BOOL WINAPI CMN_IsCharSpaceW(WCHAR ch)
  415. {
  416. return INUPPERPAGES(ch) ?
  417. IsUpperSpace(ch) :
  418. Lex_rgFlags[(UCHAR) ch] & Lex_SpaceFlag;
  419. }
  420. __inline BOOL WINAPI CMN_IsCharPunctW(WCHAR ch)
  421. {
  422. return INUPPERPAGES(ch) ? IsUpperPunct(ch) : Lex_rgFlags[(UCHAR) ch] & Lex_PunctFlag;
  423. }
  424. __inline BOOL WINAPI CMN_IsCharPrintW(WCHAR ch)
  425. {
  426. return INUPPERPAGES(ch) ?
  427. !CMN_IsCharSpaceW(ch) :
  428. Lex_rgFlags[(UCHAR) ch] &
  429. (Lex_PunctFlag | Lex_UpperFlag | Lex_LowerFlag | Lex_DigitFlag);
  430. }
  431. __inline BOOL WINAPI CMN_IsCharInLexiconW(WCHAR ch)
  432. {
  433. return INUPPERPAGES(ch) ?
  434. (!IsUpperPunct(ch) || ch == 0x2019 || ch == 0x2018) :
  435. Lex_rgFlags[(UCHAR) ch] & Lex_LexiconFlag;
  436. }
  437. __inline BOOL WINAPI CMN_IsCharVowelW(WCHAR ch)
  438. {
  439. return INUPPERPAGES(ch) ? FALSE : Lex_rgFlags[(UCHAR) ch] & Lex_VowelFlag;
  440. }
  441. __inline BOOL WINAPI CMN_IsCharGraphW(WCHAR ch)
  442. {
  443. return INUPPERPAGES(ch) ?
  444. TRUE :
  445. Lex_rgFlags[(UCHAR) ch] &
  446. (Lex_LowerFlag |
  447. Lex_UpperFlag |
  448. Lex_DigitFlag |
  449. Lex_PunctFlag);
  450. }
  451. // Some punctuation flags
  452. #define Lex_PunctLead 0x01 /* leading punctuation */
  453. #define Lex_PunctJoin 0x02 /* joining punctuation */
  454. #define Lex_PunctTrail 0x04 /* trailing punctuation */
  455. // reuse Lex_SpaceFlag here
  456. extern const BYTE Lex_rgPunctFlags[NTRANSTAB];
  457. __inline BOOL WINAPI CMN_IsLeadPunctW(WCHAR ch)
  458. {
  459. return INUPPERPAGES(ch) ?
  460. (ch == 0x201c || ch == 0x2018) :
  461. (Lex_rgPunctFlags[(UCHAR) ch] & Lex_PunctLead);
  462. }
  463. __inline BOOL WINAPI CMN_IsJoinPunctW(WCHAR ch)
  464. {
  465. return INUPPERPAGES(ch) ? FALSE : Lex_rgPunctFlags[(UCHAR) ch] & Lex_PunctJoin;
  466. }
  467. __inline BOOL WINAPI CMN_IsTrailPunctW(WCHAR ch)
  468. {
  469. return INUPPERPAGES(ch) ?
  470. (ch == 0x201d || ch == 0x2019) :
  471. (Lex_rgPunctFlags[(UCHAR) ch] & Lex_PunctTrail);
  472. }
  473. BOOL WINAPI IsUpperWordDelim(WCHAR ch);
  474. __inline BOOL WINAPI CMN_IsCharWordDelimW(WCHAR ch)
  475. {
  476. return INUPPERPAGES(ch) ?
  477. IsUpperWordDelim(ch) :
  478. Lex_rgPunctFlags[(UCHAR) ch] & Lex_SpaceFlag;
  479. }
  480. // implementation in lexfuncs.c
  481. WCHAR WINAPI CMN_CharUpperW(const WCHAR ch);
  482. WCHAR WINAPI CMN_CharLowerW(const WCHAR ch);
  483. BOOL WINAPI CMN_IsStringEqualNoCaseW(const WCHAR *pwz1, const WCHAR *pwz2);
  484. BOOL WINAPI CMN_IsStringEqualNoCaseNumW(const WCHAR *pwz1, const WCHAR *pwz2, int cch);
  485. DWORD WINAPI CMN_CharUpperBuffW(WCHAR *pwz, DWORD cchLength);
  486. DWORD WINAPI CMN_CharLowerBuffW(WCHAR *pwz, DWORD cchLength);
  487. int WINAPI CMN_CompareStringNoCaseW(const WCHAR *pwz1, const WCHAR *pwz2);
  488. int WINAPI CMN_CompareStringNoCaseNumW(const WCHAR *pwz1, const WCHAR *pwz2, int cch);
  489. // note that this version does not set errno on errors
  490. long WINAPI CMN_wcstol( const wchar_t *nptr, const wchar_t * *endptr, int base );
  491. __inline int WINAPI CMN_wtoi( const wchar_t *string )
  492. {
  493. return CMN_wcstol(string, NULL, 10);
  494. }
  495. __inline wchar_t * WINAPI CMN_wcsupr( wchar_t *string )
  496. {
  497. CMN_CharUpperBuffW(string, wcslen(string));
  498. return string;
  499. }
  500. __inline wchar_t * WINAPI CMN_wcslwr( wchar_t *string )
  501. {
  502. CMN_CharLowerBuffW(string, wcslen(string));
  503. return string;
  504. }
  505. ////////////////////
  506. // debug.c
  507. /////////////////////
  508. #if defined(_DEBUG)
  509. extern void WINAPI DebugAssert(LPCTSTR, LPCTSTR, UINT);
  510. extern void WINAPI SetAssertOptions(DWORD);
  511. #else // _DEBUG
  512. #define DebugAssert(a, b, c)
  513. #define SetAssertOptions(a)
  514. #endif // _DEBUG defined
  515. /****************************************************************
  516. These are versions of some WINAPI functions that normally don't work
  517. on win95 with Unicode (not supported). They have the same arguments
  518. as the API functions
  519. If UNICODE is not defined, they become the A versions
  520. If UNICODE is defined and x86, they become our W version
  521. If UNICODE is defined and not x86, they become API W version
  522. ****************************************************************/
  523. #include <sys/stat.h> // this needs to be before the redefs we do below
  524. #include <stdlib.h> // as does this
  525. // want to do these substitutions regardless
  526. #define IsCharLowerW CMN_IsCharLowerW
  527. #define IsCharUpperW CMN_IsCharUpperW
  528. #define IsCharAlphaW CMN_IsCharAlphaW
  529. #define IsCharAlphaNumericW CMN_IsCharAlphaNumericW
  530. #define CharUpperBuffW CMN_CharUpperBuffW
  531. #define CharLowerBuffW CMN_CharLowerBuffW
  532. #define _wcsicmp CMN_CompareStringNoCaseW
  533. #define _wcsnicmp CMN_CompareStringNoCaseNumW
  534. #define towupper CMN_CharUpperW
  535. #define towlower CMN_CharLowerW
  536. #define wcstol CMN_wcstol
  537. #define _wtoi CMN_wtoi
  538. #define _wcsupr CMN_wcsupr
  539. #define _wcslwr CMN_wcslwr
  540. #undef iswdigit
  541. #define iswdigit CMN_IsCharDigitW
  542. #undef iswspace
  543. #define iswspace CMN_IsCharSpaceW
  544. #undef iswpunct
  545. #define iswpunct CMN_IsCharPunctW
  546. #undef iswprint
  547. #define iswprint CMN_IsCharPrintW
  548. #undef iswalpha
  549. #define iswalpha CMN_IsCharAlphaW
  550. #undef iswalnum
  551. #define iswalnum CMN_IsCharAlphaNumericW
  552. #undef iswgraph
  553. #define iswgraph CMN_IsCharGraphW
  554. #undef iswupper
  555. #define iswupper CMN_IsCharUpperW
  556. #undef iswlower
  557. #define iswlower CMN_IsCharLowerW
  558. // function defs for our versions
  559. int WINAPI CMN_LoadStringW(HINSTANCE hModule, UINT uiId, WCHAR * wszString, int cchStringMax);
  560. int WINAPI CMN_LoadStringWEx(HINSTANCE hModule, UINT uiId, WCHAR * wszString, int cchStringMax, LANGID lid);
  561. // these two functions replace the associated RTL functions - however
  562. // they can't be just replaced - as they use a third argument to maintain state
  563. // instead of static variables within the function.
  564. // Use these the same as the RTL functions, but declare TCHAR *pnexttoken before use
  565. // and pass its address as the third parameter
  566. wchar_t * WINAPI CMN_wcstok (wchar_t * string, const wchar_t * control, wchar_t **pnextoken);
  567. char * WINAPI CMN_strtok (char * string, const char * control, char **pnextoken);
  568. #if defined(UNICODE)
  569. #define CMN_tcstok CMN_wcstok
  570. #else
  571. #define CMN_tcstok CMN_strtok
  572. #endif
  573. #if defined(_M_IX86) && !defined(WINCE) && !defined(NTONLY)
  574. #define CreateFileW CMN_CreateFileW
  575. #define LoadLibraryW CMN_LoadLibraryW
  576. #define GetModuleFileNameW CMN_GetModuleFileNameW
  577. #define GetFileAttributesW CMN_GetFileAttributesW
  578. // FindResourceW works in win95
  579. // as does FindResourceExW
  580. //#define PostMessageW ERR_Does_not_work_in_w95 // no easy replacement for this one
  581. #define FindWindowW ERR_No_w95_equiv_yet
  582. #define lstrcpynW CMN_lstrcpynW
  583. #define lstrcatW CMN_lstrcatW
  584. #define lstrcmpiW CMN_lstrcmpiW
  585. #define lstrcpyW CMN_lstrcpyW
  586. #define lstrlenW CMN_lstrlenW
  587. #define lstrcmpW CMN_lstrcmpW
  588. #define wsprintfW swprintf
  589. #define _wstat CMN_wstat
  590. #define CharNextW CMN_CharNextW
  591. #define LoadStringW CMN_LoadStringW
  592. #define _wfopen CMN_wfopen
  593. HANDLE WINAPI
  594. CMN_CreateFileW (
  595. PCWSTR pwzFileName, // pointer to name of the file
  596. DWORD dwDesiredAccess, // access (read-write) mode
  597. DWORD dwShareMode, // share mode
  598. LPSECURITY_ATTRIBUTES pSecurityAttributes, // pointer to security descriptor
  599. DWORD dwCreationDistribution, // how to create
  600. DWORD dwFlagsAndAttributes, // file attributes
  601. HANDLE hTemplateFile); // handle to file with attributes to copy
  602. HINSTANCE WINAPI CMN_LoadLibraryW(const WCHAR *pwszLibraryFileName);
  603. DWORD WINAPI CMN_GetModuleFileNameW( HINSTANCE hModule, // handle to module to find filename for
  604. WCHAR *lpFilename, // pointer to buffer to receive module path
  605. DWORD nSize); // size of buffer, in characters
  606. DWORD WINAPI CMN_GetFileAttributesW(const WCHAR *lpFileName); // address of the name of a file or directory
  607. // note: Even though WINAPI returns WCHAR *, I define this as returning void
  608. void WINAPI CMN_lstrcpynW( WCHAR *lpString1, // address of target buffer
  609. const WCHAR *lpString2, // address of source string
  610. int iMaxLength); // number of bytes or characters to copy
  611. #define CMN_lstrcmpiW _wcsicmp // just use c-runtime for now
  612. #define CMN_lstrcpyW wcscpy
  613. #define CMN_lstrcatW wcscat
  614. #define CMN_lstrlenW(pwz) ((int) wcslen(pwz))
  615. #define CMN_lstrcmpW wcscmp
  616. #define CMN_CharNextW(pwz) (pwz + 1)
  617. FILE *WINAPI CMN_wfopen(const WCHAR *pwzFileName, const WCHAR *pwzUnimode);
  618. int WINAPI CMN_wstat(const WCHAR *pwzPath, struct _stat *pStatBuffer);
  619. #else // there is no win95 - and it must be NT
  620. #define CMN_CreateFileW CreateFileW
  621. #define CMN_LoadLibraryW LoadLibraryW
  622. #define CMN_GetModuleFileNameW GetModuleFileNameW
  623. #define CMN_GetFileAttributesW GetFileAttributesW
  624. #define CMN_lstrcpynW lstrcpynW
  625. #define CMN_lstrcmpiW lstrcmpiW
  626. #define CMN_lstrcpyW lstrcpyW
  627. #define CMN_lstrcatW lstrcatW
  628. #define CMN_lstrcmpW lstrcmpW
  629. #define CMN_wfopen _wfopen
  630. #define CMN_wstat _wstat
  631. #define CMN_CharNextW CharNextW
  632. #endif
  633. // Outputs Readable Error String to the Debug Output
  634. #if defined (_DEBUG)
  635. void WINAPI CMN_OutputSystemErrA(const char *pszMsg, const char *pszComponent);
  636. void WINAPI CMN_OutputSystemErrW(const WCHAR *pwzMsg, const WCHAR *pwzComponent);
  637. void WINAPI CMN_OutputErrA(DWORD dwErr, const char *pszMsg, const char *pszComponent);
  638. void WINAPI CMN_OutputErrW(DWORD dwErr, const WCHAR *pwzMsg, const WCHAR *pwzComponent);
  639. # if defined (UNICODE)
  640. # define CMN_OutputSystemErr CMN_OutputSystemErrW
  641. # define CMN_OutputErr CMN_OutputErrW
  642. # else
  643. # define CMN_OutputSystemErr CMN_OutputSystemErrA
  644. # define CMN_OutputErr CMN_OutputErrA
  645. # endif
  646. #else //!_DEBUG
  647. # define CMN_OutputSystemErr(x, y)
  648. # define CMN_OutputSystemErrA(x, y)
  649. # define CMN_OutputSystemErrW(x, y)
  650. # define CMN_OutputErr(n, x, y)
  651. # define CMN_OutputErrA(n, x, y)
  652. # define CMN_OutputErrW(n, x, y)
  653. #endif
  654. ///////////////////////
  655. // LexWin95.c
  656. ///////////////////////
  657. #define LoadLibraryW2A CMN_LoadLibraryW
  658. #define CreateFileW2A CMN_CreateFileW
  659. // Add anything new here, within the extern "C" clause
  660. #ifdef __cplusplus
  661. } // ends the extern "C" clause
  662. // here's some C++ specific stuff
  663. inline BOOL IsMapFileUnicode(PMFILE pmf, BOOL fDefault=TRUE)
  664. {
  665. if (pmf->hFileMap)
  666. return pmf->fSrcUnicode;
  667. // must be zero length, set and return default
  668. return pmf->fSrcUnicode = fDefault;
  669. }
  670. inline void MapFileCodePage(PMFILE pmf, UINT uCP)
  671. {
  672. pmf->uCodePage = uCP;
  673. }
  674. #if defined(CPPMEMORY)
  675. inline void * _cdecl operator new (size_t size)
  676. {
  677. #if defined(DEBUG)
  678. return dbgMalloc(size);
  679. #else
  680. return LocalAlloc( LMEM_FIXED, size );
  681. #endif
  682. }
  683. inline void _cdecl operator delete(void *pMem)
  684. {
  685. if (!pMem)
  686. return;
  687. #if defined(DEBUG)
  688. dbgFree(pMem);
  689. #else
  690. LocalFree(pMem);
  691. #endif
  692. }
  693. #endif // CPPMEMORY
  694. #endif // __cplusplus
  695. #endif // _NLGLIB_H_