home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l041 / 2.ddi / MISC.ARC / TABUILD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-12-31  |  16.2 KB  |  571 lines

  1. (****************************************************************)
  2. (*                     DATABASE TOOLBOX 4.0                     *)
  3. (*     Copyright (c) 1984, 87 by Borland International, Inc.    *)
  4. (*                                                              *)
  5. (*                         TABuild                              *)
  6. (*                                                              *)
  7. (*  Purpose: Configures Turbo Access according to the data      *)
  8. (*           record and key definitions in the input file.      *)
  9. (*                                                              *)
  10. (* The built-in editor that TABUILD uses was implemented with   *)
  11. (* a unit called BINED.TPU, which is not included with the      *)
  12. (* Database Toolbox.  The Turbo Pascal Editor Toolbox 4.0       *)
  13. (* contains BINED.TPU along with full documentation about its   *)
  14. (* capabilities.  If you have purchased the Editor Toolbox 4.0, *)
  15. (* you can recompile TABUILD and link in BINED.TPU with the     *)
  16. (* following steps in the integrated environment:               *)
  17. (*                                                              *)
  18. (* 1)  Load TABuild.pas (this file) into the Turbo Pascal       *)
  19. (*     editor.                                                  *)
  20. (*                                                              *)
  21. (* 2)  Pull down the Options menu and select Compiler.          *)
  22. (*                                                              *)
  23. (* 3)  Select Conditional Defines and type in BINED, then       *)
  24. (*     press return.  This conditional directive will tell      *)
  25. (*     the compiler to link in BINED.TPU according to the       *)
  26. (*     directives given below.                                  *)
  27. (*                                                              *)
  28. (* 4)  Copy BINED.TPU into your current directory or disk;      *)
  29. (*     you can also set a Unit Directory path to BINED.TPU      *)
  30. (*     in the Options menu.                                     *)
  31. (*                                                              *)
  32. (* 5)  Press F9 to make the TABuild program.                    *)
  33. (*                                                              *)
  34. (* With the command-line compiler (TPC.EXE), you may issue the  *)
  35. (* following command at the dos prompt to make the necessary    *)
  36. (* units and define the conditional symbol BINED:               *)
  37. (*                                                              *)
  38. (*   TPC TABUILD /M /DBINED                                     *)
  39. (*                                                              *)
  40. (* /DBINED defines the symbol BINED which is used to compile    *)
  41. (*         the code for TABUILD's built-in editor.              *)
  42. (*                                                              *)
  43. (****************************************************************)
  44. program TABuild;
  45. {$M 6000, 4000, $16000}
  46. uses CRT,
  47.      DOS,
  48.      MiscTool,
  49. {    If a compiler error occurs here, you need to unpack the source
  50.      to the MiscTool unit from the archived file Tools.arc.  See the
  51.      README file on disk 1 for detailed instructions. }
  52.  
  53.      EditLn,
  54.      FileUtil,
  55.      SetConst
  56.  
  57.      {$IFDEF BINED} ,
  58.       BinEd,
  59. {     If a compiler error occurs here, you need the unit BINED.TPU
  60.       from the Turbo Pascal Editor Toolbox 4.0.  See the documentation
  61.       at the top of this file for detailed instructions. }
  62.  
  63.       TAEdit
  64.      {$ENDIF};
  65.  
  66. {$V-}
  67. {$I Paths.inc}
  68. const
  69.   Version = '4.00';
  70.   CopyrightMsg = 'Copyright (C)';
  71.   Year = '1987';
  72.   Company = 'Borland International';
  73.   EXE = '.EXE';
  74.   PAS = '.PAS';
  75.   TPU = '.TPU';
  76.   TypeExt = '.TYP';
  77.   SizeExt = '.SIZ';
  78.   DefExt = '.DEF';
  79.   ProgName = 'TABuild';
  80.   InstallProg = 'TAInst';
  81.   TPC = 'TPC';
  82.   Turbo = 'TURBO';
  83.   TAccess = 'TACCESS';
  84.   TAHigh = 'TAHIGH';
  85.   TAGenSizes = 'TASizes';
  86.  
  87.   DebugFlag = ' /dTADebug';
  88.  
  89.   SectionName = '"Configuring Turbo Pascal Access"';
  90.  
  91.   type
  92.     Line = string[80];
  93.     Options =  (UseWorkSheet, CompTAHigh, DebugInfo);
  94.     OptionRec = record
  95.                   OptStr : string[3];
  96.                   FlagSet : boolean;
  97.                   OptHelp : Line;
  98.                 end;
  99.     CompOptions = record
  100.                     OptStr : string[4];
  101.                     OptHelp,
  102.                     OptList : Line;
  103.                   end;
  104.   const
  105.     BuildOptions : array[Options] of OptionRec =
  106.                    ( (OptStr : '/W+'; FlagSet : false;
  107.                      OptHelp : 'Use the TABuild Constants WorkSheet to calculate Turbo Access constants'),
  108.                     (OptStr : '/H-'; FlagSet : true;
  109.                      OptHelp : 'Do not compile the Turbo Access High-Level Unit'),
  110.                     (OptStr : '/E-'; FlagSet : true;
  111.                      OptHelp : 'No Turbo Access error messages and procedure names')
  112.                    );
  113.    CompilerOptions : CompOptions =
  114.       (OptStr : '/$xx';
  115.        OptHelp : 'Compile Turbo Access with directive xx';
  116.        OptList : '');
  117.  
  118. var
  119.   UserFileSpec : FileSpec;
  120.   CurDir : PathName;
  121.  
  122. procedure ReportError(ErrorMsg,
  123.                       ErrorHelp : Line);
  124. begin
  125.   Beep;
  126.   Writeln;
  127.   Writeln('Error: ', ErrorMsg);
  128.   if ErrorHelp <> '' then
  129.     Writeln(ErrorHelp);
  130. end;
  131.  
  132. procedure ManualHelp(Subject : string);
  133. begin
  134.   Writeln('For more information on ', Subject, ', see the section ');
  135.   Writeln(SectionName, ' in your Database Toolbox manual.');
  136. end;
  137.  
  138. procedure SyntaxHelp;
  139. const
  140.   FlagColumn = 2;
  141.   MsgColumn = 6;
  142. var
  143.   CurOpt : Options;
  144. begin
  145.   Writeln;
  146.   Writeln(ProgName, ' configures Turbo Access with your data record and key type definitions.');
  147.   Writeln;
  148.   Writeln('Syntax: ', ProgName, ' [options] TypesFile');
  149.   Writeln('Options:');
  150.   for CurOpt := UseWorkSheet to DebugInfo do
  151.     with BuildOptions[CurOpt] do
  152.       Writeln('':FlagColumn, OptStr, '':MsgColumn - Length(OptStr), OptHelp);
  153.   with CompilerOptions do
  154.     Writeln('':FlagColumn, OptStr, '':MsgColumn - Length(OptStr), OptHelp);
  155.   Writeln;
  156.   ManualHelp(ProgName);
  157. end;
  158.  
  159.  
  160. procedure CheckParam(CurParamStr : String;
  161.                      var TypesFile : FileName);
  162. var
  163.   CurOpt : Options;
  164. begin
  165.   if CurParamStr[1] <> '/' then
  166.     TypesFile := CurParamStr
  167.   else
  168.   begin
  169.     CurOpt := UseWorkSheet;
  170.     repeat
  171.       if CurParamStr = BuildOptions[CurOpt].OptStr then
  172.       begin
  173.         BuildOptions[CurOpt].flagSet := not BuildOptions[CurOpt].flagSet;
  174.         Exit;
  175.       end;
  176.       CurOpt := succ(CurOpt);
  177.     until (CurOpt > DebugInfo);
  178.     if Pos('$', CurParamStr) > 0 then
  179.        CompilerOptions.OptList := CompilerOptions.OptList + ' ' + CurParamStr;
  180.   end;
  181. end;
  182.  
  183. function GetParams(var TypesFile : FileName) : boolean;
  184. var
  185.   CurParamNum : integer;
  186.   CurParamStr : string;
  187. begin
  188.   TypesFile := '';
  189.   for CurParamNum := 1 to ParamCount do
  190.   begin
  191.     CurParamStr := UpCaseStr(ParamStr(CurParamNum));
  192.     CheckParam(CurParamStr, TypesFile);
  193.   end;
  194.   GetParams := TypesFile <> '';
  195. end;
  196.  
  197. function FoundUserFile(var TypesFile : FileName) : boolean;
  198. var
  199.   Found : boolean;
  200. begin
  201.   GetFileSpec(UserFileSpec, TypesFile);
  202.   with UserFileSpec do
  203.   begin
  204.     Found := Exist(Path + Name + Ext);
  205.     if not Found then
  206.     if Ext = '' then
  207.     begin
  208.       Ext := TypeExt;
  209.       Found := Exist(Path + Name + Ext);
  210.     end;
  211.     if not found then
  212.     begin
  213.       {$IFDEF BINED}
  214.        Found := CreateTypeFile(UserFileSpec);
  215.        if Found then
  216.        begin
  217.          ClrScr;
  218.          Found := EditTypeFile(UserFileSpec);
  219.        end;
  220.        {$ELSE}
  221.        ReportError('Could not find type definition file ', Path + Name + Ext);
  222.        {$ENDIF}
  223.     end;
  224.   end;
  225.   FoundUserFile := found;
  226. end; { FoundUserFile }
  227.  
  228. function FoundCompiler : boolean;
  229. var
  230.   found : boolean;
  231.   CurFile : FileName;
  232. begin
  233.   if TurboPath = '' then
  234.     TurboPath := CurDir + '\';
  235.   CurFile := TurboPath + TPC + EXE;
  236.   found := Exist(CurFile);
  237.   {$IFNDEF BINED}
  238.   CurFile := TurboPath + TURBO + EXE;
  239.   found := Exist(CurFile);
  240.   {$ENDIF}
  241.   if not found then
  242.   begin
  243.     ReportError('Could not find the compiler ' + CurFile,
  244.                 'Run '+InstallProg+' and install the Turbo Pascal Directory');
  245.     Writeln;
  246.     ManualHelp(InstallProg);
  247.   end;
  248.   FoundCompiler := found;
  249. end; { FoundCompiler }
  250.  
  251. function FoundAccessFiles : boolean;
  252. var
  253.   found : boolean;
  254.   CurFile : FileName;
  255. begin
  256.   if TAccessPath = '' then
  257.     TAccessPath := CurDir + '\';
  258.   CurFile := TAccessPath + TAccess + PAS;
  259.   found := Exist(CurFile);;
  260.   if found then
  261.   begin
  262.     CurFile := TAccessPath + TAGenSizes + PAS;
  263.     found := Exist(CurFile);
  264.   end;
  265.   if not found then
  266.   begin
  267.     ReportError('Could not find the Turbo Access file ' + CurFile,
  268.                 'Run '+InstallProg+' and install the Turbo Access Directory');
  269.     Writeln;
  270.     ManualHelp(InstallProg);
  271.   end;
  272.   FoundAccessFiles := found;
  273. end; { FoundAccessFiles }
  274.  
  275. function FoundFiles(var TypesFile : FileName) : boolean;
  276. var
  277.   Found : boolean;
  278. begin
  279.   Found := FoundCompiler;
  280.   if Found then
  281.     Found := FoundAccessFiles;
  282.   if Found then
  283.     Found := FoundUserFile(TypesFile);
  284.   FoundFiles := Found;
  285. end; { FoundFiles }
  286.  
  287. function GoodStartUp(var TypesFile : FileName) : boolean;
  288. var
  289.   StartOk : boolean;
  290. begin
  291.   GetDir(0, CurDir);
  292.   Writeln(ProgName, ' version ', Version);
  293.   Writeln(CopyrightMsg, ' ', Year, ' ', Company);
  294.   StartOk := GetParams(TypesFile);
  295.   if not StartOk then
  296.     SyntaxHelp
  297.   else
  298.     StartOk := FoundFiles(TypesFile);
  299.   GoodStartUp := StartOk;
  300. end;
  301.  
  302. function AnswerYes : boolean;
  303. var
  304.   ch : char;
  305. begin
  306.   repeat
  307.     ch := UpCase(ReadKey);
  308.   until ch in ['Y', 'N'];
  309.   Writeln(ch);
  310.   AnswerYes := ch = 'Y';
  311. end; { AnswerYes }
  312.  
  313. var
  314.   CommandLine : string;
  315.  
  316.  
  317. var
  318.   CRTcbreakV : Pointer;
  319.  
  320. const
  321.   CBreak = $1B;
  322.  
  323. function GetCBreakV : pointer;
  324. var
  325.   r : registers;
  326.   p : LongInt;
  327. begin
  328.   FillChar(r, SizeOf(r), 0);
  329.   r.AH := $35;
  330.   r.AL := CBreak;
  331.   MSDOS(r);
  332.   with r do
  333.     GetCBreakV := ptr(ES, BX);
  334. end;
  335.  
  336. procedure SetCBreakV(p : pointer);
  337. var
  338.   r : registers;
  339. begin
  340.   FillChar(r, SizeOf(r), 0);
  341.   r.AH := $25;
  342.   r.AL := CBreak;
  343.   r.ES := Seg(p^);
  344.   r.bx := Ofs(p^);
  345.   MSDos(r);
  346. end;
  347.  
  348. procedure Invoke(ProgramName, CommandLine : String);
  349. begin
  350.   SetCbreakV(SaveInt1b);
  351.   Exec(ProgramName, CommandLine);
  352.   SetCbreakV(CRTcbreakV);
  353. end; { Invoke }
  354.  
  355. procedure CompileUserTypes(var ConfigError : boolean);
  356. var
  357.   CompErrors : text;
  358.   OutFileSpec : FileSpec;
  359. begin
  360.   repeat
  361.     with UserFileSpec do
  362.     begin
  363.       CopyFile(Path + Name + Ext, TAccessPath + TAccess + TypeExt);
  364.       Writeln;
  365.       Writeln('Calculating data record and key sizes by compiling/running ', TAGenSizes);
  366.       {$IFDEF BINED}
  367.       with OutFileSpec do
  368.       begin
  369.         Path := TAccessPath;
  370.         Name := 'TPC';
  371.         Ext := '.Out';
  372.         Redir(CompErrors, Path + Name + Ext);
  373.       end;
  374.       {$ENDIF}
  375.       CommandLine := ' /I' + TAccessPath;
  376.       Invoke(TurboPath + TPC + EXE,
  377.              TAccessPath + TAGenSizes + PAS + CommandLine);
  378.       ConfigError := (DosExitCode <> 0) or (DosError <> 0);
  379.       {$IFDEF BINED}
  380.       UnRedir;
  381.       Close(CompErrors);
  382.       {$ENDIF}
  383.       if ConfigError then
  384.       begin
  385.         Writeln;
  386.         Write('Error compiling ', TAGenSizes + PAS, ', Would you like to edit ', Name + Ext, '? ');
  387.        if AnswerYes then
  388.        begin
  389.          {$IFDEF BINED}
  390.          if not FixError(CompErrors, TAGenSizes + PAS,
  391.                          OutFileSpec, UserFileSpec) then
  392.            Exit;
  393.          {$ELSE}
  394.          Invoke(TurboPath + Turbo + EXE, Path + Name + Ext);
  395.          if (DosExitCode <> 0) or (DosError <> 0) then
  396.            Abort('Error invoking ' + TurboPath + Turbo + EXE);
  397.          {$ENDIF}
  398.        end
  399.        else
  400.          Exit;
  401.       end;
  402.     end;
  403.   until (not ConfigError);
  404.   Remove(TAccessPath + TAccess + TypeExt);
  405.   {$IFDEF BINED}
  406.   Erase(CompErrors);
  407.   {$ENDIF}
  408. end; { CompileUserTypes }
  409.  
  410. procedure StripBlanks(var CurLine : String);
  411. var
  412.   i : integer;
  413. begin
  414.   i := 1;
  415.   while (i <= Length(CurLine)) do
  416.   begin
  417.     if CurLine[i] = ' ' then
  418.       Delete(CurLine, i, 1)
  419.     else
  420.       Inc(i, 1);
  421.   end;
  422. end; { StripBlanks }
  423.  
  424. procedure GetSizes(var Sizes : text;
  425.                    var MaxDataSize,
  426.                        MaxKeyLen : integer);
  427.  
  428. function StripNum(CurLine : String) : integer;
  429. var
  430.   Code : integer;
  431.   ReturnNum : integer;
  432.   NumStr : string;
  433. begin
  434.   StripBlanks(CurLine);
  435.   Code := Pos('=', CurLine);
  436.   if Code > 0 then
  437.   begin
  438.     NumStr := Copy(CurLine, Code + 1, Length(CurLine) - Code);
  439.     Val(NumStr, ReturnNum, Code);
  440.   end
  441.   else
  442.     ReturnNum := Code;
  443.   StripNum := ReturnNum;
  444. end; { StripNum }
  445.  
  446. var
  447.   CurLine : String;
  448.  
  449. begin
  450.   Close(Sizes);
  451.   Reset(Sizes);
  452.   Readln(Sizes, CurLine);
  453.   MaxDataSize := StripNum(CurLine);
  454.   Readln(Sizes, CurLine);
  455.   MaxKeyLen := StripNum(CurLine);
  456.   Close(Sizes);
  457.   Erase(Sizes);
  458. end; { GetSizes }
  459.  
  460. procedure GenSizes(var MaxDataSize,
  461.                    MaxKeyLen : integer;
  462.                    var ConfigError : boolean);
  463. var
  464.   Sizes : Text;
  465. begin
  466.   with UserFileSpec do
  467.   begin
  468.     Redir(Sizes, TAccessPath + Name + SizeExt);
  469.     Invoke(TAccessPath + TAGenSizes + EXE, '');
  470.     ConfigError := (DOSExitCode <> 0) or (DosError <> 0);
  471.     UnRedir;
  472.     if (DOSError = 1) then
  473.       Abort('TABuild terminated by user');
  474.     if not ConfigError then
  475.       GetSizes(Sizes, MaxDataSize, MaxKeyLen);
  476.   end;
  477. end;
  478.  
  479. procedure ConfigTAccess(var ConfigError : boolean);
  480. begin
  481.   CompileUserTypes(ConfigError);
  482.   if not ConfigError then
  483.   begin
  484.     GenSizes(DefaultMaxRecSize, DefaultMaxKeyLen, ConfigError);
  485.     if not ConfigError then
  486.     begin
  487.       with UserFileSpec do
  488.         TypeFileNm := Name + Ext;
  489.       DefFileNm := TAccessPath + TAccess + DefExt;
  490.       UseDefaults := not(BuildOptions[UseWorkSheet].flagSet);
  491.       TAConstants;
  492.     end;
  493.     Writeln('Successfully generated Turbo Access constants');
  494.     Writeln;
  495.   end;
  496. end; { ConfigTAccess }
  497.  
  498. procedure CompileTAccess(var ConfigError : boolean);
  499. var
  500.   CommandLine : String;
  501. begin
  502.   Writeln('Compiling the Turbo Access Unit');
  503.   CommandLine := ' /U' + TAccessPath;
  504.   CommandLine := CommandLine + ' /I' + TAccessPath;
  505.   CommandLine := CommandLine + CompilerOptions.OptList;
  506.   if BuildOptions[DebugInfo].FlagSet then
  507.     CommandLine := CommandLine + ' ' + DebugFlag;
  508.   Invoke(TurboPath + TPC + EXE, TAccessPath + TAccess + PAS + ' ' + CommandLine);
  509.   ConfigError := (DOSExitCode <> 0) or (DosError <> 0);
  510. end; { CompileTAccess }
  511.  
  512. procedure CompileTAHigh(var ConfigError : boolean);
  513. var
  514.   CommandLine : string;
  515. begin
  516.   ConfigError := false;
  517.   if BuildOptions[CompTAHigh].FlagSet then
  518.     if Exist(TAccessPath + TAHigh + pas) then
  519.     begin
  520.       Writeln;
  521.       Writeln('Compiling the Turbo Access High-Level calls');
  522.       CommandLine := ' /U' + TAccessPath;
  523.       CommandLine := CommandLine + ' /I' + TAccessPath;
  524.       if BuildOptions[DebugInfo].FlagSet then
  525.         CommandLine := CommandLine + ' ' + DebugFlag;
  526.       Invoke(TurboPath + TPC + EXE, TAccessPath + TAHigh  + PAS + CommandLine);
  527.       ConfigError := (DOSExitCode <> 0) and (DOSError <> 0);
  528.       if not ConfigError and
  529.         (TAccessPath <> UserFileSpec.Path) then
  530.         MoveFile(TaccessPath + TAHigh + TPU, UserFileSpec.Path + TAHigh + TPU);
  531.     end;
  532. end; { CompileTAHigh }
  533.  
  534. procedure SignOff(ConfigError : boolean);
  535. begin
  536.   if not ConfigError then
  537.   begin
  538.     if (TAccessPath <> UserFileSpec.Path) then
  539.     begin
  540.       MoveFile(TaccessPath + TAccess + TPU, UserFileSpec.Path + TAccess + TPU);
  541.       with UserFileSpec do
  542.         MoveFile(TaccessPath + TAccess + DefExt, Path + Name + DefExt);
  543.     end;
  544.     Writeln;
  545.     Write('Successfully configured ', TAccess);
  546.     if BuildOptions[CompTAHigh].FlagSet then
  547.       Write(' and ', TAHigh);
  548.     Writeln(' for:');
  549.     with UserFileSpec do
  550.       Writeln('  ', Path, Name, Ext);
  551.   end;
  552. end; { SignOff }
  553.  
  554. var
  555.   TypesFile : FileName;
  556.   ConfigError : boolean;
  557.  
  558. begin
  559.   CRTcbreakV := GetCBreakV;
  560.   ConfigError := not GoodStartUp(TypesFile);
  561.   if not ConfigError then
  562.   begin
  563.     ConfigTAccess(ConfigError);
  564.     if not ConfigError then
  565.       CompileTAccess(ConfigError);
  566.     if not ConfigError then
  567.       CompileTAHigh(ConfigError);
  568.   end;
  569.   SignOff(ConfigError);
  570. end.
  571.