verbose.pas 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. MaxErrorCount : longint = 50;
  27. { <$100 can include file and linenr info }
  28. V_Fatal = $0;
  29. V_Error = $1;
  30. V_Normal = $2;
  31. V_Warning = $4;
  32. V_Note = $8;
  33. V_Hint = $10;
  34. V_Info = $100;
  35. V_Status = $200;
  36. V_Used = $400;
  37. V_Tried = $800;
  38. V_Macro = $1000;
  39. V_Procedure = $2000;
  40. V_Conditional = $4000;
  41. V_Debug = $8000;
  42. V_All = $ffffffff;
  43. V_Default = V_Fatal + V_Error + V_Normal;
  44. Verbosity : longint=V_Default;
  45. type
  46. TCompileStatus = record
  47. currentmodule,
  48. currentsource : string; { filename }
  49. currentline,
  50. currentcolumn : longint; { current line and column }
  51. compiledlines : longint; { the number of lines which are compiled }
  52. errorcount : longint; { number of generated errors }
  53. end;
  54. var
  55. status : tcompilestatus;
  56. msg : pmessage;
  57. UseStdErr,
  58. Use_Rhide : boolean;
  59. procedure LoadMsgFile(const fn:string);
  60. function SetVerbosity(const s:string):boolean;
  61. procedure stop;
  62. procedure comment(l:longint;const s:string);
  63. procedure internalerror(i:longint);
  64. procedure Message(w:tmsgconst);
  65. procedure Message1(w:tmsgconst;const s1:string);
  66. procedure Message2(w:tmsgconst;const s1,s2:string);
  67. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  68. { Function redirecting for IDE support }
  69. type
  70. tstopprocedure = procedure;
  71. tcommentfunction = function(Level:Longint;const s:string):boolean;
  72. tinternalerrorfunction = function(i:longint):boolean;
  73. var
  74. do_stop : tstopprocedure;
  75. do_comment : tcommentfunction;
  76. do_internalerror : tinternalerrorfunction;
  77. implementation
  78. uses
  79. globals;
  80. procedure LoadMsgFile(const fn:string);
  81. begin
  82. if not (msg=nil) then
  83. dispose(msg,Done);
  84. msg:=new(pmessage,InitExtern(fn,ord(endmsgconst)));
  85. end;
  86. function SetVerbosity(const s:string):boolean;
  87. var
  88. m : Longint;
  89. i : Word;
  90. inverse : boolean;
  91. c : char;
  92. begin
  93. setverbosity:=false;
  94. val(s,m,i);
  95. if (i=0) and (s<>'') then
  96. verbosity:=m
  97. else
  98. begin
  99. for i:=1 to length(s) do
  100. begin
  101. c:=s[i];
  102. if (i<length(s)) and (s[i+1]='-') then
  103. begin
  104. inc(i);
  105. inverse:=true;
  106. end
  107. else
  108. inverse:=false;
  109. case upcase(s[i]) of
  110. { Special cases }
  111. 'A' : Verbosity:=V_All;
  112. '0' : Verbosity:=V_Default;
  113. 'R' : begin
  114. if inverse then
  115. begin
  116. Use_rhide:=false;
  117. UseStdErr:=false;
  118. end
  119. else
  120. begin
  121. Use_rhide:=true;
  122. UseStdErr:=true;
  123. end;
  124. end;
  125. { Normal cases - do an or }
  126. 'E' : if inverse then
  127. Verbosity:=Verbosity and (not V_Error)
  128. else
  129. Verbosity:=Verbosity or V_Error;
  130. 'I' : if inverse then
  131. Verbosity:=Verbosity and (not V_Info)
  132. else
  133. Verbosity:=Verbosity or V_Info;
  134. 'W' : if inverse then
  135. Verbosity:=Verbosity and (not V_Warning)
  136. else
  137. Verbosity:=Verbosity or V_Warning;
  138. 'N' : if inverse then
  139. Verbosity:=Verbosity and (not V_Note)
  140. else
  141. Verbosity:=Verbosity or V_Note;
  142. 'H' : if inverse then
  143. Verbosity:=Verbosity and (not V_Hint)
  144. else
  145. Verbosity:=Verbosity or V_Hint;
  146. 'L' : if inverse then
  147. Verbosity:=Verbosity and (not V_Status)
  148. else
  149. Verbosity:=Verbosity or V_Status;
  150. 'U' : if inverse then
  151. Verbosity:=Verbosity and (not V_Used)
  152. else
  153. Verbosity:=Verbosity or V_Used;
  154. 'T' : if inverse then
  155. Verbosity:=Verbosity and (not V_Tried)
  156. else
  157. Verbosity:=Verbosity or V_Tried;
  158. 'M' : if inverse then
  159. Verbosity:=Verbosity and (not V_Macro)
  160. else
  161. Verbosity:=Verbosity or V_Macro;
  162. 'P' : if inverse then
  163. Verbosity:=Verbosity and (not V_Procedure)
  164. else
  165. Verbosity:=Verbosity or V_Procedure;
  166. 'C' : if inverse then
  167. Verbosity:=Verbosity and (not V_Conditional)
  168. else
  169. Verbosity:=Verbosity or V_Conditional;
  170. 'D' : if inverse then
  171. Verbosity:=Verbosity and (not V_Debug)
  172. else
  173. Verbosity:=Verbosity or V_Debug;
  174. end;
  175. end;
  176. end;
  177. if Verbosity=0 then
  178. Verbosity:=V_Default;
  179. setverbosity:=true;
  180. end;
  181. procedure stop;
  182. begin
  183. {$ifndef TP}
  184. do_stop();
  185. {$else}
  186. do_stop;
  187. {$endif}
  188. end;
  189. procedure internalerror(i : longint);
  190. begin
  191. do_internalerror(i);
  192. stop;
  193. end;
  194. procedure Comment(l:longint;const s:string);
  195. var
  196. dostop : boolean;
  197. begin
  198. dostop:=((l and V_Fatal)<>0);
  199. if (l and V_Error)<>0 then
  200. inc(status.errorcount);
  201. { fix status }
  202. {$ifdef NEWINPUT}
  203. status.currentline:=aktfilepos.line;
  204. status.currentcolumn:=aktfilepos.column;
  205. {$endif}
  206. { show comment }
  207. if do_comment(l,s) or dostop or (status.errorcount>=maxerrorcount) then
  208. stop
  209. end;
  210. Procedure Msg2Comment(s:string);
  211. var
  212. idx,i,v : longint;
  213. dostop : boolean;
  214. begin
  215. {Reset}
  216. dostop:=false;
  217. v:=0;
  218. {Parse options}
  219. idx:=pos('_',s);
  220. if idx=0 then
  221. v:=V_Default
  222. else
  223. if (idx in [1..5]) then
  224. begin
  225. for i:=1 to idx do
  226. begin
  227. case upcase(s[i]) of
  228. 'F' : begin
  229. v:=v or V_Fatal;
  230. dostop:=true;
  231. end;
  232. 'E' : begin
  233. v:=v or V_Error;
  234. inc(status.errorcount);
  235. end;
  236. 'O' : v:=v or V_Normal;
  237. 'W' : v:=v or V_Warning;
  238. 'N' : v:=v or V_Note;
  239. 'H' : v:=v or V_Hint;
  240. 'I' : v:=v or V_Info;
  241. 'L' : v:=v or V_Status;
  242. 'U' : v:=v or V_Used;
  243. 'T' : v:=v or V_Tried;
  244. 'M' : v:=v or V_Macro;
  245. 'P' : v:=v or V_Procedure;
  246. 'C' : v:=v or V_Conditional;
  247. 'D' : v:=v or V_Debug;
  248. 'S' : dostop:=true;
  249. '_' : ;
  250. end;
  251. end;
  252. end;
  253. Delete(s,1,idx);
  254. Replace(s,'$VER',version_string);
  255. Replace(s,'$TARGET',target_string);
  256. { fix status }
  257. {$ifdef NEWINPUT}
  258. status.currentline:=aktfilepos.line;
  259. status.currentcolumn:=aktfilepos.column;
  260. {$endif}
  261. { show comment }
  262. if do_comment(v,s) or dostop or (status.errorcount>=maxerrorcount) then
  263. stop;
  264. end;
  265. procedure Message(w:tmsgconst);
  266. begin
  267. Msg2Comment(msg^.Get(ord(w)));
  268. end;
  269. procedure Message1(w:tmsgconst;const s1:string);
  270. begin
  271. Msg2Comment(msg^.Get1(ord(w),s1));
  272. end;
  273. procedure Message2(w:tmsgconst;const s1,s2:string);
  274. begin
  275. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  276. end;
  277. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  278. begin
  279. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  280. end;
  281. begin
  282. {$IFNDEF EXTERN_MSG}
  283. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  284. {$ENDIF}
  285. end.
  286. {
  287. $Log$
  288. Revision 1.9 1998-07-07 11:20:20 peter
  289. + NEWINPUT for a better inputfile and scanner object
  290. Revision 1.8 1998/05/23 01:21:35 peter
  291. + aktasmmode, aktoptprocessor, aktoutputformat
  292. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  293. + $LIBNAME to set the library name where the unit will be put in
  294. * splitted cgi386 a bit (codeseg to large for bp7)
  295. * nasm, tasm works again. nasm moved to ag386nsm.pas
  296. Revision 1.7 1998/05/21 19:33:40 peter
  297. + better procedure directive handling and only one table
  298. Revision 1.6 1998/05/12 10:47:01 peter
  299. * moved printstatus to verb_def
  300. + V_Normal which is between V_Error and V_Warning and doesn't have a
  301. prefix like error: warning: and is included in V_Default
  302. * fixed some messages
  303. * first time parameter scan is only for -v and -T
  304. - removed old style messages
  305. Revision 1.5 1998/04/30 15:59:43 pierre
  306. * GDB works again better :
  307. correct type info in one pass
  308. + UseTokenInfo for better source position
  309. * fixed one remaining bug in scanner for line counts
  310. * several little fixes
  311. Revision 1.4 1998/04/23 12:11:22 peter
  312. * fixed -v0 to displayV_Default (=errors+fatals)
  313. Revision 1.3 1998/04/13 21:15:42 florian
  314. * error handling of pass_1 and cgi386 fixed
  315. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  316. fixed, verified
  317. }