catch.pas 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. {$define has_signal}
  27. {$ifdef havelinuxrtl10}
  28. Linux,
  29. {$else}
  30. BaseUnix,Unix,
  31. {$endif}
  32. {$endif}
  33. {$ifdef go32v2}
  34. {$define has_signal}
  35. dpmiexcp,
  36. {$endif}
  37. {$ifdef watcom}
  38. {$define has_signal}
  39. dpmiexcp,
  40. {$endif}
  41. verbose;
  42. {$ifdef has_signal}
  43. Var
  44. NewSignal,
  45. OldSigInt : SignalHandler;
  46. {$endif}
  47. Const in_const_evaluation : boolean = false;
  48. Implementation
  49. uses
  50. comphook;
  51. {$ifdef has_signal}
  52. {$ifdef unix}
  53. Procedure CatchSignal(Sig : Longint);cdecl;
  54. {$else}
  55. Function CatchSignal(Sig : longint):longint; cdecl;
  56. {$endif}
  57. begin
  58. case Sig of
  59. SIGINT :
  60. raise EControlCAbort.Create;
  61. end;
  62. {$ifndef unix}
  63. CatchSignal:=0;
  64. {$endif}
  65. end;
  66. {$endif def has_signal}
  67. begin
  68. {$ifndef nocatch}
  69. {$ifdef has_signal}
  70. NewSignal:=SignalHandler(@CatchSignal);
  71. OldSigInt:={$ifdef havelinuxrtl10}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGINT,NewSignal);
  72. {$endif}
  73. {$endif nocatch}
  74. end.