gendef.pas 3.6 KB

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