fpcatch.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. {$i globdir.inc}
  15. {$ifdef linux}
  16. uses
  17. linux;
  18. {$endif}
  19. {$ifdef go32v2}
  20. uses
  21. dpmiexcp;
  22. {$endif}
  23. {$ifdef HasSignal}
  24. Var
  25. NewSignal,OldSigSegm,OldSigInt : SignalHandler;
  26. {$endif}
  27. Const
  28. CtrlCPressed : Boolean = false;
  29. Implementation
  30. uses
  31. {$ifdef FPC}
  32. keyboard,
  33. drivers,
  34. {$endif FPC}
  35. app,commands,msgbox,
  36. FPString,FPIDE;
  37. {$ifdef HasSignal}
  38. {$ifdef linux}
  39. Procedure CatchSignal(Sig : Integer);cdecl;
  40. {$else}
  41. Function CatchSignal(Sig : longint):longint;
  42. {$endif}
  43. var MustQuit: boolean;
  44. begin
  45. case Sig of
  46. SIGSEGV : begin
  47. if Assigned(Application) then IDEApp.Done;
  48. Writeln('Internal Error caught');
  49. {$ifndef DEBUG}
  50. Halt;
  51. {$else DEBUG}
  52. RunError(216);
  53. {$endif DEBUG}
  54. end;
  55. SIGINT : begin
  56. IF NOT CtrlCPressed and Assigned(Application) then
  57. begin
  58. MustQuit:=false;
  59. {$ifdef FPC}
  60. CtrlCPressed:=true;
  61. Keyboard.PutKeyEvent((kbCtrl shl 16) or kbCtrlC);
  62. {$endif FPC}
  63. end
  64. else
  65. begin
  66. if Assigned(Application) then
  67. MustQuit:=MessageBox(#3+msg_QuitConfirm,nil,mferror+mfyesbutton+mfnobutton)=cmYes
  68. else
  69. MustQuit:=true;
  70. end;
  71. if MustQuit then
  72. begin
  73. if Assigned(Application) then IDEApp.Done;
  74. {$ifndef DEBUG}
  75. Halt;
  76. {$else DEBUG}
  77. RunError(216);
  78. {$endif DEBUG}
  79. end;
  80. end;
  81. end;
  82. {$ifndef linux}
  83. CatchSignal:=0;
  84. {$endif}
  85. end;
  86. {$endif def HasSignal}
  87. begin
  88. {$ifdef HasSignal}
  89. {$ifndef TP}
  90. NewSignal:=SignalHandler(@CatchSignal);
  91. {$else TP}
  92. NewSignal:=SignalHandler(CatchSignal);
  93. {$endif TP}
  94. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  95. OldSigInt:=Signal (SIGINT,NewSignal);
  96. {$endif}
  97. end.
  98. {
  99. $Log$
  100. Revision 1.6 2000-06-22 09:07:11 pierre
  101. * Gabor changes: see fixes.txt
  102. Revision 1.5 2000/05/02 08:42:26 pierre
  103. * new set of Gabor changes: see fixes.txt
  104. Revision 1.4 2000/03/07 21:09:20 pierre
  105. * Use globdir.inc HasSignal conditional
  106. + Uses PutKeyEvent for CtrlC
  107. Revision 1.3 1999/12/20 14:23:16 pierre
  108. * MyApp renamed IDEApp
  109. * TDebugController.ResetDebuggerRows added to
  110. get resetting of debugger rows
  111. Revision 1.2 1999/04/07 21:55:42 peter
  112. + object support for browser
  113. * html help fixes
  114. * more desktop saving things
  115. * NODEBUG directive to exclude debugger
  116. Revision 1.1 1999/02/20 15:18:28 peter
  117. + ctrl-c capture with confirm dialog
  118. + ascii table in the tools menu
  119. + heapviewer
  120. * empty file fixed
  121. * fixed callback routines in fpdebug to have far for tp7
  122. }