verbose.pas 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit handles the verbose management
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit verbose;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. {$IFNDEF USE_FAKE_SYSUTILS}
  22. sysutils,
  23. {$ELSE}
  24. fksysutl,
  25. {$ENDIF}
  26. cutils,
  27. globtype,finput,
  28. cmsgs;
  29. {$ifndef EXTERN_MSG}
  30. {$i msgtxt.inc}
  31. {$endif}
  32. {$i msgidx.inc}
  33. Const
  34. { Levels }
  35. V_None = $0;
  36. V_Fatal = $1;
  37. V_Error = $2;
  38. V_Normal = $4; { doesn't show a text like Error: }
  39. V_Warning = $8;
  40. V_Note = $10;
  41. V_Hint = $20;
  42. V_LineInfoMask = $fff;
  43. { From here by default no line info }
  44. V_Info = $1000;
  45. V_Status = $2000;
  46. V_Used = $4000;
  47. V_Tried = $8000;
  48. V_Conditional = $10000;
  49. V_Debug = $20000;
  50. V_Executable = $40000;
  51. V_LevelMask = $fffffff;
  52. V_All = V_LevelMask;
  53. V_Default = V_Fatal + V_Error + V_Normal;
  54. { Flags }
  55. V_LineInfo = $10000000;
  56. var
  57. msg : pmessage;
  58. paraprintnodetree : byte;
  59. type
  60. tmsgqueueevent = procedure(const s:TMsgStr;v,w:longint) of object;
  61. const
  62. msgfilename : string = '';
  63. procedure SetRedirectFile(const fn:string);
  64. function SetVerbosity(const s:string):boolean;
  65. procedure PrepareReport;
  66. function CheckVerbosity(v:longint):boolean;
  67. function SetMessageVerbosity(v:longint;state:tmsgstate):boolean;
  68. procedure RestoreLocalVerbosity(pstate : pmessagestaterecord);
  69. procedure FreeLocalVerbosity(var fstate : pmessagestaterecord);
  70. function ChangeMessageVerbosity(s: string; var i: integer;state:tmsgstate): boolean;
  71. procedure ShowStatus;
  72. function ErrorCount:longint;
  73. procedure SetErrorFlags(const s:string);
  74. procedure GenerateError;
  75. procedure Internalerror(i:longint);{$ifndef VER2_6}noreturn;{$endif VER2_6}
  76. procedure Comment(l:longint;s:ansistring);
  77. function MessageStr(w:longint):TMsgStr;
  78. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  79. procedure Message1(w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  80. procedure Message2(w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  81. procedure Message3(w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  82. procedure Message4(w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  83. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  84. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  85. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  86. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  87. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  88. { message calls with codegenerror support }
  89. procedure cgmessage(t : longint);
  90. procedure cgmessage1(t : longint;const s : TMsgStr);
  91. procedure cgmessage2(t : longint;const s1,s2 : TMsgStr);
  92. procedure cgmessage3(t : longint;const s1,s2,s3 : TMsgStr);
  93. procedure CGMessagePos(const pos:tfileposinfo;t:longint);
  94. procedure CGMessagePos1(const pos:tfileposinfo;t:longint;const s1:TMsgStr);
  95. procedure CGMessagePos2(const pos:tfileposinfo;t:longint;const s1,s2:TMsgStr);
  96. procedure CGMessagePos3(const pos:tfileposinfo;t:longint;const s1,s2,s3:TMsgStr);
  97. procedure FlushOutput;
  98. procedure InitVerbose;
  99. procedure DoneVerbose;
  100. implementation
  101. uses
  102. comphook,fmodule,constexp,globals,cfileutl,switches;
  103. {****************************************************************************
  104. Extra Handlers for default compiler
  105. ****************************************************************************}
  106. procedure DoneRedirectFile;
  107. begin
  108. if status.use_redir then
  109. begin
  110. close(status.redirfile);
  111. status.use_redir:=false;
  112. end;
  113. if status.use_bugreport then
  114. begin
  115. close(status.reportbugfile);
  116. status.use_bugreport:=false;
  117. end;
  118. end;
  119. procedure SetRedirectFile(const fn:string);
  120. begin
  121. { close old redirection file because FileRedirection is handled in both passes }
  122. if status.use_redir then
  123. close(status.redirfile);
  124. assign(status.redirfile,fn);
  125. {$push}{$I-}
  126. append(status.redirfile);
  127. if ioresult <> 0 then
  128. begin
  129. assign(status.redirfile,fn);
  130. rewrite(status.redirfile);
  131. end;
  132. {$pop}
  133. status.use_redir:=(ioresult=0);
  134. end;
  135. procedure PrepareReport;
  136. var
  137. fn : string;
  138. begin
  139. if status.use_bugreport then
  140. exit;
  141. fn:='fpcdebug.txt';
  142. assign(status.reportbugfile,fn);
  143. {$push}{$I-}
  144. append(status.reportbugfile);
  145. if ioresult <> 0 then
  146. rewrite(status.reportbugfile);
  147. {$pop}
  148. status.use_bugreport:=(ioresult=0);
  149. if status.use_bugreport then
  150. writeln(status.reportbugfile,'FPC bug report file');
  151. end;
  152. procedure RestoreLocalVerbosity(pstate : pmessagestaterecord);
  153. begin
  154. msg^.ResetStates;
  155. while assigned(pstate) do
  156. begin
  157. SetMessageVerbosity(pstate^.value,pstate^.state);
  158. pstate:=pstate^.next;
  159. end;
  160. end;
  161. procedure FreeLocalVerbosity(var fstate : pmessagestaterecord);
  162. var pstate : pmessagestaterecord;
  163. begin
  164. pstate:=unaligned(fstate);
  165. while assigned(pstate) do
  166. begin
  167. unaligned(fstate):=pstate^.next;
  168. freemem(pstate);
  169. pstate:=unaligned(fstate);
  170. end;
  171. end;
  172. function ChangeMessageVerbosity(s: string; var i : integer;state:tmsgstate): boolean;
  173. var
  174. tok : string;
  175. msgnr, code : longint;
  176. begin
  177. { delete everything up to and including 'm' }
  178. delete(s,1,i);
  179. { the rest of the string must be message numbers }
  180. inc(i,length(s)+1);
  181. result:=false;
  182. repeat
  183. tok:=GetToken(s,',');
  184. if (tok='') then
  185. break;
  186. val(tok, msgnr, code);
  187. if (code<>0) then
  188. exit;
  189. if not msg^.setverbosity(msgnr,state) then
  190. exit
  191. else
  192. recordpendingmessagestate(msgnr, state);
  193. until false;
  194. result:=true;
  195. end;
  196. function SetMessageVerbosity(v:longint;state:tmsgstate):boolean;
  197. begin
  198. result:=msg^.setverbosity(v,state);
  199. end;
  200. function CheckVerbosity(v:longint):boolean;
  201. begin
  202. result:=do_checkverbosity(v);
  203. end;
  204. function SetVerbosity(const s:string):boolean;
  205. const
  206. message_verbosity:array[boolean] of tmsgstate=(ms_off_global,ms_on_global);
  207. var
  208. m : Longint;
  209. i : Integer;
  210. inverse : boolean;
  211. c : char;
  212. begin
  213. Setverbosity:=false;
  214. val(s,m,i);
  215. if (i=0) and (s<>'') then
  216. status.verbosity:=m
  217. else
  218. begin
  219. i:=1;
  220. while i<=length(s) do
  221. begin
  222. c:=upcase(s[i]);
  223. inverse:=false;
  224. { on/off ? }
  225. if (i<length(s)) then
  226. case s[i+1] of
  227. '-' : begin
  228. inc(i);
  229. inverse:=true;
  230. end;
  231. '+' : inc(i);
  232. end;
  233. { handle switch }
  234. case c of
  235. { Special cases }
  236. '0' : status.verbosity:=V_Default;
  237. 'A' : status.verbosity:=V_All;
  238. 'B' : begin
  239. if inverse then
  240. status.print_source_path:=false
  241. else
  242. status.print_source_path:=true;
  243. end;
  244. 'M' : if not ChangeMessageVerbosity(s,i,message_verbosity[inverse]) then
  245. begin
  246. result:=false;
  247. exit
  248. end;
  249. 'P' : begin
  250. if inverse then
  251. paraprintnodetree:=0
  252. else
  253. paraprintnodetree:=1;
  254. end;
  255. 'Q' : begin
  256. if inverse then
  257. status.showmsgnrs:=false
  258. else
  259. status.showmsgnrs:=true;
  260. end;
  261. 'R' : begin
  262. if inverse then
  263. begin
  264. status.use_gccoutput:=false;
  265. status.use_stderr:=false;
  266. end
  267. else
  268. begin
  269. status.use_gccoutput:=true;
  270. status.use_stderr:=true;
  271. end;
  272. end;
  273. 'V' : PrepareReport;
  274. 'Z' : begin
  275. if inverse then
  276. status.use_stderr:=false
  277. else
  278. status.use_stderr:=true;
  279. end;
  280. { Normal cases - do an or }
  281. 'C' : if inverse then
  282. status.verbosity:=status.verbosity and (not V_Conditional)
  283. else
  284. status.verbosity:=status.verbosity or V_Conditional;
  285. 'D' : if inverse then
  286. status.verbosity:=status.verbosity and (not V_Debug)
  287. else
  288. status.verbosity:=status.verbosity or V_Debug;
  289. 'E' : if inverse then
  290. status.verbosity:=status.verbosity and (not V_Error)
  291. else
  292. status.verbosity:=status.verbosity or V_Error;
  293. 'H' : if inverse then
  294. status.verbosity:=status.verbosity and (not V_Hint)
  295. else
  296. status.verbosity:=status.verbosity or V_Hint;
  297. 'I' : if inverse then
  298. status.verbosity:=status.verbosity and (not V_Info)
  299. else
  300. status.verbosity:=status.verbosity or V_Info;
  301. 'L' : if inverse then
  302. status.verbosity:=status.verbosity and (not V_Status)
  303. else
  304. status.verbosity:=status.verbosity or V_Status;
  305. 'N' : if inverse then
  306. status.verbosity:=status.verbosity and (not V_Note)
  307. else
  308. status.verbosity:=status.verbosity or V_Note;
  309. 'S' : if inverse then
  310. status.verbosity:=status.verbosity and (not V_TimeStamps)
  311. else
  312. status.verbosity:=status.verbosity or V_TimeStamps;
  313. 'T' : if inverse then
  314. status.verbosity:=status.verbosity and (not V_Tried)
  315. else
  316. status.verbosity:=status.verbosity or V_Tried;
  317. 'U' : if inverse then
  318. status.verbosity:=status.verbosity and (not V_Used)
  319. else
  320. status.verbosity:=status.verbosity or V_Used;
  321. 'W' : if inverse then
  322. status.verbosity:=status.verbosity and (not V_Warning)
  323. else
  324. status.verbosity:=status.verbosity or V_Warning;
  325. 'X' : if inverse then
  326. status.verbosity:=status.verbosity and (not V_Executable)
  327. else
  328. status.verbosity:=status.verbosity or V_Executable;
  329. end;
  330. inc(i);
  331. end;
  332. end;
  333. if status.verbosity=0 then
  334. status.verbosity:=V_Default;
  335. setverbosity:=true;
  336. end;
  337. procedure Loadprefixes;
  338. function loadprefix(w:longint):string;
  339. var
  340. s : string;
  341. idx : longint;
  342. begin
  343. s:=msg^.get(w,[]);
  344. idx:=pos('_',s);
  345. if idx>0 then
  346. Loadprefix:=Copy(s,idx+1,255)
  347. else
  348. Loadprefix:=s;
  349. end;
  350. begin
  351. { Load the prefixes }
  352. fatalstr:=Loadprefix(general_i_fatal);
  353. errorstr:=Loadprefix(general_i_error);
  354. warningstr:=Loadprefix(general_i_warning);
  355. notestr:=Loadprefix(general_i_note);
  356. hintstr:=Loadprefix(general_i_hint);
  357. end;
  358. procedure LoadMsgFile(const fn:string);
  359. begin
  360. { reload the internal messages if not already loaded }
  361. {$ifndef EXTERN_MSG}
  362. if not msg^.msgintern then
  363. msg^.LoadIntern(@msgtxt,msgtxtsize,msgtxt_codepage);
  364. {$endif}
  365. if not msg^.LoadExtern(fn) then
  366. begin
  367. {$ifdef EXTERN_MSG}
  368. writeln('Fatal: Cannot find error message file.');
  369. halt(3);
  370. {$else}
  371. msg^.LoadIntern(@msgtxt,msgtxtsize,msgtxt_codepage);
  372. {$endif}
  373. end;
  374. { reload the prefixes using the new messages }
  375. Loadprefixes;
  376. end;
  377. procedure MaybeLoadMessageFile;
  378. begin
  379. { Load new message file }
  380. if (msgfilename<>'') then
  381. begin
  382. LoadMsgFile(msgfilename);
  383. msgfilename:='';
  384. end;
  385. end;
  386. var
  387. lastfileidx,
  388. lastmoduleidx : longint;
  389. Procedure UpdateStatus;
  390. var
  391. module : tmodule;
  392. begin
  393. { fix status }
  394. status.currentline:=current_filepos.line;
  395. status.currentcolumn:=current_filepos.column;
  396. if (current_filepos.moduleindex <> lastmoduleidx) or
  397. (current_filepos.fileindex <> lastfileidx) then
  398. begin
  399. module:=get_module(current_filepos.moduleindex);
  400. if assigned(module) and assigned(module.sourcefiles) then
  401. begin
  402. { update status record }
  403. status.currentmodule:=module.modulename^;
  404. status.currentsourceppufilename:=module.ppufilename;
  405. status.currentmodulestate:=ModuleStateStr[module.state];
  406. status.currentsource:=module.sourcefiles.get_file_name(current_filepos.fileindex);
  407. status.currentsourcepath:=module.sourcefiles.get_file_path(current_filepos.fileindex);
  408. status.sources_avail:=module.sources_avail;
  409. { if currentsourcepath is relative, make it absolute }
  410. if not path_absolute(status.currentsourcepath) then
  411. status.currentsourcepath:=GetCurrentDir+status.currentsourcepath;
  412. { update lastfileidx only if name known PM }
  413. if status.currentsource<>'' then
  414. lastfileidx:=current_filepos.fileindex
  415. else
  416. lastfileidx:=0;
  417. lastmoduleidx:=module.unit_index;
  418. end;
  419. end;
  420. end;
  421. procedure ShowStatus;
  422. begin
  423. UpdateStatus;
  424. if do_status() then
  425. raise ECompilerAbort.Create;
  426. end;
  427. function ErrorCount:longint;
  428. begin
  429. ErrorCount:=status.errorcount;
  430. end;
  431. procedure SetErrorFlags(const s:string);
  432. var
  433. code : integer;
  434. i,j,l : longint;
  435. begin
  436. { empty string means error count = 1 for backward compatibility (PFV) }
  437. if s='' then
  438. begin
  439. status.maxerrorcount:=1;
  440. exit;
  441. end;
  442. i:=0;
  443. while (i<length(s)) do
  444. begin
  445. inc(i);
  446. case s[i] of
  447. '0'..'9' :
  448. begin
  449. j:=i;
  450. while (j<=length(s)) and (s[j] in ['0'..'9']) do
  451. inc(j);
  452. val(copy(s,i,j-i),l,code);
  453. if code<>0 then
  454. l:=1;
  455. status.maxerrorcount:=l;
  456. i:=j-1;
  457. end;
  458. 'w','W' :
  459. begin
  460. if (i<length(s)) and (s[i+1]='-') then
  461. begin
  462. inc(i);
  463. status.errorwarning:=false;
  464. end
  465. else
  466. begin
  467. status.errorwarning:=true;
  468. { Enable writing of warnings, to avoid getting errors without any message }
  469. status.verbosity:=status.verbosity or V_Warning;
  470. end;
  471. end;
  472. 'n','N' :
  473. begin
  474. if (i<length(s)) and (s[i+1]='-') then
  475. begin
  476. inc(i);
  477. status.errornote:=false;
  478. end
  479. else
  480. begin
  481. status.errornote:=true;
  482. { Enable writing of notes, to avoid getting errors without any message }
  483. status.verbosity:=status.verbosity or V_Note;
  484. end;
  485. end;
  486. 'h','H' :
  487. begin
  488. if (i<length(s)) and (s[i+1]='-') then
  489. begin
  490. inc(i);
  491. status.errorhint:=false;
  492. end
  493. else
  494. begin
  495. status.errorhint:=true;
  496. { Enable writing of hints, to avoid getting errors without any message }
  497. status.verbosity:=status.verbosity or V_Hint;
  498. end;
  499. end;
  500. end;
  501. end;
  502. end;
  503. procedure GenerateError;
  504. begin
  505. inc(status.errorcount);
  506. end;
  507. procedure internalerror(i : longint);{$ifndef VER2_6}noreturn;{$endif VER2_6}
  508. begin
  509. UpdateStatus;
  510. do_internalerror(i);
  511. GenerateError;
  512. raise ECompilerAbort.Create;
  513. end;
  514. procedure Comment(l:longint;s:ansistring);
  515. var
  516. dostop : boolean;
  517. begin
  518. dostop:=((l and V_Fatal)<>0);
  519. if ((l and V_Error)<>0) or
  520. ((l and V_Fatal)<>0) or
  521. (status.errorwarning and ((l and V_Warning)<>0)) or
  522. (status.errornote and ((l and V_Note)<>0)) or
  523. (status.errorhint and ((l and V_Hint)<>0)) then
  524. GenerateError
  525. else
  526. if l and V_Warning <> 0 then
  527. inc(status.countWarnings)
  528. else
  529. if l and V_Note <> 0 then
  530. inc(status.countNotes)
  531. else
  532. if l and V_Hint <> 0 then
  533. inc(status.countHints);
  534. { check verbosity level }
  535. if not CheckVerbosity(l) then
  536. exit;
  537. if (l and V_LineInfoMask)<>0 then
  538. l:=l or V_LineInfo;
  539. { Create status info }
  540. UpdateStatus;
  541. { Fix replacements }
  542. DefaultReplacements(s);
  543. { show comment }
  544. if do_comment(l,s) or dostop then
  545. raise ECompilerAbort.Create;
  546. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  547. begin
  548. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  549. status.skip_error:=true;
  550. raise ECompilerAbort.Create;
  551. end;
  552. end;
  553. function GetMessageState(m:longint):tmsgstate;
  554. var
  555. i: integer;
  556. begin
  557. i:=m div 1000;
  558. { get the default state }
  559. Result:=msg^.msgstates[i]^[m mod 1000];
  560. { and search at the current unit settings }
  561. { todo }
  562. end;
  563. Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
  564. var
  565. idx,i,v : longint;
  566. dostop : boolean;
  567. doqueue : boolean;
  568. st : tmsgstate;
  569. ch : char;
  570. begin
  571. {Reset}
  572. dostop:=false;
  573. doqueue:=false;
  574. v:=0;
  575. {Parse options}
  576. idx:=pos('_',s);
  577. if idx=0 then
  578. v:=V_None
  579. else
  580. if (idx >= 1) And (idx <= 5) then
  581. begin
  582. for i:=1 to idx do
  583. begin
  584. ch:=upcase(s[i]);
  585. case ch of
  586. 'F' :
  587. begin
  588. v:=v or V_Fatal;
  589. GenerateError;
  590. dostop:=true;
  591. end;
  592. 'E','W','N','H':
  593. begin
  594. if ch='E' then
  595. st:=ms_error
  596. else
  597. st:=GetMessageState(w);
  598. { We only want to know about local value }
  599. st:= tmsgstate(ord(st) and ms_local_mask);
  600. if st=ms_error then
  601. begin
  602. v:=v or V_Error;
  603. GenerateError;
  604. end
  605. else if st<>ms_off then
  606. case ch of
  607. 'W':
  608. begin
  609. v:=v or V_Warning;
  610. if CheckVerbosity(V_Warning) then
  611. if status.errorwarning then
  612. GenerateError
  613. else
  614. inc(status.countWarnings);
  615. end;
  616. 'N' :
  617. begin
  618. v:=v or V_Note;
  619. if CheckVerbosity(V_Note) then
  620. if status.errornote then
  621. GenerateError
  622. else
  623. inc(status.countNotes);
  624. end;
  625. 'H' :
  626. begin
  627. v:=v or V_Hint;
  628. if CheckVerbosity(V_Hint) then
  629. if status.errorhint then
  630. GenerateError
  631. else
  632. inc(status.countHints);
  633. end;
  634. end;
  635. end;
  636. 'O' :
  637. v:=v or V_Normal;
  638. 'I' :
  639. v:=v or V_Info;
  640. 'L' :
  641. v:=v or V_LineInfo;
  642. 'U' :
  643. v:=v or V_Used;
  644. 'T' :
  645. v:=v or V_Tried;
  646. 'C' :
  647. v:=v or V_Conditional;
  648. 'D' :
  649. v:=v or V_Debug;
  650. 'X' :
  651. v:=v or V_Executable;
  652. 'S' :
  653. dostop:=true;
  654. '_' : ;
  655. end;
  656. end;
  657. end;
  658. Delete(s,1,idx);
  659. { check verbosity level }
  660. if not CheckVerbosity(v) then
  661. begin
  662. doqueue := onqueue <> nil;
  663. if not doqueue then
  664. exit;
  665. end;
  666. if (v and V_LineInfoMask)<>0 then
  667. v:=v or V_LineInfo;
  668. { fix status }
  669. UpdateStatus;
  670. { Fix replacements }
  671. DefaultReplacements(s);
  672. if status.showmsgnrs then
  673. s:='('+tostr(w)+') '+s;
  674. if doqueue then
  675. begin
  676. onqueue(s,v,w);
  677. exit;
  678. end;
  679. { show comment }
  680. if do_comment(v,s) or dostop then
  681. raise ECompilerAbort.Create;
  682. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  683. begin
  684. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  685. status.skip_error:=true;
  686. raise ECompilerAbort.Create;
  687. end;
  688. end;
  689. function MessageStr(w:longint):TMsgStr;
  690. begin
  691. MaybeLoadMessageFile;
  692. MessageStr:=msg^.Get(w,[]);
  693. end;
  694. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  695. begin
  696. MaybeLoadMessageFile;
  697. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  698. end;
  699. procedure Message1(w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  700. begin
  701. MaybeLoadMessageFile;
  702. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  703. end;
  704. procedure Message2(w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  705. begin
  706. MaybeLoadMessageFile;
  707. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  708. end;
  709. procedure Message3(w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  710. begin
  711. MaybeLoadMessageFile;
  712. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  713. end;
  714. procedure Message4(w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  715. begin
  716. MaybeLoadMessageFile;
  717. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  718. end;
  719. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  720. var
  721. oldpos : tfileposinfo;
  722. begin
  723. oldpos:=current_filepos;
  724. current_filepos:=pos;
  725. MaybeLoadMessageFile;
  726. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  727. current_filepos:=oldpos;
  728. end;
  729. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  730. var
  731. oldpos : tfileposinfo;
  732. begin
  733. oldpos:=current_filepos;
  734. current_filepos:=pos;
  735. MaybeLoadMessageFile;
  736. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  737. current_filepos:=oldpos;
  738. end;
  739. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  740. var
  741. oldpos : tfileposinfo;
  742. begin
  743. oldpos:=current_filepos;
  744. current_filepos:=pos;
  745. MaybeLoadMessageFile;
  746. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  747. current_filepos:=oldpos;
  748. end;
  749. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  750. var
  751. oldpos : tfileposinfo;
  752. begin
  753. oldpos:=current_filepos;
  754. current_filepos:=pos;
  755. MaybeLoadMessageFile;
  756. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  757. current_filepos:=oldpos;
  758. end;
  759. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  760. var
  761. oldpos : tfileposinfo;
  762. begin
  763. oldpos:=current_filepos;
  764. current_filepos:=pos;
  765. MaybeLoadMessageFile;
  766. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  767. current_filepos:=oldpos;
  768. end;
  769. {*****************************************************************************
  770. override the message calls to set codegenerror
  771. *****************************************************************************}
  772. procedure cgmessage(t : longint);
  773. var
  774. olderrorcount : longint;
  775. begin
  776. if not(codegenerror) then
  777. begin
  778. olderrorcount:=Errorcount;
  779. verbose.Message(t);
  780. codegenerror:=olderrorcount<>Errorcount;
  781. end;
  782. end;
  783. procedure cgmessage1(t : longint;const s : TMsgStr);
  784. var
  785. olderrorcount : longint;
  786. begin
  787. if not(codegenerror) then
  788. begin
  789. olderrorcount:=Errorcount;
  790. verbose.Message1(t,s);
  791. codegenerror:=olderrorcount<>Errorcount;
  792. end;
  793. end;
  794. procedure cgmessage2(t : longint;const s1,s2 : TMsgStr);
  795. var
  796. olderrorcount : longint;
  797. begin
  798. if not(codegenerror) then
  799. begin
  800. olderrorcount:=Errorcount;
  801. verbose.Message2(t,s1,s2);
  802. codegenerror:=olderrorcount<>Errorcount;
  803. end;
  804. end;
  805. procedure cgmessage3(t : longint;const s1,s2,s3 : TMsgStr);
  806. var
  807. olderrorcount : longint;
  808. begin
  809. if not(codegenerror) then
  810. begin
  811. olderrorcount:=Errorcount;
  812. verbose.Message3(t,s1,s2,s3);
  813. codegenerror:=olderrorcount<>Errorcount;
  814. end;
  815. end;
  816. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  817. var
  818. olderrorcount : longint;
  819. begin
  820. if not(codegenerror) then
  821. begin
  822. olderrorcount:=Errorcount;
  823. verbose.MessagePos(pos,t);
  824. codegenerror:=olderrorcount<>Errorcount;
  825. end;
  826. end;
  827. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : TMsgStr);
  828. var
  829. olderrorcount : longint;
  830. begin
  831. if not(codegenerror) then
  832. begin
  833. olderrorcount:=Errorcount;
  834. verbose.MessagePos1(pos,t,s1);
  835. codegenerror:=olderrorcount<>Errorcount;
  836. end;
  837. end;
  838. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : TMsgStr);
  839. var
  840. olderrorcount : longint;
  841. begin
  842. if not(codegenerror) then
  843. begin
  844. olderrorcount:=Errorcount;
  845. verbose.MessagePos2(pos,t,s1,s2);
  846. codegenerror:=olderrorcount<>Errorcount;
  847. end;
  848. end;
  849. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : TMsgStr);
  850. var
  851. olderrorcount : longint;
  852. begin
  853. if not(codegenerror) then
  854. begin
  855. olderrorcount:=Errorcount;
  856. verbose.MessagePos3(pos,t,s1,s2,s3);
  857. codegenerror:=olderrorcount<>Errorcount;
  858. end;
  859. end;
  860. procedure FlushOutput;
  861. begin
  862. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  863. begin
  864. if Status.Use_Redir then
  865. Flush(Status.RedirFile)
  866. else
  867. Flush(Output);
  868. end;
  869. end;
  870. {*****************************************************************************
  871. Initialization
  872. *****************************************************************************}
  873. procedure InitVerbose;
  874. begin
  875. { Init }
  876. msg:=new(pmessage,Init(20,msgidxmax));
  877. if msg=nil then
  878. begin
  879. writeln('Fatal: MsgIdx Wrong');
  880. halt(3);
  881. end;
  882. {$ifndef EXTERN_MSG}
  883. msg^.LoadIntern(@msgtxt,msgtxtsize,msgtxt_codepage);
  884. {$else EXTERN_MSG}
  885. LoadMsgFile(exepath+'errore.msg');
  886. {$endif EXTERN_MSG}
  887. FillChar(Status,sizeof(TCompilerStatus),0);
  888. status.verbosity:=V_Default;
  889. Status.MaxErrorCount:=50;
  890. Status.codesize:=aword(-1);
  891. Status.datasize:=aword(-1);
  892. Loadprefixes;
  893. lastfileidx:=-1;
  894. lastmoduleidx:=-1;
  895. status.currentmodule:='';
  896. status.currentsourceppufilename:='';
  897. status.currentsource:='';
  898. status.currentsourcepath:='';
  899. { Register internalerrorproc for cutils/cclasses }
  900. internalerrorproc:=@internalerror;
  901. end;
  902. procedure DoneVerbose;
  903. begin
  904. if assigned(msg) then
  905. begin
  906. dispose(msg,Done);
  907. msg:=nil;
  908. end;
  909. DoneRedirectFile;
  910. end;
  911. initialization
  912. constexp.internalerrorproc:=@internalerror;
  913. finalization
  914. { Be sure to close the redirect files to flush all data }
  915. DoneRedirectFile;
  916. end.