verbose.pas 25 KB

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