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 KbdState : FAPI.KBDINFO; ***** ^ not supported yet 57 lngth : FAPI.STRINGINBUF; ***** ^ not supported yet 58 BytesRead, StrSize, CrSpot : CARDINAL; 59 Distance, NewFilePtr, OldFilePtr : LONGINT; 60 linefeed: ARRAY [0..0] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 61 62 BEGIN 63 (*ReadStr*) 64 TheStr[0] := 0C; ***** ^ not supported yet ***** ^ not supported yet 65 linefeed[0] := CHR(10); ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 66 StrSize := HIGH(TheStr); ***** ^ undeclared identifier ***** ^ not supported yet 67 (* For some mysterious reason, if you set StrSize to HIGH+1, 68 the call to KBDSTRINGIN doesn't wait for input. *) 69 IF FileHandle = inp THEN ***** ^ undeclared identifier 70 71 KbdState.cb := 10; ***** ^ not supported yet ***** ^ not supported yet 72 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 73 KbdState.chTurnAround := 0; ***** ^ not supported yet ***** ^ not supported yet 74 KbdState.fsInterim := 0; ***** ^ not supported yet ***** ^ not supported yet 75 KbdState.fsState := 0; ***** ^ not supported yet ***** ^ not supported yet 76 77 IF 0 # FAPI.KBDSETSTATUS( SYSTEM.ADR(KbdState), 0 ) THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 78 END; 79 80 lngth.cb := StrSize; ***** ^ not supported yet ***** ^ not supported yet 81 IF 0 # FAPI.KBDSTRINGIN( SYSTEM.ADR(TheStr), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 82 SYSTEM.ADR(lngth), 0, 0 ) THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 83 END; 84 (* This goddamned thing echoes the carriage return. *) 85 WriteStr( outp, linefeed ); ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 86 (* So we make the best of it by echoing a linefeed. *) 87 TheStr[ lngth.cchIn ] := 0C; ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 88 RETURN; 89 END; 90 91 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 92 VAL(LONGINT, 0), 1, SYSTEM.ADR(OldFilePtr)) # 0 THEN ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 93 END; 94 (* Move 0 bytes relative to the current position in the 95 file so that we can find out what our current position is. *) 96 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 97 IF FAPI.DOSREAD( FileHandle, SYSTEM.ADR(TheStr), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 98 StrSize, SYSTEM.ADR(BytesRead) ) = 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 99 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 100 (* Scan for a carriage return *) 101 IF (CrSpot < BytesRead) THEN 102 (* We found one. *) 103 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 104 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 105 (* If the next character is a linefeed *) 106 INC( CrSpot ); ***** ^ undeclared identifier ***** ^ not supported yet 107 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 108 END; 109 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 110 OldFilePtr + VAL(LONGINT, CrSpot+1), 0, ***** ^ undeclared identifier ***** ^ not supported yet 111 SYSTEM.ADR(NewFilePtr)) # 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 112 END; 113 END; 114 ELSE 115 ErrorManager.WARN("DOSREAD error "); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 116 END; 117 END ReadStr; ***** ^ not supported yet 118 119 120 PROCEDURE ReadString(FileHandle : CARDINAL; VAR 121 TheStr : ARRAY OF CHAR; VAR EndOfFileReached: ***** ^ not supported yet 122 BOOLEAN ); 123 VAR 124 StrSize, BytesRead, CrSpot: CARDINAL; 125 OldFilePtr, NewFilePtr: LONGINT; 126 BEGIN 127 StrSize := HIGH(TheStr) + 1; ***** ^ undeclared identifier ***** ^ not supported yet 128 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 129 VAL(LONGINT, 0), 1, SYSTEM.ADR(OldFilePtr)) # 0 THEN ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 130 END; 131 (* Move 0 bytes relative to the current position in the 132 file so that we can find out what our current position is. *) 133 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 134 (* If the following read fails, maybe because we've reached 135 the end of the file, it won't zero out TheStr. We have to 136 make sure TheStr is null if we're not reading a new string. *) 137 IF FAPI.DOSREAD( FileHandle, SYSTEM.ADR(TheStr), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 138 StrSize, SYSTEM.ADR(BytesRead) ) = 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 139 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 140 (* Scan for a carriage return *) 141 IF (CrSpot < BytesRead) THEN 142 (* We found one. *) 143 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 144 BytesRead := StrSize; 145 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 146 (* If the next character is a linefeed *) 147 INC( CrSpot ); ***** ^ undeclared identifier ***** ^ not supported yet 148 TheStr[CrSpot] := 0C; ***** ^ not supported yet ***** ^ not supported yet 149 END; 150 IF FAPI.DOSCHGFILEPTR( FileHandle, ***** ^ not supported yet ***** ^ not supported yet 151 OldFilePtr + VAL(LONGINT, CrSpot + 1), 0, ***** ^ undeclared identifier ***** ^ not supported yet 152 SYSTEM.ADR(NewFilePtr)) # 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 153 END; 154 END; 155 END; 156 EndOfFileReached := BytesRead < StrSize; 157 END ReadString; ***** ^ not supported yet 158 159 160 PROCEDURE WriteEol(FileHandle : CARDINAL; TheStr : ARRAY OF CHAR); ***** ^ not supported yet 161 VAR 162 TmpStr : ARRAY [0..255] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 163 bufstr : ARRAY [0..2] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 164 BEGIN 165 IF M2Strings.Length(TheStr)<=254 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 166 M2Strings.Concat(TheStr, CrLf, TmpStr); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 167 WriteStr(FileHandle, TmpStr); ***** ^ not supported yet ***** ^ not supported yet 168 ELSE 169 WriteStr(FileHandle, TheStr); ***** ^ not supported yet ***** ^ not supported yet 170 WriteStr(FileHandle, CrLf); ***** ^ not supported yet ***** ^ undeclared identifier 171 END; 172 END WriteEol; ***** ^ not supported yet 173 174 175 PROCEDURE MessageType(FunctionResult : CHAR) : CARDINAL; 176 BEGIN 177 RETURN ORD( FunctionResult ); ***** ^ undeclared identifier ***** ^ not supported yet 178 END MessageType; ***** ^ not supported yet 179 180 181 PROCEDURE PrintMessage(FunctionResult : CARDINAL); 182 VAR 183 TmpStr: ARRAY [0..79] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 184 BEGIN 185 ErrStrgs.NumToStr( FunctionResult, TmpStr ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 186 CASE FunctionResult OF 187 NoError : (*do nothing*) ***** ^ undeclared identifier 188 | PartialRead, EndOfFile: ***** ^ undeclared identifier ***** ^ undeclared identifier 189 WriteStr( ErrorOutp, TmpStr ); ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 190 ELSE 191 ErrorManager.WARN( TmpStr ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 192 END; 193 END PrintMessage; ***** ^ not supported yet 194 195 BEGIN 196 Initialized := FALSE; 197 Init(); ***** ^ not supported yet ***** ^ not supported yet 198 END StringIO. ***** ^ not supported yet 228 errors