verb_def.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. This unit handles the default verbose routines
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit verb_def;
  19. interface
  20. uses verbose;
  21. procedure SetRedirectFile(const fn:string);
  22. procedure _stop;
  23. procedure _comment(Level:Longint;const s:string);
  24. function _internalerror(i : longint) : boolean;
  25. implementation
  26. uses
  27. strings,dos,globals,files;
  28. const
  29. { RHIDE expect gcc like error output }
  30. rh_errorstr='error: ';
  31. rh_warningstr='warning: ';
  32. fatalstr='Fatal: ';
  33. errorstr='Error: ';
  34. warningstr='Warning: ';
  35. notestr='Note: ';
  36. hintstr='Hint: ';
  37. var
  38. redirexitsave : pointer;
  39. redirtext : boolean;
  40. redirfile : text;
  41. {****************************************************************************
  42. Extra Handlers for default compiler
  43. ****************************************************************************}
  44. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  45. begin
  46. exitproc:=redirexitsave;
  47. if redirtext then
  48. close(redirfile);
  49. end;
  50. procedure SetRedirectFile(const fn:string);
  51. begin
  52. assign(redirfile,fn);
  53. {$I-}
  54. rewrite(redirfile);
  55. {$I+}
  56. redirtext:=(ioresult=0);
  57. if redirtext then
  58. begin
  59. redirexitsave:=exitproc;
  60. exitproc:=@DoneRedirectFile;
  61. end;
  62. end;
  63. {****************************************************************************
  64. Predefined default Handlers
  65. ****************************************************************************}
  66. { predefined handler to stop the compiler }
  67. procedure _stop;
  68. begin
  69. halt(1);
  70. end;
  71. Procedure _comment(Level:Longint;const s:string);
  72. var
  73. hs : string;
  74. begin
  75. if (verbosity and Level)=Level then
  76. begin
  77. { Status info?, Called every line }
  78. if ((Level and V_Status)<>0) and (s='') then
  79. begin
  80. if (abslines=1) then
  81. WriteLn(memavail shr 10,' Kb Free');
  82. if (status.currentline mod 100=0) then
  83. Write(status.currentline,' ',memavail shr 10,' Kb Free'#13);
  84. end
  85. else
  86. { Message }
  87. begin
  88. hs:='';
  89. if not(use_rhide) then
  90. begin
  91. if (verbosity and Level)=V_Hint then
  92. hs:=hintstr;
  93. if (verbosity and Level)=V_Note then
  94. hs:=notestr;
  95. if (verbosity and Level)=V_Warning then
  96. hs:=warningstr;
  97. if (verbosity and Level)=V_Error then
  98. hs:=errorstr;
  99. if (verbosity and Level)=V_Fatal then
  100. hs:=fatalstr;
  101. end
  102. else
  103. begin
  104. if (verbosity and Level)=V_Hint then
  105. hs:=rh_warningstr;
  106. if (verbosity and Level)=V_Note then
  107. hs:=rh_warningstr;
  108. if (verbosity and Level)=V_Warning then
  109. hs:=rh_warningstr;
  110. if (verbosity and Level)=V_Error then
  111. hs:=rh_errorstr;
  112. if (verbosity and Level)=V_Fatal then
  113. hs:=rh_errorstr;
  114. end;
  115. if (Level<$100) and Assigned(current_module) and Assigned(current_module^.current_inputfile) then
  116. hs:=current_module^.current_inputfile^.get_file_line+' '+hs;
  117. { add the message to the text }
  118. hs:=hs+s;
  119. {$ifdef FPC}
  120. if UseStdErr and (Level<$100) then
  121. begin
  122. writeln(stderr,hs);
  123. flush(stderr);
  124. end
  125. else
  126. {$endif}
  127. begin
  128. if redirtext then
  129. writeln(redirfile,hs)
  130. else
  131. writeln(hs);
  132. end;
  133. end;
  134. end;
  135. end;
  136. function _internalerror(i : longint) : boolean;
  137. begin
  138. comment(V_Fatal,'Internal error '+tostr(i));
  139. _internalerror:=true;
  140. end;
  141. begin
  142. {$ifdef FPC}
  143. do_stop:=@_stop;
  144. do_comment:=@_comment;
  145. do_internalerror:=@_internalerror;
  146. {$else}
  147. do_stop:=_stop;
  148. do_comment:=_comment;
  149. do_internalerror:=_internalerror;
  150. {$endif}
  151. end.
  152. {
  153. $Log$
  154. Revision 1.7 1998-05-12 10:47:01 peter
  155. * moved printstatus to verb_def
  156. + V_Normal which is between V_Error and V_Warning and doesn't have a
  157. prefix like error: warning: and is included in V_Default
  158. * fixed some messages
  159. * first time parameter scan is only for -v and -T
  160. - removed old style messages
  161. Revision 1.6 1998/05/11 13:07:58 peter
  162. + $ifdef NEWPPU for the new ppuformat
  163. + $define GDB not longer required
  164. * removed all warnings and stripped some log comments
  165. * no findfirst/findnext anymore to remove smartlink *.o files
  166. Revision 1.5 1998/04/30 15:59:43 pierre
  167. * GDB works again better :
  168. correct type info in one pass
  169. + UseTokenInfo for better source position
  170. * fixed one remaining bug in scanner for line counts
  171. * several little fixes
  172. Revision 1.4 1998/04/29 10:34:09 pierre
  173. + added some code for ansistring (not complete nor working yet)
  174. * corrected operator overloading
  175. * corrected nasm output
  176. + started inline procedures
  177. + added starstarn : use ** for exponentiation (^ gave problems)
  178. + started UseTokenInfo cond to get accurate positions
  179. }