import.pas 7.1 KB

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