verb_def.pas 6.7 KB

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