verb_def.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. {$define allow_oldstyle}
  22. var
  23. UseStdErr : boolean;
  24. procedure SetRedirectFile(const fn:string);
  25. procedure _stop;
  26. procedure _comment(Level:Longint;const s:string);
  27. {$ifdef allow_oldstyle}
  28. function _warning(w : tmsgconst) : boolean;
  29. function _note(w : tmsgconst) : boolean;
  30. function _error(w : tmsgconst) : boolean;
  31. function _fatalerror(w : tmsgconst) : boolean;
  32. function _internalerror(i : longint) : boolean;
  33. {$endif}
  34. implementation
  35. uses
  36. strings,dos,cobjects,systems,globals,files;
  37. const
  38. {$ifdef USE_RHIDE}
  39. { RHIDE expect gcc like error output }
  40. fatalstr='fatal: ';
  41. errorstr='error: ';
  42. warningstr='warning: ';
  43. notestr='warning: ';
  44. hintstr='warning: ';
  45. {$else}
  46. fatalstr='Fatal Error: ';
  47. errorstr='Error: ';
  48. warningstr='Warning: ';
  49. notestr='Note: ';
  50. hintstr='Hint: ';
  51. {$endif USE_RHIDE}
  52. var
  53. redirexitsave : pointer;
  54. redirtext : boolean;
  55. redirfile : text;
  56. {****************************************************************************
  57. Extra Handlers for default compiler
  58. ****************************************************************************}
  59. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  60. begin
  61. exitproc:=redirexitsave;
  62. if redirtext then
  63. close(redirfile);
  64. end;
  65. procedure SetRedirectFile(const fn:string);
  66. begin
  67. assign(redirfile,fn);
  68. {$I-}
  69. rewrite(redirfile);
  70. {$I+}
  71. redirtext:=(ioresult=0);
  72. if redirtext then
  73. begin
  74. redirexitsave:=exitproc;
  75. exitproc:=@DoneRedirectFile;
  76. end;
  77. end;
  78. {****************************************************************************
  79. Predefined default Handlers
  80. ****************************************************************************}
  81. { predefined handler to stop the compiler }
  82. procedure _stop;
  83. begin
  84. halt(1);
  85. end;
  86. Procedure _comment(Level:Longint;const s:string);
  87. var
  88. hs : string;
  89. {$ifdef USE_RHIDE}
  90. i : longint;
  91. {$endif}
  92. begin
  93. if (verbosity and Level)=Level then
  94. begin
  95. {Create hs}
  96. hs:='';
  97. if (verbosity and Level)=V_Hint then
  98. hs:=hintstr;
  99. if (verbosity and Level)=V_Note then
  100. hs:=notestr;
  101. if (verbosity and Level)=V_Warning then
  102. hs:=warningstr;
  103. if (verbosity and Level)=V_Error then
  104. hs:=errorstr;
  105. if (verbosity and Level)=V_Fatal then
  106. hs:=fatalstr;
  107. if (Level<$100) and Assigned(current_module) and
  108. Assigned(current_module^.current_inputfile) then
  109. hs:=current_module^.current_inputfile^.get_file_line+' '+hs;
  110. {$ifdef USE_RHIDE}
  111. if (Level<$100) then
  112. begin
  113. i:=length(hs)+1;
  114. hs:=hs+lowercase(Copy(s,1,5))+Copy(s,6,255);
  115. end
  116. else
  117. {$endif USE_RHIDE}
  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. function _internalerror(i : longint) : boolean;
  136. var
  137. temp : string;
  138. begin
  139. if assigned(current_module^.current_inputfile) then
  140. temp:=current_module^.current_inputfile^.get_file_line+': '
  141. else
  142. temp:='';
  143. comment(V_Error,temp+'Internal error '+tostr(i));
  144. _internalerror:=true;
  145. end;
  146. {****************************************************************************
  147. Old Style
  148. ****************************************************************************}
  149. {$ifdef allow_oldstyle}
  150. procedure ShowExtError(l:longint;w:tmsgconst);
  151. var
  152. s : string;
  153. begin
  154. {fix the string to be written }
  155. s:=msg^.get(ord(w));
  156. if assigned(exterror) then
  157. begin
  158. s:=s+strpas(exterror);
  159. strdispose(exterror);
  160. exterror:=nil;
  161. end;
  162. _comment(l,s);
  163. end;
  164. { predefined handler for warnings }
  165. function _warning(w : tmsgconst) : boolean;
  166. begin
  167. ShowExtError(V_Warning,w);
  168. _warning:=false;
  169. end;
  170. function _note(w : tmsgconst) : boolean;
  171. begin
  172. ShowExtError(V_Note,w);
  173. _note:=false;
  174. end;
  175. function _error(w : tmsgconst) : boolean;
  176. begin
  177. ShowExtError(V_Error,w);
  178. _error:=(errorcount>50);
  179. end;
  180. function _fatalerror(w : tmsgconst) : boolean;
  181. begin
  182. ShowExtError(V_Error,w);
  183. _fatalerror:=true;
  184. end;
  185. {$endif}
  186. begin
  187. {$ifdef FPC}
  188. do_stop:=@_stop;
  189. do_comment:=@_comment;
  190. {$ifdef allow_oldstyle}
  191. do_note:=@_note;
  192. do_warning:=@_warning;
  193. do_error:=@_error;
  194. do_fatalerror:=@_fatalerror;
  195. do_internalerror:=@_internalerror;
  196. {$endif}
  197. {$else}
  198. do_stop:=_stop;
  199. do_comment:=_comment;
  200. {$ifdef allow_oldstyle}
  201. do_note:=_note;
  202. do_warning:=_warning;
  203. do_error:=_error;
  204. do_fatalerror:=_fatalerror;
  205. do_internalerror:=_internalerror;
  206. {$endif}
  207. {$endif}
  208. end.
  209. {
  210. $Log$
  211. Revision 1.1.1.1 1998-03-25 11:18:15 root
  212. * Restored version
  213. Revision 1.6 1998/03/10 16:43:34 peter
  214. * fixed Fatal error writting
  215. Revision 1.5 1998/03/10 01:17:30 peter
  216. * all files have the same header
  217. * messages are fully implemented, EXTDEBUG uses Comment()
  218. + AG... files for the Assembler generation
  219. Revision 1.4 1998/03/06 00:53:02 peter
  220. * replaced all old messages from errore.msg, only ExtDebug and some
  221. Comment() calls are left
  222. * fixed options.pas
  223. Revision 1.3 1998/03/04 17:34:15 michael
  224. + Changed ifdef FPK to ifdef FPC
  225. Revision 1.2 1998/03/03 16:45:25 peter
  226. + message support for assembler parsers
  227. }