verbose.pas 26 KB

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