verbose.pas 25 KB

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