NDXSORT.LST 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. Listing:
  2. 1 IMPLEMENTATION MODULE NdxSort;
  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/ndxsort.mov 1.8 10 Mar 1991 15:30:36 coleb $
  13. 12 *
  14. 13 *
  15. 14 * Written and contributed by Torbjorn Sund of
  16. 15 * Tromsoe, Norway.
  17. 16 *
  18. 17 *)
  19. 18
  20. 19
  21. 20 (*EntryDiag:
  22. 21 IMPORT Diagnostics;
  23. 22 :EntryDiag*)
  24. 23 IMPORT ErrorManager;
  25. 24 IMPORT GenLists;
  26. 25 IMPORT LowLevel;
  27. 26 IMPORT M2Strings;
  28. 27 IMPORT NdxFiles;
  29. 28 IMPORT NdxTypes;
  30. 29 IMPORT PosUtils;
  31. 30 IMPORT StrConv;
  32. 31 IMPORT StrEdit;
  33. 32 IMPORT SYSTEM;
  34. 33
  35. 34 VAR
  36. 35 Initialized : BOOLEAN;
  37. 36
  38. 37 PROCEDURE Init();
  39. 38 BEGIN
  40. 39 IF Initialized THEN
  41. 40 RETURN;
  42. 41 ELSE
  43. 42 Initialized := TRUE;
  44. 43 END;
  45. 44 (*EntryDiag:
  46. 45 Diagnostics.Init();
  47. 46 :EntryDiag*)
  48. 47 ErrorManager.Init();
  49. ***** ^ not supported yet
  50. ***** ^ not supported yet
  51. ***** ^ not supported yet
  52. 48 LowLevel.Init();
  53. ***** ^ not supported yet
  54. ***** ^ not supported yet
  55. ***** ^ not supported yet
  56. 49 StrEdit.Init();
  57. ***** ^ not supported yet
  58. ***** ^ not supported yet
  59. ***** ^ not supported yet
  60. 50 NdxTypes.Init();
  61. ***** ^ not supported yet
  62. ***** ^ not supported yet
  63. ***** ^ not supported yet
  64. 51 NdxFiles.Init();
  65. ***** ^ not supported yet
  66. ***** ^ not supported yet
  67. ***** ^ not supported yet
  68. 52 GenLists.Init();
  69. ***** ^ not supported yet
  70. ***** ^ not supported yet
  71. ***** ^ not supported yet
  72. 53 M2Strings.Init();
  73. ***** ^ not supported yet
  74. ***** ^ not supported yet
  75. ***** ^ not supported yet
  76. 54 PosUtils.Init();
  77. ***** ^ not supported yet
  78. ***** ^ not supported yet
  79. ***** ^ not supported yet
  80. 55 StrConv.Init();
  81. ***** ^ not supported yet
  82. ***** ^ not supported yet
  83. ***** ^ not supported yet
  84. 56
  85. 57 (*EntryDiag:
  86. 58 Diagnostics.diagS( 'Entering NdxSort', '' );
  87. 59 :EntryDiag*)
  88. 60
  89. 61 DefMaxPos := InitDefMaxPos;
  90. ***** ^ undeclared identifier
  91. ***** ^ undeclared identifier
  92. 62
  93. 63 (*EntryDiag:
  94. 64 Diagnostics.diagS( 'Exiting NdxSort', '' );
  95. 65 :EntryDiag*)
  96. 66 END Init;
  97. ***** ^ not supported yet
  98. 67
  99. 68
  100. 69 CONST
  101. 70 AFTERLAST = 65535;
  102. 71 (* clarifies list-append operation *)
  103. 72
  104. 73 TYPE
  105. 74 String = ARRAY [0..127] OF CHAR;
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. 75
  109. 76 (* below taken from Repertoire book *)
  110. 77 PROCEDURE TypeOf(TheList : GenLists.GenList; TheElmt : CARDINAL) : CARDINAL;
  111. ***** ^ not supported yet
  112. 78 VAR
  113. 79 TypeCode, DummySize : CARDINAL;
  114. 80 DummyAddr : POINTER TO CARDINAL;
  115. ***** ^ not supported yet
  116. 81 BEGIN
  117. 82 GenLists.GetElmtAdr(TheList, TheElmt, DummyAddr, DummySize, TypeCode);
  118. ***** ^ not supported yet
  119. ***** ^ not supported yet
  120. ***** ^ not supported yet
  121. ***** ^ not supported yet
  122. ***** ^ not supported yet
  123. 83 RETURN TypeCode;
  124. 84 END TypeOf;
  125. ***** ^ not supported yet
  126. 85
  127. 86
  128. 87 (* PMI. Get1Parameter below is something I seem to end up implementing
  129. 88 variations upon again and again. You might use your procedure to
  130. 89 parse the structure string - or at closer look it seems to be convoluted
  131. 90 enough already! You might consider implementing a general, useful,
  132. 91 small, fast etc parsing routine ?
  133. 92 *)
  134. 93 PROCEDURE Get1Parameter(TheStr : ARRAY OF CHAR; TheSep : CHAR;
  135. ***** ^ not supported yet
  136. 94 TheNum : CARDINAL; VAR ThePar : ARRAY OF CHAR) : BOOLEAN;
  137. ***** ^ not supported yet
  138. 95 VAR
  139. 96 AtPos, Postpos, AtNo, len : CARDINAL;
  140. 97 BEGIN
  141. 98 len := M2Strings.Length(TheStr);
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. 99 (* search for separator number TheNum-1 *)
  146. 100 AtNo := 1;
  147. 101 AtPos := 0;
  148. 102 WHILE (AtPos<len) AND (AtNo<TheNum) DO
  149. 103 INC(AtNo);
  150. ***** ^ undeclared identifier
  151. ***** ^ not supported yet
  152. 104 AtPos := PosUtils.Positn(TheSep,TheStr,AtPos)+1;
  153. ***** ^ not supported yet
  154. ***** ^ not supported yet
  155. ***** ^ not supported yet
  156. ***** ^ not supported yet
  157. 105 END;
  158. 106 IF (AtNo<TheNum) OR (AtPos>=len) THEN
  159. 107 (* didn't find it *)
  160. 108 RETURN FALSE;
  161. 109 ELSE
  162. 110 (* found it, so get the parameter *)
  163. 111 IF AtPos>=len THEN
  164. 112 StrEdit.SetLength(ThePar, 0);
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. ***** ^ not supported yet
  169. 113 ELSE
  170. 114 Postpos := PosUtils.Positn(TheSep,TheStr,AtPos);
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. ***** ^ not supported yet
  174. ***** ^ not supported yet
  175. 115 IF Postpos<len THEN
  176. 116 M2Strings.Copy(TheStr, AtPos, Postpos-AtPos, ThePar);
  177. ***** ^ not supported yet
  178. ***** ^ not supported yet
  179. ***** ^ not supported yet
  180. ***** ^ not supported yet
  181. 117 ELSE
  182. 118 (* Postpos may be greater than len, so to be on the safe side: *)
  183. 119 M2Strings.Copy(TheStr, AtPos, len-AtPos, ThePar);
  184. ***** ^ not supported yet
  185. ***** ^ not supported yet
  186. ***** ^ not supported yet
  187. ***** ^ not supported yet
  188. 120 END;
  189. 121 END;
  190. 122 RETURN TRUE;
  191. 123 END;
  192. 124 (* shouldn't get here *)
  193. 125 HALT();
  194. ***** ^ undeclared identifier
  195. ***** ^ not supported yet
  196. 126 END Get1Parameter;
  197. ***** ^ not supported yet
  198. 127
  199. 128
  200. 129 PROCEDURE CompareCriteria(e1 : SYSTEM.ADDRESS; l1 : CARDINAL; e2 : SYSTEM.ADDRESS;
  201. ***** ^ not supported yet
  202. ***** ^ not supported yet
  203. 130 l2 : CARDINAL) : INTEGER;
  204. 131 (* Compare routine for SortList. It is assumed here that
  205. 132 (1) the elements to be sorted are themselves lists of equal length, and
  206. 133 (2) there is at least one spot in the sublists with unequal elements of
  207. 134 same type.
  208. 135 These conditions are guaranteed by InitCriteriaList(...) below.
  209. 136 *)
  210. 137 VAR
  211. 138 count, spot : CARDINAL;
  212. 139 maxcount : CARDINAL;
  213. 140 RdAd1, RdAd2 : SYSTEM.ADDRESS;
  214. ***** ^ not supported yet
  215. 141 GL1, GL2 : GenLists.GenList;
  216. ***** ^ not supported yet
  217. 142 GLP1, GLP2 : POINTER TO GenLists.GenList;
  218. ***** ^ not supported yet
  219. 143 Typ1, Typ2 : CARDINAL;
  220. 144 Siz1, Siz2 : CARDINAL;
  221. 145 Reslt : INTEGER;
  222. 146 Str1, Str2 : String;
  223. ***** ^ not supported yet
  224. 147 BEGIN
  225. 148 (* Note that it is not necessary to EXIT from the outer LOOP,
  226. 149 the inner LOOP shall always RETURN (see conditions above).
  227. 150 *)
  228. 151 spot := 0;
  229. 152 LOOP
  230. 153 INC(spot);
  231. ***** ^ undeclared identifier
  232. ***** ^ not supported yet
  233. 154 (* would have been nice to dereference directly through a construct
  234. 155 like GLPType(e1)^, but Logitech won't take that one. Even more
  235. 156 elegant of course would have been to declare e1 and e2 NOT as
  236. 157 ADDRESS, but as POINTER TO GenList directly. Why couldn't a variable
  237. 158 of type ADDRESS be compatible with any pointer type?
  238. 159 Well, programming probably never was meant to be easy. Sigh ..
  239. 160 *)
  240. 161 GLP1 := e1;
  241. ***** ^ not supported yet
  242. ***** ^ not supported yet
  243. 162 GL1 := GLP1^;
  244. ***** ^ not supported yet
  245. ***** ^ not supported yet
  246. 163 Typ1 := TypeOf(GL1,spot);
  247. ***** ^ not supported yet
  248. ***** ^ not supported yet
  249. ***** ^ not supported yet
  250. 164 GLP2 := e2;
  251. ***** ^ not supported yet
  252. ***** ^ not supported yet
  253. 165 GL2 := GLP2^;
  254. ***** ^ not supported yet
  255. ***** ^ not supported yet
  256. 166 Typ2 := TypeOf(GL2,spot);
  257. ***** ^ not supported yet
  258. ***** ^ not supported yet
  259. ***** ^ not supported yet
  260. 167 IF Typ1=Typ2 THEN
  261. 168 (* should I compare apples and oranges ? *)
  262. 169 IF Typ1=GenLists.StrCode THEN
  263. ***** ^ not supported yet
  264. ***** ^ not supported yet
  265. 170 GenLists.GetElmt(GL1, spot, Str1, Typ1);
  266. ***** ^ not supported yet
  267. ***** ^ not supported yet
  268. ***** ^ not supported yet
  269. ***** ^ not supported yet
  270. ***** ^ not supported yet
  271. 171 GenLists.GetElmt(GL2, spot, Str2, Typ2);
  272. ***** ^ not supported yet
  273. ***** ^ not supported yet
  274. ***** ^ not supported yet
  275. ***** ^ not supported yet
  276. ***** ^ not supported yet
  277. 172 Reslt := M2Strings.CompareStr(Str1,Str2);
  278. ***** ^ not supported yet
  279. ***** ^ not supported yet
  280. ***** ^ not supported yet
  281. ***** ^ not supported yet
  282. 173 IF Reslt#0 THEN
  283. 174 RETURN Reslt;
  284. 175 END;
  285. 176 ELSE
  286. 177 (* PMI! I never sort on anything else than strings,
  287. 178 so this part of the code has probably never been
  288. 179 executed.
  289. 180 *)
  290. 181 GenLists.GetElmtAdr(GL1, spot, RdAd1, Siz1, Typ1);
  291. ***** ^ not supported yet
  292. ***** ^ not supported yet
  293. ***** ^ not supported yet
  294. ***** ^ not supported yet
  295. ***** ^ not supported yet
  296. 182 GenLists.GetElmtAdr(GL2, spot, RdAd2, Siz2, Typ2);
  297. ***** ^ not supported yet
  298. ***** ^ not supported yet
  299. ***** ^ not supported yet
  300. ***** ^ not supported yet
  301. ***** ^ not supported yet
  302. 183 (* block compare could come in handy here, but the one found in
  303. 184 Logitech's block ops only returns true/false. Silly *)
  304. 185 count := 0;
  305. 186 maxcount := Siz1;
  306. 187 IF Siz2>Siz1 THEN
  307. 188 maxcount := Siz2;
  308. 189 END;
  309. 190 (* this is probably a good place to turn off run-time checks *)
  310. 191 LOOP
  311. 192 INC(count);
  312. ***** ^ undeclared identifier
  313. ***** ^ not supported yet
  314. 193 IF count>maxcount THEN
  315. 194 EXIT;
  316. 195 END;
  317. 196 IF CARDINAL(RdAd1^) > CARDINAL(RdAd2^) THEN
  318. ***** ^ not supported yet
  319. ***** ^ not supported yet
  320. 197 RETURN -1;
  321. 198 ELSIF CARDINAL(RdAd1^) < CARDINAL(RdAd2^) THEN
  322. ***** ^ not supported yet
  323. ***** ^ not supported yet
  324. 199 RETURN 1;
  325. 200 END;
  326. 201 LowLevel.IncAddr( RdAd1, 1 );
  327. ***** ^ not supported yet
  328. ***** ^ not supported yet
  329. ***** ^ not supported yet
  330. ***** ^ not supported yet
  331. 202 LowLevel.IncAddr( RdAd2, 1 );
  332. ***** ^ not supported yet
  333. ***** ^ not supported yet
  334. ***** ^ not supported yet
  335. ***** ^ not supported yet
  336. 203 END;
  337. 204 END;
  338. 205 (* EXITed, elements equal so far. test lengths. *)
  339. 206 IF Siz1>Siz2 THEN
  340. 207 RETURN -1;
  341. 208 ELSIF Siz1<Siz2 THEN
  342. 209 RETURN 1;
  343. 210 END;
  344. 211 END;
  345. 212 (* IF types equal *)
  346. 213 (* proceed to next element in the two lists *)
  347. 214 END;
  348. 215 (* LOOP *)
  349. 216 (* impossible to get here *)
  350. 217 HALT();
  351. ***** ^ undeclared identifier
  352. ***** ^ not supported yet
  353. 218 END CompareCriteria;
  354. ***** ^ not supported yet
  355. 219
  356. 220
  357. 221 (* routine to decode the string with sort fields and optionally lengths *)
  358. 222 PROCEDURE DecodeFieldStr(TheFile : NdxTypes.NdxFileType; FieldStr : ARRAY OF
  359. ***** ^ not supported yet
  360. 223 CHAR; VAR FieldList : GenLists.GenList);
  361. ***** ^ not supported yet
  362. ***** ^ not supported yet
  363. 224 (* Give this routine an NdxFile and a string containing names of
  364. 225 fields in this file, the routine will exit with FieldList containing
  365. 226 a list of the position of each field in the genlist that holds the
  366. 227 file's data record. Fields that are not in the file are ignored.
  367. 228 The names in the FieldStr are separated by blank(s). Each name may
  368. 229 optionally be followed by parameters, separated from the name and from
  369. 230 each other by comma. The first parameter signifies the maximum
  370. 231 number of bytes used for keeping the copy of that field in the criteria
  371. 232 list, default is DefMaxSize. Subsequent parameters are (currently)
  372. 233 ignored, but could easily be stored in the FieldStr to be used
  373. 234 while building the criteria list.
  374. 235 Execution speed has not been a concern for the implementation.
  375. 236 *)
  376. 237 CONST
  377. 238 FieldSep = ' ';
  378. 239 ParSep = ',';
  379. 240 VAR
  380. 241 AFieldName, AString : String;
  381. ***** ^ not supported yet
  382. 242 FieldPart, NumbrPart : String;
  383. ***** ^ not supported yet
  384. 243 MaxPos, p, dummy, AType : CARDINAL;
  385. 244 found : BOOLEAN;
  386. 245 BEGIN
  387. 246 StrEdit.CrunchBlanks(FieldStr);
  388. ***** ^ not supported yet
  389. ***** ^ not supported yet
  390. ***** ^ not supported yet
  391. 247 StrEdit.CAPstr(FieldStr);
  392. ***** ^ not supported yet
  393. ***** ^ not supported yet
  394. ***** ^ not supported yet
  395. 248 p := 0;
  396. 249 LOOP
  397. 250 (* on all fields in the input string *)
  398. 251 INC(p);
  399. ***** ^ undeclared identifier
  400. ***** ^ not supported yet
  401. 252 IF NOT Get1Parameter(FieldStr,FieldSep,p,AString) THEN
  402. ***** ^ not supported yet
  403. ***** ^ not supported yet
  404. ***** ^ not supported yet
  405. 253 EXIT;
  406. 254 END;
  407. 255 (* look into the substructure of this parameter *)
  408. 256 IF Get1Parameter(AString,ParSep,1,FieldPart) AND (M2Strings.Length(
  409. ***** ^ not supported yet
  410. ***** ^ not supported yet
  411. ***** ^ not supported yet
  412. ***** ^ not supported yet
  413. ***** ^ not supported yet
  414. 257 FieldPart)>0) THEN
  415. ***** ^ not supported yet
  416. 258 IF Get1Parameter(AString,ParSep,2,NumbrPart) AND
  417. ***** ^ not supported yet
  418. ***** ^ not supported yet
  419. ***** ^ not supported yet
  420. 259 StrConv.StrToCardinal(NumbrPart,0,MaxPos) AND (MaxPos>0) THEN
  421. ***** ^ not supported yet
  422. ***** ^ not supported yet
  423. ***** ^ not supported yet
  424. ***** ^ not supported yet
  425. 260 IF MaxPos>255 THEN
  426. 261 MaxPos := 255;
  427. 262 END;
  428. 263 ELSE
  429. 264 MaxPos := DefMaxPos;
  430. ***** ^ undeclared identifier
  431. 265 END;
  432. 266 (* is this a field of the file ? Could use Get1Parameter on the
  433. 267 structure string instead of relying on internal details of the
  434. 268 NdxFile-record.
  435. 269 *)
  436. 270 GenLists.GetElmt(TheFile^.StructLst, 1, AFieldName, AType);
  437. ***** ^ not supported yet
  438. ***** ^ not supported yet
  439. ***** ^ not supported yet
  440. ***** ^ not supported yet
  441. ***** ^ not supported yet
  442. ***** ^ not supported yet
  443. 271 LOOP
  444. 272 IF M2Strings.CompareStr(FieldPart,AFieldName)=0 THEN
  445. ***** ^ not supported yet
  446. ***** ^ not supported yet
  447. ***** ^ not supported yet
  448. ***** ^ not supported yet
  449. 273 found := TRUE;
  450. 274 EXIT;
  451. 275 ELSIF GenLists.ElmtNow(TheFile^.StructLst)>=GenLists.ListLength(TheFile^.
  452. ***** ^ not supported yet
  453. ***** ^ not supported yet
  454. ***** ^ not supported yet
  455. ***** ^ not supported yet
  456. ***** ^ not supported yet
  457. ***** ^ not supported yet
  458. ***** ^ not supported yet
  459. 276 StructLst) THEN
  460. ***** ^ not supported yet
  461. 277 found := FALSE;
  462. 278 EXIT;
  463. 279 END;
  464. 280 GenLists.NextElmt(TheFile^.StructLst, 1, AFieldName, AType);
  465. ***** ^ not supported yet
  466. ***** ^ not supported yet
  467. ***** ^ not supported yet
  468. ***** ^ not supported yet
  469. ***** ^ not supported yet
  470. ***** ^ not supported yet
  471. 281 END;
  472. 282 (* LOOP on structure list *)
  473. 283 IF found THEN
  474. 284 (* append the position and the max size *)
  475. 285 dummy := GenLists.ElmtNow(TheFile^.StructLst);
  476. ***** ^ not supported yet
  477. ***** ^ not supported yet
  478. ***** ^ not supported yet
  479. ***** ^ not supported yet
  480. 286 GenLists.ListInsert(dummy, 0, FieldList, AFTERLAST);
  481. ***** ^ not supported yet
  482. ***** ^ not supported yet
  483. ***** ^ not supported yet
  484. ***** ^ not supported yet
  485. 287 GenLists.ListInsert(MaxPos, 0, FieldList, AFTERLAST);
  486. ***** ^ not supported yet
  487. ***** ^ not supported yet
  488. ***** ^ not supported yet
  489. ***** ^ not supported yet
  490. 288 END;
  491. 289 END;
  492. 290 (* IF FieldPart not empty *)
  493. 291 END;
  494. 292 (* LOOP on the input string *)
  495. 293 END DecodeFieldStr;
  496. ***** ^ not supported yet
  497. 294
  498. 295
  499. 296 PROCEDURE InitCriteriaList(TheNdxFile : NdxTypes.NdxFileType; TheIndexes :
  500. ***** ^ not supported yet
  501. 297 GenLists.GenList; FldNums : GenLists.GenList; VAR into : GenLists.GenList);
  502. ***** ^ not supported yet
  503. ***** ^ not supported yet
  504. ***** ^ not supported yet
  505. 298 (* Initialize the "into" criteria list for those records in TheNdxFile
  506. 299 that are selected by TheIndexes. For each record, use the fields
  507. 300 that are indicated by the FldNums list.
  508. 301 NB. To keep NewList and DisposeList on the same program level (easier to
  509. 302 verify correctness), it is left to the calling program to do a
  510. 303 NewList(into) before calling InitCriteriaList.
  511. 304 The "into" GenList is structured as a list of lists, where each sublist
  512. 305 corresponds to a record in TheNdxFile. The elements of each sublist contain
  513. 306 values fetched from fields in each data record, and FldNums specifies which
  514. 307 data fields shall enter as criterion.
  515. 308 In addition, the next-to-last element of each sublist contains the original
  516. 309 sequence number, this guarantees that the sort is stable, and makes the
  517. 310 compare routine easier (will always find two elements that are unequal).
  518. 311 The last element of the sublist contains a copy of the original record
  519. 312 key. It is not used during the sort but is copied back into the output
  520. 313 (sorted) list after the sort is finished..
  521. 314 *)
  522. 315 VAR
  523. 316 AType : CARDINAL;
  524. 317 SubList : GenLists.GenList;
  525. ***** ^ not supported yet
  526. 318 AListPtr : POINTER TO GenLists.GenList;
  527. ***** ^ not supported yet
  528. 319 TheRec : GenLists.GenList;
  529. ***** ^ not supported yet
  530. 320 ReadAddr : SYSTEM.ADDRESS;
  531. ***** ^ not supported yet
  532. 321 TheSize, MaxSiz : CARDINAL;
  533. 322 TheNum : CARDINAL;
  534. 323 IndexNo : CARDINAL;
  535. 324 AnIndex : NdxTypes.RecNameStr;
  536. ***** ^ not supported yet
  537. 325 AnNdxElmt : NdxTypes.NdxElement;
  538. ***** ^ not supported yet
  539. 326 TypeOK : BOOLEAN;
  540. 327 BEGIN
  541. 328 IF GenLists.ListLength(FldNums)=0 THEN
  542. ***** ^ not supported yet
  543. ***** ^ not supported yet
  544. ***** ^ not supported yet
  545. 329 RETURN;
  546. 330 END;
  547. 331 IndexNo := 0;
  548. 332 (* Loop on the selected records in TheNdxFile *)
  549. 333 WHILE IndexNo < GenLists.ListLength(TheIndexes) DO
  550. ***** ^ not supported yet
  551. ***** ^ not supported yet
  552. ***** ^ not supported yet
  553. 334 INC(IndexNo);
  554. ***** ^ undeclared identifier
  555. ***** ^ not supported yet
  556. 335 TypeOK := TRUE;
  557. 336 CASE TypeOf(TheIndexes,IndexNo) OF
  558. ***** ^ not supported yet
  559. ***** ^ not supported yet
  560. ***** ^ not supported yet
  561. 337 NdxTypes.NdxTypeCode :
  562. ***** ^ not supported yet
  563. ***** ^ not supported yet
  564. 338 GenLists.GetElmt(TheIndexes, IndexNo, AnNdxElmt, AType);
  565. ***** ^ not supported yet
  566. ***** ^ not supported yet
  567. ***** ^ not supported yet
  568. ***** ^ not supported yet
  569. ***** ^ not supported yet
  570. 339 StrEdit.AssignStr(AnNdxElmt.RecName, AnIndex);
  571. ***** ^ not supported yet
  572. ***** ^ not supported yet
  573. ***** ^ not supported yet
  574. ***** ^ not supported yet
  575. ***** ^ not supported yet
  576. 340 | GenLists.StrCode :
  577. ***** ^ not supported yet
  578. ***** ^ not supported yet
  579. 341 GenLists.GetElmt(TheIndexes, IndexNo, AnIndex, AType);
  580. ***** ^ not supported yet
  581. ***** ^ not supported yet
  582. ***** ^ not supported yet
  583. ***** ^ not supported yet
  584. ***** ^ not supported yet
  585. 342 ELSE
  586. 343 TypeOK := FALSE;
  587. 344 END;
  588. 345 IF NOT TypeOK THEN
  589. 346 ErrorManager.WARN('Improper type in TheIndexes in NdxSort.InitCriteriaList');
  590. ***** ^ not supported yet
  591. ***** ^ not supported yet
  592. ***** ^ not supported yet
  593. 347 ELSIF NOT NdxFiles.RecordExists(TheNdxFile,AnIndex) THEN
  594. ***** ^ not supported yet
  595. ***** ^ not supported yet
  596. ***** ^ not supported yet
  597. ***** ^ not supported yet
  598. 348 (* that's ok, no such record, not much to be done then *)
  599. 349 ELSIF NOT NdxFiles.GetField(TheNdxFile,AnIndex,'RECORD',AType,TheRec) THEN
  600. ***** ^ not supported yet
  601. ***** ^ not supported yet
  602. ***** ^ not supported yet
  603. ***** ^ not supported yet
  604. ***** ^ not supported yet
  605. ***** ^ not supported yet
  606. 350 (* ? *)
  607. 351 ErrorManager.WARN('Corrupted RECORD in NdxSort.InitCriteriaList');
  608. ***** ^ not supported yet
  609. ***** ^ not supported yet
  610. ***** ^ not supported yet
  611. 352 ELSIF AType#GenLists.ListCode THEN
  612. ***** ^ not supported yet
  613. ***** ^ not supported yet
  614. 353 ErrorManager.WARN('Corrupted GetField in NdxSort.InitCriteriaList');
  615. ***** ^ not supported yet
  616. ***** ^ not supported yet
  617. ***** ^ not supported yet
  618. 354 ELSE
  619. 355 (* Move each sort field into the sublist. *)
  620. 356 GenLists.NewList(SubList);
  621. ***** ^ not supported yet
  622. ***** ^ not supported yet
  623. ***** ^ not supported yet
  624. 357 (* note structure of FldNums: REPEAT(fieldno maxfieldsize) *)
  625. 358 GenLists.GetElmt(FldNums, 1, TheNum, AType);
  626. ***** ^ not supported yet
  627. ***** ^ not supported yet
  628. ***** ^ not supported yet
  629. ***** ^ not supported yet
  630. 359 GenLists.NextElmt(FldNums, 1, MaxSiz, AType);
  631. ***** ^ not supported yet
  632. ***** ^ not supported yet
  633. ***** ^ not supported yet
  634. ***** ^ not supported yet
  635. 360 (* could put this into loop *)
  636. 361 LOOP
  637. 362 (* on each selected field *)
  638. 363 GenLists.GetElmtAdr(TheRec, TheNum, ReadAddr, TheSize, AType);
  639. ***** ^ not supported yet
  640. ***** ^ not supported yet
  641. ***** ^ not supported yet
  642. ***** ^ not supported yet
  643. ***** ^ not supported yet
  644. 364 (* It doesn't make much sense to compare lists as addresses.
  645. 365 So if the field is a list, use instead the first element of the
  646. 366 list, and if that element is a list, use the first element, etc,
  647. 367 etc, ... ad nauseatum
  648. 368 *)
  649. 369 LOOP
  650. 370 IF AType#GenLists.ListCode THEN
  651. ***** ^ not supported yet
  652. ***** ^ not supported yet
  653. 371 EXIT;
  654. 372 END;
  655. 373 AListPtr := ReadAddr;
  656. ***** ^ not supported yet
  657. ***** ^ not supported yet
  658. 374 IF GenLists.ListLength(AListPtr^)=0 THEN
  659. ***** ^ not supported yet
  660. ***** ^ not supported yet
  661. ***** ^ not supported yet
  662. 375 EXIT;
  663. 376 END;
  664. 377 (* retry with the first elmt of the list *)
  665. 378 GenLists.GetElmtAdr(AListPtr^, 1, ReadAddr, TheSize, AType);
  666. ***** ^ not supported yet
  667. ***** ^ not supported yet
  668. ***** ^ not supported yet
  669. ***** ^ not supported yet
  670. ***** ^ not supported yet
  671. 379 END;
  672. 380 GenLists.ListInsertAdr(ReadAddr, TheSize, AType, SubList, AFTERLAST);
  673. ***** ^ not supported yet
  674. ***** ^ not supported yet
  675. ***** ^ not supported yet
  676. ***** ^ not supported yet
  677. ***** ^ not supported yet
  678. 381 IF GenLists.ElmtNow(FldNums)>=GenLists.ListLength(FldNums) THEN
  679. ***** ^ not supported yet
  680. ***** ^ not supported yet
  681. ***** ^ not supported yet
  682. ***** ^ not supported yet
  683. ***** ^ not supported yet
  684. ***** ^ not supported yet
  685. 382 EXIT;
  686. 383 END;
  687. 384 GenLists.NextElmt(FldNums, 1, TheNum, AType);
  688. ***** ^ not supported yet
  689. ***** ^ not supported yet
  690. ***** ^ not supported yet
  691. ***** ^ not supported yet
  692. 385 GenLists.NextElmt(FldNums, 1, MaxSiz, AType);
  693. ***** ^ not supported yet
  694. ***** ^ not supported yet
  695. ***** ^ not supported yet
  696. ***** ^ not supported yet
  697. 386 END;
  698. 387 (* append to SubList the original position number in the main list *)
  699. 388 GenLists.ListInsert(IndexNo, 0, SubList, AFTERLAST);
  700. ***** ^ not supported yet
  701. ***** ^ not supported yet
  702. ***** ^ not supported yet
  703. ***** ^ not supported yet
  704. 389 (* append the record index to the sublist *)
  705. 390 GenLists.ListInsert(AnIndex, GenLists.StrCode, SubList, AFTERLAST);
  706. ***** ^ not supported yet
  707. ***** ^ not supported yet
  708. ***** ^ not supported yet
  709. ***** ^ not supported yet
  710. ***** ^ not supported yet
  711. ***** ^ not supported yet
  712. ***** ^ not supported yet
  713. 391 (* finally append the sublist to the main list *)
  714. 392 (* note that in 1.4c, the sublist is absorbed into the main list,
  715. 393 so the sublist should not be disposed afterwards
  716. 394 *)
  717. 395 GenLists.ListInsert(SubList, GenLists.ListCode, into, AFTERLAST);
  718. ***** ^ not supported yet
  719. ***** ^ not supported yet
  720. ***** ^ not supported yet
  721. ***** ^ not supported yet
  722. ***** ^ not supported yet
  723. ***** ^ not supported yet
  724. ***** ^ not supported yet
  725. 396 END;
  726. 397 (* IF index is proper type AND record found AND has proper type *)
  727. 398 END;
  728. 399 (* LOOP on all selected records *)
  729. 400 END InitCriteriaList;
  730. ***** ^ not supported yet
  731. 401
  732. 402
  733. 403 PROCEDURE RefillSortedList(frm : GenLists.GenList; VAR into : GenLists.GenList);
  734. ***** ^ not supported yet
  735. ***** ^ not supported yet
  736. 404 VAR
  737. 405 AType : CARDINAL;
  738. 406 AList : GenLists.GenList;
  739. ***** ^ not supported yet
  740. 407 AString : String;
  741. ***** ^ not supported yet
  742. 408 BEGIN
  743. 409 (* dispose of the original key sequence found in SortedList *)
  744. 410 GenLists.DisposeList(into);
  745. ***** ^ not supported yet
  746. ***** ^ not supported yet
  747. ***** ^ not supported yet
  748. 411 GenLists.NewList(into);
  749. ***** ^ not supported yet
  750. ***** ^ not supported yet
  751. ***** ^ not supported yet
  752. 412 (* initialize loop with first element of list *)
  753. 413 IF GenLists.ListLength(frm)=0 THEN
  754. ***** ^ not supported yet
  755. ***** ^ not supported yet
  756. ***** ^ not supported yet
  757. 414 RETURN;
  758. 415 END;
  759. 416 GenLists.GetElmt(frm, 1, AList, AType);
  760. ***** ^ not supported yet
  761. ***** ^ not supported yet
  762. ***** ^ not supported yet
  763. ***** ^ not supported yet
  764. ***** ^ not supported yet
  765. 417 LOOP
  766. 418 IF AType#GenLists.ListCode THEN
  767. ***** ^ not supported yet
  768. ***** ^ not supported yet
  769. 419 ErrorManager.WARN('Corrupted frm in NdxSort.RefillSortedList');
  770. ***** ^ not supported yet
  771. ***** ^ not supported yet
  772. ***** ^ not supported yet
  773. 420 ELSE
  774. 421 (* index is in the last element of each (list) element of the frm list*)
  775. 422 GenLists.GetElmt(AList, GenLists.ListLength(AList), AString, AType);
  776. ***** ^ not supported yet
  777. ***** ^ not supported yet
  778. ***** ^ not supported yet
  779. ***** ^ not supported yet
  780. ***** ^ not supported yet
  781. ***** ^ not supported yet
  782. ***** ^ not supported yet
  783. ***** ^ not supported yet
  784. 423 IF AType#GenLists.StrCode THEN
  785. ***** ^ not supported yet
  786. ***** ^ not supported yet
  787. 424 ErrorManager.WARN('Corrupted frm.sublist in NdxSort.RefillSortedList');
  788. ***** ^ not supported yet
  789. ***** ^ not supported yet
  790. ***** ^ not supported yet
  791. 425 ELSE
  792. 426 GenLists.ListInsert(AString, AType, into, AFTERLAST);
  793. ***** ^ not supported yet
  794. ***** ^ not supported yet
  795. ***** ^ not supported yet
  796. ***** ^ not supported yet
  797. ***** ^ not supported yet
  798. 427 END;
  799. 428 END;
  800. 429 IF GenLists.ElmtNow(frm)>=GenLists.ListLength(frm) THEN
  801. ***** ^ not supported yet
  802. ***** ^ not supported yet
  803. ***** ^ not supported yet
  804. ***** ^ not supported yet
  805. ***** ^ not supported yet
  806. ***** ^ not supported yet
  807. 430 EXIT;
  808. 431 END;
  809. 432 GenLists.NextElmt(frm, 1, AList, AType);
  810. ***** ^ not supported yet
  811. ***** ^ not supported yet
  812. ***** ^ not supported yet
  813. ***** ^ not supported yet
  814. ***** ^ not supported yet
  815. 433 END;
  816. 434 (* LOOP *)
  817. 435 END RefillSortedList;
  818. ***** ^ not supported yet
  819. 436
  820. 437
  821. 438 PROCEDURE AltNdxSort(TheFile : NdxTypes.NdxFileType; TheFields : ARRAY OF CHAR;
  822. ***** ^ not supported yet
  823. ***** ^ not supported yet
  824. 439 VAR TheRecordList : GenLists.GenList);
  825. ***** ^ not supported yet
  826. 440 (* Finally, the main driver routine. *)
  827. 441 VAR
  828. 442 FieldNumbers, CriteriaList : GenLists.GenList;
  829. ***** ^ not supported yet
  830. 443 BEGIN
  831. 444 (* NdxSort *)
  832. 445 IF NOT GenLists.Initialized(TheRecordList) THEN
  833. ***** ^ not supported yet
  834. ***** ^ not supported yet
  835. ***** ^ not supported yet
  836. 446 ErrorManager.WARN(' Unitialized "TheRecordList" in call to NdxSort');
  837. ***** ^ not supported yet
  838. ***** ^ not supported yet
  839. ***** ^ not supported yet
  840. 447 GenLists.NewList(TheRecordList);
  841. ***** ^ not supported yet
  842. ***** ^ not supported yet
  843. ***** ^ not supported yet
  844. 448 END;
  845. 449 (* Decode the string with the list of fields to sort on *)
  846. 450 GenLists.NewList(FieldNumbers);
  847. ***** ^ not supported yet
  848. ***** ^ not supported yet
  849. ***** ^ not supported yet
  850. 451 DecodeFieldStr(TheFile, TheFields, FieldNumbers);
  851. ***** ^ not supported yet
  852. ***** ^ not supported yet
  853. ***** ^ not supported yet
  854. ***** ^ not supported yet
  855. 452 (* Initialize the list of sort criteria *)
  856. 453 GenLists.NewList(CriteriaList);
  857. ***** ^ not supported yet
  858. ***** ^ not supported yet
  859. ***** ^ not supported yet
  860. 454 IF GenLists.ListLength(TheRecordList)>0 THEN
  861. ***** ^ not supported yet
  862. ***** ^ not supported yet
  863. ***** ^ not supported yet
  864. 455 (* TheRecordList contains the list of ptrs to selected records *)
  865. 456 InitCriteriaList(TheFile, TheRecordList, FieldNumbers,
  866. ***** ^ not supported yet
  867. ***** ^ not supported yet
  868. ***** ^ not supported yet
  869. ***** ^ not supported yet
  870. 457 CriteriaList);
  871. ***** ^ not supported yet
  872. 458 ELSE
  873. 459 (* otherwise, sort the whole file *)
  874. 460 InitCriteriaList(TheFile, TheFile^.Ndx, FieldNumbers,
  875. ***** ^ not supported yet
  876. ***** ^ not supported yet
  877. ***** ^ not supported yet
  878. ***** ^ not supported yet
  879. ***** ^ not supported yet
  880. 461 CriteriaList);
  881. ***** ^ not supported yet
  882. 462 END;
  883. 463 (* Sort the criteria list *)
  884. 464 GenLists.SortList(CriteriaList, CompareCriteria);
  885. ***** ^ not supported yet
  886. ***** ^ not supported yet
  887. ***** ^ not supported yet
  888. ***** ^ not supported yet
  889. 465 (* dispose and refill the original list of record keys *)
  890. 466 RefillSortedList(CriteriaList, TheRecordList);
  891. ***** ^ not supported yet
  892. ***** ^ not supported yet
  893. ***** ^ not supported yet
  894. 467 (* finally do away with all temporary lists *)
  895. 468 GenLists.DisposeList(CriteriaList);
  896. ***** ^ not supported yet
  897. ***** ^ not supported yet
  898. ***** ^ not supported yet
  899. 469 GenLists.DisposeList(FieldNumbers);
  900. ***** ^ not supported yet
  901. ***** ^ not supported yet
  902. ***** ^ not supported yet
  903. 470 END AltNdxSort;
  904. ***** ^ not supported yet
  905. 471
  906. 472
  907. 473 BEGIN
  908. 474 Initialized := FALSE;
  909. 475 Init();
  910. ***** ^ not supported yet
  911. ***** ^ not supported yet
  912. 476 END NdxSort.
  913. ***** ^ not supported yet
  914. 436 errors