fpcatch.pas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit fpcatch;
  13. interface
  14. {$ifdef linux}
  15. {$define has_signal}
  16. uses
  17. linux;
  18. {$endif}
  19. {$ifdef go32v2}
  20. {$define has_signal}
  21. uses
  22. dpmiexcp;
  23. {$endif}
  24. {$ifdef has_signal}
  25. Var
  26. NewSignal,OldSigSegm,OldSigInt : SignalHandler;
  27. {$endif}
  28. Implementation
  29. uses
  30. commands,msgbox,
  31. fpide,fpviews;
  32. {$ifdef has_signal}
  33. {$ifdef linux}
  34. Procedure CatchSignal(Sig : Integer);cdecl;
  35. {$else}
  36. Function CatchSignal(Sig : longint):longint;
  37. {$endif}
  38. begin
  39. case Sig of
  40. SIGSEGV : begin
  41. MyApp.Done;
  42. Writeln('Internal Error caught');
  43. Halt;
  44. end;
  45. SIGINT : begin
  46. if MessageBox(#3'Do You really want to quit?',nil,mferror+mfyesbutton+mfnobutton)=cmYes then
  47. begin
  48. MyApp.Done;
  49. Halt;
  50. end;
  51. end;
  52. end;
  53. {$ifndef linux}
  54. CatchSignal:=0;
  55. {$endif}
  56. end;
  57. {$endif def has_signal}
  58. begin
  59. {$ifdef has_signal}
  60. {$ifndef TP}
  61. NewSignal:=SignalHandler(@CatchSignal);
  62. {$else TP}
  63. NewSignal:=SignalHandler(CatchSignal);
  64. {$endif TP}
  65. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  66. OldSigInt:=Signal (SIGINT,NewSignal);
  67. {$endif}
  68. end.
  69. {
  70. $Log$
  71. Revision 1.1 1999-02-20 15:18:28 peter
  72. + ctrl-c capture with confirm dialog
  73. + ascii table in the tools menu
  74. + heapviewer
  75. * empty file fixed
  76. * fixed callback routines in fpdebug to have far for tp7
  77. }