Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2760 lines
88 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* search.c Search/Replace */
  5. /* Brodie Nov 25 83 */
  6. /* Lipkie Nov 15 83 */
  7. #define NOATOM
  8. #define NOBITMAP
  9. #define NOBRUSH
  10. #define NOCLIPBOARD
  11. #define NOCOLOR
  12. #define NOCOMM
  13. #define NOCREATESTRUCT
  14. #define NODRAWTEXT
  15. #define NOFONT
  16. #ifndef JAPAN
  17. #define NOGDI
  18. #endif
  19. #define NOGDICAPMASKS
  20. #define NOHDC
  21. #define NOICON
  22. #define NOKEYSTATE
  23. #define NOMEMMGR
  24. #define NOMENUS
  25. #define NOMETAFILE
  26. #define NOOPENFILE
  27. #define NOPEN
  28. #define NORASTEROPS
  29. #define NORECT
  30. #define NOREGION
  31. #define NOSCROLL
  32. #define NOSHOWWINDOW
  33. #define NOSOUND
  34. #define NOSYSCOMMANDS
  35. #define NOSYSMETRICS
  36. #define NOTEXTMETRIC
  37. #define NOWH
  38. #define NOWINSTYLES
  39. #define NOWNDCLASS
  40. #include <windows.h>
  41. #define NOIDISAVEPRINT
  42. #include "mw.h"
  43. #include "dlgdefs.h"
  44. #include "cmddefs.h"
  45. #include "docdefs.h"
  46. #include "str.h"
  47. #define NOKCCODES
  48. #include "ch.h"
  49. #include "editdefs.h"
  50. #include "propdefs.h"
  51. #include "filedefs.h"
  52. #include "dispdefs.h"
  53. #include "wwdefs.h"
  54. #include "fkpdefs.h"
  55. #include "fmtdefs.h"
  56. #if defined(JAPAN) || defined(KOREA) //T-HIROYN Win3.1
  57. #include "kanji.h"
  58. extern int vcchFetch;
  59. #endif
  60. #ifdef INEFFLOCKDOWN
  61. extern FARPROC lpDialogFind;
  62. extern FARPROC lpDialogChange;
  63. #else
  64. FARPROC lpDialogFind = NULL;
  65. FARPROC lpDialogChange = NULL;
  66. BOOL far PASCAL DialogFind(HWND, unsigned, WORD, LONG);
  67. BOOL far PASCAL DialogChange(HWND, unsigned, WORD, LONG);
  68. #endif
  69. extern HANDLE hMmwModInstance;
  70. extern HWND vhDlgFind;
  71. extern HWND vhDlgChange;
  72. extern HANDLE hParentWw; /* Handle to the parent window */
  73. extern int vfCursorVisible;
  74. extern int vfOutOfMemory;
  75. extern struct WWD rgwwd[];
  76. extern int wwMac;
  77. #ifdef ENABLE /* no pDialogCur and ActiveWindow */
  78. extern WINDOWPTR windowSearch;
  79. extern WINDOWPTR windowRep;
  80. extern WINDOWPTR pDialogCur;
  81. extern WINDOWPTR ActiveWindow;
  82. extern int cxEditScroll;/* not sure how cxEditScroll is used */
  83. extern struct SEL selSearch;
  84. #endif
  85. extern struct FKPD vfkpdParaIns;
  86. extern struct PAP *vppapNormal;
  87. extern typeFC fcMacPapIns;
  88. extern int wwCur;
  89. extern struct WWD *pwwdCur;
  90. extern struct CHP vchpInsert;
  91. extern struct PAP vpapPrevIns;
  92. extern int vfSelecting;
  93. extern typeCP cpMacCur;
  94. extern typeCP cpMinCur;
  95. extern int vfSeeSel;
  96. extern int vfSeeEdgeSel;
  97. extern int docCur;
  98. extern struct SEL selCur;
  99. extern typeCP vcpFetch;
  100. extern int vccpFetch;
  101. extern CHAR *vpchFetch;
  102. extern struct UAB vuab;
  103. extern int vfSysFull;
  104. extern struct PAP vpapAbs;
  105. extern struct CHP vchpFetch;
  106. extern int ferror;
  107. extern typeCP cpWall;
  108. /* Globals used to store settings of flags. Used to propose responses. */
  109. extern BOOL fParaReplace /* = false initially */;
  110. extern BOOL fReplConfirm /* = TRUE initially */;
  111. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  112. extern BOOL fSearchDist /* = true initially */;
  113. #endif
  114. extern BOOL fSearchWord /* = false initially */;
  115. extern BOOL fSearchCase /* = false initially */;
  116. extern BOOL fSpecialMatch;
  117. extern BOOL fMatchedWhite /* = false initially */;
  118. extern CHAR (**hszSearch)[]; /* Default search string */
  119. extern CHAR (**hszReplace)[]; /* Default replace string */
  120. extern CHAR (**hszFlatSearch)[]; /* All lower case version of search string */
  121. extern CHAR (**hszRealReplace)[]; /* used for building replacement text */
  122. extern CHAR (**hszCaseReplace)[]; /* used for building replacement text with
  123. appropriate capitalization. */
  124. extern typeCP cpMatchLim;
  125. extern int vfDidSearch;
  126. extern CHAR *szSearch;
  127. extern CHAR (**HszCreate())[];
  128. extern HWND vhWndMsgBoxParent;
  129. extern HCURSOR vhcIBeam;
  130. extern HCURSOR vhcArrow;
  131. #ifdef INTL
  132. extern CHAR szAppName[];
  133. extern CHAR szSepName[];
  134. #endif
  135. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  136. char DistSearchString[513];
  137. #endif
  138. NEAR DoSearch(void);
  139. NEAR DoReplace(int, int);
  140. typeCP NEAR CpSearchSz(typeCP, typeCP, CHAR *);
  141. NEAR FMakeFlat(int);
  142. NEAR SetSpecialMatch(void);
  143. NEAR FSetParaReplace(int);
  144. NEAR WCaseCp(typeCP, typeCP);
  145. NEAR SetChangeString(HANDLE, int);
  146. NEAR PutCpInWwVertSrch(typeCP);
  147. #ifndef NOLA
  148. BOOL (NEAR FAbort(void));
  149. #endif
  150. BOOL (NEAR FWordCp(typeCP, typeCP));
  151. BOOL (NEAR FChMatch(int, int *, BOOL));
  152. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  153. BOOL (NEAR J_FChMatch(CHAR, CHAR, int *,int *));
  154. #endif
  155. NEAR InsertPapsForReplace(typeFC);
  156. NEAR DestroyModeless(HWND *);
  157. NEAR FDlgSzTooLong(HWND, int, CHAR *, int);
  158. NEAR idiMsgResponse(HWND, int, int);
  159. BOOL CheckEnableButton(HANDLE, HANDLE);
  160. BOOL bInSearchReplace = FALSE; // avoid close when we are searching!
  161. #define CmdReplace(fThenFind) bInSearchReplace = TRUE; \
  162. DoReplace(false, fThenFind); \
  163. bInSearchReplace = FALSE
  164. #define CmdReplaceAll() bInSearchReplace = TRUE; \
  165. DoReplace(true, false); \
  166. bInSearchReplace = FALSE
  167. #ifndef NOLA
  168. static int fAbortSearch = FALSE;
  169. #endif
  170. static int fChangeSel;
  171. static int fSelSave = FALSE;
  172. static struct SEL selSave;
  173. #ifdef DBCS
  174. /* Additional variables to handle white-space matching
  175. for the DBCS space. */
  176. static int cbLastMatch;
  177. /* Since CpFirstSty(, styChar) calls on FetchCp(), any assumption
  178. made about the validity of global variables set by FetchCp()
  179. is no longer valid. We explicitly save those variables after
  180. each FetchCp and use those instead. (Used in CpSearchSz().)*/
  181. static typeCP cpFetchSave;
  182. static int ccpFetchSave;
  183. static CHAR *pchFetchSave;
  184. /* Also, we move some of the local variables out from
  185. CpSearchSz() so that they can be changed by FChMatch(). */
  186. /*
  187. int ichDoc;
  188. int cchMatched;
  189. typeCP cpFetchNext;
  190. */
  191. #endif
  192. NEAR DoSearch()
  193. {
  194. int cch;
  195. typeCP cpSearch;
  196. typeCP cpSearchLim;
  197. typeCP cpSearchNext;
  198. typeCP cpWallActual;
  199. typeCP cpMatchFirst;
  200. typeCP CpMin();
  201. int idpmt;
  202. int fDidSearch;
  203. if (docCur == docNil)
  204. return;
  205. cch = CchSz(**hszSearch)-1;
  206. if(cch == 0)
  207. {
  208. /* this should only occur if the user execute Repeat last find without having
  209. previously defined a search string. */
  210. Error(IDPMTNotFound);
  211. return;
  212. }
  213. SetSpecialMatch();
  214. if(!FMakeFlat(cch))
  215. return;
  216. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  217. if(!fSpecialMatch && !fSearchDist)
  218. {
  219. myHantoZen(**hszFlatSearch,DistSearchString,513);
  220. cch = CchSz(DistSearchString)-1;
  221. }
  222. #endif
  223. fDidSearch = vfDidSearch;
  224. cpWallActual = fDidSearch ? CpMin(cpWall, cpMacCur) : cpMacCur;
  225. cpSearchNext = fDidSearch ? selCur.cpLim : selCur.cpFirst;
  226. cpSearchLim = (cpSearchNext <= cpWallActual) ? cpWallActual : cpMacCur;
  227. {
  228. do
  229. {
  230. ContinueSearch:
  231. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  232. if(!fSpecialMatch && !fSearchDist)
  233. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,DistSearchString);
  234. else
  235. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,**hszFlatSearch);
  236. #else
  237. cpSearch=CpSearchSz(cpSearchNext,cpSearchLim,**hszFlatSearch);
  238. #endif
  239. if (cpSearch == cpNil)
  240. {
  241. #ifndef NOLA
  242. if (fAbortSearch)
  243. {
  244. Error(IDPMTCancelSearch);
  245. fAbortSearch = FALSE;
  246. vfDidSearch = FALSE;
  247. FreeH(hszFlatSearch);
  248. return;
  249. }
  250. #endif
  251. if (cpSearchLim == cpWall && fDidSearch)
  252. {
  253. SearchFail: Error(vfDidSearch ? IDPMTSearchDone :
  254. IDPMTNotFound);
  255. if (vfDidSearch) /* did we previously have a match?*/
  256. { /* Yes, do setup for next pass */
  257. /* clear flag so we can search some more */
  258. vfDidSearch = false;
  259. /* set "Wall" to immediately after last match */
  260. cpWall = selCur.cpLim;
  261. /* ask that selection be displayed */
  262. vfSeeSel = vfSeeEdgeSel = TRUE;
  263. }
  264. FreeH(hszFlatSearch);
  265. return;
  266. }
  267. else
  268. {
  269. cpSearchNext = cpMinCur;
  270. cpSearchLim = cpWall;
  271. fDidSearch = true;
  272. goto ContinueSearch;
  273. }
  274. }
  275. #ifdef DBCS /* was in JAPAN */
  276. cpSearchNext = CpLastStyChar( cpSearch ) + 1;
  277. #else
  278. cpSearchNext = CpLastStyChar( cpSearch + 1 );
  279. #endif
  280. }
  281. /*--- while (fSearchWord && !FWordCp(cpSearch, cpMatchLim-cpSearch));--*/
  282. while (!FCpValid(cpSearch, cpMatchLim - cpSearch));
  283. }
  284. if (!vfDidSearch)
  285. {
  286. cpWall = cpSearch;
  287. vfDidSearch = true;
  288. }
  289. /*Select( CpFirstSty( cpSearch, styChar ), CpLastStyChar( cpMatchLim ) );*/
  290. if ( (cpMatchFirst = CpFirstSty( cpSearch, styChar )) != cpMatchLim )
  291. Select( cpMatchFirst, cpMatchLim );
  292. PutCpInWwVertSrch(selCur.cpFirst);
  293. vfSeeSel = vfSeeEdgeSel = TRUE;
  294. FreeH(hszFlatSearch);
  295. }
  296. NEAR DoReplace(fReplaceAll, fThenFind)
  297. int fReplaceAll;
  298. int fThenFind;
  299. {
  300. /* Replace now works as follows:
  301. if the current selection is the search text, then replace it with
  302. the replace text and jump to the next occurrence of the search text.
  303. Otherwise, just jump to the next occurrence of the search text.
  304. If fReplaceAll is true, then repeat this operation until the end
  305. of the document. */
  306. int cch;
  307. typeCP cpSearchStart;
  308. typeCP cpSearch;
  309. typeCP cpSearchNext;
  310. typeCP cpSearchLim;
  311. typeCP cpSearchNow;
  312. typeCP cpSearchLimNow;
  313. typeCP dcp;
  314. BOOL f1CharSel;
  315. BOOL fFirstTime;
  316. int ich;
  317. int cchReplace;
  318. int cwReplace;
  319. int iCurCase;
  320. int iLastCase;
  321. typeFC fcCaseSz;
  322. typeCP cpMacTextT;
  323. typeCP cpWallActual;
  324. int fDidSearch = vfDidSearch;
  325. struct CHP chp;
  326. typeCP cpMacSave;
  327. iLastCase = -1; /* indicate that the string pointed to by hszCaseReplace
  328. has not been given a value yet. */
  329. if (!FWriteOk(fwcNil) || docCur == docNil)
  330. /* Out of memory, read only document, etc */
  331. return;
  332. cch = CchSz(**hszSearch)-1;
  333. if(cch == 0)
  334. {
  335. Error(IDPMTNotFound);
  336. return;
  337. }
  338. SetSpecialMatch();
  339. if(!FMakeFlat(cch))
  340. return;
  341. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  342. if(!fSpecialMatch && !fSearchDist)
  343. {
  344. myHantoZen(**hszFlatSearch,DistSearchString,513);
  345. cch = CchSz(DistSearchString)-1;
  346. }
  347. #endif
  348. cwReplace = CwFromCch(cchReplace = CchSz(**hszReplace));
  349. if(FNoHeap(hszRealReplace = (CHAR (**) [])HAllocate(cwReplace)))
  350. {
  351. FreeH(hszFlatSearch);
  352. return;
  353. }
  354. bltbyte(**hszReplace, **hszRealReplace, cchReplace);
  355. if(FNoHeap(hszCaseReplace = (CHAR (**) [])HAllocate(cwReplace)))
  356. {
  357. FreeH(hszFlatSearch);
  358. FreeH(hszRealReplace);
  359. return;
  360. }
  361. if(!FSetParaReplace(cchReplace))
  362. {
  363. FreeH(hszFlatSearch);
  364. FreeH(hszCaseReplace);
  365. FreeH(hszRealReplace);
  366. return;
  367. }
  368. cch = CchSz(**hszRealReplace)-1;
  369. fFirstTime = TRUE;
  370. cpWallActual = fDidSearch ? CpMin(cpWall, cpMacCur) : cpMacCur;
  371. cpSearchNow = cpSearchStart = selCur.cpFirst;
  372. if (fReplaceAll || !fThenFind)
  373. cpSearchLim = selCur.cpLim;
  374. else
  375. cpSearchLim = (cpSearchStart < cpWallActual) ? cpWallActual : cpMacCur;
  376. cpSearchLimNow = selCur.cpLim;
  377. if (fReplaceAll)
  378. {
  379. cpWallActual = cpSearchLim;
  380. fDidSearch = true;
  381. }
  382. NoUndo(); /* Prevent the SetUndo from getting merged with adjacent stuff */
  383. cpMacTextT = CpMacText(docCur);
  384. if(cpSearchLimNow > cpMacTextT)
  385. SetUndo(uacDelNS, docCur, cp0, cpMacTextT, docNil, cpNil, cp0, 0);
  386. else
  387. SetUndo(uacDelNS, docCur, cpSearchStart, cpSearchLimNow - cpSearchStart,
  388. docNil, cpNil, cp0, 0);
  389. if (ferror) goto MemoryError;
  390. cpSearchNext = cpSearchStart;
  391. {
  392. do
  393. {
  394. /* ForcePmt(IDPMTSearching);*/
  395. do
  396. {
  397. ContinueSearch:
  398. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  399. if(!fSpecialMatch && !fSearchDist)
  400. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,DistSearchString);
  401. else
  402. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,**hszFlatSearch);
  403. #else
  404. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,**hszFlatSearch);
  405. #endif
  406. if (cpSearch == cpNil)
  407. if ((cpSearchLim == cpWallActual && fDidSearch) || fAbortSearch)
  408. DoneReplacingN:
  409. {
  410. DoneReplacingP:
  411. FreeH(hszFlatSearch);
  412. FreeH(hszCaseReplace);
  413. FreeH(hszRealReplace);
  414. cpMacTextT = CpMacText(docCur);
  415. if (fReplaceAll || fFirstTime)
  416. {
  417. if(cpSearchLimNow > cpMacTextT)
  418. SetUndo(uacInsert,docCur,cp0,
  419. cpMacTextT,docNil,cpNil,cp0,0);
  420. else
  421. SetUndo(uacInsert,docCur,cpSearchStart,
  422. cpSearchLimNow - cpSearchStart,
  423. docNil,cpNil,cp0,0);
  424. if (ferror) goto MemoryError;
  425. vuab.uac = uacReplGlobal;
  426. SetUndoMenuStr(IDSTRUndoBase);
  427. /*Select( CpFirstSty( cpSearchStart, styChar ),
  428. CpLastStyChar( cpSearchLimNow ) );*/
  429. Select( CpFirstSty( cpSearchStart, styChar ),
  430. (fReplaceAll ? cpSearchStart : cpSearchLimNow) );
  431. vfSeeSel = fReplaceAll;
  432. if (fReplaceAll)
  433. { /* reestablish the search after a changeall in case of a F3 next time */
  434. vfDidSearch = false;
  435. cpWall = selCur.cpLim;
  436. }
  437. }
  438. else if (!fReplaceAll)
  439. {
  440. if (cpSearch == cpNil)
  441. /*Select( CpFirstSty( cpSearchStart, styChar ),
  442. CpLastStyChar( cpSearchLimNow ) );*/
  443. Select( CpFirstSty( cpSearchStart, styChar ),
  444. cpSearchLimNow );
  445. else if (!fFirstTime)
  446. /*Select( CpFirstSty( cpSearch, styChar ),
  447. CpLastStyChar( cpMatchLim ) );*/
  448. Select( CpFirstSty( cpSearch, styChar ),
  449. cpMatchLim );
  450. PutCpInWwVertSrch(selCur.cpFirst);
  451. vfSeeSel = vfSeeEdgeSel = TRUE;
  452. }
  453. if (fAbortSearch)
  454. {
  455. fAbortSearch = FALSE;
  456. Error(IDPMTCancelSearch);
  457. }
  458. else if (fFirstTime)
  459. Error(fReplaceAll ? IDPMTNoReplace : (vfDidSearch ? IDPMTSearchDone : IDPMTNotFound));
  460. return;
  461. }
  462. else
  463. {
  464. cpSearchNext = cpMinCur;
  465. cpSearchLim = cpWallActual;
  466. fDidSearch = true;
  467. goto ContinueSearch;
  468. }
  469. #ifdef DBCS /* was in JAPAN */
  470. cpSearchNext = CpLastStyChar( cpSearch ) + 1;
  471. #else
  472. cpSearchNext = CpLastStyChar( cpSearch + 1 );
  473. #endif
  474. }
  475. /* while(fSearchWord && !FWordCp(cpSearch,cpMatchLim - cpSearch));*/
  476. while(!FCpValid(cpSearch, cpMatchLim - cpSearch));
  477. if (!fReplaceAll && (cpSearch != cpSearchNow || cpMatchLim != cpSearchLimNow))
  478. {
  479. if (fThenFind)
  480. { /* Get here if: Did a Change, then Find. Could not
  481. do the change, but did find a next occurence */
  482. cpSearchNow = cpSearchNext = cpSearchStart = cpSearch;
  483. cpSearchLimNow = cpMatchLim;
  484. fFirstTime = false; /* suppress error message */
  485. SetUndo(uacInsert, docCur, cpSearchStart,
  486. cpSearchLimNow - cpSearchStart, docNil, cpNil, cp0, 0);
  487. if (ferror) goto MemoryError;
  488. if (!vfDidSearch)
  489. {
  490. cpWall = cpSearch;
  491. vfDidSearch = true;
  492. }
  493. /*---- continue;----*/
  494. goto DoneReplacingN;
  495. }
  496. fFirstTime = true; /* Cause error message */
  497. cpSearchStart = cpSearchNow;
  498. cpSearchLim = cpSearchLimNow;
  499. goto DoneReplacingN;
  500. }
  501. /*----- vfDidSearch = true;----*/
  502. #ifdef FOOTNOTES
  503. if(FEditFtn(cpSearch, cpMatchLim))
  504. {
  505. ferror = false; /* Reset error condition so that we don't
  506. deallocate strings twice (KJS) */
  507. continue;
  508. }
  509. #endif
  510. fFirstTime = FALSE;
  511. if (vfOutOfMemory || vfSysFull)
  512. { /* Out of memory (heap or disk) */
  513. Error(IDPMTNoMemory);
  514. FreeH(hszFlatSearch);
  515. FreeH(hszRealReplace);
  516. FreeH(hszCaseReplace);
  517. cpMacTextT = CpMacText(docCur);
  518. if(cpSearchLim > cpMacTextT)
  519. SetUndo(uacInsert,docCur,cp0,cpMacTextT,docNil,cpNil,cp0,0);
  520. else
  521. SetUndo(uacInsert,docCur,cpSearchStart,
  522. cpSearchLimNow - cpSearchStart,docNil,cpNil,cp0,0);
  523. if (ferror)
  524. NoUndo();
  525. else
  526. vuab.uac = uacReplGlobal;
  527. return;
  528. }
  529. FetchCp(docCur, cpSearch, 0, fcmProps); /* Get props of first char
  530. that we are replacing */
  531. blt(&vchpFetch, &chp, cwCHP);
  532. chp.fSpecial = false;
  533. iCurCase = 0; /* assume that the replacement string doesn't
  534. require special capitalization */
  535. /* if we're not matching upper/lower case call WCaseCp to determine
  536. the capitalization pattern of the matched string */
  537. if (!fSearchCase)
  538. iCurCase = WCaseCp(cpSearch, cpMatchLim - cpSearch);
  539. /* if the new capitalization pattern of the matched string
  540. doesn't match the current contents of hszCaseReplace,
  541. copy the replacement string to hszCaseReplace and transform
  542. hszCaseReplace to conform to the new pattern */
  543. if (iCurCase != iLastCase)
  544. switch (iCurCase)
  545. {
  546. default:
  547. case 0: /* no special capitalization required */
  548. bltbyte(**hszRealReplace, **hszCaseReplace, cch+1);
  549. break;
  550. case 1: /* first character of string must be capitalized */
  551. bltbyte(**hszRealReplace, **hszCaseReplace, cch+1);
  552. ***hszCaseReplace = ChUpper(***hszRealReplace);
  553. break;
  554. case 2: /* all characters must be capitalized */
  555. #ifdef DBCS //t-Yoshio
  556. for (ich = 0; ich < cch;) {
  557. if(!IsDbcsLeadByte((BYTE)(**hszRealReplace)[ich])) {
  558. (**hszCaseReplace)[ich] =
  559. ChUpper((**hszRealReplace)[ich]);
  560. ich++;
  561. }
  562. else {
  563. (**hszCaseReplace)[ich] = (**hszRealReplace)[ich];
  564. (**hszCaseReplace)[ich+1] = (**hszRealReplace)[ich+1]; ich+=2;
  565. }
  566. }
  567. #else
  568. for (ich = 0; ich < cch;ich++)
  569. (**hszCaseReplace)[ich] = ChUpper((**hszRealReplace)[ich]);
  570. #endif
  571. break;
  572. }
  573. /* do CachePara to find the current para props. CachePara has the
  574. side effect of setting vpapAbs */
  575. CachePara(docCur, cpSearch);
  576. /* if the capitalization pattern has changed OR
  577. the character properties of the replacement text don't match
  578. those of the last insert OR
  579. the paragraph properties of the replacement text don't match
  580. those of the last insert, THEN
  581. 1) call NewChpIns to write a run describing the character
  582. properties of the previous insertion text,
  583. 2) call FcWScratch to write the characters of the replacement
  584. string to the scratch file,
  585. 3) if we are replacing paragraph marks, call InsertPapsForReplace
  586. to write runs describing each paragraph in the replacement
  587. string */
  588. if (iCurCase != iLastCase ||
  589. CchDiffer(&vchpInsert,&chp,cchCHP) != 0 ||
  590. (fParaReplace && CchDiffer(&vpapPrevIns, &vpapAbs, cchPAP) != 0))
  591. {
  592. NewChpIns(&chp);
  593. fcCaseSz = FcWScratch(**hszCaseReplace,cch);
  594. if (fParaReplace)
  595. InsertPapsForReplace(fcCaseSz);
  596. }
  597. /* Now since we have written the proper replacement text to
  598. the scratch file and have setup the character and paragraph runs to
  599. describe that text, simply do a replace to insert the replacement
  600. text into the piece table */
  601. Replace(docCur, cpSearch, cp0, fnScratch, fcCaseSz, (typeFC) cch);
  602. if (ferror) goto MemoryError;
  603. #ifdef JAPAN //T-HIROYN Win3.1
  604. /* When we replace from ANSI CharSet string to SHIFTJIS CharSet String
  605. We needs follows */
  606. {
  607. struct CHP savechpT;
  608. typeCP cpF, cpFirst, cpLim, kcpF, kcpL;
  609. int cchF;
  610. int kanjiftc;
  611. CHAR *rp;
  612. CHAR ch, bSet;
  613. int cchS, cblen;
  614. CHAR rgch[ cchCHP + 1 ];
  615. rgch [0] = sprmCSame;
  616. if(NATIVE_CHARSET != GetCharSetFromChp(&chp)) {
  617. kanjiftc = GetKanjiFtc(&chp);
  618. savechpT = chp;
  619. cpFirst = cpSearch;
  620. do {
  621. FetchCp(docCur, cpFirst, 0, fcmChars);
  622. cpF = vcpFetch;
  623. cchF = vcchFetch;
  624. rp = vpchFetch;
  625. if ((cpF+cchF) < cpSearch + cch)
  626. cpLim = (cpF+cchF);
  627. else
  628. cpLim = cpSearch + cch;
  629. cpFirst = kcpL;
  630. cchS = 0;
  631. kcpF = cpF;
  632. while ( kcpF < cpLim ) {
  633. ch = *rp;
  634. bSet = FALSE;
  635. if( FKana(ch) || IsDBCSLeadByte(ch) ) {
  636. cblen = GetKanjiStringLen(cchS, cchF, rp);
  637. bSet = TRUE;
  638. } else {
  639. cblen = GetAlphaStringLen(cchS, cchF, rp);
  640. }
  641. kcpL = kcpF + cblen;
  642. cchS += cblen;
  643. rp += cblen;
  644. if(bSet) {
  645. SetFtcToPchp(&chp, kanjiftc);
  646. bltbyte( &chp, &rgch [1], cchCHP );
  647. AddSprmCps(rgch, docCur, kcpF, kcpL);
  648. }
  649. kcpF = kcpL;
  650. }
  651. cpFirst = kcpF;
  652. } while ((cpF + cchF) < cpSearch + cch );
  653. chp = savechpT;
  654. }
  655. } // END JAPAN
  656. #endif
  657. iLastCase = iCurCase; /* record new capitalization pattern */
  658. /* Now delete the found text from the piece table*/
  659. cpMacSave = cpMacCur;
  660. Replace(docCur, cpSearch+cch, cpMatchLim - cpSearch, fnNil, fc0, fc0);
  661. dcp = cpMacSave - cpMacCur; /* Calculate dcp here because picture
  662. paragraphs may have interfered with deleting */
  663. if (ferror) goto MemoryError;
  664. if (!fReplaceAll)
  665. {
  666. SetUndo(uacInsert, docCur, cpSearch, (typeCP) cch,
  667. docNil, cpNil, cp0, 0);
  668. if (ferror) goto MemoryError;
  669. SetUndoMenuStr(IDSTRUndoBase);
  670. }
  671. cpSearchLim += cch - dcp;
  672. cpMatchLim += cch - dcp;
  673. cpWallActual += cch - dcp;
  674. #ifdef DBCS /* was in JAPAN */
  675. cpSearchNext = cpMatchLim;
  676. #else
  677. cpSearchNext = CpLastStyChar( cpMatchLim );
  678. #endif
  679. if (fReplaceAll)
  680. cpSearchLimNow = cpSearchLim;
  681. }
  682. while (fReplaceAll);
  683. }
  684. if (fThenFind)
  685. {
  686. do
  687. {
  688. ContinueSearch2:
  689. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  690. if(!fSpecialMatch && !fSearchDist)
  691. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,DistSearchString);
  692. else
  693. cpSearch = CpSearchSz(cpSearchNext,cpSearchLim,**hszFlatSearch);
  694. if(cpSearch == cpNil)
  695. #else
  696. if ((cpSearch = CpSearchSz(cpSearchNext, cpSearchLim,
  697. **hszFlatSearch)) == cpNil)
  698. #endif
  699. {
  700. if ((cpSearchLim == cpWallActual && fDidSearch) ||
  701. fAbortSearch)
  702. {
  703. fFirstTime = false; /* Supress error message */
  704. /*Select( CpFirstSty( cpSearchStart, styChar ),
  705. CpLastStyChar( cpMatchLim ) );*/
  706. Select( CpFirstSty( cpSearchStart, styChar ),
  707. cpMatchLim );
  708. PutCpInWwVertSrch(selCur.cpFirst);
  709. cpSearchLimNow = cpMatchLim;
  710. Error(fAbortSearch ?
  711. IDPMTCancelSearch : IDPMTSearchDone);
  712. fAbortSearch = FALSE;
  713. vfDidSearch = false;
  714. cpWall = selCur.cpLim;
  715. goto DoneReplacingP;
  716. }
  717. else
  718. {
  719. cpSearchNext = cpMinCur;
  720. cpSearchLim = cpWallActual;
  721. fDidSearch = true;
  722. goto ContinueSearch2;
  723. }
  724. }
  725. #ifdef DBCS /* was in JAPAN */
  726. cpSearchNext = CpLastStyChar( cpSearch ) + 1;
  727. #else
  728. cpSearchNext = CpLastStyChar( cpSearch + 1 );
  729. #endif
  730. }
  731. /*-- while(fSearchWord && !FWordCp(cpSearch,cpMatchLim - cpSearch));*/
  732. while(!FCpValid(cpSearch, cpMatchLim - cpSearch));
  733. if (!vfDidSearch)
  734. {
  735. cpWall = cpSearch;
  736. vfDidSearch = true;
  737. }
  738. }
  739. goto DoneReplacingP;
  740. MemoryError:
  741. FreeH(hszFlatSearch);
  742. FreeH(hszCaseReplace);
  743. FreeH(hszRealReplace);
  744. NoUndo();
  745. /* counter off the losing insertion point after incomplete change all */
  746. if (fReplaceAll && fSelSave)
  747. {
  748. selCur.cpFirst = selSave.cpFirst;
  749. selCur.cpLim = selSave.cpLim;
  750. }
  751. }
  752. #ifdef DBCS
  753. BOOL fDBCS = FALSE;
  754. #endif
  755. typeCP NEAR CpSearchSz(cpFirst, cpMacSearch, sz)
  756. typeCP cpFirst;
  757. typeCP cpMacSearch;
  758. CHAR *sz;
  759. {{ /* Finds first occurrence of sz in docCur starting at cpFirst */
  760. /* Returns cpNil if not found */
  761. /* Ignore case of letters if fSearchCase is FALSE. This assumes that the
  762. pattern has already been folded to lower case. */
  763. CHAR ch;
  764. BOOL fMatched;
  765. int ichPat = 0;
  766. int ichDoc = 0;
  767. int cchMatched = 0;
  768. typeCP cpFetchNext;
  769. /*EVENT event;*/
  770. #ifdef DBCS
  771. typeCP cpFound;
  772. CHAR rgchT[dcpAvgSent];
  773. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  774. CHAR chNext;
  775. CHAR dch[3];
  776. #endif
  777. #endif
  778. szSearch = sz;
  779. #ifdef DBCS
  780. /* Initialize those local variables moved out from this
  781. function. */
  782. ichDoc = 0;
  783. cchMatched = 0;
  784. pchFetchSave = &rgchT[0];
  785. cbLastMatch = 1;
  786. #endif
  787. #ifdef DBCS
  788. FetchCp(docCur, cpFirst, 0, fcmChars + fcmNoExpand);
  789. cpFetchSave = vcpFetch;
  790. #ifdef JAPAN //raid 4709 bug fix
  791. bltbyte(vpchFetch, rgchT, ccpFetchSave =
  792. ((vccpFetch > (dcpAvgSent-2)) ? (dcpAvgSent-2) : vccpFetch));
  793. {
  794. int inc;
  795. BOOL bDBCSBreak = FALSE;
  796. typeCP saveVcpFetch;
  797. for(inc = 0;inc < ccpFetchSave;inc++) {
  798. if(IsDBCSLeadByte((BYTE)rgchT[inc])) {
  799. inc++;
  800. if(inc >= ccpFetchSave) {
  801. bDBCSBreak = TRUE;
  802. break;
  803. }
  804. }
  805. }
  806. if(bDBCSBreak) {
  807. saveVcpFetch = vcpFetch;
  808. FetchCp(docCur, cpFetchSave + ccpFetchSave,
  809. 0, fcmChars + fcmNoExpand);
  810. bltbyte(vpchFetch, rgchT+ccpFetchSave,1);
  811. ccpFetchSave++;
  812. vcpFetch = saveVcpFetch;
  813. }
  814. }
  815. #else //JAPAN
  816. bltbyte(vpchFetch, rgchT,
  817. ccpFetchSave = ((vccpFetch > dcpAvgSent) ? dcpAvgSent : vccpFetch));
  818. if (vccpFetch > dcpAvgSent) {
  819. int inc;
  820. fDBCS = 0;
  821. for(inc = 0;inc < dcpAvgSent;inc++) {
  822. if(fDBCS)
  823. fDBCS = 0;
  824. else
  825. fDBCS = IsDBCSLeadByte((BYTE)rgchT[inc]);
  826. }
  827. if(fDBCS)
  828. ccpFetchSave--;
  829. fDBCS = 0;
  830. }
  831. #endif //JAPAN
  832. Assert(cpFetchSave == cpFirst);
  833. cpFetchNext = cpFetchSave + ccpFetchSave;
  834. #else //DBCS
  835. FetchCp(docCur, cpFirst, 0, fcmChars + fcmNoExpand);
  836. Assert(vcpFetch == cpFirst);
  837. cpFetchNext = vcpFetch + vccpFetch;
  838. #endif //DBCS
  839. fMatchedWhite = false;
  840. for (; ;)
  841. {
  842. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  843. cbLastMatch = 1;
  844. #endif
  845. if (szSearch[ichPat] == '\0' )
  846. {{ /* Found it */
  847. #ifdef DBCS
  848. typeCP cpFound;
  849. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  850. if(IsDBCSLeadByte((BYTE)ch))
  851. cpMatchLim = vcpFetch+ichDoc - (fMatchedWhite ? 2 : 0);
  852. else
  853. cpMatchLim = vcpFetch+ichDoc - (fMatchedWhite ? 1 : 0);
  854. #else
  855. cpMatchLim = vcpFetch+ichDoc - (fMatchedWhite ? 1 : 0);
  856. #endif
  857. cpFound = cpFetchSave + ichDoc - cchMatched;
  858. if (CpFirstSty(cpFound, styChar) == cpFound) {
  859. /* It is on a Kanji boundary. We really found it. */
  860. return (cpFound);
  861. }
  862. else {
  863. /* The last character did not match, try again
  864. excluding the last byte match. */
  865. cchMatched -= cbLastMatch;
  866. cbLastMatch = 1;
  867. fMatchedWhite = false;
  868. goto lblNextMatch;
  869. }
  870. #else
  871. cpMatchLim = vcpFetch+ichDoc - (fMatchedWhite ? 1 : 0);
  872. return vcpFetch + ichDoc - cchMatched;
  873. #endif
  874. }}
  875. #ifdef DBCS
  876. if (cpFetchSave + ichDoc >= cpMacSearch)
  877. #else
  878. if (vcpFetch + ichDoc >= cpMacSearch)
  879. #endif
  880. {{ /* Not found */
  881. if(fMatchedWhite && szSearch[ichPat+2] == '\0')
  882. { /* Found it */
  883. #ifdef DBCS
  884. cpMatchLim = cpFetchSave + ichDoc;
  885. cpFound = cpFetchSave + ichDoc - cchMatched;
  886. if (CpFirstSty(cpFound, styChar) == cpFound) {
  887. /* It is on a Kanji boundary, We really found it. */
  888. return (cpFound);
  889. }
  890. else {
  891. /* The last character did not match, try again
  892. excluding the last byte match. */
  893. cchMatched -= cbLastMatch;
  894. cbLastMatch = 1;
  895. fMatchedWhite = false;
  896. goto lblNextMatch;
  897. }
  898. #else
  899. cpMatchLim = vcpFetch+ichDoc;
  900. return vcpFetch + ichDoc - cchMatched;
  901. #endif
  902. }
  903. else
  904. return cpNil;
  905. }}
  906. #if defined(DBCS)
  907. if (ichDoc + cbLastMatch - 1 >= ccpFetchSave)
  908. #else
  909. if (ichDoc >= vccpFetch)
  910. #endif
  911. { /* Need more cp's */
  912. {{
  913. #ifndef NOLA /* no look ahead */
  914. /* check if abort search */
  915. if (FAbort())
  916. {
  917. fAbortSearch = TRUE;
  918. return cpNil;
  919. }
  920. #endif /* NOLA */
  921. /* FetchCp(docNil, cpNil, 0, fcmChars + fcmNoExpand); */
  922. /* we changed from a sequential fetch to a random fetch because a resize of the
  923. window may cause another FetchCp before we reach here */
  924. #ifdef DBCS
  925. FetchCp(docCur, cpFetchNext, 0, fcmChars + fcmNoExpand);
  926. cpFetchSave = vcpFetch;
  927. #ifdef JAPAN //raid 4709 bug fix
  928. bltbyte(vpchFetch, rgchT, ccpFetchSave =
  929. ((vccpFetch > (dcpAvgSent-2)) ? (dcpAvgSent-2) : vccpFetch));
  930. {
  931. int inc;
  932. BOOL bDBCSBreak = FALSE;
  933. typeCP saveVcpFetch;
  934. for(inc = 0;inc < ccpFetchSave;inc++) {
  935. if(IsDBCSLeadByte((BYTE)rgchT[inc])) {
  936. inc++;
  937. if(inc >= ccpFetchSave) {
  938. bDBCSBreak = TRUE;
  939. break;
  940. }
  941. }
  942. }
  943. if(bDBCSBreak) {
  944. saveVcpFetch = vcpFetch;
  945. FetchCp(docCur, cpFetchSave + ccpFetchSave,
  946. 0, fcmChars + fcmNoExpand);
  947. bltbyte(vpchFetch, rgchT+ccpFetchSave,1);
  948. ccpFetchSave++;
  949. vcpFetch = saveVcpFetch;
  950. }
  951. }
  952. #else //JAPAN
  953. bltbyte(vpchFetch, rgchT,
  954. ccpFetchSave = ((vccpFetch > dcpAvgSent) ?
  955. dcpAvgSent : vccpFetch));
  956. if (vccpFetch > dcpAvgSent) {
  957. int inc;
  958. fDBCS = 0;
  959. for(inc = 0;inc < dcpAvgSent;inc++) {
  960. if(fDBCS)
  961. fDBCS = 0;
  962. else
  963. fDBCS = IsDBCSLeadByte((BYTE)rgchT[inc]);
  964. }
  965. if(fDBCS)
  966. ccpFetchSave--;
  967. fDBCS = 0;
  968. }
  969. #endif //JAPAN
  970. cpFetchNext = cpFetchSave + ccpFetchSave;
  971. #else //DBCS
  972. FetchCp(docCur, cpFetchNext, 0, fcmChars + fcmNoExpand);
  973. cpFetchNext = vcpFetch + vccpFetch;
  974. #endif //DBCS
  975. ichDoc = 0;
  976. }}
  977. continue;
  978. }
  979. #ifdef DBCS
  980. ch = pchFetchSave[ichDoc++];
  981. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  982. if(IsDBCSLeadByte((BYTE)ch))
  983. {
  984. chNext = pchFetchSave[ichDoc++];
  985. cbLastMatch = 2;
  986. }
  987. else
  988. {
  989. chNext = pchFetchSave[ichDoc];
  990. cbLastMatch = 1;
  991. }
  992. #else
  993. cbLastMatch = 1;
  994. #endif /*JAPAN*/
  995. #else
  996. ch = vpchFetch[ichDoc++];
  997. #endif
  998. if(!fSpecialMatch)
  999. {
  1000. /* NOTE: this is just ChLower() brought in-line for speed */
  1001. #ifdef DBCS
  1002. if( fDBCS )
  1003. #if defined(KOREA)
  1004. {
  1005. if(!fSearchCase)
  1006. if(ch >= 'A' && ch <= 'Z') ch += 'a' - 'A';
  1007. else if (ch == 0xA3 && (chNext >= 0xC1 && chNext <= 0xDA))
  1008. chNext = 0x20 + chNext;
  1009. fDBCS = FALSE;
  1010. }
  1011. #else
  1012. fDBCS = FALSE;
  1013. #endif
  1014. else
  1015. if(!fSearchCase)
  1016. #if defined(TAIWAN) || defined(PRC)
  1017. if ( !( fDBCS = IsDBCSLeadByte( ch )))
  1018. #endif
  1019. { /* avoid proc call for common cases */
  1020. if(ch >= 'A' && ch <= 'Z') ch += 'a' - 'A';
  1021. #ifdef JAPAN /*t-Yoshio*/
  1022. if(ch == 0x82 && (chNext >= 0x60 && chNext <= 0x79))
  1023. chNext = 0x21 + chNext;
  1024. #elif defined(KOREA)
  1025. else if(ch == 0xA3 && (chNext >= 0xC1 && chNext <= 0xDA))
  1026. chNext = 0x20 + chNext;
  1027. #else
  1028. else if(ch < 'a' || ch > 'z') ch = ChLower(ch);
  1029. #endif
  1030. }
  1031. #else
  1032. if(!fSearchCase)
  1033. { /* avoid proc call for common cases */
  1034. if(ch >= 'A' && ch <= 'Z') ch += 'a' - 'A';
  1035. else if(ch < 'a' || ch > 'z') ch = ChLower(ch);
  1036. }
  1037. #endif
  1038. #ifdef JAPAN /*t-Yoshio*/
  1039. if(!fSearchDist)
  1040. {
  1041. char han_str[3];
  1042. han_str[0] = ch;han_str[1] = '\0';han_str[2] = '\0';
  1043. if(IsDBCSLeadByte((BYTE)ch))
  1044. {
  1045. if(szSearch[ichPat] == ch && szSearch[ichPat+1] == chNext)
  1046. {
  1047. ichPat+=2;
  1048. fMatched = true;
  1049. }
  1050. else
  1051. fMatched = false;
  1052. }
  1053. else
  1054. {
  1055. if(ch >= 0xca && ch <= 0xce)
  1056. {
  1057. if(!myIsSonant(szSearch[ichPat],szSearch[ichPat+1]))
  1058. han_str[1] = '\0';
  1059. else if(chNext == 0xde || chNext == 0xdf )
  1060. {
  1061. han_str[1] = chNext;
  1062. han_str[2] = '\0';
  1063. cbLastMatch = 2;
  1064. ichDoc++;
  1065. }
  1066. else
  1067. han_str[1] = '\0';
  1068. }
  1069. else if(ch >= 0xa6 && ch <= 0xc4)
  1070. {
  1071. if(!myIsSonant(szSearch[ichPat],szSearch[ichPat+1]))
  1072. han_str[1] = '\0';
  1073. else if(chNext == 0xde )
  1074. {
  1075. han_str[1] = chNext;
  1076. han_str[2] = '\0';
  1077. cbLastMatch = 2;
  1078. ichDoc++;
  1079. }
  1080. else
  1081. han_str[1] = '\0';
  1082. }
  1083. else
  1084. han_str[1] = '\0';
  1085. myHantoZen(han_str,dch,3);
  1086. if(szSearch[ichPat] == dch[0] && szSearch[ichPat+1] == dch[1])
  1087. {
  1088. ichPat+=2;
  1089. fMatched = true;
  1090. }
  1091. else if(ch == chReturn || ch == chNRHFile)
  1092. fMatched = true;
  1093. else
  1094. fMatched = false;
  1095. }
  1096. }
  1097. else
  1098. {
  1099. if(IsDBCSLeadByte((BYTE)ch))
  1100. {
  1101. if(szSearch[ichPat] == ch && szSearch[ichPat+1] == chNext)
  1102. {
  1103. ichPat+=2;
  1104. fMatched = true;
  1105. }
  1106. else
  1107. fMatched = false;
  1108. }
  1109. else if(szSearch[ichPat] == ch)
  1110. {
  1111. ichPat++;
  1112. fMatched = true;
  1113. }
  1114. else if(ch == chReturn || ch == chNRHFile)
  1115. fMatched = true;
  1116. else
  1117. fMatched = false;
  1118. }
  1119. #elif defined(KOREA)
  1120. if(!fSearchDist)
  1121. {
  1122. char han_str[3];
  1123. han_str[0] = ch;han_str[1] = '\0';han_str[2] = '\0';
  1124. if(IsDBCSLeadByte((BYTE)ch))
  1125. {
  1126. if(szSearch[ichPat] == ch && szSearch[ichPat+1] == chNext)
  1127. {
  1128. ichPat+=2;
  1129. fMatched = true;
  1130. }
  1131. else
  1132. fMatched = false;
  1133. }
  1134. else
  1135. {
  1136. han_str[1] = '\0';
  1137. myHantoZen(han_str,dch,3);
  1138. if(szSearch[ichPat] == dch[0] && szSearch[ichPat+1] == dch[1])
  1139. {
  1140. ichPat+=2;
  1141. fMatched = true;
  1142. }
  1143. else if(ch == chReturn || ch == chNRHFile)
  1144. fMatched = true;
  1145. else
  1146. fMatched = false;
  1147. }
  1148. }
  1149. else
  1150. {
  1151. if(IsDBCSLeadByte((BYTE)ch))
  1152. {
  1153. if(szSearch[ichPat] == ch && szSearch[ichPat+1] == chNext)
  1154. {
  1155. ichPat+=2;
  1156. fMatched = true;
  1157. }
  1158. else
  1159. fMatched = false;
  1160. }
  1161. else if(szSearch[ichPat] == ch)
  1162. {
  1163. ichPat++;
  1164. fMatched = true;
  1165. }
  1166. else if(ch == chReturn || ch == chNRHFile)
  1167. fMatched = true;
  1168. else
  1169. fMatched = false;
  1170. }
  1171. #else
  1172. if(szSearch[ichPat] == ch)
  1173. {
  1174. ichPat++;
  1175. fMatched = true;
  1176. }
  1177. else if(ch == chReturn || ch == chNRHFile)
  1178. fMatched = true;
  1179. else
  1180. fMatched = false;
  1181. #endif
  1182. }
  1183. else
  1184. {
  1185. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  1186. fMatched = J_FChMatch(ch,chNext,&ichPat,&ichDoc);
  1187. #else
  1188. fMatched = FChMatch(ch, &ichPat, true);
  1189. #endif
  1190. }
  1191. #ifdef DBCS
  1192. //#ifndef JAPAN /*t-Yoshio*/
  1193. #if !defined(JAPAN) && !defined(KOREA) /*t-Yoshio*/
  1194. fDBCS = IsDBCSLeadByte( ch );
  1195. #endif
  1196. #endif
  1197. if(fMatched)
  1198. {
  1199. #if defined(DBCS)
  1200. cchMatched += cbLastMatch;
  1201. #else
  1202. cchMatched++;
  1203. #endif
  1204. }
  1205. else
  1206. { /* No match; try again */
  1207. #ifdef DBCS
  1208. lblNextMatch:
  1209. #endif
  1210. if ((ichDoc -= cchMatched) < 0) /* Go back # of matched chars */
  1211. {{ /* Overshot the mark */
  1212. #ifdef DBCS
  1213. FetchCp(docCur, cpFetchSave + ichDoc, 0, fcmChars + fcmNoExpand);
  1214. cpFetchSave = vcpFetch;
  1215. #ifdef JAPAN //raid 4709 bug fix
  1216. bltbyte(vpchFetch, rgchT, ccpFetchSave =
  1217. ((vccpFetch > (dcpAvgSent-2)) ? (dcpAvgSent-2) : vccpFetch));
  1218. {
  1219. int inc;
  1220. BOOL bDBCSBreak = FALSE;
  1221. typeCP saveVcpFetch;
  1222. for(inc = 0;inc < ccpFetchSave;inc++) {
  1223. if(IsDBCSLeadByte((BYTE)rgchT[inc])) {
  1224. inc++;
  1225. if(inc >= ccpFetchSave) {
  1226. bDBCSBreak = TRUE;
  1227. break;
  1228. }
  1229. }
  1230. }
  1231. if(bDBCSBreak) {
  1232. saveVcpFetch = vcpFetch;
  1233. FetchCp(docCur, cpFetchSave + ccpFetchSave,
  1234. 0, fcmChars + fcmNoExpand);
  1235. bltbyte(vpchFetch, rgchT+ccpFetchSave,1);
  1236. ccpFetchSave++;
  1237. vcpFetch = saveVcpFetch;
  1238. }
  1239. }
  1240. #else //JAPAN
  1241. bltbyte(vpchFetch, rgchT,
  1242. ccpFetchSave = ((vccpFetch > dcpAvgSent) ?
  1243. dcpAvgSent : vccpFetch));
  1244. if (vccpFetch > dcpAvgSent) {
  1245. int inc;
  1246. fDBCS = 0;
  1247. for(inc = 0;inc < dcpAvgSent;inc++) {
  1248. if(fDBCS)
  1249. fDBCS = 0;
  1250. else
  1251. fDBCS = IsDBCSLeadByte((BYTE)rgchT[inc]);
  1252. }
  1253. if(fDBCS)
  1254. ccpFetchSave--;
  1255. fDBCS = 0;
  1256. }
  1257. #endif //JAPAN
  1258. cpFetchNext = cpFetchSave + ccpFetchSave;
  1259. #else //DBCS
  1260. FetchCp(docCur, vcpFetch + ichDoc, 0, fcmChars + fcmNoExpand);
  1261. /* this is for the next FetchCp in this forever loop that used to depend
  1262. on a sequential fetch */
  1263. cpFetchNext = vcpFetch + vccpFetch;
  1264. #endif //DBCS
  1265. ichDoc = 0;
  1266. }}
  1267. ichPat = 0;
  1268. cchMatched = 0;
  1269. }
  1270. }
  1271. }}
  1272. /* set up in hszFlatSearch a copy of hszSearch that is all lower case.
  1273. Note that we assume the old contents of hszFlatSearch were freed.
  1274. Return True if success, False if out of memory.
  1275. */
  1276. NEAR FMakeFlat(cch)
  1277. int cch; /*CchSz(**hszSearch)-1*/
  1278. {
  1279. CHAR *pch1;
  1280. CHAR *pch2;
  1281. hszFlatSearch = (CHAR (**) [])HAllocate(CwFromCch(cch+1));
  1282. if(FNoHeap(hszFlatSearch))
  1283. return(FALSE);
  1284. if(!fSearchCase)
  1285. {
  1286. #ifdef DBCS
  1287. for(pch1= **hszSearch, pch2 = **hszFlatSearch;*pch1!='\0';)
  1288. if( IsDBCSLeadByte(*pch1) ) {
  1289. #ifdef JAPAN /*t-Yoshio*/
  1290. if(*pch1 == 0x82 && (*(pch1+1) >= 0x60 && *(pch1+1) <= 0x79 ))
  1291. {
  1292. *pch2++ = *pch1++;
  1293. *pch2++ = 0x21 + *pch1++;
  1294. }
  1295. else
  1296. {
  1297. *pch2++ = *pch1++;
  1298. *pch2++ = *pch1++;
  1299. }
  1300. #elif defined(KOREA)
  1301. if(*pch1 == 0xA3 && (*(pch1+1) >= 0xC1 && *(pch1+1) <= 0xDA))
  1302. {
  1303. *pch2++ = *pch1++;
  1304. *pch2++ = 0x20 + *pch1++;
  1305. }
  1306. else
  1307. {
  1308. *pch2++ = *pch1++;
  1309. *pch2++ = *pch1++;
  1310. }
  1311. #else
  1312. *pch2++ = *pch1++;
  1313. *pch2++ = *pch1++;
  1314. #endif
  1315. } else
  1316. {
  1317. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  1318. if(*pch1 >= 'A' && *pch1 <= 'Z')
  1319. {
  1320. *pch2 = *pch1 + 0x20; pch1++; pch2++;
  1321. }
  1322. else
  1323. *pch2++ = *pch1++;
  1324. #else
  1325. *pch2++ = ChLower(*pch1++);
  1326. #endif
  1327. }
  1328. #else
  1329. for(pch1= **hszSearch, pch2 = **hszFlatSearch;*pch1!='\0';pch1++,pch2++)
  1330. *pch2 = ChLower(*pch1);
  1331. #endif
  1332. *pch2 = '\0';
  1333. }
  1334. else
  1335. bltbyte(**hszSearch, **hszFlatSearch, cch+1);
  1336. return(TRUE);
  1337. }
  1338. /* sets the global fSpecialMatch if the more complicated character matching
  1339. code is needed */
  1340. NEAR SetSpecialMatch()
  1341. {
  1342. CHAR *pch = **hszSearch;
  1343. CHAR ch;
  1344. #ifdef DBCS
  1345. for( ch = *pch ; ch != '\0'; pch = AnsiNext(pch), ch = *pch )
  1346. #else
  1347. while((ch = *pch++) != '\0')
  1348. #endif
  1349. {
  1350. switch(ch)
  1351. {
  1352. default:
  1353. continue;
  1354. case chMatchAny:
  1355. case chPrefixMatch:
  1356. case chSpace:
  1357. case chHyphen:
  1358. fSpecialMatch = true;
  1359. return;
  1360. }
  1361. }
  1362. fSpecialMatch = false;
  1363. return;
  1364. }
  1365. /* Sets the global fParaReplace if the user wants to insert Paragraph breaks
  1366. (since special insertion code must be run). Also sets up the global
  1367. hszRealReplace to reflect any meta characters in hszReplace */
  1368. NEAR FSetParaReplace(cch)
  1369. int cch; /*CchSz(**hszReplace)*/
  1370. {
  1371. CHAR *rgch = **hszRealReplace;
  1372. int ich = 0;
  1373. CHAR ch;
  1374. CHAR chNew;
  1375. fParaReplace = false;
  1376. while((ch = rgch[ich]) != '\0')
  1377. {
  1378. #ifdef DBCS
  1379. if(IsDBCSLeadByte(ch)){
  1380. ich +=2;
  1381. continue;
  1382. }
  1383. #endif
  1384. switch(ch)
  1385. {
  1386. default:
  1387. break;
  1388. case chPrefixMatch:
  1389. switch(rgch[ich+1])
  1390. {
  1391. default:
  1392. /* just escaping the next char */
  1393. if(rgch[ich+1] == '\0')
  1394. chNew = chPrefixMatch;
  1395. else
  1396. chNew = rgch[ich+1];
  1397. break;
  1398. case chMatchNBSFile:
  1399. chNew = chNBSFile;
  1400. break;
  1401. case chMatchTab:
  1402. chNew = chTab;
  1403. break;
  1404. case chMatchNewLine:
  1405. chNew = chNewLine;
  1406. break;
  1407. case chMatchNRHFile:
  1408. chNew = chNRHFile;
  1409. break;
  1410. case chMatchSect:
  1411. chNew = chSect;
  1412. break;
  1413. case chMatchEol:
  1414. chNew = chEol;
  1415. break;
  1416. }
  1417. #ifdef CRLF
  1418. if(chNew != chEol)
  1419. bltbyte(&(rgch[ich+1]),&(rgch[ich]), cch-ich-1);
  1420. #else
  1421. bltbyte(&(rgch[ich+1]),&(rgch[ich]), cch-ich-1);
  1422. #endif /*CRLF*/
  1423. if(chNew == chEol)
  1424. {
  1425. fParaReplace = true;
  1426. #ifdef CRLF
  1427. rgch[ich++] = chReturn;
  1428. #endif /*CRLF*/
  1429. }
  1430. rgch[ich] = chNew;
  1431. break;
  1432. case chEol:
  1433. #ifdef CRLF
  1434. if(ich == 0 || rgch[ich-1] != chReturn)
  1435. /* they didn't put in a return! */
  1436. {
  1437. CHAR (**hsz)[];
  1438. hsz = (CHAR (**) [])HAllocate(CwFromCch(cch+1));
  1439. if(FNoHeap(hsz))
  1440. {
  1441. return false;
  1442. }
  1443. bltbyte(**hszRealReplace, **hsz, ich);
  1444. (**hsz)[ich] = chReturn;
  1445. bltbyte((**hszRealReplace)+ich, (**hsz)+ich+1,
  1446. cch - ich);
  1447. FreeH(hszRealReplace);
  1448. hszRealReplace = hsz;
  1449. rgch = **hszRealReplace;
  1450. cch++;
  1451. ich++;
  1452. }
  1453. #endif /*CRLF*/
  1454. fParaReplace = true;
  1455. break;
  1456. }
  1457. ich++;
  1458. }
  1459. return true;
  1460. }
  1461. NEAR WCaseCp(cp,dcp)
  1462. typeCP cp;
  1463. typeCP dcp;
  1464. {
  1465. /* Determines capitalization pattern in a piece of text. Used when doing
  1466. replace to match existing pattern. returns an int which is one of:
  1467. 0 - Not initial capital
  1468. 1 - Initial Capital but lower case appears later
  1469. 2 - Initial Capital and no lower case in the string
  1470. Assumes a valid cp, dcp pair.
  1471. */
  1472. int ichDoc;
  1473. FetchCp(docCur, cp, 0, fcmChars + fcmNoExpand);
  1474. if(!isupper(vpchFetch[0]))
  1475. return(0);
  1476. /* we now know there is an initial cap. Are there any lower case chars? */
  1477. for(ichDoc=1; vcpFetch+ichDoc < cp + dcp;)
  1478. {
  1479. if(ichDoc >= vccpFetch)
  1480. {
  1481. FetchCp(docNil, cpNil, 0, fcmChars + fcmNoExpand);
  1482. ichDoc = 0;
  1483. continue;
  1484. }
  1485. if(islower(vpchFetch[ichDoc++]))
  1486. return(1);
  1487. }
  1488. /* No lower case letters were found. */
  1489. return(2);
  1490. }
  1491. int
  1492. FCpValid(cp, dcp)
  1493. typeCP cp, dcp;
  1494. {
  1495. CachePara(docCur, cp);
  1496. if (vpapAbs.fGraphics)
  1497. return false;
  1498. #ifdef JAPAN /*t-Yoshio*/
  1499. if (0)
  1500. #else
  1501. if (fSearchWord)
  1502. #endif
  1503. return FWordCp(cp, dcp);
  1504. return true;
  1505. }
  1506. NEAR DestroyModeless(phDlg)
  1507. HWND * phDlg;
  1508. {
  1509. HWND hDlg = *phDlg;
  1510. *phDlg = (HWND)NULL;
  1511. vhWndMsgBoxParent = (HANDLE)NULL;
  1512. DestroyWindow(hDlg);
  1513. } /* end of DestroyModeless */
  1514. BOOL far PASCAL DialogFind( hDlg, message, wParam, lParam )
  1515. HWND hDlg; /* Handle to the dialog box */
  1516. unsigned message;
  1517. WORD wParam;
  1518. LONG lParam;
  1519. {
  1520. CHAR szBuf[257];
  1521. int cch = 0;
  1522. HANDLE hCtlFindNext = GetDlgItem(hDlg, idiFindNext);
  1523. /* This routine handles input to the Find dialog box. */
  1524. switch (message)
  1525. {
  1526. case WM_INITDIALOG:
  1527. #ifdef ENABLE /* not sure how cxEditScroll is used */
  1528. cxEditScroll = 0;
  1529. #endif
  1530. #ifdef JAPAN /*t-Yoshio*/
  1531. CheckDlgButton(hDlg, idiDistinguishDandS, fSearchDist);
  1532. #elif defined(KOREA)
  1533. //bklee CheckDlgButton(hDlg, idiDistinguishDandS, fSearchDist);
  1534. CheckDlgButton(hDlg, idiWholeWord, fSearchWord);
  1535. #else
  1536. CheckDlgButton(hDlg, idiWholeWord, fSearchWord);
  1537. #endif
  1538. CheckDlgButton(hDlg, idiMatchCase, fSearchCase);
  1539. cch = CchCopySz(**hszSearch, szBuf);
  1540. if (cch == 0)
  1541. {
  1542. EnableWindow(hCtlFindNext, false);
  1543. }
  1544. else
  1545. {
  1546. SetDlgItemText(hDlg, idiFind, (LPSTR)szBuf);
  1547. SelectIdiText(hDlg, idiFind);
  1548. }
  1549. vfDidSearch = false;
  1550. cpWall = selCur.cpLim;
  1551. return( TRUE ); /* ask windows to set focus to the first item also */
  1552. case WM_ACTIVATE:
  1553. if (wParam) /* turns active */
  1554. {
  1555. vhWndMsgBoxParent = hDlg;
  1556. }
  1557. if (vfCursorVisible)
  1558. ShowCursor(wParam);
  1559. return(FALSE); /* so that we leave the activate message to
  1560. the dialog manager to take care of setting the focus correctly */
  1561. case WM_COMMAND:
  1562. switch (wParam)
  1563. {
  1564. case idiFind:
  1565. if (HIWORD(lParam) == EN_CHANGE)
  1566. {
  1567. vfDidSearch = false;
  1568. cpWall = selCur.cpLim;
  1569. CheckEnableButton(LOWORD(lParam), hCtlFindNext);
  1570. }
  1571. break;
  1572. #ifdef JAPAN /*t-Yoshio*/
  1573. case idiDistinguishDandS :
  1574. #elif defined(KOREA)
  1575. case idiDistinguishDandS :
  1576. case idiWholeWord:
  1577. #else
  1578. case idiWholeWord:
  1579. #endif
  1580. case idiMatchCase:
  1581. CheckDlgButton(hDlg, wParam, !IsDlgButtonChecked(hDlg, wParam));
  1582. break;
  1583. case idiFindNext:
  1584. if (IsWindowEnabled(hCtlFindNext))
  1585. {
  1586. CHAR (**hszSearchT)[] ;
  1587. if (FDlgSzTooLong(hDlg, idiFind, szBuf, 257))
  1588. {
  1589. switch (idiMsgResponse(hDlg, idiFind, IDPMTTruncateSz))
  1590. {
  1591. case idiOk:
  1592. /* show truncated text to user */
  1593. SetDlgItemText(hDlg, idiFind, (LPSTR)szBuf);
  1594. break;
  1595. case idiCancel:
  1596. default:
  1597. return(TRUE);
  1598. }
  1599. }
  1600. if (FNoHeap(hszSearchT = HszCreate(szBuf)))
  1601. break;
  1602. /* fSearchForward = 1; search direction -- always forward */
  1603. PostStatusInCaption(IDSTRSearching);
  1604. StartLongOp();
  1605. FreeH(hszSearch);
  1606. hszSearch = hszSearchT;
  1607. fSearchCase = IsDlgButtonChecked(hDlg, idiMatchCase);
  1608. #ifdef JAPAN /*t-Yoshio*/
  1609. fSearchWord = 0;
  1610. fSearchDist = IsDlgButtonChecked(hDlg, idiDistinguishDandS);
  1611. #elif defined(KOREA)
  1612. //bklee fSearchDist = IsDlgButtonChecked(hDlg, idiDistinguishDandS);
  1613. fSearchDist = 1;
  1614. fSearchWord = IsDlgButtonChecked(hDlg, idiWholeWord);
  1615. #else
  1616. fSearchWord = IsDlgButtonChecked(hDlg, idiWholeWord);
  1617. #endif
  1618. EnableExcept(vhDlgFind, FALSE);
  1619. DoSearch();
  1620. EnableExcept(vhDlgFind, TRUE);
  1621. EndLongOp(vhcIBeam);
  1622. PostStatusInCaption(NULL);
  1623. }
  1624. break;
  1625. case idiCancel:
  1626. LCancelFind:
  1627. DestroyModeless(&vhDlgFind);
  1628. break;
  1629. default:
  1630. return(FALSE);
  1631. }
  1632. break;
  1633. case WM_CLOSE:
  1634. if (bInSearchReplace)
  1635. return TRUE;
  1636. goto LCancelFind;
  1637. #ifndef INEFFLOCKDOWN
  1638. case WM_NCDESTROY:
  1639. FreeProcInstance(lpDialogFind);
  1640. lpDialogFind = NULL;
  1641. /* fall through to return false */
  1642. #endif
  1643. default:
  1644. return(FALSE);
  1645. }
  1646. return(TRUE);
  1647. } /* end of DialogFind */
  1648. BOOL far PASCAL DialogChange( hDlg, message, wParam, lParam )
  1649. HWND hDlg; /* Handle to the dialog box */
  1650. unsigned message;
  1651. WORD wParam;
  1652. LONG lParam;
  1653. {
  1654. CHAR szBuf[257]; /* max 255 char + '\0' + 1 so as to detact too long string */
  1655. int cch = 0;
  1656. HANDLE hCtlFindNext = GetDlgItem(hDlg, idiFindNext);
  1657. CHAR (**hszSearchT)[];
  1658. CHAR (**hszReplaceT)[];
  1659. /* This routine handles input to the Change dialog box. */
  1660. switch (message)
  1661. {
  1662. case WM_INITDIALOG:
  1663. #ifdef ENABLE /* not sure how cxEditScroll is used */
  1664. cxEditScroll = 0;
  1665. #endif
  1666. szBuf[0] = '\0';
  1667. #ifdef JAPAN /*t-Yoshio*/
  1668. CheckDlgButton(hDlg, idiDistinguishDandS, fSearchDist);
  1669. #elif defined(KOREA)
  1670. //bklee CheckDlgButton(hDlg, idiDistinguishDandS, fSearchDist);
  1671. CheckDlgButton(hDlg, idiWholeWord, fSearchWord);
  1672. #else
  1673. CheckDlgButton(hDlg, idiWholeWord, fSearchWord);
  1674. #endif
  1675. CheckDlgButton(hDlg, idiMatchCase, fSearchCase);
  1676. cch = CchCopySz(**hszSearch, szBuf);
  1677. SetDlgItemText(hDlg, idiFind, (LPSTR)szBuf);
  1678. if (cch > 0)
  1679. {
  1680. SelectIdiText(hDlg, idiFind);
  1681. }
  1682. else
  1683. {
  1684. EnableWindow(hCtlFindNext, false);
  1685. EnableWindow(GetDlgItem(hDlg, idiChangeThenFind), false);
  1686. //EnableWindow(GetDlgItem(hDlg, idiChange), false);
  1687. EnableWindow(GetDlgItem(hDlg, idiChangeAll), false);
  1688. }
  1689. cch = CchCopySz(**hszReplace, szBuf);
  1690. SetDlgItemText(hDlg, idiChangeTo, (LPSTR)szBuf);
  1691. fChangeSel = false;
  1692. vfDidSearch = false;
  1693. SetChangeString(hDlg, selCur.cpFirst == selCur.cpLim);
  1694. cpWall = selCur.cpLim;
  1695. return( TRUE ); /* ask windows to set focus to the first item also */
  1696. case WM_ACTIVATE:
  1697. if (wParam)
  1698. {
  1699. vhWndMsgBoxParent = hDlg;
  1700. SetChangeString(hDlg, (selCur.cpFirst == selCur.cpLim) || vfDidSearch);
  1701. }
  1702. if (vfCursorVisible)
  1703. ShowCursor(wParam);
  1704. return(FALSE); /* so that we leave the activate message to
  1705. the dialog manager to take care of setting the focus correctly */
  1706. case WM_COMMAND:
  1707. switch (wParam)
  1708. {
  1709. case idiFind: /* edittext */
  1710. if (HIWORD(lParam) == EN_CHANGE)
  1711. {
  1712. vfDidSearch = false;
  1713. cpWall = selCur.cpLim;
  1714. if (!CheckEnableButton(LOWORD(lParam), hCtlFindNext))
  1715. {
  1716. EnableWindow(GetDlgItem(hDlg, idiChangeThenFind), false);
  1717. //EnableWindow(GetDlgItem(hDlg, idiChange), false);
  1718. EnableWindow(GetDlgItem(hDlg, idiChangeAll), false);
  1719. }
  1720. else
  1721. {
  1722. EnableWindow(GetDlgItem(hDlg, idiChangeThenFind), true);
  1723. //EnableWindow(GetDlgItem(hDlg, idiChange), true);
  1724. EnableWindow(GetDlgItem(hDlg, idiChangeAll), true);
  1725. }
  1726. return(TRUE);
  1727. }
  1728. else
  1729. return(FALSE);
  1730. case idiChangeTo: /* edittext */
  1731. return(FALSE);
  1732. case idiFindNext: /* Button for Find Next */
  1733. /* Windows did not check if the default button is disabled
  1734. or not, so we have to check that! */
  1735. if (!IsWindowEnabled(hCtlFindNext))
  1736. break;
  1737. //case idiChange: /* Change, and stay put */
  1738. case idiChangeThenFind: /* Change, then Find button */
  1739. case idiChangeAll: /* Button for Replace All */
  1740. if (wwCur < 0)
  1741. break;
  1742. if (FDlgSzTooLong(hDlg, idiFind, szBuf, 257))
  1743. {
  1744. switch (idiMsgResponse(hDlg, idiFind, IDPMTTruncateSz))
  1745. {
  1746. case idiOk:
  1747. /* show truncated text to user */
  1748. SetDlgItemText(hDlg, idiFind, (LPSTR)szBuf);
  1749. break;
  1750. case idiCancel:
  1751. default:
  1752. return(TRUE);
  1753. }
  1754. }
  1755. if (FNoHeap(hszSearchT = HszCreate(szBuf)))
  1756. break;
  1757. if (FDlgSzTooLong(hDlg, idiChangeTo, szBuf, 257))
  1758. {
  1759. switch (idiMsgResponse(hDlg, idiChangeTo, IDPMTTruncateSz))
  1760. {
  1761. case idiOk:
  1762. /* show truncated text to user */
  1763. SetDlgItemText(hDlg, idiChangeTo, (LPSTR)szBuf);
  1764. break;
  1765. case idiCancel:
  1766. default:
  1767. return(TRUE);
  1768. }
  1769. }
  1770. if (FNoHeap(hszReplaceT = HszCreate(szBuf)))
  1771. break;
  1772. PostStatusInCaption(IDSTRSearching);
  1773. StartLongOp();
  1774. FreeH(hszSearch);
  1775. hszSearch = hszSearchT;
  1776. FreeH(hszReplace);
  1777. hszReplace = hszReplaceT;
  1778. /* fReplConfirm = 1;*/
  1779. fSearchCase = IsDlgButtonChecked(hDlg, idiMatchCase);
  1780. #ifdef JAPAN /*t-Yoshio*/
  1781. fSearchWord = 0;
  1782. fSearchDist = IsDlgButtonChecked(hDlg, idiDistinguishDandS);
  1783. #elif defined(KOREA)
  1784. //bklee fSearchDist = IsDlgButtonChecked(hDlg, idiDistinguishDandS);
  1785. fSearchDist = 1;
  1786. fSearchWord = IsDlgButtonChecked(hDlg, idiWholeWord);
  1787. #else
  1788. fSearchWord = IsDlgButtonChecked(hDlg, idiWholeWord);
  1789. #endif
  1790. EnableExcept(vhDlgChange, FALSE);
  1791. switch (wParam)
  1792. {
  1793. case idiFindNext:
  1794. DoSearch();
  1795. break;
  1796. //case idiChange:
  1797. case idiChangeThenFind:
  1798. CmdReplace(wParam == idiChangeThenFind);
  1799. break;
  1800. case idiChangeAll:
  1801. TurnOffSel();
  1802. if (!fChangeSel)
  1803. {
  1804. fSelSave = TRUE;
  1805. selSave.cpFirst = selCur.cpFirst;
  1806. selSave.cpLim = selCur.cpLim;
  1807. selCur.cpFirst = cpMinCur;
  1808. selCur.cpLim = cpMacCur;
  1809. }
  1810. CmdReplaceAll();
  1811. fSelSave = FALSE; /* reset */
  1812. break;
  1813. default:
  1814. Assert(FALSE);
  1815. break;
  1816. }
  1817. EnableExcept(vhDlgChange, TRUE);
  1818. SetChangeString(hDlg, vfDidSearch ? true : selCur.cpFirst == selCur.cpLim);
  1819. EndLongOp(vhcIBeam);
  1820. PostStatusInCaption(NULL);
  1821. break;
  1822. #ifdef JAPAN /*t-Yoshio*/
  1823. case idiDistinguishDandS:
  1824. #elif defined(KOREA)
  1825. case idiDistinguishDandS:
  1826. case idiWholeWord:
  1827. #else
  1828. case idiWholeWord:
  1829. #endif
  1830. case idiMatchCase:
  1831. CheckDlgButton(hDlg, wParam, !IsDlgButtonChecked(hDlg, wParam));
  1832. break;
  1833. case idiCancel:
  1834. LCancelChange:
  1835. DestroyModeless(&vhDlgChange);
  1836. break;
  1837. default:
  1838. return(FALSE);
  1839. }
  1840. break;
  1841. #if WINVER < 0x300
  1842. /* Don't really need to process this */
  1843. case WM_CLOSE:
  1844. goto LCancelChange;
  1845. #endif
  1846. #ifndef INEFFLOCKDOWN
  1847. case WM_NCDESTROY:
  1848. FreeProcInstance(lpDialogChange);
  1849. lpDialogChange = NULL;
  1850. /* fall through to return false */
  1851. #endif
  1852. default:
  1853. return(FALSE);
  1854. }
  1855. return(TRUE);
  1856. } /* end of DialogChange */
  1857. NEAR SetChangeString(hDlg, fAll)
  1858. HANDLE hDlg;
  1859. int fAll;
  1860. { /* set the last control button in CHANGE to "Change All" or "Change Selection" */
  1861. CHAR sz[256];
  1862. if (fAll == fChangeSel)
  1863. {
  1864. PchFillPchId(sz, (fAll ? IDSTRChangeAll : IDSTRChangeSel), sizeof(sz));
  1865. SetDlgItemText(hDlg, idiChangeAll, (LPSTR)sz);
  1866. fChangeSel = !fAll;
  1867. }
  1868. }
  1869. fnFindText()
  1870. {/* create dialog window only when it is not already created. */
  1871. if (!IsWindow(vhDlgFind))
  1872. {
  1873. #ifndef INEFFLOCKDOWN
  1874. if (!lpDialogFind)
  1875. if (!(lpDialogFind = MakeProcInstance(DialogFind, hMmwModInstance)))
  1876. {
  1877. WinFailure();
  1878. return;
  1879. }
  1880. #endif
  1881. vhDlgFind = CreateDialog(hMmwModInstance, MAKEINTRESOURCE(dlgFind),
  1882. hParentWw, lpDialogFind);
  1883. if (!vhDlgFind)
  1884. #ifdef WIN30
  1885. WinFailure();
  1886. #else
  1887. Error(IDPMTNoMemory);
  1888. #endif
  1889. }
  1890. else
  1891. {
  1892. SendMessage(vhDlgFind, WM_ACTIVATE, true, (LONG)NULL);
  1893. }
  1894. }
  1895. fnFindAgain()
  1896. {
  1897. register HWND hDlg = wwdCurrentDoc.wwptr;
  1898. register HWND hWndFrom;
  1899. hWndFrom = GetActiveWindow();
  1900. /* Find out where the F3 was executed from */
  1901. /* assemble hszSearch if called from Find or Change dialog box */
  1902. if (vhDlgFind || vhDlgChange)
  1903. {
  1904. if (((hDlg = vhDlgFind) && (vhDlgFind == hWndFrom ||
  1905. vhDlgFind == (HANDLE)GetWindowWord(hWndFrom, GWW_HWNDPARENT)))
  1906. ||
  1907. ((hDlg = vhDlgChange) && (vhDlgChange == hWndFrom ||
  1908. vhDlgChange == (HANDLE)GetWindowWord(hWndFrom, GWW_HWNDPARENT))))
  1909. {
  1910. SendMessage(hDlg, WM_COMMAND, idiFindNext, (LONG)0);
  1911. goto Out;
  1912. }
  1913. }
  1914. PostStatusInCaption(IDSTRSearching);
  1915. StartLongOp();
  1916. DoSearch();
  1917. EndLongOp(vhcIBeam);
  1918. PostStatusInCaption(NULL);
  1919. Out:
  1920. if (!IsWindowEnabled(wwdCurrentDoc.wwptr))
  1921. EnableWindow(wwdCurrentDoc.wwptr, true);
  1922. if (!IsWindowEnabled(hParentWw))
  1923. EnableWindow(hParentWw, true);
  1924. SendMessage(hParentWw, WM_ACTIVATE, true, (LONG)NULL);
  1925. } /* end of fnFindAgain */
  1926. fnReplaceText()
  1927. {/* create dialog window only when it is not already created. */
  1928. if (!IsWindow(vhDlgChange))
  1929. {
  1930. #ifndef INEFFLOCKDOWN
  1931. if (!lpDialogChange)
  1932. if (!(lpDialogChange = MakeProcInstance(DialogChange, hMmwModInstance)))
  1933. {
  1934. WinFailure();
  1935. return;
  1936. }
  1937. #endif
  1938. vhDlgChange = CreateDialog(hMmwModInstance, MAKEINTRESOURCE(dlgChange),
  1939. hParentWw, lpDialogChange);
  1940. if (!vhDlgChange)
  1941. #ifdef WIN30
  1942. WinFailure();
  1943. #else
  1944. Error(IDPMTNoMemory);
  1945. #endif
  1946. }
  1947. else
  1948. {
  1949. SendMessage(vhDlgChange, WM_ACTIVATE, true, (LONG)NULL);
  1950. }
  1951. }
  1952. /* P U T C P I N W W V E R T S R C H*/
  1953. NEAR PutCpInWwVertSrch(cp)
  1954. typeCP cp;
  1955. {
  1956. /* vertical case */
  1957. typeCP cpMac;
  1958. int ypMac;
  1959. struct EDL *pedl;
  1960. int dl;
  1961. int dlMac;
  1962. UpdateWw(wwCur, false);
  1963. dlMac = pwwdCur->dlMac - (vfSelecting ? 0 : 1);
  1964. if (dlMac <= 0)
  1965. return;
  1966. pedl = &(**(pwwdCur->hdndl))[dlMac - 1];
  1967. if (cp < pwwdCur->cpFirst ||
  1968. cp > (cpMac = pedl->cpMin + pedl->dcpMac) ||
  1969. cp == cpMac && pedl->fIchCpIncr)
  1970. {
  1971. DirtyCache(pwwdCur->cpFirst = cp);
  1972. pwwdCur->ichCpFirst = 0;
  1973. /* This call places the search cp vertically on the screen
  1974. by scrolling. */
  1975. CtrBackDypCtr( (pwwdCur->ypMac - pwwdCur->ypMin) >> 1, 2 );
  1976. #ifdef ENABLE /* no ActiveWindow concept yet */
  1977. if (pwwdCur->wwptr != ActiveWindow)
  1978. #endif
  1979. TrashWw(wwCur);
  1980. }
  1981. else
  1982. {
  1983. ypMac = pwwdCur->ypMac / 2;
  1984. /* Make sure that cp is still visible (scrolling if neccesary) */
  1985. pedl = &(**(pwwdCur->hdndl))[dl = DlFromYp(ypMac, pwwdCur)];
  1986. if (cp >= pedl->cpMin + pedl->dcpMac)
  1987. {
  1988. ScrollDownCtr( max( 1, dl ) );
  1989. TrashWw(wwCur);
  1990. UpdateWw(wwCur, false);
  1991. }
  1992. /* If cp is on bottom dl of the window and the dl is split by the
  1993. split bar, scroll down in doc by one line, to make insertion point
  1994. completely visible */
  1995. else if (cp >= pedl->cpMin & pedl->yp > ypMac)
  1996. {
  1997. ScrollDownCtr( 1 );
  1998. TrashWw(wwCur);
  1999. UpdateWw(wwCur,false);
  2000. }
  2001. }
  2002. }
  2003. #ifndef NOLA /* no look ahead */
  2004. BOOL (NEAR FAbort())
  2005. {
  2006. MSG msg;
  2007. register WORD vk_key;
  2008. register HANDLE hwndMsg;
  2009. HANDLE hwndPeek = (vhWndMsgBoxParent) ? vhWndMsgBoxParent : hParentWw;
  2010. if (PeekMessage((LPMSG)&msg, (HANDLE)NULL, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE))
  2011. {
  2012. hwndMsg = msg.hwnd;
  2013. if ((hwndPeek == (HANDLE)GetWindowWord(hwndMsg, GWW_HWNDPARENT)) ||
  2014. (hwndMsg == hwndPeek))
  2015. {
  2016. #ifdef DBCS
  2017. // It can be true at DBCS that WM_CHAR is the last message.
  2018. //
  2019. PeekMessage((LPMSG)&msg, hwndMsg, WM_KEYFIRST,WM_KEYLAST,PM_REMOVE);
  2020. #else
  2021. GetMessage((LPMSG)&msg, hwndMsg, WM_KEYFIRST, WM_KEYLAST);
  2022. #endif
  2023. if (msg.message == WM_KEYDOWN &&
  2024. (((vk_key = msg.wParam) == VK_ESCAPE) || (vk_key == VK_CANCEL)))
  2025. {
  2026. while (true)
  2027. {
  2028. GetMessage((LPMSG)&msg, hwndMsg, WM_KEYFIRST, WM_KEYLAST);
  2029. if (msg.message == WM_KEYUP && msg.wParam == vk_key)
  2030. return(TRUE);
  2031. }
  2032. }
  2033. else if (msg.message >= WM_SYSKEYDOWN && msg.message <= WM_SYSDEADCHAR)
  2034. DispatchMessage((LPMSG)&msg);
  2035. }
  2036. }
  2037. return(FALSE);
  2038. } /* end of FAbort */
  2039. #endif /* NOLA */
  2040. BOOL (NEAR FWordCp(cp, dcp))
  2041. typeCP cp;
  2042. typeCP dcp;
  2043. {
  2044. /* sees if the word starting at cp (with dcp chars) is a separate
  2045. word. */
  2046. int ich;
  2047. /* check the start of the word */
  2048. if(cp != cp0)
  2049. {
  2050. int wbPrev;
  2051. int wbStart;
  2052. FetchCp(docCur,cp-1,0,fcmChars + fcmNoExpand);
  2053. ich = 0;
  2054. wbPrev = WbFromCh(vpchFetch[ich]);
  2055. if(vcpFetch+vccpFetch <= cp)
  2056. {
  2057. FetchCp(docCur,cp,0,fcmChars + fcmNoExpand);
  2058. ich = 0;
  2059. }
  2060. else
  2061. ich++;
  2062. #ifdef DBCS /* was in JAPAN; KenjiK '90-12-20 */
  2063. #ifndef KOREA
  2064. /* word break is meanless. */
  2065. if(!IsDBCSLeadByte(vpchFetch[ich]))
  2066. #endif
  2067. #endif
  2068. if(wbPrev == (wbStart = WbFromCh(vpchFetch[ich])))
  2069. {
  2070. if (wbPrev != wbWhite && wbStart != wbWhite)
  2071. return(false);
  2072. }
  2073. }
  2074. /* check the end of the word */
  2075. if(cp+dcp-1 != cp0)
  2076. {
  2077. int wbEnd;
  2078. int wbLim;
  2079. if(vcpFetch+vccpFetch <= cp+dcp-1 || vcpFetch > cp+dcp-1)
  2080. {
  2081. FetchCp(docCur,cp+dcp-1,0,fcmChars + fcmNoExpand);
  2082. ich = 0;
  2083. }
  2084. else
  2085. ich = (dcp-1) - (vcpFetch-cp);
  2086. wbEnd = WbFromCh(vpchFetch[ich]);
  2087. if(vcpFetch+vccpFetch <= cp+dcp)
  2088. {
  2089. FetchCp(docCur,cp+dcp,0,fcmChars + fcmNoExpand);
  2090. ich = 0;
  2091. }
  2092. else
  2093. ich++;
  2094. #ifdef DBCS /* was in JAPAN; KenjiK '90-12-20 */
  2095. #ifndef KOREA
  2096. /* word break is meanless. */
  2097. if(!IsDBCSLeadByte(vpchFetch[ich]))
  2098. #endif
  2099. #endif
  2100. if(vccpFetch != 0 && (wbEnd == (wbLim = WbFromCh(vpchFetch[ich]))))
  2101. {
  2102. if (wbEnd != wbWhite && wbLim != wbWhite)
  2103. return(false);
  2104. }
  2105. }
  2106. return(true);
  2107. }
  2108. BOOL (NEAR FChMatch(ch, pichPat, fFwd))
  2109. int ch;
  2110. int *pichPat;
  2111. BOOL fFwd;
  2112. {
  2113. int ich = *pichPat;
  2114. int chSearch = szSearch[ich];
  2115. BOOL fPrefixed = false;
  2116. BOOL fMatched = false;
  2117. #ifdef DEBUG
  2118. Assert(fSpecialMatch);
  2119. #endif /*DEBUG*/
  2120. #ifdef DBCS
  2121. Assert(fFwd);
  2122. cbLastMatch = 1; /* Unless DBCS space. */
  2123. #endif
  2124. /* NOTE: this is just ChLower() brought in-line for speed */
  2125. #ifdef DBCS
  2126. // No need to make lower char for DBCS second byte
  2127. if(!fDBCS && !fSearchCase && ch >= 'A' && ch <= 'Z' )
  2128. #else
  2129. if(!fSearchCase && ch >= 'A' && ch <= 'Z' )
  2130. #endif
  2131. ch += 'a' - 'A';
  2132. if(!fFwd && ich > 0 && szSearch[ich-1] == chPrefixMatch)
  2133. /* see if the char is prefixed by a chPrefixMatch */
  2134. {
  2135. chSearch = chPrefixMatch;
  2136. --ich;
  2137. }
  2138. for(;;)
  2139. {
  2140. switch(chSearch)
  2141. {
  2142. default:
  2143. //#ifdef JAPAN
  2144. #if defined(JAPAN) || defined(KOREA)
  2145. if(IsDBCSLeadByte(chSearch))
  2146. cbLastMatch = 2;
  2147. #endif
  2148. if(ch == chSearch)
  2149. goto GoodMatch;
  2150. else if(ch == chReturn || ch == chNRHFile)
  2151. goto EasyMatch;
  2152. break;
  2153. case chSpace:
  2154. if(ch == chSpace || ch == chNBSFile)
  2155. goto GoodMatch;
  2156. break;
  2157. case chHyphen:
  2158. if(ch == chHyphen || ch == chNRHFile || ch == chNBH)
  2159. goto GoodMatch;
  2160. break;
  2161. case chMatchAny:
  2162. if(ch == chReturn || ch == chNRHFile)
  2163. goto EasyMatch;
  2164. if(!fPrefixed || ch == chMatchAny)
  2165. goto GoodMatch;
  2166. break;
  2167. case chPrefixMatch:
  2168. if(fPrefixed)
  2169. {
  2170. if(ch == chPrefixMatch)
  2171. goto GoodMatch;
  2172. else
  2173. break;
  2174. }
  2175. else
  2176. {
  2177. chSearch = szSearch[ich+1];
  2178. if(fFwd)
  2179. ++ich;
  2180. fPrefixed = true;
  2181. switch(chSearch)
  2182. {
  2183. default:
  2184. continue;
  2185. case chMatchEol:
  2186. chSearch = chEol;
  2187. continue;
  2188. case chMatchTab:
  2189. chSearch = chTab;
  2190. continue;
  2191. case chMatchWhite:
  2192. switch(ch)
  2193. {
  2194. default:
  2195. #ifdef DBCS
  2196. lblNonWhite:
  2197. #endif
  2198. if(fMatchedWhite)
  2199. {
  2200. if(fFwd)
  2201. {
  2202. if(szSearch[++ich] =='\0')
  2203. {
  2204. *pichPat = ich;
  2205. goto EasyMatch;
  2206. }
  2207. }
  2208. else
  2209. {
  2210. ich -= 1;
  2211. if(ich < 0)
  2212. {
  2213. *pichPat = ich;
  2214. goto EasyMatch;
  2215. }
  2216. }
  2217. *pichPat = ich;
  2218. fMatchedWhite = false;
  2219. chSearch = szSearch[ich];
  2220. continue;
  2221. }
  2222. break;
  2223. case chSpace:
  2224. case chReturn:
  2225. case chEol:
  2226. case chTab:
  2227. case chNBSFile:
  2228. case chNewLine:
  2229. case chSect:
  2230. fMatchedWhite = true;
  2231. goto EasyMatch;
  2232. }
  2233. break;
  2234. case chMatchNBSFile:
  2235. chSearch = chNBSFile;
  2236. continue;
  2237. case chMatchNewLine:
  2238. chSearch = chNewLine;
  2239. continue;
  2240. case chMatchNRHFile:
  2241. chSearch = chNRHFile;
  2242. continue;
  2243. case chMatchSect:
  2244. chSearch = chSect;
  2245. continue;
  2246. }
  2247. }
  2248. break;
  2249. }
  2250. fMatchedWhite = false;
  2251. return false;
  2252. }
  2253. GoodMatch:
  2254. *pichPat = ich + ((fFwd) ? 1 : (-1));
  2255. EasyMatch:
  2256. return true;
  2257. }
  2258. /* I N S E R T P A P S F O R R E P L A C E */
  2259. /* do AddRunScratch for every distinct paragraph in hszCaseReplace */
  2260. /* This is only needed when hszCaseReplace contains one or more chEols */
  2261. NEAR InsertPapsForReplace(fc)
  2262. typeFC fc;
  2263. {
  2264. int cchInsTotal = 0;
  2265. CHAR *pchTail;
  2266. CHAR *pchHead;
  2267. for(;;)
  2268. {
  2269. int cch;
  2270. pchHead = **hszCaseReplace + cchInsTotal;
  2271. pchTail = (CHAR *)index(pchHead, chEol);
  2272. if (pchTail == 0) return;
  2273. cch = pchTail - pchHead + 1; /* cch is count including chEol */
  2274. fc += cch;
  2275. cchInsTotal += cch;
  2276. AddRunScratch(&vfkpdParaIns, &vpapAbs, vppapNormal,
  2277. FParaEq(&vpapAbs, &vpapPrevIns) && vfkpdParaIns.brun != 0 ? -cchPAP : cchPAP,
  2278. fcMacPapIns = fc);
  2279. blt(&vpapAbs, &vpapPrevIns, cwPAP);
  2280. }
  2281. }
  2282. NEAR FDlgSzTooLong(hDlg, idi, pch, cchMax)
  2283. HWND hDlg;
  2284. int idi;
  2285. CHAR *pch;
  2286. int cchMax;
  2287. {
  2288. int cchGet = GetDlgItemText(hDlg, idi, (LPSTR)pch, cchMax);
  2289. *(pch+cchMax-2) = '\0'; /* just in case the string is too long */
  2290. if (cchGet > (cchMax - 2))
  2291. return(TRUE);
  2292. else
  2293. return(FALSE);
  2294. }
  2295. NEAR idiMsgResponse(hDlg, idi, idpmt)
  2296. HWND hDlg;
  2297. int idi;
  2298. int idpmt;
  2299. {
  2300. CHAR szT[cchMaxSz];
  2301. PchFillPchId(szT, idpmt, sizeof(szT));
  2302. SetFocus(GetDlgItem(hDlg, idi));
  2303. SendDlgItemMessage(hDlg, idi, EM_SETSEL, (WORD)NULL, MAKELONG(255, 32767));
  2304. return(IdPromptBoxSz(hDlg, szT, MB_OKCANCEL | MB_ICONASTERISK));
  2305. }
  2306. PostStatusInCaption(idstr)
  2307. int idstr;
  2308. {
  2309. extern HWND hParentWw;
  2310. extern CHAR szCaptionSave[];
  2311. CHAR *pchCaption = &szCaptionSave[0];
  2312. CHAR *pchLast;
  2313. int cch;
  2314. CHAR szT[256];
  2315. if (idstr == NULL)
  2316. {
  2317. /* restore the caption */
  2318. SetWindowText(hParentWw, (LPSTR)pchCaption);
  2319. }
  2320. else
  2321. {
  2322. /* save caption */
  2323. GetWindowText(hParentWw, (LPSTR)pchCaption, cchMaxFile);
  2324. /* append status message after app name */
  2325. #ifndef INTL
  2326. pchLast = pchCaption + CchSz(pchCaption) - 1;
  2327. while (pchLast-- > pchCaption)
  2328. {
  2329. if (*pchLast == ' ')
  2330. break;
  2331. }
  2332. PchFillPchId(bltbyte(pchCaption, szT, (cch = pchLast - pchCaption + 1)),
  2333. IDSTRSearching, 13);
  2334. #else
  2335. pchLast = pchCaption + CchSz(szAppName) + CchSz(szSepName) - 2;
  2336. PchFillPchId(bltbyte(pchCaption, szT, (cch = pchLast - pchCaption)),
  2337. IDSTRSearching, 13);
  2338. #endif
  2339. SetWindowText(hParentWw, (LPSTR)szT);
  2340. }
  2341. }
  2342. #if defined(JAPAN) || defined(KOREA) /*t-Yoshio*/
  2343. BOOL (NEAR J_FChMatch(ch, chNext, pichPat, pichDoc))
  2344. CHAR ch;
  2345. CHAR chNext;
  2346. int *pichPat;
  2347. int *pichDoc;
  2348. {
  2349. int ich = *pichPat;
  2350. CHAR chSearch = szSearch[ich];
  2351. CHAR chSearchNext = szSearch[ich+1];
  2352. WORD dchSearch;
  2353. BOOL fPrefixed = false;
  2354. if(!fSearchCase ) {
  2355. #ifdef JANPAN
  2356. if(ch == 0x82 && chNext >= 0x60 && chNext <= 0x79 )
  2357. chNext = 0x21 + chNext;
  2358. #else
  2359. if(ch == 0xA3 && (chNext >= 0xC1 && chNext <= 0xDA))
  2360. chNext = 0x20 + chNext;
  2361. #endif
  2362. else if( ch >= 'A' && ch <= 'Z' )
  2363. ch += 'a' - 'A';
  2364. }
  2365. for(;;) {
  2366. if( chSearch == chPrefixMatch ) {
  2367. if(fPrefixed) {
  2368. if(ch == chPrefixMatch) {
  2369. *pichPat = ich + 1;
  2370. return true;
  2371. }
  2372. break;
  2373. }
  2374. chSearch = chSearchNext;
  2375. ich++;
  2376. if(IsDBCSLeadByte(chSearch)) {
  2377. chSearchNext = szSearch[ich+1];
  2378. continue;
  2379. }
  2380. fPrefixed = true;
  2381. switch(chSearch)
  2382. {
  2383. default:
  2384. continue;
  2385. case chMatchEol:
  2386. chSearch = chEol;
  2387. break;
  2388. case chMatchTab:
  2389. chSearch = chTab;
  2390. break;
  2391. case chMatchNBSFile:
  2392. chSearch = chNBSFile;
  2393. break;
  2394. case chMatchNewLine:
  2395. chSearch = chNewLine;
  2396. break;
  2397. case chMatchNRHFile:
  2398. chSearch = chNRHFile;
  2399. break;
  2400. case chMatchSect:
  2401. chSearch = chSect;
  2402. break;
  2403. case chMatchWhite:
  2404. if(IsDBCSLeadByte((BYTE)ch)) {
  2405. #if defined(JAPAN)
  2406. if(ch == 0x81 && chNext == 0x40) {
  2407. #else
  2408. if(!fSearchDist && (ch == 0xA1 && chNext == 0xA1)) {
  2409. #endif
  2410. fMatchedWhite = true;
  2411. return true;
  2412. }
  2413. }
  2414. else if( ch == chSpace || ch == chReturn || ch == chEol ||
  2415. ch == chNBSFile || ch == chTab || ch == chNewLine || ch == chSect )
  2416. {
  2417. fMatchedWhite = true;
  2418. return true;
  2419. }
  2420. if(fMatchedWhite) {
  2421. if(szSearch[ich+1] =='\0') {
  2422. *pichPat = ich + 1;
  2423. return true;
  2424. }
  2425. *pichPat = ich++;
  2426. fMatchedWhite = false;
  2427. chSearch = szSearch[ich];
  2428. chSearchNext = szSearch[ich+1];
  2429. break;
  2430. }
  2431. #ifdef KOREA
  2432. fMatchedWhite = false;
  2433. return false;
  2434. #else
  2435. break;
  2436. #endif
  2437. }
  2438. }
  2439. if( chSearch == chMatchAny ) {
  2440. if(ch == chReturn || ch == chNRHFile)
  2441. return true;
  2442. if(!fPrefixed || ch == chMatchAny) {
  2443. *pichPat = ich + 1;
  2444. return true;
  2445. }
  2446. break;
  2447. }
  2448. if(chSearch == chSpace ) {
  2449. if(ch == chSpace || ch == chNBSFile || (ch == 0x81 && chNext == 0x40)) {
  2450. *pichPat = ich + 1;
  2451. return true;
  2452. }
  2453. break;
  2454. }
  2455. if(chSearch == chHyphen ) {
  2456. if(ch == chHyphen || ch == chNRHFile || ch == chNBH) {
  2457. *pichPat = ich + 1;
  2458. return true;
  2459. }
  2460. break;
  2461. }
  2462. if(!fSearchDist)
  2463. {
  2464. CHAR Doc[3];
  2465. CHAR Pat[3];
  2466. CHAR tmp[3];
  2467. Doc[0] = Doc[1] = Doc[2] = '\0';
  2468. Pat[0] = Pat[1] = Pat[2] = '\0';
  2469. if(IsDBCSLeadByte((WORD)chSearch)) {
  2470. Pat[0] = chSearch;
  2471. Pat[1] = chSearchNext;
  2472. ich += 2;
  2473. }
  2474. else {
  2475. tmp[0] = chSearch;
  2476. tmp[1] = tmp[2] = '\0';
  2477. if(chSearch >= 0xca && chSearch <= 0xce) {
  2478. if(chSearchNext == 0xde || chSearchNext == 0xdf ) {
  2479. tmp[1] = chNext;
  2480. ich += 1;
  2481. }
  2482. }
  2483. else if(chSearch >= 0xa6 && chSearch <= 0xc4) {
  2484. if(chSearchNext == 0xde ) {
  2485. tmp[1] = chNext;
  2486. ich += 1;
  2487. }
  2488. }
  2489. ich += 1;
  2490. myHantoZen(tmp,Pat,3);
  2491. }
  2492. if(IsDBCSLeadByte((BYTE)ch))
  2493. {
  2494. if(Pat[0] == ch && Pat[1] == chNext)
  2495. {
  2496. *pichPat = ich;
  2497. return true;
  2498. }
  2499. else
  2500. return false;
  2501. }
  2502. else {
  2503. tmp[0] = ch;
  2504. if(ch >= 0xca && ch <= 0xce) {
  2505. if(myIsSonant(Pat[0],Pat[1]) && chNext == 0xde || chNext == 0xdf ) {
  2506. tmp[1] = chNext;
  2507. cbLastMatch = 2;
  2508. *pichDoc++;
  2509. }
  2510. }
  2511. else if(ch >= 0xa6 && ch <= 0xc4) {
  2512. if(!myIsSonant(Pat[0],Pat[1]) && chNext == 0xde ) {
  2513. tmp[1] = chNext;
  2514. cbLastMatch = 2;
  2515. *pichDoc++;
  2516. }
  2517. }
  2518. myHantoZen(tmp,Doc,3);
  2519. if(Pat[0] == Doc[0] && Pat[1] == Doc[1])
  2520. {
  2521. *pichPat = ich;
  2522. return true;
  2523. }
  2524. else if(ch == chReturn || ch == chNRHFile)
  2525. return true;
  2526. else
  2527. return false;
  2528. }
  2529. return false;
  2530. }
  2531. if( chSearch == ch) {
  2532. if(IsDBCSLeadByte((BYTE)ch)) {
  2533. if(chSearchNext == chNext) {
  2534. *pichPat = ich + 2;
  2535. return true;
  2536. }
  2537. else
  2538. return false;
  2539. }
  2540. *pichPat = ich + 1;
  2541. return true;
  2542. }
  2543. else if(ch == chReturn || ch == chNRHFile)
  2544. return true;
  2545. break;
  2546. }
  2547. /*UnMatched*/
  2548. fMatchedWhite = false;
  2549. return false;
  2550. }
  2551. #endif