Listing: 1 IMPLEMENTATION MODULE StringIO; 2 (* 3 * REPERTOIRE 4 * Release 1.6 5 * By Charles Bradford and Cole Brecheen 6 * (c) Copyright 1985-1992 PMI 7 * Green Bay, Wisconsin 8 * All rights reserved 9 * (414) 468-6040 10 * 11 * $Header: D:/logfiles/mods/stringio.mov 1.7 17 Mar 1991 18:00:12 coleb $ 12 * 13 *) 14 15 IMPORT ErrStrgs; 16 IMPORT ErrorManager; 17 IMPORT LowLevel; 18 IMPORT M2Strings; 19 IMPORT SYSTEM; 20 IMPORT FAPI; 21 22 VAR 23 Initialized : BOOLEAN; 24 25 PROCEDURE Init(); 26 BEGIN 27 IF Initialized THEN 28 RETURN; 29 ELSE 30 Initialized := TRUE; 31 END; 32 ErrStrgs.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 33 ErrorManager.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 34 LowLevel.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 35 M2Strings.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 36 CrLf[0] := 15C; ***** ^ undeclared identifier ***** ^ not supported yet 37 CrLf[1] := 12C; ***** ^ undeclared identifier ***** ^ not supported yet 38 END Init; ***** ^ not supported yet 39 40 41 PROCEDURE WriteStr(FileHandle : CARDINAL; TheStr : ARRAY OF CHAR); ***** ^ not supported yet 42 VAR 43 BytesWritten: CARDINAL; 44 ErrorReturn: CARDINAL; 45 BEGIN 46 ErrorReturn := FAPI.DOSWRITE( FileHandle, SYSTEM.ADR(TheStr), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 47 M2Strings.Length(TheStr), SYSTEM.ADR(BytesWritten) ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 48 IF ErrorReturn #0 THEN 49 ErrorManager.WarnNumber("DOSWRITE error", ErrorReturn); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 50 END; 51 END WriteStr; ***** ^ not supported yet 52 53 54 PROCEDURE ReadStr(FileHandle : CARDINAL; VAR TheStr : ARRAY OF CHAR); ***** ^ not supported yet 55 VAR 56 lngth : FAPI.STRINGINBUF; ***** ^ not supported yet 57 BytesRead, StrSize, CrSpot : CARDINAL; 58 Distance, NewFilePtr, OldFilePtr : LONGINT; 59 linefeed: ARRAY [0..0] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 60 hAtr,hType: CARDINAL; 61 62 PROCEDURE ReadKbd; 63 VAR 64 KbdState : FAPI.KBDINFO; ***** ^ not supported yet 65 s:ARRAY[0..255] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 66 BEGIN 67 (* we have to got through some contortions here because KBDSTRINGIN 68 returns the final carriage return loosing the last chr position *) 69 KbdState.cb := 10; ***** ^ not supported yet ***** ^ not supported yet 70 KbdState.fsMask := FAPI.KEYBOARD_ECHO_ON + FAPI.KEYBOARD_ASCII_MODE; ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 71 KbdState.chTurnAround := 0; ***** ^ not supported yet ***** ^ not supported yet 72 KbdState.fsInterim := 0; ***** ^ not supported yet ***** ^ not supported yet 73 KbdState.fsState := 0; ***** ^ not supported yet ***** ^ not supported yet 74 IF 0 # FAPI.KBDSETSTATUS( SYSTEM.ADR(KbdState), FileHandle) THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 75 END; 76 77 lngth.cb := StrSize+1; ***** ^ not supported yet ***** ^ not supported yet 78 IF 0 # FAPI.KBDSTRINGIN( SYSTEM.ADR(s), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 79 SYSTEM.ADR(lngth), 0, FileHandle ) THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 80 END; 81 (* KBDSTRNGIN Echos the carriage return. *) 82 WriteStr( outp, linefeed ); ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 83 (* So we make the best of it by echoing a linefeed. *) 84 s[ lngth.cchIn ] := 0C; ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 85 M2Strings.Assign(s,TheStr); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 86 END ReadKbd; ***** ^ not supported yet 87 88 BEGIN 89 (*ReadStr*) 90 TheStr[0] := 0C; ***** ^ not supported yet ***** ^ not supported yet 91 linefeed[0] := CHR(10); ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 92 StrSize := HIGH(TheStr)+1; ***** ^ undeclared identifier ***** ^ not supported yet 93 (* check to see if handle is a keybourd 94 under os/2 there could be other keybourd handles 95 also the keybourd could be redirected to a file. 96 JM 7/17/92 *) 97 98 IF FAPI.DOSQHANDTYPE(FileHandle,SYSTEM.ADR(hType),SYSTEM.ADR(hAtr)) # 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 99 ErrorManager.WARN("KBDSETSTATUS"); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 100 END; 101 102 IF( hType=1) AND (8001H IN BITSET( hAtr)) (*Std in and char device *) ***** ^ undeclared identifier ***** ^ not supported yet 103 THEN 104 ReadKbd; ***** ^ not supported yet 105 ELSE 106 107 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 108 VAL(LONGINT, 0), 1, SYSTEM.ADR(OldFilePtr)) # 0 THEN ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 109 END; 110 (* Move 0 bytes relative to the current position in the 111 file so that we can find out what our current position is. *) 112 LowLevel.Fill( SYSTEM.ADR(TheStr), StrSize, 0C ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 113 IF FAPI.DOSREAD( FileHandle, SYSTEM.ADR(TheStr), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 114 StrSize, SYSTEM.ADR(BytesRead) ) = 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 115 CrSpot := LowLevel.ScanEQ( BytesRead, CHR(13), SYSTEM.ADR(TheStr) ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 116 (* Scan for a carriage return *) 117 IF (CrSpot < BytesRead) THEN 118 (* We found one. *) 119 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 120 IF (CrSpot < HIGH(TheStr)) AND (TheStr[CrSpot + 1] = CHR(10)) THEN ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 121 (* If the next character is a linefeed *) 122 INC( CrSpot ); ***** ^ undeclared identifier ***** ^ not supported yet 123 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 124 END; 125 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 126 OldFilePtr + VAL(LONGINT, CrSpot+1), 0, ***** ^ undeclared identifier ***** ^ not supported yet 127 SYSTEM.ADR(NewFilePtr)) # 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 128 END; 129 END; 130 ELSE 131 ErrorManager.WARN("DOSREAD error "); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 132 END; 133 134 END; 135 136 END ReadStr; ***** ^ not supported yet 137 138 139 PROCEDURE ReadString(FileHandle : CARDINAL; VAR 140 TheStr : ARRAY OF CHAR; VAR EndOfFileReached: ***** ^ not supported yet 141 BOOLEAN ); 142 VAR 143 StrSize, BytesRead, CrSpot: CARDINAL; 144 OldFilePtr, NewFilePtr: LONGINT; 145 BEGIN 146 StrSize := HIGH(TheStr) + 1; ***** ^ undeclared identifier ***** ^ not supported yet 147 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 148 VAL(LONGINT, 0), 1, SYSTEM.ADR(OldFilePtr)) # 0 THEN ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 149 END; 150 (* Move 0 bytes relative to the current position in the 151 file so that we can find out what our current position is. *) 152 LowLevel.Fill( SYSTEM.ADR(TheStr), StrSize, 0C ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 153 (* If the following read fails, maybe because we've reached 154 the end of the file, it won't zero out TheStr. We have to 155 make sure TheStr is null if we're not reading a new string. *) 156 IF FAPI.DOSREAD( FileHandle, SYSTEM.ADR(TheStr), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 157 StrSize, SYSTEM.ADR(BytesRead) ) = 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 158 CrSpot := LowLevel.ScanEQ( BytesRead, CHR(13), SYSTEM.ADR(TheStr) ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 159 (* Scan for a carriage return *) 160 IF (CrSpot < BytesRead) THEN 161 (* We found one. *) 162 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 163 BytesRead := StrSize; 164 IF (CrSpot < HIGH(TheStr)) AND (TheStr[CrSpot + 1] = CHR(10)) THEN ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 165 (* If the next character is a linefeed *) 166 INC( CrSpot ); ***** ^ undeclared identifier ***** ^ not supported yet 167 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 168 END; 169 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 170 OldFilePtr + VAL(LONGINT, CrSpot + 1), 0, ***** ^ undeclared identifier ***** ^ not supported yet 171 SYSTEM.ADR(NewFilePtr)) # 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 172 END; 173 END; 174 END; 175 EndOfFileReached := BytesRead < StrSize; 176 END ReadString; ***** ^ not supported yet 177 178 179 PROCEDURE WriteEol(FileHandle : CARDINAL; TheStr : ARRAY OF CHAR); ***** ^ not supported yet 180 VAR 181 TmpStr : ARRAY [0..255] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 182 bufstr : ARRAY [0..2] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 183 BEGIN 184 IF M2Strings.Length(TheStr)<=254 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 185 M2Strings.Concat(TheStr, CrLf, TmpStr); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 186 WriteStr(FileHandle, TmpStr); ***** ^ not supported yet ***** ^ not supported yet 187 ELSE 188 WriteStr(FileHandle, TheStr); ***** ^ not supported yet ***** ^ not supported yet 189 WriteStr(FileHandle, CrLf); ***** ^ not supported yet ***** ^ undeclared identifier 190 END; 191 END WriteEol; ***** ^ not supported yet 192 193 194 PROCEDURE MessageType(FunctionResult : CHAR) : CARDINAL; 195 BEGIN 196 RETURN ORD( FunctionResult ); ***** ^ undeclared identifier ***** ^ not supported yet 197 END MessageType; ***** ^ not supported yet 198 199 200 PROCEDURE PrintMessage(FunctionResult : CARDINAL); 201 VAR 202 TmpStr: ARRAY [0..79] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 203 BEGIN 204 ErrStrgs.NumToStr( FunctionResult, TmpStr ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 205 CASE FunctionResult OF 206 NoError : (*do nothing*) ***** ^ undeclared identifier 207 | PartialRead, EndOfFile: ***** ^ undeclared identifier ***** ^ undeclared identifier 208 WriteStr( ErrorOutp, TmpStr ); ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 209 ELSE 210 ErrorManager.WARN( TmpStr ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 211 END; 212 END PrintMessage; ***** ^ not supported yet 213 214 BEGIN 215 Initialized := FALSE; 216 Init(); ***** ^ not supported yet ***** ^ not supported yet 217 END StringIO. ***** ^ not supported yet 248 errors