import.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. This unit implements an uniform import object
  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. unit import;
  18. interface
  19. uses
  20. cobjects;
  21. type
  22. pimported_item = ^timported_item;
  23. timported_item = object(tlinkedlist_item)
  24. ordnr : word;
  25. name,
  26. func : pstring;
  27. lab : pointer; { should be plabel, but this gaves problems with circular units }
  28. is_var : boolean;
  29. constructor init(const n,s : string;o : word);
  30. constructor init_var(const n,s : string);
  31. destructor done;virtual;
  32. end;
  33. pimportlist = ^timportlist;
  34. timportlist = object(tlinkedlist_item)
  35. dllname : pstring;
  36. imported_items : plinkedlist;
  37. constructor init(const n : string);
  38. destructor done;virtual;
  39. end;
  40. pimportlib=^timportlib;
  41. timportlib=object
  42. constructor Init;
  43. destructor Done;
  44. procedure preparelib(const s:string);virtual;
  45. procedure importprocedure(const func,module:string;index:longint;const name:string);virtual;
  46. procedure importvariable(const varname,module:string;const name:string);virtual;
  47. procedure generatelib;virtual;
  48. end;
  49. var
  50. importlib : pimportlib;
  51. procedure InitImport;
  52. procedure DoneImport;
  53. implementation
  54. uses
  55. systems,verbose,globals
  56. {$ifdef i386}
  57. ,os2_targ
  58. ,win_targ
  59. {$endif}
  60. ,lin_targ
  61. ;
  62. {****************************************************************************
  63. Timported_item
  64. ****************************************************************************}
  65. constructor timported_item.init(const n,s : string;o : word);
  66. begin
  67. inherited init;
  68. func:=stringdup(n);
  69. name:=stringdup(s);
  70. ordnr:=o;
  71. lab:=nil;
  72. is_var:=false;
  73. end;
  74. constructor timported_item.init_var(const n,s : string);
  75. begin
  76. inherited init;
  77. func:=stringdup(n);
  78. name:=stringdup(s);
  79. ordnr:=0;
  80. lab:=nil;
  81. is_var:=true;
  82. end;
  83. destructor timported_item.done;
  84. begin
  85. stringdispose(name);
  86. inherited done;
  87. end;
  88. {****************************************************************************
  89. TImportlist
  90. ****************************************************************************}
  91. constructor timportlist.init(const n : string);
  92. begin
  93. inherited init;
  94. dllname:=stringdup(n);
  95. imported_items:=new(plinkedlist,init);
  96. end;
  97. destructor timportlist.done;
  98. begin
  99. dispose(imported_items,done);
  100. stringdispose(dllname);
  101. end;
  102. {****************************************************************************
  103. TImportLib
  104. ****************************************************************************}
  105. constructor timportlib.Init;
  106. begin
  107. end;
  108. destructor timportlib.Done;
  109. begin
  110. end;
  111. procedure timportlib.preparelib(const s:string);
  112. begin
  113. Message(exec_e_dll_not_supported);
  114. end;
  115. procedure timportlib.importprocedure(const func,module:string;index:longint;const name:string);
  116. begin
  117. Message(exec_e_dll_not_supported);
  118. end;
  119. procedure timportlib.importvariable(const varname,module:string;const name:string);
  120. begin
  121. Message(exec_e_dll_not_supported);
  122. end;
  123. procedure timportlib.generatelib;
  124. begin
  125. Message(exec_e_dll_not_supported);
  126. end;
  127. procedure DoneImport;
  128. begin
  129. if assigned(importlib) then
  130. dispose(importlib,done);
  131. end;
  132. procedure InitImport;
  133. begin
  134. case target_info.target of
  135. {$ifdef i386}
  136. target_i386_Linux :
  137. importlib:=new(pimportliblinux,Init);
  138. target_i386_Win32 :
  139. importlib:=new(pimportlibwin32,Init);
  140. target_i386_OS2 :
  141. importlib:=new(pimportlibos2,Init);
  142. {$endif i386}
  143. {$ifdef m68k}
  144. target_m68k_Linux :
  145. importlib:=new(pimportliblinux,Init);
  146. {$endif m68k}
  147. else
  148. importlib:=new(pimportlib,Init);
  149. end;
  150. end;
  151. end.
  152. {
  153. $Log$
  154. Revision 1.9 1998-11-28 16:20:50 peter
  155. + support for dll variables
  156. Revision 1.8 1998/10/19 18:07:12 peter
  157. + external dll_name name func support for linux
  158. Revision 1.7 1998/10/19 15:41:02 peter
  159. * better splitname to support glib-1.1.dll alike names
  160. Revision 1.6 1998/10/13 13:10:17 peter
  161. * new style for m68k/i386 infos and enums
  162. Revision 1.5 1998/10/06 17:16:51 pierre
  163. * some memory leaks fixed (thanks to Peter for heaptrc !)
  164. Revision 1.4 1998/09/30 12:16:47 peter
  165. * remove extension if one is specified
  166. Revision 1.3 1998/06/04 23:51:43 peter
  167. * m68k compiles
  168. + .def file creation moved to gendef.pas so it could also be used
  169. for win32
  170. Revision 1.2 1998/04/27 23:10:28 peter
  171. + new scanner
  172. * $makelib -> if smartlink
  173. * small filename fixes pmodule.setfilename
  174. * moved import from files.pas -> import.pas
  175. Revision 1.1.1.1 1998/03/25 11:18:12 root
  176. * Restored version
  177. Revision 1.3 1998/03/10 01:17:19 peter
  178. * all files have the same header
  179. * messages are fully implemented, EXTDEBUG uses Comment()
  180. + AG... files for the Assembler generation
  181. Revision 1.2 1998/03/06 00:52:21 peter
  182. * replaced all old messages from errore.msg, only ExtDebug and some
  183. Comment() calls are left
  184. * fixed options.pas
  185. }