catch.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. {$define has_signal}
  24. linux,
  25. {$endif}
  26. {$ifdef go32v2}
  27. {$define has_signal}
  28. dpmiexcp,
  29. {$endif}
  30. verbose;
  31. {$ifdef has_signal}
  32. Var
  33. NewSignal,OldSigSegm,OldSigInt : SignalHandler;
  34. Implementation
  35. {$ifdef has_signal}
  36. {$ifdef linux}
  37. Procedure CatchSignal(Sig : Integer);cdecl;
  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. {$endif def has_signal}
  58. begin
  59. {$ifdef has_signal}
  60. {$ifndef TP}
  61. NewSignal:=SignalHandler(@CatchSignal);
  62. {$else TP}
  63. NewSignal:=SignalHandler(CatchSignal);
  64. {$endif TP}
  65. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  66. OldSigInt:=Signal (SIGINT,NewSignal);
  67. {$endif}
  68. end.
  69. {
  70. $Log$
  71. Revision 1.3 1999-01-27 13:20:37 pierre
  72. * slightly rewritten code
  73. Revision 1.2 1998/09/08 13:01:09 michael
  74. Adapted to changed Signal call
  75. Revision 1.1.1.1 1998/03/25 11:18:12 root
  76. * Restored version
  77. Revision 1.5 1998/03/10 01:17:15 peter
  78. * all files have the same header
  79. * messages are fully implemented, EXTDEBUG uses Comment()
  80. + AG... files for the Assembler generation
  81. Revision 1.4 1998/03/02 01:48:07 peter
  82. * renamed target_DOS to target_GO32V1
  83. + new verbose system, merged old errors and verbose units into one new
  84. verbose.pas, so errors.pas is obsolete
  85. Revision 1.3 1998/02/13 10:34:37 daniel
  86. * Made Motorola version compilable.
  87. * Fixed optimizer
  88. Revision 1.2 1998/01/27 23:34:35 peter
  89. + SIGINT capture with exit. It works for linux and go32v2 (last one
  90. not 100% yet)
  91. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  92. FPC Compiler CVS start
  93. }