verbose.pas 12 KB

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