home *** CD-ROM | disk | FTP | other *** search
- (*$V-,R-*)
- PROGRAM DosRun; {This is the PibDoDos.pas program altered to include a menu
- procedure and with most of the long blocks of comments
- removed, in order to better see the code. I have found that
- this system works quite well, but does hang for one interation
- when the child program ends other than normally. I have not
- implemented any checking of the error code returned by the
- external program TURBORUN.COM, which this program demonstrates.
- Stephen C. McGough, for the Turbo Pascal SIG, Madison IBM PC
- User Group.}
-
-
- {$I MENUMOD.INC} {This is a set of routines which I took from the file }
- {"TURBUTIL.PAS"; it supplies a highlighted menu, which
- returns an integer representing the selection. The use
- of the menu system is described below. -SCM}
-
-
- CONST
- NUL = #00 (* Terminator for DOS Ascii z-strings *);
-
- TYPE
- AnyStr = STRING[255];
- Char_Array = ARRAY[1..1] OF CHAR;
- Char_Ptr = ^Char_Array;
-
- VAR
- Command_Line: AnyStr (* Command to be executed *);
- Return_Code: INTEGER (* DOS return code *);
- ComSpec: AnyStr (* Comspec from DOS environment *);
-
-
- FUNCTION UpCaseStr(S : AnyStr): AnyStr;
- var
- i : integer;
- begin
- for i := 1 to length(S) do
- S[i] := UpCase(S[i]);
- UpCaseStr := S;
- end;
-
-
- {########################################################################}
-
- PROCEDURE RunExt( VAR Ret_Code: INTEGER;
- VAR Command_Line );
-
- EXTERNAL 'TURBORUN.COM'; {This is the program which makes it all work.}
-
- {########################################################################}
-
-
- PROCEDURE Get_ComSpec( VAR ComSpec: AnyStr ); {This procedure is probably not
- necessary, if you have not
- altered the location of the
- COMMAND.COM file.}
-
- CONST
- ComSpec_String: String[7] = 'OMSPEC=';
-
- VAR
- Env_Ptr: Char_Ptr;
- Env_Pos: INTEGER;
- Env_Found: BOOLEAN;
- Spec_Pos: INTEGER;
- I: INTEGER;
-
- BEGIN (* Get_ComSpec *)
- (* Initialize ComSpec to null string *)
- ComSpec := '';
- (* Pick up starting address, offset of *)
- (* DOS environment string. *)
-
- Env_Ptr := PTR( MEMW[ CSEG: $2C] , 0 );
- Env_Pos := 0;
- (* Search for COMSPEC= in environment. *)
- (* Following will be file definition of *)
- (* COMMAND.COM. *)
- REPEAT
- (* Look for initial 'C' of 'COMSPEC=' *)
-
- WHILE( Env_Ptr^[Env_Pos] <> 'C' ) DO
- Env_Pos := Env_Pos + 1;
- (* Flag indicating environment string *)
- (* has been found -- assume TRUE to *)
- (* start *)
- Env_Found := TRUE;
-
- I := 1;
- (* Check characters after 'C'. Are they *)
- (* 'OMSPEC=' ? *)
-
- WHILE ( Env_Found AND ( I < 8 ) ) DO
- IF Env_Ptr^[Env_Pos + I] = ComSpec_String[ I ] THEN
- I := I + 1
- ELSE
- Env_Found := FALSE;
-
- Spec_Pos := Env_Pos + I;
- (* If 'OMSPEC=' found, then we found *)
- (* the comspec. If not, keep going. *)
-
- IF ( I = 8 ) THEN
- Env_Found := TRUE
- ELSE
- BEGIN
- WHILE ( Env_Ptr^[Spec_Pos] <> NUL ) DO
- Spec_Pos := Spec_Pos + 1;
- Env_Pos := Spec_Pos;
- END;
-
- UNTIL Env_Found;
-
- (* Pick up the COMMAND.COM definition *)
- (* following the COMSPEC=. *)
-
- WHILE ( Env_Ptr^[Spec_Pos] <> NUL ) DO
- BEGIN
- ComSpec := ComSpec + Env_Ptr^[Spec_Pos];
- Spec_Pos := Spec_Pos + 1;
- END;
-
- END (* Get_ComSpec *);
-
-
-
- Procedure DoCommand;
- BEGIN
-
- {*} Command_Line := UpCaseStr(Command_Line); {*}
-
- (* Prefix comspec to command line *)
-
- IF LENGTH( Command_Line ) > 0 THEN
- Command_Line := ComSpec + ' /C ' + Command_Line + NUL
- ELSE
- Command_Line := ComSpec + NUL;
-
- (* Execute the command *)
-
- RunExt( Return_Code , Command_Line[1] );
-
-
- End; {of DoCommand}
-
-
-
- { * * * * * DEMO OF THE PROGRAM * * * * * }
-
- Var
- MenuList1 : Menu_Selections;
- MenuChoice: integer;
- Count : integer;
-
- BEGIN
- ClrScr;
- Get_ComSpec(comspec);
-
-
- {Using the MenuModule: Define up to 15 prompts in array MenuList.
- The last prompt must be the null string. These prompts will be
- passed to the function "Menu" below}
-
- MenuList1[1] := ' Run REFLEX ';
- MenuList1[2] := ' Run MICROSOFT WORD ';
- MenuList1[3] := ' Run INPUT PREPROSSER ';
- MenuList1[4] := ' DOS Gateway ';
- MenuList1[5] := ' END ';
- MenuList1[6] := '';
-
- Command_Line := '';
- REPEAT
- IF COMMAND_LINE <> 'END' THEN
- Begin
- Window(1,1,80,25);
- ClrScr;
- Window(14,1,64,25);
-
- {The function "Menu" returns an integer corresponding to the
- subscript of the prompt selected from array "MenuList1". The
- parameters passed to "Menu" are:
-
- the name of the array of prompts
- the X location of the menu; if 0 then it will be centered
- the Y location of the menu
- the menu's title string in single quotes
- the X location of the title;if 0 then it will be centered
- the Y location of the title
- the default selection (integer)
- }
-
- Menuchoice := Menu(MenuList1,0,10,'PLEASE MAKE YOUR CHOICE FROM THIS MENU',0,4,1);
- case MenuChoice of
-
- 1:Begin
- Command_Line := 'cd \reflex';
- DoCommand;
- Command_Line := 'reflex.com';
- DoCommand;
- end;
- 2:begin
- ClrScr;
- Command_Line := 'cd \';
- DoCommand;
- Command_line := 'word.bat';
- DoCommand;
- ClrScr;
- end;
- 3:begin
- ClrScr;
- Command_Line := 'cd \turbo\workarea';
- DoCommand;
- Command_Line := 'main.com';
- DoCommand;
- ClrScr;
- end;
- 4:begin
- ClrScr;
- for count := 1 to 5 do
- Writeln('* * * TO RETURN TO THE MENU TYPE "EXIT" * * *');
- Command_Line := '';
- DoCommand;
- ClrScr;
- end;
- 5:begin
- ClrScr;
- Command_Line := 'END';
- end;
- end;
- END;
- UNTIL (COMMAND_LINE = 'END');
- END (*DosRun*).
-