verbose.pas 29 KB

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