verbose.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. {$IFNDEF MACOS_USE_FAKE_SYSUTILS}
  23. sysutils,
  24. {$ENDIF}
  25. cutils,
  26. globals,finput,
  27. cmsgs;
  28. {$ifndef EXTERN_MSG}
  29. {$i msgtxt.inc}
  30. {$endif}
  31. {$i msgidx.inc}
  32. Const
  33. { Levels }
  34. V_None = $0;
  35. V_Fatal = $1;
  36. V_Error = $2;
  37. V_Normal = $4; { doesn't show a text like Error: }
  38. V_Warning = $8;
  39. V_Note = $10;
  40. V_Hint = $20;
  41. V_LineInfoMask = $fff;
  42. { From here by default no line info }
  43. V_Info = $1000;
  44. V_Status = $2000;
  45. V_Used = $4000;
  46. V_Tried = $8000;
  47. V_Conditional = $10000;
  48. V_Debug = $20000;
  49. V_Executable = $40000;
  50. V_LevelMask = $fffffff;
  51. V_All = V_LevelMask;
  52. V_Default = V_Fatal + V_Error + V_Normal;
  53. { Flags }
  54. V_LineInfo = $10000000;
  55. var
  56. msg : pmessage;
  57. const
  58. msgfilename : string = '';
  59. type
  60. EControlCAbort=class(Exception)
  61. constructor Create;
  62. end;
  63. procedure SetRedirectFile(const fn:string);
  64. function SetVerbosity(const s:string):boolean;
  65. procedure PrepareReport;
  66. function CheckVerbosity(v:longint):boolean;
  67. procedure SetCompileModule(p:tmodulebase);
  68. procedure Stop(err:longint);
  69. procedure ShowStatus;
  70. function ErrorCount:longint;
  71. procedure SetErrorFlags(const s:string);
  72. procedure GenerateError;
  73. procedure Internalerror(i:longint);
  74. procedure Comment(l:longint;s:string);
  75. function MessagePchar(w:longint):pchar;
  76. procedure Message(w:longint);
  77. procedure Message1(w:longint;const s1:string);
  78. procedure Message2(w:longint;const s1,s2:string);
  79. procedure Message3(w:longint;const s1,s2,s3:string);
  80. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  81. procedure MessagePos(const pos:tfileposinfo;w:longint);
  82. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  83. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  84. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  85. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  86. { message calls with codegenerror support }
  87. procedure cgmessage(t : longint);
  88. procedure cgmessage1(t : longint;const s : string);
  89. procedure cgmessage2(t : longint;const s1,s2 : string);
  90. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  91. procedure CGMessagePos(const pos:tfileposinfo;t:longint);
  92. procedure CGMessagePos1(const pos:tfileposinfo;t:longint;const s1:string);
  93. procedure CGMessagePos2(const pos:tfileposinfo;t:longint;const s1,s2:string);
  94. procedure CGMessagePos3(const pos:tfileposinfo;t:longint;const s1,s2,s3:string);
  95. procedure InitVerbose;
  96. procedure DoneVerbose;
  97. implementation
  98. uses
  99. comphook;
  100. var
  101. compiling_module : tmodulebase;
  102. {****************************************************************************
  103. Control-C Exception
  104. ****************************************************************************}
  105. constructor EControlCAbort.Create;
  106. begin
  107. {$IFNDEF MACOS_USE_FAKE_SYSUTILS}
  108. inherited Create('Ctrl-C Signaled!');
  109. {$ELSE}
  110. inherited Create;
  111. {$ENDIF}
  112. end;
  113. {****************************************************************************
  114. Extra Handlers for default compiler
  115. ****************************************************************************}
  116. procedure DoneRedirectFile;
  117. begin
  118. if status.use_redir then
  119. begin
  120. close(status.redirfile);
  121. status.use_redir:=false;
  122. end;
  123. if status.use_bugreport then
  124. begin
  125. close(status.reportbugfile);
  126. status.use_bugreport:=false;
  127. end;
  128. end;
  129. procedure SetRedirectFile(const fn:string);
  130. begin
  131. assign(status.redirfile,fn);
  132. {$I-}
  133. append(status.redirfile);
  134. if ioresult <> 0 then
  135. rewrite(status.redirfile);
  136. {$I+}
  137. status.use_redir:=(ioresult=0);
  138. end;
  139. procedure PrepareReport;
  140. var
  141. fn : string;
  142. begin
  143. if status.use_bugreport then
  144. exit;
  145. fn:='fpcdebug.txt';
  146. assign(status.reportbugfile,fn);
  147. {$I-}
  148. append(status.reportbugfile);
  149. if ioresult <> 0 then
  150. rewrite(status.reportbugfile);
  151. {$I+}
  152. status.use_bugreport:=(ioresult=0);
  153. if status.use_bugreport then
  154. writeln(status.reportbugfile,'FPC bug report file');
  155. end;
  156. function CheckVerbosity(v:longint):boolean;
  157. begin
  158. CheckVerbosity:=status.use_bugreport or
  159. ((status.verbosity and (v and V_LevelMask))=(v and V_LevelMask));
  160. end;
  161. function SetVerbosity(const s:string):boolean;
  162. var
  163. m : Longint;
  164. i : Integer;
  165. inverse : boolean;
  166. c : char;
  167. begin
  168. Setverbosity:=false;
  169. val(s,m,i);
  170. if (i=0) and (s<>'') then
  171. status.verbosity:=m
  172. else
  173. begin
  174. i:=1;
  175. while i<=length(s) do
  176. begin
  177. c:=upcase(s[i]);
  178. inverse:=false;
  179. { on/off ? }
  180. if (i<length(s)) then
  181. case s[i+1] of
  182. '-' : begin
  183. inc(i);
  184. inverse:=true;
  185. end;
  186. '+' : inc(i);
  187. end;
  188. { handle switch }
  189. case c of
  190. { Special cases }
  191. 'A' : status.verbosity:=V_All;
  192. '0' : status.verbosity:=V_Default;
  193. 'P' : begin
  194. if inverse then
  195. paraprintnodetree:=0
  196. else
  197. paraprintnodetree:=1;
  198. end;
  199. 'R' : begin
  200. if inverse then
  201. begin
  202. status.use_gccoutput:=false;
  203. status.use_stderr:=false;
  204. end
  205. else
  206. begin
  207. status.use_gccoutput:=true;
  208. status.use_stderr:=true;
  209. end;
  210. end;
  211. 'Z' : begin
  212. if inverse then
  213. status.use_stderr:=false
  214. else
  215. status.use_stderr:=true;
  216. end;
  217. { Normal cases - do an or }
  218. 'E' : if inverse then
  219. status.verbosity:=status.verbosity and (not V_Error)
  220. else
  221. status.verbosity:=status.verbosity or V_Error;
  222. 'I' : if inverse then
  223. status.verbosity:=status.verbosity and (not V_Info)
  224. else
  225. status.verbosity:=status.verbosity or V_Info;
  226. 'W' : if inverse then
  227. status.verbosity:=status.verbosity and (not V_Warning)
  228. else
  229. status.verbosity:=status.verbosity or V_Warning;
  230. 'N' : if inverse then
  231. status.verbosity:=status.verbosity and (not V_Note)
  232. else
  233. status.verbosity:=status.verbosity or V_Note;
  234. 'H' : if inverse then
  235. status.verbosity:=status.verbosity and (not V_Hint)
  236. else
  237. status.verbosity:=status.verbosity or V_Hint;
  238. 'L' : if inverse then
  239. status.verbosity:=status.verbosity and (not V_Status)
  240. else
  241. status.verbosity:=status.verbosity or V_Status;
  242. 'U' : if inverse then
  243. status.verbosity:=status.verbosity and (not V_Used)
  244. else
  245. status.verbosity:=status.verbosity or V_Used;
  246. 'T' : if inverse then
  247. status.verbosity:=status.verbosity and (not V_Tried)
  248. else
  249. status.verbosity:=status.verbosity or V_Tried;
  250. 'C' : if inverse then
  251. status.verbosity:=status.verbosity and (not V_Conditional)
  252. else
  253. status.verbosity:=status.verbosity or V_Conditional;
  254. 'D' : if inverse then
  255. status.verbosity:=status.verbosity and (not V_Debug)
  256. else
  257. status.verbosity:=status.verbosity or V_Debug;
  258. 'X' : if inverse then
  259. status.verbosity:=status.verbosity and (not V_Executable)
  260. else
  261. status.verbosity:=status.verbosity or V_Executable;
  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. procedure SetCompileModule(p:tmodulebase);
  321. begin
  322. compiling_module:=p;
  323. end;
  324. var
  325. lastfileidx,
  326. lastmoduleidx : longint;
  327. Procedure UpdateStatus;
  328. begin
  329. { fix status }
  330. status.currentline:=aktfilepos.line;
  331. status.currentcolumn:=aktfilepos.column;
  332. if assigned(compiling_module) and
  333. assigned(compiling_module.sourcefiles) and
  334. ((compiling_module.unit_index<>lastmoduleidx) or
  335. (aktfilepos.fileindex<>lastfileidx)) then
  336. begin
  337. { update status record }
  338. status.currentmodule:=compiling_module.modulename^;
  339. status.currentsource:=compiling_module.sourcefiles.get_file_name(aktfilepos.fileindex);
  340. status.currentsourcepath:=compiling_module.sourcefiles.get_file_path(aktfilepos.fileindex);
  341. { update lastfileidx only if name known PM }
  342. if status.currentsource<>'' then
  343. lastfileidx:=aktfilepos.fileindex
  344. else
  345. lastfileidx:=0;
  346. lastmoduleidx:=compiling_module.unit_index;
  347. end;
  348. if assigned(compiling_module) then
  349. status.compiling_current:=(compiling_module.state in [ms_compile,ms_second_compile]);
  350. end;
  351. procedure stop(err:longint);
  352. begin
  353. do_stop(err);
  354. end;
  355. procedure ShowStatus;
  356. begin
  357. UpdateStatus;
  358. if do_status() then
  359. stop(1);
  360. end;
  361. function ErrorCount:longint;
  362. begin
  363. ErrorCount:=status.errorcount;
  364. end;
  365. procedure SetErrorFlags(const s:string);
  366. var
  367. code : integer;
  368. i,j,l : longint;
  369. begin
  370. { empty string means error count = 1 for backward compatibility (PFV) }
  371. if s='' then
  372. begin
  373. status.maxerrorcount:=1;
  374. exit;
  375. end;
  376. i:=0;
  377. while (i<length(s)) do
  378. begin
  379. inc(i);
  380. case s[i] of
  381. '0'..'9' :
  382. begin
  383. j:=i;
  384. while (j<=length(s)) and (s[j] in ['0'..'9']) do
  385. inc(j);
  386. val(copy(s,i,j-i),l,code);
  387. if code<>0 then
  388. l:=1;
  389. status.maxerrorcount:=l;
  390. i:=j;
  391. end;
  392. 'w','W' :
  393. status.errorwarning:=true;
  394. 'n','N' :
  395. status.errornote:=true;
  396. 'h','H' :
  397. status.errorhint:=true;
  398. end;
  399. end;
  400. end;
  401. procedure GenerateError;
  402. begin
  403. inc(status.errorcount);
  404. end;
  405. procedure internalerror(i : longint);
  406. begin
  407. UpdateStatus;
  408. do_internalerror(i);
  409. inc(status.errorcount);
  410. stop(1);
  411. end;
  412. procedure Comment(l:longint;s:string);
  413. var
  414. dostop : boolean;
  415. begin
  416. dostop:=((l and V_Fatal)<>0);
  417. if ((l and V_Error)<>0) or
  418. (status.errorwarning and ((l and V_Warning)<>0)) or
  419. (status.errornote and ((l and V_Note)<>0)) or
  420. (status.errorhint and ((l and V_Hint)<>0)) then
  421. inc(status.errorcount);
  422. { check verbosity level }
  423. if not CheckVerbosity(l) then
  424. exit;
  425. if (l and V_LineInfoMask)<>0 then
  426. l:=l or V_LineInfo;
  427. { Create status info }
  428. UpdateStatus;
  429. { Fix replacements }
  430. DefaultReplacements(s);
  431. { show comment }
  432. if do_comment(l,s) or dostop then
  433. stop(1);
  434. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  435. begin
  436. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  437. status.skip_error:=true;
  438. stop(1);
  439. end;
  440. end;
  441. Procedure Msg2Comment(s:string);
  442. var
  443. idx,i,v : longint;
  444. dostop : boolean;
  445. begin
  446. {Reset}
  447. dostop:=false;
  448. v:=0;
  449. {Parse options}
  450. idx:=pos('_',s);
  451. if idx=0 then
  452. v:=V_Normal
  453. else
  454. if (idx >= 1) And (idx <= 5) then
  455. begin
  456. for i:=1 to idx do
  457. begin
  458. case upcase(s[i]) of
  459. 'F' :
  460. begin
  461. v:=v or V_Fatal;
  462. inc(status.errorcount);
  463. dostop:=true;
  464. end;
  465. 'E' :
  466. begin
  467. v:=v or V_Error;
  468. inc(status.errorcount);
  469. end;
  470. 'O' :
  471. v:=v or V_Normal;
  472. 'W':
  473. begin
  474. v:=v or V_Warning;
  475. if status.errorwarning then
  476. inc(status.errorcount);
  477. end;
  478. 'N' :
  479. begin
  480. v:=v or V_Note;
  481. if status.errornote then
  482. inc(status.errorcount);
  483. end;
  484. 'H' :
  485. begin
  486. v:=v or V_Hint;
  487. if status.errorhint then
  488. inc(status.errorcount);
  489. end;
  490. 'I' :
  491. v:=v or V_Info;
  492. 'L' :
  493. v:=v or V_LineInfo;
  494. 'U' :
  495. v:=v or V_Used;
  496. 'T' :
  497. v:=v or V_Tried;
  498. 'C' :
  499. v:=v or V_Conditional;
  500. 'D' :
  501. v:=v or V_Debug;
  502. 'X' :
  503. v:=v or V_Executable;
  504. 'S' :
  505. dostop:=true;
  506. '_' : ;
  507. end;
  508. end;
  509. end;
  510. Delete(s,1,idx);
  511. { check verbosity level }
  512. if not CheckVerbosity(v) then
  513. exit;
  514. if (v and V_LineInfoMask)<>0 then
  515. v:=v or V_LineInfo;
  516. { fix status }
  517. UpdateStatus;
  518. { Fix replacements }
  519. DefaultReplacements(s);
  520. { show comment }
  521. if do_comment(v,s) or dostop then
  522. stop(1);
  523. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  524. begin
  525. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  526. status.skip_error:=true;
  527. stop(1);
  528. end;
  529. end;
  530. function MessagePchar(w:longint):pchar;
  531. begin
  532. MaybeLoadMessageFile;
  533. MessagePchar:=msg^.GetPchar(w)
  534. end;
  535. procedure Message(w:longint);
  536. begin
  537. MaybeLoadMessageFile;
  538. Msg2Comment(msg^.Get(w,[]));
  539. end;
  540. procedure Message1(w:longint;const s1:string);
  541. {$ifdef ver1_0}
  542. var
  543. hs1 : string;
  544. {$endif ver1_0}
  545. begin
  546. MaybeLoadMessageFile;
  547. {$ifdef ver1_0}
  548. { 1.0.x is broken, it uses concatcopy instead of shortstring
  549. copy when passing array of shortstring. (PFV) }
  550. hs1:=s1;
  551. Msg2Comment(msg^.Get(w,[hs1]));
  552. {$else ver1_0}
  553. Msg2Comment(msg^.Get(w,[s1]));
  554. {$endif ver1_0}
  555. end;
  556. procedure Message2(w:longint;const s1,s2:string);
  557. {$ifdef ver1_0}
  558. var
  559. hs1,hs2 : string;
  560. {$endif ver1_0}
  561. begin
  562. MaybeLoadMessageFile;
  563. {$ifdef ver1_0}
  564. { 1.0.x is broken, it uses concatcopy instead of shortstring
  565. copy when passing array of shortstring. (PFV) }
  566. hs1:=s1;
  567. hs2:=s2;
  568. Msg2Comment(msg^.Get(w,[hs1,hs2]));
  569. {$else ver1_0}
  570. Msg2Comment(msg^.Get(w,[s1,s2]));
  571. {$endif ver1_0}
  572. end;
  573. procedure Message3(w:longint;const s1,s2,s3:string);
  574. {$ifdef ver1_0}
  575. var
  576. hs1,hs2,hs3 : string;
  577. {$endif ver1_0}
  578. begin
  579. MaybeLoadMessageFile;
  580. {$ifdef ver1_0}
  581. { 1.0.x is broken, it uses concatcopy instead of shortstring
  582. copy when passing array of shortstring. (PFV) }
  583. hs1:=s1;
  584. hs2:=s2;
  585. hs3:=s3;
  586. Msg2Comment(msg^.Get(w,[hs1,hs2,hs3]));
  587. {$else ver1_0}
  588. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  589. {$endif ver1_0}
  590. end;
  591. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  592. {$ifdef ver1_0}
  593. var
  594. hs1,hs2,hs3,hs4 : string;
  595. {$endif ver1_0}
  596. begin
  597. MaybeLoadMessageFile;
  598. {$ifdef ver1_0}
  599. { 1.0.x is broken, it uses concatcopy instead of shortstring
  600. copy when passing array of shortstring. (PFV) }
  601. hs1:=s1;
  602. hs2:=s2;
  603. hs3:=s3;
  604. hs4:=s4;
  605. Msg2Comment(msg^.Get(w,[hs1,hs2,hs3,hs4]));
  606. {$else ver1_0}
  607. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  608. {$endif ver1_0}
  609. end;
  610. procedure MessagePos(const pos:tfileposinfo;w:longint);
  611. var
  612. oldpos : tfileposinfo;
  613. begin
  614. oldpos:=aktfilepos;
  615. aktfilepos:=pos;
  616. MaybeLoadMessageFile;
  617. Msg2Comment(msg^.Get(w,[]));
  618. aktfilepos:=oldpos;
  619. end;
  620. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  621. var
  622. oldpos : tfileposinfo;
  623. begin
  624. oldpos:=aktfilepos;
  625. aktfilepos:=pos;
  626. MaybeLoadMessageFile;
  627. Msg2Comment(msg^.Get(w,[s1]));
  628. aktfilepos:=oldpos;
  629. end;
  630. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  631. var
  632. oldpos : tfileposinfo;
  633. begin
  634. oldpos:=aktfilepos;
  635. aktfilepos:=pos;
  636. MaybeLoadMessageFile;
  637. Msg2Comment(msg^.Get(w,[s1,s2]));
  638. aktfilepos:=oldpos;
  639. end;
  640. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  641. var
  642. oldpos : tfileposinfo;
  643. begin
  644. oldpos:=aktfilepos;
  645. aktfilepos:=pos;
  646. MaybeLoadMessageFile;
  647. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  648. aktfilepos:=oldpos;
  649. end;
  650. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  651. var
  652. oldpos : tfileposinfo;
  653. begin
  654. oldpos:=aktfilepos;
  655. aktfilepos:=pos;
  656. MaybeLoadMessageFile;
  657. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  658. aktfilepos:=oldpos;
  659. end;
  660. {*****************************************************************************
  661. override the message calls to set codegenerror
  662. *****************************************************************************}
  663. procedure cgmessage(t : longint);
  664. var
  665. olderrorcount : longint;
  666. begin
  667. if not(codegenerror) then
  668. begin
  669. olderrorcount:=Errorcount;
  670. verbose.Message(t);
  671. codegenerror:=olderrorcount<>Errorcount;
  672. end;
  673. end;
  674. procedure cgmessage1(t : longint;const s : string);
  675. var
  676. olderrorcount : longint;
  677. begin
  678. if not(codegenerror) then
  679. begin
  680. olderrorcount:=Errorcount;
  681. verbose.Message1(t,s);
  682. codegenerror:=olderrorcount<>Errorcount;
  683. end;
  684. end;
  685. procedure cgmessage2(t : longint;const s1,s2 : string);
  686. var
  687. olderrorcount : longint;
  688. begin
  689. if not(codegenerror) then
  690. begin
  691. olderrorcount:=Errorcount;
  692. verbose.Message2(t,s1,s2);
  693. codegenerror:=olderrorcount<>Errorcount;
  694. end;
  695. end;
  696. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  697. var
  698. olderrorcount : longint;
  699. begin
  700. if not(codegenerror) then
  701. begin
  702. olderrorcount:=Errorcount;
  703. verbose.Message3(t,s1,s2,s3);
  704. codegenerror:=olderrorcount<>Errorcount;
  705. end;
  706. end;
  707. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  708. var
  709. olderrorcount : longint;
  710. begin
  711. if not(codegenerror) then
  712. begin
  713. olderrorcount:=Errorcount;
  714. verbose.MessagePos(pos,t);
  715. codegenerror:=olderrorcount<>Errorcount;
  716. end;
  717. end;
  718. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  719. var
  720. olderrorcount : longint;
  721. begin
  722. if not(codegenerror) then
  723. begin
  724. olderrorcount:=Errorcount;
  725. verbose.MessagePos1(pos,t,s1);
  726. codegenerror:=olderrorcount<>Errorcount;
  727. end;
  728. end;
  729. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  730. var
  731. olderrorcount : longint;
  732. begin
  733. if not(codegenerror) then
  734. begin
  735. olderrorcount:=Errorcount;
  736. verbose.MessagePos2(pos,t,s1,s2);
  737. codegenerror:=olderrorcount<>Errorcount;
  738. end;
  739. end;
  740. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  741. var
  742. olderrorcount : longint;
  743. begin
  744. if not(codegenerror) then
  745. begin
  746. olderrorcount:=Errorcount;
  747. verbose.MessagePos3(pos,t,s1,s2,s3);
  748. codegenerror:=olderrorcount<>Errorcount;
  749. end;
  750. end;
  751. {*****************************************************************************
  752. Initialization
  753. *****************************************************************************}
  754. procedure InitVerbose;
  755. begin
  756. { Init }
  757. msg:=new(pmessage,Init(20,msgidxmax));
  758. if msg=nil then
  759. begin
  760. writeln('Fatal: MsgIdx Wrong');
  761. halt(3);
  762. end;
  763. {$ifndef EXTERN_MSG}
  764. msg^.LoadIntern(@msgtxt,msgtxtsize);
  765. {$else EXTERN_MSG}
  766. LoadMsgFile(exepath+'errore.msg');
  767. {$endif EXTERN_MSG}
  768. FillChar(Status,sizeof(TCompilerStatus),0);
  769. status.verbosity:=V_Default;
  770. Status.MaxErrorCount:=50;
  771. Loadprefixes;
  772. lastfileidx:=-1;
  773. lastmoduleidx:=-1;
  774. status.currentmodule:='';
  775. status.currentsource:='';
  776. status.currentsourcepath:='';
  777. status.compiling_current:=false;
  778. compiling_module:=nil;
  779. { Register internalerrorproc for cutils/cclasses }
  780. internalerrorproc:=@internalerror;
  781. end;
  782. procedure DoneVerbose;
  783. begin
  784. if assigned(msg) then
  785. begin
  786. dispose(msg,Done);
  787. msg:=nil;
  788. end;
  789. DoneRedirectFile;
  790. end;
  791. initialization
  792. finalization
  793. { Be sure to close the redirect files to flush all data }
  794. DoneRedirectFile;
  795. end.
  796. {
  797. $Log$
  798. Revision 1.40 2005-02-16 22:39:25 olle
  799. * made macos compile
  800. Revision 1.39 2005/02/15 19:15:45 peter
  801. * Handle Control-C exception more cleanly
  802. Revision 1.38 2005/02/14 17:13:09 peter
  803. * truncate log
  804. Revision 1.37 2005/02/07 17:25:28 peter
  805. -vz for output to stderr
  806. Revision 1.36 2005/01/20 17:29:07 peter
  807. * fixed -vv
  808. }