home *** CD-ROM | disk | FTP | other *** search
- {$R-,S-,I-,D+,F-,V-,B-,N-,L+ }
- {$M 4096,0,0}
-
- Program TC2TP;
- { This is the front-end program that will drive all of the }
- { necessary processes to create a usable .OBJ file from a }
- { Turbo C routine. It will first spawn TCC to compile the C }
- { module with the correct options set. It will then spawn }
- { the second part of this module, C2P. C2P will massage the }
- { .ASM file that was generated by the call to TCC to be }
- { compatible with Turbo Pascal. }
-
- Uses
- DOS, Tools; { Link in the necessary units }
-
- Type
- Path = String[71];
-
- Const
- { These constants must be changed to reflect the location of }
- { these programs on your system. Failure to do this will }
- { cause the program to not execute correctly. }
- TCCPath : Path = 'R:\Tcc.exe';
- IncPath : Path = 'R:\include';
- AsmPath : Path = 'M:\tasm.exe';
- C2PPath : Path = 'C2P.EXE';
- DoAssembly : Boolean = TRUE;
- Optimize : Boolean = TRUE;
- LargeCode : Boolean = FALSE;
-
- Var
- FileName : Path;
-
- Procedure ProcessCmdLine;
- { This procedure will process the command line for any }
- { options that have been passed. They will set the }
- { appropriate info inside the program. }
-
- Type
- CommandLine = String[127];
-
- Var
- I : Word;
- Opt : Path;
-
- Begin
- For I := 1 to ParamCount Do
- Begin
- Opt := ParamStr(I);
- Case Opt[1] Of
- '/','-' : Case UpCase( Opt[2] ) of
- 'N' : DoAssembly := FALSE; {No Assembly}
- 'L' : LargeCode := TRUE; {Large Code}
- 'I' : IncPath := RightStr(Opt,3);
- {Include path}
- 'S' : Optimize := FALSE; {Slow}
- End;
- Else
- FileName := Opt;
- End;
- End;
- End;
-
- Procedure MyExec(Prog,Cmd : String);
- { This program will execute the required utility program that }
- { is used by this program. }
-
- Begin
- SwapVectors;
- Exec(Prog,Cmd);
- SwapVectors;
- End;
-
-
- Function SpawnTCC(FName : Path) : Boolean;
- { THis routine will spawn the Turbo C command line compiler }
- { assuring that the correct options have been passed to it. }
-
- Var
- CommandLine : String;
- Model : String[4];
- Opto : String[9];
-
- Begin
- If LargeCode Then
- Model := '-ml '
- Else
- Model := '-mc ';
- If Optimize Then
- Opto := '-Z -G -O '
- Else
- Opto := '';
-
- CommandLine := Model + Opto + '-S -c -p -u- -k -I'+
- IncPath + ' ' + FName;
- MyExec( TCCPath,CommandLine );
- If DOSError <> 0 Then
- Begin
- Writeln( 'Error spawning ',TCCPath );
- Writeln( 'DosError = ',DosError );
- SpawnTCC := FALSE;
- Exit;
- End;
- If DosExitCode = 0 Then
- Begin
- Writeln( 'C code compiled successfully!' );
- SpawnTCC := TRUE;
- End
- Else
- SpawnTCC := FALSE;
- End;
-
- Function SpawnC2P( FName : Path ) : Boolean;
- { This routine will spawn the second utility program in our }
- { conversion routines. }
- Var
- ExitCode : Integer;
- Msg : Str80;
-
- Begin
- MyExec( C2PPath,FName );
- If DosError <> 0 Then
- Begin
- Writeln('Error spawning ',C2PPath);
- Writeln('DOSError = ',DOSError);
- End;
- ExitCode := DOSExitCode;
- If ExitCode <> 0 Then
- Begin
- Case ExitCode of
- 99 : Msg := 'File Not Specified';
- Else
- Msg := 'C2P error';
- End;
- Writeln(Msg);
- End;
- SpawnC2P := ( DOSError = 0 ) and ( ExitCode = 0 );
- End;
-
- Function SpawnAsm(FName : Path) : Boolean;
- { This program will spawn the Assembler installed by the ASM }
- { path in the constant. You must make sure to point the path }
- { so it can locate the assembler. }
-
- Begin
- MyExec( AsmPath,FName + ';' );
- If DOSError <> 0 Then
- Begin
- Writeln( 'DosError = ',DosError );
- Writeln( 'Error spawning ',ASMPath );
- SpawnASM := FALSE;
- Exit;
- End;
- If DosExitCode = 0 Then
- Begin
- Writeln( 'ASP file successfully assembled!' );
- SpawnAsm := TRUE;
- End
- Else
- SpawnAsm := FALSE;
- End;
-
- Procedure Advance2Lines;
- { Simple procedure to advance the screen two lines. }
-
- Begin
- Writeln;
- Writeln;
- End;
-
- Var
- Success : Boolean; { Local variable to Main }
-
- Begin
- Advance2Lines;
- If( ParamCount < 1 ) Then
- Begin
- Writeln( 'TC2TP FileName' );
- Halt(99);
- End;
- ProcessCmdLine;
- Success := SpawnTCC( FileName );
- If Success Then
- Begin
- Advance2Lines;
- Success := SpawnC2P( FileName );
- If( Success and DoAssembly ) Then
- Begin
- Advance2Lines;
- Success := SpawnAsm( FileExt( FileName,'ASP' ) );
- End;
- End;
- End.