DBSTUFF.LST 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. Listing:
  2. 1 IMPLEMENTATION MODULE DBStuff;
  3. 2 (*
  4. 3 * ModBase
  5. 4 * Release 3.0
  6. 5 * (c) Copyright 1986 - 1991 PMI
  7. 6 Copyright 1988 - 1991 John McMonagle
  8. 7 * P.O. Box 8402
  9. 8 * Green Bay Wi 53308
  10. 9 * All Rights Reserved
  11. 10 * by Ed Ross
  12. 11 *)
  13. 12
  14. 13 FROM DBIndxes IMPORT DBIndex,GoTop,FindPositionCh,
  15. 14 CurrentRec,CurrentKeyCh,NextRecord;
  16. 15 FROM ModBase3 IMPORT DBFile,ReadDBRec,DeleteRecord,DBFieldDescriptor;
  17. 16 FROM StrConv IMPORT CardinalToStr;
  18. 17 FROM ScrnTypes IMPORT DisplayFrame;
  19. 18 FROM ControlUtils IMPORT ReadInput,ChangeField;
  20. 19 FROM DateFunctions IMPORT Date,DateToStr,StrToDate;
  21. 20 FROM GenLists IMPORT GenList,DisposeList,ListInsert,NewList,
  22. 21 GetElmt,ListInsertAdr,ListLength,Initialized;
  23. 22 FROM StrEdit IMPORT CrunchBlanks,SetLength,Append,
  24. 23 CAPstr,DeleteChar;
  25. 24 FROM Str IMPORT Length,Compare,Copy;
  26. 25 FROM PosUtils IMPORT Pos,Present;
  27. 26 FROM LowLevel IMPORT Fill;
  28. 27 FROM SYSTEM IMPORT ADR,SIZE,ADDRESS;
  29. 28 FROM HandleIO IMPORT FileExists,OpenFile,SetFilePtr,CreateFile,BlockWrite,
  30. 29 CloseHandle,BlockRead,FromStart;
  31. 30 FROM StringIO IMPORT ErrorMessage;
  32. 31
  33. 32 VAR
  34. 33 CharSet : SET OF CHAR;
  35. ***** ^ not supported yet
  36. 34 J : CHAR;
  37. 35
  38. 36 PROCEDURE MakeDescriptor(VAR Desc : DBFieldDescriptor;
  39. 37 Name : ARRAY OF CHAR; Size : CARDINAL;
  40. ***** ^ not supported yet
  41. 38 Dec : CARDINAL;Type : CHAR);
  42. 39 BEGIN
  43. 40 Fill(ADR(Desc),SIZE(Desc),0);
  44. ***** ^ not supported yet
  45. ***** ^ not supported yet
  46. ***** ^ not supported yet
  47. ***** ^ not supported yet
  48. ***** ^ not supported yet
  49. ***** ^ not supported yet
  50. 41 Copy(Desc.name , Name);
  51. ***** ^ not supported yet
  52. ***** ^ not supported yet
  53. ***** ^ not supported yet
  54. ***** ^ not supported yet
  55. 42 Desc.size := Size;
  56. ***** ^ not supported yet
  57. ***** ^ not supported yet
  58. 43 Desc.decplaces := Dec;
  59. ***** ^ not supported yet
  60. ***** ^ not supported yet
  61. 44 Copy(Desc.fldtype , Type);
  62. ***** ^ not supported yet
  63. ***** ^ not supported yet
  64. ***** ^ not supported yet
  65. ***** ^ not supported yet
  66. 45 END MakeDescriptor;
  67. ***** ^ not supported yet
  68. 46
  69. 47 PROCEDURE MakeSeqNbr(SeqFile, (* file name where seq kept -no extention *)
  70. 48 Prefix : ARRAY OF CHAR; (*key prefix "91-','C'*)
  71. ***** ^ not supported yet
  72. 49 VAR Key : ARRAY OF CHAR); (* returned key *)
  73. ***** ^ not supported yet
  74. 50
  75. 51
  76. 52 VAR
  77. 53 H : CARDINAL;
  78. 54 Str : ARRAY [0..8] OF CHAR;
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. 55 Seq : CARDINAL;
  82. 56 FileName : ARRAY[0..15] OF CHAR;
  83. ***** ^ not supported yet
  84. ***** ^ not supported yet
  85. 57 EM : ErrorMessage;
  86. 58 J : CARDINAL;
  87. 59 BEGIN
  88. 60 Copy(FileName , SeqFile);
  89. ***** ^ not supported yet
  90. ***** ^ not supported yet
  91. ***** ^ not supported yet
  92. 61 CrunchBlanks(FileName);
  93. ***** ^ not supported yet
  94. ***** ^ not supported yet
  95. 62 IF Pos(FileName,'.') < HIGH(FileName)+1
  96. ***** ^ not supported yet
  97. ***** ^ not supported yet
  98. ***** ^ not supported yet
  99. ***** ^ undeclared identifier
  100. ***** ^ not supported yet
  101. 63 THEN SetLength(FileName,Pos(FileName,'.'));
  102. ***** ^ not supported yet
  103. ***** ^ not supported yet
  104. ***** ^ not supported yet
  105. ***** ^ not supported yet
  106. ***** ^ not supported yet
  107. 64 END;
  108. 65 Append(FileName,'Seq');
  109. ***** ^ not supported yet
  110. ***** ^ not supported yet
  111. ***** ^ not supported yet
  112. 66 IF FileExists(FileName)
  113. ***** ^ not supported yet
  114. ***** ^ not supported yet
  115. 67 THEN
  116. 68 EM := OpenFile(H,FileName);
  117. ***** ^ not supported yet
  118. ***** ^ not supported yet
  119. ***** ^ not supported yet
  120. 69 EM := BlockRead(H,ADR(Seq),SIZE(Seq));
  121. ***** ^ not supported yet
  122. ***** ^ not supported yet
  123. ***** ^ not supported yet
  124. ***** ^ not supported yet
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. 70 SetFilePtr(H,FromStart,0);
  128. ***** ^ not supported yet
  129. ***** ^ not supported yet
  130. ***** ^ not supported yet
  131. 71 ELSE
  132. 72 EM := CreateFile(H,FileName); (* initialize seq number *)
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. ***** ^ not supported yet
  136. 73 Seq := 999;
  137. 74 END;
  138. 75 INC(Seq);
  139. ***** ^ undeclared identifier
  140. ***** ^ not supported yet
  141. 76 EM := BlockWrite(H,ADR(Seq),SIZE(Seq)); (* update the file *)
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. ***** ^ not supported yet
  146. ***** ^ not supported yet
  147. ***** ^ not supported yet
  148. 77 EM := CloseHandle(H);
  149. ***** ^ not supported yet
  150. ***** ^ not supported yet
  151. ***** ^ not supported yet
  152. 78 CardinalToStr(Seq,5,Str);
  153. ***** ^ not supported yet
  154. ***** ^ not supported yet
  155. 79 Copy(Key , Prefix);
  156. ***** ^ not supported yet
  157. ***** ^ not supported yet
  158. ***** ^ not supported yet
  159. 80 FOR J := 0 TO Length(Str) DO
  160. ***** ^ not supported yet
  161. ***** ^ not supported yet
  162. 81 IF Str[J] = ' '
  163. ***** ^ not supported yet
  164. ***** ^ not supported yet
  165. 82 THEN Str[J] := '0';
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. 83 END;
  169. 84 END;
  170. 85 Append(Key,Str);
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. ***** ^ not supported yet
  174. 86 MakeKey(Key);
  175. ***** ^ undeclared identifier
  176. ***** ^ not supported yet
  177. 87 END MakeSeqNbr;
  178. ***** ^ not supported yet
  179. 88
  180. 89
  181. 90 PROCEDURE MakeKey(VAR Key : ARRAY OF CHAR);
  182. ***** ^ not supported yet
  183. 91 VAR J : CARDINAL;
  184. 92 L : CARDINAL;
  185. 93 BEGIN
  186. 94 CAPstr(Key);
  187. ***** ^ not supported yet
  188. ***** ^ not supported yet
  189. 95 L := Length(Key);
  190. ***** ^ not supported yet
  191. ***** ^ not supported yet
  192. 96 IF L > 0
  193. 97 THEN
  194. 98 DEC(L);
  195. ***** ^ undeclared identifier
  196. ***** ^ not supported yet
  197. 99 END;
  198. 100 FOR J := 0 TO L DO
  199. 101 IF NOT (Key[J] IN CharSet)
  200. ***** ^ not supported yet
  201. ***** ^ not supported yet
  202. ***** ^ not supported yet
  203. 102 THEN Key[J] := ' ';
  204. ***** ^ not supported yet
  205. ***** ^ not supported yet
  206. 103 END;
  207. 104 END;
  208. 105 DeleteChar(' ',Key);
  209. ***** ^ not supported yet
  210. ***** ^ not supported yet
  211. 106
  212. 107 END MakeKey;
  213. ***** ^ not supported yet
  214. 108
  215. 109
  216. 110
  217. 111
  218. 112 PROCEDURE ReadDateField( DF : DisplayFrame; VAR D : Date;
  219. 113 FldName : ARRAY OF CHAR);
  220. ***** ^ not supported yet
  221. 114 VAR
  222. 115 S : ARRAY [0..15] OF CHAR;
  223. ***** ^ not supported yet
  224. ***** ^ not supported yet
  225. 116 Ok : BOOLEAN;
  226. 117 BEGIN
  227. 118 ReadInput(DF,S,FldName);
  228. ***** ^ not supported yet
  229. ***** ^ not supported yet
  230. ***** ^ not supported yet
  231. ***** ^ not supported yet
  232. 119 StrToDate(S,D,Ok);
  233. ***** ^ not supported yet
  234. ***** ^ not supported yet
  235. ***** ^ not supported yet
  236. ***** ^ not supported yet
  237. 120 END ReadDateField;
  238. ***** ^ not supported yet
  239. 121
  240. 122 PROCEDURE ChangeDateField(VAR DF : DisplayFrame; D : Date;
  241. 123 FldName : ARRAY OF CHAR);
  242. ***** ^ not supported yet
  243. 124 VAR
  244. 125 S : ARRAY[0..15] OF CHAR;
  245. ***** ^ not supported yet
  246. ***** ^ not supported yet
  247. 126 B : BOOLEAN;
  248. 127 BEGIN
  249. 128 DateToStr(D,S,B);
  250. ***** ^ not supported yet
  251. ***** ^ not supported yet
  252. ***** ^ not supported yet
  253. ***** ^ not supported yet
  254. 129 ChangeField(DF,S,FldName,TRUE);
  255. ***** ^ not supported yet
  256. ***** ^ not supported yet
  257. ***** ^ not supported yet
  258. ***** ^ not supported yet
  259. ***** ^ not supported yet
  260. 130 END ChangeDateField;
  261. ***** ^ not supported yet
  262. 131
  263. 132
  264. 133
  265. 134 PROCEDURE ReadAllRecs(VAR DBF : DBFile; ReadProc :ReadRec; VAR TheList : GenList);
  266. ***** ^ undeclared identifier
  267. 135
  268. 136 VAR
  269. 137 TmpList : GenList;
  270. 138 LI : LONGINT;
  271. 139 J : CARDINAL;
  272. 140 Code : CARDINAL;
  273. 141 RecAddr : ADDRESS;
  274. 142 Size : CARDINAL;
  275. 143 BEGIN
  276. 144 NewList(TmpList);
  277. ***** ^ not supported yet
  278. ***** ^ not supported yet
  279. 145 FOR J := 1 TO ListLength(TheList) DO
  280. ***** ^ not supported yet
  281. ***** ^ not supported yet
  282. 146 GetElmt(TheList,J,LI,Code);
  283. ***** ^ not supported yet
  284. ***** ^ not supported yet
  285. ***** ^ not supported yet
  286. 147 ReadDBRec(DBF,LI);
  287. ***** ^ not supported yet
  288. ***** ^ not supported yet
  289. ***** ^ not supported yet
  290. 148 ReadProc(RecAddr,Size);
  291. ***** ^ not supported yet
  292. ***** ^ not supported yet
  293. ***** ^ not supported yet
  294. 149 ListInsertAdr(RecAddr,Size,1,TmpList,J)
  295. ***** ^ not supported yet
  296. ***** ^ not supported yet
  297. ***** ^ not supported yet
  298. ***** ^ not supported yet
  299. 150 END;
  300. 151 DisposeList(TheList);
  301. ***** ^ not supported yet
  302. ***** ^ not supported yet
  303. 152 TheList := TmpList;
  304. ***** ^ not supported yet
  305. ***** ^ not supported yet
  306. 153
  307. 154 END ReadAllRecs;
  308. ***** ^ not supported yet
  309. 155
  310. 156 PROCEDURE DeleteAllRecs(VAR DBF : DBFile; TheList : GenList);
  311. 157 VAR
  312. 158 LI : LONGINT;
  313. 159 J : CARDINAL;
  314. 160 Code : CARDINAL;
  315. 161 BEGIN
  316. 162 FOR J := 1 TO ListLength(TheList) DO
  317. ***** ^ not supported yet
  318. ***** ^ not supported yet
  319. 163 GetElmt(TheList,J,LI,Code);
  320. ***** ^ not supported yet
  321. ***** ^ not supported yet
  322. ***** ^ not supported yet
  323. 164 ReadDBRec(DBF,LI); (* position data file *)
  324. ***** ^ not supported yet
  325. ***** ^ not supported yet
  326. ***** ^ not supported yet
  327. 165 DeleteRecord(DBF);
  328. ***** ^ not supported yet
  329. ***** ^ not supported yet
  330. 166 END;
  331. 167 END DeleteAllRecs;
  332. ***** ^ not supported yet
  333. 168
  334. 169 PROCEDURE FindAll(Idx : DBIndex; KeyExp : ARRAY OF CHAR;
  335. ***** ^ not supported yet
  336. 170 Condition : ConditionType;
  337. ***** ^ undeclared identifier
  338. 171 VAR TheList : GenList );
  339. 172
  340. 173 VAR
  341. 174 B : BOOLEAN;
  342. 175 Str : ARRAY[0..80] OF CHAR;
  343. ***** ^ not supported yet
  344. ***** ^ not supported yet
  345. 176 Cond : INTEGER;
  346. 177 CRec : LONGINT;
  347. 178 BEGIN
  348. 179 IF Initialized(TheList)
  349. ***** ^ not supported yet
  350. ***** ^ not supported yet
  351. 180 THEN
  352. 181 DisposeList(TheList);
  353. ***** ^ not supported yet
  354. ***** ^ not supported yet
  355. 182 END;
  356. 183 NewList(TheList);
  357. ***** ^ not supported yet
  358. ***** ^ not supported yet
  359. 184 CASE Condition OF
  360. ***** ^ not supported yet
  361. 185 LT,LE : GoTop(Idx);
  362. ***** ^ undeclared identifier
  363. ***** ^ undeclared identifier
  364. ***** ^ not supported yet
  365. ***** ^ not supported yet
  366. 186 B := TRUE;
  367. 187 |EQ,BeginsWith,GE : FindPositionCh(Idx,KeyExp,B);
  368. ***** ^ undeclared identifier
  369. ***** ^ undeclared identifier
  370. ***** ^ undeclared identifier
  371. ***** ^ not supported yet
  372. ***** ^ not supported yet
  373. ***** ^ not supported yet
  374. ***** ^ not supported yet
  375. 188 END; (* end case of *)
  376. 189 IF Condition = BeginsWith
  377. ***** ^ not supported yet
  378. ***** ^ undeclared identifier
  379. 190 THEN
  380. 191 CurrentKeyCh(Idx,Str); (* get the current key *)
  381. ***** ^ not supported yet
  382. ***** ^ not supported yet
  383. ***** ^ not supported yet
  384. 192 B := (Pos(KeyExp,Str) = 0)
  385. ***** ^ not supported yet
  386. ***** ^ not supported yet
  387. ***** ^ not supported yet
  388. 193 END;
  389. 194 IF NOT B
  390. 195 THEN RETURN;
  391. 196 END;
  392. 197
  393. 198 LOOP
  394. 199 CurrentKeyCh(Idx,Str); (* get the current key *)
  395. ***** ^ not supported yet
  396. ***** ^ not supported yet
  397. ***** ^ not supported yet
  398. 200 Cond := Compare(KeyExp,Str); (* do it here so I do it only once*)
  399. ***** ^ not supported yet
  400. ***** ^ not supported yet
  401. ***** ^ not supported yet
  402. 201 CASE Condition OF
  403. ***** ^ not supported yet
  404. 202 LT : IF Cond = 1
  405. ***** ^ undeclared identifier
  406. 203 THEN
  407. 204 EXIT; (* done with this loop *)
  408. 205 END;
  409. 206 |LE : IF Cond < 1
  410. ***** ^ undeclared identifier
  411. 207 THEN
  412. 208 ListInsert(CurrentRec(Idx),1,TheList,1); (* put in front of the list*)
  413. ***** ^ not supported yet
  414. ***** ^ not supported yet
  415. ***** ^ not supported yet
  416. ***** ^ not supported yet
  417. ***** ^ not supported yet
  418. 209 END;
  419. 210 |EQ : IF Cond = 0
  420. ***** ^ undeclared identifier
  421. 211 THEN
  422. 212 ListInsert(CurrentRec(Idx),1,TheList,1); (* put in front of the list*)
  423. ***** ^ not supported yet
  424. ***** ^ not supported yet
  425. ***** ^ not supported yet
  426. ***** ^ not supported yet
  427. ***** ^ not supported yet
  428. 213 ELSE
  429. 214 EXIT;
  430. 215 END;
  431. 216 |GE : IF Cond >= 0
  432. ***** ^ undeclared identifier
  433. 217 THEN
  434. 218 ListInsert(CurrentRec(Idx),1,TheList,1); (* put in front of the list*)
  435. ***** ^ not supported yet
  436. ***** ^ not supported yet
  437. ***** ^ not supported yet
  438. ***** ^ not supported yet
  439. ***** ^ not supported yet
  440. 219 END;
  441. 220 |BeginsWith :
  442. ***** ^ undeclared identifier
  443. 221 IF Pos(KeyExp,Str) = 0
  444. ***** ^ not supported yet
  445. ***** ^ not supported yet
  446. ***** ^ not supported yet
  447. 222 THEN
  448. 223 ListInsert(CurrentRec(Idx),1,TheList,1); (* put in front of the list*)
  449. ***** ^ not supported yet
  450. ***** ^ not supported yet
  451. ***** ^ not supported yet
  452. ***** ^ not supported yet
  453. ***** ^ not supported yet
  454. 224 ELSE
  455. 225 EXIT;
  456. 226 END;
  457. 227 |Contains : IF Present(KeyExp,Str)
  458. ***** ^ undeclared identifier
  459. ***** ^ not supported yet
  460. ***** ^ not supported yet
  461. ***** ^ not supported yet
  462. 228 THEN
  463. 229 ListInsert(CurrentRec(Idx),1,TheList,1);
  464. ***** ^ not supported yet
  465. ***** ^ not supported yet
  466. ***** ^ not supported yet
  467. ***** ^ not supported yet
  468. ***** ^ not supported yet
  469. 230 END;
  470. 231 END; (* end of case condition of *)
  471. 232 CRec := CurrentRec(Idx);
  472. ***** ^ not supported yet
  473. ***** ^ not supported yet
  474. 233 IF NOT NextRecord(Idx, CRec)
  475. ***** ^ not supported yet
  476. ***** ^ not supported yet
  477. ***** ^ not supported yet
  478. 234 THEN
  479. 235 EXIT;
  480. 236 END;
  481. 237 END; (* end of loop *)
  482. 238
  483. 239
  484. 240 END FindAll;
  485. ***** ^ not supported yet
  486. 241
  487. 242 BEGIN
  488. 243 CharSet := CharSet / CharSet;
  489. ***** ^ not supported yet
  490. ***** ^ not supported yet
  491. ***** ^ not supported yet
  492. 244 FOR J := 'A' TO 'Z' DO
  493. ***** ^ FOR needs integer variable and bounds
  494. ***** ^ FOR needs integer variable and bounds
  495. ***** ^ FOR needs integer variable and bounds
  496. 245 INCL ( CharSet,J);
  497. ***** ^ undeclared identifier
  498. ***** ^ not supported yet
  499. ***** ^ not supported yet
  500. 246 END;
  501. 247 FOR J := '0' TO '9' DO
  502. ***** ^ FOR needs integer variable and bounds
  503. ***** ^ FOR needs integer variable and bounds
  504. ***** ^ FOR needs integer variable and bounds
  505. 248 INCL(CharSet,J);
  506. ***** ^ undeclared identifier
  507. ***** ^ not supported yet
  508. ***** ^ not supported yet
  509. 249 END;
  510. 250 INCL(CharSet,'-');
  511. ***** ^ undeclared identifier
  512. ***** ^ not supported yet
  513. ***** ^ not supported yet
  514. 251 INCL(CharSet,'&');
  515. ***** ^ undeclared identifier
  516. ***** ^ not supported yet
  517. ***** ^ not supported yet
  518. 252 INCL(CharSet,'!');
  519. ***** ^ undeclared identifier
  520. ***** ^ not supported yet
  521. ***** ^ not supported yet
  522. 253 INCL(CharSet,'?');
  523. ***** ^ undeclared identifier
  524. ***** ^ not supported yet
  525. ***** ^ not supported yet
  526. 254
  527. 255 END DBStuff.
  528. ***** ^ not supported yet
  529. 256
  530. 272 errors