verbose.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Peter Vreman
  4. This unit handles the verbose management
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit verbose;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. sysutils,
  23. cutils,
  24. globals,finput,
  25. cmsgs;
  26. {$ifndef EXTERN_MSG}
  27. {$i msgtxt.inc}
  28. {$endif}
  29. {$i msgidx.inc}
  30. Const
  31. { Levels }
  32. V_None = $0;
  33. V_Fatal = $1;
  34. V_Error = $2;
  35. V_Normal = $4; { doesn't show a text like Error: }
  36. V_Warning = $8;
  37. V_Note = $10;
  38. V_Hint = $20;
  39. V_LineInfoMask = $fff;
  40. { From here by default no line info }
  41. V_Info = $1000;
  42. V_Status = $2000;
  43. V_Used = $4000;
  44. V_Tried = $8000;
  45. V_Conditional = $10000;
  46. V_Debug = $20000;
  47. V_Executable = $40000;
  48. V_LevelMask = $fffffff;
  49. V_All = V_LevelMask;
  50. V_Default = V_Fatal + V_Error + V_Normal;
  51. { Flags }
  52. V_LineInfo = $10000000;
  53. var
  54. msg : pmessage;
  55. const
  56. msgfilename : string = '';
  57. type
  58. EControlCAbort=class(Exception)
  59. constructor Create;
  60. end;
  61. procedure SetRedirectFile(const fn:string);
  62. function SetVerbosity(const s:string):boolean;
  63. procedure PrepareReport;
  64. function CheckVerbosity(v:longint):boolean;
  65. procedure SetCompileModule(p:tmodulebase);
  66. procedure Stop(err:longint);
  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:string);
  73. function MessagePchar(w:longint):pchar;
  74. procedure Message(w:longint);
  75. procedure Message1(w:longint;const s1:string);
  76. procedure Message2(w:longint;const s1,s2:string);
  77. procedure Message3(w:longint;const s1,s2,s3:string);
  78. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  79. procedure MessagePos(const pos:tfileposinfo;w:longint);
  80. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  81. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  82. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  83. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  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 InitVerbose;
  94. procedure DoneVerbose;
  95. implementation
  96. uses
  97. comphook;
  98. var
  99. compiling_module : tmodulebase;
  100. {****************************************************************************
  101. Control-C Exception
  102. ****************************************************************************}
  103. constructor EControlCAbort.Create;
  104. begin
  105. inherited Create('Ctrl-C Signaled!');
  106. end;
  107. {****************************************************************************
  108. Extra Handlers for default compiler
  109. ****************************************************************************}
  110. procedure DoneRedirectFile;
  111. begin
  112. if status.use_redir then
  113. begin
  114. close(status.redirfile);
  115. status.use_redir:=false;
  116. end;
  117. if status.use_bugreport then
  118. begin
  119. close(status.reportbugfile);
  120. status.use_bugreport:=false;
  121. end;
  122. end;
  123. procedure SetRedirectFile(const fn:string);
  124. begin
  125. assign(status.redirfile,fn);
  126. {$I-}
  127. append(status.redirfile);
  128. if ioresult <> 0 then
  129. rewrite(status.redirfile);
  130. {$I+}
  131. status.use_redir:=(ioresult=0);
  132. end;
  133. procedure PrepareReport;
  134. var
  135. fn : string;
  136. begin
  137. if status.use_bugreport then
  138. exit;
  139. fn:='fpcdebug.txt';
  140. assign(status.reportbugfile,fn);
  141. {$I-}
  142. append(status.reportbugfile);
  143. if ioresult <> 0 then
  144. rewrite(status.reportbugfile);
  145. {$I+}
  146. status.use_bugreport:=(ioresult=0);
  147. if status.use_bugreport then
  148. writeln(status.reportbugfile,'FPC bug report file');
  149. end;
  150. function CheckVerbosity(v:longint):boolean;
  151. begin
  152. CheckVerbosity:=status.use_bugreport or
  153. ((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
  154. end;
  155. function SetVerbosity(const s:string):boolean;
  156. var
  157. m : Longint;
  158. i : Integer;
  159. inverse : boolean;
  160. c : char;
  161. begin
  162. Setverbosity:=false;
  163. val(s,m,i);
  164. if (i=0) and (s<>'') then
  165. status.verbosity:=m
  166. else
  167. begin
  168. i:=1;
  169. while i<=length(s) do
  170. begin
  171. c:=upcase(s[i]);
  172. inverse:=false;
  173. { on/off ? }
  174. if (i<length(s)) then
  175. case s[i+1] of
  176. '-' : begin
  177. inc(i);
  178. inverse:=true;
  179. end;
  180. '+' : inc(i);
  181. end;
  182. { handle switch }
  183. case c of
  184. { Special cases }
  185. 'A' : status.verbosity:=V_All;
  186. '0' : status.verbosity:=V_Default;
  187. 'P' : begin
  188. if inverse then
  189. paraprintnodetree:=0
  190. else
  191. paraprintnodetree:=1;
  192. end;
  193. 'R' : begin
  194. if inverse then
  195. begin
  196. status.use_gccoutput:=false;
  197. status.use_stderr:=false;
  198. end
  199. else
  200. begin
  201. status.use_gccoutput:=true;
  202. status.use_stderr:=true;
  203. end;
  204. end;
  205. 'Z' : begin
  206. if inverse then
  207. status.use_stderr:=false
  208. else
  209. status.use_stderr:=true;
  210. end;
  211. { Normal cases - do an or }
  212. 'E' : if inverse then
  213. status.verbosity:=status.verbosity and (not V_Error)
  214. else
  215. status.verbosity:=status.verbosity or V_Error;
  216. 'I' : if inverse then
  217. status.verbosity:=status.verbosity and (not V_Info)
  218. else
  219. status.verbosity:=status.verbosity or V_Info;
  220. 'W' : if inverse then
  221. status.verbosity:=status.verbosity and (not V_Warning)
  222. else
  223. status.verbosity:=status.verbosity or V_Warning;
  224. 'N' : if inverse then
  225. status.verbosity:=status.verbosity and (not V_Note)
  226. else
  227. status.verbosity:=status.verbosity or V_Note;
  228. 'H' : if inverse then
  229. status.verbosity:=status.verbosity and (not V_Hint)
  230. else
  231. status.verbosity:=status.verbosity or V_Hint;
  232. 'L' : if inverse then
  233. status.verbosity:=status.verbosity and (not V_Status)
  234. else
  235. status.verbosity:=status.verbosity or V_Status;
  236. 'U' : if inverse then
  237. status.verbosity:=status.verbosity and (not V_Used)
  238. else
  239. status.verbosity:=status.verbosity or V_Used;
  240. 'T' : if inverse then
  241. status.verbosity:=status.verbosity and (not V_Tried)
  242. else
  243. status.verbosity:=status.verbosity or V_Tried;
  244. 'C' : if inverse then
  245. status.verbosity:=status.verbosity and (not V_Conditional)
  246. else
  247. status.verbosity:=status.verbosity or V_Conditional;
  248. 'D' : if inverse then
  249. status.verbosity:=status.verbosity and (not V_Debug)
  250. else
  251. status.verbosity:=status.verbosity or V_Debug;
  252. 'X' : if inverse then
  253. status.verbosity:=status.verbosity and (not V_Executable)
  254. else
  255. status.verbosity:=status.verbosity or V_Executable;
  256. 'V' : PrepareReport;
  257. end;
  258. inc(i);
  259. end;
  260. end;
  261. if status.verbosity=0 then
  262. status.verbosity:=V_Default;
  263. setverbosity:=true;
  264. end;
  265. procedure Loadprefixes;
  266. function loadprefix(w:longint):string;
  267. var
  268. s : string;
  269. idx : longint;
  270. begin
  271. s:=msg^.get(w,[]);
  272. idx:=pos('_',s);
  273. if idx>0 then
  274. Loadprefix:=Copy(s,idx+1,255)
  275. else
  276. Loadprefix:=s;
  277. end;
  278. begin
  279. { Load the prefixes }
  280. fatalstr:=Loadprefix(general_i_fatal);
  281. errorstr:=Loadprefix(general_i_error);
  282. warningstr:=Loadprefix(general_i_warning);
  283. notestr:=Loadprefix(general_i_note);
  284. hintstr:=Loadprefix(general_i_hint);
  285. end;
  286. procedure LoadMsgFile(const fn:string);
  287. begin
  288. { reload the internal messages if not already loaded }
  289. {$ifndef EXTERN_MSG}
  290. if not msg^.msgintern then
  291. msg^.LoadIntern(@msgtxt,msgtxtsize);
  292. {$endif}
  293. if not msg^.LoadExtern(fn) then
  294. begin
  295. {$ifdef EXTERN_MSG}
  296. writeln('Fatal: Cannot find error message file.');
  297. halt(3);
  298. {$else}
  299. msg^.LoadIntern(@msgtxt,msgtxtsize);
  300. {$endif}
  301. end;
  302. { reload the prefixes using the new messages }
  303. Loadprefixes;
  304. end;
  305. procedure MaybeLoadMessageFile;
  306. begin
  307. { Load new message file }
  308. if (msgfilename<>'') then
  309. begin
  310. LoadMsgFile(msgfilename);
  311. msgfilename:='';
  312. end;
  313. end;
  314. procedure SetCompileModule(p:tmodulebase);
  315. begin
  316. compiling_module:=p;
  317. end;
  318. var
  319. lastfileidx,
  320. lastmoduleidx : longint;
  321. Procedure UpdateStatus;
  322. begin
  323. { fix status }
  324. status.currentline:=aktfilepos.line;
  325. status.currentcolumn:=aktfilepos.column;
  326. if assigned(compiling_module) and
  327. assigned(compiling_module.sourcefiles) and
  328. ((compiling_module.unit_index<>lastmoduleidx) or
  329. (aktfilepos.fileindex<>lastfileidx)) then
  330. begin
  331. { update status record }
  332. status.currentmodule:=compiling_module.modulename^;
  333. status.currentsource:=compiling_module.sourcefiles.get_file_name(aktfilepos.fileindex);
  334. status.currentsourcepath:=compiling_module.sourcefiles.get_file_path(aktfilepos.fileindex);
  335. { update lastfileidx only if name known PM }
  336. if status.currentsource<>'' then
  337. lastfileidx:=aktfilepos.fileindex
  338. else
  339. lastfileidx:=0;
  340. lastmoduleidx:=compiling_module.unit_index;
  341. end;
  342. if assigned(compiling_module) then
  343. status.compiling_current:=(compiling_module.state in [ms_compile,ms_second_compile]);
  344. end;
  345. procedure stop(err:longint);
  346. begin
  347. do_stop(err);
  348. end;
  349. procedure ShowStatus;
  350. begin
  351. UpdateStatus;
  352. if do_status() then
  353. stop(1);
  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;
  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. stop(1);
  405. end;
  406. procedure Comment(l:longint;s:string);
  407. var
  408. dostop : boolean;
  409. begin
  410. dostop:=((l and V_Fatal)<>0);
  411. if ((l and V_Error)<>0) or
  412. (status.errorwarning and ((l and V_Warning)<>0)) or
  413. (status.errornote and ((l and V_Note)<>0)) or
  414. (status.errorhint and ((l and V_Hint)<>0)) then
  415. inc(status.errorcount);
  416. { check verbosity level }
  417. if not CheckVerbosity(l) then
  418. exit;
  419. if (l and V_LineInfoMask)<>0 then
  420. l:=l or V_LineInfo;
  421. { Create status info }
  422. UpdateStatus;
  423. { Fix replacements }
  424. DefaultReplacements(s);
  425. { show comment }
  426. if do_comment(l,s) or dostop then
  427. stop(1);
  428. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  429. begin
  430. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  431. status.skip_error:=true;
  432. stop(1);
  433. end;
  434. end;
  435. Procedure Msg2Comment(s:string);
  436. var
  437. idx,i,v : longint;
  438. dostop : boolean;
  439. begin
  440. {Reset}
  441. dostop:=false;
  442. v:=0;
  443. {Parse options}
  444. idx:=pos('_',s);
  445. if idx=0 then
  446. v:=V_Normal
  447. else
  448. if (idx >= 1) And (idx <= 5) then
  449. begin
  450. for i:=1 to idx do
  451. begin
  452. case upcase(s[i]) of
  453. 'F' :
  454. begin
  455. v:=v or V_Fatal;
  456. inc(status.errorcount);
  457. dostop:=true;
  458. end;
  459. 'E' :
  460. begin
  461. v:=v or V_Error;
  462. inc(status.errorcount);
  463. end;
  464. 'O' :
  465. v:=v or V_Normal;
  466. 'W':
  467. begin
  468. v:=v or V_Warning;
  469. if status.errorwarning then
  470. inc(status.errorcount);
  471. end;
  472. 'N' :
  473. begin
  474. v:=v or V_Note;
  475. if status.errornote then
  476. inc(status.errorcount);
  477. end;
  478. 'H' :
  479. begin
  480. v:=v or V_Hint;
  481. if status.errorhint then
  482. inc(status.errorcount);
  483. end;
  484. 'I' :
  485. v:=v or V_Info;
  486. 'L' :
  487. v:=v or V_LineInfo;
  488. 'U' :
  489. v:=v or V_Used;
  490. 'T' :
  491. v:=v or V_Tried;
  492. 'C' :
  493. v:=v or V_Conditional;
  494. 'D' :
  495. v:=v or V_Debug;
  496. 'X' :
  497. v:=v or V_Executable;
  498. 'S' :
  499. dostop:=true;
  500. '_' : ;
  501. end;
  502. end;
  503. end;
  504. Delete(s,1,idx);
  505. { check verbosity level }
  506. if not CheckVerbosity(v) then
  507. exit;
  508. if (v and V_LineInfoMask)<>0 then
  509. v:=v or V_LineInfo;
  510. { fix status }
  511. UpdateStatus;
  512. { Fix replacements }
  513. DefaultReplacements(s);
  514. { show comment }
  515. if do_comment(v,s) or dostop then
  516. stop(1);
  517. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  518. begin
  519. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  520. status.skip_error:=true;
  521. stop(1);
  522. end;
  523. end;
  524. function MessagePchar(w:longint):pchar;
  525. begin
  526. MaybeLoadMessageFile;
  527. MessagePchar:=msg^.GetPchar(w)
  528. end;
  529. procedure Message(w:longint);
  530. begin
  531. MaybeLoadMessageFile;
  532. Msg2Comment(msg^.Get(w,[]));
  533. end;
  534. procedure Message1(w:longint;const s1:string);
  535. {$ifdef ver1_0}
  536. var
  537. hs1 : string;
  538. {$endif ver1_0}
  539. begin
  540. MaybeLoadMessageFile;
  541. {$ifdef ver1_0}
  542. { 1.0.x is broken, it uses concatcopy instead of shortstring
  543. copy when passing array of shortstring. (PFV) }
  544. hs1:=s1;
  545. Msg2Comment(msg^.Get(w,[hs1]));
  546. {$else ver1_0}
  547. Msg2Comment(msg^.Get(w,[s1]));
  548. {$endif ver1_0}
  549. end;
  550. procedure Message2(w:longint;const s1,s2:string);
  551. {$ifdef ver1_0}
  552. var
  553. hs1,hs2 : string;
  554. {$endif ver1_0}
  555. begin
  556. MaybeLoadMessageFile;
  557. {$ifdef ver1_0}
  558. { 1.0.x is broken, it uses concatcopy instead of shortstring
  559. copy when passing array of shortstring. (PFV) }
  560. hs1:=s1;
  561. hs2:=s2;
  562. Msg2Comment(msg^.Get(w,[hs1,hs2]));
  563. {$else ver1_0}
  564. Msg2Comment(msg^.Get(w,[s1,s2]));
  565. {$endif ver1_0}
  566. end;
  567. procedure Message3(w:longint;const s1,s2,s3:string);
  568. {$ifdef ver1_0}
  569. var
  570. hs1,hs2,hs3 : string;
  571. {$endif ver1_0}
  572. begin
  573. MaybeLoadMessageFile;
  574. {$ifdef ver1_0}
  575. { 1.0.x is broken, it uses concatcopy instead of shortstring
  576. copy when passing array of shortstring. (PFV) }
  577. hs1:=s1;
  578. hs2:=s2;
  579. hs3:=s3;
  580. Msg2Comment(msg^.Get(w,[hs1,hs2,hs3]));
  581. {$else ver1_0}
  582. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  583. {$endif ver1_0}
  584. end;
  585. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  586. {$ifdef ver1_0}
  587. var
  588. hs1,hs2,hs3,hs4 : string;
  589. {$endif ver1_0}
  590. begin
  591. MaybeLoadMessageFile;
  592. {$ifdef ver1_0}
  593. { 1.0.x is broken, it uses concatcopy instead of shortstring
  594. copy when passing array of shortstring. (PFV) }
  595. hs1:=s1;
  596. hs2:=s2;
  597. hs3:=s3;
  598. hs4:=s4;
  599. Msg2Comment(msg^.Get(w,[hs1,hs2,hs3,hs4]));
  600. {$else ver1_0}
  601. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  602. {$endif ver1_0}
  603. end;
  604. procedure MessagePos(const pos:tfileposinfo;w:longint);
  605. var
  606. oldpos : tfileposinfo;
  607. begin
  608. oldpos:=aktfilepos;
  609. aktfilepos:=pos;
  610. MaybeLoadMessageFile;
  611. Msg2Comment(msg^.Get(w,[]));
  612. aktfilepos:=oldpos;
  613. end;
  614. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  615. var
  616. oldpos : tfileposinfo;
  617. begin
  618. oldpos:=aktfilepos;
  619. aktfilepos:=pos;
  620. MaybeLoadMessageFile;
  621. Msg2Comment(msg^.Get(w,[s1]));
  622. aktfilepos:=oldpos;
  623. end;
  624. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  625. var
  626. oldpos : tfileposinfo;
  627. begin
  628. oldpos:=aktfilepos;
  629. aktfilepos:=pos;
  630. MaybeLoadMessageFile;
  631. Msg2Comment(msg^.Get(w,[s1,s2]));
  632. aktfilepos:=oldpos;
  633. end;
  634. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  635. var
  636. oldpos : tfileposinfo;
  637. begin
  638. oldpos:=aktfilepos;
  639. aktfilepos:=pos;
  640. MaybeLoadMessageFile;
  641. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  642. aktfilepos:=oldpos;
  643. end;
  644. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  645. var
  646. oldpos : tfileposinfo;
  647. begin
  648. oldpos:=aktfilepos;
  649. aktfilepos:=pos;
  650. MaybeLoadMessageFile;
  651. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  652. aktfilepos:=oldpos;
  653. end;
  654. {*****************************************************************************
  655. override the message calls to set codegenerror
  656. *****************************************************************************}
  657. procedure cgmessage(t : longint);
  658. var
  659. olderrorcount : longint;
  660. begin
  661. if not(codegenerror) then
  662. begin
  663. olderrorcount:=Errorcount;
  664. verbose.Message(t);
  665. codegenerror:=olderrorcount<>Errorcount;
  666. end;
  667. end;
  668. procedure cgmessage1(t : longint;const s : string);
  669. var
  670. olderrorcount : longint;
  671. begin
  672. if not(codegenerror) then
  673. begin
  674. olderrorcount:=Errorcount;
  675. verbose.Message1(t,s);
  676. codegenerror:=olderrorcount<>Errorcount;
  677. end;
  678. end;
  679. procedure cgmessage2(t : longint;const s1,s2 : string);
  680. var
  681. olderrorcount : longint;
  682. begin
  683. if not(codegenerror) then
  684. begin
  685. olderrorcount:=Errorcount;
  686. verbose.Message2(t,s1,s2);
  687. codegenerror:=olderrorcount<>Errorcount;
  688. end;
  689. end;
  690. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  691. var
  692. olderrorcount : longint;
  693. begin
  694. if not(codegenerror) then
  695. begin
  696. olderrorcount:=Errorcount;
  697. verbose.Message3(t,s1,s2,s3);
  698. codegenerror:=olderrorcount<>Errorcount;
  699. end;
  700. end;
  701. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  702. var
  703. olderrorcount : longint;
  704. begin
  705. if not(codegenerror) then
  706. begin
  707. olderrorcount:=Errorcount;
  708. verbose.MessagePos(pos,t);
  709. codegenerror:=olderrorcount<>Errorcount;
  710. end;
  711. end;
  712. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  713. var
  714. olderrorcount : longint;
  715. begin
  716. if not(codegenerror) then
  717. begin
  718. olderrorcount:=Errorcount;
  719. verbose.MessagePos1(pos,t,s1);
  720. codegenerror:=olderrorcount<>Errorcount;
  721. end;
  722. end;
  723. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  724. var
  725. olderrorcount : longint;
  726. begin
  727. if not(codegenerror) then
  728. begin
  729. olderrorcount:=Errorcount;
  730. verbose.MessagePos2(pos,t,s1,s2);
  731. codegenerror:=olderrorcount<>Errorcount;
  732. end;
  733. end;
  734. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  735. var
  736. olderrorcount : longint;
  737. begin
  738. if not(codegenerror) then
  739. begin
  740. olderrorcount:=Errorcount;
  741. verbose.MessagePos3(pos,t,s1,s2,s3);
  742. codegenerror:=olderrorcount<>Errorcount;
  743. end;
  744. end;
  745. {*****************************************************************************
  746. Initialization
  747. *****************************************************************************}
  748. procedure InitVerbose;
  749. begin
  750. { Init }
  751. msg:=new(pmessage,Init(20,msgidxmax));
  752. if msg=nil then
  753. begin
  754. writeln('Fatal: MsgIdx Wrong');
  755. halt(3);
  756. end;
  757. {$ifndef EXTERN_MSG}
  758. msg^.LoadIntern(@msgtxt,msgtxtsize);
  759. {$else EXTERN_MSG}
  760. LoadMsgFile(exepath+'errore.msg');
  761. {$endif EXTERN_MSG}
  762. FillChar(Status,sizeof(TCompilerStatus),0);
  763. status.verbosity:=V_Default;
  764. Status.MaxErrorCount:=50;
  765. Loadprefixes;
  766. lastfileidx:=-1;
  767. lastmoduleidx:=-1;
  768. status.currentmodule:='';
  769. status.currentsource:='';
  770. status.currentsourcepath:='';
  771. status.compiling_current:=false;
  772. compiling_module:=nil;
  773. { Register internalerrorproc for cutils/cclasses }
  774. internalerrorproc:=@internalerror;
  775. end;
  776. procedure DoneVerbose;
  777. begin
  778. if assigned(msg) then
  779. begin
  780. dispose(msg,Done);
  781. msg:=nil;
  782. end;
  783. DoneRedirectFile;
  784. end;
  785. initialization
  786. finalization
  787. { Be sure to close the redirect files to flush all data }
  788. DoneRedirectFile;
  789. end.
  790. {
  791. $Log$
  792. Revision 1.39 2005-02-15 19:15:45 peter
  793. * Handle Control-C exception more cleanly
  794. Revision 1.38 2005/02/14 17:13:09 peter
  795. * truncate log
  796. Revision 1.37 2005/02/07 17:25:28 peter
  797. -vz for output to stderr
  798. Revision 1.36 2005/01/20 17:29:07 peter
  799. * fixed -vv
  800. }