import.pas 7.3 KB

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