script.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_info.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. Add('echo Assembling '+FileName);
  99. Add (Command+' '+Options);
  100. Add('if [ $? != 0 ]; then DoExitAsm '+FileName+'; fi');
  101. {$else}
  102. Add('SET THEFILE='+FileName);
  103. Add('echo Assembling %THEFILE%');
  104. Add(command+' '+Options);
  105. Add('if errorlevel 1 goto asmend');
  106. {$endif}
  107. end;
  108. Procedure TasmScript.AddLinkCommand (Const Command, Options, FileName : String);
  109. begin
  110. {$ifdef linux}
  111. Add('echo Linking '+FileName);
  112. Add (Command+' '+Options);
  113. Add('if [ $? != 0 ]; then DoExitLink '+FileName+'; fi');
  114. {$else}
  115. Add('SET THEFILE='+FileName);
  116. Add('echo Linking %THEFILE%');
  117. Add (Command+' '+Options);
  118. Add('if errorlevel 1 goto linkend');
  119. {$endif}
  120. end;
  121. Procedure TAsmScript.AddDeleteCommand (Const FileName : String);
  122. begin
  123. {$ifdef linux}
  124. Add('rm '+FileName);
  125. {$else}
  126. Add('Del '+FileName);
  127. {$endif}
  128. end;
  129. Procedure TAsmScript.WriteToDisk;
  130. Begin
  131. {$ifdef linux}
  132. AddStart('{ echo "An error occurred while linking $1"; exit 1; }');
  133. AddStart('DoExitLink ()');
  134. AddStart('{ echo "An error occurred while assembling $1"; exit 1; }');
  135. AddStart('DoExitAsm ()');
  136. AddStart('#!/bin/bash');
  137. {$else}
  138. AddStart('@echo off');
  139. Add('goto end');
  140. Add(':asmend');
  141. Add('echo An error occured while assembling %THEFILE%');
  142. Add('goto end');
  143. Add(':linkend');
  144. Add('echo An error occured while linking %THEFILE%');
  145. Add(':end');
  146. {$endif}
  147. TScript.WriteToDisk;
  148. end;
  149. end.
  150. {
  151. $Log$
  152. Revision 1.1 1998-03-25 11:18:13 root
  153. Initial revision
  154. Revision 1.6 1998/03/10 01:17:28 peter
  155. * all files have the same header
  156. * messages are fully implemented, EXTDEBUG uses Comment()
  157. + AG... files for the Assembler generation
  158. Revision 1.5 1998/02/23 12:53:46 pierre
  159. + added some info when running ppas.bat
  160. * updated makefile
  161. Revision 1.4 1998/02/19 00:11:08 peter
  162. * fixed -g to work again
  163. * fixed some typos with the scriptobject
  164. Revision 1.3 1998/02/18 14:18:30 michael
  165. + added log at end of file (retroactively)
  166. revision 1.2
  167. date: 1998/02/18 13:43:15; author: michael; state: Exp; lines: +75 -20
  168. + Implemented an OS independent AsmRes object.
  169. ----------------------------
  170. revision 1.1
  171. date: 1998/02/17 21:44:04; author: peter; state: Exp;
  172. + Initial implementation
  173. }