123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- {
- $Id$
- Copyright (c) 1998 by Peter Vreman
- This unit handles the default verbose routines
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- unit verb_def;
- interface
- uses verbose;
- {$define allow_oldstyle}
- procedure SetRedirectFile(const fn:string);
- procedure _stop;
- procedure _comment(Level:Longint;const s:string);
- {$ifdef allow_oldstyle}
- function _warning(w : tmsgconst) : boolean;
- function _note(w : tmsgconst) : boolean;
- function _error(w : tmsgconst) : boolean;
- function _fatalerror(w : tmsgconst) : boolean;
- function _internalerror(i : longint) : boolean;
- {$endif}
- implementation
- uses
- strings,dos,cobjects,systems,globals,files;
- const
- { RHIDE expect gcc like error output }
- rh_errorstr='error: ';
- rh_warningstr='warning: ';
- fatalstr='Fatal Error: ';
- errorstr='Error: ';
- warningstr='Warning: ';
- notestr='Note: ';
- hintstr='Hint: ';
- var
- redirexitsave : pointer;
- redirtext : boolean;
- redirfile : text;
- {****************************************************************************
- Extra Handlers for default compiler
- ****************************************************************************}
- procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
- begin
- exitproc:=redirexitsave;
- if redirtext then
- close(redirfile);
- end;
- procedure SetRedirectFile(const fn:string);
- begin
- assign(redirfile,fn);
- {$I-}
- rewrite(redirfile);
- {$I+}
- redirtext:=(ioresult=0);
- if redirtext then
- begin
- redirexitsave:=exitproc;
- exitproc:=@DoneRedirectFile;
- end;
- end;
- {****************************************************************************
- Predefined default Handlers
- ****************************************************************************}
- { predefined handler to stop the compiler }
- procedure _stop;
- begin
- halt(1);
- end;
- Procedure _comment(Level:Longint;const s:string);
- var
- hs : string;
- i : longint;
- begin
- if (verbosity and Level)=Level then
- begin
- {Create hs}
- hs:='';
- if not(use_rhide) then
- begin
- if (verbosity and Level)=V_Hint then
- hs:=hintstr;
- if (verbosity and Level)=V_Note then
- hs:=notestr;
- if (verbosity and Level)=V_Warning then
- hs:=warningstr;
- if (verbosity and Level)=V_Error then
- hs:=errorstr;
- if (verbosity and Level)=V_Fatal then
- hs:=fatalstr;
- end
- else
- begin
- if (verbosity and Level)=V_Hint then
- hs:=rh_warningstr;
- if (verbosity and Level)=V_Note then
- hs:=rh_warningstr;
- if (verbosity and Level)=V_Warning then
- hs:=rh_warningstr;
- if (verbosity and Level)=V_Error then
- hs:=rh_errorstr;
- if (verbosity and Level)=V_Fatal then
- hs:=rh_errorstr;
- end;
- if (Level<$100) and Assigned(current_module) and
- Assigned(current_module^.current_inputfile) then
- hs:=current_module^.current_inputfile^.get_file_line+' '+hs;
- (* {$ifdef USE_RHIDE}
- What was this ??? I did not code that (PM)
- if (Level<$100) then
- begin
- i:=length(hs)+1;
- hs:=hs+lowercase(Copy(s,1,5))+Copy(s,6,255);
- end
- else
- {$endif USE_RHIDE} *)
- hs:=hs+s;
- {$ifdef FPC}
- if UseStdErr and (Level<$100) then
- begin
- writeln(stderr,hs);
- flush(stderr);
- end
- else
- {$ENDIF}
- begin
- if redirtext then
- writeln(redirfile,hs)
- else
- writeln(hs);
- end;
- end;
- end;
- function _internalerror(i : longint) : boolean;
- begin
- comment(V_Fatal,'Internal error '+tostr(i));
- _internalerror:=true;
- end;
- {****************************************************************************
- Old Style
- ****************************************************************************}
- {$ifdef allow_oldstyle}
- procedure ShowExtError(l:longint;w:tmsgconst);
- var
- s : string;
- begin
- {fix the string to be written }
- s:=msg^.get(ord(w));
- if assigned(exterror) then
- begin
- s:=s+strpas(exterror);
- strdispose(exterror);
- exterror:=nil;
- end;
- _comment(l,s);
- end;
- { predefined handler for warnings }
- function _warning(w : tmsgconst) : boolean;
- begin
- ShowExtError(V_Warning,w);
- _warning:=false;
- end;
- function _note(w : tmsgconst) : boolean;
- begin
- ShowExtError(V_Note,w);
- _note:=false;
- end;
- function _error(w : tmsgconst) : boolean;
- begin
- ShowExtError(V_Error,w);
- _error:=(errorcount>50);
- end;
- function _fatalerror(w : tmsgconst) : boolean;
- begin
- ShowExtError(V_Error,w);
- _fatalerror:=true;
- end;
- {$endif}
- begin
- (* {$ifdef USE_RHIDE}
- UseStdErr:=true;
- {$endif USE_RHIDE} *)
- {$ifdef FPC}
- do_stop:=@_stop;
- do_comment:=@_comment;
- {$ifdef allow_oldstyle}
- do_note:=@_note;
- do_warning:=@_warning;
- do_error:=@_error;
- do_fatalerror:=@_fatalerror;
- do_internalerror:=@_internalerror;
- {$endif}
- {$else}
- do_stop:=_stop;
- do_comment:=_comment;
- {$ifdef allow_oldstyle}
- do_note:=_note;
- do_warning:=_warning;
- do_error:=_error;
- do_fatalerror:=_fatalerror;
- do_internalerror:=_internalerror;
- {$endif}
- {$endif}
- end.
- {
- $Log$
- Revision 1.5 1998-04-30 15:59:43 pierre
- * GDB works again better :
- correct type info in one pass
- + UseTokenInfo for better source position
- * fixed one remaining bug in scanner for line counts
- * several little fixes
- Revision 1.4 1998/04/29 10:34:09 pierre
- + added some code for ansistring (not complete nor working yet)
- * corrected operator overloading
- * corrected nasm output
- + started inline procedures
- + added starstarn : use ** for exponentiation (^ gave problems)
- + started UseTokenInfo cond to get accurate positions
- Revision 1.2 1998/03/28 23:09:57 florian
- * secondin bugfix (m68k and i386)
- * overflow checking bugfix (m68k and i386) -- pretty useless in
- secondadd, since everything is done using 32-bit
- * loading pointer to routines hopefully fixed (m68k)
- * flags problem with calls to RTL internal routines fixed (still strcmp
- to fix) (m68k)
- * #ELSE was still incorrect (didn't take care of the previous level)
- * problem with filenames in the command line solved
- * problem with mangledname solved
- * linking name problem solved (was case insensitive)
- * double id problem and potential crash solved
- * stop after first error
- * and=>test problem removed
- * correct read for all float types
- * 2 sigsegv fixes and a cosmetic fix for Internal Error
- * push/pop is now correct optimized (=> mov (%esp),reg)
- Revision 1.1.1.1 1998/03/25 11:18:15 root
- * Restored version
- Revision 1.6 1998/03/10 16:43:34 peter
- * fixed Fatal error writting
- Revision 1.5 1998/03/10 01:17:30 peter
- * all files have the same header
- * messages are fully implemented, EXTDEBUG uses Comment()
- + AG... files for the Assembler generation
- Revision 1.4 1998/03/06 00:53:02 peter
- * replaced all old messages from errore.msg, only ExtDebug and some
- Comment() calls are left
- * fixed options.pas
- Revision 1.3 1998/03/04 17:34:15 michael
- + Changed ifdef FPK to ifdef FPC
- Revision 1.2 1998/03/03 16:45:25 peter
- + message support for assembler parsers
- }
|