import.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. {$ifndef NOTARGETLINUX}
  58. ,t_linux
  59. {$endif}
  60. {$ifndef NOTARGETOS2}
  61. ,t_os2
  62. {$endif}
  63. {$ifndef NOTARGETWIN32}
  64. ,t_win32
  65. {$endif}
  66. {$ifndef NOTARGETGO32V2}
  67. ,t_go32v2
  68. {$endif}
  69. {$endif}
  70. {$ifdef m68k}
  71. {$ifndef NOTARGETLINUX}
  72. ,t_linux
  73. {$endif}
  74. {$endif}
  75. {$ifdef powerpc}
  76. {$ifndef NOTARGETLINUX}
  77. ,t_linux
  78. {$endif}
  79. {$endif}
  80. {$ifdef alpha}
  81. {$ifndef NOTARGETLINUX}
  82. ,t_linux
  83. {$endif}
  84. {$endif}
  85. ;
  86. {****************************************************************************
  87. Timported_item
  88. ****************************************************************************}
  89. constructor timported_item.init(const n,s : string;o : word);
  90. begin
  91. inherited init;
  92. func:=stringdup(n);
  93. name:=stringdup(s);
  94. ordnr:=o;
  95. lab:=nil;
  96. is_var:=false;
  97. end;
  98. constructor timported_item.init_var(const n,s : string);
  99. begin
  100. inherited init;
  101. func:=stringdup(n);
  102. name:=stringdup(s);
  103. ordnr:=0;
  104. lab:=nil;
  105. is_var:=true;
  106. end;
  107. destructor timported_item.done;
  108. begin
  109. stringdispose(name);
  110. stringdispose(func);
  111. inherited done;
  112. end;
  113. {****************************************************************************
  114. TImportlist
  115. ****************************************************************************}
  116. constructor timportlist.init(const n : string);
  117. begin
  118. inherited init;
  119. dllname:=stringdup(n);
  120. imported_items:=new(plinkedlist,init);
  121. end;
  122. destructor timportlist.done;
  123. begin
  124. dispose(imported_items,done);
  125. stringdispose(dllname);
  126. end;
  127. {****************************************************************************
  128. TImportLib
  129. ****************************************************************************}
  130. constructor timportlib.Init;
  131. begin
  132. end;
  133. destructor timportlib.Done;
  134. begin
  135. end;
  136. procedure timportlib.preparelib(const s:string);
  137. begin
  138. Message(exec_e_dll_not_supported);
  139. end;
  140. procedure timportlib.importprocedure(const func,module:string;index:longint;const name:string);
  141. begin
  142. Message(exec_e_dll_not_supported);
  143. end;
  144. procedure timportlib.importvariable(const varname,module:string;const name:string);
  145. begin
  146. Message(exec_e_dll_not_supported);
  147. end;
  148. procedure timportlib.generatelib;
  149. begin
  150. Message(exec_e_dll_not_supported);
  151. end;
  152. procedure DoneImport;
  153. begin
  154. if assigned(importlib) then
  155. dispose(importlib,done);
  156. end;
  157. procedure InitImport;
  158. begin
  159. case target_info.target of
  160. {$ifdef i386}
  161. target_i386_Linux :
  162. importlib:=new(pimportliblinux,Init);
  163. target_i386_Win32 :
  164. importlib:=new(pimportlibwin32,Init);
  165. target_i386_OS2 :
  166. importlib:=new(pimportlibos2,Init);
  167. {$endif i386}
  168. {$ifdef m68k}
  169. target_m68k_Linux :
  170. importlib:=new(pimportliblinux,Init);
  171. {$endif m68k}
  172. {$ifdef alpha}
  173. target_alpha_Linux :
  174. importlib:=new(pimportliblinux,Init);
  175. {$endif alpha}
  176. {$ifdef powerpc}
  177. target_alpha_Linux :
  178. importlib:=new(pimportliblinux,Init);
  179. {$endif powerpc}
  180. else
  181. importlib:=new(pimportlib,Init);
  182. end;
  183. end;
  184. end.
  185. {
  186. $Log$
  187. Revision 1.13 1999-10-21 14:29:34 peter
  188. * redesigned linker object
  189. + library support for linux (only procedures can be exported)
  190. Revision 1.12 1999/08/04 13:02:44 jonas
  191. * all tokens now start with an underscore
  192. * PowerPC compiles!!
  193. Revision 1.11 1999/08/03 13:50:16 michael
  194. + Changes for alpha
  195. Revision 1.10 1999/05/17 14:33:01 pierre
  196. * func was not disposed in timported_item
  197. Revision 1.9 1998/11/28 16:20:50 peter
  198. + support for dll variables
  199. Revision 1.8 1998/10/19 18:07:12 peter
  200. + external dll_name name func support for linux
  201. Revision 1.7 1998/10/19 15:41:02 peter
  202. * better splitname to support glib-1.1.dll alike names
  203. Revision 1.6 1998/10/13 13:10:17 peter
  204. * new style for m68k/i386 infos and enums
  205. Revision 1.5 1998/10/06 17:16:51 pierre
  206. * some memory leaks fixed (thanks to Peter for heaptrc !)
  207. Revision 1.4 1998/09/30 12:16:47 peter
  208. * remove extension if one is specified
  209. Revision 1.3 1998/06/04 23:51:43 peter
  210. * m68k compiles
  211. + .def file creation moved to gendef.pas so it could also be used
  212. for win32
  213. Revision 1.2 1998/04/27 23:10:28 peter
  214. + new scanner
  215. * $makelib -> if smartlink
  216. * small filename fixes pmodule.setfilename
  217. * moved import from files.pas -> import.pas
  218. Revision 1.1.1.1 1998/03/25 11:18:12 root
  219. * Restored version
  220. Revision 1.3 1998/03/10 01:17:19 peter
  221. * all files have the same header
  222. * messages are fully implemented, EXTDEBUG uses Comment()
  223. + AG... files for the Assembler generation
  224. Revision 1.2 1998/03/06 00:52:21 peter
  225. * replaced all old messages from errore.msg, only ExtDebug and some
  226. Comment() calls are left
  227. * fixed options.pas
  228. }