verbose.pas 26 KB

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