MEMOFUNC.LST 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. Listing:
  2. 1 IMPLEMENTATION MODULE MemoFunctions;
  3. 2
  4. 3 (*
  5. 4 * ModBase
  6. 5 * Release 3.0
  7. 6 * (c) Copyright 1986 - 1991 John McMonagle & Donald G. Fletcher
  8. 7 * (c) Copyright 1986 - 1991 PMI
  9. 8 * P.O. Box 8402
  10. 9 * Green Bay Wi 53308
  11. 10 * All Rights Reserved
  12. 11 *)
  13. 12
  14. 13 FROM SYSTEM IMPORT ADR,ADDRESS;
  15. 14
  16. 15 (*Repertoire modules*)
  17. 16 FROM HandleIO IMPORT BlockRead, BlockWrite,OpenFile,
  18. 17 EndReached, SetFilePtr, GetFilePtr,FileOffSet;
  19. 18 FROM StringIO IMPORT ErrorMessage, NoError, PartialRead, PrintMessage;
  20. 19 FROM StrConv IMPORT StrToLongInteger, LongIntegerToStr;
  21. 20 FROM StrEdit IMPORT Append;
  22. 21 FROM M2Strings IMPORT Length,Pos;
  23. 22 FROM LowLevel IMPORT Fill;
  24. 23 FROM ErrorManager IMPORT WARN;
  25. 24 FROM Numbers IMPORT Min;
  26. 25 (*ModBase modules*)
  27. 26 FROM ModBase3 IMPORT DBFile, GetField,MemoSize, Replace,OpenMemo,MemoHandle;
  28. 27 FROM VStorage IMPORT
  29. 28 DosAlloc, DosDealloc;
  30. 29
  31. 30 PROCEDURE DEALLOCATE(VAR loc:ADDRESS;size:CARDINAL);
  32. 31 BEGIN
  33. 32 DosDealloc(loc,size);
  34. ***** ^ not supported yet
  35. ***** ^ not supported yet
  36. ***** ^ not supported yet
  37. 33 END DEALLOCATE;
  38. ***** ^ not supported yet
  39. 34
  40. 35 PROCEDURE ALLOCATE(VAR loc:ADDRESS;size:CARDINAL);
  41. 36 BEGIN
  42. 37 DosAlloc(loc,size);
  43. ***** ^ not supported yet
  44. ***** ^ not supported yet
  45. ***** ^ not supported yet
  46. 38 END ALLOCATE;
  47. ***** ^ not supported yet
  48. 39
  49. 40 CONST
  50. 41 EndOfMemo = 32C;
  51. 42 MemoBlockSize = 512;
  52. 43 MaxMemoSize =4000;
  53. 44
  54. 45
  55. 46 PROCEDURE PadFile( FileHandle: CARDINAL; TheChar: CHAR;
  56. 47 HowMany: CARDINAL );
  57. 48 VAR
  58. 49 TmpBufPtr: POINTER TO CARDINAL;
  59. ***** ^ not supported yet
  60. 50 BEGIN
  61. 51 ALLOCATE( TmpBufPtr, HowMany );
  62. ***** ^ not supported yet
  63. ***** ^ not supported yet
  64. ***** ^ not supported yet
  65. 52 Fill( TmpBufPtr, HowMany, TheChar );
  66. ***** ^ not supported yet
  67. ***** ^ not supported yet
  68. ***** ^ not supported yet
  69. 53 IF BlockWrite( FileHandle, TmpBufPtr, HowMany ) # NoError THEN
  70. ***** ^ not supported yet
  71. ***** ^ not supported yet
  72. ***** ^ not supported yet
  73. ***** ^ not supported yet
  74. 54 HALT;
  75. ***** ^ undeclared identifier
  76. 55 END;
  77. 56 DEALLOCATE( TmpBufPtr, HowMany );
  78. ***** ^ not supported yet
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. 57 END PadFile;
  82. ***** ^ not supported yet
  83. 58
  84. 59 PROCEDURE GetMemoField(VAR alias: DBFile; fieldnum: CARDINAL; VAR
  85. 60 memo: ARRAY OF CHAR);
  86. ***** ^ not supported yet
  87. 61
  88. 62 VAR
  89. 63 FileError: ErrorMessage;
  90. 64 memostr: ARRAY [0..9] OF CHAR;
  91. ***** ^ not supported yet
  92. ***** ^ not supported yet
  93. 65 block: ARRAY[0..MemoSize-1] OF CHAR;
  94. ***** ^ not supported yet
  95. ***** ^ not supported yet
  96. ***** ^ not supported yet
  97. 66 memopos, memonum: LONGINT;
  98. 67 handle,i: CARDINAL;
  99. 68 fieldok: BOOLEAN;
  100. 69 BEGIN
  101. 70 IF NOT OpenMemo(alias)
  102. ***** ^ not supported yet
  103. ***** ^ not supported yet
  104. 71 THEN
  105. 72 WARN('Unable to open memo file')
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. 73 END;
  109. 74 handle:=MemoHandle(alias);
  110. ***** ^ not supported yet
  111. ***** ^ not supported yet
  112. 75 GetField(alias, fieldnum, memostr);
  113. ***** ^ not supported yet
  114. ***** ^ not supported yet
  115. ***** ^ not supported yet
  116. 76 (* First check to make sure there is a memo to read *)
  117. 77 IF (StrToLongInteger(memostr,0, memonum))
  118. ***** ^ not supported yet
  119. ***** ^ not supported yet
  120. ***** ^ not supported yet
  121. 78 AND (memonum > VAL(LONGINT,0)) THEN
  122. ***** ^ undeclared identifier
  123. ***** ^ not supported yet
  124. 79 memopos := VAL(LONGINT, MemoBlockSize) * memonum;
  125. ***** ^ undeclared identifier
  126. ***** ^ not supported yet
  127. 80 SetFilePtr(handle, FromStart, memopos);
  128. ***** ^ not supported yet
  129. ***** ^ undeclared identifier
  130. ***** ^ not supported yet
  131. 81 memo[0] := 0C;
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. 82 block[0] := 0C;
  135. ***** ^ not supported yet
  136. ***** ^ not supported yet
  137. 83 LOOP
  138. 84 FileError := BlockRead(handle, ADR(block[0]), MemoSize);
  139. ***** ^ not supported yet
  140. ***** ^ not supported yet
  141. ***** ^ not supported yet
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. 85 IF (FileError=NoError) OR (FileError=PartialRead) THEN
  146. ***** ^ not supported yet
  147. ***** ^ not supported yet
  148. ***** ^ not supported yet
  149. ***** ^ not supported yet
  150. 86 i:=Pos(EndOfMemo,block);
  151. ***** ^ not supported yet
  152. ***** ^ not supported yet
  153. 87 IF i<MemoSize THEN
  154. ***** ^ not supported yet
  155. 88 block[i]:=0C;
  156. ***** ^ not supported yet
  157. ***** ^ not supported yet
  158. 89 Append(memo,block);
  159. ***** ^ not supported yet
  160. ***** ^ not supported yet
  161. ***** ^ not supported yet
  162. 90 EXIT;
  163. 91 ELSE
  164. 92 Append(memo,block);
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. 93 END;
  169. 94 ELSE
  170. 95 EXIT
  171. 96 END;
  172. 97 END;
  173. 98 ELSE (* the memofield was empty *)
  174. 99 memo[0] := 0C;
  175. ***** ^ not supported yet
  176. ***** ^ not supported yet
  177. 100 END;
  178. 101 END GetMemoField;
  179. ***** ^ not supported yet
  180. 102
  181. 103
  182. 104 PROCEDURE ReplaceM(VAR alias: DBFile; fieldnum: CARDINAL;VAR memo:
  183. 105 ARRAY OF CHAR);
  184. ***** ^ not supported yet
  185. 106
  186. 107 VAR
  187. 108 FileError: ErrorMessage;
  188. 109 ptrstr: ARRAY [0..9] OF CHAR;
  189. ***** ^ not supported yet
  190. ***** ^ not supported yet
  191. 110 blocknum, blockpos: LONGINT;
  192. 111 OldMemo :POINTER TO ARRAY[0..MaxMemoSize]OF CHAR;
  193. ***** ^ not supported yet
  194. ***** ^ not supported yet
  195. 112 handle:CARDINAL;
  196. 113 (* seem a bit overkill but use of comparestr will use usualy 8K of stack *)
  197. 114 PROCEDURE StrEqual(VAR str1,str2:ARRAY OF CHAR):BOOLEAN;
  198. ***** ^ not supported yet
  199. 115 VAR
  200. 116 limit, count:CARDINAL;
  201. 117
  202. 118 BEGIN
  203. 119 limit:=Min(HIGH(str1),HIGH(str2));
  204. ***** ^ not supported yet
  205. ***** ^ undeclared identifier
  206. ***** ^ not supported yet
  207. ***** ^ undeclared identifier
  208. ***** ^ not supported yet
  209. 120 count:=0;
  210. 121 WHILE count<limit
  211. 122 DO
  212. 123 IF str1[count]#str2[count]
  213. ***** ^ not supported yet
  214. ***** ^ not supported yet
  215. ***** ^ not supported yet
  216. ***** ^ not supported yet
  217. 124 THEN
  218. 125 RETURN FALSE;
  219. 126 ELSIF str1[count]=0C
  220. ***** ^ not supported yet
  221. ***** ^ not supported yet
  222. 127 THEN
  223. 128 RETURN TRUE;
  224. 129 END;
  225. 130 INC(count);
  226. ***** ^ undeclared identifier
  227. ***** ^ not supported yet
  228. 131 END (* while *);
  229. 132 IF HIGH(str1)<HIGH(str2)
  230. ***** ^ undeclared identifier
  231. ***** ^ not supported yet
  232. ***** ^ undeclared identifier
  233. ***** ^ not supported yet
  234. 133 THEN
  235. 134 RETURN str2[count]=0C;
  236. ***** ^ not supported yet
  237. ***** ^ not supported yet
  238. 135 ELSIF HIGH(str1)>HIGH(str2)
  239. ***** ^ undeclared identifier
  240. ***** ^ not supported yet
  241. ***** ^ undeclared identifier
  242. ***** ^ not supported yet
  243. 136 THEN
  244. 137 RETURN str1[count]=0C
  245. ***** ^ not supported yet
  246. ***** ^ not supported yet
  247. 138 ELSE
  248. 139 RETURN TRUE;
  249. 140 END;
  250. 141 END StrEqual;
  251. ***** ^ not supported yet
  252. 142
  253. 143 BEGIN
  254. 144 IF NOT OpenMemo(alias)
  255. ***** ^ not supported yet
  256. ***** ^ not supported yet
  257. 145 THEN
  258. 146 WARN('Unable to open memo file')
  259. ***** ^ not supported yet
  260. ***** ^ not supported yet
  261. 147 END;
  262. 148 handle:=MemoHandle(alias);
  263. ***** ^ not supported yet
  264. ***** ^ not supported yet
  265. 149 IF memo[0]#0C THEN (* Added to avoid writing a '' Memo !!!! *)
  266. ***** ^ not supported yet
  267. ***** ^ not supported yet
  268. 150 (* check to see if memo changed *)
  269. 151 NEW(OldMemo);
  270. ***** ^ undeclared identifier
  271. ***** ^ not supported yet
  272. 152 GetMemoField(alias,fieldnum,OldMemo^);
  273. ***** ^ not supported yet
  274. ***** ^ not supported yet
  275. ***** ^ not supported yet
  276. 153 IF NOT StrEqual(OldMemo^,memo)
  277. ***** ^ not supported yet
  278. ***** ^ not supported yet
  279. ***** ^ not supported yet
  280. 154 THEN
  281. 155 SetFilePtr(handle, FromStart, VAL(LONGINT,0));
  282. ***** ^ not supported yet
  283. ***** ^ undeclared identifier
  284. ***** ^ undeclared identifier
  285. ***** ^ not supported yet
  286. 156 FileError := BlockRead(handle, ADR(blocknum), 4);
  287. ***** ^ not supported yet
  288. ***** ^ not supported yet
  289. ***** ^ not supported yet
  290. ***** ^ not supported yet
  291. ***** ^ not supported yet
  292. 157 blockpos := blocknum * VAL(LONGINT,MemoBlockSize);
  293. ***** ^ undeclared identifier
  294. ***** ^ not supported yet
  295. 158 SetFilePtr(handle, FromStart, blockpos);
  296. ***** ^ not supported yet
  297. ***** ^ undeclared identifier
  298. ***** ^ not supported yet
  299. 159 FileError := BlockWrite(handle, ADR(memo), Length(memo));
  300. ***** ^ not supported yet
  301. ***** ^ not supported yet
  302. ***** ^ not supported yet
  303. ***** ^ not supported yet
  304. ***** ^ not supported yet
  305. ***** ^ not supported yet
  306. 160 IF (Length(memo) MOD MemoBlockSize) # 0 THEN
  307. ***** ^ not supported yet
  308. ***** ^ not supported yet
  309. 161 PadFile( handle, EndOfMemo, MemoBlockSize -
  310. ***** ^ not supported yet
  311. 162 (Length(memo) MOD MemoBlockSize) );
  312. ***** ^ not supported yet
  313. ***** ^ not supported yet
  314. ***** ^ not supported yet
  315. 163 END;
  316. 164 LongIntegerToStr(blocknum, 10,ptrstr);
  317. ***** ^ not supported yet
  318. ***** ^ not supported yet
  319. 165 Replace(alias, fieldnum, ptrstr);
  320. ***** ^ not supported yet
  321. ***** ^ not supported yet
  322. ***** ^ not supported yet
  323. 166 blockpos := GetFilePtr(handle);
  324. ***** ^ not supported yet
  325. ***** ^ not supported yet
  326. 167 (* find what will be the next available block
  327. 168 And write it to the first 4 bytes of the file *)
  328. 169 blocknum := blockpos DIV VAL(LONGINT,MemoBlockSize);
  329. ***** ^ undeclared identifier
  330. ***** ^ not supported yet
  331. 170 SetFilePtr(handle, FromStart, VAL(LONGINT,0));
  332. ***** ^ not supported yet
  333. ***** ^ undeclared identifier
  334. ***** ^ undeclared identifier
  335. ***** ^ not supported yet
  336. 171 FileError := BlockWrite(handle, ADR(blocknum), 4);
  337. ***** ^ not supported yet
  338. ***** ^ not supported yet
  339. ***** ^ not supported yet
  340. ***** ^ not supported yet
  341. ***** ^ not supported yet
  342. 172 END;
  343. 173 DISPOSE(OldMemo);
  344. ***** ^ undeclared identifier
  345. ***** ^ not supported yet
  346. 174 ELSE
  347. 175 Replace(alias, fieldnum,' ');
  348. ***** ^ not supported yet
  349. ***** ^ not supported yet
  350. ***** ^ not supported yet
  351. 176 END;
  352. 177 END ReplaceM;
  353. ***** ^ not supported yet
  354. 178
  355. 179 BEGIN
  356. 180 END MemoFunctions.
  357. ***** ^ not supported yet
  358. 176 errors