verbose.pas 11 KB

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