verbose.pas 28 KB

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