home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0414.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  4.9 KB  |  194 lines

  1. {$R-,S-,I-,D+,F-,V-,B-,N-,L+ }
  2. {$M 4096,0,0}
  3.  
  4. Program TC2TP;
  5. { This is the front-end program that will drive all of the    }
  6. { necessary processes to create a usable .OBJ file from a     }
  7. { Turbo C routine.  It will first spawn TCC to compile the C  }
  8. { module with the correct options set.  It will then spawn    }
  9. { the second part of this module, C2P.  C2P will massage the  }
  10. { .ASM file that was generated by the call to TCC to be       }
  11. { compatible with Turbo Pascal.                               }
  12.  
  13. Uses
  14.   DOS, Tools;            { Link in the necessary units        }
  15.  
  16. Type
  17.   Path             = String[71];
  18.  
  19. Const
  20. { These constants must be changed to reflect the location of  }
  21. { these programs on your system.  Failure to do this will     }
  22. { cause the program to not execute correctly.                 }
  23.   TCCPath          : Path = 'R:\Tcc.exe';
  24.   IncPath          : Path = 'R:\include';
  25.   AsmPath          : Path = 'M:\tasm.exe';
  26.   C2PPath          : Path = 'C2P.EXE';
  27.   DoAssembly       : Boolean = TRUE;
  28.   Optimize         : Boolean = TRUE;
  29.   LargeCode        : Boolean = FALSE;
  30.  
  31. Var
  32.   FileName         : Path;
  33.  
  34. Procedure ProcessCmdLine;
  35. { This procedure will process the command line for any        }
  36. { options that have been passed.  They will set the           }
  37. { appropriate info inside the program.                        }
  38.  
  39. Type
  40.   CommandLine      = String[127];
  41.  
  42. Var
  43.   I                : Word;
  44.   Opt              : Path;
  45.  
  46. Begin
  47.   For I := 1 to ParamCount Do
  48.   Begin
  49.     Opt := ParamStr(I);
  50.     Case Opt[1] Of
  51.       '/','-' : Case UpCase( Opt[2] ) of
  52.                   'N' : DoAssembly  := FALSE; {No Assembly}
  53.                   'L' : LargeCode   := TRUE;  {Large Code}
  54.                   'I' : IncPath     := RightStr(Opt,3);
  55.                                               {Include path}
  56.                   'S' : Optimize    := FALSE; {Slow}
  57.                 End;
  58.       Else
  59.         FileName := Opt;
  60.     End;
  61.   End;
  62. End;
  63.  
  64. Procedure MyExec(Prog,Cmd : String);
  65. { This program will execute the required utility program that }
  66. { is used by this program.                                    }
  67.  
  68. Begin
  69.   SwapVectors;
  70.   Exec(Prog,Cmd);
  71.   SwapVectors;
  72. End;
  73.  
  74.  
  75. Function SpawnTCC(FName : Path) : Boolean;
  76. { THis routine will spawn the Turbo C command line compiler   }
  77. { assuring that the correct options have been passed to it.   }
  78.  
  79. Var
  80.   CommandLine      : String;
  81.   Model            : String[4];
  82.   Opto             : String[9];
  83.  
  84. Begin
  85.   If LargeCode Then
  86.     Model := '-ml '
  87.   Else
  88.     Model := '-mc ';
  89.   If Optimize Then
  90.     Opto := '-Z -G -O '
  91.   Else
  92.     Opto := '';
  93.  
  94.   CommandLine  := Model + Opto + '-S -c -p -u- -k -I'+
  95.                   IncPath + ' ' + FName;
  96.   MyExec( TCCPath,CommandLine );
  97.   If DOSError <> 0 Then
  98.   Begin
  99.     Writeln( 'Error spawning ',TCCPath );
  100.     Writeln( 'DosError = ',DosError );
  101.     SpawnTCC := FALSE;
  102.     Exit;
  103.   End;
  104.   If DosExitCode = 0 Then
  105.   Begin
  106.     Writeln( 'C code compiled successfully!' );
  107.     SpawnTCC := TRUE;
  108.   End
  109.   Else
  110.     SpawnTCC := FALSE;
  111. End;
  112.  
  113. Function SpawnC2P( FName : Path ) : Boolean;
  114. { This routine will spawn the second utility program in our   }
  115. { conversion routines.                                        }
  116. Var
  117.   ExitCode         : Integer;
  118.   Msg              : Str80;
  119.  
  120. Begin
  121.   MyExec( C2PPath,FName );
  122.   If DosError <> 0 Then
  123.   Begin
  124.     Writeln('Error spawning ',C2PPath);
  125.     Writeln('DOSError = ',DOSError);
  126.   End;
  127.   ExitCode := DOSExitCode;
  128.   If ExitCode <> 0 Then
  129.   Begin
  130.     Case ExitCode of
  131.       99 : Msg := 'File Not Specified';
  132.       Else
  133.         Msg := 'C2P error';
  134.     End;
  135.     Writeln(Msg);
  136.   End;
  137.   SpawnC2P := ( DOSError = 0 ) and ( ExitCode = 0 );
  138. End;
  139.  
  140. Function SpawnAsm(FName : Path) : Boolean;
  141. { This program will spawn the Assembler installed by the ASM  }
  142. { path in the constant.  You must make sure to point the path }
  143. { so it can locate the assembler.                             }
  144.  
  145. Begin
  146.   MyExec( AsmPath,FName + ';' );
  147.   If DOSError <> 0 Then
  148.   Begin
  149.     Writeln( 'DosError = ',DosError );
  150.     Writeln( 'Error spawning ',ASMPath );
  151.     SpawnASM := FALSE;
  152.     Exit;
  153.   End;
  154.   If DosExitCode = 0 Then
  155.   Begin
  156.     Writeln( 'ASP file successfully assembled!' );
  157.     SpawnAsm := TRUE;
  158.   End
  159.   Else
  160.     SpawnAsm := FALSE;
  161. End;
  162.  
  163. Procedure Advance2Lines;
  164. { Simple procedure to advance the screen two lines.           }
  165.  
  166. Begin
  167.   Writeln;
  168.   Writeln;
  169. End;
  170.  
  171. Var
  172.   Success          : Boolean;       { Local variable to Main }
  173.  
  174. Begin
  175.   Advance2Lines;
  176.   If( ParamCount < 1 ) Then
  177.   Begin
  178.     Writeln( 'TC2TP FileName' );
  179.     Halt(99);
  180.   End;
  181.   ProcessCmdLine;
  182.   Success := SpawnTCC( FileName );
  183.   If Success Then
  184.   Begin
  185.     Advance2Lines;
  186.     Success := SpawnC2P( FileName );
  187.     If( Success and DoAssembly ) Then
  188.     Begin
  189.       Advance2Lines;
  190.       Success := SpawnAsm( FileExt( FileName,'ASP' ) );
  191.     End;
  192.   End;
  193. End.
  194.