comphook.pas 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit handles the compilerhooks for output to external programs
  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. }
  18. unit comphook;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. finput;
  23. Const
  24. { <$10000 will show file and line }
  25. V_None = $0;
  26. V_Fatal = $1;
  27. V_Error = $2;
  28. V_Normal = $4; { doesn't show a text like Error: }
  29. V_Warning = $8;
  30. V_Note = $10;
  31. V_Hint = $20;
  32. V_Macro = $100;
  33. V_Procedure = $200;
  34. V_Conditional = $400;
  35. V_Assem = $800;
  36. V_Declarations = $1000;
  37. V_Info = $10000;
  38. V_Status = $20000;
  39. V_Used = $40000;
  40. V_Tried = $80000;
  41. V_Debug = $100000;
  42. V_Executable = $200000;
  43. V_ShowFile = $ffff;
  44. V_All = $ffffffff;
  45. V_Default = V_Fatal + V_Error + V_Normal;
  46. const
  47. { RHIDE expect gcc like error output }
  48. fatalstr : string[20] = 'Fatal:';
  49. errorstr : string[20] = 'Error:';
  50. warningstr : string[20] = 'Warning:';
  51. notestr : string[20] = 'Note:';
  52. hintstr : string[20] = 'Hint:';
  53. type
  54. PCompilerStatus = ^TCompilerStatus;
  55. TCompilerStatus = record
  56. { Current status }
  57. currentmodule,
  58. currentsourcepath,
  59. currentsource : string; { filename }
  60. currentline,
  61. currentcolumn : longint; { current line and column }
  62. { Total Status }
  63. compiledlines : longint; { the number of lines which are compiled }
  64. errorcount : longint; { number of generated errors }
  65. { Settings for the output }
  66. verbosity : longint;
  67. maxerrorcount : longint;
  68. errorwarning,
  69. errornote,
  70. errorhint,
  71. skip_error,
  72. use_stderr,
  73. use_redir,
  74. use_gccoutput : boolean;
  75. { Redirection support }
  76. redirfile : text;
  77. end;
  78. var
  79. status : tcompilerstatus;
  80. { Default Functions }
  81. procedure def_stop;
  82. procedure def_halt(i : longint);
  83. Function def_status:boolean;
  84. Function def_comment(Level:Longint;const s:string):boolean;
  85. function def_internalerror(i:longint):boolean;
  86. procedure def_initsymbolinfo;
  87. procedure def_donesymbolinfo;
  88. procedure def_extractsymbolinfo;
  89. function def_openinputfile(const filename: string): tinputfile;
  90. Function def_getnamedfiletime(Const F : String) : Longint;
  91. {$ifdef DEBUG}
  92. { allow easy stopping in GDB
  93. using
  94. b DEF_GDB_STOP
  95. cond 1 LEVEL <= 8 }
  96. procedure def_gdb_stop(level : longint);
  97. {$endif DEBUG}
  98. { Function redirecting for IDE support }
  99. type
  100. tstopprocedure = procedure;
  101. thaltprocedure = procedure(i : longint);
  102. tstatusfunction = function:boolean;
  103. tcommentfunction = function(Level:Longint;const s:string):boolean;
  104. tinternalerrorfunction = function(i:longint):boolean;
  105. tinitsymbolinfoproc = procedure;
  106. tdonesymbolinfoproc = procedure;
  107. textractsymbolinfoproc = procedure;
  108. topeninputfilefunc = function(const filename: string): tinputfile;
  109. tgetnamedfiletimefunc = function(const filename: string): longint;
  110. const
  111. do_stop : tstopprocedure = def_stop;
  112. do_halt : thaltprocedure = def_halt;
  113. do_status : tstatusfunction = def_status;
  114. do_comment : tcommentfunction = def_comment;
  115. do_internalerror : tinternalerrorfunction = def_internalerror;
  116. do_initsymbolinfo : tinitsymbolinfoproc = def_initsymbolinfo;
  117. do_donesymbolinfo : tdonesymbolinfoproc = def_donesymbolinfo;
  118. do_extractsymbolinfo : textractsymbolinfoproc = def_extractsymbolinfo;
  119. do_openinputfile : topeninputfilefunc = def_openinputfile;
  120. do_getnamedfiletime : tgetnamedfiletimefunc = def_getnamedfiletime;
  121. implementation
  122. uses
  123. {$ifdef Unix}
  124. linux,
  125. {$endif}
  126. {$ifdef delphi}
  127. dmisc
  128. {$else}
  129. dos
  130. {$endif}
  131. ;
  132. {****************************************************************************
  133. Helper Routines
  134. ****************************************************************************}
  135. function gccfilename(const s : string) : string;
  136. var
  137. i : longint;
  138. begin
  139. for i:=1to length(s) do
  140. begin
  141. case s[i] of
  142. '\' : gccfilename[i]:='/';
  143. 'A'..'Z' : gccfilename[i]:=chr(ord(s[i])+32);
  144. else
  145. gccfilename[i]:=s[i];
  146. end;
  147. end;
  148. gccfilename[0]:=s[0];
  149. end;
  150. function tostr(i : longint) : string;
  151. var
  152. hs : string;
  153. begin
  154. str(i,hs);
  155. tostr:=hs;
  156. end;
  157. {****************************************************************************
  158. Predefined default Handlers
  159. ****************************************************************************}
  160. { predefined handler when then compiler stops }
  161. procedure def_stop;
  162. begin
  163. Halt(1);
  164. end;
  165. {$ifdef DEBUG}
  166. { allow easy stopping in GDB
  167. using
  168. b DEF_GDB_STOP
  169. cond 1 LEVEL <= 8 }
  170. procedure def_gdb_stop(level : longint);
  171. begin
  172. { Its only a dummy for GDB }
  173. end;
  174. {$endif DEBUG}
  175. procedure def_halt(i : longint);
  176. begin
  177. halt(i);
  178. end;
  179. function def_status:boolean;
  180. begin
  181. def_status:=false; { never stop }
  182. { Status info?, Called every line }
  183. if ((status.verbosity and V_Status)<>0) then
  184. begin
  185. {$ifndef Delphi}
  186. if (status.compiledlines=1) then
  187. WriteLn(memavail shr 10,' Kb Free');
  188. {$endif Delphi}
  189. if (status.currentline>0) and (status.currentline mod 100=0) then
  190. {$ifdef FPC}
  191. WriteLn(status.currentline,' ',memavail shr 10,'/',system.heapsize shr 10,' Kb Free');
  192. {$else}
  193. {$ifndef Delphi}
  194. WriteLn(status.currentline,' ',memavail shr 10,' Kb Free');
  195. {$endif Delphi}
  196. {$endif}
  197. end
  198. end;
  199. Function def_comment(Level:Longint;const s:string):boolean;
  200. const
  201. rh_errorstr = 'error:';
  202. rh_warningstr = 'warning:';
  203. var
  204. hs : string;
  205. begin
  206. def_comment:=false; { never stop }
  207. hs:='';
  208. if not(status.use_gccoutput) then
  209. begin
  210. if (status.verbosity and Level)=V_Hint then
  211. hs:=hintstr;
  212. if (status.verbosity and Level)=V_Note then
  213. hs:=notestr;
  214. if (status.verbosity and Level)=V_Warning then
  215. hs:=warningstr;
  216. if (status.verbosity and Level)=V_Error then
  217. hs:=errorstr;
  218. if (status.verbosity and Level)=V_Fatal then
  219. hs:=fatalstr;
  220. end
  221. else
  222. begin
  223. if (status.verbosity and Level)=V_Hint then
  224. hs:=rh_warningstr;
  225. if (status.verbosity and Level)=V_Note then
  226. hs:=rh_warningstr;
  227. if (status.verbosity and Level)=V_Warning then
  228. hs:=rh_warningstr;
  229. if (status.verbosity and Level)=V_Error then
  230. hs:=rh_errorstr;
  231. if (status.verbosity and Level)=V_Fatal then
  232. hs:=rh_errorstr;
  233. end;
  234. if (Level<=V_ShowFile) and (status.currentsource<>'') and (status.currentline>0) then
  235. begin
  236. { Adding the column should not confuse RHIDE,
  237. even if it does not yet use it PM
  238. but only if it is after error or warning !! PM }
  239. if status.currentcolumn>0 then
  240. begin
  241. if status.use_gccoutput then
  242. hs:=gccfilename(status.currentsource)+':'+tostr(status.currentline)+': '+hs+' '+
  243. tostr(status.currentcolumn)+': '+s
  244. else
  245. hs:=status.currentsource+'('+tostr(status.currentline)+
  246. ','+tostr(status.currentcolumn)+') '+hs+' '+s;
  247. end
  248. else
  249. begin
  250. if status.use_gccoutput then
  251. hs:=gccfilename(status.currentsource)+': '+hs+' '+tostr(status.currentline)+': '+s
  252. else
  253. hs:=status.currentsource+'('+tostr(status.currentline)+') '+hs+' '+s;
  254. end;
  255. end
  256. else
  257. begin
  258. if hs<>'' then
  259. hs:=hs+' '+s
  260. else
  261. hs:=s;
  262. end;
  263. {$ifdef FPC}
  264. if status.use_stderr then
  265. begin
  266. writeln(stderr,hs);
  267. flush(stderr);
  268. end
  269. else
  270. {$endif}
  271. begin
  272. if status.use_redir then
  273. writeln(status.redirfile,hs)
  274. else
  275. writeln(hs);
  276. end;
  277. {$ifdef DEBUG}
  278. def_gdb_stop(level);
  279. {$endif DEBUG}
  280. end;
  281. function def_internalerror(i : longint) : boolean;
  282. begin
  283. do_comment(V_Fatal,'Internal error '+tostr(i));
  284. def_internalerror:=true;
  285. end;
  286. procedure def_initsymbolinfo;
  287. begin
  288. end;
  289. procedure def_donesymbolinfo;
  290. begin
  291. end;
  292. procedure def_extractsymbolinfo;
  293. begin
  294. end;
  295. function def_openinputfile(const filename: string): tinputfile;
  296. begin
  297. def_openinputfile:=tdosinputfile.create(filename);
  298. end;
  299. Function def_GetNamedFileTime (Const F : String) : Longint;
  300. var
  301. L : Longint;
  302. {$ifndef Unix}
  303. info : SearchRec;
  304. {$else}
  305. info : stat;
  306. {$endif}
  307. begin
  308. l:=-1;
  309. {$ifdef Unix}
  310. if FStat (F,Info) then
  311. L:=info.mtime;
  312. {$else}
  313. {$ifdef delphi}
  314. dmisc.FindFirst (F,archive+readonly+hidden,info);
  315. {$else delphi}
  316. FindFirst (F,archive+readonly+hidden,info);
  317. {$endif delphi}
  318. if DosError=0 then
  319. l:=info.time;
  320. FindClose(info);
  321. {$endif Unix}
  322. def_GetNamedFileTime:=l;
  323. end;
  324. end.
  325. {
  326. $Log$
  327. Revision 1.11 2000-12-26 15:58:29 peter
  328. * check for verbosity in verbose instead of comphook
  329. Revision 1.10 2000/12/25 00:07:25 peter
  330. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  331. tlinkedlist objects)
  332. Revision 1.9 2000/11/13 15:26:12 marco
  333. * Renamefest
  334. Revision 1.8 2000/09/30 16:07:20 peter
  335. * prefix fix (merged)
  336. Revision 1.7 2000/09/24 21:33:46 peter
  337. * message updates merges
  338. Revision 1.6 2000/09/24 15:06:13 peter
  339. * use defines.inc
  340. Revision 1.5 2000/08/27 16:11:50 peter
  341. * moved some util functions from globals,cobjects to cutils
  342. * splitted files into finput,fmodule
  343. Revision 1.4 2000/08/13 13:04:15 peter
  344. * -vb update
  345. Revision 1.3 2000/08/12 15:30:45 peter
  346. * IDE patch for stream reading (merged)
  347. Revision 1.2 2000/07/13 11:32:38 michael
  348. + removed logs
  349. }