verbose.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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. else
  470. inc(status.countWarnings);
  471. end;
  472. 'N' :
  473. begin
  474. v:=v or V_Note;
  475. if status.errornote then
  476. inc(status.errorcount)
  477. else
  478. inc(status.countNotes);
  479. end;
  480. 'H' :
  481. begin
  482. v:=v or V_Hint;
  483. if status.errorhint then
  484. inc(status.errorcount)
  485. else
  486. inc(status.countHints);
  487. end;
  488. 'I' :
  489. v:=v or V_Info;
  490. 'L' :
  491. v:=v or V_LineInfo;
  492. 'U' :
  493. v:=v or V_Used;
  494. 'T' :
  495. v:=v or V_Tried;
  496. 'C' :
  497. v:=v or V_Conditional;
  498. 'D' :
  499. v:=v or V_Debug;
  500. 'X' :
  501. v:=v or V_Executable;
  502. 'S' :
  503. dostop:=true;
  504. '_' : ;
  505. end;
  506. end;
  507. end;
  508. Delete(s,1,idx);
  509. { check verbosity level }
  510. if not CheckVerbosity(v) then
  511. begin
  512. doqueue := onqueue <> nil;
  513. if not doqueue then
  514. exit;
  515. end;
  516. if (v and V_LineInfoMask)<>0 then
  517. v:=v or V_LineInfo;
  518. { fix status }
  519. UpdateStatus;
  520. { Fix replacements }
  521. DefaultReplacements(s);
  522. if doqueue then
  523. begin
  524. onqueue(s,v,w);
  525. exit;
  526. end;
  527. { show comment }
  528. if do_comment(v,s) or dostop then
  529. raise ECompilerAbort.Create;
  530. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  531. begin
  532. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  533. status.skip_error:=true;
  534. raise ECompilerAbort.Create;
  535. end;
  536. end;
  537. function MessagePchar(w:longint):pchar;
  538. begin
  539. MaybeLoadMessageFile;
  540. MessagePchar:=msg^.GetPchar(w)
  541. end;
  542. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  543. begin
  544. MaybeLoadMessageFile;
  545. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  546. end;
  547. procedure Message1(w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  548. begin
  549. MaybeLoadMessageFile;
  550. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  551. end;
  552. procedure Message2(w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  553. begin
  554. MaybeLoadMessageFile;
  555. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  556. end;
  557. procedure Message3(w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  558. begin
  559. MaybeLoadMessageFile;
  560. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  561. end;
  562. procedure Message4(w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  563. begin
  564. MaybeLoadMessageFile;
  565. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  566. end;
  567. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  568. var
  569. oldpos : tfileposinfo;
  570. begin
  571. oldpos:=aktfilepos;
  572. aktfilepos:=pos;
  573. MaybeLoadMessageFile;
  574. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  575. aktfilepos:=oldpos;
  576. end;
  577. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  578. var
  579. oldpos : tfileposinfo;
  580. begin
  581. oldpos:=aktfilepos;
  582. aktfilepos:=pos;
  583. MaybeLoadMessageFile;
  584. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  585. aktfilepos:=oldpos;
  586. end;
  587. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  588. var
  589. oldpos : tfileposinfo;
  590. begin
  591. oldpos:=aktfilepos;
  592. aktfilepos:=pos;
  593. MaybeLoadMessageFile;
  594. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  595. aktfilepos:=oldpos;
  596. end;
  597. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  598. var
  599. oldpos : tfileposinfo;
  600. begin
  601. oldpos:=aktfilepos;
  602. aktfilepos:=pos;
  603. MaybeLoadMessageFile;
  604. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  605. aktfilepos:=oldpos;
  606. end;
  607. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  608. var
  609. oldpos : tfileposinfo;
  610. begin
  611. oldpos:=aktfilepos;
  612. aktfilepos:=pos;
  613. MaybeLoadMessageFile;
  614. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  615. aktfilepos:=oldpos;
  616. end;
  617. {*****************************************************************************
  618. override the message calls to set codegenerror
  619. *****************************************************************************}
  620. procedure cgmessage(t : longint);
  621. var
  622. olderrorcount : longint;
  623. begin
  624. if not(codegenerror) then
  625. begin
  626. olderrorcount:=Errorcount;
  627. verbose.Message(t);
  628. codegenerror:=olderrorcount<>Errorcount;
  629. end;
  630. end;
  631. procedure cgmessage1(t : longint;const s : string);
  632. var
  633. olderrorcount : longint;
  634. begin
  635. if not(codegenerror) then
  636. begin
  637. olderrorcount:=Errorcount;
  638. verbose.Message1(t,s);
  639. codegenerror:=olderrorcount<>Errorcount;
  640. end;
  641. end;
  642. procedure cgmessage2(t : longint;const s1,s2 : string);
  643. var
  644. olderrorcount : longint;
  645. begin
  646. if not(codegenerror) then
  647. begin
  648. olderrorcount:=Errorcount;
  649. verbose.Message2(t,s1,s2);
  650. codegenerror:=olderrorcount<>Errorcount;
  651. end;
  652. end;
  653. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  654. var
  655. olderrorcount : longint;
  656. begin
  657. if not(codegenerror) then
  658. begin
  659. olderrorcount:=Errorcount;
  660. verbose.Message3(t,s1,s2,s3);
  661. codegenerror:=olderrorcount<>Errorcount;
  662. end;
  663. end;
  664. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  665. var
  666. olderrorcount : longint;
  667. begin
  668. if not(codegenerror) then
  669. begin
  670. olderrorcount:=Errorcount;
  671. verbose.MessagePos(pos,t);
  672. codegenerror:=olderrorcount<>Errorcount;
  673. end;
  674. end;
  675. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  676. var
  677. olderrorcount : longint;
  678. begin
  679. if not(codegenerror) then
  680. begin
  681. olderrorcount:=Errorcount;
  682. verbose.MessagePos1(pos,t,s1);
  683. codegenerror:=olderrorcount<>Errorcount;
  684. end;
  685. end;
  686. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  687. var
  688. olderrorcount : longint;
  689. begin
  690. if not(codegenerror) then
  691. begin
  692. olderrorcount:=Errorcount;
  693. verbose.MessagePos2(pos,t,s1,s2);
  694. codegenerror:=olderrorcount<>Errorcount;
  695. end;
  696. end;
  697. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  698. var
  699. olderrorcount : longint;
  700. begin
  701. if not(codegenerror) then
  702. begin
  703. olderrorcount:=Errorcount;
  704. verbose.MessagePos3(pos,t,s1,s2,s3);
  705. codegenerror:=olderrorcount<>Errorcount;
  706. end;
  707. end;
  708. procedure FlushOutput;
  709. begin
  710. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  711. begin
  712. if Status.Use_Redir then
  713. Flush(Status.RedirFile)
  714. else
  715. Flush(Output);
  716. end;
  717. end;
  718. {*****************************************************************************
  719. Initialization
  720. *****************************************************************************}
  721. procedure InitVerbose;
  722. begin
  723. { Init }
  724. msg:=new(pmessage,Init(20,msgidxmax));
  725. if msg=nil then
  726. begin
  727. writeln('Fatal: MsgIdx Wrong');
  728. halt(3);
  729. end;
  730. {$ifndef EXTERN_MSG}
  731. msg^.LoadIntern(@msgtxt,msgtxtsize);
  732. {$else EXTERN_MSG}
  733. LoadMsgFile(exepath+'errore.msg');
  734. {$endif EXTERN_MSG}
  735. FillChar(Status,sizeof(TCompilerStatus),0);
  736. status.verbosity:=V_Default;
  737. Status.MaxErrorCount:=50;
  738. Status.codesize:=-1;
  739. Status.datasize:=-1;
  740. Loadprefixes;
  741. lastfileidx:=-1;
  742. lastmoduleidx:=-1;
  743. status.currentmodule:='';
  744. status.currentsource:='';
  745. status.currentsourcepath:='';
  746. status.compiling_current:=false;
  747. compiling_module:=nil;
  748. { Register internalerrorproc for cutils/cclasses }
  749. internalerrorproc:=@internalerror;
  750. end;
  751. procedure DoneVerbose;
  752. begin
  753. if assigned(msg) then
  754. begin
  755. dispose(msg,Done);
  756. msg:=nil;
  757. end;
  758. DoneRedirectFile;
  759. end;
  760. initialization
  761. finalization
  762. { Be sure to close the redirect files to flush all data }
  763. DoneRedirectFile;
  764. end.