home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_32.arc / 86WORLD.FIG next >
Text File  |  1979-12-31  |  4KB  |  178 lines

  1.  
  2. <<86 figure 1 - GetEnvironment for Pascal >>
  3.  
  4. CONST string128 = string[128];
  5.  
  6. {----------------------- GetEnvironment ----------------------}
  7. {    return the value of the Environment Variable 'EnvVar'    }
  8. {-------------------------------------------------------------}
  9. FUNCTION GetEnvironment (EnvVar : String128) : String128;
  10.  
  11. CONST
  12.     NULL = ^@;
  13.  
  14. VAR
  15.     EnvPtr : ^CHAR;
  16.     EnvSeg : INTEGER ABSOLUTE CSEG:$2C;
  17.     EnvOfs : INTEGER;
  18.     Found  : BOOLEAN;
  19.     TmpStr, MatchStr : String128;
  20.  
  21. begin
  22. TmpStr := '';
  23. EnvOfs := 0;
  24. EnvPtr := Ptr(EnvSeg, EnvOfs);
  25. Found  := FALSE;
  26. WHILE (EnvPtr^ <> NULL) AND (NOT Found) DO
  27.  
  28.     { check for match of current variable name }
  29.     begin
  30.     MatchStr := '';
  31.     WHILE (EnvPtr^ <> NULL) DO
  32.         { extract an environment variable name and its value }
  33.         begin
  34.         MatchStr := MatchStr + EnvPtr^;
  35.         EnvOfs := EnvOfs+1;
  36.         EnvPtr := Ptr(EnvSeg, EnvOfs);
  37.         end;
  38.     IF (EnvVar = Copy (MatchStr, 1, POS('=',MatchStr)-1)) THEN
  39.         { Found the variable, get its value to return }
  40.         begin
  41.         TmpStr := COPY(MatchStr, POS('=',MatchStr)+1, Length(MatchStr));
  42.         Found := TRUE;
  43.         end  {  if variable found }
  44.     ELSE
  45.         { Not Found, move past NULL to next variable }
  46.         begin
  47.         EnvOfs := EnvOfs+1;
  48.         EnvPtr := Ptr(EnvSeg,EnvOfs);
  49.         end;  { variable not found }
  50.     end;  { while not found and not end of environment }
  51.  
  52. GetEnvironment := TmpStr;   { transfer result into return variable }
  53. end;  { GetEnvironment }
  54.  
  55.  
  56. <<86 figure 2 - GetEnvironment for assembly language >>
  57. ;
  58. ;    GetEnvironment- return a pointer to the value of a string
  59. ;            in the MSDOS "Environment"
  60. ;
  61. ;    ENTRY: DS:SI --> a string (in Pascal Format) containing var. name
  62. ;
  63. ;    EXIT:  IF (NC)  ES:DI --> the value of said variable
  64. ;           IF (C) nothing (not found)
  65.  
  66. ENVSEG    equ    word ptr cs:2Ch    ;ptr to environment in base page
  67.  
  68. GetEnvironment    PROC    Near
  69.     PUSH    AX
  70.     PUSH    CX
  71.     PUSH    SI
  72.  
  73.     MOV    ES,ENVSEG
  74.     XOR    DI,DI
  75.     XOR    AX,AX
  76.     CMP    ES:[DI],AL    ;see if no environment at all
  77.     JZ    GetEnv9
  78. GetEnv1:
  79.     POP    SI        ;retrieve string address
  80.     PUSH    SI
  81.         MOV     CL,[SI]
  82.     XOR    CH,CH
  83.         INC     SI
  84.     REPE    CMPSB        ;try to match
  85.     JNZ    GetEnv2
  86.  
  87.     CMP    ES:byte ptr [DI],'='
  88.     JZ    GetEnv3        ;FOUND
  89. GetEnv2:
  90.     MOV    CX,0FFFFh    ;NOT FOUND
  91.         REPNZ    SCASB        ;scan until 0
  92.     CMP    ES:[DI],AL
  93.     JZ    GetEnv9        ;if double 0 then end of environment
  94.     JMP    GetEnv1        ;else try next one
  95. GetEnv3:
  96.     INC    DI        ;point past '='
  97.     STC            ;indicate FOUND
  98. GetEnv9:
  99.     POP    SI
  100.     POP    CX
  101.     POP    AX
  102.     CMC
  103.     RET
  104. GetEnvironment    ENDP
  105.  
  106.  
  107. <<86 figure 3 - new FINDCOMSPEC for assembly language Exec >>
  108.  
  109. COMSPECSTR    DB    7,'COMSPEC'
  110.  
  111. FINDCOMSPEC:
  112.     PUSH    SI
  113.         MOV    PATHOFS,offset DEFPATH    ;set up default
  114.     MOV    PATHSEG,DS
  115.  
  116.     MOV    SI,offset COMSPECSTR
  117.     CALL    GetEnvironment
  118.     JC    FINDCOMSPEC9
  119.  
  120.         MOV    PATHOFS,DI        ;found
  121.     MOV    PATHSEG,ES
  122. FINDCOMSPEC9:
  123.     POP    SI
  124.     RET
  125.  
  126.  
  127. <<86 figure 4 - new TESTEXEC to test modified EXEC >>
  128. ;
  129. ;    TESTEXEC.ASM - test the new exec procedure
  130. ;
  131. ;    This program MUST be made into a .COM file:
  132. ;
  133. ;        masm testexec;
  134. ;        link testexec+asmexec;
  135. ;        exe2bin testexec
  136. ;        ren testexec.bin testexec.com
  137. ;        erase testexec.exe
  138. ;
  139.     EXTRN    Exec:NEAR
  140.  
  141. Code    segment    byte public 'CODE'
  142.     assume    cs:code,ds:code
  143.     org    100h
  144. TESTEXEC:
  145.     MOV    SP,8000h
  146.     MOV    BX,800h    ;request 32k even though we'll never need it
  147.     MOV    AH,4Ah    ;actually we are 'freeing' all but 32k
  148.     INT    21h
  149.  
  150.     MOV    SI,80h    ;execute the command trailer
  151.     CALL    EXEC    ;in the base page (CS:80h)
  152.  
  153.     MOV    AH,4Ch    ;(since this is a COM, CS==DS)
  154.     INT    21h
  155. Code    ENDS
  156.  
  157.     end    TESTEXEC
  158.  
  159.  
  160. ((This is 86world figure A.))
  161.  
  162. DB    'M2LIB=C:\M2\LIB',0
  163. DB    'PATH=C:\;C:\BIN;\',0
  164. DB    'CLUB=Sierra',0
  165. DB    'NEIGHBORHOOD=Watts'
  166.     .
  167.     .
  168. DB    0
  169.  
  170. ((this is 86 Fig. B))
  171.  
  172. ComFile := '\command.com'+chr(0);
  173.  
  174. ((this is 86 Fig C))
  175.  
  176. ComFile := GetEnvironment('COMSPEC')
  177.            +chr(0);
  178.