NDXUTILS.LST 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. Listing:
  2. 1 IMPLEMENTATION MODULE NdxUtils;
  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/ndxutils.mov 1.7 10 Mar 1991 15:30:56 coleb $
  13. 12 *
  14. 13 *)
  15. 14
  16. 15
  17. 16 (*EntryDiag:
  18. 17 IMPORT Diagnostics;
  19. 18 :EntryDiag*)
  20. 19
  21. 20 (*
  22. 21 IMPORT BuildLst;
  23. 22 *)
  24. 23 IMPORT EnvironUtils;
  25. 24 IMPORT ErrorManager;
  26. 25 IMPORT ErrorNames;
  27. 26 IMPORT HandleIO;
  28. 27 IMPORT GenLists;
  29. 28 IMPORT ListUtils;
  30. 29 IMPORT LowLevel;
  31. 30 IMPORT M2Strings;
  32. 31 IMPORT NdxBones;
  33. 32 IMPORT NdxFiles;
  34. 33 FROM NdxTypes IMPORT NdxElement;
  35. 34 IMPORT NdxTypes;
  36. ***** ^ duplicate identifier
  37. 35 IMPORT Numbers;
  38. 36 IMPORT NumTypes;
  39. 37 IMPORT PosUtils;
  40. 38 IMPORT StrConv;
  41. 39 IMPORT StrEdit;
  42. 40 IMPORT StringIO;
  43. 41 IMPORT SYSTEM;
  44. 42 IMPORT VStorage;
  45. 43
  46. 44 VAR
  47. 45 Initialized : BOOLEAN;
  48. 46
  49. 47
  50. 48 PROCEDURE CopyMatchingFields( NdxF1: NdxTypes.NdxFileType; VAR
  51. ***** ^ not supported yet
  52. 49 NdxF2: NdxTypes.NdxFileType; RecName: ARRAY OF CHAR;
  53. ***** ^ not supported yet
  54. ***** ^ not supported yet
  55. 50 MatchingFields: GenLists.GenList );
  56. ***** ^ not supported yet
  57. 51 VAR
  58. 52 spot, TypeCode: CARDINAL;
  59. 53 FieldName1, FieldName2: ARRAY [0..79] OF CHAR;
  60. ***** ^ not supported yet
  61. ***** ^ not supported yet
  62. 54 BufElement: ARRAY [0..1023] OF CHAR;
  63. ***** ^ not supported yet
  64. ***** ^ not supported yet
  65. 55 TmpList1, TmpList2: GenLists.GenList;
  66. ***** ^ not supported yet
  67. 56
  68. 57 PROCEDURE GetPair( index: CARDINAL; TheList: GenLists.GenList;
  69. ***** ^ not supported yet
  70. 58 VAR s1, s2: ARRAY OF CHAR );
  71. ***** ^ not supported yet
  72. 59 VAR
  73. 60 eqspot, TypeCode: CARDINAL;
  74. 61 BEGIN
  75. 62 GenLists.GetElmt( TheList, index, s1, TypeCode );
  76. ***** ^ not supported yet
  77. ***** ^ not supported yet
  78. ***** ^ not supported yet
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. 63 eqspot := PosUtils.Pos( '=', s1 );
  82. ***** ^ not supported yet
  83. ***** ^ not supported yet
  84. ***** ^ not supported yet
  85. 64 IF eqspot < HIGH(s1) THEN
  86. ***** ^ undeclared identifier
  87. ***** ^ not supported yet
  88. 65 M2Strings.Copy( s1, eqspot + 1, (M2Strings.Length(s1) - eqspot) - 1,
  89. ***** ^ not supported yet
  90. ***** ^ not supported yet
  91. ***** ^ not supported yet
  92. ***** ^ not supported yet
  93. ***** ^ not supported yet
  94. ***** ^ not supported yet
  95. 66 s2 );
  96. ***** ^ not supported yet
  97. 67 M2Strings.Delete( s1, eqspot, M2Strings.Length(s1) - eqspot );
  98. ***** ^ not supported yet
  99. ***** ^ not supported yet
  100. ***** ^ not supported yet
  101. ***** ^ not supported yet
  102. ***** ^ not supported yet
  103. ***** ^ not supported yet
  104. ***** ^ not supported yet
  105. 68 ELSE
  106. 69 StrEdit.SetLength( s1, 0 );
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. ***** ^ not supported yet
  110. ***** ^ not supported yet
  111. 70 StrEdit.SetLength( s2, 0 );
  112. ***** ^ not supported yet
  113. ***** ^ not supported yet
  114. ***** ^ not supported yet
  115. ***** ^ not supported yet
  116. 71 END;
  117. 72 END GetPair;
  118. ***** ^ not supported yet
  119. 73
  120. 74 BEGIN (* CopyMatchingFields *)
  121. 75 spot := 1;
  122. 76 GetPair( spot, MatchingFields, FieldName1, FieldName2 );
  123. ***** ^ not supported yet
  124. ***** ^ not supported yet
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. 77 WHILE spot <= GenLists.ListLength( MatchingFields ) DO
  128. ***** ^ not supported yet
  129. ***** ^ not supported yet
  130. ***** ^ not supported yet
  131. 78 IF (M2Strings.Length(FieldName1) > 0) AND
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. 79 (M2Strings.Length(FieldName2) > 0) THEN
  136. ***** ^ not supported yet
  137. ***** ^ not supported yet
  138. ***** ^ not supported yet
  139. 80 IF NdxFiles.GetField( NdxF1, RecName, FieldName1,
  140. ***** ^ not supported yet
  141. ***** ^ not supported yet
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. 81 TypeCode, BufElement ) THEN
  146. ***** ^ not supported yet
  147. 82 IF TypeCode # GenLists.ListCode THEN
  148. ***** ^ not supported yet
  149. ***** ^ not supported yet
  150. 83 IF NOT NdxFiles.PutField( NdxF2, RecName, FieldName2,
  151. ***** ^ not supported yet
  152. ***** ^ not supported yet
  153. ***** ^ not supported yet
  154. ***** ^ not supported yet
  155. ***** ^ not supported yet
  156. 84 TypeCode, BufElement ) THEN
  157. ***** ^ not supported yet
  158. 85 (* You could do something here to account
  159. 86 for fields that do not exist in the
  160. 87 destination structure *)
  161. 88 END;
  162. 89 ELSE
  163. 90 (* copy lists before insertion *)
  164. 91 IF NdxFiles.GetField( NdxF1, RecName, FieldName1,
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. ***** ^ not supported yet
  169. ***** ^ not supported yet
  170. 92 TypeCode, TmpList1 ) THEN
  171. ***** ^ not supported yet
  172. 93 GenLists.CopyList( TmpList1, TmpList2 );
  173. ***** ^ not supported yet
  174. ***** ^ not supported yet
  175. ***** ^ not supported yet
  176. ***** ^ not supported yet
  177. 94 IF NOT NdxFiles.PutField( NdxF2, RecName, FieldName2,
  178. ***** ^ not supported yet
  179. ***** ^ not supported yet
  180. ***** ^ not supported yet
  181. ***** ^ not supported yet
  182. ***** ^ not supported yet
  183. 95 TypeCode, TmpList2 ) THEN
  184. ***** ^ not supported yet
  185. 96 (* You could do something here to account
  186. 97 for fields that do not exist in the
  187. 98 destination structure *)
  188. 99 END;
  189. 100 END;
  190. 101 END;
  191. 102 END;
  192. 103 END;
  193. 104 INC( spot );
  194. ***** ^ undeclared identifier
  195. ***** ^ not supported yet
  196. 105 IF spot <= GenLists.ListLength(MatchingFields) THEN
  197. ***** ^ not supported yet
  198. ***** ^ not supported yet
  199. ***** ^ not supported yet
  200. 106 GetPair( spot, MatchingFields, FieldName1, FieldName2 );
  201. ***** ^ not supported yet
  202. ***** ^ not supported yet
  203. ***** ^ not supported yet
  204. ***** ^ not supported yet
  205. 107 END;
  206. 108 END;
  207. 109 IF NOT NdxFiles.WriteRecord( NdxF2, RecName ) THEN
  208. ***** ^ not supported yet
  209. ***** ^ not supported yet
  210. ***** ^ not supported yet
  211. ***** ^ not supported yet
  212. 110 (* You could do something here to account for records
  213. 111 that could not be read from source file, so none of
  214. 112 the GetFields above succeeded *)
  215. 113 END;
  216. 114 END CopyMatchingFields;
  217. ***** ^ not supported yet
  218. 115
  219. 116
  220. 117 PROCEDURE CopyRecord( RecName: ARRAY OF CHAR; SourceFile, DestFile:
  221. ***** ^ not supported yet
  222. 118 NdxTypes.NdxFileType ): BOOLEAN;
  223. ***** ^ not supported yet
  224. 119 VAR
  225. 120 TypeCode: CARDINAL;
  226. 121 TmpList1, TmpList2: GenLists.GenList;
  227. ***** ^ not supported yet
  228. 122 BEGIN
  229. 123 IF NdxFiles.GetField( SourceFile, RecName, 'RECORD', TypeCode,
  230. ***** ^ not supported yet
  231. ***** ^ not supported yet
  232. ***** ^ not supported yet
  233. ***** ^ not supported yet
  234. ***** ^ not supported yet
  235. 124 TmpList1 ) THEN
  236. ***** ^ not supported yet
  237. 125 IF TypeCode = GenLists.ListCode THEN
  238. ***** ^ not supported yet
  239. ***** ^ not supported yet
  240. 126 GenLists.CopyList( TmpList1, TmpList2 );
  241. ***** ^ not supported yet
  242. ***** ^ not supported yet
  243. ***** ^ not supported yet
  244. ***** ^ not supported yet
  245. 127 IF NdxFiles.PutField( DestFile, RecName, 'RECORD', TypeCode,
  246. ***** ^ not supported yet
  247. ***** ^ not supported yet
  248. ***** ^ not supported yet
  249. ***** ^ not supported yet
  250. ***** ^ not supported yet
  251. 128 TmpList2 ) THEN
  252. ***** ^ not supported yet
  253. 129 IF NdxFiles.WriteRecord( DestFile, RecName ) THEN
  254. ***** ^ not supported yet
  255. ***** ^ not supported yet
  256. ***** ^ not supported yet
  257. ***** ^ not supported yet
  258. 130 RETURN TRUE;
  259. 131 END;
  260. 132 END;
  261. 133 END;
  262. 134 END;
  263. 135 RETURN FALSE;
  264. 136 END CopyRecord;
  265. ***** ^ not supported yet
  266. 137
  267. 138
  268. 139 PROCEDURE TransferRecord( RecName: ARRAY OF CHAR; SourceFile, DestFile:
  269. ***** ^ not supported yet
  270. 140 NdxTypes.NdxFileType ): BOOLEAN;
  271. ***** ^ not supported yet
  272. 141 VAR
  273. 142 TypeCode: CARDINAL;
  274. 143 TmpList1, TmpList2: GenLists.GenList;
  275. ***** ^ not supported yet
  276. 144 BEGIN
  277. 145 IF NdxFiles.GetField( SourceFile, RecName, 'RECORD', TypeCode,
  278. ***** ^ not supported yet
  279. ***** ^ not supported yet
  280. ***** ^ not supported yet
  281. ***** ^ not supported yet
  282. ***** ^ not supported yet
  283. 146 TmpList1 ) THEN
  284. ***** ^ not supported yet
  285. 147 IF TypeCode = GenLists.ListCode THEN
  286. ***** ^ not supported yet
  287. ***** ^ not supported yet
  288. 148 GenLists.CopyList( TmpList1, TmpList2 );
  289. ***** ^ not supported yet
  290. ***** ^ not supported yet
  291. ***** ^ not supported yet
  292. ***** ^ not supported yet
  293. 149 IF NdxFiles.PutField( DestFile, RecName, 'RECORD', TypeCode,
  294. ***** ^ not supported yet
  295. ***** ^ not supported yet
  296. ***** ^ not supported yet
  297. ***** ^ not supported yet
  298. ***** ^ not supported yet
  299. 150 TmpList2 ) THEN
  300. ***** ^ not supported yet
  301. 151 IF NdxFiles.WriteRecord( DestFile, RecName ) THEN
  302. ***** ^ not supported yet
  303. ***** ^ not supported yet
  304. ***** ^ not supported yet
  305. ***** ^ not supported yet
  306. 152 IF NdxFiles.DeleteRecord( SourceFile, RecName ) THEN
  307. ***** ^ not supported yet
  308. ***** ^ not supported yet
  309. ***** ^ not supported yet
  310. ***** ^ not supported yet
  311. 153 RETURN TRUE;
  312. 154 END;
  313. 155 END;
  314. 156 END;
  315. 157 END;
  316. 158 END;
  317. 159 RETURN FALSE;
  318. 160 END TransferRecord;
  319. ***** ^ not supported yet
  320. 161
  321. 162
  322. 163 PROCEDURE ExportToFile( NdxFile: NdxTypes.NdxFileType; RecNameList:
  323. ***** ^ not supported yet
  324. 164 GenLists.GenList; fhandle: CARDINAL );
  325. ***** ^ not supported yet
  326. 165 (* exports records to a plain ascii file *)
  327. 166 VAR
  328. 167 lngth, cnt, TypeCode: CARDINAL;
  329. 168 TmpStr: NdxTypes.RecNameStr;
  330. ***** ^ not supported yet
  331. 169 TmpList: GenLists.GenList;
  332. ***** ^ not supported yet
  333. 170 SearchingAll: BOOLEAN;
  334. 171 TmpNdxRec: NdxTypes.NdxElement;
  335. ***** ^ not supported yet
  336. 172 BEGIN
  337. 173 lngth := GenLists.ListLength( RecNameList );
  338. ***** ^ not supported yet
  339. ***** ^ not supported yet
  340. ***** ^ not supported yet
  341. 174 IF lngth = 0 THEN
  342. 175 SearchingAll := TRUE;
  343. 176 lngth := GenLists.ListLength( NdxFile^.Ndx );
  344. ***** ^ not supported yet
  345. ***** ^ not supported yet
  346. ***** ^ not supported yet
  347. ***** ^ not supported yet
  348. 177 ELSE
  349. 178 SearchingAll := FALSE;
  350. 179 END;
  351. 180 FOR cnt := 1 TO lngth DO
  352. 181 IF SearchingAll THEN
  353. 182 GenLists.GetElmt( NdxFile^.Ndx, cnt, TmpNdxRec, TypeCode );
  354. ***** ^ not supported yet
  355. ***** ^ not supported yet
  356. ***** ^ not supported yet
  357. ***** ^ not supported yet
  358. ***** ^ not supported yet
  359. ***** ^ not supported yet
  360. 183 StrEdit.AssignStr( TmpNdxRec.RecName, TmpStr );
  361. ***** ^ not supported yet
  362. ***** ^ not supported yet
  363. ***** ^ not supported yet
  364. ***** ^ not supported yet
  365. ***** ^ not supported yet
  366. 184 ELSE
  367. 185 GenLists.GetElmt( RecNameList, cnt, TmpStr, TypeCode );
  368. ***** ^ not supported yet
  369. ***** ^ not supported yet
  370. ***** ^ not supported yet
  371. ***** ^ not supported yet
  372. ***** ^ not supported yet
  373. 186 (*Put the cnt'th record name in TmpStr.*)
  374. 187 END;
  375. 188 IF (M2Strings.Length( TmpStr ) > 0) AND
  376. ***** ^ not supported yet
  377. ***** ^ not supported yet
  378. ***** ^ not supported yet
  379. 189 (0 # M2Strings.CompareStr( TmpStr, (*BuildLst.ListStorageRec*)
  380. ***** ^ not supported yet
  381. ***** ^ not supported yet
  382. ***** ^ not supported yet
  383. 190 'qQqQqQqQ' )) THEN
  384. ***** ^ not supported yet
  385. 191 (*Next, get the entire record.*)
  386. 192 IF NOT NdxFiles.GetField( NdxFile, TmpStr, 'RECORD', TypeCode,
  387. ***** ^ not supported yet
  388. ***** ^ not supported yet
  389. ***** ^ not supported yet
  390. ***** ^ not supported yet
  391. ***** ^ not supported yet
  392. 193 TmpList ) THEN
  393. ***** ^ not supported yet
  394. 194 StringIO.WriteStr( fhandle, TmpStr );
  395. ***** ^ not supported yet
  396. ***** ^ not supported yet
  397. ***** ^ not supported yet
  398. 195 StringIO.WriteEol( fhandle, ' is not a record in this file.' );
  399. ***** ^ not supported yet
  400. ***** ^ not supported yet
  401. ***** ^ not supported yet
  402. 196 END;
  403. 197 (*We are assuming TypeCode will always = ListCode here.*)
  404. 198 ListUtils.PrintList( fhandle, TmpList, 0, ',' );
  405. ***** ^ not supported yet
  406. ***** ^ not supported yet
  407. ***** ^ not supported yet
  408. ***** ^ not supported yet
  409. 199 END;
  410. 200 END;
  411. 201 END ExportToFile;
  412. ***** ^ not supported yet
  413. 202
  414. 203
  415. 204 PROCEDURE SizeInfo( VAR NdxFile: NdxTypes.NdxFileType; VAR TotlSize,
  416. ***** ^ not supported yet
  417. 205 GbgSize: LONGINT; VAR PctUsed, NumDataRecs, NumGbgRecs:
  418. 206 CARDINAL);
  419. 207 VAR
  420. 208 CardTotalRecs: CARDINAL;
  421. 209 long2, long1, NdxElemSize, LongTotalRecs : LONGINT;
  422. 210 (*We use these temporary variables to avoid bugs in
  423. 211 Logitech's v3.03 compiler.*)
  424. 212 BEGIN
  425. 213 GarbageSize( NdxFile^.Ndx, GbgSize, NumDataRecs, NumGbgRecs);
  426. ***** ^ undeclared identifier
  427. ***** ^ not supported yet
  428. ***** ^ not supported yet
  429. ***** ^ not supported yet
  430. 214 (* returns total size of garbage data and number of records *)
  431. 215 CardTotalRecs := NumDataRecs + NumGbgRecs;
  432. 216 NdxElemSize := Numbers.Lc( SYSTEM.TSIZE(NdxElement));
  433. ***** ^ not supported yet
  434. ***** ^ not supported yet
  435. ***** ^ not supported yet
  436. ***** ^ not supported yet
  437. ***** ^ not supported yet
  438. 217 LongTotalRecs := Numbers.Lc( CardTotalRecs);
  439. ***** ^ not supported yet
  440. ***** ^ not supported yet
  441. ***** ^ not supported yet
  442. 218 long1 := (NdxElemSize * LongTotalRecs);
  443. 219 TotlSize := NdxFile^.NdxFilePtr + long1;
  444. ***** ^ not supported yet
  445. ***** ^ not supported yet
  446. 220 INC( TotlSize, 6 );
  447. ***** ^ undeclared identifier
  448. ***** ^ not supported yet
  449. 221 long2 := Numbers.Lc( NumGbgRecs);
  450. ***** ^ not supported yet
  451. ***** ^ not supported yet
  452. ***** ^ not supported yet
  453. 222 long1 := (NdxElemSize * long2);
  454. 223 GbgSize := GbgSize + long1;
  455. 224 (* add size of garbage index entries to garbage size of data *)
  456. 225 long1 := GbgSize * Numbers.Lc( 100);
  457. ***** ^ not supported yet
  458. ***** ^ not supported yet
  459. ***** ^ not supported yet
  460. 226 long2 := long1 DIV TotlSize;
  461. 227 PctUsed := 100 - Numbers.C( long2);
  462. ***** ^ not supported yet
  463. ***** ^ not supported yet
  464. ***** ^ not supported yet
  465. 228 END SizeInfo;
  466. ***** ^ not supported yet
  467. 229
  468. 230
  469. 231 PROCEDURE GetRecName( NdxFile: NdxTypes.NdxFileType; Which: CARDINAL;
  470. ***** ^ not supported yet
  471. 232 VAR RecName: ARRAY OF CHAR ): BOOLEAN;
  472. ***** ^ not supported yet
  473. 233 (* returns name of Which'th ndx element, or FALSE if not found *)
  474. 234 VAR
  475. 235 NdxEl : NdxTypes.NdxElement;
  476. ***** ^ not supported yet
  477. 236 TheType: CARDINAL;
  478. 237 BEGIN
  479. 238 NdxTypes.CheckInit( NdxFile);
  480. ***** ^ not supported yet
  481. ***** ^ not supported yet
  482. ***** ^ not supported yet
  483. 239 IF GenLists.ListLength( NdxFile^.Ndx) < Which THEN
  484. ***** ^ not supported yet
  485. ***** ^ not supported yet
  486. ***** ^ not supported yet
  487. ***** ^ not supported yet
  488. 240 RETURN FALSE;
  489. 241 END;
  490. 242 GenLists.GetElmt( NdxFile^.Ndx, Which, NdxEl, TheType);
  491. ***** ^ not supported yet
  492. ***** ^ not supported yet
  493. ***** ^ not supported yet
  494. ***** ^ not supported yet
  495. ***** ^ not supported yet
  496. ***** ^ not supported yet
  497. 243 StrEdit.AssignStr( NdxEl.RecName, RecName);
  498. ***** ^ not supported yet
  499. ***** ^ not supported yet
  500. ***** ^ not supported yet
  501. ***** ^ not supported yet
  502. ***** ^ not supported yet
  503. 244 RETURN M2Strings.Length(RecName) # 0;
  504. ***** ^ not supported yet
  505. ***** ^ not supported yet
  506. ***** ^ not supported yet
  507. 245 (* Return FALSE if index entry is marked as garbage *)
  508. 246 END GetRecName;
  509. ***** ^ not supported yet
  510. 247
  511. 248
  512. 249 PROCEDURE GetRecNames( NdxFile: NdxTypes.NdxFileType;
  513. ***** ^ not supported yet
  514. 250 VAR NameList: GenLists.GenList );
  515. ***** ^ not supported yet
  516. 251 VAR
  517. 252 TmpElmt: NdxTypes.NdxElement;
  518. ***** ^ not supported yet
  519. 253 lngth, cnt, TypeCode : CARDINAL;
  520. 254 BEGIN
  521. 255 GenLists.NewList( NameList );
  522. ***** ^ not supported yet
  523. ***** ^ not supported yet
  524. ***** ^ not supported yet
  525. 256 lngth := GenLists.ListLength( NdxFile^.Ndx );
  526. ***** ^ not supported yet
  527. ***** ^ not supported yet
  528. ***** ^ not supported yet
  529. ***** ^ not supported yet
  530. 257 FOR cnt := 1 TO lngth DO
  531. 258 GenLists.GetElmt( NdxFile^.Ndx, cnt, TmpElmt, TypeCode );
  532. ***** ^ not supported yet
  533. ***** ^ not supported yet
  534. ***** ^ not supported yet
  535. ***** ^ not supported yet
  536. ***** ^ not supported yet
  537. ***** ^ not supported yet
  538. 259 StrEdit.CrunchBlanks( TmpElmt.RecName );
  539. ***** ^ not supported yet
  540. ***** ^ not supported yet
  541. ***** ^ not supported yet
  542. ***** ^ not supported yet
  543. 260 IF (NOT PosUtils.Equal(TmpElmt.RecName, 'qQqQqQqQ'
  544. ***** ^ not supported yet
  545. ***** ^ not supported yet
  546. ***** ^ not supported yet
  547. ***** ^ not supported yet
  548. ***** ^ not supported yet
  549. 261 (*BuildLst.ListStorageRec*)) )
  550. 262 AND (M2Strings.Length( TmpElmt.RecName ) > 0) THEN
  551. ***** ^ not supported yet
  552. ***** ^ not supported yet
  553. ***** ^ not supported yet
  554. ***** ^ not supported yet
  555. 263 GenLists.ListInsert( TmpElmt.RecName, GenLists.StrCode,
  556. ***** ^ not supported yet
  557. ***** ^ not supported yet
  558. ***** ^ not supported yet
  559. ***** ^ not supported yet
  560. ***** ^ not supported yet
  561. ***** ^ not supported yet
  562. 264 NameList, 65535 );
  563. ***** ^ not supported yet
  564. ***** ^ not supported yet
  565. 265 END;
  566. 266 END;
  567. 267 END GetRecNames;
  568. ***** ^ not supported yet
  569. 268
  570. 269
  571. 270 PROCEDURE GarbageSize( VAR TheNdx: GenLists.GenList; VAR GbgSize:
  572. ***** ^ not supported yet
  573. 271 LONGINT; VAR NumDataRecs, NumGbgRecs: CARDINAL);
  574. 272 VAR
  575. 273 cnt, dum: CARDINAL;
  576. 274 TheElmt: NdxTypes.NdxElement;
  577. ***** ^ not supported yet
  578. 275 long1: LONGINT;
  579. 276 BEGIN
  580. 277 GbgSize := NumTypes.L0;
  581. ***** ^ not supported yet
  582. ***** ^ not supported yet
  583. 278 NumGbgRecs := 0;
  584. 279 NumDataRecs := GenLists.ListLength( TheNdx);
  585. ***** ^ not supported yet
  586. ***** ^ not supported yet
  587. ***** ^ not supported yet
  588. 280 FOR cnt := 1 TO NumDataRecs DO
  589. 281 GenLists.GetElmt( TheNdx, cnt, TheElmt, dum);
  590. ***** ^ not supported yet
  591. ***** ^ not supported yet
  592. ***** ^ not supported yet
  593. ***** ^ not supported yet
  594. ***** ^ not supported yet
  595. 282 IF TheElmt.UsedChars < TheElmt.Allocated THEN
  596. ***** ^ not supported yet
  597. ***** ^ not supported yet
  598. ***** ^ not supported yet
  599. ***** ^ not supported yet
  600. 283 (* for every record with any gargbage in it *)
  601. 284 dum := TheElmt.Allocated - TheElmt.UsedChars;
  602. ***** ^ not supported yet
  603. ***** ^ not supported yet
  604. ***** ^ not supported yet
  605. ***** ^ not supported yet
  606. 285 (*We do this in steps because of bugs in Logitech's
  607. 286 v3.03 LONGINTs.*)
  608. 287 long1 := Numbers.Lc(dum);
  609. ***** ^ not supported yet
  610. ***** ^ not supported yet
  611. ***** ^ not supported yet
  612. 288 GbgSize := GbgSize + long1;
  613. 289 IF TheElmt.UsedChars = 0 THEN
  614. ***** ^ not supported yet
  615. ***** ^ not supported yet
  616. 290 INC( NumGbgRecs);
  617. ***** ^ undeclared identifier
  618. ***** ^ not supported yet
  619. 291 END;
  620. 292 END;
  621. 293 END;
  622. 294 DEC( NumDataRecs, NumGbgRecs);
  623. ***** ^ undeclared identifier
  624. ***** ^ not supported yet
  625. 295 END GarbageSize;
  626. ***** ^ not supported yet
  627. 296
  628. 297 PROCEDURE ByFilePos(adr1: SYSTEM.ADDRESS; size1: CARDINAL;
  629. ***** ^ not supported yet
  630. 298 adr2: SYSTEM.ADDRESS; size2: CARDINAL): INTEGER;
  631. ***** ^ not supported yet
  632. 299 (*We pass this procedure to the procedure variable parameter
  633. 300 of SortList to make it sort the Ndx according to position
  634. 301 of the record in the file. Used only in CrunchNdxFile,
  635. 302 but we can't make it local to that procedure because of
  636. 303 an implementation restriction in Logitech's handling of
  637. 304 procedure variables.*)
  638. 305 VAR
  639. 306 tmpsize: CARDINAL;
  640. 307 tmp1, tmp2: NdxTypes.NdxElement;
  641. ***** ^ not supported yet
  642. 308 BEGIN
  643. 309 tmpsize := SYSTEM.TSIZE( NdxElement );
  644. ***** ^ not supported yet
  645. ***** ^ not supported yet
  646. ***** ^ not supported yet
  647. 310 LowLevel.Move( adr1, SYSTEM.ADR(tmp1), tmpsize );
  648. ***** ^ not supported yet
  649. ***** ^ not supported yet
  650. ***** ^ not supported yet
  651. ***** ^ not supported yet
  652. ***** ^ not supported yet
  653. ***** ^ not supported yet
  654. ***** ^ not supported yet
  655. 311 LowLevel.Move( adr2, SYSTEM.ADR(tmp2), tmpsize );
  656. ***** ^ not supported yet
  657. ***** ^ not supported yet
  658. ***** ^ not supported yet
  659. ***** ^ not supported yet
  660. ***** ^ not supported yet
  661. ***** ^ not supported yet
  662. ***** ^ not supported yet
  663. 312 IF tmp1.FilePos > tmp2.FilePos THEN
  664. ***** ^ not supported yet
  665. ***** ^ not supported yet
  666. ***** ^ not supported yet
  667. ***** ^ not supported yet
  668. 313 RETURN 1;
  669. 314 ELSIF tmp1.FilePos < tmp2.FilePos THEN
  670. ***** ^ not supported yet
  671. ***** ^ not supported yet
  672. ***** ^ not supported yet
  673. ***** ^ not supported yet
  674. 315 RETURN -1;
  675. 316 ELSE
  676. 317 RETURN 0;
  677. 318 END;
  678. 319 END ByFilePos;
  679. ***** ^ not supported yet
  680. 320
  681. 321 PROCEDURE ByFileName( adr1: SYSTEM.ADDRESS; size1: CARDINAL; adr2:
  682. ***** ^ not supported yet
  683. 322 SYSTEM.ADDRESS; size2: CARDINAL ): INTEGER;
  684. ***** ^ not supported yet
  685. 323 (*We pass this procedure to the procedure variable parameter
  686. 324 of SortList to make it restore the Ndx to reverse
  687. 325 alphabetical order.*)
  688. 326 VAR
  689. 327 tmpsize: CARDINAL;
  690. 328 tmp1, tmp2: NdxTypes.NdxElement;
  691. ***** ^ not supported yet
  692. 329 BEGIN
  693. 330 tmpsize := SYSTEM.TSIZE(NdxElement);
  694. ***** ^ not supported yet
  695. ***** ^ not supported yet
  696. ***** ^ not supported yet
  697. 331 LowLevel.Move( adr1, SYSTEM.ADR(tmp1), tmpsize );
  698. ***** ^ not supported yet
  699. ***** ^ not supported yet
  700. ***** ^ not supported yet
  701. ***** ^ not supported yet
  702. ***** ^ not supported yet
  703. ***** ^ not supported yet
  704. ***** ^ not supported yet
  705. 332 LowLevel.Move( adr2, SYSTEM.ADR(tmp2), tmpsize );
  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. 333 RETURN - M2Strings.CompareStr( tmp1.RecName, tmp2.RecName );
  714. ***** ^ not supported yet
  715. ***** ^ not supported yet
  716. ***** ^ not supported yet
  717. ***** ^ not supported yet
  718. ***** ^ not supported yet
  719. ***** ^ not supported yet
  720. 334 END ByFileName;
  721. ***** ^ not supported yet
  722. 335
  723. 336 PROCEDURE CrunchNdxFile( VAR NdxFile: NdxTypes.NdxFileType );
  724. ***** ^ not supported yet
  725. 337 (*Copies the file over itself.*)
  726. 338
  727. 339 PROCEDURE MoveFileData( TheHandle: CARDINAL;
  728. 340 FromSpot, ToSpot: LONGINT; HowMuch: CARDINAL);
  729. 341 VAR
  730. 342 BytesCopied, BufSize, ChunkSize : CARDINAL;
  731. 343 bufadr: SYSTEM.ADDRESS;
  732. ***** ^ not supported yet
  733. 344 SavedMessage: CARDINAL;
  734. 345 TmpL : LONGINT;
  735. 346 BEGIN
  736. 347 BytesCopied := 0;
  737. 348 IF VStorage.DosAvail( HowMuch ) THEN
  738. ***** ^ not supported yet
  739. ***** ^ not supported yet
  740. ***** ^ not supported yet
  741. 349 BufSize := HowMuch;
  742. 350 ELSE
  743. 351 BufSize := EnvironUtils.MemAvail( 1000 );
  744. ***** ^ not supported yet
  745. ***** ^ not supported yet
  746. ***** ^ not supported yet
  747. 352 (*Guesses the amount of memory available to within 1000
  748. 353 bytes.*)
  749. 354 END;
  750. 355 VStorage.DosAlloc( bufadr, BufSize );
  751. ***** ^ not supported yet
  752. ***** ^ not supported yet
  753. ***** ^ not supported yet
  754. ***** ^ not supported yet
  755. 356 REPEAT
  756. 357 IF (HowMuch - BytesCopied) > BufSize THEN
  757. 358 ChunkSize := BufSize;
  758. 359 ELSE
  759. 360 ChunkSize := HowMuch - BytesCopied;
  760. 361 END;
  761. 362 TmpL := FromSpot + Numbers.Lc( BytesCopied);
  762. ***** ^ not supported yet
  763. ***** ^ not supported yet
  764. ***** ^ not supported yet
  765. 363 (*Necessary because of bugs in Logitech's LONGINT
  766. 364 arithmetic that have persisted into v3.03.*)
  767. 365 HandleIO.SetFilePtr( TheHandle, HandleIO.FromStart, TmpL );
  768. ***** ^ not supported yet
  769. ***** ^ not supported yet
  770. ***** ^ not supported yet
  771. ***** ^ not supported yet
  772. ***** ^ not supported yet
  773. 366 SavedMessage := HandleIO.BlockRead( TheHandle, bufadr, ChunkSize );
  774. ***** ^ not supported yet
  775. ***** ^ not supported yet
  776. ***** ^ not supported yet
  777. ***** ^ not supported yet
  778. 367 CASE SavedMessage OF
  779. 368 StringIO.NoError, StringIO.PartialRead, StringIO.EndOfFile:
  780. ***** ^ not supported yet
  781. ***** ^ not supported yet
  782. ***** ^ not supported yet
  783. ***** ^ not supported yet
  784. ***** ^ not supported yet
  785. ***** ^ not supported yet
  786. 369 (*Do nothing.*);
  787. 370 ELSE
  788. 371 StringIO.PrintMessage( SavedMessage );
  789. ***** ^ not supported yet
  790. ***** ^ not supported yet
  791. ***** ^ not supported yet
  792. 372 (*Explains the error and aborts the program.*)
  793. 373 END;
  794. 374 TmpL := ToSpot + Numbers.Lc(BytesCopied);
  795. ***** ^ not supported yet
  796. ***** ^ not supported yet
  797. ***** ^ not supported yet
  798. 375 HandleIO.SetFilePtr( TheHandle, HandleIO.FromStart, TmpL );
  799. ***** ^ not supported yet
  800. ***** ^ not supported yet
  801. ***** ^ not supported yet
  802. ***** ^ not supported yet
  803. ***** ^ not supported yet
  804. 376 SavedMessage := HandleIO.BlockWrite( TheHandle, bufadr, ChunkSize );
  805. ***** ^ not supported yet
  806. ***** ^ not supported yet
  807. ***** ^ not supported yet
  808. ***** ^ not supported yet
  809. 377 CASE SavedMessage OF
  810. 378 StringIO.NoError, StringIO.PartialRead, StringIO.EndOfFile:
  811. ***** ^ not supported yet
  812. ***** ^ not supported yet
  813. ***** ^ not supported yet
  814. ***** ^ not supported yet
  815. ***** ^ not supported yet
  816. ***** ^ not supported yet
  817. 379 (*Do nothing.*);
  818. 380 ELSE
  819. 381 StringIO.PrintMessage( SavedMessage );
  820. ***** ^ not supported yet
  821. ***** ^ not supported yet
  822. ***** ^ not supported yet
  823. 382 (*Explains the error and aborts the program.*)
  824. 383 END;
  825. 384 INC( BytesCopied, ChunkSize );
  826. ***** ^ undeclared identifier
  827. ***** ^ not supported yet
  828. 385 UNTIL BytesCopied = HowMuch;
  829. 386 VStorage.DosDealloc( bufadr, BufSize );
  830. ***** ^ not supported yet
  831. ***** ^ not supported yet
  832. ***** ^ not supported yet
  833. ***** ^ not supported yet
  834. 387 END MoveFileData;
  835. ***** ^ not supported yet
  836. 388
  837. 389 VAR
  838. 390 WritingSpot: LONGINT;
  839. 391 RecordCnt, TypeCode : CARDINAL;
  840. 392 TmpElmt: NdxTypes.NdxElement;
  841. ***** ^ not supported yet
  842. 393 ListReplaceNeeded : BOOLEAN;
  843. 394
  844. 395 BEGIN
  845. 396 (*CrunchNdxFile*)
  846. 397 NdxTypes.CheckInit( NdxFile );
  847. ***** ^ not supported yet
  848. ***** ^ not supported yet
  849. ***** ^ not supported yet
  850. 398 IF GenLists.ListLength( NdxFile^.Ndx ) = 0 THEN
  851. ***** ^ not supported yet
  852. ***** ^ not supported yet
  853. ***** ^ not supported yet
  854. ***** ^ not supported yet
  855. 399 (*empty file*)
  856. 400 RETURN;
  857. 401 END;
  858. 402
  859. 403 HandleIO.UpdateDisk( NdxFile^.handle );
  860. ***** ^ not supported yet
  861. ***** ^ not supported yet
  862. ***** ^ not supported yet
  863. ***** ^ not supported yet
  864. 404 GenLists.SortList( NdxFile^.Ndx, ByFilePos );
  865. ***** ^ not supported yet
  866. ***** ^ not supported yet
  867. ***** ^ not supported yet
  868. ***** ^ not supported yet
  869. ***** ^ not supported yet
  870. 405 RecordCnt := 1;
  871. 406 GenLists.GetElmt(NdxFile^.Ndx, RecordCnt, TmpElmt, TypeCode);
  872. ***** ^ not supported yet
  873. ***** ^ not supported yet
  874. ***** ^ not supported yet
  875. ***** ^ not supported yet
  876. ***** ^ not supported yet
  877. ***** ^ not supported yet
  878. 407 WritingSpot := TmpElmt.FilePos;
  879. ***** ^ not supported yet
  880. ***** ^ not supported yet
  881. 408 (*Skip the structure record.*)
  882. 409 ListReplaceNeeded := FALSE;
  883. 410 WHILE RecordCnt <= GenLists.ListLength(NdxFile^.Ndx) DO
  884. ***** ^ not supported yet
  885. ***** ^ not supported yet
  886. ***** ^ not supported yet
  887. ***** ^ not supported yet
  888. 411 (* We look at every element in the Ndx. *)
  889. 412 GenLists.GetElmt(NdxFile^.Ndx, RecordCnt, TmpElmt, TypeCode);
  890. ***** ^ not supported yet
  891. ***** ^ not supported yet
  892. ***** ^ not supported yet
  893. ***** ^ not supported yet
  894. ***** ^ not supported yet
  895. ***** ^ not supported yet
  896. 413 IF (M2Strings.Length(TmpElmt.RecName) > 0) THEN
  897. ***** ^ not supported yet
  898. ***** ^ not supported yet
  899. ***** ^ not supported yet
  900. ***** ^ not supported yet
  901. 414 IF TmpElmt.FilePos > WritingSpot THEN
  902. ***** ^ not supported yet
  903. ***** ^ not supported yet
  904. 415 (* If the record starts farther into the file than we think it's
  905. 416 supposed to start. *)
  906. 417 MoveFileData( NdxFile^.handle, TmpElmt.FilePos,
  907. ***** ^ not supported yet
  908. ***** ^ not supported yet
  909. ***** ^ not supported yet
  910. ***** ^ not supported yet
  911. ***** ^ not supported yet
  912. 418 WritingSpot, TmpElmt.UsedChars );
  913. ***** ^ not supported yet
  914. ***** ^ not supported yet
  915. 419 (* In NdxFile^.handle, move TmpElmt.UsedChars from TmpElmt.FilePos
  916. 420 to WritingSpot. *)
  917. 421 TmpElmt.FilePos := WritingSpot;
  918. ***** ^ not supported yet
  919. ***** ^ not supported yet
  920. 422 NdxFile^.UpdateNeeded := TRUE;
  921. ***** ^ not supported yet
  922. ***** ^ not supported yet
  923. 423 ListReplaceNeeded := TRUE;
  924. 424 ELSIF TmpElmt.Allocated > TmpElmt.UsedChars THEN
  925. ***** ^ not supported yet
  926. ***** ^ not supported yet
  927. ***** ^ not supported yet
  928. ***** ^ not supported yet
  929. 425 (* We know that the amount of space allocated to this record is
  930. 426 going to be reduced in the next loop, so we go ahead and update
  931. 427 its entry in the Ndx. *)
  932. 428 ListReplaceNeeded := TRUE;
  933. 429 END;
  934. 430 IF ListReplaceNeeded THEN
  935. 431 TmpElmt.Allocated := TmpElmt.UsedChars;
  936. ***** ^ not supported yet
  937. ***** ^ not supported yet
  938. ***** ^ not supported yet
  939. ***** ^ not supported yet
  940. 432 GenLists.ListReplace(TmpElmt, TypeCode, NdxFile^.Ndx, RecordCnt);
  941. ***** ^ not supported yet
  942. ***** ^ not supported yet
  943. ***** ^ not supported yet
  944. ***** ^ not supported yet
  945. ***** ^ not supported yet
  946. ***** ^ not supported yet
  947. 433 ListReplaceNeeded := FALSE;
  948. 434 END;
  949. 435 WritingSpot := WritingSpot + Numbers.Lc( TmpElmt.UsedChars );
  950. ***** ^ not supported yet
  951. ***** ^ not supported yet
  952. ***** ^ not supported yet
  953. ***** ^ not supported yet
  954. 436 (* Since we increment WritingSpot by TmpElmt.UsedChars instead of by
  955. 437 TmpElmt.Allocated, when we look at the next record, its FilePos
  956. 438 will be greater than WritingSpot, so we will crunch out small bits
  957. 439 of garbage at the ends of records. *)
  958. 440 INC( RecordCnt );
  959. ***** ^ undeclared identifier
  960. ***** ^ not supported yet
  961. 441 ELSE
  962. 442 (* The length of the RecName is 0, so we know it's a garbage record.*)
  963. 443 GenLists.ListDelete( NdxFile^.Ndx, RecordCnt, 1 );
  964. ***** ^ not supported yet
  965. ***** ^ not supported yet
  966. ***** ^ not supported yet
  967. ***** ^ not supported yet
  968. ***** ^ not supported yet
  969. 444 NdxFile^.UpdateNeeded := TRUE;
  970. ***** ^ not supported yet
  971. ***** ^ not supported yet
  972. 445 END;
  973. 446 END; (*WHILE*)
  974. 447 NdxFile^.NdxFilePtr := WritingSpot;
  975. ***** ^ not supported yet
  976. ***** ^ not supported yet
  977. 448 (*Sets the position of the NdxMarker.*)
  978. 449 IF GenLists.ListLength( NdxFile^.Ndx ) > 0 THEN
  979. ***** ^ not supported yet
  980. ***** ^ not supported yet
  981. ***** ^ not supported yet
  982. ***** ^ not supported yet
  983. 450 GenLists.SortList( NdxFile^.Ndx, ByFileName );
  984. ***** ^ not supported yet
  985. ***** ^ not supported yet
  986. ***** ^ not supported yet
  987. ***** ^ not supported yet
  988. ***** ^ not supported yet
  989. 451 (*Put the Ndx list back into reverse alphabetical order.*)
  990. 452 END;
  991. 453 IF NdxFile^.UpdateNeeded THEN
  992. ***** ^ not supported yet
  993. ***** ^ not supported yet
  994. 454 NdxFiles.WriteNdx( NdxFile );
  995. ***** ^ not supported yet
  996. ***** ^ not supported yet
  997. ***** ^ not supported yet
  998. 455 END;
  999. 456 END CrunchNdxFile;
  1000. ***** ^ not supported yet
  1001. 457
  1002. 458
  1003. 459 PROCEDURE RebuildNdx( VAR NdxFile: NdxTypes.NdxFileType );
  1004. ***** ^ not supported yet
  1005. 460 (*Scans a file for record separators and builds a new linked
  1006. 461 list of record names, record sizes, and file offsets, then
  1007. 462 writes the list to the file, beginning at the last byte of
  1008. 463 the last record in the file. Used to repair damaged
  1009. 464 NdxFiles. *)
  1010. 465 CONST
  1011. 466 DuplicateNameMessage =
  1012. 467 'Duplicate RecName found. Will try to make it unique';
  1013. ***** ^ not supported yet
  1014. 468 IrreparableMsg = 'NdxFile may be irreparably damaged';
  1015. ***** ^ not supported yet
  1016. 469
  1017. 470 VAR
  1018. 471 RecFound, FileEndReached, NdxMarkFound, Garbage, FirstChar:
  1019. 472 BOOLEAN;
  1020. 473 bufch: CHAR;
  1021. 474 L4, ThisEndSpot, FileSize, BytesToRead, LastSpot, FileSpot: LONGINT;
  1022. 475 NdxElemSize, NestingLevel, cnt, BufSize, BufSpot, ZeroRecSize,
  1023. 476 ChunkSize, memory: CARDINAL;
  1024. 477 buf: LowLevel.Address8086;
  1025. ***** ^ not supported yet
  1026. 478 OldNdxElmt, NewNdxElmt: NdxTypes.NdxElement;
  1027. ***** ^ not supported yet
  1028. 479 TmpRecName: NdxTypes.RecNameStr;
  1029. ***** ^ not supported yet
  1030. 480 TmpStr: ARRAY [0..127] OF CHAR;
  1031. ***** ^ not supported yet
  1032. ***** ^ not supported yet
  1033. 481
  1034. 482 PROCEDURE MakeUniqueName( InStr: ARRAY OF CHAR;
  1035. ***** ^ not supported yet
  1036. 483 VAR OutStr: ARRAY OF CHAR);
  1037. ***** ^ not supported yet
  1038. 484 VAR
  1039. 485 dumc: CARDINAL;
  1040. 486 TimeStr: ARRAY [0..30] OF CHAR;
  1041. ***** ^ not supported yet
  1042. ***** ^ not supported yet
  1043. 487 BEGIN
  1044. 488 StrEdit.AssignStr( InStr, OutStr );
  1045. ***** ^ not supported yet
  1046. ***** ^ not supported yet
  1047. ***** ^ not supported yet
  1048. ***** ^ not supported yet
  1049. 489 EnvironUtils.GetTime(dumc,dumc,dumc,dumc, TimeStr);
  1050. ***** ^ not supported yet
  1051. ***** ^ not supported yet
  1052. ***** ^ not supported yet
  1053. 490 StrEdit.DeleteChar( ':', TimeStr );
  1054. ***** ^ not supported yet
  1055. ***** ^ not supported yet
  1056. ***** ^ not supported yet
  1057. 491 StrEdit.DeleteChar( ' ', TimeStr );
  1058. ***** ^ not supported yet
  1059. ***** ^ not supported yet
  1060. ***** ^ not supported yet
  1061. 492 IF M2Strings.Length(OutStr) < (HIGH(OutStr) - 1) THEN
  1062. ***** ^ not supported yet
  1063. ***** ^ not supported yet
  1064. ***** ^ not supported yet
  1065. ***** ^ undeclared identifier
  1066. ***** ^ not supported yet
  1067. 493 M2Strings.Delete( TimeStr, 1, M2Strings.Length(TimeStr) - 2 );
  1068. ***** ^ not supported yet
  1069. ***** ^ not supported yet
  1070. ***** ^ not supported yet
  1071. ***** ^ not supported yet
  1072. ***** ^ not supported yet
  1073. ***** ^ not supported yet
  1074. ***** ^ not supported yet
  1075. 494 StrEdit.Append( OutStr, TimeStr );
  1076. ***** ^ not supported yet
  1077. ***** ^ not supported yet
  1078. ***** ^ not supported yet
  1079. ***** ^ not supported yet
  1080. 495 ELSE
  1081. 496 StrEdit.AssignStr( TimeStr, OutStr );
  1082. ***** ^ not supported yet
  1083. ***** ^ not supported yet
  1084. ***** ^ not supported yet
  1085. ***** ^ not supported yet
  1086. 497 END;
  1087. 498 END MakeUniqueName;
  1088. ***** ^ not supported yet
  1089. 499
  1090. 500 PROCEDURE NextChar(): CHAR;
  1091. 501 VAR
  1092. 502 tmpch: CHAR;
  1093. 503 SavedMessage: CARDINAL;
  1094. 504 BEGIN
  1095. 505 IF FirstChar THEN
  1096. 506 (*We only want to allocate our buffer on the first
  1097. 507 call.*)
  1098. 508 FirstChar := FALSE;
  1099. 509 FileSpot := NumTypes.L0;
  1100. ***** ^ not supported yet
  1101. ***** ^ not supported yet
  1102. 510 (*FileSpot tracks our position in the file.*)
  1103. 511 BytesToRead := FileSize;
  1104. 512 IF BytesToRead > Numbers.Lc( 65000) THEN
  1105. ***** ^ not supported yet
  1106. ***** ^ not supported yet
  1107. ***** ^ not supported yet
  1108. 513 (*We make it a little less than 64K because the Storage
  1109. 514 module can't really allocate a full 64K block.*)
  1110. 515 BufSize := 65000;
  1111. 516 ELSE
  1112. 517 BufSize := Numbers.C( BytesToRead );
  1113. ***** ^ not supported yet
  1114. ***** ^ not supported yet
  1115. ***** ^ not supported yet
  1116. 518 END;
  1117. 519 memory := EnvironUtils.MemAvail( 5000 );
  1118. ***** ^ not supported yet
  1119. ***** ^ not supported yet
  1120. ***** ^ not supported yet
  1121. 520 (*Guess the amount of memory available, to within 5000
  1122. 521 bytes.*)
  1123. 522 IF memory < BufSize THEN
  1124. 523 BufSize := memory;
  1125. 524 END;
  1126. 525 VStorage.DosAlloc( buf.a, BufSize );
  1127. ***** ^ not supported yet
  1128. ***** ^ not supported yet
  1129. ***** ^ not supported yet
  1130. ***** ^ not supported yet
  1131. ***** ^ not supported yet
  1132. 526 BufSpot := BufSize;
  1133. 527 (*We do this so that we'll begin by doing a BlockRead,
  1134. 528 just as we would if we'd reached the end of a buffer.*)
  1135. 529 ChunkSize := BufSize;
  1136. 530 END;
  1137. 531 IF BytesToRead = NumTypes.L0 THEN
  1138. ***** ^ not supported yet
  1139. ***** ^ not supported yet
  1140. 532 FileEndReached := TRUE;
  1141. 533 RETURN 0C;
  1142. 534 END;
  1143. 535 IF (BufSpot >= ChunkSize) THEN
  1144. 536 IF BytesToRead < Numbers.Lc( BufSize) THEN
  1145. ***** ^ not supported yet
  1146. ***** ^ not supported yet
  1147. ***** ^ not supported yet
  1148. 537 (*If we have fewer bytes to read than will fit in the
  1149. 538 buffer.*)
  1150. 539 ChunkSize := Numbers.C( BytesToRead );
  1151. ***** ^ not supported yet
  1152. ***** ^ not supported yet
  1153. ***** ^ not supported yet
  1154. 540 END;
  1155. 541 HandleIO.SetFilePtr( NdxFile^.handle, HandleIO.FromStart, FileSpot );
  1156. ***** ^ not supported yet
  1157. ***** ^ not supported yet
  1158. ***** ^ not supported yet
  1159. ***** ^ not supported yet
  1160. ***** ^ not supported yet
  1161. ***** ^ not supported yet
  1162. ***** ^ not supported yet
  1163. 542 SavedMessage := HandleIO.BlockRead( NdxFile^.handle, buf.a,
  1164. ***** ^ not supported yet
  1165. ***** ^ not supported yet
  1166. ***** ^ not supported yet
  1167. ***** ^ not supported yet
  1168. ***** ^ not supported yet
  1169. ***** ^ not supported yet
  1170. 543 ChunkSize );
  1171. ***** ^ not supported yet
  1172. 544 (*This is where we actually load the buffer.*)
  1173. 545 IF (SavedMessage # StringIO.NoError)
  1174. ***** ^ not supported yet
  1175. ***** ^ not supported yet
  1176. 546 AND
  1177. 547 (SavedMessage # StringIO.PartialRead)
  1178. ***** ^ not supported yet
  1179. ***** ^ not supported yet
  1180. 548 AND
  1181. 549 (SavedMessage # StringIO.EndOfFile) THEN
  1182. ***** ^ not supported yet
  1183. ***** ^ not supported yet
  1184. 550 StringIO.PrintMessage( SavedMessage );
  1185. ***** ^ not supported yet
  1186. ***** ^ not supported yet
  1187. ***** ^ not supported yet
  1188. 551 END;
  1189. 552 BufSpot := 0;
  1190. 553 END;
  1191. 554 tmpch := LowLevel.PeekByte( buf.seg, buf.off + BufSpot );
  1192. ***** ^ not supported yet
  1193. ***** ^ not supported yet
  1194. ***** ^ not supported yet
  1195. ***** ^ not supported yet
  1196. ***** ^ not supported yet
  1197. ***** ^ not supported yet
  1198. ***** ^ not supported yet
  1199. 555 INC( BufSpot );
  1200. ***** ^ undeclared identifier
  1201. ***** ^ not supported yet
  1202. 556 INC( FileSpot );
  1203. ***** ^ undeclared identifier
  1204. ***** ^ not supported yet
  1205. 557 DEC( BytesToRead );
  1206. ***** ^ undeclared identifier
  1207. ***** ^ not supported yet
  1208. 558 IF BytesToRead = NumTypes.L0 THEN
  1209. ***** ^ not supported yet
  1210. ***** ^ not supported yet
  1211. 559 FileEndReached := TRUE;
  1212. 560 END;
  1213. 561 RETURN tmpch;
  1214. 562 END NextChar;
  1215. ***** ^ not supported yet
  1216. 563
  1217. 564 PROCEDURE NextCard(): CARDINAL;
  1218. 565 VAR
  1219. 566 conv : RECORD
  1220. 567 (*Used in swap and BytesToWord.*)
  1221. 568 CASE : BOOLEAN OF
  1222. ***** ^ not supported yet
  1223. ***** ^ 'POINTER' expected
  1224. 569 TRUE :
  1225. 570 x : CARDINAL;
  1226. 571 | FALSE :
  1227. 572 a, b : CHAR;
  1228. 573 END;
  1229. 574 END;
  1230. 575 BEGIN
  1231. 576 conv.a := NextChar();
  1232. 577 conv.b := NextChar();
  1233. 578 RETURN conv.x;
  1234. 579 END NextCard;
  1235. 580
  1236. 581
  1237. 582 PROCEDURE NdxEntryInsert( TmpElmt: NdxTypes.NdxElement;
  1238. 583 VAR NdxFile: NdxTypes.NdxFileType ): BOOLEAN;
  1239. 584 VAR
  1240. 585 dummylong: LONGINT;
  1241. 586 TheElmt, dummycard: CARDINAL;
  1242. 587 BEGIN
  1243. 588 IF NOT NdxBones.FindRecord( NdxFile, TmpElmt.RecName, dummylong,
  1244. 589 dummycard, TheElmt) THEN
  1245. 590 (*The FindRecord returns the alphabetically correct
  1246. 591 insertion point, TheElmt.*)
  1247. 592 GenLists.ListInsert( TmpElmt, NdxTypes.NdxTypeCode, NdxFile^.Ndx,
  1248. 593 TheElmt);
  1249. 594 RETURN TRUE;
  1250. 595 ELSE
  1251. 596 RETURN FALSE;
  1252. 597 END;
  1253. 598 END NdxEntryInsert;
  1254. 599
  1255. 600
  1256. 601 PROCEDURE SetName( RecName: ARRAY OF CHAR;
  1257. 602 VAR OldNdxElmt: NdxTypes.NdxElement );
  1258. 603 BEGIN
  1259. 604 IF OldNdxElmt.FilePos = NumTypes.L0 THEN
  1260. 605 (* This makes sure that we don't try to set the name of
  1261. 606 the last record while we're processing the first
  1262. 607 record in the file.*)
  1263. 608 RETURN;
  1264. 609 END;
  1265. 610 StrEdit.AssignStr( RecName, OldNdxElmt.RecName );
  1266. 611 IF M2Strings.Length( RecName ) > 0 THEN
  1267. 612 WHILE NOT NdxEntryInsert(OldNdxElmt, NdxFile ) DO
  1268. 613 StrEdit.AssignStr( DuplicateNameMessage, TmpStr );
  1269. 614 M2Strings.Insert( ': ', TmpStr, 0 );
  1270. 615 M2Strings.Insert( RecName, TmpStr, 0 );
  1271. 616 ErrorManager.WARN( TmpStr );
  1272. 617 MakeUniqueName(OldNdxElmt.RecName, OldNdxElmt.RecName);
  1273. 618 StrEdit.AssignStr( OldNdxElmt.RecName, TmpStr );
  1274. 619 M2Strings.Insert( 'Trying "', TmpStr, 0 );
  1275. 620 StrEdit.Append( TmpStr, '". Please note new name' );
  1276. 621 ErrorManager.WARN( TmpStr );
  1277. 622 END;
  1278. 623 ELSE
  1279. 624 GenLists.ListInsert(OldNdxElmt,
  1280. 625 NdxTypes.NdxTypeCode, NdxFile^.Ndx, 65535);
  1281. 626 (*appends OldNdxElmt to end of Ndx*)
  1282. 627 END;
  1283. 628 END SetName;
  1284. 629
  1285. 630 PROCEDURE SkipToNext();
  1286. 631 (* When something goes wrong in a record, we call this to try
  1287. 632 to skip ahead to the next thing that looks like the start
  1288. 633 of a record. It's not foolproof, but it ought to work
  1289. 634 most of the time.*)
  1290. 635 BEGIN
  1291. 636 StringIO.WriteEol( StringIO.outp, 'Skipping over this data:' );
  1292. 637 LOOP
  1293. 638 bufch := NextChar();
  1294. 639 StringIO.WriteStr( StringIO.outp, bufch );
  1295. 640 IF (bufch = NdxBones.CodeChar) THEN
  1296. 641 bufch := NextChar();
  1297. 642 IF bufch = NdxBones.NdxMarker[1] THEN
  1298. 643 NdxMarkFound := TRUE;
  1299. 644 EXIT;
  1300. 645 END;
  1301. 646 IF (bufch = NdxBones.StartSep[1]) AND
  1302. 647 (NextCard() = GenLists.ListCode) AND
  1303. 648 (NextChar() = NdxBones.CodeChar) AND
  1304. 649 (NextChar() = NdxBones.StartSep[1]) AND
  1305. 650 (NextCard() = GenLists.StrCode) THEN
  1306. 651 bufch := NextChar();
  1307. 652 IF (bufch = 'O') OR (bufch = 'G') THEN
  1308. 653 NestingLevel := 2;
  1309. 654 RecFound := TRUE;
  1310. 655 EXIT;
  1311. 656 END;
  1312. 657 END;
  1313. 658 END;
  1314. 659 END;
  1315. 660 END SkipToNext;
  1316. 661
  1317. 662 PROCEDURE TruncateChosen(): BOOLEAN;
  1318. 663 VAR
  1319. 664 tmp: ARRAY [0..15] OF CHAR;
  1320. 665 BEGIN
  1321. 666 StringIO.WriteEol( StringIO.outp, '' );
  1322. 667 StringIO.WriteStr( StringIO.outp,
  1323. 668 'Do you want to truncate the file here? ' );
  1324. 669 StringIO.ReadStr( StringIO.inp, tmp );
  1325. 670 IF CAP(tmp[0]) = 'Y' THEN
  1326. 671 NdxMarkFound := TRUE;
  1327. 672 RETURN TRUE;
  1328. 673 ELSE
  1329. 674 RETURN FALSE;
  1330. 675 END;
  1331. 676 END TruncateChosen;
  1332. 677
  1333. 678 PROCEDURE MarkBad( VAR RecName: ARRAY OF CHAR );
  1334. 679 VAR
  1335. 680 TmpStr: ARRAY [0..79] OF CHAR;
  1336. 681 BEGIN
  1337. 682 StrConv.LongIntegerToStr( FileSpot, 0, TmpStr );
  1338. 683 StrEdit.Append( TmpStr,
  1339. 684 '= file offset. This record has been corrupted: "' );
  1340. 685 StrEdit.Append( TmpStr, RecName );
  1341. 686 StrEdit.Append( TmpStr, '"' );
  1342. 687 ErrorManager.WARN( TmpStr );
  1343. 688 StrEdit.SetLength( RecName, 0 );
  1344. 689 END MarkBad;
  1345. 690
  1346. 691 BEGIN
  1347. 692 (*RebuildNdx*)
  1348. 693 NdxElemSize := SYSTEM.TSIZE(NdxElement);
  1349. 694 (*This gets us around a bug in the beta copy of v3.0.*)
  1350. 695 GenLists.NewList( NdxFile^.Ndx );
  1351. 696 (*Initialize the list in preparation for rebuilding it; we
  1352. 697 assume it hasn't yet been initialized.*)
  1353. 698 FileSize := HandleIO.FileLength( NdxFile^.handle );
  1354. 699 HandleIO.SetFilePtr( NdxFile^.handle, HandleIO.FromStart, NumTypes.L0 );
  1355. 700 LowLevel.Fill( SYSTEM.ADR(OldNdxElmt), NdxElemSize, 0C );
  1356. 701 LowLevel.Fill( SYSTEM.ADR(NewNdxElmt), NdxElemSize, 0C );
  1357. 702 StrEdit.SetLength( TmpRecName, 0 );
  1358. 703 NdxMarkFound := FALSE;
  1359. 704 FileEndReached := FALSE;
  1360. 705 FirstChar := TRUE;
  1361. 706 ZeroRecSize := NextCard();
  1362. 707 (*BufSpot should now be 2, because the byte at offset 2--the
  1363. 708 3rd byte--is the next one to be read.*)
  1364. 709 IF (FileSize < NumTypes.L65535) AND
  1365. 710 (ZeroRecSize > Numbers.C( FileSize)) THEN
  1366. 711 ErrorManager.WARN( IrreparableMsg );
  1367. 712 END;
  1368. 713 FOR cnt := 1 TO ZeroRecSize DO
  1369. 714 (*Skip the zero record because it just contains the
  1370. 715 structure.*)
  1371. 716 bufch := NextChar();
  1372. 717 END;
  1373. 718 NestingLevel := 1;
  1374. 719 RecFound := FALSE;
  1375. 720 LastSpot := NumTypes.L0;
  1376. 721 ThisEndSpot := NumTypes.L0;
  1377. 722 WHILE (NOT FileEndReached) AND (NOT NdxMarkFound) DO
  1378. 723 (*Find the next CodeChar.*)
  1379. 724 bufch := NextChar();
  1380. 725
  1381. 726 IF bufch = NdxBones.CodeChar THEN
  1382. 727 bufch := NextChar();
  1383. 728 (*find out what kind of separator this is*)
  1384. 729 IF bufch = NdxBones.StartSep[1] THEN
  1385. 730 INC( NestingLevel );
  1386. 731 bufch := NextChar();
  1387. 732 bufch := NextChar();
  1388. 733 (*Skip over the type code.*)
  1389. 734 IF NestingLevel = 2 THEN
  1390. 735 RecFound := TRUE;
  1391. 736 END;
  1392. 737 ELSIF bufch = NdxBones.EndSep[1] THEN
  1393. 738 DEC( NestingLevel );
  1394. 739 IF NestingLevel = 1 THEN
  1395. 740 ThisEndSpot := FileSpot;
  1396. 741 ELSIF NestingLevel = 0 THEN
  1397. 742 (*If NestingLevel gets back to 0 before we find the
  1398. 743 NdxMarker, we're done for.*)
  1399. 744 ErrorManager.WARN( IrreparableMsg );
  1400. 745 MarkBad( TmpRecName );
  1401. 746 IF NOT TruncateChosen() THEN
  1402. 747 SkipToNext();
  1403. 748 END;
  1404. 749 ThisEndSpot := FileSpot;
  1405. 750 END;
  1406. 751 ELSIF bufch = NdxBones.NdxMarker[1] THEN
  1407. 752 ThisEndSpot := FileSpot;
  1408. 753 NdxMarkFound := TRUE;
  1409. 754 ELSIF bufch = NdxBones.CodedStr[1] THEN
  1410. 755 (* This means there was a CodeChar embedded in the
  1411. 756 user's data. We just skip it. It will be decoded
  1412. 757 when it's read.*)
  1413. 758 ELSE
  1414. 759 StrConv.LongIntegerToStr( FileSpot, 0, TmpStr );
  1415. 760 M2Strings.Insert( '" ": illegal character at ', TmpStr, 0 );
  1416. 761 TmpStr[1] := bufch;
  1417. 762 ErrorManager.WARN( TmpStr );
  1418. 763 MarkBad( TmpRecName );
  1419. 764 IF NOT TruncateChosen() THEN
  1420. 765 SkipToNext();
  1421. 766 END;
  1422. 767 END;
  1423. 768 END;
  1424. 769
  1425. 770 IF (NOT NdxMarkFound) AND RecFound THEN
  1426. 771 RecFound := FALSE;
  1427. 772 (*We've just read the next record StartSep.*)
  1428. 773 LowLevel.Fill( SYSTEM.ADR(OldNdxElmt), NdxElemSize, 0C );
  1429. 774 OldNdxElmt.FilePos := LastSpot;
  1430. 775 (* position saved when last start sep was found *)
  1431. 776 OldNdxElmt.Allocated := Numbers.C( FileSpot - LastSpot);
  1432. 777 DEC( OldNdxElmt.Allocated, 4 );
  1433. 778 (* position when this rec startsep found minus
  1434. 779 position saved when last rec start sep was found *)
  1435. 780 IF M2Strings.Length(TmpRecName) > 0 THEN
  1436. 781 OldNdxElmt.UsedChars := Numbers.C( ThisEndSpot - LastSpot );
  1437. 782 (*position when this rec endsep found minus
  1438. 783 position saved when last rec start sep was found *)
  1439. 784 ELSE
  1440. 785 OldNdxElmt.UsedChars := 0;
  1441. 786 END;
  1442. 787 L4 := Numbers.Lc( 4);
  1443. 788 (*We do this to avoid a bug in Logitech's v3.0
  1444. 789 LONGINTs.*)
  1445. 790 LastSpot := FileSpot - L4;
  1446. 791
  1447. 792 SetName( TmpRecName, OldNdxElmt );
  1448. 793
  1449. 794 bufch := NextChar(); bufch := NextChar();
  1450. 795 (*Skip over the StartSep that starts the record name.*)
  1451. 796 bufch := NextChar(); bufch := NextChar();
  1452. 797 (*Skip over the record name type code.*)
  1453. 798 StrEdit.SetLength(TmpRecName, 0);
  1454. 799 bufch := NextChar();
  1455. 800 Garbage := bufch = 'G';
  1456. 801 LOOP
  1457. 802 (*This is where we get the record name, we keep it in
  1458. 803 TmpRecName until we get to the start of the next
  1459. 804 record or to the NdxMarker. SetName then assigns
  1460. 805 TmpRecName to the RecName field of OldNdxElmt, taking
  1461. 806 care of any duplication of names.*)
  1462. 807 bufch := NextChar();
  1463. 808 IF FileEndReached THEN
  1464. 809 EXIT;
  1465. 810 END;
  1466. 811 IF bufch = NdxBones.CodeChar THEN
  1467. 812 bufch := NextChar();
  1468. 813 IF bufch = NdxBones.EndSep[1] THEN
  1469. 814 IF Garbage THEN
  1470. 815 StrEdit.SetLength( TmpRecName, 0 );
  1471. 816 END;
  1472. 817 EXIT;
  1473. 818 END;
  1474. 819 ELSE
  1475. 820 StrEdit.Append( TmpRecName, bufch );
  1476. 821 END;
  1477. 822 END;
  1478. 823 StrEdit.CrunchBlanks( TmpRecName );
  1479. 824 ELSIF NdxMarkFound THEN
  1480. 825 LowLevel.Fill( SYSTEM.ADR(OldNdxElmt), NdxElemSize, 0C );
  1481. 826 OldNdxElmt.FilePos := LastSpot;
  1482. 827 (* position saved when last start sep was found *)
  1483. 828 OldNdxElmt.Allocated := Numbers.C( FileSpot - LastSpot);
  1484. 829 DEC( OldNdxElmt.Allocated, 2 );
  1485. 830 (* position when this rec startsep found minus
  1486. 831 position saved when last rec start sep was found *)
  1487. 832 IF M2Strings.Length( TmpRecName ) > 0 THEN
  1488. 833 OldNdxElmt.UsedChars := Numbers.C( ThisEndSpot - LastSpot);
  1489. 834 (*position when this rec endsep found minus
  1490. 835 position saved when last rec start sep was found *)
  1491. 836 ELSE
  1492. 837 OldNdxElmt.UsedChars := 0;
  1493. 838 END;
  1494. 839 NdxFile^.NdxFilePtr := FileSpot - NumTypes.L2;
  1495. 840 SetName( TmpRecName, OldNdxElmt );
  1496. 841 END;
  1497. 842 END;(*WHILE (NOT FileEndReached) AND (NOT NdxMarkFound)*)
  1498. 843
  1499. 844 IF (NOT NdxMarkFound) THEN
  1500. 845 IF LastSpot = NumTypes.L0 THEN
  1501. 846 ErrorNames.WarningName('NotNdx');
  1502. 847 ELSE
  1503. 848 NdxFile^.NdxFilePtr := LastSpot;
  1504. 849 END;
  1505. 850 END;
  1506. 851
  1507. 852 VStorage.DosDealloc( buf.a, BufSize );
  1508. 853 NdxFile^.BufSizeNow := 0;
  1509. 854 NdxFiles.WriteNdx( NdxFile );
  1510. 855 END RebuildNdx;
  1511. 856
  1512. 857 PROCEDURE AllowRebuild( VAR NdxFile: NdxTypes.NdxFileType );
  1513. 858 BEGIN
  1514. 859 ErrorManager.WARN( 'Damaged file. Will attempt to rebuild it' );
  1515. 860 RebuildNdx( NdxFile );
  1516. 861 END AllowRebuild;
  1517. 862
  1518. 863
  1519. 864 PROCEDURE Init();
  1520. 865 BEGIN
  1521. 866 IF Initialized THEN
  1522. 867 RETURN;
  1523. 868 ELSE
  1524. 869 Initialized := TRUE;
  1525. 870 END;
  1526. 871 (*EntryDiag:
  1527. 872 Diagnostics.Init();
  1528. 873 :EntryDiag*)
  1529. 874
  1530. 875 EnvironUtils.Init();
  1531. 876 ErrorManager.Init();
  1532. 877 ErrorNames.Init();
  1533. 878 HandleIO.Init();
  1534. 879 GenLists.Init();
  1535. 880 ListUtils.Init();
  1536. 881 LowLevel.Init();
  1537. 882 M2Strings.Init();
  1538. 883 NdxBones.Init();
  1539. 884 NdxFiles.Init();
  1540. 885 NdxTypes.Init();
  1541. 886 Numbers.Init();
  1542. 887 NumTypes.Init();
  1543. 888 PosUtils.Init();
  1544. 889 StrConv.Init();
  1545. 890 StrEdit.Init();
  1546. 891 StringIO.Init();
  1547. 892 VStorage.Init();
  1548. 893 (*EntryDiag:
  1549. 894 Diagnostics.diagS( 'Entering NdxUtils', '' );
  1550. 895 :EntryDiag*)
  1551. 896 NdxBones.RebuildProc := AllowRebuild;
  1552. 897 (*EntryDiag:
  1553. 898 Diagnostics.diagS( 'Exiting NdxUtils', '' );
  1554. 899 :EntryDiag*)
  1555. 900 END Init;
  1556. 901
  1557. 902
  1558. 903 BEGIN
  1559. 904 Initialized := FALSE;
  1560. 905 Init();
  1561. 906 END NdxUtils.
  1562. 654 errors