DBCOPIER.LST 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. Listing:
  2. 1 IMPLEMENTATION MODULE DBCopier;
  3. 2
  4. 3 (*
  5. 4 * ModBase
  6. 5 * Release 3.0
  7. 6 * (c) Copyright 1990-1991 PMI
  8. 7 * P.O. Box 8402
  9. 8 * Green Bay Wi 53308
  10. 9 * All Rights Reserved
  11. 10 *
  12. 11 *)
  13. 12
  14. 13 FROM M2Strings IMPORT
  15. 14 Delete, Pos, Length, Assign, CompareStr, Concat;
  16. 15
  17. 16 FROM SYSTEM IMPORT
  18. 17 BYTE, ADR, TSIZE, ADDRESS;
  19. 18
  20. 19 FROM DBFields IMPORT
  21. 20 ReplaceL, ReplaceD, GetLogicalField, GetDateField;
  22. 21
  23. 22 FROM ErrorManager IMPORT
  24. 23 WARN;
  25. 24
  26. 25 FROM MemoFunctions IMPORT
  27. 26 GetMemoField, ReplaceM;
  28. 27
  29. 28 FROM ModBase3 IMPORT
  30. 29 AppendBlank, Deleted, ReadDBRec, WriteDBRec, DBFile, DBFieldDescriptor,
  31. 30 UpdateDBFile, GetField, CloseDBF, InitDBF, SetDBBuffer,OpenDBF,
  32. 31 IndexList,BuildDBF,NumberOfFields,FieldList,DefaultFixUp,
  33. 32 FileName,HasMemo,SetIndexList,Replace,RecordPtr,MaxRecLength,
  34. 33 DBFieldPtr,NumberRecords,SetDBSafetyOn,SetDBSafetyOff,SafetySet,
  35. 34 BufferSize,RecordLength,DisposeDBF;
  36. 35
  37. 36 FROM HandleIO IMPORT
  38. 37 FindFile, FileOffSet, CreateFile, OpenFile, EndReached, BlockWrite,
  39. 38 CloseHandle, SetFilePtr, FileExists, BlockRead;
  40. 39
  41. 40 FROM StringIO IMPORT
  42. 41 ErrorMessage, WriteStr, ReadStr, WriteEol, PrintMessage;
  43. 42
  44. 43 FROM Drectory IMPORT
  45. 44 RenameFile, DeleteFile;
  46. 45
  47. 46 FROM LowLevel IMPORT
  48. 47 Move;
  49. 48
  50. 49 FROM VStorage IMPORT
  51. 50 DosAlloc, DosDealloc;
  52. 51
  53. 52 PROCEDURE DEALLOCATE(VAR loc:ADDRESS;size:CARDINAL);
  54. 53 BEGIN
  55. 54 DosDealloc(loc,size);
  56. ***** ^ not supported yet
  57. ***** ^ not supported yet
  58. ***** ^ not supported yet
  59. 55 END DEALLOCATE;
  60. ***** ^ not supported yet
  61. 56
  62. 57 PROCEDURE ALLOCATE(VAR loc:ADDRESS;size:CARDINAL);
  63. 58 BEGIN
  64. 59 DosAlloc(loc,size);
  65. ***** ^ not supported yet
  66. ***** ^ not supported yet
  67. ***** ^ not supported yet
  68. 60 END ALLOCATE;
  69. ***** ^ not supported yet
  70. 61
  71. 62 (* all routines assume dbase3 file naming conventions *)
  72. 63
  73. 64 PROCEDURE CompareDescriptor
  74. 65 ( VAR a,
  75. 66 b : ARRAY OF DBFieldDescriptor;
  76. ***** ^ not supported yet
  77. 67 size : CARDINAL ) : BOOLEAN;
  78. 68
  79. 69 VAR
  80. 70 i : CARDINAL;
  81. 71
  82. 72 BEGIN
  83. 73 FOR i := 0 TO size-1 DO
  84. 74 IF CompareStr( a[i].name, b[i].name ) # 0
  85. ***** ^ not supported yet
  86. ***** ^ not supported yet
  87. ***** ^ not supported yet
  88. ***** ^ not supported yet
  89. ***** ^ not supported yet
  90. ***** ^ not supported yet
  91. ***** ^ not supported yet
  92. 75 THEN
  93. 76 RETURN FALSE;
  94. 77 END (* if CompareStr *);
  95. 78 IF a[i].size # b[i].size
  96. ***** ^ not supported yet
  97. ***** ^ not supported yet
  98. ***** ^ not supported yet
  99. ***** ^ not supported yet
  100. ***** ^ not supported yet
  101. ***** ^ not supported yet
  102. 79 THEN
  103. 80 RETURN FALSE;
  104. 81 END (* if a *);
  105. 82 IF a[i].fldtype # b[i].fldtype
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. ***** ^ not supported yet
  110. ***** ^ not supported yet
  111. ***** ^ not supported yet
  112. 83 THEN
  113. 84 RETURN FALSE;
  114. 85 END (* if a *);
  115. 86 IF a[i].fldtype = 'N'
  116. ***** ^ not supported yet
  117. ***** ^ not supported yet
  118. ***** ^ not supported yet
  119. 87 THEN
  120. 88 IF a[i].decplaces # b[i].decplaces
  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. 89 THEN
  128. 90 RETURN FALSE;
  129. 91 END (* if a *);
  130. 92 END (* if a *);
  131. 93 END (* for *);
  132. 94 RETURN TRUE;
  133. 95 END CompareDescriptor;
  134. ***** ^ not supported yet
  135. 96
  136. 97
  137. 98 PROCEDURE DBPack
  138. 99 ( VAR dbf : DBFile );
  139. 100
  140. 101 VAR
  141. 102 indexes:ADDRESS;
  142. 103 pos,
  143. 104 handle : CARDINAL;
  144. 105 TempDBF : DBFile;
  145. 106 name,
  146. 107 string,
  147. 108 memo : ARRAY[ 0 .. 30 ] OF CHAR;
  148. ***** ^ not supported yet
  149. ***** ^ not supported yet
  150. 109 fields : DBFieldPtr;
  151. 110
  152. 111 BEGIN
  153. 112 IF NOT OpenDBF(dbf)
  154. ***** ^ not supported yet
  155. ***** ^ not supported yet
  156. 113 THEN
  157. 114 WARN('Not able to open file in DBPack');
  158. ***** ^ not supported yet
  159. ***** ^ not supported yet
  160. 115 END;
  161. 116 indexes:=IndexList(dbf);
  162. ***** ^ not supported yet
  163. ***** ^ not supported yet
  164. ***** ^ not supported yet
  165. 117 (* Should consider a better Temp name system *)
  166. 118 FileName(dbf,name);
  167. ***** ^ not supported yet
  168. ***** ^ not supported yet
  169. ***** ^ not supported yet
  170. 119 InitDBF( '@@tempfi.dbf', TempDBF, 0 ,FALSE,TRUE,TRUE,DefaultFixUp);
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. ***** ^ not supported yet
  174. ***** ^ not supported yet
  175. 120 fields:=FieldList(dbf);
  176. ***** ^ not supported yet
  177. ***** ^ not supported yet
  178. ***** ^ not supported yet
  179. 121 IF BuildDBF( fields^,NumberOfFields(dbf), TempDBF )=0 THEN
  180. ***** ^ not supported yet
  181. ***** ^ not supported yet
  182. ***** ^ not supported yet
  183. ***** ^ not supported yet
  184. ***** ^ not supported yet
  185. 122 DBCopy( dbf, TempDBF, FALSE );
  186. ***** ^ undeclared identifier
  187. ***** ^ not supported yet
  188. ***** ^ not supported yet
  189. ***** ^ not supported yet
  190. 123 CloseDBF( dbf );
  191. ***** ^ not supported yet
  192. ***** ^ not supported yet
  193. 124 CloseDBF( TempDBF );
  194. ***** ^ not supported yet
  195. ***** ^ not supported yet
  196. 125 PrintMessage( DeleteFile(name ) );
  197. ***** ^ not supported yet
  198. ***** ^ not supported yet
  199. ***** ^ not supported yet
  200. 126 IF HasMemo(dbf)
  201. ***** ^ not supported yet
  202. ***** ^ not supported yet
  203. 127 THEN
  204. 128 Assign( name, string );
  205. ***** ^ not supported yet
  206. ***** ^ not supported yet
  207. ***** ^ not supported yet
  208. 129 pos := Pos( '.', string ) + 1;
  209. ***** ^ not supported yet
  210. ***** ^ not supported yet
  211. 130 Delete( string, pos, 3 );
  212. ***** ^ not supported yet
  213. ***** ^ not supported yet
  214. ***** ^ not supported yet
  215. 131 Concat( string, 'DBT', string );
  216. ***** ^ not supported yet
  217. ***** ^ not supported yet
  218. ***** ^ not supported yet
  219. ***** ^ not supported yet
  220. 132 PrintMessage( DeleteFile( string ) );
  221. ***** ^ not supported yet
  222. ***** ^ not supported yet
  223. ***** ^ not supported yet
  224. 133 PrintMessage( RenameFile( '@@tempfi.dbt', string ) );
  225. ***** ^ not supported yet
  226. ***** ^ not supported yet
  227. ***** ^ not supported yet
  228. ***** ^ not supported yet
  229. 134 END (* if *);
  230. 135 PrintMessage( RenameFile( '@@tempfi.dbf', name ) );
  231. ***** ^ not supported yet
  232. ***** ^ not supported yet
  233. ***** ^ not supported yet
  234. ***** ^ not supported yet
  235. 136 SetIndexList(dbf,indexes);
  236. ***** ^ not supported yet
  237. ***** ^ not supported yet
  238. ***** ^ not supported yet
  239. 137 ELSE
  240. 138 WARN('Unable to create temporary file in Pack, Operation aborted');
  241. ***** ^ not supported yet
  242. ***** ^ not supported yet
  243. 139 END;
  244. 140 DisposeDBF(TempDBF);
  245. ***** ^ not supported yet
  246. ***** ^ not supported yet
  247. 141 END DBPack;
  248. ***** ^ not supported yet
  249. 142
  250. 143
  251. 144 PROCEDURE DBFieldCopy
  252. 145 ( VAR Source : DBFile;
  253. 146 VAR Dest : DBFile );
  254. 147
  255. 148 VAR
  256. 149 i,
  257. 150 j : CARDINAL;
  258. 151 ok : BOOLEAN;
  259. 152 string : POINTER TO ARRAY[ 0 .. 5000 ] OF CHAR;(* for memo *)
  260. ***** ^ not supported yet
  261. ***** ^ not supported yet
  262. 153 SourceName,
  263. 154 DestName : ARRAY[ 0 .. 9 ] OF CHAR;
  264. ***** ^ not supported yet
  265. ***** ^ not supported yet
  266. 155 SourceRec,
  267. 156 DestRec :POINTER TO ARRAY[1..MaxRecLength] OF CHAR;
  268. ***** ^ not supported yet
  269. ***** ^ not supported yet
  270. 157 DestFields,
  271. 158 SourceFields :DBFieldPtr;
  272. 159 BEGIN
  273. 160 NEW(string);
  274. ***** ^ undeclared identifier
  275. ***** ^ not supported yet
  276. 161 SourceRec:=RecordPtr(Source);
  277. ***** ^ not supported yet
  278. ***** ^ not supported yet
  279. ***** ^ not supported yet
  280. 162 DestRec:=RecordPtr(Dest);
  281. ***** ^ not supported yet
  282. ***** ^ not supported yet
  283. ***** ^ not supported yet
  284. 163 DestFields:=FieldList(Dest);
  285. ***** ^ not supported yet
  286. ***** ^ not supported yet
  287. ***** ^ not supported yet
  288. 164 SourceFields:=FieldList(Source);
  289. ***** ^ not supported yet
  290. ***** ^ not supported yet
  291. ***** ^ not supported yet
  292. 165 DestRec^[1] := SourceRec^[1]; (* copy delete mark *)
  293. ***** ^ not supported yet
  294. ***** ^ not supported yet
  295. ***** ^ not supported yet
  296. ***** ^ not supported yet
  297. 166 FOR i := 1 TO NumberOfFields(Source) DO
  298. ***** ^ not supported yet
  299. ***** ^ not supported yet
  300. 167 FOR j := 1 TO NumberOfFields(Dest) DO
  301. ***** ^ not supported yet
  302. ***** ^ not supported yet
  303. 168 IF CompareStr( SourceFields^[i].name, DestFields^[j].name ) = 0
  304. ***** ^ not supported yet
  305. ***** ^ not supported yet
  306. ***** ^ not supported yet
  307. ***** ^ not supported yet
  308. ***** ^ not supported yet
  309. ***** ^ not supported yet
  310. ***** ^ not supported yet
  311. 169 THEN
  312. 170 IF SourceFields^[i].fldtype = DestFields^[j].fldtype
  313. ***** ^ not supported yet
  314. ***** ^ not supported yet
  315. ***** ^ not supported yet
  316. ***** ^ not supported yet
  317. ***** ^ not supported yet
  318. ***** ^ not supported yet
  319. 171 THEN
  320. 172 IF SourceFields^[i].fldtype = 'M'
  321. ***** ^ not supported yet
  322. ***** ^ not supported yet
  323. ***** ^ not supported yet
  324. 173 THEN
  325. 174 GetMemoField( Source, i, string^ );
  326. ***** ^ not supported yet
  327. ***** ^ not supported yet
  328. ***** ^ not supported yet
  329. 175 ReplaceM( Dest, j, string^ );
  330. ***** ^ not supported yet
  331. ***** ^ not supported yet
  332. ***** ^ not supported yet
  333. 176 ELSE
  334. 177 GetField( Source, i, string^ );
  335. ***** ^ not supported yet
  336. ***** ^ not supported yet
  337. ***** ^ not supported yet
  338. 178 Replace( Dest, j, string^ );
  339. ***** ^ not supported yet
  340. ***** ^ not supported yet
  341. ***** ^ not supported yet
  342. 179 END (* if *);
  343. 180 END (* if *);
  344. 181 END (* if *);
  345. 182 END (* for *);
  346. 183 END (* for *);
  347. 184 DISPOSE(string);
  348. ***** ^ undeclared identifier
  349. ***** ^ not supported yet
  350. 185 END DBFieldCopy;
  351. ***** ^ not supported yet
  352. 186
  353. 187
  354. 188 PROCEDURE DBCopy
  355. 189 ( VAR Source : DBFile;
  356. 190 VAR Dest : DBFile;
  357. 191 CopyDeleted : BOOLEAN );
  358. 192
  359. 193 VAR
  360. 194
  361. 195 CurRec : LONGINT;
  362. 196 oldbuffer,
  363. 197 pos,i : CARDINAL;
  364. 198 CopyMemo,
  365. 199 SameStructure,
  366. 200 ok : BOOLEAN;
  367. 201 string : ARRAY[ 0 .. 29 ] OF CHAR;
  368. ***** ^ not supported yet
  369. ***** ^ not supported yet
  370. 202 OldSafety : BOOLEAN;
  371. 203 memo : POINTER TO ARRAY[0..5000] OF CHAR;
  372. ***** ^ not supported yet
  373. ***** ^ not supported yet
  374. 204 SourceRec,
  375. 205 DestRec :POINTER TO ARRAY[1..MaxRecLength] OF CHAR;
  376. ***** ^ not supported yet
  377. ***** ^ not supported yet
  378. 206 DestFields,
  379. 207 SourceFields :DBFieldPtr;
  380. 208
  381. 209 BEGIN
  382. 210 IF NOT OpenDBF(Source)
  383. ***** ^ not supported yet
  384. ***** ^ not supported yet
  385. 211 THEN
  386. 212 WARN('Not able to open Source file in DBCopy');
  387. ***** ^ not supported yet
  388. ***** ^ not supported yet
  389. 213 END;
  390. 214 IF NOT OpenDBF(Dest)
  391. ***** ^ not supported yet
  392. ***** ^ not supported yet
  393. 215 THEN
  394. 216 WARN('Not able to open Dest file in DBCopy');
  395. ***** ^ not supported yet
  396. ***** ^ not supported yet
  397. 217 END;
  398. 218 SourceRec:=RecordPtr(Source);
  399. ***** ^ not supported yet
  400. ***** ^ not supported yet
  401. ***** ^ not supported yet
  402. 219 DestRec:=RecordPtr(Dest);
  403. ***** ^ not supported yet
  404. ***** ^ not supported yet
  405. ***** ^ not supported yet
  406. 220 DestFields:=FieldList(Dest);
  407. ***** ^ not supported yet
  408. ***** ^ not supported yet
  409. ***** ^ not supported yet
  410. 221 SourceFields:=FieldList(Source);
  411. ***** ^ not supported yet
  412. ***** ^ not supported yet
  413. ***** ^ not supported yet
  414. 222 oldbuffer:=BufferSize(Source);
  415. ***** ^ not supported yet
  416. ***** ^ not supported yet
  417. 223 SetDBBuffer( Source, 32000 );
  418. ***** ^ not supported yet
  419. ***** ^ not supported yet
  420. ***** ^ not supported yet
  421. 224 OldSafety:=SafetySet(Dest);
  422. ***** ^ not supported yet
  423. ***** ^ not supported yet
  424. 225 SetDBSafetyOff(Dest);
  425. ***** ^ not supported yet
  426. ***** ^ not supported yet
  427. 226 IF HasMemo(Source) AND HasMemo(Dest)
  428. ***** ^ not supported yet
  429. ***** ^ not supported yet
  430. ***** ^ not supported yet
  431. ***** ^ not supported yet
  432. 227 THEN
  433. 228 CopyMemo := TRUE;
  434. 229 ELSE
  435. 230 CopyMemo := FALSE;
  436. 231 END (* if hasmemo *);
  437. 232 SameStructure := FALSE;
  438. 233 IF ( NumberOfFields(Source) = NumberOfFields(Dest) )
  439. ***** ^ not supported yet
  440. ***** ^ not supported yet
  441. ***** ^ not supported yet
  442. ***** ^ not supported yet
  443. 234 THEN
  444. 235 IF CompareDescriptor( SourceFields^, DestFields^,
  445. ***** ^ not supported yet
  446. ***** ^ not supported yet
  447. ***** ^ not supported yet
  448. 236 NumberOfFields(Source) )
  449. ***** ^ not supported yet
  450. ***** ^ not supported yet
  451. 237 THEN
  452. 238 SameStructure := TRUE;
  453. 239 END (* if *);
  454. 240 END (* if *);
  455. 241 IF SameStructure AND CopyMemo
  456. 242 THEN
  457. 243 NEW(memo);
  458. ***** ^ undeclared identifier
  459. ***** ^ not supported yet
  460. 244 END;
  461. 245 CurRec := VAL( LONGINT, 1 );
  462. ***** ^ undeclared identifier
  463. ***** ^ not supported yet
  464. 246 WHILE CurRec <= NumberRecords(Source) DO
  465. ***** ^ not supported yet
  466. ***** ^ not supported yet
  467. 247 ReadDBRec( Source, CurRec );
  468. ***** ^ not supported yet
  469. ***** ^ not supported yet
  470. ***** ^ not supported yet
  471. 248 IF CopyDeleted OR NOT Deleted( Source )
  472. ***** ^ not supported yet
  473. ***** ^ not supported yet
  474. 249 THEN
  475. 250 AppendBlank( Dest );
  476. ***** ^ not supported yet
  477. ***** ^ not supported yet
  478. 251 IF SameStructure
  479. 252 THEN
  480. 253 Move( SourceRec, DestRec, RecordLength(Source));
  481. ***** ^ not supported yet
  482. ***** ^ not supported yet
  483. ***** ^ not supported yet
  484. ***** ^ not supported yet
  485. ***** ^ not supported yet
  486. 254 IF CopyMemo
  487. 255 THEN
  488. 256 (* both structures are the same *)
  489. 257 FOR i := 1 TO NumberOfFields(Dest) DO
  490. ***** ^ not supported yet
  491. ***** ^ not supported yet
  492. 258 IF SourceFields^[i].fldtype = 'M'
  493. ***** ^ not supported yet
  494. ***** ^ not supported yet
  495. ***** ^ not supported yet
  496. 259 THEN
  497. 260 GetMemoField( Source, i, memo^ );
  498. ***** ^ not supported yet
  499. ***** ^ not supported yet
  500. ***** ^ not supported yet
  501. 261 ReplaceM( Dest, i, memo^ );
  502. ***** ^ not supported yet
  503. ***** ^ not supported yet
  504. ***** ^ not supported yet
  505. 262 END (* if *);
  506. 263 END (* for *);
  507. 264 END (* IF COPY MEMO *);
  508. 265 ELSE
  509. 266 DBFieldCopy( Source, Dest );
  510. ***** ^ not supported yet
  511. ***** ^ not supported yet
  512. ***** ^ not supported yet
  513. 267 END (* if *);
  514. 268 WriteDBRec( Dest );
  515. ***** ^ not supported yet
  516. ***** ^ not supported yet
  517. 269 END (* if *);
  518. 270 INC( CurRec );
  519. ***** ^ undeclared identifier
  520. ***** ^ not supported yet
  521. 271 END (* while *);
  522. 272 IF OldSafety THEN
  523. 273 SetDBSafetyOn(Dest)
  524. ***** ^ not supported yet
  525. ***** ^ not supported yet
  526. 274 END;
  527. 275 UpdateDBFile(Dest);
  528. ***** ^ not supported yet
  529. ***** ^ not supported yet
  530. 276 IF SameStructure AND CopyMemo
  531. 277 THEN
  532. 278 DISPOSE(memo);
  533. ***** ^ undeclared identifier
  534. ***** ^ not supported yet
  535. 279 END;
  536. 280 SetDBBuffer( Source, oldbuffer );
  537. ***** ^ not supported yet
  538. ***** ^ not supported yet
  539. ***** ^ not supported yet
  540. 281 END DBCopy;
  541. ***** ^ not supported yet
  542. 282
  543. 283
  544. 284
  545. 285 END DBCopier.
  546. ***** ^ not supported yet
  547. 260 errors