gendef.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. begin
  57. if WrittenOnDisk and
  58. not(cs_link_extern in aktglobalswitches) then
  59. begin
  60. assign(f,fname);
  61. {$I-}
  62. erase(f);
  63. {$I+}
  64. if ioresult<>0 then;
  65. end;
  66. importlist.done;
  67. exportlist.done;
  68. end;
  69. procedure tdeffile.addexport(const s:string);
  70. begin
  71. exportlist.insert(s);
  72. is_empty:=false;
  73. end;
  74. procedure tdeffile.addimport(const s:string);
  75. begin
  76. importlist.insert(s);
  77. is_empty:=false;
  78. end;
  79. function tdeffile.empty : boolean;
  80. begin
  81. empty:=is_empty and (description='');
  82. end;
  83. procedure tdeffile.writefile;
  84. var
  85. t : text;
  86. begin
  87. If WrittenOnDisk then
  88. Exit;
  89. { open file }
  90. assign(t,fname);
  91. {$I+}
  92. rewrite(t);
  93. {$I-}
  94. if ioresult<>0 then
  95. exit;
  96. {$ifdef i386}
  97. case target_info.target of
  98. target_i386_Os2 :
  99. begin
  100. write(t,'NAME '+inputfile);
  101. if usewindowapi then
  102. write(t,' WINDOWAPI');
  103. writeln(t,'');
  104. writeln(t,'PROTMODE');
  105. writeln(t,'DESCRIPTION '+''''+description+'''');
  106. writeln(t,'DATA'#9'MULTIPLE');
  107. writeln(t,'STACKSIZE'#9+tostr(stacksize));
  108. writeln(t,'HEAPSIZE'#9+tostr(heapsize));
  109. end;
  110. target_i386_win32 :
  111. begin
  112. if description<>'' then
  113. writeln(t,'DESCRIPTION '+''''+description+'''');
  114. if dllversion<>'' then
  115. writeln(t,'VERSION '+dllversion);
  116. end;
  117. end;
  118. {$endif}
  119. {write imports}
  120. if not importlist.empty then
  121. begin
  122. writeln(t,'');
  123. writeln(t,'IMPORTS');
  124. while not importlist.empty do
  125. writeln(t,#9+importlist.get);
  126. end;
  127. {write exports}
  128. if not exportlist.empty then
  129. begin
  130. writeln(t,'');
  131. writeln(t,'EXPORTS');
  132. while not exportlist.empty do
  133. writeln(t,#9+exportlist.get);
  134. end;
  135. close(t);
  136. WrittenOnDisk:=true;
  137. end;
  138. end.
  139. {
  140. $Log$
  141. Revision 1.2 2000-07-13 11:32:41 michael
  142. + removed logs
  143. }