verbose.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  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. Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
  486. var
  487. idx,i,v : longint;
  488. dostop : boolean;
  489. doqueue : boolean;
  490. begin
  491. {Reset}
  492. dostop:=false;
  493. doqueue:=false;
  494. v:=0;
  495. {Parse options}
  496. idx:=pos('_',s);
  497. if idx=0 then
  498. v:=V_None
  499. else
  500. if (idx >= 1) And (idx <= 5) then
  501. begin
  502. for i:=1 to idx do
  503. begin
  504. case upcase(s[i]) of
  505. 'F' :
  506. begin
  507. v:=v or V_Fatal;
  508. inc(status.errorcount);
  509. dostop:=true;
  510. end;
  511. 'E' :
  512. begin
  513. v:=v or V_Error;
  514. inc(status.errorcount);
  515. end;
  516. 'O' :
  517. v:=v or V_Normal;
  518. 'W':
  519. begin
  520. v:=v or V_Warning;
  521. if CheckVerbosity(V_Warning) then
  522. if status.errorwarning then
  523. inc(status.errorcount)
  524. else
  525. inc(status.countWarnings);
  526. end;
  527. 'N' :
  528. begin
  529. v:=v or V_Note;
  530. if CheckVerbosity(V_Note) then
  531. if status.errornote then
  532. inc(status.errorcount)
  533. else
  534. inc(status.countNotes);
  535. end;
  536. 'H' :
  537. begin
  538. v:=v or V_Hint;
  539. if CheckVerbosity(V_Hint) then
  540. if status.errorhint then
  541. inc(status.errorcount)
  542. else
  543. inc(status.countHints);
  544. end;
  545. 'I' :
  546. v:=v or V_Info;
  547. 'L' :
  548. v:=v or V_LineInfo;
  549. 'U' :
  550. v:=v or V_Used;
  551. 'T' :
  552. v:=v or V_Tried;
  553. 'C' :
  554. v:=v or V_Conditional;
  555. 'D' :
  556. v:=v or V_Debug;
  557. 'X' :
  558. v:=v or V_Executable;
  559. 'S' :
  560. dostop:=true;
  561. '_' : ;
  562. end;
  563. end;
  564. end;
  565. Delete(s,1,idx);
  566. { check verbosity level }
  567. if not CheckVerbosity(v) then
  568. begin
  569. doqueue := onqueue <> nil;
  570. if not doqueue then
  571. exit;
  572. end;
  573. if (v and V_LineInfoMask)<>0 then
  574. v:=v or V_LineInfo;
  575. { fix status }
  576. UpdateStatus;
  577. { Fix replacements }
  578. DefaultReplacements(s);
  579. if status.showmsgnrs then
  580. s:='('+tostr(w)+') '+s;
  581. if doqueue then
  582. begin
  583. onqueue(s,v,w);
  584. exit;
  585. end;
  586. { show comment }
  587. if do_comment(v,s) or dostop then
  588. raise ECompilerAbort.Create;
  589. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  590. begin
  591. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  592. status.skip_error:=true;
  593. raise ECompilerAbort.Create;
  594. end;
  595. end;
  596. function MessagePchar(w:longint):pchar;
  597. begin
  598. MaybeLoadMessageFile;
  599. MessagePchar:=msg^.GetPchar(w)
  600. end;
  601. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  602. begin
  603. MaybeLoadMessageFile;
  604. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  605. end;
  606. procedure Message1(w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  607. begin
  608. MaybeLoadMessageFile;
  609. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  610. end;
  611. procedure Message2(w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  612. begin
  613. MaybeLoadMessageFile;
  614. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  615. end;
  616. procedure Message3(w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  617. begin
  618. MaybeLoadMessageFile;
  619. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  620. end;
  621. procedure Message4(w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  622. begin
  623. MaybeLoadMessageFile;
  624. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  625. end;
  626. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  627. var
  628. oldpos : tfileposinfo;
  629. begin
  630. oldpos:=current_filepos;
  631. current_filepos:=pos;
  632. MaybeLoadMessageFile;
  633. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  634. current_filepos:=oldpos;
  635. end;
  636. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string;onqueue:tmsgqueueevent=nil);
  637. var
  638. oldpos : tfileposinfo;
  639. begin
  640. oldpos:=current_filepos;
  641. current_filepos:=pos;
  642. MaybeLoadMessageFile;
  643. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  644. current_filepos:=oldpos;
  645. end;
  646. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string;onqueue:tmsgqueueevent=nil);
  647. var
  648. oldpos : tfileposinfo;
  649. begin
  650. oldpos:=current_filepos;
  651. current_filepos:=pos;
  652. MaybeLoadMessageFile;
  653. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  654. current_filepos:=oldpos;
  655. end;
  656. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string;onqueue:tmsgqueueevent=nil);
  657. var
  658. oldpos : tfileposinfo;
  659. begin
  660. oldpos:=current_filepos;
  661. current_filepos:=pos;
  662. MaybeLoadMessageFile;
  663. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  664. current_filepos:=oldpos;
  665. end;
  666. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string;onqueue:tmsgqueueevent=nil);
  667. var
  668. oldpos : tfileposinfo;
  669. begin
  670. oldpos:=current_filepos;
  671. current_filepos:=pos;
  672. MaybeLoadMessageFile;
  673. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  674. current_filepos:=oldpos;
  675. end;
  676. {*****************************************************************************
  677. override the message calls to set codegenerror
  678. *****************************************************************************}
  679. procedure cgmessage(t : longint);
  680. var
  681. olderrorcount : longint;
  682. begin
  683. if not(codegenerror) then
  684. begin
  685. olderrorcount:=Errorcount;
  686. verbose.Message(t);
  687. codegenerror:=olderrorcount<>Errorcount;
  688. end;
  689. end;
  690. procedure cgmessage1(t : longint;const s : string);
  691. var
  692. olderrorcount : longint;
  693. begin
  694. if not(codegenerror) then
  695. begin
  696. olderrorcount:=Errorcount;
  697. verbose.Message1(t,s);
  698. codegenerror:=olderrorcount<>Errorcount;
  699. end;
  700. end;
  701. procedure cgmessage2(t : longint;const s1,s2 : string);
  702. var
  703. olderrorcount : longint;
  704. begin
  705. if not(codegenerror) then
  706. begin
  707. olderrorcount:=Errorcount;
  708. verbose.Message2(t,s1,s2);
  709. codegenerror:=olderrorcount<>Errorcount;
  710. end;
  711. end;
  712. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  713. var
  714. olderrorcount : longint;
  715. begin
  716. if not(codegenerror) then
  717. begin
  718. olderrorcount:=Errorcount;
  719. verbose.Message3(t,s1,s2,s3);
  720. codegenerror:=olderrorcount<>Errorcount;
  721. end;
  722. end;
  723. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  724. var
  725. olderrorcount : longint;
  726. begin
  727. if not(codegenerror) then
  728. begin
  729. olderrorcount:=Errorcount;
  730. verbose.MessagePos(pos,t);
  731. codegenerror:=olderrorcount<>Errorcount;
  732. end;
  733. end;
  734. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  735. var
  736. olderrorcount : longint;
  737. begin
  738. if not(codegenerror) then
  739. begin
  740. olderrorcount:=Errorcount;
  741. verbose.MessagePos1(pos,t,s1);
  742. codegenerror:=olderrorcount<>Errorcount;
  743. end;
  744. end;
  745. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  746. var
  747. olderrorcount : longint;
  748. begin
  749. if not(codegenerror) then
  750. begin
  751. olderrorcount:=Errorcount;
  752. verbose.MessagePos2(pos,t,s1,s2);
  753. codegenerror:=olderrorcount<>Errorcount;
  754. end;
  755. end;
  756. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  757. var
  758. olderrorcount : longint;
  759. begin
  760. if not(codegenerror) then
  761. begin
  762. olderrorcount:=Errorcount;
  763. verbose.MessagePos3(pos,t,s1,s2,s3);
  764. codegenerror:=olderrorcount<>Errorcount;
  765. end;
  766. end;
  767. procedure FlushOutput;
  768. begin
  769. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  770. begin
  771. if Status.Use_Redir then
  772. Flush(Status.RedirFile)
  773. else
  774. Flush(Output);
  775. end;
  776. end;
  777. {*****************************************************************************
  778. Initialization
  779. *****************************************************************************}
  780. procedure InitVerbose;
  781. begin
  782. { Init }
  783. msg:=new(pmessage,Init(20,msgidxmax));
  784. if msg=nil then
  785. begin
  786. writeln('Fatal: MsgIdx Wrong');
  787. halt(3);
  788. end;
  789. {$ifndef EXTERN_MSG}
  790. msg^.LoadIntern(@msgtxt,msgtxtsize);
  791. {$else EXTERN_MSG}
  792. LoadMsgFile(exepath+'errore.msg');
  793. {$endif EXTERN_MSG}
  794. FillChar(Status,sizeof(TCompilerStatus),0);
  795. status.verbosity:=V_Default;
  796. Status.MaxErrorCount:=50;
  797. Status.codesize:=aword(-1);
  798. Status.datasize:=aword(-1);
  799. Loadprefixes;
  800. lastfileidx:=-1;
  801. lastmoduleidx:=-1;
  802. status.currentmodule:='';
  803. status.currentsource:='';
  804. status.currentsourcepath:='';
  805. { Register internalerrorproc for cutils/cclasses }
  806. internalerrorproc:=@internalerror;
  807. end;
  808. procedure DoneVerbose;
  809. begin
  810. if assigned(msg) then
  811. begin
  812. dispose(msg,Done);
  813. msg:=nil;
  814. end;
  815. DoneRedirectFile;
  816. end;
  817. initialization
  818. constexp.internalerror:=@internalerror;
  819. finalization
  820. { Be sure to close the redirect files to flush all data }
  821. DoneRedirectFile;
  822. end.