gendef.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Generation of a .def file for needed for Os2/Win32
  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 gendef;
  19. interface
  20. uses cobjects;
  21. type
  22. pdeffile=^tdeffile;
  23. tdeffile=object
  24. fname : string;
  25. constructor init(const fn:string);
  26. destructor done;
  27. procedure addexport(const s:string);
  28. procedure addimport(const s:string);
  29. procedure writefile;
  30. function empty : boolean;
  31. private
  32. is_empty : boolean;
  33. WrittenOnDisk : boolean;
  34. exportlist,
  35. importlist : tstringcontainer;
  36. end;
  37. var
  38. deffile : tdeffile;
  39. implementation
  40. uses
  41. systems,globtype,globals;
  42. {******************************************************************************
  43. TDefFile
  44. ******************************************************************************}
  45. constructor tdeffile.init(const fn:string);
  46. begin
  47. fname:=fn;
  48. WrittenOnDisk:=false;
  49. is_empty:=true;
  50. importlist.init;
  51. exportlist.init;
  52. end;
  53. destructor tdeffile.done;
  54. var
  55. f : file;
  56. i : word;
  57. begin
  58. if WrittenOnDisk and
  59. not(cs_link_extern in aktglobalswitches) then
  60. begin
  61. assign(f,fname);
  62. {$I-}
  63. erase(f);
  64. {$I+}
  65. i:=ioresult;
  66. end;
  67. importlist.done;
  68. exportlist.done;
  69. end;
  70. procedure tdeffile.addexport(const s:string);
  71. begin
  72. exportlist.insert(s);
  73. is_empty:=false;
  74. end;
  75. procedure tdeffile.addimport(const s:string);
  76. begin
  77. importlist.insert(s);
  78. is_empty:=false;
  79. end;
  80. function tdeffile.empty : boolean;
  81. begin
  82. empty:=is_empty and (description='');
  83. end;
  84. procedure tdeffile.writefile;
  85. var
  86. t : text;
  87. begin
  88. If WrittenOnDisk then
  89. Exit;
  90. { open file }
  91. assign(t,fname);
  92. {$I+}
  93. rewrite(t);
  94. {$I-}
  95. if ioresult<>0 then
  96. exit;
  97. {$ifdef i386}
  98. case target_info.target of
  99. target_i386_Os2 :
  100. begin
  101. write(t,'NAME '+inputfile);
  102. if usewindowapi then
  103. write(t,' WINDOWAPI');
  104. writeln(t,'');
  105. writeln(t,'PROTMODE');
  106. writeln(t,'DESCRIPTION '+''''+description+'''');
  107. writeln(t,'DATA'#9'MULTIPLE');
  108. writeln(t,'STACKSIZE'#9+tostr(stacksize));
  109. writeln(t,'HEAPSIZE'#9+tostr(heapsize));
  110. end;
  111. target_i386_win32 :
  112. begin
  113. if description<>'' then
  114. writeln(t,'DESCRIPTION '+''''+description+'''');
  115. if dllversion<>'' then
  116. writeln(t,'VERSION '+dllversion);
  117. end;
  118. end;
  119. {$endif}
  120. {write imports}
  121. if not importlist.empty then
  122. begin
  123. writeln(t,'');
  124. writeln(t,'IMPORTS');
  125. while not importlist.empty do
  126. writeln(t,#9+importlist.get);
  127. end;
  128. {write exports}
  129. if not exportlist.empty then
  130. begin
  131. writeln(t,'');
  132. writeln(t,'EXPORTS');
  133. while not exportlist.empty do
  134. writeln(t,#9+exportlist.get);
  135. end;
  136. close(t);
  137. WrittenOnDisk:=true;
  138. end;
  139. end.
  140. {
  141. $Log$
  142. Revision 1.5 2000-01-07 01:14:27 peter
  143. * updated copyright to 2000
  144. Revision 1.4 1999/12/20 23:23:28 pierre
  145. + $description $version
  146. Revision 1.3 1999/03/26 00:05:29 peter
  147. * released valintern
  148. + deffile is now removed when compiling is finished
  149. * ^( compiles now correct
  150. + static directive
  151. * shrd fixed
  152. Revision 1.2 1998/10/13 13:10:14 peter
  153. * new style for m68k/i386 infos and enums
  154. Revision 1.1 1998/06/04 23:51:39 peter
  155. * m68k compiles
  156. + .def file creation moved to gendef.pas so it could also be used
  157. for win32
  158. }