verbose.pas 30 KB

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