catch.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {
  2. Copyright (c) 1998-2002 by Michael Van Canneyt
  3. Unit to catch segmentation faults and Ctrl-C and exit gracefully
  4. under linux and go32v2
  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 catch;
  19. {$i fpcdefs.inc}
  20. {$ifdef DEBUG}
  21. {$define NOCATCH}
  22. {$endif DEBUG}
  23. interface
  24. uses
  25. {$ifdef unix}
  26. {$ifndef beos}
  27. {$define has_signal}
  28. {$ifdef havelinuxrtl10}
  29. Linux,
  30. {$else}
  31. BaseUnix,Unix,
  32. {$endif}
  33. {$endif}
  34. {$endif}
  35. {$ifdef go32v2}
  36. {$define has_signal}
  37. dpmiexcp,
  38. {$endif}
  39. {$ifdef watcom}
  40. {$define has_signal}
  41. dpmiexcp,
  42. {$endif}
  43. verbose;
  44. {$ifdef has_signal}
  45. Var
  46. NewSignal,
  47. OldSigInt : SignalHandler;
  48. {$endif}
  49. Const in_const_evaluation : boolean = false;
  50. Implementation
  51. {$IFNDEF MACOS_USE_FAKE_SYSUTILS}
  52. uses
  53. comphook;
  54. {$ENDIF MACOS_USE_FAKE_SYSUTILS}
  55. {$ifdef has_signal}
  56. {$ifdef unix}
  57. Procedure CatchSignal(Sig : Longint);cdecl;
  58. {$else}
  59. Function CatchSignal(Sig : longint):longint;
  60. {$endif}
  61. begin
  62. case Sig of
  63. SIGINT :
  64. raise EControlCAbort.Create;
  65. end;
  66. {$ifndef unix}
  67. CatchSignal:=0;
  68. {$endif}
  69. end;
  70. {$endif def has_signal}
  71. begin
  72. {$ifndef nocatch}
  73. {$ifdef has_signal}
  74. NewSignal:=SignalHandler(@CatchSignal);
  75. OldSigInt:={$ifdef havelinuxrtl10}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGINT,NewSignal);
  76. {$endif}
  77. {$endif nocatch}
  78. end.