verbose.pas 26 KB

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