verbose.pas 24 KB

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