SCANUTIL.LST 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  1. Listing:
  2. 1 IMPLEMENTATION MODULE ScanUtils;
  3. 2 (*
  4. 3 * REPERTOIRE
  5. 4 * Release 1.6
  6. 5 * By Charles Bradford and Cole Brecheen
  7. 6 * (c) Copyright 1985-1992 PMI
  8. 7 * Green Bay, Wisconsin
  9. 8 * All rights reserved
  10. 9 * (414) 468-6040
  11. 10 *
  12. 11 * $Header: D:/logfiles/mods/scanutil.mov 1.2 17 Mar 1991 17:56:48 coleb $
  13. 12 *
  14. 13 *)
  15. 14
  16. 15
  17. 16
  18. 17 IMPORT LowLevel;
  19. 18 IMPORT M2Strings;
  20. 19 IMPORT Numbers;
  21. 20 IMPORT StrEdit;
  22. 21 IMPORT SYSTEM;
  23. 22
  24. 23 VAR
  25. 24 Initialized : BOOLEAN;
  26. 25
  27. 26 PROCEDURE Init();
  28. 27 BEGIN
  29. 28 IF Initialized THEN
  30. 29 RETURN;
  31. 30 ELSE
  32. 31 Initialized := TRUE;
  33. 32 END;
  34. 33 LowLevel.Init();
  35. ***** ^ not supported yet
  36. ***** ^ not supported yet
  37. ***** ^ not supported yet
  38. 34 M2Strings.Init();
  39. ***** ^ not supported yet
  40. ***** ^ not supported yet
  41. ***** ^ not supported yet
  42. 35 Numbers.Init();
  43. ***** ^ not supported yet
  44. ***** ^ not supported yet
  45. ***** ^ not supported yet
  46. 36 StrEdit.Init();
  47. ***** ^ not supported yet
  48. ***** ^ not supported yet
  49. ***** ^ not supported yet
  50. 37 END Init;
  51. ***** ^ not supported yet
  52. 38
  53. 39
  54. 40 CONST
  55. 41 space = ' ';
  56. 42 tab = CHAR(9);
  57. ***** ^ not supported yet
  58. 43
  59. 44
  60. 45 PROCEDURE ScanForByte(size : INTEGER; lookfor : SYSTEM.BYTE;
  61. ***** ^ not supported yet
  62. 46 start : SYSTEM.ADDRESS; caseMatters: CaseSensitivity ) : INTEGER;
  63. ***** ^ not supported yet
  64. ***** ^ undeclared identifier
  65. 47 VAR
  66. 48 cnt: INTEGER;
  67. 49 tmpAdr: LowLevel.Address8086;
  68. ***** ^ not supported yet
  69. 50 BEGIN
  70. 51 tmpAdr.x := start;
  71. ***** ^ not supported yet
  72. ***** ^ not supported yet
  73. ***** ^ not supported yet
  74. 52 IF size < 0 THEN
  75. 53 FOR cnt := 0 TO ABS(size + 1) DO
  76. ***** ^ undeclared identifier
  77. ***** ^ not supported yet
  78. 54 IF caseMatters = CaseInsens THEN
  79. ***** ^ not supported yet
  80. ***** ^ undeclared identifier
  81. 55 IF CAP(CHAR(lookfor)) = CAP(tmpAdr.b^) THEN
  82. ***** ^ undeclared identifier
  83. ***** ^ not supported yet
  84. ***** ^ undeclared identifier
  85. ***** ^ not supported yet
  86. ***** ^ not supported yet
  87. 56 RETURN cnt;
  88. 57 END;
  89. 58 ELSE
  90. 59 IF CHAR(lookfor) = tmpAdr.b^ THEN
  91. ***** ^ not supported yet
  92. ***** ^ not supported yet
  93. ***** ^ not supported yet
  94. 60 RETURN cnt;
  95. 61 END;
  96. 62 END;
  97. 63 DEC(tmpAdr.off);
  98. ***** ^ undeclared identifier
  99. ***** ^ not supported yet
  100. ***** ^ not supported yet
  101. 64 END;
  102. 65 ELSIF size > 0 THEN
  103. 66 FOR cnt := 0 TO (size - 1) DO
  104. 67 IF caseMatters = CaseInsens THEN
  105. ***** ^ not supported yet
  106. ***** ^ undeclared identifier
  107. 68 IF CAP(CHAR(lookfor)) = CAP(tmpAdr.b^) THEN
  108. ***** ^ undeclared identifier
  109. ***** ^ not supported yet
  110. ***** ^ undeclared identifier
  111. ***** ^ not supported yet
  112. ***** ^ not supported yet
  113. 69 RETURN cnt;
  114. 70 END;
  115. 71 ELSE
  116. 72 IF CHAR(lookfor) = tmpAdr.b^ THEN
  117. ***** ^ not supported yet
  118. ***** ^ not supported yet
  119. ***** ^ not supported yet
  120. 73 RETURN cnt;
  121. 74 END;
  122. 75 END;
  123. 76 INC(tmpAdr.off);
  124. ***** ^ undeclared identifier
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. 77 END;
  128. 78 END;
  129. 79 RETURN size;
  130. 80 END ScanForByte;
  131. ***** ^ not supported yet
  132. 81
  133. 82
  134. 83 PROCEDURE BreakPoint(VAR thestr : ARRAY OF CHAR; maxlength : CARDINAL;
  135. ***** ^ not supported yet
  136. 84 breakchars : ARRAY OF CHAR) : CARDINAL;
  137. ***** ^ not supported yet
  138. 85 VAR
  139. 86 cnt : CARDINAL;
  140. 87 BEGIN
  141. 88 cnt := maxlength-1;
  142. 89 WHILE (cnt>0) AND
  143. 90 (Pos(thestr[cnt], breakchars, CaseSens) > HIGH(breakchars)) DO
  144. ***** ^ undeclared identifier
  145. ***** ^ not supported yet
  146. ***** ^ not supported yet
  147. ***** ^ not supported yet
  148. ***** ^ undeclared identifier
  149. ***** ^ undeclared identifier
  150. ***** ^ not supported yet
  151. 91 DEC(cnt);
  152. ***** ^ undeclared identifier
  153. ***** ^ not supported yet
  154. 92 END;
  155. 93 IF (cnt=0) AND
  156. 94 (Pos(thestr[0], breakchars, CaseSens) > HIGH(breakchars)) THEN
  157. ***** ^ undeclared identifier
  158. ***** ^ not supported yet
  159. ***** ^ not supported yet
  160. ***** ^ not supported yet
  161. ***** ^ undeclared identifier
  162. ***** ^ undeclared identifier
  163. ***** ^ not supported yet
  164. 95 RETURN (maxlength);
  165. 96 ELSE
  166. 97 RETURN (cnt);
  167. 98 END;
  168. 99 END BreakPoint;
  169. ***** ^ not supported yet
  170. 100
  171. 101
  172. 102 PROCEDURE BreakPtAdr( TheAdr: SYSTEM.ADDRESS; TheSize: CARDINAL;
  173. ***** ^ not supported yet
  174. 103 maxlength : CARDINAL; breakchars : ARRAY OF CHAR) :
  175. ***** ^ not supported yet
  176. 104 CARDINAL;
  177. 105 VAR
  178. 106 cnt : CARDINAL;
  179. 107 tmp : LowLevel.Address8086;
  180. ***** ^ not supported yet
  181. 108 BEGIN
  182. 109 cnt := maxlength-1;
  183. 110 tmp.a := TheAdr;
  184. ***** ^ not supported yet
  185. ***** ^ not supported yet
  186. ***** ^ not supported yet
  187. 111 INC( tmp.off, cnt );
  188. ***** ^ undeclared identifier
  189. ***** ^ not supported yet
  190. ***** ^ not supported yet
  191. ***** ^ not supported yet
  192. 112 WHILE (cnt>0) AND (NOT Present(tmp.b^, breakchars, CaseSens)) DO
  193. ***** ^ undeclared identifier
  194. ***** ^ not supported yet
  195. ***** ^ not supported yet
  196. ***** ^ not supported yet
  197. ***** ^ undeclared identifier
  198. 113 DEC( tmp.off );
  199. ***** ^ undeclared identifier
  200. ***** ^ not supported yet
  201. ***** ^ not supported yet
  202. 114 DEC(cnt);
  203. ***** ^ undeclared identifier
  204. ***** ^ not supported yet
  205. 115 END;
  206. 116 IF (cnt=0) AND (NOT Present(tmp.b^, breakchars, CaseSens)) THEN
  207. ***** ^ undeclared identifier
  208. ***** ^ not supported yet
  209. ***** ^ not supported yet
  210. ***** ^ not supported yet
  211. ***** ^ undeclared identifier
  212. 117 RETURN maxlength;
  213. 118 ELSE
  214. 119 RETURN cnt;
  215. 120 END;
  216. 121 END BreakPtAdr;
  217. ***** ^ not supported yet
  218. 122
  219. 123
  220. 124 PROCEDURE ByteCount( size: CARDINAL; lookfor: CHAR; start:
  221. 125 SYSTEM.ADDRESS): CARDINAL;
  222. ***** ^ not supported yet
  223. 126 VAR
  224. 127 cnt, offset, skipped: CARDINAL;
  225. 128 BEGIN
  226. 129 cnt := 0;
  227. 130 offset := 0;
  228. 131 WHILE offset < size DO
  229. 132 skipped := LowLevel.ScanEQ( size - offset, lookfor,
  230. ***** ^ not supported yet
  231. ***** ^ not supported yet
  232. 133 LowLevel.AddAddr(start, offset) );
  233. ***** ^ not supported yet
  234. ***** ^ not supported yet
  235. ***** ^ not supported yet
  236. ***** ^ not supported yet
  237. 134 IF skipped < (size - offset) THEN
  238. 135 INC( cnt );
  239. ***** ^ undeclared identifier
  240. ***** ^ not supported yet
  241. 136 INC( offset, skipped + 1 );
  242. ***** ^ undeclared identifier
  243. ***** ^ not supported yet
  244. 137 ELSE
  245. 138 RETURN cnt;
  246. 139 END;
  247. 140 END;
  248. 141 RETURN cnt;
  249. 142 END ByteCount;
  250. ***** ^ not supported yet
  251. 143
  252. 144
  253. 145 PROCEDURE Equal( str1, str2: ARRAY OF CHAR;
  254. ***** ^ not supported yet
  255. 146 caseMatters: CaseSensitivity ): BOOLEAN;
  256. ***** ^ undeclared identifier
  257. 147 BEGIN
  258. 148 IF caseMatters = CaseInsens THEN
  259. ***** ^ not supported yet
  260. ***** ^ undeclared identifier
  261. 149 StrEdit.CAPstr(str1);
  262. ***** ^ not supported yet
  263. ***** ^ not supported yet
  264. ***** ^ not supported yet
  265. 150 StrEdit.CAPstr(str2);
  266. ***** ^ not supported yet
  267. ***** ^ not supported yet
  268. ***** ^ not supported yet
  269. 151 END;
  270. 152 RETURN M2Strings.CompareStr(str1, str2) = 0;
  271. ***** ^ not supported yet
  272. ***** ^ not supported yet
  273. ***** ^ not supported yet
  274. ***** ^ not supported yet
  275. 153 END Equal;
  276. ***** ^ not supported yet
  277. 154
  278. 155
  279. 156 PROCEDURE FindNthPattern(pattern: ARRAY OF CHAR; which: CARDINAL;
  280. ***** ^ not supported yet
  281. 157 searchIn: ARRAY OF CHAR; caseMatters: CaseSensitivity ): CARDINAL;
  282. ***** ^ not supported yet
  283. ***** ^ undeclared identifier
  284. 158 VAR
  285. 159 cnt, lastSpot, inLngth: CARDINAL;
  286. 160 found : BOOLEAN;
  287. 161 BEGIN
  288. 162 found := FALSE;
  289. 163 lastSpot := 0;
  290. 164 cnt := 0;
  291. 165 inLngth := M2Strings.Length(searchIn);
  292. ***** ^ not supported yet
  293. ***** ^ not supported yet
  294. ***** ^ not supported yet
  295. 166 REPEAT
  296. 167 lastSpot := Positn(pattern, searchIn, lastSpot, caseMatters);
  297. ***** ^ undeclared identifier
  298. ***** ^ not supported yet
  299. ***** ^ not supported yet
  300. ***** ^ not supported yet
  301. 168 IF lastSpot >= inLngth THEN
  302. 169 cnt := which + 1;
  303. 170 ELSE
  304. 171 INC(cnt);
  305. ***** ^ undeclared identifier
  306. ***** ^ not supported yet
  307. 172 END;
  308. 173 IF cnt = which THEN
  309. 174 found := TRUE;
  310. 175 END;
  311. 176 UNTIL found OR (cnt > which);
  312. 177 IF cnt > which THEN
  313. 178 RETURN(65535);
  314. 179 ELSE
  315. 180 RETURN(lastSpot);
  316. 181 END;
  317. 182 END FindNthPattern;
  318. ***** ^ not supported yet
  319. 183
  320. 184
  321. 185 PROCEDURE FirstNonMatching(TheChar : CHAR; VAR TheStr : ARRAY OF CHAR) :
  322. ***** ^ not supported yet
  323. 186 CHAR;
  324. 187 (* Returns the first character in TheStr that does not match
  325. 188 TheChar. If none found, returns TheChar. *)
  326. 189 VAR
  327. 190 spot, leng : CARDINAL;
  328. 191 BEGIN
  329. 192 leng := M2Strings.Length(TheStr);
  330. ***** ^ not supported yet
  331. ***** ^ not supported yet
  332. ***** ^ not supported yet
  333. 193 IF leng = 0 THEN
  334. 194 RETURN TheChar;
  335. 195 END;
  336. 196 spot := LowLevel.ScanNE( leng, TheChar, SYSTEM.ADR(TheStr) );
  337. ***** ^ not supported yet
  338. ***** ^ not supported yet
  339. ***** ^ not supported yet
  340. ***** ^ not supported yet
  341. ***** ^ not supported yet
  342. 197 IF spot < leng THEN
  343. 198 RETURN TheStr[spot];
  344. ***** ^ not supported yet
  345. ***** ^ not supported yet
  346. 199 ELSE
  347. 200 RETURN TheChar;
  348. 201 END;
  349. 202 END FirstNonMatching;
  350. ***** ^ not supported yet
  351. 203
  352. 204
  353. 205 PROCEDURE IsAlphaChar( TheChar: CHAR ): BOOLEAN;
  354. 206 BEGIN
  355. 207 RETURN ((TheChar >= 'a') AND (TheChar <= 'z')) OR ((TheChar
  356. 208 >= 'A') AND (TheChar <= 'Z'));
  357. 209 END IsAlphaChar;
  358. ***** ^ not supported yet
  359. 210
  360. 211
  361. 212 PROCEDURE IsBlank(TheStr : ARRAY OF CHAR) : BOOLEAN;
  362. ***** ^ not supported yet
  363. 213 (*TRUE if thestr is all blanks *)
  364. 214 VAR
  365. 215 answer, leng : CARDINAL;
  366. 216 BEGIN
  367. 217 leng := M2Strings.Length(TheStr);
  368. ***** ^ not supported yet
  369. ***** ^ not supported yet
  370. ***** ^ not supported yet
  371. 218 IF leng=0 THEN
  372. 219 RETURN TRUE;
  373. 220 END;
  374. 221 answer := LowLevel.ScanNE(leng,space,SYSTEM.ADR(TheStr));
  375. ***** ^ not supported yet
  376. ***** ^ not supported yet
  377. ***** ^ not supported yet
  378. ***** ^ not supported yet
  379. ***** ^ not supported yet
  380. 222 RETURN (answer>=leng);
  381. 223 END IsBlank;
  382. ***** ^ not supported yet
  383. 224
  384. 225
  385. 226 PROCEDURE IsNextPattern( Pattern: ARRAY OF CHAR; VAR TheStr:
  386. ***** ^ not supported yet
  387. 227 ARRAY OF CHAR; StartingSpot: CARDINAL;
  388. ***** ^ not supported yet
  389. 228 caseMatters: CaseSensitivity ): BOOLEAN;
  390. ***** ^ undeclared identifier
  391. 229 VAR
  392. 230 tmp, cnt: CARDINAL;
  393. 231 lngth: INTEGER;
  394. 232 tmpadr: LowLevel.Address8086;
  395. ***** ^ not supported yet
  396. 233 result: BOOLEAN;
  397. 234 BEGIN
  398. 235 lngth := INTEGER(M2Strings.Length(TheStr)) - INTEGER(StartingSpot);
  399. ***** ^ not supported yet
  400. ***** ^ not supported yet
  401. ***** ^ not supported yet
  402. ***** ^ not supported yet
  403. 236 (* Don't bother looking if the StartingSpot is greater than the
  404. 237 length of the string. *)
  405. 238 IF lngth < 0 THEN
  406. 239 RETURN FALSE;
  407. 240 END;
  408. 241 tmp := PosAdr( Pattern, LowLevel.AddAddr( SYSTEM.ADR(TheStr),
  409. ***** ^ undeclared identifier
  410. ***** ^ not supported yet
  411. ***** ^ not supported yet
  412. ***** ^ not supported yet
  413. ***** ^ not supported yet
  414. ***** ^ not supported yet
  415. ***** ^ not supported yet
  416. 242 StartingSpot), CARDINAL(lngth), caseMatters );
  417. ***** ^ not supported yet
  418. ***** ^ not supported yet
  419. ***** ^ not supported yet
  420. 243 (* Figure out where Pattern appears, if at all. *)
  421. 244 IF tmp = CARDINAL(lngth) THEN
  422. ***** ^ not supported yet
  423. 245 (* If it doesn't appear at all, return FALSE. *)
  424. 246 RETURN FALSE;
  425. 247 END;
  426. 248 (* tmp now represents the offset beyond StartingSpot at which
  427. 249 Pattern appears. We want to know if that's the same offset
  428. 250 as the first nonblank character beyond StartingSpot. *)
  429. 251 result := TRUE;
  430. 252 cnt := StartingSpot;
  431. 253 WHILE ((cnt < tmp) AND result) DO
  432. 254 IF (TheStr[cnt] # space) AND (TheStr[cnt] # tab) THEN
  433. ***** ^ not supported yet
  434. ***** ^ not supported yet
  435. ***** ^ not supported yet
  436. ***** ^ not supported yet
  437. 255 result := FALSE;
  438. 256 END;
  439. 257 INC(cnt);
  440. ***** ^ undeclared identifier
  441. ***** ^ not supported yet
  442. 258 END;
  443. 259 RETURN result;
  444. 260 END IsNextPattern;
  445. ***** ^ not supported yet
  446. 261
  447. 262
  448. 263 PROCEDURE IsNumber( TheStr: ARRAY OF CHAR; StartingSpot:
  449. ***** ^ not supported yet
  450. 264 CARDINAL ): BOOLEAN;
  451. 265 VAR
  452. 266 AllNumbers, PointFound, AtLeastOneFound : BOOLEAN;
  453. 267 EndStr, index : CARDINAL;
  454. 268 bufch : CHAR;
  455. 269 BEGIN
  456. 270 M2Strings.Delete( TheStr, 0, StartingSpot );
  457. ***** ^ not supported yet
  458. ***** ^ not supported yet
  459. ***** ^ not supported yet
  460. ***** ^ not supported yet
  461. 271 StrEdit.CrunchBlanks( TheStr );
  462. ***** ^ not supported yet
  463. ***** ^ not supported yet
  464. ***** ^ not supported yet
  465. 272 EndStr := M2Strings.Length(TheStr);
  466. ***** ^ not supported yet
  467. ***** ^ not supported yet
  468. ***** ^ not supported yet
  469. 273 IF (EndStr = 0) OR Present( space, TheStr, CaseSens ) THEN
  470. ***** ^ undeclared identifier
  471. ***** ^ not supported yet
  472. ***** ^ undeclared identifier
  473. 274 RETURN FALSE;
  474. 275 END;
  475. 276 DEC( EndStr );
  476. ***** ^ undeclared identifier
  477. ***** ^ not supported yet
  478. 277 index := 0;
  479. 278 AtLeastOneFound := FALSE;
  480. 279 PointFound := FALSE;
  481. 280 AllNumbers := TRUE;
  482. 281 REPEAT
  483. 282 bufch := TheStr[index];
  484. ***** ^ not supported yet
  485. ***** ^ not supported yet
  486. 283 IF IsNumericChar( bufch ) THEN
  487. ***** ^ undeclared identifier
  488. ***** ^ not supported yet
  489. 284 AtLeastOneFound := TRUE;
  490. 285 ELSIF (bufch = '-') OR (bufch = '+') THEN
  491. 286 IF NOT (index = 0) THEN
  492. 287 AllNumbers := FALSE;
  493. 288 END;
  494. 289 ELSIF bufch = '.' THEN
  495. 290 IF PointFound THEN
  496. 291 AllNumbers := FALSE;
  497. 292 ELSE
  498. 293 PointFound := TRUE;
  499. 294 END;
  500. 295 ELSE
  501. 296 AllNumbers := FALSE;
  502. 297 END;
  503. 298 INC( index );
  504. ***** ^ undeclared identifier
  505. ***** ^ not supported yet
  506. 299 UNTIL (NOT AllNumbers) OR (index > EndStr);
  507. 300 RETURN AtLeastOneFound AND AllNumbers;
  508. 301 END IsNumber;
  509. ***** ^ not supported yet
  510. 302
  511. 303
  512. 304 PROCEDURE IsNumericChar( TheChar: CHAR ): BOOLEAN;
  513. 305 BEGIN
  514. 306 RETURN (TheChar >= '0') AND (TheChar <= '9');
  515. 307 END IsNumericChar;
  516. ***** ^ not supported yet
  517. 308
  518. 309
  519. 310 PROCEDURE IsWhiteSpace( TheChar: CHAR ): BOOLEAN;
  520. 311 BEGIN
  521. 312 RETURN (TheChar = space) OR (TheChar = tab);
  522. 313 END IsWhiteSpace;
  523. ***** ^ not supported yet
  524. 314
  525. 315
  526. 316 PROCEDURE LastNonMatching(TheChar : CHAR; VAR TheStr
  527. 317 : ARRAY OF CHAR) : CHAR;
  528. ***** ^ not supported yet
  529. 318 (* Starts at the end of TheStr and searches backward for a
  530. 319 character that does not match TheChar. If none found,
  531. 320 returns TheChar. *)
  532. 321 VAR
  533. 322 spot: INTEGER;
  534. 323 BEGIN
  535. 324 spot := M2Strings.Length(TheStr);
  536. ***** ^ not supported yet
  537. ***** ^ not supported yet
  538. ***** ^ not supported yet
  539. 325 IF spot = 0 THEN
  540. 326 RETURN TheChar;
  541. 327 ELSE
  542. 328 DEC( spot );
  543. ***** ^ undeclared identifier
  544. ***** ^ not supported yet
  545. 329 END;
  546. 330 WHILE (TheStr[spot] = TheChar) AND (spot > 0) DO
  547. ***** ^ not supported yet
  548. ***** ^ not supported yet
  549. 331 DEC( spot );
  550. ***** ^ undeclared identifier
  551. ***** ^ not supported yet
  552. 332 END;
  553. 333 IF spot > 0 THEN
  554. 334 RETURN TheStr[spot];
  555. ***** ^ not supported yet
  556. ***** ^ not supported yet
  557. 335 ELSE
  558. 336 RETURN TheChar;
  559. 337 END;
  560. 338 END LastNonMatching;
  561. ***** ^ not supported yet
  562. 339
  563. 340
  564. 341 PROCEDURE MatchingPos( spot: CARDINAL; TheStr: ARRAY
  565. 342 OF CHAR ): CARDINAL;
  566. ***** ^ not supported yet
  567. 343 (*Returns the position of the ending character that matches
  568. 344 the beginning character at position spot within TheStr. If
  569. 345 TheStr does not have a valid beginning character at spot,
  570. 346 or if spot is not inside the present length of TheStr, or
  571. 347 if no matching ending character is found, MatchingPos
  572. 348 returns spot.*)
  573. 349 VAR
  574. 350 TmpSpot, StackCount, lngth : CARDINAL;
  575. 351 Opener, Closer, bufch: CHAR;
  576. 352 Openers, Closers: ARRAY [0..3] OF CHAR;
  577. ***** ^ not supported yet
  578. ***** ^ not supported yet
  579. 353 BEGIN
  580. 354 StrEdit.AssignStr( '[{(<', Openers );
  581. ***** ^ not supported yet
  582. ***** ^ not supported yet
  583. ***** ^ not supported yet
  584. ***** ^ not supported yet
  585. 355 StrEdit.AssignStr( ']})>', Closers );
  586. ***** ^ not supported yet
  587. ***** ^ not supported yet
  588. ***** ^ not supported yet
  589. ***** ^ not supported yet
  590. 356 lngth := M2Strings.Length( TheStr );
  591. ***** ^ not supported yet
  592. ***** ^ not supported yet
  593. ***** ^ not supported yet
  594. 357 IF spot >= lngth THEN
  595. 358 RETURN spot;
  596. 359 END;
  597. 360 bufch := TheStr[spot];
  598. ***** ^ not supported yet
  599. ***** ^ not supported yet
  600. 361 TmpSpot := LowLevel.ScanEQ(SYSTEM.SIZE(Openers), bufch,
  601. ***** ^ not supported yet
  602. ***** ^ not supported yet
  603. ***** ^ not supported yet
  604. ***** ^ not supported yet
  605. ***** ^ not supported yet
  606. 362 SYSTEM.ADR(Openers) );
  607. ***** ^ not supported yet
  608. ***** ^ not supported yet
  609. ***** ^ not supported yet
  610. 363 IF TmpSpot <= HIGH( Openers ) THEN
  611. ***** ^ undeclared identifier
  612. ***** ^ not supported yet
  613. 364 Opener := bufch;
  614. 365 Closer := Closers[ TmpSpot ];
  615. ***** ^ not supported yet
  616. ***** ^ not supported yet
  617. 366 TmpSpot := spot + 1;
  618. 367 StackCount := 0;
  619. 368 WHILE TmpSpot < lngth DO
  620. 369 IF TheStr[ TmpSpot ] = Opener THEN
  621. ***** ^ not supported yet
  622. ***** ^ not supported yet
  623. 370 INC( StackCount );
  624. ***** ^ undeclared identifier
  625. ***** ^ not supported yet
  626. 371 ELSIF TheStr[ TmpSpot ] = Closer THEN
  627. ***** ^ not supported yet
  628. ***** ^ not supported yet
  629. 372 IF StackCount = 0 THEN
  630. 373 RETURN TmpSpot;
  631. 374 ELSE
  632. 375 DEC( StackCount );
  633. ***** ^ undeclared identifier
  634. ***** ^ not supported yet
  635. 376 END;
  636. 377 END;
  637. 378 INC( TmpSpot );
  638. ***** ^ undeclared identifier
  639. ***** ^ not supported yet
  640. 379 END;
  641. 380 END;
  642. 381 RETURN spot;
  643. 382 END MatchingPos;
  644. ***** ^ not supported yet
  645. 383
  646. 384
  647. 385 PROCEDURE PatternScan( PatternAdr: SYSTEM.ADDRESS;
  648. ***** ^ not supported yet
  649. 386 PatternSize: CARDINAL; ScanAreaAdr: SYSTEM.ADDRESS;
  650. ***** ^ not supported yet
  651. 387 ScanAreaSize: CARDINAL; caseMatters: CaseSensitivity ): CARDINAL;
  652. ***** ^ undeclared identifier
  653. 388 VAR
  654. 389 BytesSkipped, ThisScan, cnt, PossibleStartSpots : CARDINAL;
  655. 390 MaxScan: INTEGER;
  656. 391 PatAdr, AreaAdr: LowLevel.Address8086;
  657. ***** ^ not supported yet
  658. 392 BEGIN
  659. 393 PatAdr.a := PatternAdr;
  660. ***** ^ not supported yet
  661. ***** ^ not supported yet
  662. ***** ^ not supported yet
  663. 394 AreaAdr.a := ScanAreaAdr;
  664. ***** ^ not supported yet
  665. ***** ^ not supported yet
  666. ***** ^ not supported yet
  667. 395 IF (ScanAreaSize >= PatternSize) AND (PatternSize#0) THEN
  668. 396 PossibleStartSpots := ScanAreaSize - PatternSize + 1;
  669. 397 IF PossibleStartSpots > 32766 THEN
  670. 398 MaxScan := 32766;
  671. 399 ELSE
  672. 400 MaxScan := PossibleStartSpots;
  673. 401 END;
  674. 402 BytesSkipped := ScanForByte( MaxScan, PatAdr.b^, ScanAreaAdr,
  675. ***** ^ not supported yet
  676. ***** ^ not supported yet
  677. ***** ^ not supported yet
  678. ***** ^ not supported yet
  679. 403 caseMatters );
  680. ***** ^ not supported yet
  681. 404 ThisScan := BytesSkipped;
  682. 405 INC( AreaAdr.off, ThisScan );
  683. ***** ^ undeclared identifier
  684. ***** ^ not supported yet
  685. ***** ^ not supported yet
  686. ***** ^ not supported yet
  687. 406 WHILE (BytesSkipped < PossibleStartSpots) DO
  688. 407 IF ThisScan < CARDINAL(MaxScan) THEN
  689. ***** ^ not supported yet
  690. 408 cnt := 0;
  691. 409 LOOP
  692. 410 (* as long as following elements equal do:*)
  693. 411 INC( cnt );
  694. ***** ^ undeclared identifier
  695. ***** ^ not supported yet
  696. 412 IF cnt >= PatternSize THEN
  697. 413 (*if at end of pattern, we've found a match*)
  698. 414 RETURN BytesSkipped;
  699. 415 END;
  700. 416 INC( PatAdr.off );
  701. ***** ^ undeclared identifier
  702. ***** ^ not supported yet
  703. ***** ^ not supported yet
  704. 417 INC( AreaAdr.off );
  705. ***** ^ undeclared identifier
  706. ***** ^ not supported yet
  707. ***** ^ not supported yet
  708. 418 IF caseMatters = CaseInsens THEN
  709. ***** ^ not supported yet
  710. ***** ^ undeclared identifier
  711. 419 IF CAP(AreaAdr.b^) # CAP(PatAdr.b^) THEN
  712. ***** ^ undeclared identifier
  713. ***** ^ not supported yet
  714. ***** ^ not supported yet
  715. ***** ^ undeclared identifier
  716. ***** ^ not supported yet
  717. ***** ^ not supported yet
  718. 420 (*if next element # object, stop comparing*)
  719. 421 EXIT;
  720. 422 END;
  721. 423 ELSE
  722. 424 IF AreaAdr.b^ # PatAdr.b^ THEN
  723. ***** ^ not supported yet
  724. ***** ^ not supported yet
  725. ***** ^ not supported yet
  726. ***** ^ not supported yet
  727. 425 (*if next element # object, stop comparing*)
  728. 426 EXIT;
  729. 427 END;
  730. 428 END;
  731. 429 END;
  732. 430 END;
  733. 431 INC( BytesSkipped );
  734. ***** ^ undeclared identifier
  735. ***** ^ not supported yet
  736. 432 IF BytesSkipped > PossibleStartSpots THEN
  737. 433 RETURN ScanAreaSize;
  738. 434 (* Pattern not found. *)
  739. 435 ELSIF (PossibleStartSpots - BytesSkipped) > 32766 THEN
  740. 436 MaxScan := 32766;
  741. 437 ELSE
  742. 438 MaxScan := PossibleStartSpots - BytesSkipped;
  743. 439 END;
  744. 440 PatAdr.a := PatternAdr;
  745. ***** ^ not supported yet
  746. ***** ^ not supported yet
  747. ***** ^ not supported yet
  748. 441 AreaAdr.a := ScanAreaAdr;
  749. ***** ^ not supported yet
  750. ***** ^ not supported yet
  751. ***** ^ not supported yet
  752. 442 INC( AreaAdr.off, BytesSkipped );
  753. ***** ^ undeclared identifier
  754. ***** ^ not supported yet
  755. ***** ^ not supported yet
  756. ***** ^ not supported yet
  757. 443 ThisScan := ScanForByte( MaxScan,
  758. ***** ^ not supported yet
  759. 444 PatAdr.b^, AreaAdr.a, caseMatters );
  760. ***** ^ not supported yet
  761. ***** ^ not supported yet
  762. ***** ^ not supported yet
  763. ***** ^ not supported yet
  764. ***** ^ not supported yet
  765. 445 INC( BytesSkipped, ThisScan );
  766. ***** ^ undeclared identifier
  767. ***** ^ not supported yet
  768. 446 INC( AreaAdr.off, ThisScan );
  769. ***** ^ undeclared identifier
  770. ***** ^ not supported yet
  771. ***** ^ not supported yet
  772. ***** ^ not supported yet
  773. 447 END;
  774. 448 END;
  775. 449 RETURN ScanAreaSize;
  776. 450 (* Pattern not found. *)
  777. 451 END PatternScan;
  778. ***** ^ not supported yet
  779. 452
  780. 453
  781. 454 PROCEDURE PosAdr(VAR s2 : ARRAY OF CHAR; s : SYSTEM.ADDRESS;
  782. ***** ^ not supported yet
  783. ***** ^ not supported yet
  784. 455 size: CARDINAL; caseMatters: CaseSensitivity ) : CARDINAL;
  785. ***** ^ undeclared identifier
  786. 456 BEGIN
  787. 457 RETURN PatternScan( SYSTEM.ADR(s2), M2Strings.Length(s2), s,
  788. ***** ^ not supported yet
  789. ***** ^ not supported yet
  790. ***** ^ not supported yet
  791. ***** ^ not supported yet
  792. ***** ^ not supported yet
  793. ***** ^ not supported yet
  794. ***** ^ not supported yet
  795. ***** ^ not supported yet
  796. 458 size, caseMatters );
  797. ***** ^ not supported yet
  798. 459 END PosAdr;
  799. ***** ^ not supported yet
  800. 460
  801. 461
  802. 462 PROCEDURE Pos(s2 : ARRAY OF CHAR; s : ARRAY OF CHAR;
  803. ***** ^ not supported yet
  804. ***** ^ not supported yet
  805. 463 caseMatters: CaseSensitivity ) : CARDINAL;
  806. ***** ^ undeclared identifier
  807. 464 (* Return the index in s of the first occurence of the substring s2,
  808. 465 or High(s)+1 if there are no occurences of s2.*)
  809. 466 VAR
  810. 467 i, j, n, n2, len : CARDINAL;
  811. 468 BEGIN
  812. 469 n := M2Strings.Length(s);
  813. ***** ^ not supported yet
  814. ***** ^ not supported yet
  815. ***** ^ not supported yet
  816. 470 (*length of string to search in*)
  817. 471 n2 := M2Strings.Length(s2);
  818. ***** ^ not supported yet
  819. ***** ^ not supported yet
  820. ***** ^ not supported yet
  821. 472 (*length of string to search for*)
  822. 473 IF (n >= n2) AND (n2 # 0) THEN
  823. 474 (*only search if target bigger than object; object non-null*)
  824. 475 len := n-n2+1;
  825. 476 (* number of possible starting positions *)
  826. 477 i := ScanForByte(len, s2[0], SYSTEM.ADR(s[0]), caseMatters);
  827. ***** ^ not supported yet
  828. ***** ^ not supported yet
  829. ***** ^ not supported yet
  830. ***** ^ not supported yet
  831. ***** ^ not supported yet
  832. ***** ^ not supported yet
  833. ***** ^ not supported yet
  834. ***** ^ not supported yet
  835. 478 (*changed; start at first occurence of s2[0]*)
  836. 479 WHILE (i<len) DO
  837. 480 (*only for possible starting positions*)
  838. 481 j := 1;
  839. 482 LOOP
  840. 483 (* as long as following elements equal object do:*)
  841. 484 IF j >= n2 THEN
  842. 485 (*if at end of object, finished*)
  843. 486 RETURN i;
  844. 487 END;
  845. 488 IF caseMatters = CaseInsens THEN
  846. ***** ^ not supported yet
  847. ***** ^ undeclared identifier
  848. 489 IF CAP(s[i+j]) # CAP(s2[0+j]) THEN
  849. ***** ^ undeclared identifier
  850. ***** ^ not supported yet
  851. ***** ^ not supported yet
  852. ***** ^ undeclared identifier
  853. ***** ^ not supported yet
  854. ***** ^ not supported yet
  855. 490 (*if next element # to object, stop comparing*)
  856. 491 EXIT;
  857. 492 END;
  858. 493 ELSE
  859. 494 IF s[i+j] # s2[0+j] THEN
  860. ***** ^ not supported yet
  861. ***** ^ not supported yet
  862. ***** ^ not supported yet
  863. ***** ^ not supported yet
  864. 495 (*if next element # to object, stop comparing*)
  865. 496 EXIT;
  866. 497 END;
  867. 498 END;
  868. 499 INC(j);
  869. ***** ^ undeclared identifier
  870. ***** ^ not supported yet
  871. 500 END;
  872. 501 i := i + 1 + CARDINAL(
  873. 502 ScanForByte( len-1-i, s2[0], SYSTEM.ADR(s[i+1]), caseMatters));
  874. ***** ^ not supported yet
  875. ***** ^ not supported yet
  876. ***** ^ not supported yet
  877. ***** ^ not supported yet
  878. ***** ^ not supported yet
  879. ***** ^ not supported yet
  880. ***** ^ not supported yet
  881. ***** ^ not supported yet
  882. 503 (*changed: try next possible starting position *)
  883. 504 END;
  884. 505 END;
  885. 506 RETURN (HIGH(s)+1);
  886. ***** ^ undeclared identifier
  887. ***** ^ not supported yet
  888. 507 (* String not found. *)
  889. 508 END Pos;
  890. ***** ^ not supported yet
  891. 509
  892. 510
  893. 511 PROCEDURE PosDelimited(VAR pattern, obj, delimiters : ARRAY OF
  894. 512 CHAR; caseMatters: CaseSensitivity ) : CARDINAL;
  895. ***** ^ not supported yet
  896. ***** ^ undeclared identifier
  897. 513 (*These are VAR parameters just for purposes of efficiency.
  898. 514 Neither is actually changed.*)
  899. 515 VAR
  900. 516 spot1, spot2 : CARDINAL;
  901. 517 BEGIN
  902. 518 (*PosDelimited*)
  903. 519 IF PresentPos( pattern, obj, spot1, caseMatters ) THEN
  904. ***** ^ undeclared identifier
  905. ***** ^ not supported yet
  906. ***** ^ not supported yet
  907. ***** ^ not supported yet
  908. 520 spot2 := spot1 + M2Strings.Length(pattern);
  909. ***** ^ not supported yet
  910. ***** ^ not supported yet
  911. ***** ^ not supported yet
  912. 521 (*spot2 should now point to the character after the
  913. 522 pattern*)
  914. 523 IF (spot1=0)
  915. 524 OR
  916. 525 Present(obj[spot1-1], delimiters, caseMatters) THEN
  917. ***** ^ undeclared identifier
  918. ***** ^ not supported yet
  919. ***** ^ not supported yet
  920. ***** ^ not supported yet
  921. ***** ^ not supported yet
  922. 526 (*Now we know everything to the left of the pattern
  923. 527 is okay.*)
  924. 528 IF (spot2>=M2Strings.Length(obj)) OR Present(obj[spot2],
  925. ***** ^ not supported yet
  926. ***** ^ not supported yet
  927. ***** ^ not supported yet
  928. ***** ^ undeclared identifier
  929. ***** ^ not supported yet
  930. ***** ^ not supported yet
  931. 529 delimiters, caseMatters) THEN
  932. ***** ^ not supported yet
  933. ***** ^ not supported yet
  934. 530 (*And now we know everything is okay to the right.*)
  935. 531 RETURN (spot1);
  936. 532 END;
  937. 533 END;
  938. 534 END;
  939. 535 RETURN (HIGH(obj)+1);
  940. ***** ^ undeclared identifier
  941. ***** ^ not supported yet
  942. 536 END PosDelimited;
  943. ***** ^ not supported yet
  944. 537
  945. 538
  946. 539 PROCEDURE Positn(s2 : ARRAY OF CHAR; s : ARRAY OF CHAR; i : CARDINAL;
  947. ***** ^ not supported yet
  948. ***** ^ not supported yet
  949. 540 caseMatters: CaseSensitivity ) : CARDINAL;
  950. ***** ^ undeclared identifier
  951. 541 (* Return the index in s of the first occurence of the substring s2,
  952. 542 at or after index i, or HIGH(s)+1 if there are no occurences of s2.*)
  953. 543 VAR
  954. 544 len, PosAdrResult: CARDINAL;
  955. 545 BEGIN
  956. 546 len := M2Strings.Length( s );
  957. ***** ^ not supported yet
  958. ***** ^ not supported yet
  959. ***** ^ not supported yet
  960. 547 IF len > i THEN
  961. 548 PosAdrResult := PosAdr( s2, SYSTEM.ADR(s[i]), len - i, caseMatters );
  962. ***** ^ not supported yet
  963. ***** ^ not supported yet
  964. ***** ^ not supported yet
  965. ***** ^ not supported yet
  966. ***** ^ not supported yet
  967. ***** ^ not supported yet
  968. ***** ^ not supported yet
  969. 549 IF PosAdrResult < (len - i) THEN
  970. 550 RETURN i + PosAdrResult;
  971. 551 END;
  972. 552 END;
  973. 553 RETURN (HIGH(s)+1);
  974. ***** ^ undeclared identifier
  975. ***** ^ not supported yet
  976. 554 (* String not found.*)
  977. 555 END Positn;
  978. ***** ^ not supported yet
  979. 556
  980. 557
  981. 558 PROCEDURE Present(str1, str2 : ARRAY OF CHAR;
  982. ***** ^ not supported yet
  983. 559 caseMatters: CaseSensitivity ) : BOOLEAN;
  984. ***** ^ undeclared identifier
  985. 560 BEGIN
  986. 561 IF Pos( str1, str2, caseMatters ) <= HIGH(str2) THEN
  987. ***** ^ not supported yet
  988. ***** ^ not supported yet
  989. ***** ^ not supported yet
  990. ***** ^ not supported yet
  991. ***** ^ undeclared identifier
  992. ***** ^ not supported yet
  993. 562 RETURN (TRUE);
  994. 563 ELSE
  995. 564 RETURN (FALSE);
  996. 565 END;
  997. 566 END Present;
  998. ***** ^ not supported yet
  999. 567
  1000. 568
  1001. 569 PROCEDURE PresentPos(str1, str2 : ARRAY OF CHAR; VAR spot:
  1002. ***** ^ not supported yet
  1003. 570 CARDINAL; caseMatters: CaseSensitivity ) : BOOLEAN;
  1004. ***** ^ undeclared identifier
  1005. 571 VAR
  1006. 572 size: CARDINAL;
  1007. 573 BEGIN
  1008. 574 size := M2Strings.Length(str2);
  1009. ***** ^ not supported yet
  1010. ***** ^ not supported yet
  1011. ***** ^ not supported yet
  1012. 575 spot := PosAdr( str1, SYSTEM.ADR(str2), size, caseMatters );
  1013. ***** ^ not supported yet
  1014. ***** ^ not supported yet
  1015. ***** ^ not supported yet
  1016. ***** ^ not supported yet
  1017. ***** ^ not supported yet
  1018. ***** ^ not supported yet
  1019. 576 IF spot < size THEN
  1020. 577 RETURN (TRUE);
  1021. 578 ELSE
  1022. 579 spot := HIGH(str2) + 1;
  1023. ***** ^ undeclared identifier
  1024. ***** ^ not supported yet
  1025. 580 RETURN (FALSE);
  1026. 581 END;
  1027. 582 END PresentPos;
  1028. ***** ^ not supported yet
  1029. 583
  1030. 584
  1031. 585 PROCEDURE SubStrMatch( str1: ARRAY OF CHAR; StartingAt1,
  1032. ***** ^ not supported yet
  1033. 586 EndingAt1: CARDINAL; VAR str2: ARRAY OF CHAR; StartingAt2,
  1034. ***** ^ not supported yet
  1035. 587 EndingAt2: CARDINAL; caseMatters: CaseSensitivity ): BOOLEAN;
  1036. ***** ^ undeclared identifier
  1037. 588 VAR
  1038. 589 size1, size2, tmpc: CARDINAL;
  1039. 590 BEGIN
  1040. 591 size1 := M2Strings.Length(str1);
  1041. ***** ^ not supported yet
  1042. ***** ^ not supported yet
  1043. ***** ^ not supported yet
  1044. 592 size2 := M2Strings.Length(str2);
  1045. ***** ^ not supported yet
  1046. ***** ^ not supported yet
  1047. ***** ^ not supported yet
  1048. 593 IF (size1 <= StartingAt1) OR (size2 <= StartingAt2) OR
  1049. 594 (StartingAt1 > EndingAt1) OR (StartingAt2 > EndingAt2) THEN
  1050. 595 RETURN FALSE;
  1051. 596 END;
  1052. 597 size1 := Numbers.Min( EndingAt1 + 1, size1) - StartingAt1;
  1053. ***** ^ not supported yet
  1054. ***** ^ not supported yet
  1055. ***** ^ not supported yet
  1056. 598 size2 := Numbers.Min( EndingAt2 + 1, size2) - StartingAt2;
  1057. ***** ^ not supported yet
  1058. ***** ^ not supported yet
  1059. ***** ^ not supported yet
  1060. 599 tmpc := PatternScan( SYSTEM.ADR(str1[StartingAt1]), size1,
  1061. ***** ^ not supported yet
  1062. ***** ^ not supported yet
  1063. ***** ^ not supported yet
  1064. ***** ^ not supported yet
  1065. ***** ^ not supported yet
  1066. 600 SYSTEM.ADR(str2[StartingAt2]), size2, caseMatters );
  1067. ***** ^ not supported yet
  1068. ***** ^ not supported yet
  1069. ***** ^ not supported yet
  1070. ***** ^ not supported yet
  1071. ***** ^ not supported yet
  1072. 601 RETURN tmpc = 0;
  1073. 602 END SubStrMatch;
  1074. ***** ^ not supported yet
  1075. 603
  1076. 604
  1077. 605 BEGIN
  1078. 606 Initialized := FALSE;
  1079. 607 Init();
  1080. ***** ^ not supported yet
  1081. ***** ^ not supported yet
  1082. 608 END ScanUtils.
  1083. ***** ^ not supported yet
  1084. 474 errors