Category : Modula II Source Code
Archive   : TASKING.ZIP
Filename : GETPSP.MOD

 
Output of file : GETPSP.MOD contained in archive : TASKING.ZIP
IMPLEMENTATION MODULE GetPSP;

FROM SYSTEM IMPORT
BYTE, ADDRESS, SWI, RTSVECTOR, SETREG, GETREG, AX, BX, CX;

PROCEDURE getarg(argnum: argno; VAR arg: ARRAY OF CHAR);
(*
returns empty string for arg(numberOfArgs+1)
returns a program name for arg(0) (may be phoney)
args are delimited by blanks
*)
VAR
i, j, len, cmd: CARDINAL;
BEGIN
WITH PSPptr^ DO
len := ORD(commTail[0]);
i := 1;
(* skip leading blank(s) *)
WHILE (i <= len) & (commTail[i] = ' ') DO INC(i) END;
(* skip to requested arg *)
j := 0;
WHILE (i <= len) & (j < argnum) DO
WHILE (i <= len) & (commTail[i] # ' ') DO INC(i) END;
WHILE (i <= len) & (commTail[i] = ' ') DO INC(i) END;
INC(j);
END;
(* copy requested arg *)
j := 0;
WHILE (i <= len) & (commTail[i] # ' ') & (j <= HIGH(arg)) DO
arg[j] := commTail[i];
INC(j);
INC(i);
END;
END; (* with *)
IF j <= HIGH(arg) THEN arg[j] := 0C END;
END getarg;

PROCEDURE getenv(key: ARRAY OF CHAR; VAR val: ARRAY OF CHAR);
VAR
i, j, cnt: CARDINAL;
found: BOOLEAN;
match: BOOLEAN;

PROCEDURE toupper(ch: CHAR): CHAR;
BEGIN
IF (ch >= 'a') & (ch <= 'z') THEN
ch := CAP(ch);
END;
RETURN ch;
END toupper;

BEGIN (* getenv *)
i := 0;
cnt := 0;
WHILE ENVIRptr^[cnt] # 0C DO (* while not last string *)
j := 0;
match := TRUE;
REPEAT
IF match THEN (* still matching ?*)
IF ((j > HIGH(key)) OR (key[j] = 0C)) THEN (* end of key string ? *)
IF ENVIRptr^[cnt] = '=' THEN (* end of env name ? *)
j := 0; (* copy env to result string *)
REPEAT
INC(cnt);
val[j] := ENVIRptr^[cnt];
INC(j);
UNTIL ENVIRptr^[cnt] = 0C;
RETURN; (* found *)
ELSE
match := FALSE;
END;
ELSE (* still comparing *)
match := toupper(key[j]) = ENVIRptr^[cnt];
END;
INC(j);
END; (* if match *)
INC(cnt);
UNTIL ENVIRptr^[cnt] = 0C; (* end of one env string *)
INC(cnt);
END; (* while *)
val[0] := 0C; (* no match *)
END getenv;

VAR
tmpPtr: ADDRESS;

BEGIN
SETREG(AX, 0026H); (* RTS(38) - get Program Segment Prefix Pointer *)
SWI(RTSVECTOR); (* rts call *)
GETREG(BX, tmpPtr.OFFSET);
GETREG(CX, tmpPtr.SEGMENT);
PSPptr := tmpPtr;
tmpPtr.SEGMENT := PSPptr^.EnvironmentSeg;
tmpPtr.OFFSET := 0;
ENVIRptr := tmpPtr;
END GetPSP.


  3 Responses to “Category : Modula II Source Code
Archive   : TASKING.ZIP
Filename : GETPSP.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/