verbose.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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,fmodule;
  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. var
  323. module : tmodulebase;
  324. begin
  325. { fix status }
  326. status.currentline:=current_filepos.line;
  327. status.currentcolumn:=current_filepos.column;
  328. module:=get_module(current_filepos.moduleindex);
  329. if assigned(module) and
  330. assigned(module.sourcefiles) and
  331. ((module.unit_index<>lastmoduleidx) or
  332. (current_filepos.fileindex<>lastfileidx)) then
  333. begin
  334. { update status record }
  335. status.currentmodule:=module.modulename^;
  336. status.currentsource:=module.sourcefiles.get_file_name(current_filepos.fileindex);
  337. status.currentsourcepath:=module.sourcefiles.get_file_path(current_filepos.fileindex);
  338. { update lastfileidx only if name known PM }
  339. if status.currentsource<>'' then
  340. lastfileidx:=current_filepos.fileindex
  341. else
  342. lastfileidx:=0;
  343. lastmoduleidx:=compiling_module.unit_index;
  344. end;
  345. if assigned(module) then
  346. status.compiling_current:=(compiling_module.state in [ms_compile,ms_second_compile]);
  347. end;
  348. procedure ShowStatus;
  349. begin
  350. UpdateStatus;
  351. if do_status() then
  352. raise ECompilerAbort.Create;
  353. end;
  354. function ErrorCount:longint;
  355. begin
  356. ErrorCount:=status.errorcount;
  357. end;
  358. procedure SetErrorFlags(const s:string);
  359. var
  360. code : integer;
  361. i,j,l : longint;
  362. begin
  363. { empty string means error count = 1 for backward compatibility (PFV) }
  364. if s='' then
  365. begin
  366. status.maxerrorcount:=1;
  367. exit;
  368. end;
  369. i:=0;
  370. while (i<length(s)) do
  371. begin
  372. inc(i);
  373. case s[i] of
  374. '0'..'9' :
  375. begin
  376. j:=i;
  377. while (j<=length(s)) and (s[j] in ['0'..'9']) do
  378. inc(j);
  379. val(copy(s,i,j-i),l,code);
  380. if code<>0 then
  381. l:=1;
  382. status.maxerrorcount:=l;
  383. i:=j;
  384. end;
  385. 'w','W' :
  386. status.errorwarning:=true;
  387. 'n','N' :
  388. status.errornote:=true;
  389. 'h','H' :
  390. status.errorhint:=true;
  391. end;
  392. end;
  393. end;
  394. procedure GenerateError;
  395. begin
  396. inc(status.errorcount);
  397. end;
  398. procedure internalerror(i : longint);
  399. begin
  400. UpdateStatus;
  401. do_internalerror(i);
  402. inc(status.errorcount);
  403. raise ECompilerAbort.Create;
  404. end;
  405. procedure Comment(l:longint;s:string);
  406. var
  407. dostop : boolean;
  408. begin
  409. dostop:=((l and V_Fatal)<>0);
  410. if ((l and V_Error)<>0) or
  411. (status.errorwarning and ((l and V_Warning)<>0)) or
  412. (status.errornote and ((l and V_Note)<>0)) or
  413. (status.errorhint and ((l and V_Hint)<>0)) then
  414. inc(status.errorcount);
  415. { check verbosity level }
  416. if not CheckVerbosity(l) then
  417. exit;
  418. if (l and V_LineInfoMask)<>0 then
  419. l:=l or V_LineInfo;
  420. { Create status info }
  421. UpdateStatus;
  422. { Fix replacements }
  423. DefaultReplacements(s);
  424. { show comment }
  425. if do_comment(l,s) or dostop then
  426. raise ECompilerAbort.Create;
  427. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  428. begin
  429. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  430. status.skip_error:=true;
  431. raise ECompilerAbort.Create;
  432. end;
  433. end;
  434. Procedure Msg2Comment(s:string;w:longint;onqueue:tmsgqueueevent);
  435. var
  436. idx,i,v : longint;
  437. dostop : boolean;
  438. doqueue : boolean;
  439. begin
  440. {Reset}
  441. dostop:=false;
  442. doqueue:=false;
  443. v:=0;
  444. {Parse options}
  445. idx:=pos('_',s);
  446. if idx=0 then
  447. v:=V_Normal
  448. else
  449. if (idx >= 1) And (idx <= 5) then
  450. begin
  451. for i:=1 to idx do
  452. begin
  453. case upcase(s[i]) of
  454. 'F' :
  455. begin
  456. v:=v or V_Fatal;
  457. inc(status.errorcount);
  458. dostop:=true;
  459. end;
  460. 'E' :
  461. begin
  462. v:=v or V_Error;
  463. inc(status.errorcount);
  464. end;
  465. 'O' :
  466. v:=v or V_Normal;
  467. 'W':
  468. begin
  469. v:=v or V_Warning;
  470. if status.errorwarning then
  471. inc(status.errorcount)
  472. else
  473. inc(status.countWarnings);
  474. end;
  475. 'N' :
  476. begin
  477. v:=v or V_Note;
  478. if status.errornote then
  479. inc(status.errorcount)
  480. else
  481. inc(status.countNotes);
  482. end;
  483. 'H' :
  484. begin
  485. v:=v or V_Hint;
  486. if status.errorhint then
  487. inc(status.errorcount)
  488. else
  489. inc(status.countHints);
  490. end;
  491. 'I' :
  492. v:=v or V_Info;
  493. 'L' :
  494. v:=v or V_LineInfo;
  495. 'U' :
  496. v:=v or V_Used;
  497. 'T' :
  498. v:=v or V_Tried;
  499. 'C' :
  500. v:=v or V_Conditional;
  501. 'D' :
  502. v:=v or V_Debug;
  503. 'X' :
  504. v:=v or V_Executable;
  505. 'S' :
  506. dostop:=true;
  507. '_' : ;
  508. end;
  509. end;
  510. end;
  511. Delete(s,1,idx);
  512. { check verbosity level }
  513. if not CheckVerbosity(v) then
  514. begin
  515. doqueue := onqueue <> nil;
  516. if not doqueue then
  517. exit;
  518. end;
  519. if (v and V_LineInfoMask)<>0 then
  520. v:=v or V_LineInfo;
  521. { fix status }
  522. UpdateStatus;
  523. { Fix replacements }
  524. DefaultReplacements(s);
  525. if doqueue then
  526. begin
  527. onqueue(s,v,w);
  528. exit;
  529. end;
  530. { show comment }
  531. if do_comment(v,s) or dostop then
  532. raise ECompilerAbort.Create;
  533. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  534. begin
  535. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  536. status.skip_error:=true;
  537. raise ECompilerAbort.Create;
  538. end;
  539. end;
  540. function MessagePchar(w:longint):pchar;
  541. begin
  542. MaybeLoadMessageFile;
  543. MessagePchar:=msg^.GetPchar(w)
  544. end;
  545. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  546. begin
  547. MaybeLoadMessageFile;
  548. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  549. end;
  550. procedure Message1(w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  551. begin
  552. MaybeLoadMessageFile;
  553. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  554. end;
  555. procedure Message2(w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  556. begin
  557. MaybeLoadMessageFile;
  558. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  559. end;
  560. procedure Message3(w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  561. begin
  562. MaybeLoadMessageFile;
  563. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  564. end;
  565. procedure Message4(w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  566. begin
  567. MaybeLoadMessageFile;
  568. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  569. end;
  570. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  571. var
  572. oldpos : tfileposinfo;
  573. begin
  574. oldpos:=current_filepos;
  575. current_filepos:=pos;
  576. MaybeLoadMessageFile;
  577. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  578. current_filepos:=oldpos;
  579. end;
  580. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  581. var
  582. oldpos : tfileposinfo;
  583. begin
  584. oldpos:=current_filepos;
  585. current_filepos:=pos;
  586. MaybeLoadMessageFile;
  587. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  588. current_filepos:=oldpos;
  589. end;
  590. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  591. var
  592. oldpos : tfileposinfo;
  593. begin
  594. oldpos:=current_filepos;
  595. current_filepos:=pos;
  596. MaybeLoadMessageFile;
  597. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  598. current_filepos:=oldpos;
  599. end;
  600. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  601. var
  602. oldpos : tfileposinfo;
  603. begin
  604. oldpos:=current_filepos;
  605. current_filepos:=pos;
  606. MaybeLoadMessageFile;
  607. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  608. current_filepos:=oldpos;
  609. end;
  610. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  611. var
  612. oldpos : tfileposinfo;
  613. begin
  614. oldpos:=current_filepos;
  615. current_filepos:=pos;
  616. MaybeLoadMessageFile;
  617. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  618. current_filepos:=oldpos;
  619. end;
  620. {*****************************************************************************
  621. override the message calls to set codegenerror
  622. *****************************************************************************}
  623. procedure cgmessage(t : longint);
  624. var
  625. olderrorcount : longint;
  626. begin
  627. if not(codegenerror) then
  628. begin
  629. olderrorcount:=Errorcount;
  630. verbose.Message(t);
  631. codegenerror:=olderrorcount<>Errorcount;
  632. end;
  633. end;
  634. procedure cgmessage1(t : longint;const s : string);
  635. var
  636. olderrorcount : longint;
  637. begin
  638. if not(codegenerror) then
  639. begin
  640. olderrorcount:=Errorcount;
  641. verbose.Message1(t,s);
  642. codegenerror:=olderrorcount<>Errorcount;
  643. end;
  644. end;
  645. procedure cgmessage2(t : longint;const s1,s2 : string);
  646. var
  647. olderrorcount : longint;
  648. begin
  649. if not(codegenerror) then
  650. begin
  651. olderrorcount:=Errorcount;
  652. verbose.Message2(t,s1,s2);
  653. codegenerror:=olderrorcount<>Errorcount;
  654. end;
  655. end;
  656. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  657. var
  658. olderrorcount : longint;
  659. begin
  660. if not(codegenerror) then
  661. begin
  662. olderrorcount:=Errorcount;
  663. verbose.Message3(t,s1,s2,s3);
  664. codegenerror:=olderrorcount<>Errorcount;
  665. end;
  666. end;
  667. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  668. var
  669. olderrorcount : longint;
  670. begin
  671. if not(codegenerror) then
  672. begin
  673. olderrorcount:=Errorcount;
  674. verbose.MessagePos(pos,t);
  675. codegenerror:=olderrorcount<>Errorcount;
  676. end;
  677. end;
  678. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  679. var
  680. olderrorcount : longint;
  681. begin
  682. if not(codegenerror) then
  683. begin
  684. olderrorcount:=Errorcount;
  685. verbose.MessagePos1(pos,t,s1);
  686. codegenerror:=olderrorcount<>Errorcount;
  687. end;
  688. end;
  689. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  690. var
  691. olderrorcount : longint;
  692. begin
  693. if not(codegenerror) then
  694. begin
  695. olderrorcount:=Errorcount;
  696. verbose.MessagePos2(pos,t,s1,s2);
  697. codegenerror:=olderrorcount<>Errorcount;
  698. end;
  699. end;
  700. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  701. var
  702. olderrorcount : longint;
  703. begin
  704. if not(codegenerror) then
  705. begin
  706. olderrorcount:=Errorcount;
  707. verbose.MessagePos3(pos,t,s1,s2,s3);
  708. codegenerror:=olderrorcount<>Errorcount;
  709. end;
  710. end;
  711. procedure FlushOutput;
  712. begin
  713. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  714. begin
  715. if Status.Use_Redir then
  716. Flush(Status.RedirFile)
  717. else
  718. Flush(Output);
  719. end;
  720. end;
  721. {*****************************************************************************
  722. Initialization
  723. *****************************************************************************}
  724. procedure InitVerbose;
  725. begin
  726. { Init }
  727. msg:=new(pmessage,Init(20,msgidxmax));
  728. if msg=nil then
  729. begin
  730. writeln('Fatal: MsgIdx Wrong');
  731. halt(3);
  732. end;
  733. {$ifndef EXTERN_MSG}
  734. msg^.LoadIntern(@msgtxt,msgtxtsize);
  735. {$else EXTERN_MSG}
  736. LoadMsgFile(exepath+'errore.msg');
  737. {$endif EXTERN_MSG}
  738. FillChar(Status,sizeof(TCompilerStatus),0);
  739. status.verbosity:=V_Default;
  740. Status.MaxErrorCount:=50;
  741. Status.codesize:=-1;
  742. Status.datasize:=-1;
  743. Loadprefixes;
  744. lastfileidx:=-1;
  745. lastmoduleidx:=-1;
  746. status.currentmodule:='';
  747. status.currentsource:='';
  748. status.currentsourcepath:='';
  749. status.compiling_current:=false;
  750. compiling_module:=nil;
  751. { Register internalerrorproc for cutils/cclasses }
  752. internalerrorproc:=@internalerror;
  753. end;
  754. procedure DoneVerbose;
  755. begin
  756. if assigned(msg) then
  757. begin
  758. dispose(msg,Done);
  759. msg:=nil;
  760. end;
  761. DoneRedirectFile;
  762. end;
  763. initialization
  764. finalization
  765. { Be sure to close the redirect files to flush all data }
  766. DoneRedirectFile;
  767. end.