home *** CD-ROM | disk | FTP | other *** search
- {------------------------------------------------------------}
- {- FlashPac Pascal Library (Dos1 Unit) - V3.5 -}
- {- (c) Copyright 1986-1991 - All Rights Reserved -}
- {- SimpleSoft Inc -}
- {- 1209 Poplar St -}
- {- La Crescent, MN 55947 -}
- {------------------------------------------------------------}
-
- Unit FPDos1;
- Interface
- {$B-,F+}
- {$IFNDEF VER40}
- {D-}
- {$ENDIF}
- Uses Dos;
-
- {--------------------------------------------------------------------}
-
- Procedure Beep(Freq,Dur : Word);
-
- {$IFNDEF VER60}
- Function DosExec( CommandLine : String ) : integer;
- {$ENDIF}
-
-
- Implementation
-
- Const
- Copyright1 = 'FlashPac Pascal Library (Dos Unit) - V3.5';
- Copyright2 = '(c) Copyright 1986-1991 - All Rights Reserved';
- Copyright3 = 'SimpleSoft, Inc.';
- Copyright4 = '1209 Poplar St';
- Copyright5 = 'La Crescent, MN 55947';
-
- {$L dos1\beep }
-
- {--------------------------------------------------------------------}
-
- Procedure Beep; External;
-
- {$IFNDEF VER60}
- {---------------------------------------------------------------------}
- {- This function gives a programmer the ability to execute any -}
- {- program from Turbo Pascal 4.0/5.0 without having to specify the -}
- {- maximum heap limit. This function uses the DOS function call -}
- {- 4ah to return the unused memory in the heap to DOS. The CmdLine -}
- {- contains the full filespec of the program to be executed and the -}
- {- command line parameters for the program being executed. The -}
- {- maximum length for the CmdLine is 127 characters. -}
- {- -}
- {- 1. Program saves the contents of the Free list onto the heap. -}
- {- 2. Frees up unsed memory area between the current HeapPtr and -}
- {- the top of memory and returns it to DOS. -}
- {- 3. Parses the CmdLine and passes the parameters into Turbo's -}
- {- Exec command. -}
- {- 4. On return the program reclaims the memory left in DOS -}
- {- 5. Restores the Free memory block list to high memory -}
- {- 6. Returns a termination code to the calling statement. -}
- {- -}
- {- Return Codes: -}
- {- 0 - Normal termination -}
- {- 1 - Invalid function number -}
- {- 2 - File not found -}
- {- 5 - Access denied -}
- {- 8 - insufficient memory -}
- {- 10 - invalid envoronment -}
- {- 11 - invalid format -}
- {- 999 - Length of command line string is to long -}
- {- -}
- {---------------------------------------------------------------------}
-
- Function DosExec( CommandLine : String ) : Integer;
- Const
- ReturnCode : Integer = 0;
- FreeSize : Word = 0;
- Var
- FreeCopy : ^Byte;
- i : Integer;
- Path : String;
- CmdLine : String;
- Regs : Registers;
-
- Begin
-
- {------------------------------------------------------------------}
- {- check parm string length -}
- {------------------------------------------------------------------}
-
- If Length( CommandLine ) > 127 Then
- DosExec := 999
- Else Begin
-
- {---------------------------------------------------------------}
- {- save Free list if need be -}
- {---------------------------------------------------------------}
-
- If Ofs(FreePtr^) <> 0 Then Begin
- FreeSize := 0 - Ofs( FreePtr^ );
- GetMem( FreeCopy, FreeSize + 16 );
- move( FreePtr^, FreeCopy^, FreeSize );
- End;
-
- {---------------------------------------------------------------}
- {- realloc memory block to minimum amount needed. -}
- {---------------------------------------------------------------}
-
- Regs.es := PrefixSeg;
- Regs.bx := Seg( HeapPtr^ ) - PrefixSeg + 1;
- Regs.ah := $4a;
- Intr( $21, Regs );
-
- {---------------------------------------------------------------}
- {- Parse command line -}
- {---------------------------------------------------------------}
-
- FillChar( Path, SizeOf( Path ) , 0 );
- FillChar( CmdLine, SizeOf( CmdLine ), 0 );
- i := Pos( ' ', CommandLine );
- If i = 0 Then
- Path := Copy( CommandLine, 1, Length( CommandLine ) )
- Else Begin
- Path := Copy( CommandLine, 1, i-1 );
- CmdLine := Copy( CommandLine, i+1, Length( CommandLine ) - i );
- End;
-
- {---------------------------------------------------------------}
- {- execute the child process -}
- {---------------------------------------------------------------}
-
- Exec( Path, CmdLine ); {- call child process -}
- If DosError = 0 Then
- ReturnCode := DosExitCode {- set return code -}
- Else
- ReturnCode := DosError;
-
- {---------------------------------------------------------------}
- {- reclaim child process's memory -}
- {---------------------------------------------------------------}
-
- Regs.es := PrefixSeg; {- ask for 1 meg of memory to find -}
- Regs.bx := $0ffff; {- out how many paragraphs are -}
- Regs.ah := $4a; {- available. Amount of memory -}
- Intr( $21, Regs ); {- available is returned in bx. -}
-
- Regs.ah := $4a; {- reclaim amount of memory -}
- Intr( $21, Regs ); {- available with this call. -}
-
- {---------------------------------------------------------------}
- {- reset the Free list if need be -}
- {---------------------------------------------------------------}
-
- If FreeSize > 0 Then Begin
- move( FreeCopy^, FreePtr^, FreeSize );
- FreeMem ( FreeCopy, FreeSize + 16 );
- End;
-
- {---------------------------------------------------------------}
- {- set the return code -}
- {---------------------------------------------------------------}
-
- DosExec := ReturnCode;
- End;
- End;
- {$ENDIF}
-
- Begin
- End.
-