script.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. This unit handles the writing of script files
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit Script;
  19. interface
  20. uses
  21. CObjects;
  22. type
  23. PScript=^TScript;
  24. TScript=object
  25. fn : string[80];
  26. data : TStringQueue;
  27. constructor Init(const s:string);
  28. destructor Done;
  29. procedure AddStart(const s:string);
  30. procedure Add(const s:string);
  31. Function Empty:boolean;
  32. procedure WriteToDisk;virtual;
  33. end;
  34. TAsmScript = Object (TScript)
  35. Constructor Init (Const ScriptName : String);
  36. Procedure AddAsmCommand (Const Command, Options,FileName : String);
  37. Procedure AddLinkCommand (Const Command, Options, FileName : String);
  38. Procedure AddDeleteCommand (Const FileName : String);
  39. Procedure WriteToDisk;virtual;
  40. end;
  41. PAsmScript = ^TAsmScript;
  42. { Asm response file }
  43. var
  44. AsmRes : TAsmScript;
  45. implementation
  46. uses
  47. {$ifdef linux}
  48. linux,
  49. {$endif}
  50. globals,systems;
  51. {****************************************************************************
  52. TScript
  53. ****************************************************************************}
  54. constructor TScript.Init(const s:string);
  55. begin
  56. fn:=FixFileName(s)+source_os.scriptext;
  57. data.Init;
  58. end;
  59. destructor TScript.Done;
  60. begin
  61. data.done;
  62. end;
  63. procedure TScript.AddStart(const s:string);
  64. begin
  65. data.Insert(s);
  66. end;
  67. procedure TScript.Add(const s:string);
  68. begin
  69. data.Concat(s);
  70. end;
  71. Function TScript.Empty:boolean;
  72. begin
  73. Empty:=Data.Empty;
  74. end;
  75. procedure TScript.WriteToDisk;
  76. var
  77. t : Text;
  78. begin
  79. Assign(t,fn);
  80. Rewrite(t);
  81. while not data.Empty do
  82. Writeln(t,data.Get);
  83. Close(t);
  84. {$ifdef linux}
  85. ChMod(fn,493);
  86. {$endif}
  87. end;
  88. {****************************************************************************
  89. Asm Response
  90. ****************************************************************************}
  91. Constructor TAsmScript.Init (Const ScriptName : String);
  92. begin
  93. Inherited Init(ScriptName);
  94. end;
  95. Procedure TAsmScript.AddAsmCommand (Const Command, Options,FileName : String);
  96. begin
  97. {$ifdef linux}
  98. if FileName<>'' then
  99. Add('echo Assembling '+FileName);
  100. Add (Command+' '+Options);
  101. Add('if [ $? != 0 ]; then DoExitAsm '+FileName+'; fi');
  102. {$else}
  103. if FileName<>'' then
  104. begin
  105. Add('SET THEFILE='+FileName);
  106. Add('echo Assembling %THEFILE%');
  107. end;
  108. Add(command+' '+Options);
  109. Add('if errorlevel 1 goto asmend');
  110. {$endif}
  111. end;
  112. Procedure TasmScript.AddLinkCommand (Const Command, Options, FileName : String);
  113. begin
  114. {$ifdef linux}
  115. if FileName<>'' then
  116. Add('echo Linking '+FileName);
  117. Add (Command+' '+Options);
  118. Add('if [ $? != 0 ]; then DoExitLink '+FileName+'; fi');
  119. {$else}
  120. if FileName<>'' then
  121. begin
  122. Add('SET THEFILE='+FileName);
  123. Add('echo Linking %THEFILE%');
  124. end;
  125. Add (Command+' '+Options);
  126. Add('if errorlevel 1 goto linkend');
  127. {$endif}
  128. end;
  129. Procedure TAsmScript.AddDeleteCommand (Const FileName : String);
  130. begin
  131. {$ifdef linux}
  132. Add('rm '+FileName);
  133. {$else}
  134. Add('Del '+FileName);
  135. {$endif}
  136. end;
  137. Procedure TAsmScript.WriteToDisk;
  138. Begin
  139. {$ifdef linux}
  140. AddStart('{ echo "An error occurred while linking $1"; exit 1; }');
  141. AddStart('DoExitLink ()');
  142. AddStart('{ echo "An error occurred while assembling $1"; exit 1; }');
  143. AddStart('DoExitAsm ()');
  144. AddStart('#!/bin/bash');
  145. {$else}
  146. AddStart('@echo off');
  147. Add('goto end');
  148. Add(':asmend');
  149. Add('echo An error occured while assembling %THEFILE%');
  150. Add('goto end');
  151. Add(':linkend');
  152. Add('echo An error occured while linking %THEFILE%');
  153. Add(':end');
  154. {$endif}
  155. TScript.WriteToDisk;
  156. end;
  157. end.
  158. {
  159. $Log$
  160. Revision 1.2 1998-05-04 17:54:29 peter
  161. + smartlinking works (only case jumptable left todo)
  162. * redesign of systems.pas to support assemblers and linkers
  163. + Unitname is now also in the PPU-file, increased version to 14
  164. }