catch.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {
  2. $Id$
  3. Copyright (c) 1997-98 by Michael Van Canneyt
  4. Unit to catch segmentation faults and Ctrl-C and exit gracefully
  5. under linux and go32v2
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *********************************************************************
  18. }
  19. Unit catch;
  20. interface
  21. uses
  22. {$ifdef linux}
  23. linux,
  24. {$endif}
  25. {$ifdef go32v2}
  26. dpmiexcp,
  27. {$endif}
  28. verbose;
  29. Var
  30. {$ifdef linux}
  31. NewSignal,OldSigSegm,OldSigInt : PSignalHandler;
  32. {$else}
  33. NewSignal,OldSigSegm,OldSigInt : SignalHandler;
  34. {$endif}
  35. Implementation
  36. {$ifdef linux}
  37. Procedure CatchSignal(Sig : Integer);
  38. {$else}
  39. Function CatchSignal(Sig : longint):longint;
  40. {$endif}
  41. begin
  42. case Sig of
  43. SIGSEGV : begin
  44. { Temporary message - until we get an error number... }
  45. writeln ('Panic : Internal compiler error, exiting.');
  46. internalerror(9999);
  47. end;
  48. SIGINT : begin
  49. WriteLn('Ctrl-C Signaled!');
  50. Stop;
  51. end;
  52. end;
  53. {$ifndef linux}
  54. CatchSignal:=0;
  55. {$endif}
  56. end;
  57. begin
  58. {$ifdef linux}
  59. NewSignal:=PSignalHandler(@CatchSignal);
  60. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  61. OldSigInt:=Signal (SIGINT,NewSignal);
  62. {$else}
  63. NewSignal:=SignalHandler(@CatchSignal);
  64. Signal (SIGSEGV,NewSignal);
  65. Signal (SIGINT,NewSignal);
  66. {$endif}
  67. end.
  68. {
  69. $Log$
  70. Revision 1.1 1998-03-25 11:18:12 root
  71. Initial revision
  72. Revision 1.5 1998/03/10 01:17:15 peter
  73. * all files have the same header
  74. * messages are fully implemented, EXTDEBUG uses Comment()
  75. + AG... files for the Assembler generation
  76. Revision 1.4 1998/03/02 01:48:07 peter
  77. * renamed target_DOS to target_GO32V1
  78. + new verbose system, merged old errors and verbose units into one new
  79. verbose.pas, so errors.pas is obsolete
  80. Revision 1.3 1998/02/13 10:34:37 daniel
  81. * Made Motorola version compilable.
  82. * Fixed optimizer
  83. Revision 1.2 1998/01/27 23:34:35 peter
  84. + SIGINT capture with exit. It works for linux and go32v2 (last one
  85. not 100% yet)
  86. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  87. FPC Compiler CVS start
  88. }