Listing: 1 IMPLEMENTATION MODULE EnvironUtils; 2 (* 3 * REPERTOIRE 4 * Release 1.6 5 * By Charles Bradford and Cole Brecheen 6 * (c) Copyright 1985-1991 PMI 7 * Portland, Oregon 8 * All rights reserved 9 * (503) 236-1788 10 * 11 * $Header: D:/logfiles/mods/environu.mov 1.9 17 Mar 1991 17:52:14 coleb $ 12 *) 13 14 15 (*EntryDiag: 16 IMPORT Diagnostics; 17 :EntryDiag*) 18 19 IMPORT ByteFiddler; 20 IMPORT ErrorManager; 21 IMPORT LowLevel; 22 IMPORT M2Strings; 23 IMPORT FAPI; 24 IMPORT PosUtils; 25 IMPORT StrConv; 26 IMPORT StrEdit; 27 IMPORT StringIO; 28 IMPORT SYSTEM; 29 IMPORT VStorage; 30 31 VAR 32 Initialized : BOOLEAN; 33 34 PROCEDURE Init(); 35 BEGIN 36 IF Initialized THEN 37 RETURN; 38 ELSE 39 Initialized := TRUE; 40 END; 41 (*EntryDiag: 42 Diagnostics.Init(); 43 :EntryDiag*) 44 45 ByteFiddler.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 46 ErrorManager.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 47 LowLevel.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 48 M2Strings.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 49 PosUtils.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 50 StrConv.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 51 StrEdit.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 52 StringIO.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 53 VStorage.Init(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 54 END Init; ***** ^ not supported yet 55 56 57 PROCEDURE CutFirstParam(VAR TheStr : ARRAY OF CHAR); ***** ^ not supported yet 58 (* use when running under Logitech's run-time debugger *) 59 VAR 60 spot : CARDINAL; 61 BEGIN 62 StrEdit.CrunchBlanks(TheStr); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 63 spot := M2Strings.Pos(' ',TheStr); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 64 IF spot<=HIGH(TheStr) THEN ***** ^ undeclared identifier ***** ^ not supported yet 65 M2Strings.Delete(TheStr, 0, spot+1); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 66 ELSE 67 StrEdit.SetLength(TheStr, 0); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 68 END; 69 END CutFirstParam; ***** ^ not supported yet 70 71 72 PROCEDURE GetProgParams(VAR ParamStr : ARRAY OF CHAR); ***** ^ not supported yet 73 VAR 74 StrAdr : LowLevel.Address8086; ***** ^ not supported yet 75 knownLength, errcode, cnt, tmpw, CmdLineOffs : CARDINAL; 76 tmpc : CHAR; 77 LastWasNull: BOOLEAN; 78 machineMode: CARDINAL; 79 BEGIN 80 machineMode := 0; 81 (* Have to initialize machineMode because DOSGETMACHINEMODE is 82 * actually expecting the address of a single byte; we use a 83 * CARDINAL because JPI is obstinate about letting us compare 84 * byte values with the constants in FAPI.DEF. 85 *) 86 errcode := FAPI.DOSGETMACHINEMODE(SYSTEM.ADR(machineMode)); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 87 IF machineMode = FAPI.MODE_REAL THEN ***** ^ not supported yet ***** ^ not supported yet 88 StrAdr.seg := GetPSP(); ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet 89 StrAdr.off := 81H; ***** ^ not supported yet ***** ^ not supported yet 90 knownLength := ORD(LowLevel.PeekByte(StrAdr.seg, StrAdr.off - 1)); ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 91 ELSE 92 knownLength := 0FFFFH; 93 (* In protected mode, the command line follows the 94 * environment block. Not so in real mode. It's in the PSP 95 * in real mode. And in real mode, you have to pay attention 96 * to the length byte that precedes the command line. You 97 * can't count on null termination, which is the only thing 98 * that signals the end of the command line in protected 99 * mode. 100 *) 101 IF FAPI.DOSGETENV( ***** ^ not supported yet ***** ^ not supported yet 102 SYSTEM.ADR(StrAdr.seg), ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 103 SYSTEM.ADR(CmdLineOffs )) # 0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 104 ErrorManager.WARN( "Failed to get command line." ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 105 END; 106 StrAdr.off := CmdLineOffs; ***** ^ not supported yet ***** ^ not supported yet 107 tmpc := LowLevel.PeekByte(StrAdr.seg,StrAdr.off ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 108 WHILE (tmpc # 0C) DO 109 (* Now we start on the fully qualified name of the program. *) 110 INC(StrAdr.off); ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet 111 tmpc := LowLevel.PeekByte(StrAdr.seg, StrAdr.off); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 112 END; 113 INC( StrAdr.off ); ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet 114 END; 115 116 LowLevel.Fill( SYSTEM.ADR(ParamStr), HIGH(ParamStr) + 1, 0C ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet 117 (* Fill the whole thing with nulls so we don't have to worry 118 about terminating the string in the right place. *) 119 cnt := 0; 120 tmpc := StrAdr.b^; ***** ^ not supported yet ***** ^ not supported yet 121 (* If there are any parameters at all, this 122 will always be a space. *) 123 WHILE (tmpc # 0C) AND 124 (tmpc # 377C) AND 125 (cnt <= HIGH(ParamStr)) AND ***** ^ undeclared identifier ***** ^ not supported yet 126 ((cnt + 1) < knownLength) DO 127 (* Now we are on the parameters. *) 128 INC(StrAdr.off); ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet 129 tmpc := StrAdr.b^; ***** ^ not supported yet ***** ^ not supported yet 130 ParamStr[ cnt ] := tmpc; ***** ^ not supported yet ***** ^ not supported yet 131 INC( cnt ); ***** ^ undeclared identifier ***** ^ not supported yet 132 END; 133 END GetProgParams; ***** ^ not supported yet 134 135 136 PROCEDURE ParsedParam( ParamNum: CARDINAL; VAR Result: ARRAY 137 OF CHAR ): BOOLEAN; ***** ^ not supported yet 138 VAR 139 ParamCnt, BlankSpot1, BlankSpot2: CARDINAL; 140 FullLine: ARRAY [0..255] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 141 BEGIN 142 GetProgParams( FullLine ); ***** ^ not supported yet ***** ^ not supported yet 143 StrEdit.CrunchBlanks( FullLine ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 144 StrEdit.Append( FullLine, ' ' ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 145 IF M2Strings.Length( FullLine ) > 1 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 146 IF (ParamNum = 0) THEN 147 ErrorManager.WARN('Zero passed to ParsedParam'); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 148 END; 149 ParamCnt := 0; 150 BlankSpot1 := 0; 151 BlankSpot2 := 0; 152 WHILE (ParamCnt < ParamNum) AND 153 (BlankSpot2 <= HIGH(FullLine) ) DO ***** ^ undeclared identifier ***** ^ not supported yet 154 BlankSpot2 := PosUtils.Positn( ' ', FullLine, BlankSpot2 ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 155 INC( ParamCnt ); ***** ^ undeclared identifier ***** ^ not supported yet 156 IF ParamCnt < ParamNum THEN 157 BlankSpot1 := BlankSpot2; 158 INC( BlankSpot2 ); ***** ^ undeclared identifier ***** ^ not supported yet 159 END; 160 END; 161 IF BlankSpot2 > HIGH(FullLine) THEN ***** ^ undeclared identifier ***** ^ not supported yet 162 RETURN(FALSE); 163 ELSE 164 IF BlankSpot1 # 0 THEN 165 INC(BlankSpot1); ***** ^ undeclared identifier ***** ^ not supported yet 166 END; 167 M2Strings.Copy( FullLine, BlankSpot1, ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 168 BlankSpot2 - BlankSpot1, Result ); ***** ^ not supported yet 169 RETURN(TRUE); 170 END; 171 ELSE 172 RETURN(FALSE); 173 END; 174 END ParsedParam; ***** ^ not supported yet 175 176 177 PROCEDURE GetDosVersion(VAR major, minor : CARDINAL); 178 VAR 179 tmpc : CARDINAL; 180 BEGIN 181 tmpc := 0; 182 FAPI.DOSGETVERSION( SYSTEM.ADR(tmpc )); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 183 major := ORD( CHAR(ByteFiddler.HighByte( tmpc )) ); ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 184 minor := ORD( CHAR(ByteFiddler.LowByte( tmpc )) ); ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 185 END GetDosVersion; ***** ^ not supported yet 186 187 188 PROCEDURE GetPSP() : CARDINAL; 189 VAR 190 rgstr : LowLevel.regpack; ***** ^ not supported yet 191 errcode, DosVersion, Subvers, PSPseg : CARDINAL; 192 machineMode: CARDINAL; 193 BEGIN 194 machineMode := 0; 195 (* Have to initialize machineMode because DOSGETMACHINEMODE is 196 * actually expecting the address of a single byte; we use a 197 * CARDINAL because JPI is obstinate about letting us compare 198 * byte values with the constants in FAPI.DEF. 199 *) 200 errcode := FAPI.DOSGETMACHINEMODE(SYSTEM.ADR(machineMode)); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 201 IF machineMode = FAPI.MODE_REAL THEN ***** ^ not supported yet ***** ^ not supported yet 202 GetDosVersion(DosVersion, Subvers); ***** ^ not supported yet ***** ^ not supported yet 203 IF DosVersion >= 3 THEN 204 rgstr.a.h := 142C; (* 62H *) ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 205 ELSE 206 rgstr.a.h := 121C; (* 51H *) ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 207 END; 208 LowLevel.msdos( rgstr); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 209 IF LowLevel.FlaggedError(rgstr.flags) THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 210 ErrorManager.WarnNumber("DOS error getting PSP:", ORD(rgstr.a.l)); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ undeclared identifier ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 211 END; 212 RETURN (rgstr.b.x); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 213 ELSE 214 ErrorManager.WARN("Attempt to GetPSP in protected mode"); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 215 END; 216 RETURN(0); 217 END GetPSP; ***** ^ not supported yet 218 219 220 PROCEDURE EnvironmentSeg(): CARDINAL; 221 VAR 222 pspSeg, envSeg, cmdlineOffs, errcode: CARDINAL; 223 machineMode: CARDINAL; 224 BEGIN 225 machineMode := 0; 226 (* Have to initialize machineMode because DOSGETMACHINEMODE is 227 * actually expecting the address of a single byte; we use a 228 * CARDINAL because JPI is obstinate about letting us compare 229 * byte values with the constants in FAPI.DEF. 230 *) 231 errcode := FAPI.DOSGETMACHINEMODE(SYSTEM.ADR(machineMode)); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 232 IF machineMode = FAPI.MODE_REAL THEN ***** ^ not supported yet ***** ^ not supported yet 233 (* We break out the steps to make them easier to see in CodeView. *) 234 pspSeg := GetPSP(); ***** ^ not supported yet ***** ^ not supported yet 235 envSeg := LowLevel.PeekWord( pspSeg, 2CH ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 236 (*Get segment address of the environment from PSP.*) 237 ELSE 238 errcode := FAPI.DOSGETENV(SYSTEM.ADR(envSeg), SYSTEM.ADR(cmdlineOffs)); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 239 (*Even though this is FAPI, it just doesn't seem to work 240 under DOS. That's why we're doing it differently depending 241 on the mode we're in. cmdlineOffs is telling us where the 242 command line is in the environment segment, but we don't care 243 about that now.*) 244 END; 245 RETURN envSeg; 246 END EnvironmentSeg; ***** ^ not supported yet 247 248 249 PROCEDURE ReadEnvironment(name : ARRAY OF CHAR; VAR parameter : ***** ^ not supported yet 250 ARRAY OF CHAR); ***** ^ not supported yet 251 VAR 252 bufch : CHAR; 253 tmpcopy : ARRAY [0..255] OF CHAR; ***** ^ not supported yet ***** ^ not supported yet 254 (*expanded from [0..80] on 11 Nov 86*) 255 found : BOOLEAN; 256 cmdlineOffs, pspSeg, errcode, EnvSeg, EnvNdx, cnt, EqSpot: CARDINAL; 257 machineMode: SYSTEM.BYTE; ***** ^ not supported yet 258 BEGIN 259 EnvSeg := EnvironmentSeg(); ***** ^ not supported yet ***** ^ not supported yet 260 (* We'd like to call DOSSCANENV here, but it's not FAPI. *) 261 262 EnvNdx := 0; 263 found := FALSE; 264 StrEdit.SetLength(parameter, 0); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 265 StrEdit.CAPstr( name ); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 266 267 REPEAT 268 StrEdit.SetLength(tmpcopy, 0); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 269 bufch := LowLevel.PeekByte(EnvSeg,EnvNdx); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 270 WHILE bufch # 0C DO 271 bufch := CAP(bufch); ***** ^ undeclared identifier ***** ^ not supported yet 272 StrEdit.Append(tmpcopy, bufch); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 273 INC(EnvNdx); ***** ^ undeclared identifier ***** ^ not supported yet 274 bufch := LowLevel.PeekByte(EnvSeg,EnvNdx); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 275 END; 276 IF M2Strings.Pos(name,tmpcopy)=0 THEN ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 277 EqSpot := M2Strings.Pos('=',tmpcopy); ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 278 IF (EqSpot16) DO ***** ^ not supported yet ***** ^ not supported yet ***** ^ not supported yet 430 lasttry := try; 431 try := lowtry + (try-lowtry) DIV 2; 432 END; 433 IF ((lasttry-try) > within) AND (try>16) THEN 434 lowtry := try; 435 try := try + (lasttry-try) DIV 2; 436 ELSE 437 EXIT; 438 END; 439 END; 440 IF try<=16 THEN 441 RETURN 0; 442 ELSE 443 RETURN try; 444 END; 445 END MemAvail; ***** ^ not supported yet 446 447 BEGIN 448 Initialized := FALSE; 449 Init(); ***** ^ not supported yet ***** ^ not supported yet 450 END EnvironUtils. ***** ^ not supported yet 505 errors