verbose.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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. end;
  464. 'N' :
  465. begin
  466. v:=v or V_Note;
  467. if status.errornote then
  468. inc(status.errorcount);
  469. end;
  470. 'H' :
  471. begin
  472. v:=v or V_Hint;
  473. if status.errorhint then
  474. inc(status.errorcount);
  475. end;
  476. 'I' :
  477. v:=v or V_Info;
  478. 'L' :
  479. v:=v or V_LineInfo;
  480. 'U' :
  481. v:=v or V_Used;
  482. 'T' :
  483. v:=v or V_Tried;
  484. 'C' :
  485. v:=v or V_Conditional;
  486. 'D' :
  487. v:=v or V_Debug;
  488. 'X' :
  489. v:=v or V_Executable;
  490. 'S' :
  491. dostop:=true;
  492. '_' : ;
  493. end;
  494. end;
  495. end;
  496. Delete(s,1,idx);
  497. { check verbosity level }
  498. if not CheckVerbosity(v) then
  499. exit;
  500. if (v and V_LineInfoMask)<>0 then
  501. v:=v or V_LineInfo;
  502. { fix status }
  503. UpdateStatus;
  504. { Fix replacements }
  505. DefaultReplacements(s);
  506. { show comment }
  507. if do_comment(v,s) or dostop then
  508. raise ECompilerAbort.Create;
  509. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  510. begin
  511. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  512. status.skip_error:=true;
  513. raise ECompilerAbort.Create;
  514. end;
  515. end;
  516. function MessagePchar(w:longint):pchar;
  517. begin
  518. MaybeLoadMessageFile;
  519. MessagePchar:=msg^.GetPchar(w)
  520. end;
  521. procedure Message(w:longint);
  522. begin
  523. MaybeLoadMessageFile;
  524. Msg2Comment(msg^.Get(w,[]));
  525. end;
  526. procedure Message1(w:longint;const s1:string);
  527. begin
  528. MaybeLoadMessageFile;
  529. Msg2Comment(msg^.Get(w,[s1]));
  530. end;
  531. procedure Message2(w:longint;const s1,s2:string);
  532. begin
  533. MaybeLoadMessageFile;
  534. Msg2Comment(msg^.Get(w,[s1,s2]));
  535. end;
  536. procedure Message3(w:longint;const s1,s2,s3:string);
  537. begin
  538. MaybeLoadMessageFile;
  539. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  540. end;
  541. procedure Message4(w:longint;const s1,s2,s3,s4:string);
  542. begin
  543. MaybeLoadMessageFile;
  544. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  545. end;
  546. procedure MessagePos(const pos:tfileposinfo;w:longint);
  547. var
  548. oldpos : tfileposinfo;
  549. begin
  550. oldpos:=aktfilepos;
  551. aktfilepos:=pos;
  552. MaybeLoadMessageFile;
  553. Msg2Comment(msg^.Get(w,[]));
  554. aktfilepos:=oldpos;
  555. end;
  556. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:string);
  557. var
  558. oldpos : tfileposinfo;
  559. begin
  560. oldpos:=aktfilepos;
  561. aktfilepos:=pos;
  562. MaybeLoadMessageFile;
  563. Msg2Comment(msg^.Get(w,[s1]));
  564. aktfilepos:=oldpos;
  565. end;
  566. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:string);
  567. var
  568. oldpos : tfileposinfo;
  569. begin
  570. oldpos:=aktfilepos;
  571. aktfilepos:=pos;
  572. MaybeLoadMessageFile;
  573. Msg2Comment(msg^.Get(w,[s1,s2]));
  574. aktfilepos:=oldpos;
  575. end;
  576. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:string);
  577. var
  578. oldpos : tfileposinfo;
  579. begin
  580. oldpos:=aktfilepos;
  581. aktfilepos:=pos;
  582. MaybeLoadMessageFile;
  583. Msg2Comment(msg^.Get(w,[s1,s2,s3]));
  584. aktfilepos:=oldpos;
  585. end;
  586. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:string);
  587. var
  588. oldpos : tfileposinfo;
  589. begin
  590. oldpos:=aktfilepos;
  591. aktfilepos:=pos;
  592. MaybeLoadMessageFile;
  593. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]));
  594. aktfilepos:=oldpos;
  595. end;
  596. {*****************************************************************************
  597. override the message calls to set codegenerror
  598. *****************************************************************************}
  599. procedure cgmessage(t : longint);
  600. var
  601. olderrorcount : longint;
  602. begin
  603. if not(codegenerror) then
  604. begin
  605. olderrorcount:=Errorcount;
  606. verbose.Message(t);
  607. codegenerror:=olderrorcount<>Errorcount;
  608. end;
  609. end;
  610. procedure cgmessage1(t : longint;const s : string);
  611. var
  612. olderrorcount : longint;
  613. begin
  614. if not(codegenerror) then
  615. begin
  616. olderrorcount:=Errorcount;
  617. verbose.Message1(t,s);
  618. codegenerror:=olderrorcount<>Errorcount;
  619. end;
  620. end;
  621. procedure cgmessage2(t : longint;const s1,s2 : string);
  622. var
  623. olderrorcount : longint;
  624. begin
  625. if not(codegenerror) then
  626. begin
  627. olderrorcount:=Errorcount;
  628. verbose.Message2(t,s1,s2);
  629. codegenerror:=olderrorcount<>Errorcount;
  630. end;
  631. end;
  632. procedure cgmessage3(t : longint;const s1,s2,s3 : string);
  633. var
  634. olderrorcount : longint;
  635. begin
  636. if not(codegenerror) then
  637. begin
  638. olderrorcount:=Errorcount;
  639. verbose.Message3(t,s1,s2,s3);
  640. codegenerror:=olderrorcount<>Errorcount;
  641. end;
  642. end;
  643. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  644. var
  645. olderrorcount : longint;
  646. begin
  647. if not(codegenerror) then
  648. begin
  649. olderrorcount:=Errorcount;
  650. verbose.MessagePos(pos,t);
  651. codegenerror:=olderrorcount<>Errorcount;
  652. end;
  653. end;
  654. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : string);
  655. var
  656. olderrorcount : longint;
  657. begin
  658. if not(codegenerror) then
  659. begin
  660. olderrorcount:=Errorcount;
  661. verbose.MessagePos1(pos,t,s1);
  662. codegenerror:=olderrorcount<>Errorcount;
  663. end;
  664. end;
  665. procedure cgmessagepos2(const pos:tfileposinfo;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.MessagePos2(pos,t,s1,s2);
  673. codegenerror:=olderrorcount<>Errorcount;
  674. end;
  675. end;
  676. procedure cgmessagepos3(const pos:tfileposinfo;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.MessagePos3(pos,t,s1,s2,s3);
  684. codegenerror:=olderrorcount<>Errorcount;
  685. end;
  686. end;
  687. procedure FlushOutput;
  688. begin
  689. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  690. begin
  691. if Status.Use_Redir then
  692. Flush(Status.RedirFile)
  693. else
  694. Flush(Output);
  695. end;
  696. end;
  697. {*****************************************************************************
  698. Initialization
  699. *****************************************************************************}
  700. procedure InitVerbose;
  701. begin
  702. { Init }
  703. msg:=new(pmessage,Init(20,msgidxmax));
  704. if msg=nil then
  705. begin
  706. writeln('Fatal: MsgIdx Wrong');
  707. halt(3);
  708. end;
  709. {$ifndef EXTERN_MSG}
  710. msg^.LoadIntern(@msgtxt,msgtxtsize);
  711. {$else EXTERN_MSG}
  712. LoadMsgFile(exepath+'errore.msg');
  713. {$endif EXTERN_MSG}
  714. FillChar(Status,sizeof(TCompilerStatus),0);
  715. status.verbosity:=V_Default;
  716. Status.MaxErrorCount:=50;
  717. Loadprefixes;
  718. lastfileidx:=-1;
  719. lastmoduleidx:=-1;
  720. status.currentmodule:='';
  721. status.currentsource:='';
  722. status.currentsourcepath:='';
  723. status.compiling_current:=false;
  724. compiling_module:=nil;
  725. { Register internalerrorproc for cutils/cclasses }
  726. internalerrorproc:=@internalerror;
  727. end;
  728. procedure DoneVerbose;
  729. begin
  730. if assigned(msg) then
  731. begin
  732. dispose(msg,Done);
  733. msg:=nil;
  734. end;
  735. DoneRedirectFile;
  736. end;
  737. initialization
  738. finalization
  739. { Be sure to close the redirect files to flush all data }
  740. DoneRedirectFile;
  741. end.