home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_38.arc / 86WRLD38.FIG next >
Text File  |  1987-09-21  |  2KB  |  63 lines

  1. { listing 1 - corrected Exec for Turbo Pascal }
  2.  
  3. {--------------------------- Exec ----------------------------}
  4. {    execute 'Command' as if it was typed at the A> prompt    }
  5. {      requires Getenvironment function from Micro C. 32      }
  6. {-------------------------------------------------------------}
  7. FUNCTION Exec (Command : string128) : INTEGER;
  8.  
  9. CONST
  10.     SSSave   : INTEGER = 0;
  11.     SPSave   : INTEGER = 0;
  12.     RetAX    : INTEGER = 0;
  13.     RetFlags : INTEGER = 0;
  14.  
  15. TYPE
  16.     ExecPacketRec = RECORD
  17.         EnvironmentSeg : INTEGER;
  18.         CommandPtr,
  19.         FCB1,
  20.         FCB2           : ^CHAR;
  21.         end;    { ExecPacketRec }
  22.  
  23. VAR ComFile  : String20;
  24.     ExecPack : ExecPacketRec;
  25.  
  26.     begin
  27.     ComFile := GetEnvironment('COMSPEC')+chr(0);{ execute command.com }
  28.     IF (length(command) > 0) THEN              { sending it this line }
  29.         Insert ('/c ',Command,1);        { 'c' switch means 'do this' }
  30.     command[length(command)+1] := ^M;
  31.  
  32.     ExecPack.EnvironmentSeg := $0000;      { use parent's environment }
  33.     ExecPack.CommandPtr := Ptr(seg(Command),ofs(Command));
  34.     ExecPack.FCB1 := Ptr(0,0);
  35.     ExecPack.FCB2 := Ptr(0,0);
  36.  
  37.     { START OF MODIFIED AREA }
  38.     inline($06/$1E/$55/$9C/     { push es, ds, bp, flags              }
  39.            $8C/$D0/$8E/$D8/     { mov ax,ss  mov ds,ax (seg(ComFile)) }
  40.            $BA/ComFile/         { mov dx,offset ComFile[0]            }
  41.            $01/$EA/$42/         { add dx,bp  inc dx                   }
  42.            $8E/$C0/             { mov es,ax           (seg(ExecPack)) }
  43.            $BB/ExecPack/        { mov bx,offset ExecPack              }
  44.            $01/$EB/             { add bx,bp                           }
  45.            $B8/$00/$4B/         { mov ax,4B00h          }
  46.            $2E/$8C/$16/SSSave/  { mov cs:[SSSave],ss <<-}
  47.            $2E/$89/$26/SPSave/  { mov cs:[SPSave],sp <<-}
  48.            $CD/$21/             { int 21h               }
  49.            $2E/$8E/$16/SSSave/  { mov ss,cs:[SSSave] <<-}
  50.            $2E/$8B/$26/SPSave/  { mov sp,cs:[SPSave] <<-}
  51.            $2E/$A3/RetAX/       { mov cs:[RetAX],ax     }
  52.            $9C/$58/             { pushf pop ax          }
  53.            $2E/$A3/RetFlags/    { mov cs:[RetFlags],ax  }
  54.            $9D/$5D/$1F/$07);    { pop flags, bp, ds, es }
  55.  
  56.     IF ((RetFlags and CARRY) = 0) THEN
  57.         Exec := 0
  58.     ELSE
  59.         Exec := RetAX;
  60.     { END OF MODIFIED AREA }
  61.     end;   { Exec }
  62.  
  63.