POSUTILS.LST 44 KB

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