verbose.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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(s:string;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. procedure ShowStatus;
  68. function ErrorCount:longint;
  69. procedure SetErrorFlags(const s:string);
  70. procedure GenerateError;
  71. procedure Internalerror(i:longint);
  72. procedure Comment(l:longint;s:ansistring);
  73. function MessagePchar(w:longint):pchar;
  74. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  75. procedure Message1(w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  76. procedure Message2(w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  77. procedure Message3(w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  78. procedure Message4(w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  79. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  80. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  81. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  82. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  83. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  84. { message calls with codegenerror support }
  85. procedure cgmessage(t : longint);
  86. procedure cgmessage1(t : longint;const s : string);
  87. procedure cgmessage2(t : longint;const s1,s2 : string);
  88. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  89. procedure CGMessagePos(const pos:tfileposinfo;t:longint);
  90. procedure CGMessagePos1(const pos:tfileposinfo;t:longint;const s1:string);
  91. procedure CGMessagePos2(const pos:tfileposinfo;t:longint;const s1,s2:string);
  92. procedure CGMessagePos3(const pos:tfileposinfo;t:longint;const s1,s2,s3:string);
  93. procedure FlushOutput;
  94. procedure InitVerbose;
  95. procedure DoneVerbose;
  96. implementation
  97. uses
  98. comphook,fmodule,constexp,globals;
  99. {****************************************************************************
  100. Extra Handlers for default compiler
  101. ****************************************************************************}
  102. procedure DoneRedirectFile;
  103. begin
  104. if status.use_redir then
  105. begin
  106. close(status.redirfile);
  107. status.use_redir:=false;
  108. end;
  109. if status.use_bugreport then
  110. begin
  111. close(status.reportbugfile);
  112. status.use_bugreport:=false;
  113. end;
  114. end;
  115. procedure SetRedirectFile(const fn:string);
  116. begin
  117. { close old redirection file because FileRedirection is handled in both passes }
  118. if status.use_redir then
  119. close(status.redirfile);
  120. assign(status.redirfile,fn);
  121. {$I-}
  122. append(status.redirfile);
  123. if ioresult <> 0 then
  124. begin
  125. assign(status.redirfile,fn);
  126. rewrite(status.redirfile);
  127. end;
  128. {$I+}
  129. status.use_redir:=(ioresult=0);
  130. end;
  131. procedure PrepareReport;
  132. var
  133. fn : string;
  134. begin
  135. if status.use_bugreport then
  136. exit;
  137. fn:='fpcdebug.txt';
  138. assign(status.reportbugfile,fn);
  139. {$I-}
  140. append(status.reportbugfile);
  141. if ioresult <> 0 then
  142. rewrite(status.reportbugfile);
  143. {$I+}
  144. status.use_bugreport:=(ioresult=0);
  145. if status.use_bugreport then
  146. writeln(status.reportbugfile,'FPC bug report file');
  147. end;
  148. function CheckVerbosity(v:longint):boolean;
  149. begin
  150. CheckVerbosity:=status.use_bugreport or
  151. ((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
  152. end;
  153. function SetVerbosity(const s:string):boolean;
  154. var
  155. m : Longint;
  156. i : Integer;
  157. inverse : boolean;
  158. c : char;
  159. begin
  160. Setverbosity:=false;
  161. val(s,m,i);
  162. if (i=0) and (s<>'') then
  163. status.verbosity:=m
  164. else
  165. begin
  166. i:=1;
  167. while i<=length(s) do
  168. begin
  169. c:=upcase(s[i]);
  170. inverse:=false;
  171. { on/off ? }
  172. if (i<length(s)) then
  173. case s[i+1] of
  174. '-' : begin
  175. inc(i);
  176. inverse:=true;
  177. end;
  178. '+' : inc(i);
  179. end;
  180. { handle switch }
  181. case c of
  182. { Special cases }
  183. 'A' : status.verbosity:=V_All;
  184. 'B' : begin
  185. if inverse then
  186. status.print_source_path:=false
  187. else
  188. status.print_source_path:=true;
  189. end;
  190. '0' : status.verbosity:=V_Default;
  191. 'P' : begin
  192. if inverse then
  193. paraprintnodetree:=0
  194. else
  195. paraprintnodetree:=1;
  196. end;
  197. 'R' : begin
  198. if inverse then
  199. begin
  200. status.use_gccoutput:=false;
  201. status.use_stderr:=false;
  202. end
  203. else
  204. begin
  205. status.use_gccoutput:=true;
  206. status.use_stderr:=true;
  207. end;
  208. end;
  209. 'Z' : begin
  210. if inverse then
  211. status.use_stderr:=false
  212. else
  213. status.use_stderr:=true;
  214. end;
  215. { Normal cases - do an or }
  216. 'E' : if inverse then
  217. status.verbosity:=status.verbosity and (not V_Error)
  218. else
  219. status.verbosity:=status.verbosity or V_Error;
  220. 'I' : if inverse then
  221. status.verbosity:=status.verbosity and (not V_Info)
  222. else
  223. status.verbosity:=status.verbosity or V_Info;
  224. 'W' : if inverse then
  225. status.verbosity:=status.verbosity and (not V_Warning)
  226. else
  227. status.verbosity:=status.verbosity or V_Warning;
  228. 'N' : if inverse then
  229. status.verbosity:=status.verbosity and (not V_Note)
  230. else
  231. status.verbosity:=status.verbosity or V_Note;
  232. 'H' : if inverse then
  233. status.verbosity:=status.verbosity and (not V_Hint)
  234. else
  235. status.verbosity:=status.verbosity or V_Hint;
  236. 'L' : if inverse then
  237. status.verbosity:=status.verbosity and (not V_Status)
  238. else
  239. status.verbosity:=status.verbosity or V_Status;
  240. 'U' : if inverse then
  241. status.verbosity:=status.verbosity and (not V_Used)
  242. else
  243. status.verbosity:=status.verbosity or V_Used;
  244. 'T' : if inverse then
  245. status.verbosity:=status.verbosity and (not V_Tried)
  246. else
  247. status.verbosity:=status.verbosity or V_Tried;
  248. 'C' : if inverse then
  249. status.verbosity:=status.verbosity and (not V_Conditional)
  250. else
  251. status.verbosity:=status.verbosity or V_Conditional;
  252. 'D' : if inverse then
  253. status.verbosity:=status.verbosity and (not V_Debug)
  254. else
  255. status.verbosity:=status.verbosity or V_Debug;
  256. 'X' : if inverse then
  257. status.verbosity:=status.verbosity and (not V_Executable)
  258. else
  259. status.verbosity:=status.verbosity or V_Executable;
  260. 'S' : if inverse then
  261. status.verbosity:=status.verbosity and (not V_TimeStamps)
  262. else
  263. status.verbosity:=status.verbosity or V_TimeStamps;
  264. 'V' : PrepareReport;
  265. end;
  266. inc(i);
  267. end;
  268. end;
  269. if status.verbosity=0 then
  270. status.verbosity:=V_Default;
  271. setverbosity:=true;
  272. end;
  273. procedure Loadprefixes;
  274. function loadprefix(w:longint):string;
  275. var
  276. s : string;
  277. idx : longint;
  278. begin
  279. s:=msg^.get(w,[]);
  280. idx:=pos('_',s);
  281. if idx>0 then
  282. Loadprefix:=Copy(s,idx+1,255)
  283. else
  284. Loadprefix:=s;
  285. end;
  286. begin
  287. { Load the prefixes }
  288. fatalstr:=Loadprefix(general_i_fatal);
  289. errorstr:=Loadprefix(general_i_error);
  290. warningstr:=Loadprefix(general_i_warning);
  291. notestr:=Loadprefix(general_i_note);
  292. hintstr:=Loadprefix(general_i_hint);
  293. end;
  294. procedure LoadMsgFile(const fn:string);
  295. begin
  296. { reload the internal messages if not already loaded }
  297. {$ifndef EXTERN_MSG}
  298. if not msg^.msgintern then
  299. msg^.LoadIntern(@msgtxt,msgtxtsize);
  300. {$endif}
  301. if not msg^.LoadExtern(fn) then
  302. begin
  303. {$ifdef EXTERN_MSG}
  304. writeln('Fatal: Cannot find error message file.');
  305. halt(3);
  306. {$else}
  307. msg^.LoadIntern(@msgtxt,msgtxtsize);
  308. {$endif}
  309. end;
  310. { reload the prefixes using the new messages }
  311. Loadprefixes;
  312. end;
  313. procedure MaybeLoadMessageFile;
  314. begin
  315. { Load new message file }
  316. if (msgfilename<>'') then
  317. begin
  318. LoadMsgFile(msgfilename);
  319. msgfilename:='';
  320. end;
  321. end;
  322. var
  323. lastfileidx,
  324. lastmoduleidx : longint;
  325. Procedure UpdateStatus;
  326. var
  327. module : tmodulebase;
  328. begin
  329. { fix status }
  330. status.currentline:=current_filepos.line;
  331. status.currentcolumn:=current_filepos.column;
  332. module:=get_module(current_filepos.moduleindex);
  333. if assigned(module) and
  334. assigned(module.sourcefiles) and
  335. ((module.unit_index<>lastmoduleidx) or
  336. (current_filepos.fileindex<>lastfileidx)) then
  337. begin
  338. { update status record }
  339. status.currentmodule:=module.modulename^;
  340. status.currentmodulestate:=ModuleStateStr[module.state];
  341. status.currentsource:=module.sourcefiles.get_file_name(current_filepos.fileindex);
  342. status.currentsourcepath:=module.sourcefiles.get_file_path(current_filepos.fileindex);
  343. { update lastfileidx only if name known PM }
  344. if status.currentsource<>'' then
  345. lastfileidx:=current_filepos.fileindex
  346. else
  347. lastfileidx:=0;
  348. lastmoduleidx:=module.unit_index;
  349. end;
  350. end;
  351. procedure ShowStatus;
  352. begin
  353. UpdateStatus;
  354. if do_status() then
  355. raise ECompilerAbort.Create;
  356. end;
  357. function ErrorCount:longint;
  358. begin
  359. ErrorCount:=status.errorcount;
  360. end;
  361. procedure SetErrorFlags(const s:string);
  362. var
  363. code : integer;
  364. i,j,l : longint;
  365. begin
  366. { empty string means error count = 1 for backward compatibility (PFV) }
  367. if s='' then
  368. begin
  369. status.maxerrorcount:=1;
  370. exit;
  371. end;
  372. i:=0;
  373. while (i<length(s)) do
  374. begin
  375. inc(i);
  376. case s[i] of
  377. '0'..'9' :
  378. begin
  379. j:=i;
  380. while (j<=length(s)) and (s[j] in ['0'..'9']) do
  381. inc(j);
  382. val(copy(s,i,j-i),l,code);
  383. if code<>0 then
  384. l:=1;
  385. status.maxerrorcount:=l;
  386. i:=j;
  387. end;
  388. 'w','W' :
  389. status.errorwarning:=true;
  390. 'n','N' :
  391. status.errornote:=true;
  392. 'h','H' :
  393. status.errorhint:=true;
  394. end;
  395. end;
  396. end;
  397. procedure GenerateError;
  398. begin
  399. inc(status.errorcount);
  400. end;
  401. procedure internalerror(i : longint);
  402. begin
  403. UpdateStatus;
  404. do_internalerror(i);
  405. inc(status.errorcount);
  406. raise ECompilerAbort.Create;
  407. end;
  408. procedure Comment(l:longint;s:ansistring);
  409. var
  410. dostop : boolean;
  411. begin
  412. dostop:=((l and V_Fatal)<>0);
  413. if ((l and V_Error)<>0) or
  414. ((l and V_Fatal)<>0) or
  415. (status.errorwarning and ((l and V_Warning)<>0)) or
  416. (status.errornote and ((l and V_Note)<>0)) or
  417. (status.errorhint and ((l and V_Hint)<>0)) then
  418. inc(status.errorcount)
  419. else
  420. if l and V_Warning <> 0 then
  421. inc(status.countWarnings)
  422. else
  423. if l and V_Note <> 0 then
  424. inc(status.countNotes)
  425. else
  426. if l and V_Hint <> 0 then
  427. inc(status.countHints);
  428. { check verbosity level }
  429. if not CheckVerbosity(l) then
  430. exit;
  431. if (l and V_LineInfoMask)<>0 then
  432. l:=l or V_LineInfo;
  433. { Create status info }
  434. UpdateStatus;
  435. { Fix replacements }
  436. DefaultReplacements(s);
  437. { show comment }
  438. if do_comment(l,s) or dostop then
  439. raise ECompilerAbort.Create;
  440. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  441. begin
  442. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  443. status.skip_error:=true;
  444. raise ECompilerAbort.Create;
  445. end;
  446. end;
  447. Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
  448. var
  449. idx,i,v : longint;
  450. dostop : boolean;
  451. doqueue : boolean;
  452. begin
  453. {Reset}
  454. dostop:=false;
  455. doqueue:=false;
  456. v:=0;
  457. {Parse options}
  458. idx:=pos('_',s);
  459. if idx=0 then
  460. v:=V_Normal
  461. else
  462. if (idx >= 1) And (idx <= 5) then
  463. begin
  464. for i:=1 to idx do
  465. begin
  466. case upcase(s[i]) of
  467. 'F' :
  468. begin
  469. v:=v or V_Fatal;
  470. inc(status.errorcount);
  471. dostop:=true;
  472. end;
  473. 'E' :
  474. begin
  475. v:=v or V_Error;
  476. inc(status.errorcount);
  477. end;
  478. 'O' :
  479. v:=v or V_Normal;
  480. 'W':
  481. begin
  482. v:=v or V_Warning;
  483. if status.errorwarning then
  484. inc(status.errorcount)
  485. else
  486. inc(status.countWarnings);
  487. end;
  488. 'N' :
  489. begin
  490. v:=v or V_Note;
  491. if status.errornote then
  492. inc(status.errorcount)
  493. else
  494. inc(status.countNotes);
  495. end;
  496. 'H' :
  497. begin
  498. v:=v or V_Hint;
  499. if status.errorhint then
  500. inc(status.errorcount)
  501. else
  502. inc(status.countHints);
  503. end;
  504. 'I' :
  505. v:=v or V_Info;
  506. 'L' :
  507. v:=v or V_LineInfo;
  508. 'U' :
  509. v:=v or V_Used;
  510. 'T' :
  511. v:=v or V_Tried;
  512. 'C' :
  513. v:=v or V_Conditional;
  514. 'D' :
  515. v:=v or V_Debug;
  516. 'X' :
  517. v:=v or V_Executable;
  518. 'S' :
  519. dostop:=true;
  520. '_' : ;
  521. end;
  522. end;
  523. end;
  524. Delete(s,1,idx);
  525. { check verbosity level }
  526. if not CheckVerbosity(v) then
  527. begin
  528. doqueue := onqueue <> nil;
  529. if not doqueue then
  530. exit;
  531. end;
  532. if (v and V_LineInfoMask)<>0 then
  533. v:=v or V_LineInfo;
  534. { fix status }
  535. UpdateStatus;
  536. { Fix replacements }
  537. DefaultReplacements(s);
  538. if doqueue then
  539. begin
  540. onqueue(s,v,w);
  541. exit;
  542. end;
  543. { show comment }
  544. if do_comment(v,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 MessagePchar(w:longint):pchar;
  554. begin
  555. MaybeLoadMessageFile;
  556. MessagePchar:=msg^.GetPchar(w)
  557. end;
  558. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  559. begin
  560. MaybeLoadMessageFile;
  561. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  562. end;
  563. procedure Message1(w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  564. begin
  565. MaybeLoadMessageFile;
  566. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  567. end;
  568. procedure Message2(w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  569. begin
  570. MaybeLoadMessageFile;
  571. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  572. end;
  573. procedure Message3(w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  574. begin
  575. MaybeLoadMessageFile;
  576. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  577. end;
  578. procedure Message4(w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  579. begin
  580. MaybeLoadMessageFile;
  581. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  582. end;
  583. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  584. var
  585. oldpos : tfileposinfo;
  586. begin
  587. oldpos:=current_filepos;
  588. current_filepos:=pos;
  589. MaybeLoadMessageFile;
  590. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  591. current_filepos:=oldpos;
  592. end;
  593. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  594. var
  595. oldpos : tfileposinfo;
  596. begin
  597. oldpos:=current_filepos;
  598. current_filepos:=pos;
  599. MaybeLoadMessageFile;
  600. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  601. current_filepos:=oldpos;
  602. end;
  603. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  604. var
  605. oldpos : tfileposinfo;
  606. begin
  607. oldpos:=current_filepos;
  608. current_filepos:=pos;
  609. MaybeLoadMessageFile;
  610. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  611. current_filepos:=oldpos;
  612. end;
  613. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  614. var
  615. oldpos : tfileposinfo;
  616. begin
  617. oldpos:=current_filepos;
  618. current_filepos:=pos;
  619. MaybeLoadMessageFile;
  620. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  621. current_filepos:=oldpos;
  622. end;
  623. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  624. var
  625. oldpos : tfileposinfo;
  626. begin
  627. oldpos:=current_filepos;
  628. current_filepos:=pos;
  629. MaybeLoadMessageFile;
  630. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  631. current_filepos:=oldpos;
  632. end;
  633. {*****************************************************************************
  634. override the message calls to set codegenerror
  635. *****************************************************************************}
  636. procedure cgmessage(t : longint);
  637. var
  638. olderrorcount : longint;
  639. begin
  640. if not(codegenerror) then
  641. begin
  642. olderrorcount:=Errorcount;
  643. verbose.Message(t);
  644. codegenerror:=olderrorcount<>Errorcount;
  645. end;
  646. end;
  647. procedure cgmessage1(t : longint;const s : string);
  648. var
  649. olderrorcount : longint;
  650. begin
  651. if not(codegenerror) then
  652. begin
  653. olderrorcount:=Errorcount;
  654. verbose.Message1(t,s);
  655. codegenerror:=olderrorcount<>Errorcount;
  656. end;
  657. end;
  658. procedure cgmessage2(t : longint;const s1,s2 : string);
  659. var
  660. olderrorcount : longint;
  661. begin
  662. if not(codegenerror) then
  663. begin
  664. olderrorcount:=Errorcount;
  665. verbose.Message2(t,s1,s2);
  666. codegenerror:=olderrorcount<>Errorcount;
  667. end;
  668. end;
  669. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  670. var
  671. olderrorcount : longint;
  672. begin
  673. if not(codegenerror) then
  674. begin
  675. olderrorcount:=Errorcount;
  676. verbose.Message3(t,s1,s2,s3);
  677. codegenerror:=olderrorcount<>Errorcount;
  678. end;
  679. end;
  680. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  681. var
  682. olderrorcount : longint;
  683. begin
  684. if not(codegenerror) then
  685. begin
  686. olderrorcount:=Errorcount;
  687. verbose.MessagePos(pos,t);
  688. codegenerror:=olderrorcount<>Errorcount;
  689. end;
  690. end;
  691. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  692. var
  693. olderrorcount : longint;
  694. begin
  695. if not(codegenerror) then
  696. begin
  697. olderrorcount:=Errorcount;
  698. verbose.MessagePos1(pos,t,s1);
  699. codegenerror:=olderrorcount<>Errorcount;
  700. end;
  701. end;
  702. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  703. var
  704. olderrorcount : longint;
  705. begin
  706. if not(codegenerror) then
  707. begin
  708. olderrorcount:=Errorcount;
  709. verbose.MessagePos2(pos,t,s1,s2);
  710. codegenerror:=olderrorcount<>Errorcount;
  711. end;
  712. end;
  713. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  714. var
  715. olderrorcount : longint;
  716. begin
  717. if not(codegenerror) then
  718. begin
  719. olderrorcount:=Errorcount;
  720. verbose.MessagePos3(pos,t,s1,s2,s3);
  721. codegenerror:=olderrorcount<>Errorcount;
  722. end;
  723. end;
  724. procedure FlushOutput;
  725. begin
  726. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  727. begin
  728. if Status.Use_Redir then
  729. Flush(Status.RedirFile)
  730. else
  731. Flush(Output);
  732. end;
  733. end;
  734. {*****************************************************************************
  735. Initialization
  736. *****************************************************************************}
  737. procedure InitVerbose;
  738. begin
  739. { Init }
  740. msg:=new(pmessage,Init(20,msgidxmax));
  741. if msg=nil then
  742. begin
  743. writeln('Fatal: MsgIdx Wrong');
  744. halt(3);
  745. end;
  746. {$ifndef EXTERN_MSG}
  747. msg^.LoadIntern(@msgtxt,msgtxtsize);
  748. {$else EXTERN_MSG}
  749. LoadMsgFile(exepath+'errore.msg');
  750. {$endif EXTERN_MSG}
  751. FillChar(Status,sizeof(TCompilerStatus),0);
  752. status.verbosity:=V_Default;
  753. Status.MaxErrorCount:=50;
  754. Status.codesize:=-1;
  755. Status.datasize:=-1;
  756. Loadprefixes;
  757. lastfileidx:=-1;
  758. lastmoduleidx:=-1;
  759. status.currentmodule:='';
  760. status.currentsource:='';
  761. status.currentsourcepath:='';
  762. { Register internalerrorproc for cutils/cclasses }
  763. internalerrorproc:=@internalerror;
  764. end;
  765. procedure DoneVerbose;
  766. begin
  767. if assigned(msg) then
  768. begin
  769. dispose(msg,Done);
  770. msg:=nil;
  771. end;
  772. DoneRedirectFile;
  773. end;
  774. initialization
  775. constexp.internalerror:=@internalerror;
  776. finalization
  777. { Be sure to close the redirect files to flush all data }
  778. DoneRedirectFile;
  779. end.