import.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. {$i defines.inc}
  19. interface
  20. uses
  21. cutils,cclasses,
  22. aasm;
  23. type
  24. timported_item = class(tlinkedlistitem)
  25. ordnr : word;
  26. name,
  27. func : pstring;
  28. lab : tasmlabel; { should be plabel, but this gaves problems with circular units }
  29. is_var : boolean;
  30. constructor Create(const n,s : string;o : word);
  31. constructor Create_var(const n,s : string);
  32. destructor Destroy;override;
  33. end;
  34. timportlist = class(tlinkedlistitem)
  35. dllname : pstring;
  36. imported_items : tlinkedlist;
  37. constructor Create(const n : string);
  38. destructor Destroy;Override;
  39. end;
  40. timportlib=class
  41. private
  42. notsupmsg : boolean;
  43. procedure NotSupported;
  44. public
  45. constructor Create;
  46. destructor Destroy;override;
  47. procedure preparelib(const s:string);virtual;
  48. procedure importprocedure(const func,module:string;index:longint;const name:string);virtual;
  49. procedure importvariable(const varname,module:string;const name:string);virtual;
  50. procedure generatelib;virtual;
  51. procedure generatesmartlib;virtual;
  52. end;
  53. TDLLScanner=class
  54. public
  55. f:file;
  56. impname:string;
  57. TheWord:array[0..1]of char;
  58. HeaderOffset:cardinal;
  59. loaded:integer;
  60. function isSuitableFileType(x:cardinal):longbool;virtual;abstract;
  61. function GetEdata(HeaderEntry:cardinal):longbool;virtual;abstract;
  62. function Scan(const binname:string):longbool;virtual;abstract;
  63. end;
  64. var
  65. importlib : timportlib;
  66. procedure InitImport;
  67. procedure DoneImport;
  68. implementation
  69. uses
  70. systems,verbose,globals
  71. {$ifdef i386}
  72. {$ifndef NOTARGETLINUX}
  73. ,t_linux
  74. {$endif}
  75. {$ifndef NOTARGETFREEBSD}
  76. ,t_fbsd
  77. {$endif}
  78. {$ifndef NOTARGETSUNOS}
  79. ,t_sunos
  80. {$endif}
  81. {$ifndef NOTARGETOS2}
  82. ,t_os2
  83. {$endif}
  84. {$ifndef NOTARGETWIN32}
  85. ,t_win32
  86. {$endif}
  87. {$ifndef NOTARGETNETWARE}
  88. ,t_nwm
  89. {$endif}
  90. {$ifndef NOTARGETGO32V2}
  91. ,t_go32v2
  92. {$endif}
  93. {$endif}
  94. {$ifdef m68k}
  95. {$ifndef NOTARGETLINUX}
  96. ,t_linux
  97. {$endif}
  98. {$endif}
  99. {$ifdef powerpc}
  100. {$ifndef NOTARGETLINUX}
  101. ,t_linux
  102. {$endif}
  103. {$endif}
  104. {$ifdef alpha}
  105. {$ifndef NOTARGETLINUX}
  106. ,t_linux
  107. {$endif}
  108. {$endif}
  109. ;
  110. {****************************************************************************
  111. Timported_item
  112. ****************************************************************************}
  113. constructor timported_item.Create(const n,s : string;o : word);
  114. begin
  115. inherited Create;
  116. func:=stringdup(n);
  117. name:=stringdup(s);
  118. ordnr:=o;
  119. lab:=nil;
  120. is_var:=false;
  121. end;
  122. constructor timported_item.create_var(const n,s : string);
  123. begin
  124. inherited Create;
  125. func:=stringdup(n);
  126. name:=stringdup(s);
  127. ordnr:=0;
  128. lab:=nil;
  129. is_var:=true;
  130. end;
  131. destructor timported_item.destroy;
  132. begin
  133. stringdispose(name);
  134. stringdispose(func);
  135. inherited destroy;
  136. end;
  137. {****************************************************************************
  138. TImportlist
  139. ****************************************************************************}
  140. constructor timportlist.Create(const n : string);
  141. begin
  142. inherited Create;
  143. dllname:=stringdup(n);
  144. imported_items:=Tlinkedlist.Create;
  145. end;
  146. destructor timportlist.destroy;
  147. begin
  148. imported_items.free;
  149. stringdispose(dllname);
  150. end;
  151. {****************************************************************************
  152. TImportLib
  153. ****************************************************************************}
  154. constructor timportlib.Create;
  155. begin
  156. notsupmsg:=false;
  157. end;
  158. destructor timportlib.Destroy;
  159. begin
  160. end;
  161. procedure timportlib.NotSupported;
  162. begin
  163. { show the message only once }
  164. if not notsupmsg then
  165. begin
  166. Message(exec_e_dll_not_supported);
  167. notsupmsg:=true;
  168. end;
  169. end;
  170. procedure timportlib.preparelib(const s:string);
  171. begin
  172. NotSupported;
  173. end;
  174. procedure timportlib.importprocedure(const func,module:string;index:longint;const name:string);
  175. begin
  176. NotSupported;
  177. end;
  178. procedure timportlib.importvariable(const varname,module:string;const name:string);
  179. begin
  180. NotSupported;
  181. end;
  182. procedure timportlib.generatelib;
  183. begin
  184. NotSupported;
  185. end;
  186. procedure timportlib.generatesmartlib;
  187. begin
  188. NotSupported;
  189. end;
  190. procedure DoneImport;
  191. begin
  192. if assigned(importlib) then
  193. importlib.free;
  194. end;
  195. procedure InitImport;
  196. begin
  197. case target_info.target of
  198. {$ifdef i386}
  199. {$ifndef NOTARGETLINUX}
  200. target_i386_Linux :
  201. importlib:=Timportliblinux.Create;
  202. {$endif}
  203. {$ifndef NOTARGETFREEBSD}
  204. target_i386_freebsd:
  205. importlib:=Timportlibfreebsd.Create;
  206. {$endif}
  207. {$ifndef NOTARGETSUNOS}
  208. target_i386_sunos:
  209. importlib:=Timportlibsunos.Create;
  210. {$endif}
  211. {$ifndef NOTARGETWIN32}
  212. target_i386_Win32 :
  213. importlib:=Timportlibwin32.Create;
  214. {$endif}
  215. {$ifndef NOTARGETOS2}
  216. target_i386_OS2 :
  217. importlib:=Timportlibos2.Create;
  218. {$endif}
  219. {$ifndef NOTARGETNETWARE}
  220. target_i386_netware :
  221. importlib:=Timportlibnetware.Create;
  222. {$endif}
  223. {$endif i386}
  224. {$ifdef m68k}
  225. target_m68k_Linux :
  226. importlib:=Timportliblinux.Create;
  227. {$endif m68k}
  228. {$ifdef alpha}
  229. target_alpha_Linux :
  230. importlib:=Timportliblinux.Create;
  231. {$endif alpha}
  232. {$ifdef powerpc}
  233. target_alpha_Linux :
  234. importlib:=Timportliblinux.Create;
  235. {$endif powerpc}
  236. else
  237. importlib:=Timportlib.Create;
  238. end;
  239. end;
  240. end.
  241. {
  242. $Log$
  243. Revision 1.12 2001-04-13 01:22:08 peter
  244. * symtable change to classes
  245. * range check generation and errors fixed, make cycle DEBUG=1 works
  246. * memory leaks fixed
  247. Revision 1.11 2001/03/06 18:28:02 peter
  248. * patch from Pavel with a new and much faster DLL Scanner for
  249. automatic importing so $linklib works for DLLs. Thanks Pavel!
  250. Revision 1.10 2001/02/26 19:44:52 peter
  251. * merged generic m68k updates from fixes branch
  252. Revision 1.9 2001/02/03 00:09:02 peter
  253. * fixed netware typo in previous commit
  254. Revision 1.8 2001/02/02 22:43:39 peter
  255. * add notarget defines
  256. Revision 1.7 2000/12/25 00:07:26 peter
  257. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  258. tlinkedlist objects)
  259. Revision 1.6 2000/09/24 15:06:18 peter
  260. * use defines.inc
  261. Revision 1.5 2000/09/16 12:22:52 peter
  262. * freebsd support merged
  263. Revision 1.4 2000/09/11 17:00:23 florian
  264. + first implementation of Netware Module support, thanks to
  265. Armin Diehl ([email protected]) for providing the patches
  266. Revision 1.3 2000/08/27 16:11:51 peter
  267. * moved some util functions from globals,cobjects to cutils
  268. * splitted files into finput,fmodule
  269. Revision 1.2 2000/07/13 11:32:43 michael
  270. + removed logs
  271. }