verbose.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. currentsource : string; { filename }
  48. currentline : longint; { current line number }
  49. totalcompiledlines : longint; { the number of lines which are compiled }
  50. totallines : longint; { total lines to compile, can be 0 }
  51. end;
  52. var
  53. status : tcompilestatus;
  54. errorcount : longint; { number of generated errors }
  55. msg : pmessage;
  56. UseStdErr,
  57. Use_Rhide : boolean;
  58. procedure LoadMsgFile(const fn:string);
  59. function SetVerbosity(const s:string):boolean;
  60. procedure stop;
  61. procedure comment(l:longint;const s:string);
  62. procedure internalerror(i:longint);
  63. procedure Message(w:tmsgconst);
  64. procedure Message1(w:tmsgconst;const s1:string);
  65. procedure Message2(w:tmsgconst;const s1,s2:string);
  66. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  67. { Function redirecting for IDE support }
  68. type
  69. tstopprocedure = procedure;
  70. tcommentprocedure = procedure(Level:Longint;const s:string);
  71. {old handlers }
  72. terrorfunction = function(w:tmsgconst) : boolean;
  73. tinternalerrorfunction = function(i : longint) : boolean;
  74. var
  75. { this procedure is called to stop the compiler }
  76. { e.g. this procedure has to restore the state before compiling }
  77. do_stop : tstopprocedure;
  78. { called when writing something to the screen, called with the level }
  79. { of the comment }
  80. do_comment : tcommentprocedure;
  81. { only for compatibility }
  82. do_note,do_warning,do_error,do_fatalerror : terrorfunction;
  83. do_internalerror : tinternalerrorfunction;
  84. implementation
  85. uses globals;
  86. procedure LoadMsgFile(const fn:string);
  87. begin
  88. if not (msg=nil) then
  89. dispose(msg,Done);
  90. msg:=new(pmessage,InitExtern(fn,ord(endmsgconst)));
  91. end;
  92. function SetVerbosity(const s:string):boolean;
  93. var
  94. m : Longint;
  95. i : Word;
  96. inverse : boolean;
  97. c : char;
  98. begin
  99. setverbosity:=false;
  100. val(s,m,i);
  101. if (i=0) and (s<>'') then
  102. verbosity:=m
  103. else
  104. begin
  105. for i:=1 to length(s) do
  106. begin
  107. c:=s[i];
  108. if (i<length(s)) and (s[i+1]='-') then
  109. begin
  110. inc(i);
  111. inverse:=true;
  112. end
  113. else
  114. inverse:=false;
  115. case upcase(s[i]) of
  116. { Special cases }
  117. 'A' : Verbosity:=V_All;
  118. '0' : Verbosity:=V_Default;
  119. 'R' : begin
  120. if inverse then
  121. begin
  122. Use_rhide:=false;
  123. UseStdErr:=false;
  124. end
  125. else
  126. begin
  127. Use_rhide:=true;
  128. UseStdErr:=true;
  129. end;
  130. end;
  131. { Normal cases - do an or }
  132. 'E' : if inverse then
  133. Verbosity:=Verbosity and (not V_Error)
  134. else
  135. Verbosity:=Verbosity or V_Error;
  136. 'I' : if inverse then
  137. Verbosity:=Verbosity and (not V_Info)
  138. else
  139. Verbosity:=Verbosity or V_Info;
  140. 'W' : if inverse then
  141. Verbosity:=Verbosity and (not V_Warning)
  142. else
  143. Verbosity:=Verbosity or V_Warning;
  144. 'N' : if inverse then
  145. Verbosity:=Verbosity and (not V_Note)
  146. else
  147. Verbosity:=Verbosity or V_Note;
  148. 'H' : if inverse then
  149. Verbosity:=Verbosity and (not V_Hint)
  150. else
  151. Verbosity:=Verbosity or V_Hint;
  152. 'L' : if inverse then
  153. Verbosity:=Verbosity and (not V_Status)
  154. else
  155. Verbosity:=Verbosity or V_Status;
  156. 'U' : if inverse then
  157. Verbosity:=Verbosity and (not V_Used)
  158. else
  159. Verbosity:=Verbosity or V_Used;
  160. 'T' : if inverse then
  161. Verbosity:=Verbosity and (not V_Tried)
  162. else
  163. Verbosity:=Verbosity or V_Tried;
  164. 'M' : if inverse then
  165. Verbosity:=Verbosity and (not V_Macro)
  166. else
  167. Verbosity:=Verbosity or V_Macro;
  168. 'P' : if inverse then
  169. Verbosity:=Verbosity and (not V_Procedure)
  170. else
  171. Verbosity:=Verbosity or V_Procedure;
  172. 'C' : if inverse then
  173. Verbosity:=Verbosity and (not V_Conditional)
  174. else
  175. Verbosity:=Verbosity or V_Conditional;
  176. 'D' : if inverse then
  177. Verbosity:=Verbosity and (not V_Debug)
  178. else
  179. Verbosity:=Verbosity or V_Debug;
  180. end;
  181. end;
  182. end;
  183. if Verbosity=0 then
  184. Verbosity:=V_Default;
  185. setverbosity:=true;
  186. end;
  187. procedure stop;
  188. begin
  189. {$ifndef TP}
  190. do_stop();
  191. {$else}
  192. do_stop;
  193. {$endif}
  194. end;
  195. procedure internalerror(i : longint);
  196. begin
  197. do_internalerror(i);
  198. stop;
  199. end;
  200. procedure Comment(l:longint;const s:string);
  201. var
  202. msg : string;
  203. begin
  204. msg:=s;
  205. Replace(msg,'$VER',version_string);
  206. Replace(msg,'$TARGET',target_string);
  207. do_comment(l,msg);
  208. end;
  209. Procedure Msg2Comment(s:string);
  210. var
  211. idx,i,v : longint;
  212. dostop : boolean;
  213. begin
  214. {Reset}
  215. dostop:=false;
  216. v:=0;
  217. {Parse options}
  218. idx:=pos('_',s);
  219. if idx=0 then
  220. v:=V_Default
  221. else
  222. if (idx in [1..5]) then
  223. begin
  224. for i:=1 to idx do
  225. begin
  226. case upcase(s[i]) of
  227. 'F' : begin
  228. v:=v or V_Fatal;
  229. dostop:=true;
  230. end;
  231. 'E' : begin
  232. v:=v or V_Error;
  233. inc(errorcount);
  234. dostop:=(errorcount>=maxerrorcount);
  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. Comment(v,s);
  255. if dostop then
  256. stop;
  257. end;
  258. procedure Message(w:tmsgconst);
  259. begin
  260. Msg2Comment(msg^.Get(ord(w)));
  261. end;
  262. procedure Message1(w:tmsgconst;const s1:string);
  263. begin
  264. Msg2Comment(msg^.Get1(ord(w),s1));
  265. end;
  266. procedure Message2(w:tmsgconst;const s1,s2:string);
  267. begin
  268. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  269. end;
  270. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  271. begin
  272. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  273. end;
  274. begin
  275. {$IFNDEF EXTERN_MSG}
  276. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  277. {$ENDIF}
  278. end.
  279. {
  280. $Log$
  281. Revision 1.6 1998-05-12 10:47:01 peter
  282. * moved printstatus to verb_def
  283. + V_Normal which is between V_Error and V_Warning and doesn't have a
  284. prefix like error: warning: and is included in V_Default
  285. * fixed some messages
  286. * first time parameter scan is only for -v and -T
  287. - removed old style messages
  288. Revision 1.5 1998/04/30 15:59:43 pierre
  289. * GDB works again better :
  290. correct type info in one pass
  291. + UseTokenInfo for better source position
  292. * fixed one remaining bug in scanner for line counts
  293. * several little fixes
  294. Revision 1.4 1998/04/23 12:11:22 peter
  295. * fixed -v0 to displayV_Default (=errors+fatals)
  296. Revision 1.3 1998/04/13 21:15:42 florian
  297. * error handling of pass_1 and cgi386 fixed
  298. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  299. fixed, verified
  300. }