fpcatch.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. app,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. var CanQuit: boolean;
  39. begin
  40. case Sig of
  41. SIGSEGV : begin
  42. if Assigned(Application) then IDEApp.Done;
  43. Writeln('Internal Error caught');
  44. Halt;
  45. end;
  46. SIGINT : begin
  47. if Assigned(Application) then
  48. CanQuit:=MessageBox(#3'Do You really want to quit?',nil,mferror+mfyesbutton+mfnobutton)=cmYes
  49. else
  50. CanQuit:=true;
  51. if CanQuit then
  52. begin
  53. if Assigned(Application) then IDEApp.Done;
  54. Halt;
  55. end;
  56. end;
  57. end;
  58. {$ifndef linux}
  59. CatchSignal:=0;
  60. {$endif}
  61. end;
  62. {$endif def has_signal}
  63. begin
  64. {$ifdef has_signal}
  65. {$ifndef TP}
  66. NewSignal:=SignalHandler(@CatchSignal);
  67. {$else TP}
  68. NewSignal:=SignalHandler(CatchSignal);
  69. {$endif TP}
  70. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  71. OldSigInt:=Signal (SIGINT,NewSignal);
  72. {$endif}
  73. end.
  74. {
  75. $Log$
  76. Revision 1.3 1999-12-20 14:23:16 pierre
  77. * MyApp renamed IDEApp
  78. * TDebugController.ResetDebuggerRows added to
  79. get resetting of debugger rows
  80. Revision 1.2 1999/04/07 21:55:42 peter
  81. + object support for browser
  82. * html help fixes
  83. * more desktop saving things
  84. * NODEBUG directive to exclude debugger
  85. Revision 1.1 1999/02/20 15:18:28 peter
  86. + ctrl-c capture with confirm dialog
  87. + ascii table in the tools menu
  88. + heapviewer
  89. * empty file fixed
  90. * fixed callback routines in fpdebug to have far for tp7
  91. }