verb_def.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. procedure SetRedirectFile(const fn:string);
  21. procedure _stop;
  22. Function _comment(Level:Longint;const s:string):boolean;
  23. function _internalerror(i : longint) : boolean;
  24. implementation
  25. uses
  26. verbose,globals,
  27. {$ifndef NEWINPUT}
  28. files,
  29. {$endif}
  30. strings,dos;
  31. const
  32. { RHIDE expect gcc like error output }
  33. rh_errorstr='error: ';
  34. rh_warningstr='warning: ';
  35. fatalstr='Fatal: ';
  36. errorstr='Error: ';
  37. warningstr='Warning: ';
  38. notestr='Note: ';
  39. hintstr='Hint: ';
  40. var
  41. redirexitsave : pointer;
  42. redirtext : boolean;
  43. redirfile : text;
  44. {****************************************************************************
  45. Extra Handlers for default compiler
  46. ****************************************************************************}
  47. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  48. begin
  49. exitproc:=redirexitsave;
  50. if redirtext then
  51. close(redirfile);
  52. end;
  53. procedure SetRedirectFile(const fn:string);
  54. begin
  55. assign(redirfile,fn);
  56. {$I-}
  57. rewrite(redirfile);
  58. {$I+}
  59. redirtext:=(ioresult=0);
  60. if redirtext then
  61. begin
  62. redirexitsave:=exitproc;
  63. exitproc:=@DoneRedirectFile;
  64. end;
  65. end;
  66. {****************************************************************************
  67. Predefined default Handlers
  68. ****************************************************************************}
  69. { predefined handler to stop the compiler }
  70. procedure _stop;
  71. begin
  72. halt(1);
  73. end;
  74. Function _comment(Level:Longint;const s:string):boolean;
  75. var
  76. hs : string;
  77. begin
  78. _comment:=false; { never stop }
  79. if (verbosity and Level)=Level then
  80. begin
  81. { Status info?, Called every line }
  82. if ((Level and V_Status)<>0) and (s='') then
  83. begin
  84. if (status.compiledlines=1) then
  85. WriteLn(memavail shr 10,' Kb Free');
  86. if (status.currentline>0) and (status.currentline mod 100=0) then
  87. {$ifdef FPC}
  88. WriteLn(status.currentline,' ',memavail shr 10,'/',system.heapsize shr 10,' Kb Free');
  89. {$else}
  90. WriteLn(status.currentline,' ',memavail shr 10,' Kb Free');
  91. {$endif}
  92. end
  93. else
  94. { Message }
  95. begin
  96. hs:='';
  97. if not(use_rhide) then
  98. begin
  99. if (verbosity and Level)=V_Hint then
  100. hs:=hintstr;
  101. if (verbosity and Level)=V_Note then
  102. hs:=notestr;
  103. if (verbosity and Level)=V_Warning then
  104. hs:=warningstr;
  105. if (verbosity and Level)=V_Error then
  106. hs:=errorstr;
  107. if (verbosity and Level)=V_Fatal then
  108. hs:=fatalstr;
  109. end
  110. else
  111. begin
  112. if (verbosity and Level)=V_Hint then
  113. hs:=rh_warningstr;
  114. if (verbosity and Level)=V_Note then
  115. hs:=rh_warningstr;
  116. if (verbosity and Level)=V_Warning then
  117. hs:=rh_warningstr;
  118. if (verbosity and Level)=V_Error then
  119. hs:=rh_errorstr;
  120. if (verbosity and Level)=V_Fatal then
  121. hs:=rh_errorstr;
  122. end;
  123. {$ifdef NEWINPUT}
  124. if (Level<$100) and (status.currentline>0) then
  125. begin
  126. if Use_Rhide then
  127. hs:=lower(bstoslash(status.currentsource))+':'+tostr(status.currentline)+': '+hs
  128. else
  129. hs:=status.currentsource+'('+tostr(status.currentline)+','+tostr(status.currentcolumn)+') '+hs;
  130. end;
  131. {$else}
  132. if (Level<$100) and Assigned(current_module) and Assigned(current_module^.current_inputfile) then
  133. hs:=current_module^.current_inputfile^.get_file_line+' '+hs;
  134. {$endif NEWINPUT}
  135. { add the message to the text }
  136. hs:=hs+s;
  137. {$ifdef FPC}
  138. if UseStdErr and (Level<$100) then
  139. begin
  140. writeln(stderr,hs);
  141. flush(stderr);
  142. end
  143. else
  144. {$endif}
  145. begin
  146. if redirtext then
  147. writeln(redirfile,hs)
  148. else
  149. writeln(hs);
  150. end;
  151. end;
  152. end;
  153. end;
  154. function _internalerror(i : longint) : boolean;
  155. begin
  156. _comment(V_Fatal,'Internal error '+tostr(i));
  157. _internalerror:=true;
  158. end;
  159. begin
  160. {$ifdef FPC}
  161. do_stop:=@_stop;
  162. do_comment:=@_comment;
  163. do_internalerror:=@_internalerror;
  164. {$else}
  165. do_stop:=_stop;
  166. do_comment:=_comment;
  167. do_internalerror:=_internalerror;
  168. {$endif}
  169. end.
  170. {
  171. $Log$
  172. Revision 1.12 1998-07-07 11:20:19 peter
  173. + NEWINPUT for a better inputfile and scanner object
  174. Revision 1.11 1998/06/19 15:40:00 peter
  175. * bp7 fix
  176. Revision 1.10 1998/06/16 11:32:19 peter
  177. * small cosmetic fixes
  178. Revision 1.9 1998/05/23 01:21:33 peter
  179. + aktasmmode, aktoptprocessor, aktoutputformat
  180. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  181. + $LIBNAME to set the library name where the unit will be put in
  182. * splitted cgi386 a bit (codeseg to large for bp7)
  183. * nasm, tasm works again. nasm moved to ag386nsm.pas
  184. Revision 1.8 1998/05/21 19:33:38 peter
  185. + better procedure directive handling and only one table
  186. Revision 1.7 1998/05/12 10:47:01 peter
  187. * moved printstatus to verb_def
  188. + V_Normal which is between V_Error and V_Warning and doesn't have a
  189. prefix like error: warning: and is included in V_Default
  190. * fixed some messages
  191. * first time parameter scan is only for -v and -T
  192. - removed old style messages
  193. Revision 1.6 1998/05/11 13:07:58 peter
  194. + $ifdef NEWPPU for the new ppuformat
  195. + $define GDB not longer required
  196. * removed all warnings and stripped some log comments
  197. * no findfirst/findnext anymore to remove smartlink *.o files
  198. Revision 1.5 1998/04/30 15:59:43 pierre
  199. * GDB works again better :
  200. correct type info in one pass
  201. + UseTokenInfo for better source position
  202. * fixed one remaining bug in scanner for line counts
  203. * several little fixes
  204. Revision 1.4 1998/04/29 10:34:09 pierre
  205. + added some code for ansistring (not complete nor working yet)
  206. * corrected operator overloading
  207. * corrected nasm output
  208. + started inline procedures
  209. + added starstarn : use ** for exponentiation (^ gave problems)
  210. + started UseTokenInfo cond to get accurate positions
  211. }