verb_def.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. begin
  137. comment(V_Fatal,'Internal error '+tostr(i));
  138. _internalerror:=true;
  139. end;
  140. {****************************************************************************
  141. Old Style
  142. ****************************************************************************}
  143. {$ifdef allow_oldstyle}
  144. procedure ShowExtError(l:longint;w:tmsgconst);
  145. var
  146. s : string;
  147. begin
  148. {fix the string to be written }
  149. s:=msg^.get(ord(w));
  150. if assigned(exterror) then
  151. begin
  152. s:=s+strpas(exterror);
  153. strdispose(exterror);
  154. exterror:=nil;
  155. end;
  156. _comment(l,s);
  157. end;
  158. { predefined handler for warnings }
  159. function _warning(w : tmsgconst) : boolean;
  160. begin
  161. ShowExtError(V_Warning,w);
  162. _warning:=false;
  163. end;
  164. function _note(w : tmsgconst) : boolean;
  165. begin
  166. ShowExtError(V_Note,w);
  167. _note:=false;
  168. end;
  169. function _error(w : tmsgconst) : boolean;
  170. begin
  171. ShowExtError(V_Error,w);
  172. _error:=(errorcount>50);
  173. end;
  174. function _fatalerror(w : tmsgconst) : boolean;
  175. begin
  176. ShowExtError(V_Error,w);
  177. _fatalerror:=true;
  178. end;
  179. {$endif}
  180. begin
  181. {$ifdef USE_RHIDE}
  182. UseStdErr:=true;
  183. {$endif USE_RHIDE}
  184. {$ifdef FPC}
  185. do_stop:=@_stop;
  186. do_comment:=@_comment;
  187. {$ifdef allow_oldstyle}
  188. do_note:=@_note;
  189. do_warning:=@_warning;
  190. do_error:=@_error;
  191. do_fatalerror:=@_fatalerror;
  192. do_internalerror:=@_internalerror;
  193. {$endif}
  194. {$else}
  195. do_stop:=_stop;
  196. do_comment:=_comment;
  197. {$ifdef allow_oldstyle}
  198. do_note:=_note;
  199. do_warning:=_warning;
  200. do_error:=_error;
  201. do_fatalerror:=_fatalerror;
  202. do_internalerror:=_internalerror;
  203. {$endif}
  204. {$endif}
  205. end.
  206. {
  207. $Log$
  208. Revision 1.3 1998-04-21 15:22:46 pierre
  209. * typing error in secondadd for mmx corrected
  210. * USE_RHIDE sets usestderr to true
  211. replacing gpc by fpc in RHIDE should be a lot easier
  212. Revision 1.2 1998/03/28 23:09:57 florian
  213. * secondin bugfix (m68k and i386)
  214. * overflow checking bugfix (m68k and i386) -- pretty useless in
  215. secondadd, since everything is done using 32-bit
  216. * loading pointer to routines hopefully fixed (m68k)
  217. * flags problem with calls to RTL internal routines fixed (still strcmp
  218. to fix) (m68k)
  219. * #ELSE was still incorrect (didn't take care of the previous level)
  220. * problem with filenames in the command line solved
  221. * problem with mangledname solved
  222. * linking name problem solved (was case insensitive)
  223. * double id problem and potential crash solved
  224. * stop after first error
  225. * and=>test problem removed
  226. * correct read for all float types
  227. * 2 sigsegv fixes and a cosmetic fix for Internal Error
  228. * push/pop is now correct optimized (=> mov (%esp),reg)
  229. Revision 1.1.1.1 1998/03/25 11:18:15 root
  230. * Restored version
  231. Revision 1.6 1998/03/10 16:43:34 peter
  232. * fixed Fatal error writting
  233. Revision 1.5 1998/03/10 01:17:30 peter
  234. * all files have the same header
  235. * messages are fully implemented, EXTDEBUG uses Comment()
  236. + AG... files for the Assembler generation
  237. Revision 1.4 1998/03/06 00:53:02 peter
  238. * replaced all old messages from errore.msg, only ExtDebug and some
  239. Comment() calls are left
  240. * fixed options.pas
  241. Revision 1.3 1998/03/04 17:34:15 michael
  242. + Changed ifdef FPK to ifdef FPC
  243. Revision 1.2 1998/03/03 16:45:25 peter
  244. + message support for assembler parsers
  245. }