verbose.pas 26 KB

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