STRINGIO.LST 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. Listing:
  2. 1 IMPLEMENTATION MODULE StringIO;
  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/stringio.mov 1.7 17 Mar 1991 18:00:12 coleb $
  13. 12 *
  14. 13 *)
  15. 14
  16. 15 IMPORT ErrStrgs;
  17. 16 IMPORT ErrorManager;
  18. 17 IMPORT LowLevel;
  19. 18 IMPORT M2Strings;
  20. 19 IMPORT SYSTEM;
  21. 20 IMPORT FAPI;
  22. 21
  23. 22 VAR
  24. 23 Initialized : BOOLEAN;
  25. 24
  26. 25 PROCEDURE Init();
  27. 26 BEGIN
  28. 27 IF Initialized THEN
  29. 28 RETURN;
  30. 29 ELSE
  31. 30 Initialized := TRUE;
  32. 31 END;
  33. 32 ErrStrgs.Init();
  34. ***** ^ not supported yet
  35. ***** ^ not supported yet
  36. ***** ^ not supported yet
  37. 33 ErrorManager.Init();
  38. ***** ^ not supported yet
  39. ***** ^ not supported yet
  40. ***** ^ not supported yet
  41. 34 LowLevel.Init();
  42. ***** ^ not supported yet
  43. ***** ^ not supported yet
  44. ***** ^ not supported yet
  45. 35 M2Strings.Init();
  46. ***** ^ not supported yet
  47. ***** ^ not supported yet
  48. ***** ^ not supported yet
  49. 36 CrLf[0] := 15C;
  50. ***** ^ undeclared identifier
  51. ***** ^ not supported yet
  52. 37 CrLf[1] := 12C;
  53. ***** ^ undeclared identifier
  54. ***** ^ not supported yet
  55. 38 END Init;
  56. ***** ^ not supported yet
  57. 39
  58. 40
  59. 41 PROCEDURE WriteStr(FileHandle : CARDINAL; TheStr : ARRAY OF CHAR);
  60. ***** ^ not supported yet
  61. 42 VAR
  62. 43 BytesWritten: CARDINAL;
  63. 44 ErrorReturn: CARDINAL;
  64. 45 BEGIN
  65. 46 ErrorReturn := FAPI.DOSWRITE( FileHandle, SYSTEM.ADR(TheStr),
  66. ***** ^ not supported yet
  67. ***** ^ not supported yet
  68. ***** ^ not supported yet
  69. ***** ^ not supported yet
  70. ***** ^ not supported yet
  71. 47 M2Strings.Length(TheStr), SYSTEM.ADR(BytesWritten) );
  72. ***** ^ not supported yet
  73. ***** ^ not supported yet
  74. ***** ^ not supported yet
  75. ***** ^ not supported yet
  76. ***** ^ not supported yet
  77. ***** ^ not supported yet
  78. 48 IF ErrorReturn #0 THEN
  79. 49 ErrorManager.WarnNumber("DOSWRITE error", ErrorReturn);
  80. ***** ^ not supported yet
  81. ***** ^ not supported yet
  82. ***** ^ not supported yet
  83. ***** ^ not supported yet
  84. 50 END;
  85. 51 END WriteStr;
  86. ***** ^ not supported yet
  87. 52
  88. 53
  89. 54 PROCEDURE ReadStr(FileHandle : CARDINAL; VAR TheStr : ARRAY OF CHAR);
  90. ***** ^ not supported yet
  91. 55 VAR
  92. 56 lngth : FAPI.STRINGINBUF;
  93. ***** ^ not supported yet
  94. 57 BytesRead, StrSize, CrSpot : CARDINAL;
  95. 58 Distance, NewFilePtr, OldFilePtr : LONGINT;
  96. 59 linefeed: ARRAY [0..0] OF CHAR;
  97. ***** ^ not supported yet
  98. ***** ^ not supported yet
  99. 60 hAtr,hType: CARDINAL;
  100. 61
  101. 62 PROCEDURE ReadKbd;
  102. 63 VAR
  103. 64 KbdState : FAPI.KBDINFO;
  104. ***** ^ not supported yet
  105. 65 s:ARRAY[0..255] OF CHAR;
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. 66 BEGIN
  109. 67 (* we have to got through some contortions here because KBDSTRINGIN
  110. 68 returns the final carriage return loosing the last chr position *)
  111. 69 KbdState.cb := 10;
  112. ***** ^ not supported yet
  113. ***** ^ not supported yet
  114. 70 KbdState.fsMask := FAPI.KEYBOARD_ECHO_ON + FAPI.KEYBOARD_ASCII_MODE;
  115. ***** ^ not supported yet
  116. ***** ^ not supported yet
  117. ***** ^ not supported yet
  118. ***** ^ not supported yet
  119. ***** ^ not supported yet
  120. ***** ^ not supported yet
  121. 71 KbdState.chTurnAround := 0;
  122. ***** ^ not supported yet
  123. ***** ^ not supported yet
  124. 72 KbdState.fsInterim := 0;
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. 73 KbdState.fsState := 0;
  128. ***** ^ not supported yet
  129. ***** ^ not supported yet
  130. 74 IF 0 # FAPI.KBDSETSTATUS( SYSTEM.ADR(KbdState), FileHandle) THEN
  131. ***** ^ not supported yet
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. ***** ^ not supported yet
  136. ***** ^ not supported yet
  137. 75 END;
  138. 76
  139. 77 lngth.cb := StrSize+1;
  140. ***** ^ not supported yet
  141. ***** ^ not supported yet
  142. 78 IF 0 # FAPI.KBDSTRINGIN( SYSTEM.ADR(s),
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. ***** ^ not supported yet
  146. ***** ^ not supported yet
  147. ***** ^ not supported yet
  148. 79 SYSTEM.ADR(lngth), 0, FileHandle ) THEN
  149. ***** ^ not supported yet
  150. ***** ^ not supported yet
  151. ***** ^ not supported yet
  152. ***** ^ not supported yet
  153. 80 END;
  154. 81 (* KBDSTRNGIN Echos the carriage return. *)
  155. 82 WriteStr( outp, linefeed );
  156. ***** ^ not supported yet
  157. ***** ^ undeclared identifier
  158. ***** ^ not supported yet
  159. 83 (* So we make the best of it by echoing a linefeed. *)
  160. 84 s[ lngth.cchIn ] := 0C;
  161. ***** ^ not supported yet
  162. ***** ^ not supported yet
  163. ***** ^ not supported yet
  164. 85 M2Strings.Assign(s,TheStr);
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. ***** ^ not supported yet
  169. 86 END ReadKbd;
  170. ***** ^ not supported yet
  171. 87
  172. 88 BEGIN
  173. 89 (*ReadStr*)
  174. 90 TheStr[0] := 0C;
  175. ***** ^ not supported yet
  176. ***** ^ not supported yet
  177. 91 linefeed[0] := CHR(10);
  178. ***** ^ not supported yet
  179. ***** ^ not supported yet
  180. ***** ^ undeclared identifier
  181. ***** ^ not supported yet
  182. 92 StrSize := HIGH(TheStr)+1;
  183. ***** ^ undeclared identifier
  184. ***** ^ not supported yet
  185. 93 (* check to see if handle is a keybourd
  186. 94 under os/2 there could be other keybourd handles
  187. 95 also the keybourd could be redirected to a file.
  188. 96 JM 7/17/92 *)
  189. 97
  190. 98 IF FAPI.DOSQHANDTYPE(FileHandle,SYSTEM.ADR(hType),SYSTEM.ADR(hAtr)) # 0 THEN
  191. ***** ^ not supported yet
  192. ***** ^ not supported yet
  193. ***** ^ not supported yet
  194. ***** ^ not supported yet
  195. ***** ^ not supported yet
  196. ***** ^ not supported yet
  197. ***** ^ not supported yet
  198. ***** ^ not supported yet
  199. 99 ErrorManager.WARN("KBDSETSTATUS");
  200. ***** ^ not supported yet
  201. ***** ^ not supported yet
  202. ***** ^ not supported yet
  203. 100 END;
  204. 101
  205. 102 IF( hType=1) AND (8001H IN BITSET( hAtr)) (*Std in and char device *)
  206. ***** ^ undeclared identifier
  207. ***** ^ not supported yet
  208. 103 THEN
  209. 104 ReadKbd;
  210. ***** ^ not supported yet
  211. 105 ELSE
  212. 106
  213. 107 IF FAPI.DOSCHGFILEPTR( FileHandle,
  214. ***** ^ not supported yet
  215. ***** ^ not supported yet
  216. 108 VAL(LONGINT, 0), 1, SYSTEM.ADR(OldFilePtr)) # 0 THEN
  217. ***** ^ undeclared identifier
  218. ***** ^ not supported yet
  219. ***** ^ not supported yet
  220. ***** ^ not supported yet
  221. ***** ^ not supported yet
  222. 109 END;
  223. 110 (* Move 0 bytes relative to the current position in the
  224. 111 file so that we can find out what our current position is. *)
  225. 112 LowLevel.Fill( SYSTEM.ADR(TheStr), StrSize, 0C );
  226. ***** ^ not supported yet
  227. ***** ^ not supported yet
  228. ***** ^ not supported yet
  229. ***** ^ not supported yet
  230. ***** ^ not supported yet
  231. ***** ^ not supported yet
  232. 113 IF FAPI.DOSREAD( FileHandle, SYSTEM.ADR(TheStr),
  233. ***** ^ not supported yet
  234. ***** ^ not supported yet
  235. ***** ^ not supported yet
  236. ***** ^ not supported yet
  237. ***** ^ not supported yet
  238. 114 StrSize, SYSTEM.ADR(BytesRead) ) = 0 THEN
  239. ***** ^ not supported yet
  240. ***** ^ not supported yet
  241. ***** ^ not supported yet
  242. 115 CrSpot := LowLevel.ScanEQ( BytesRead, CHR(13), SYSTEM.ADR(TheStr) );
  243. ***** ^ not supported yet
  244. ***** ^ not supported yet
  245. ***** ^ undeclared identifier
  246. ***** ^ not supported yet
  247. ***** ^ not supported yet
  248. ***** ^ not supported yet
  249. ***** ^ not supported yet
  250. 116 (* Scan for a carriage return *)
  251. 117 IF (CrSpot < BytesRead) THEN
  252. 118 (* We found one. *)
  253. 119 TheStr[CrSpot] := 0C;
  254. ***** ^ not supported yet
  255. ***** ^ not supported yet
  256. 120 IF (CrSpot < HIGH(TheStr)) AND (TheStr[CrSpot + 1] = CHR(10)) THEN
  257. ***** ^ undeclared identifier
  258. ***** ^ not supported yet
  259. ***** ^ not supported yet
  260. ***** ^ not supported yet
  261. ***** ^ undeclared identifier
  262. ***** ^ not supported yet
  263. 121 (* If the next character is a linefeed *)
  264. 122 INC( CrSpot );
  265. ***** ^ undeclared identifier
  266. ***** ^ not supported yet
  267. 123 TheStr[CrSpot] := 0C;
  268. ***** ^ not supported yet
  269. ***** ^ not supported yet
  270. 124 END;
  271. 125 IF FAPI.DOSCHGFILEPTR( FileHandle,
  272. ***** ^ not supported yet
  273. ***** ^ not supported yet
  274. 126 OldFilePtr + VAL(LONGINT, CrSpot+1), 0,
  275. ***** ^ undeclared identifier
  276. ***** ^ not supported yet
  277. 127 SYSTEM.ADR(NewFilePtr)) # 0 THEN
  278. ***** ^ not supported yet
  279. ***** ^ not supported yet
  280. ***** ^ not supported yet
  281. 128 END;
  282. 129 END;
  283. 130 ELSE
  284. 131 ErrorManager.WARN("DOSREAD error ");
  285. ***** ^ not supported yet
  286. ***** ^ not supported yet
  287. ***** ^ not supported yet
  288. 132 END;
  289. 133
  290. 134 END;
  291. 135
  292. 136 END ReadStr;
  293. ***** ^ not supported yet
  294. 137
  295. 138
  296. 139 PROCEDURE ReadString(FileHandle : CARDINAL; VAR
  297. 140 TheStr : ARRAY OF CHAR; VAR EndOfFileReached:
  298. ***** ^ not supported yet
  299. 141 BOOLEAN );
  300. 142 VAR
  301. 143 StrSize, BytesRead, CrSpot: CARDINAL;
  302. 144 OldFilePtr, NewFilePtr: LONGINT;
  303. 145 BEGIN
  304. 146 StrSize := HIGH(TheStr) + 1;
  305. ***** ^ undeclared identifier
  306. ***** ^ not supported yet
  307. 147 IF FAPI.DOSCHGFILEPTR( FileHandle,
  308. ***** ^ not supported yet
  309. ***** ^ not supported yet
  310. 148 VAL(LONGINT, 0), 1, SYSTEM.ADR(OldFilePtr)) # 0 THEN
  311. ***** ^ undeclared identifier
  312. ***** ^ not supported yet
  313. ***** ^ not supported yet
  314. ***** ^ not supported yet
  315. ***** ^ not supported yet
  316. 149 END;
  317. 150 (* Move 0 bytes relative to the current position in the
  318. 151 file so that we can find out what our current position is. *)
  319. 152 LowLevel.Fill( SYSTEM.ADR(TheStr), StrSize, 0C );
  320. ***** ^ not supported yet
  321. ***** ^ not supported yet
  322. ***** ^ not supported yet
  323. ***** ^ not supported yet
  324. ***** ^ not supported yet
  325. ***** ^ not supported yet
  326. 153 (* If the following read fails, maybe because we've reached
  327. 154 the end of the file, it won't zero out TheStr. We have to
  328. 155 make sure TheStr is null if we're not reading a new string. *)
  329. 156 IF FAPI.DOSREAD( FileHandle, SYSTEM.ADR(TheStr),
  330. ***** ^ not supported yet
  331. ***** ^ not supported yet
  332. ***** ^ not supported yet
  333. ***** ^ not supported yet
  334. ***** ^ not supported yet
  335. 157 StrSize, SYSTEM.ADR(BytesRead) ) = 0 THEN
  336. ***** ^ not supported yet
  337. ***** ^ not supported yet
  338. ***** ^ not supported yet
  339. 158 CrSpot := LowLevel.ScanEQ( BytesRead, CHR(13), SYSTEM.ADR(TheStr) );
  340. ***** ^ not supported yet
  341. ***** ^ not supported yet
  342. ***** ^ undeclared identifier
  343. ***** ^ not supported yet
  344. ***** ^ not supported yet
  345. ***** ^ not supported yet
  346. ***** ^ not supported yet
  347. 159 (* Scan for a carriage return *)
  348. 160 IF (CrSpot < BytesRead) THEN
  349. 161 (* We found one. *)
  350. 162 TheStr[CrSpot] := 0C;
  351. ***** ^ not supported yet
  352. ***** ^ not supported yet
  353. 163 BytesRead := StrSize;
  354. 164 IF (CrSpot < HIGH(TheStr)) AND (TheStr[CrSpot + 1] = CHR(10)) THEN
  355. ***** ^ undeclared identifier
  356. ***** ^ not supported yet
  357. ***** ^ not supported yet
  358. ***** ^ not supported yet
  359. ***** ^ undeclared identifier
  360. ***** ^ not supported yet
  361. 165 (* If the next character is a linefeed *)
  362. 166 INC( CrSpot );
  363. ***** ^ undeclared identifier
  364. ***** ^ not supported yet
  365. 167 TheStr[CrSpot] := 0C;
  366. ***** ^ not supported yet
  367. ***** ^ not supported yet
  368. 168 END;
  369. 169 IF FAPI.DOSCHGFILEPTR( FileHandle,
  370. ***** ^ not supported yet
  371. ***** ^ not supported yet
  372. 170 OldFilePtr + VAL(LONGINT, CrSpot + 1), 0,
  373. ***** ^ undeclared identifier
  374. ***** ^ not supported yet
  375. 171 SYSTEM.ADR(NewFilePtr)) # 0 THEN
  376. ***** ^ not supported yet
  377. ***** ^ not supported yet
  378. ***** ^ not supported yet
  379. 172 END;
  380. 173 END;
  381. 174 END;
  382. 175 EndOfFileReached := BytesRead < StrSize;
  383. 176 END ReadString;
  384. ***** ^ not supported yet
  385. 177
  386. 178
  387. 179 PROCEDURE WriteEol(FileHandle : CARDINAL; TheStr : ARRAY OF CHAR);
  388. ***** ^ not supported yet
  389. 180 VAR
  390. 181 TmpStr : ARRAY [0..255] OF CHAR;
  391. ***** ^ not supported yet
  392. ***** ^ not supported yet
  393. 182 bufstr : ARRAY [0..2] OF CHAR;
  394. ***** ^ not supported yet
  395. ***** ^ not supported yet
  396. 183 BEGIN
  397. 184 IF M2Strings.Length(TheStr)<=254 THEN
  398. ***** ^ not supported yet
  399. ***** ^ not supported yet
  400. ***** ^ not supported yet
  401. 185 M2Strings.Concat(TheStr, CrLf, TmpStr);
  402. ***** ^ not supported yet
  403. ***** ^ not supported yet
  404. ***** ^ not supported yet
  405. ***** ^ undeclared identifier
  406. ***** ^ not supported yet
  407. 186 WriteStr(FileHandle, TmpStr);
  408. ***** ^ not supported yet
  409. ***** ^ not supported yet
  410. 187 ELSE
  411. 188 WriteStr(FileHandle, TheStr);
  412. ***** ^ not supported yet
  413. ***** ^ not supported yet
  414. 189 WriteStr(FileHandle, CrLf);
  415. ***** ^ not supported yet
  416. ***** ^ undeclared identifier
  417. 190 END;
  418. 191 END WriteEol;
  419. ***** ^ not supported yet
  420. 192
  421. 193
  422. 194 PROCEDURE MessageType(FunctionResult : CHAR) : CARDINAL;
  423. 195 BEGIN
  424. 196 RETURN ORD( FunctionResult );
  425. ***** ^ undeclared identifier
  426. ***** ^ not supported yet
  427. 197 END MessageType;
  428. ***** ^ not supported yet
  429. 198
  430. 199
  431. 200 PROCEDURE PrintMessage(FunctionResult : CARDINAL);
  432. 201 VAR
  433. 202 TmpStr: ARRAY [0..79] OF CHAR;
  434. ***** ^ not supported yet
  435. ***** ^ not supported yet
  436. 203 BEGIN
  437. 204 ErrStrgs.NumToStr( FunctionResult, TmpStr );
  438. ***** ^ not supported yet
  439. ***** ^ not supported yet
  440. ***** ^ not supported yet
  441. 205 CASE FunctionResult OF
  442. 206 NoError : (*do nothing*)
  443. ***** ^ undeclared identifier
  444. 207 | PartialRead, EndOfFile:
  445. ***** ^ undeclared identifier
  446. ***** ^ undeclared identifier
  447. 208 WriteStr( ErrorOutp, TmpStr );
  448. ***** ^ not supported yet
  449. ***** ^ undeclared identifier
  450. ***** ^ not supported yet
  451. 209 ELSE
  452. 210 ErrorManager.WARN( TmpStr );
  453. ***** ^ not supported yet
  454. ***** ^ not supported yet
  455. ***** ^ not supported yet
  456. 211 END;
  457. 212 END PrintMessage;
  458. ***** ^ not supported yet
  459. 213
  460. 214 BEGIN
  461. 215 Initialized := FALSE;
  462. 216 Init();
  463. ***** ^ not supported yet
  464. ***** ^ not supported yet
  465. 217 END StringIO.
  466. ***** ^ not supported yet
  467. 248 errors