catch.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. {$i fpcdefs.inc}
  21. {$ifdef DEBUG}
  22. {$define NOCATCH}
  23. {$endif DEBUG}
  24. interface
  25. uses
  26. {$ifdef unix}
  27. {$ifndef beos}
  28. {$define has_signal}
  29. {$ifdef havelinuxrtl10}
  30. Linux,
  31. {$else}
  32. BaseUnix,Unix,
  33. {$endif}
  34. {$endif}
  35. {$endif}
  36. {$ifdef go32v2}
  37. {$define has_signal}
  38. dpmiexcp,
  39. {$endif}
  40. {$ifdef watcom}
  41. {$define has_signal}
  42. dpmiexcp,
  43. {$endif}
  44. verbose;
  45. {$ifdef has_signal}
  46. Var
  47. NewSignal,
  48. OldSigInt : SignalHandler;
  49. {$endif}
  50. Const in_const_evaluation : boolean = false;
  51. Implementation
  52. uses
  53. sysutils;
  54. {$ifdef has_signal}
  55. {$ifdef unix}
  56. Procedure CatchSignal(Sig : Longint);cdecl;
  57. {$else}
  58. Function CatchSignal(Sig : longint):longint;
  59. {$endif}
  60. begin
  61. case Sig of
  62. SIGINT :
  63. raise Exception.Create('Ctrl-C Signaled!');
  64. end;
  65. {$ifndef unix}
  66. CatchSignal:=0;
  67. {$endif}
  68. end;
  69. {$endif def has_signal}
  70. begin
  71. {$ifndef nocatch}
  72. {$ifdef has_signal}
  73. NewSignal:=SignalHandler(@CatchSignal);
  74. OldSigInt:={$ifdef havelinuxrtl10}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGINT,NewSignal);
  75. {$endif}
  76. {$endif nocatch}
  77. end.
  78. {
  79. $Log$
  80. Revision 1.21 2005-01-26 16:23:28 peter
  81. * detect arithmetic overflows for constants at compile time
  82. * use try..except instead of setjmp
  83. Revision 1.20 2004/10/15 09:14:16 mazen
  84. - remove $IFDEF DELPHI and related code
  85. - remove $IFDEF FPCPROCVAR and related code
  86. Revision 1.19 2004/09/09 08:19:47 olle
  87. + Added argument to Stop
  88. Revision 1.18 2004/06/20 08:55:28 florian
  89. * logs truncated
  90. }