verbose.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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 MACOS_USE_FAKE_SYSUTILS}
  22. sysutils,
  23. {$ENDIF}
  24. cutils,
  25. globals,finput,
  26. cmsgs;
  27. {$ifndef EXTERN_MSG}
  28. {$i msgtxt.inc}
  29. {$endif}
  30. {$i msgidx.inc}
  31. Const
  32. { Levels }
  33. V_None = $0;
  34. V_Fatal = $1;
  35. V_Error = $2;
  36. V_Normal = $4; { doesn't show a text like Error: }
  37. V_Warning = $8;
  38. V_Note = $10;
  39. V_Hint = $20;
  40. V_LineInfoMask = $fff;
  41. { From here by default no line info }
  42. V_Info = $1000;
  43. V_Status = $2000;
  44. V_Used = $4000;
  45. V_Tried = $8000;
  46. V_Conditional = $10000;
  47. V_Debug = $20000;
  48. V_Executable = $40000;
  49. V_LevelMask = $fffffff;
  50. V_All = V_LevelMask;
  51. V_Default = V_Fatal + V_Error + V_Normal;
  52. { Flags }
  53. V_LineInfo = $10000000;
  54. var
  55. msg : pmessage;
  56. const
  57. msgfilename : string = '';
  58. procedure SetRedirectFile(const fn:string);
  59. function SetVerbosity(const s:string):boolean;
  60. procedure PrepareReport;
  61. function CheckVerbosity(v:longint):boolean;
  62. procedure SetCompileModule(p:tmodulebase);
  63. procedure ShowStatus;
  64. function ErrorCount:longint;
  65. procedure SetErrorFlags(const s:string);
  66. procedure GenerateError;
  67. procedure Internalerror(i:longint);
  68. procedure Comment(l:longint;s:string);
  69. function MessagePchar(w:longint):pchar;
  70. procedure Message(w:longint);
  71. procedure Message1(w:longint;const s1:string);
  72. procedure Message2(w:longint;const s1,s2:string);
  73. procedure Message3(w:longint;const s1,s2,s3:string);
  74. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  75. procedure MessagePos(const pos:tfileposinfo;w:longint);
  76. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  77. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  78. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  79. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  80. { message calls with codegenerror support }
  81. procedure cgmessage(t : longint);
  82. procedure cgmessage1(t : longint;const s : string);
  83. procedure cgmessage2(t : longint;const s1,s2 : string);
  84. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  85. procedure CGMessagePos(const pos:tfileposinfo;t:longint);
  86. procedure CGMessagePos1(const pos:tfileposinfo;t:longint;const s1:string);
  87. procedure CGMessagePos2(const pos:tfileposinfo;t:longint;const s1,s2:string);
  88. procedure CGMessagePos3(const pos:tfileposinfo;t:longint;const s1,s2,s3:string);
  89. procedure FlushOutput;
  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. 'B' : begin
  177. if inverse then
  178. status.print_source_path:=false
  179. else
  180. status.print_source_path:=true;
  181. end;
  182. '0' : status.verbosity:=V_Default;
  183. 'P' : begin
  184. if inverse then
  185. paraprintnodetree:=0
  186. else
  187. paraprintnodetree:=1;
  188. end;
  189. 'R' : begin
  190. if inverse then
  191. begin
  192. status.use_gccoutput:=false;
  193. status.use_stderr:=false;
  194. end
  195. else
  196. begin
  197. status.use_gccoutput:=true;
  198. status.use_stderr:=true;
  199. end;
  200. end;
  201. 'Z' : begin
  202. if inverse then
  203. status.use_stderr:=false
  204. else
  205. status.use_stderr:=true;
  206. end;
  207. { Normal cases - do an or }
  208. 'E' : if inverse then
  209. status.verbosity:=status.verbosity and (not V_Error)
  210. else
  211. status.verbosity:=status.verbosity or V_Error;
  212. 'I' : if inverse then
  213. status.verbosity:=status.verbosity and (not V_Info)
  214. else
  215. status.verbosity:=status.verbosity or V_Info;
  216. 'W' : if inverse then
  217. status.verbosity:=status.verbosity and (not V_Warning)
  218. else
  219. status.verbosity:=status.verbosity or V_Warning;
  220. 'N' : if inverse then
  221. status.verbosity:=status.verbosity and (not V_Note)
  222. else
  223. status.verbosity:=status.verbosity or V_Note;
  224. 'H' : if inverse then
  225. status.verbosity:=status.verbosity and (not V_Hint)
  226. else
  227. status.verbosity:=status.verbosity or V_Hint;
  228. 'L' : if inverse then
  229. status.verbosity:=status.verbosity and (not V_Status)
  230. else
  231. status.verbosity:=status.verbosity or V_Status;
  232. 'U' : if inverse then
  233. status.verbosity:=status.verbosity and (not V_Used)
  234. else
  235. status.verbosity:=status.verbosity or V_Used;
  236. 'T' : if inverse then
  237. status.verbosity:=status.verbosity and (not V_Tried)
  238. else
  239. status.verbosity:=status.verbosity or V_Tried;
  240. 'C' : if inverse then
  241. status.verbosity:=status.verbosity and (not V_Conditional)
  242. else
  243. status.verbosity:=status.verbosity or V_Conditional;
  244. 'D' : if inverse then
  245. status.verbosity:=status.verbosity and (not V_Debug)
  246. else
  247. status.verbosity:=status.verbosity or V_Debug;
  248. 'X' : if inverse then
  249. status.verbosity:=status.verbosity and (not V_Executable)
  250. else
  251. status.verbosity:=status.verbosity or V_Executable;
  252. 'V' : PrepareReport;
  253. end;
  254. inc(i);
  255. end;
  256. end;
  257. if status.verbosity=0 then
  258. status.verbosity:=V_Default;
  259. setverbosity:=true;
  260. end;
  261. procedure Loadprefixes;
  262. function loadprefix(w:longint):string;
  263. var
  264. s : string;
  265. idx : longint;
  266. begin
  267. s:=msg^.get(w,[]);
  268. idx:=pos('_',s);
  269. if idx>0 then
  270. Loadprefix:=Copy(s,idx+1,255)
  271. else
  272. Loadprefix:=s;
  273. end;
  274. begin
  275. { Load the prefixes }
  276. fatalstr:=Loadprefix(general_i_fatal);
  277. errorstr:=Loadprefix(general_i_error);
  278. warningstr:=Loadprefix(general_i_warning);
  279. notestr:=Loadprefix(general_i_note);
  280. hintstr:=Loadprefix(general_i_hint);
  281. end;
  282. procedure LoadMsgFile(const fn:string);
  283. begin
  284. { reload the internal messages if not already loaded }
  285. {$ifndef EXTERN_MSG}
  286. if not msg^.msgintern then
  287. msg^.LoadIntern(@msgtxt,msgtxtsize);
  288. {$endif}
  289. if not msg^.LoadExtern(fn) then
  290. begin
  291. {$ifdef EXTERN_MSG}
  292. writeln('Fatal: Cannot find error message file.');
  293. halt(3);
  294. {$else}
  295. msg^.LoadIntern(@msgtxt,msgtxtsize);
  296. {$endif}
  297. end;
  298. { reload the prefixes using the new messages }
  299. Loadprefixes;
  300. end;
  301. procedure MaybeLoadMessageFile;
  302. begin
  303. { Load new message file }
  304. if (msgfilename<>'') then
  305. begin
  306. LoadMsgFile(msgfilename);
  307. msgfilename:='';
  308. end;
  309. end;
  310. procedure SetCompileModule(p:tmodulebase);
  311. begin
  312. compiling_module:=p;
  313. end;
  314. var
  315. lastfileidx,
  316. lastmoduleidx : longint;
  317. Procedure UpdateStatus;
  318. begin
  319. { fix status }
  320. status.currentline:=aktfilepos.line;
  321. status.currentcolumn:=aktfilepos.column;
  322. if assigned(compiling_module) and
  323. assigned(compiling_module.sourcefiles) and
  324. ((compiling_module.unit_index<>lastmoduleidx) or
  325. (aktfilepos.fileindex<>lastfileidx)) then
  326. begin
  327. { update status record }
  328. status.currentmodule:=compiling_module.modulename^;
  329. status.currentsource:=compiling_module.sourcefiles.get_file_name(aktfilepos.fileindex);
  330. status.currentsourcepath:=compiling_module.sourcefiles.get_file_path(aktfilepos.fileindex);
  331. { update lastfileidx only if name known PM }
  332. if status.currentsource<>'' then
  333. lastfileidx:=aktfilepos.fileindex
  334. else
  335. lastfileidx:=0;
  336. lastmoduleidx:=compiling_module.unit_index;
  337. end;
  338. if assigned(compiling_module) then
  339. status.compiling_current:=(compiling_module.state in [ms_compile,ms_second_compile]);
  340. end;
  341. procedure ShowStatus;
  342. begin
  343. UpdateStatus;
  344. if do_status() then
  345. raise ECompilerAbort.Create;
  346. end;
  347. function ErrorCount:longint;
  348. begin
  349. ErrorCount:=status.errorcount;
  350. end;
  351. procedure SetErrorFlags(const s:string);
  352. var
  353. code : integer;
  354. i,j,l : longint;
  355. begin
  356. { empty string means error count = 1 for backward compatibility (PFV) }
  357. if s='' then
  358. begin
  359. status.maxerrorcount:=1;
  360. exit;
  361. end;
  362. i:=0;
  363. while (i<length(s)) do
  364. begin
  365. inc(i);
  366. case s[i] of
  367. '0'..'9' :
  368. begin
  369. j:=i;
  370. while (j<=length(s)) and (s[j] in ['0'..'9']) do
  371. inc(j);
  372. val(copy(s,i,j-i),l,code);
  373. if code<>0 then
  374. l:=1;
  375. status.maxerrorcount:=l;
  376. i:=j;
  377. end;
  378. 'w','W' :
  379. status.errorwarning:=true;
  380. 'n','N' :
  381. status.errornote:=true;
  382. 'h','H' :
  383. status.errorhint:=true;
  384. end;
  385. end;
  386. end;
  387. procedure GenerateError;
  388. begin
  389. inc(status.errorcount);
  390. end;
  391. procedure internalerror(i : longint);
  392. begin
  393. UpdateStatus;
  394. do_internalerror(i);
  395. inc(status.errorcount);
  396. raise ECompilerAbort.Create;
  397. end;
  398. procedure Comment(l:longint;s:string);
  399. var
  400. dostop : boolean;
  401. begin
  402. dostop:=((l and V_Fatal)<>0);
  403. if ((l and V_Error)<>0) or
  404. (status.errorwarning and ((l and V_Warning)<>0)) or
  405. (status.errornote and ((l and V_Note)<>0)) or
  406. (status.errorhint and ((l and V_Hint)<>0)) then
  407. inc(status.errorcount);
  408. { check verbosity level }
  409. if not CheckVerbosity(l) then
  410. exit;
  411. if (l and V_LineInfoMask)<>0 then
  412. l:=l or V_LineInfo;
  413. { Create status info }
  414. UpdateStatus;
  415. { Fix replacements }
  416. DefaultReplacements(s);
  417. { show comment }
  418. if do_comment(l,s) or dostop then
  419. raise ECompilerAbort.Create;
  420. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  421. begin
  422. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  423. status.skip_error:=true;
  424. raise ECompilerAbort.Create;
  425. end;
  426. end;
  427. Procedure Msg2Comment(s:string);
  428. var
  429. idx,i,v : longint;
  430. dostop : boolean;
  431. begin
  432. {Reset}
  433. dostop:=false;
  434. v:=0;
  435. {Parse options}
  436. idx:=pos('_',s);
  437. if idx=0 then
  438. v:=V_Normal
  439. else
  440. if (idx >= 1) And (idx <= 5) then
  441. begin
  442. for i:=1 to idx do
  443. begin
  444. case upcase(s[i]) of
  445. 'F' :
  446. begin
  447. v:=v or V_Fatal;
  448. inc(status.errorcount);
  449. dostop:=true;
  450. end;
  451. 'E' :
  452. begin
  453. v:=v or V_Error;
  454. inc(status.errorcount);
  455. end;
  456. 'O' :
  457. v:=v or V_Normal;
  458. 'W':
  459. begin
  460. v:=v or V_Warning;
  461. if status.errorwarning then
  462. inc(status.errorcount)
  463. else
  464. inc(status.countWarnings);
  465. end;
  466. 'N' :
  467. begin
  468. v:=v or V_Note;
  469. if status.errornote then
  470. inc(status.errorcount)
  471. else
  472. inc(status.countNotes);
  473. end;
  474. 'H' :
  475. begin
  476. v:=v or V_Hint;
  477. if status.errorhint then
  478. inc(status.errorcount)
  479. else
  480. inc(status.countHints);
  481. end;
  482. 'I' :
  483. v:=v or V_Info;
  484. 'L' :
  485. v:=v or V_LineInfo;
  486. 'U' :
  487. v:=v or V_Used;
  488. 'T' :
  489. v:=v or V_Tried;
  490. 'C' :
  491. v:=v or V_Conditional;
  492. 'D' :
  493. v:=v or V_Debug;
  494. 'X' :
  495. v:=v or V_Executable;
  496. 'S' :
  497. dostop:=true;
  498. '_' : ;
  499. end;
  500. end;
  501. end;
  502. Delete(s,1,idx);
  503. { check verbosity level }
  504. if not CheckVerbosity(v) then
  505. exit;
  506. if (v and V_LineInfoMask)<>0 then
  507. v:=v or V_LineInfo;
  508. { fix status }
  509. UpdateStatus;
  510. { Fix replacements }
  511. DefaultReplacements(s);
  512. { show comment }
  513. if do_comment(v,s) or dostop then
  514. raise ECompilerAbort.Create;
  515. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  516. begin
  517. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  518. status.skip_error:=true;
  519. raise ECompilerAbort.Create;
  520. end;
  521. end;
  522. function MessagePchar(w:longint):pchar;
  523. begin
  524. MaybeLoadMessageFile;
  525. MessagePchar:=msg^.GetPchar(w)
  526. end;
  527. procedure Message(w:longint);
  528. begin
  529. MaybeLoadMessageFile;
  530. Msg2Comment(msg^.Get(w,[]));
  531. end;
  532. procedure Message1(w:longint;const s1:string);
  533. begin
  534. MaybeLoadMessageFile;
  535. Msg2Comment(msg^.Get(w,[s1]));
  536. end;
  537. procedure Message2(w:longint;const s1,s2:string);
  538. begin
  539. MaybeLoadMessageFile;
  540. Msg2Comment(msg^.Get(w,[s1,s2]));
  541. end;
  542. procedure Message3(w:longint;const s1,s2,s3:string);
  543. begin
  544. MaybeLoadMessageFile;
  545. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  546. end;
  547. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  548. begin
  549. MaybeLoadMessageFile;
  550. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  551. end;
  552. procedure MessagePos(const pos:tfileposinfo;w:longint);
  553. var
  554. oldpos : tfileposinfo;
  555. begin
  556. oldpos:=aktfilepos;
  557. aktfilepos:=pos;
  558. MaybeLoadMessageFile;
  559. Msg2Comment(msg^.Get(w,[]));
  560. aktfilepos:=oldpos;
  561. end;
  562. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  563. var
  564. oldpos : tfileposinfo;
  565. begin
  566. oldpos:=aktfilepos;
  567. aktfilepos:=pos;
  568. MaybeLoadMessageFile;
  569. Msg2Comment(msg^.Get(w,[s1]));
  570. aktfilepos:=oldpos;
  571. end;
  572. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  573. var
  574. oldpos : tfileposinfo;
  575. begin
  576. oldpos:=aktfilepos;
  577. aktfilepos:=pos;
  578. MaybeLoadMessageFile;
  579. Msg2Comment(msg^.Get(w,[s1,s2]));
  580. aktfilepos:=oldpos;
  581. end;
  582. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  583. var
  584. oldpos : tfileposinfo;
  585. begin
  586. oldpos:=aktfilepos;
  587. aktfilepos:=pos;
  588. MaybeLoadMessageFile;
  589. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  590. aktfilepos:=oldpos;
  591. end;
  592. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  593. var
  594. oldpos : tfileposinfo;
  595. begin
  596. oldpos:=aktfilepos;
  597. aktfilepos:=pos;
  598. MaybeLoadMessageFile;
  599. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  600. aktfilepos:=oldpos;
  601. end;
  602. {*****************************************************************************
  603. override the message calls to set codegenerror
  604. *****************************************************************************}
  605. procedure cgmessage(t : longint);
  606. var
  607. olderrorcount : longint;
  608. begin
  609. if not(codegenerror) then
  610. begin
  611. olderrorcount:=Errorcount;
  612. verbose.Message(t);
  613. codegenerror:=olderrorcount<>Errorcount;
  614. end;
  615. end;
  616. procedure cgmessage1(t : longint;const s : string);
  617. var
  618. olderrorcount : longint;
  619. begin
  620. if not(codegenerror) then
  621. begin
  622. olderrorcount:=Errorcount;
  623. verbose.Message1(t,s);
  624. codegenerror:=olderrorcount<>Errorcount;
  625. end;
  626. end;
  627. procedure cgmessage2(t : longint;const s1,s2 : string);
  628. var
  629. olderrorcount : longint;
  630. begin
  631. if not(codegenerror) then
  632. begin
  633. olderrorcount:=Errorcount;
  634. verbose.Message2(t,s1,s2);
  635. codegenerror:=olderrorcount<>Errorcount;
  636. end;
  637. end;
  638. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  639. var
  640. olderrorcount : longint;
  641. begin
  642. if not(codegenerror) then
  643. begin
  644. olderrorcount:=Errorcount;
  645. verbose.Message3(t,s1,s2,s3);
  646. codegenerror:=olderrorcount<>Errorcount;
  647. end;
  648. end;
  649. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  650. var
  651. olderrorcount : longint;
  652. begin
  653. if not(codegenerror) then
  654. begin
  655. olderrorcount:=Errorcount;
  656. verbose.MessagePos(pos,t);
  657. codegenerror:=olderrorcount<>Errorcount;
  658. end;
  659. end;
  660. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  661. var
  662. olderrorcount : longint;
  663. begin
  664. if not(codegenerror) then
  665. begin
  666. olderrorcount:=Errorcount;
  667. verbose.MessagePos1(pos,t,s1);
  668. codegenerror:=olderrorcount<>Errorcount;
  669. end;
  670. end;
  671. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : string);
  672. var
  673. olderrorcount : longint;
  674. begin
  675. if not(codegenerror) then
  676. begin
  677. olderrorcount:=Errorcount;
  678. verbose.MessagePos2(pos,t,s1,s2);
  679. codegenerror:=olderrorcount<>Errorcount;
  680. end;
  681. end;
  682. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : string);
  683. var
  684. olderrorcount : longint;
  685. begin
  686. if not(codegenerror) then
  687. begin
  688. olderrorcount:=Errorcount;
  689. verbose.MessagePos3(pos,t,s1,s2,s3);
  690. codegenerror:=olderrorcount<>Errorcount;
  691. end;
  692. end;
  693. procedure FlushOutput;
  694. begin
  695. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  696. begin
  697. if Status.Use_Redir then
  698. Flush(Status.RedirFile)
  699. else
  700. Flush(Output);
  701. end;
  702. end;
  703. {*****************************************************************************
  704. Initialization
  705. *****************************************************************************}
  706. procedure InitVerbose;
  707. begin
  708. { Init }
  709. msg:=new(pmessage,Init(20,msgidxmax));
  710. if msg=nil then
  711. begin
  712. writeln('Fatal: MsgIdx Wrong');
  713. halt(3);
  714. end;
  715. {$ifndef EXTERN_MSG}
  716. msg^.LoadIntern(@msgtxt,msgtxtsize);
  717. {$else EXTERN_MSG}
  718. LoadMsgFile(exepath+'errore.msg');
  719. {$endif EXTERN_MSG}
  720. FillChar(Status,sizeof(TCompilerStatus),0);
  721. status.verbosity:=V_Default;
  722. Status.MaxErrorCount:=50;
  723. Status.codesize:=-1;
  724. Status.datasize:=-1;
  725. Loadprefixes;
  726. lastfileidx:=-1;
  727. lastmoduleidx:=-1;
  728. status.currentmodule:='';
  729. status.currentsource:='';
  730. status.currentsourcepath:='';
  731. status.compiling_current:=false;
  732. compiling_module:=nil;
  733. { Register internalerrorproc for cutils/cclasses }
  734. internalerrorproc:=@internalerror;
  735. end;
  736. procedure DoneVerbose;
  737. begin
  738. if assigned(msg) then
  739. begin
  740. dispose(msg,Done);
  741. msg:=nil;
  742. end;
  743. DoneRedirectFile;
  744. end;
  745. initialization
  746. finalization
  747. { Be sure to close the redirect files to flush all data }
  748. DoneRedirectFile;
  749. end.