verbose.pas 27 KB

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