verbose.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. {
  2. $Id$
  3. Copyright (c) 1998 by the FPC development team
  4. This unit handles the verbose management
  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 verbose;
  19. interface
  20. uses messages;
  21. {$IFNDEF EXTERN_MSG}
  22. {$i msgtxt.inc}
  23. {$ENDIF}
  24. {$i msgidx.inc}
  25. Const
  26. { <$10000 will show file and line }
  27. V_Fatal = $0;
  28. V_Error = $1;
  29. V_Normal = $2; { doesn't show a text like Error: }
  30. V_Warning = $4;
  31. V_Note = $8;
  32. V_Hint = $10;
  33. V_Macro = $100;
  34. V_Procedure = $200;
  35. V_Conditional = $400;
  36. V_Info = $10000;
  37. V_Status = $20000;
  38. V_Used = $40000;
  39. V_Tried = $80000;
  40. V_Debug = $100000;
  41. V_ShowFile = $ffff;
  42. V_All = $ffffffff;
  43. V_Default = V_Fatal + V_Error + V_Normal;
  44. var
  45. msg : pmessage;
  46. lastfileidx,
  47. lastmoduleidx : longint;
  48. procedure SetRedirectFile(const fn:string);
  49. function SetVerbosity(const s:string):boolean;
  50. procedure LoadMsgFile(const fn:string);
  51. procedure Stop;
  52. procedure ShowStatus;
  53. procedure Internalerror(i:longint);
  54. procedure Comment(l:longint;const s:string);
  55. procedure Message(w:tmsgconst);
  56. procedure Message1(w:tmsgconst;const s1:string);
  57. procedure Message2(w:tmsgconst;const s1,s2:string);
  58. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  59. procedure InitVerbose;
  60. implementation
  61. uses
  62. files,comphook,
  63. globals;
  64. var
  65. redirexitsave : pointer;
  66. {****************************************************************************
  67. Extra Handlers for default compiler
  68. ****************************************************************************}
  69. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  70. begin
  71. exitproc:=redirexitsave;
  72. if status.use_redir then
  73. close(status.redirfile);
  74. end;
  75. procedure SetRedirectFile(const fn:string);
  76. begin
  77. assign(status.redirfile,fn);
  78. {$I-}
  79. rewrite(status.redirfile);
  80. {$I+}
  81. status.use_redir:=(ioresult=0);
  82. if status.use_redir then
  83. begin
  84. redirexitsave:=exitproc;
  85. exitproc:=@DoneRedirectFile;
  86. end;
  87. end;
  88. function SetVerbosity(const s:string):boolean;
  89. var
  90. m : Longint;
  91. i : Word;
  92. inverse : boolean;
  93. c : char;
  94. begin
  95. Setverbosity:=false;
  96. val(s,m,i);
  97. if (i=0) and (s<>'') then
  98. status.verbosity:=m
  99. else
  100. begin
  101. for i:=1 to length(s) do
  102. begin
  103. c:=s[i];
  104. if (i<length(s)) and (s[i+1]='-') then
  105. begin
  106. inc(i);
  107. inverse:=true;
  108. end
  109. else
  110. inverse:=false;
  111. case upcase(s[i]) of
  112. { Special cases }
  113. 'A' : status.verbosity:=V_All;
  114. '0' : status.verbosity:=V_Default;
  115. 'R' : begin
  116. if inverse then
  117. begin
  118. status.use_gccoutput:=false;
  119. status.use_stderr:=false;
  120. end
  121. else
  122. begin
  123. status.use_gccoutput:=true;
  124. status.use_stderr:=true;
  125. end;
  126. end;
  127. { Normal cases - do an or }
  128. 'E' : if inverse then
  129. status.verbosity:=status.verbosity and (not V_Error)
  130. else
  131. status.verbosity:=status.verbosity or V_Error;
  132. 'I' : if inverse then
  133. status.verbosity:=status.verbosity and (not V_Info)
  134. else
  135. status.verbosity:=status.verbosity or V_Info;
  136. 'W' : if inverse then
  137. status.verbosity:=status.verbosity and (not V_Warning)
  138. else
  139. status.verbosity:=status.verbosity or V_Warning;
  140. 'N' : if inverse then
  141. status.verbosity:=status.verbosity and (not V_Note)
  142. else
  143. status.verbosity:=status.verbosity or V_Note;
  144. 'H' : if inverse then
  145. status.verbosity:=status.verbosity and (not V_Hint)
  146. else
  147. status.verbosity:=status.verbosity or V_Hint;
  148. 'L' : if inverse then
  149. status.verbosity:=status.verbosity and (not V_Status)
  150. else
  151. status.verbosity:=status.verbosity or V_Status;
  152. 'U' : if inverse then
  153. status.verbosity:=status.verbosity and (not V_Used)
  154. else
  155. status.verbosity:=status.verbosity or V_Used;
  156. 'T' : if inverse then
  157. status.verbosity:=status.verbosity and (not V_Tried)
  158. else
  159. status.verbosity:=status.verbosity or V_Tried;
  160. 'M' : if inverse then
  161. status.verbosity:=status.verbosity and (not V_Macro)
  162. else
  163. status.verbosity:=status.verbosity or V_Macro;
  164. 'P' : if inverse then
  165. status.verbosity:=status.verbosity and (not V_Procedure)
  166. else
  167. status.verbosity:=status.verbosity or V_Procedure;
  168. 'C' : if inverse then
  169. status.verbosity:=status.verbosity and (not V_Conditional)
  170. else
  171. status.verbosity:=status.verbosity or V_Conditional;
  172. 'D' : if inverse then
  173. status.verbosity:=status.verbosity and (not V_Debug)
  174. else
  175. status.verbosity:=status.verbosity or V_Debug;
  176. end;
  177. end;
  178. end;
  179. if status.verbosity=0 then
  180. status.verbosity:=V_Default;
  181. setverbosity:=true;
  182. end;
  183. procedure LoadMsgFile(const fn:string);
  184. begin
  185. if not (msg=nil) then
  186. dispose(msg,Done);
  187. msg:=new(pmessage,InitExtern(fn,ord(endmsgconst)));
  188. end;
  189. procedure stop;
  190. begin
  191. {$ifndef TP}
  192. do_stop();
  193. {$else}
  194. do_stop;
  195. {$endif}
  196. end;
  197. procedure ShowStatus;
  198. begin
  199. {$ifndef TP}
  200. if do_status() then
  201. stop;
  202. {$else}
  203. if do_status then
  204. stop;
  205. {$endif}
  206. end;
  207. procedure internalerror(i : longint);
  208. begin
  209. do_internalerror(i);
  210. stop;
  211. end;
  212. procedure Comment(l:longint;const s:string);
  213. var
  214. dostop : boolean;
  215. begin
  216. dostop:=((l and V_Fatal)<>0);
  217. if (l and V_Error)<>0 then
  218. inc(status.errorcount);
  219. { fix status }
  220. status.currentline:=aktfilepos.line;
  221. status.currentcolumn:=aktfilepos.column;
  222. if assigned(current_module) and
  223. ((current_module^.unit_index<>lastmoduleidx) or
  224. (current_module^.current_index<>lastfileidx)) then
  225. begin
  226. status.currentsource:=current_module^.sourcefiles.get_file_name(current_module^.current_index);
  227. lastmoduleidx:=current_module^.unit_index;
  228. lastfileidx:=current_module^.current_index;
  229. end;
  230. { show comment }
  231. if do_comment(l,s) or dostop or (status.errorcount>=status.maxerrorcount) then
  232. stop
  233. end;
  234. Procedure Msg2Comment(s:string);
  235. var
  236. idx,i,v : longint;
  237. dostop : boolean;
  238. begin
  239. {Reset}
  240. dostop:=false;
  241. v:=0;
  242. {Parse options}
  243. idx:=pos('_',s);
  244. if idx=0 then
  245. v:=V_Default
  246. else
  247. if (idx in [1..5]) then
  248. begin
  249. for i:=1 to idx do
  250. begin
  251. case upcase(s[i]) of
  252. 'F' : begin
  253. v:=v or V_Fatal;
  254. inc(status.errorcount);
  255. dostop:=true;
  256. end;
  257. 'E' : begin
  258. v:=v or V_Error;
  259. inc(status.errorcount);
  260. end;
  261. 'O' : v:=v or V_Normal;
  262. 'W' : v:=v or V_Warning;
  263. 'N' : v:=v or V_Note;
  264. 'H' : v:=v or V_Hint;
  265. 'I' : v:=v or V_Info;
  266. 'L' : v:=v or V_Status;
  267. 'U' : v:=v or V_Used;
  268. 'T' : v:=v or V_Tried;
  269. 'M' : v:=v or V_Macro;
  270. 'P' : v:=v or V_Procedure;
  271. 'C' : v:=v or V_Conditional;
  272. 'D' : v:=v or V_Debug;
  273. 'S' : dostop:=true;
  274. '_' : ;
  275. end;
  276. end;
  277. end;
  278. Delete(s,1,idx);
  279. Replace(s,'$VER',version_string);
  280. Replace(s,'$TARGET',target_string);
  281. { fix status }
  282. status.currentline:=aktfilepos.line;
  283. status.currentcolumn:=aktfilepos.column;
  284. if assigned(current_module) and
  285. ((current_module^.unit_index<>lastmoduleidx) or
  286. (current_module^.current_index<>lastfileidx)) then
  287. begin
  288. status.currentsource:=current_module^.sourcefiles.get_file_name(current_module^.current_index);
  289. lastmoduleidx:=current_module^.unit_index;
  290. lastfileidx:=current_module^.current_index;
  291. end;
  292. { show comment }
  293. if do_comment(v,s) or dostop or (status.errorcount>=status.maxerrorcount) then
  294. stop;
  295. end;
  296. procedure Message(w:tmsgconst);
  297. begin
  298. Msg2Comment(msg^.Get(ord(w)));
  299. end;
  300. procedure Message1(w:tmsgconst;const s1:string);
  301. begin
  302. Msg2Comment(msg^.Get1(ord(w),s1));
  303. end;
  304. procedure Message2(w:tmsgconst;const s1,s2:string);
  305. begin
  306. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  307. end;
  308. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  309. begin
  310. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  311. end;
  312. procedure InitVerbose;
  313. begin
  314. { Init }
  315. FillChar(Status,sizeof(TCompilerStatus),0);
  316. status.verbosity:=V_Default;
  317. Status.MaxErrorCount:=50;
  318. end;
  319. begin
  320. {$IFNDEF EXTERN_MSG}
  321. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  322. {$ENDIF}
  323. end.
  324. {
  325. $Log$
  326. Revision 1.12 1998-08-10 10:18:37 peter
  327. + Compiler,Comphook unit which are the new interface units to the
  328. compiler
  329. Revision 1.11 1998/07/14 14:47:13 peter
  330. * released NEWINPUT
  331. Revision 1.10 1998/07/07 12:32:56 peter
  332. * status.currentsource is now calculated in verbose (more accurated)
  333. Revision 1.9 1998/07/07 11:20:20 peter
  334. + NEWINPUT for a better inputfile and scanner object
  335. Revision 1.8 1998/05/23 01:21:35 peter
  336. + aktasmmode, aktoptprocessor, aktoutputformat
  337. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  338. + $LIBNAME to set the library name where the unit will be put in
  339. * splitted cgi386 a bit (codeseg to large for bp7)
  340. * nasm, tasm works again. nasm moved to ag386nsm.pas
  341. Revision 1.7 1998/05/21 19:33:40 peter
  342. + better procedure directive handling and only one table
  343. Revision 1.6 1998/05/12 10:47:01 peter
  344. * moved printstatus to verb_def
  345. + V_Normal which is between V_Error and V_Warning and doesn't have a
  346. prefix like error: warning: and is included in V_Default
  347. * fixed some messages
  348. * first time parameter scan is only for -v and -T
  349. - removed old style messages
  350. Revision 1.5 1998/04/30 15:59:43 pierre
  351. * GDB works again better :
  352. correct type info in one pass
  353. + UseTokenInfo for better source position
  354. * fixed one remaining bug in scanner for line counts
  355. * several little fixes
  356. Revision 1.4 1998/04/23 12:11:22 peter
  357. * fixed -v0 to displayV_Default (=errors+fatals)
  358. Revision 1.3 1998/04/13 21:15:42 florian
  359. * error handling of pass_1 and cgi386 fixed
  360. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  361. fixed, verified
  362. }