catch.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. uses
  52. comphook;
  53. {$ifdef has_signal}
  54. {$ifdef unix}
  55. Procedure CatchSignal(Sig : Longint);cdecl;
  56. {$else}
  57. Function CatchSignal(Sig : longint):longint;
  58. {$endif}
  59. begin
  60. case Sig of
  61. SIGINT :
  62. raise EControlCAbort.Create;
  63. end;
  64. {$ifndef unix}
  65. CatchSignal:=0;
  66. {$endif}
  67. end;
  68. {$endif def has_signal}
  69. begin
  70. {$ifndef nocatch}
  71. {$ifdef has_signal}
  72. NewSignal:=SignalHandler(@CatchSignal);
  73. OldSigInt:={$ifdef havelinuxrtl10}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGINT,NewSignal);
  74. {$endif}
  75. {$endif nocatch}
  76. end.