import.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. stringdispose(func);
  87. inherited done;
  88. end;
  89. {****************************************************************************
  90. TImportlist
  91. ****************************************************************************}
  92. constructor timportlist.init(const n : string);
  93. begin
  94. inherited init;
  95. dllname:=stringdup(n);
  96. imported_items:=new(plinkedlist,init);
  97. end;
  98. destructor timportlist.done;
  99. begin
  100. dispose(imported_items,done);
  101. stringdispose(dllname);
  102. end;
  103. {****************************************************************************
  104. TImportLib
  105. ****************************************************************************}
  106. constructor timportlib.Init;
  107. begin
  108. end;
  109. destructor timportlib.Done;
  110. begin
  111. end;
  112. procedure timportlib.preparelib(const s:string);
  113. begin
  114. Message(exec_e_dll_not_supported);
  115. end;
  116. procedure timportlib.importprocedure(const func,module:string;index:longint;const name:string);
  117. begin
  118. Message(exec_e_dll_not_supported);
  119. end;
  120. procedure timportlib.importvariable(const varname,module:string;const name:string);
  121. begin
  122. Message(exec_e_dll_not_supported);
  123. end;
  124. procedure timportlib.generatelib;
  125. begin
  126. Message(exec_e_dll_not_supported);
  127. end;
  128. procedure DoneImport;
  129. begin
  130. if assigned(importlib) then
  131. dispose(importlib,done);
  132. end;
  133. procedure InitImport;
  134. begin
  135. case target_info.target of
  136. {$ifdef i386}
  137. target_i386_Linux :
  138. importlib:=new(pimportliblinux,Init);
  139. target_i386_Win32 :
  140. importlib:=new(pimportlibwin32,Init);
  141. target_i386_OS2 :
  142. importlib:=new(pimportlibos2,Init);
  143. {$endif i386}
  144. {$ifdef m68k}
  145. target_m68k_Linux :
  146. importlib:=new(pimportliblinux,Init);
  147. {$endif m68k}
  148. {$ifdef alpha}
  149. target_alpha_Linux :
  150. importlib:=new(pimportliblinux,Init);
  151. {$endif alpha}
  152. {$ifdef powerpc}
  153. target_alpha_Linux :
  154. importlib:=new(pimportliblinux,Init);
  155. {$endif powerpc}
  156. else
  157. importlib:=new(pimportlib,Init);
  158. end;
  159. end;
  160. end.
  161. {
  162. $Log$
  163. Revision 1.12 1999-08-04 13:02:44 jonas
  164. * all tokens now start with an underscore
  165. * PowerPC compiles!!
  166. Revision 1.11 1999/08/03 13:50:16 michael
  167. + Changes for alpha
  168. Revision 1.10 1999/05/17 14:33:01 pierre
  169. * func was not disposed in timported_item
  170. Revision 1.9 1998/11/28 16:20:50 peter
  171. + support for dll variables
  172. Revision 1.8 1998/10/19 18:07:12 peter
  173. + external dll_name name func support for linux
  174. Revision 1.7 1998/10/19 15:41:02 peter
  175. * better splitname to support glib-1.1.dll alike names
  176. Revision 1.6 1998/10/13 13:10:17 peter
  177. * new style for m68k/i386 infos and enums
  178. Revision 1.5 1998/10/06 17:16:51 pierre
  179. * some memory leaks fixed (thanks to Peter for heaptrc !)
  180. Revision 1.4 1998/09/30 12:16:47 peter
  181. * remove extension if one is specified
  182. Revision 1.3 1998/06/04 23:51:43 peter
  183. * m68k compiles
  184. + .def file creation moved to gendef.pas so it could also be used
  185. for win32
  186. Revision 1.2 1998/04/27 23:10:28 peter
  187. + new scanner
  188. * $makelib -> if smartlink
  189. * small filename fixes pmodule.setfilename
  190. * moved import from files.pas -> import.pas
  191. Revision 1.1.1.1 1998/03/25 11:18:12 root
  192. * Restored version
  193. Revision 1.3 1998/03/10 01:17:19 peter
  194. * all files have the same header
  195. * messages are fully implemented, EXTDEBUG uses Comment()
  196. + AG... files for the Assembler generation
  197. Revision 1.2 1998/03/06 00:52:21 peter
  198. * replaced all old messages from errore.msg, only ExtDebug and some
  199. Comment() calls are left
  200. * fixed options.pas
  201. }