catch.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. {$endif}
  35. Implementation
  36. {$ifdef has_signal}
  37. {$ifdef linux}
  38. Procedure CatchSignal(Sig : Integer);cdecl;
  39. {$else}
  40. Function CatchSignal(Sig : longint):longint;
  41. {$endif}
  42. begin
  43. case Sig of
  44. SIGSEGV : begin
  45. { Temporary message - until we get an error number... }
  46. writeln ('Panic : Internal compiler error, exiting.');
  47. internalerror(9999);
  48. end;
  49. SIGINT : begin
  50. WriteLn('Ctrl-C Signaled!');
  51. Stop;
  52. end;
  53. end;
  54. {$ifndef linux}
  55. CatchSignal:=0;
  56. {$endif}
  57. end;
  58. {$endif def has_signal}
  59. begin
  60. {$ifdef has_signal}
  61. {$ifndef TP}
  62. NewSignal:=SignalHandler(@CatchSignal);
  63. {$else TP}
  64. NewSignal:=SignalHandler(CatchSignal);
  65. {$endif TP}
  66. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  67. OldSigInt:=Signal (SIGINT,NewSignal);
  68. {$endif}
  69. end.
  70. {
  71. $Log$
  72. Revision 1.4 1999-01-28 19:42:03 peter
  73. * mssing endif added
  74. Revision 1.3 1999/01/27 13:20:37 pierre
  75. * slightly rewritten code
  76. Revision 1.2 1998/09/08 13:01:09 michael
  77. Adapted to changed Signal call
  78. Revision 1.1.1.1 1998/03/25 11:18:12 root
  79. * Restored version
  80. Revision 1.5 1998/03/10 01:17:15 peter
  81. * all files have the same header
  82. * messages are fully implemented, EXTDEBUG uses Comment()
  83. + AG... files for the Assembler generation
  84. Revision 1.4 1998/03/02 01:48:07 peter
  85. * renamed target_DOS to target_GO32V1
  86. + new verbose system, merged old errors and verbose units into one new
  87. verbose.pas, so errors.pas is obsolete
  88. Revision 1.3 1998/02/13 10:34:37 daniel
  89. * Made Motorola version compilable.
  90. * Fixed optimizer
  91. Revision 1.2 1998/01/27 23:34:35 peter
  92. + SIGINT capture with exit. It works for linux and go32v2 (last one
  93. not 100% yet)
  94. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  95. FPC Compiler CVS start
  96. }