verbose.pas 9.2 KB

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