catch.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *********************************************************************
  18. }
  19. Unit catch;
  20. interface
  21. uses
  22. {$ifdef linux}
  23. linux,
  24. {$endif}
  25. {$ifdef go32v2}
  26. dpmiexcp,
  27. {$endif}
  28. verbose;
  29. Var
  30. NewSignal,OldSigSegm,OldSigInt : SignalHandler;
  31. Implementation
  32. {$ifdef linux}
  33. Procedure CatchSignal(Sig : Integer);cdecl;
  34. {$else}
  35. Function CatchSignal(Sig : longint):longint;
  36. {$endif}
  37. begin
  38. case Sig of
  39. SIGSEGV : begin
  40. { Temporary message - until we get an error number... }
  41. writeln ('Panic : Internal compiler error, exiting.');
  42. internalerror(9999);
  43. end;
  44. SIGINT : begin
  45. WriteLn('Ctrl-C Signaled!');
  46. Stop;
  47. end;
  48. end;
  49. {$ifndef linux}
  50. CatchSignal:=0;
  51. {$endif}
  52. end;
  53. begin
  54. {$ifdef linux}
  55. NewSignal:=@CatchSignal;
  56. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  57. OldSigInt:=Signal (SIGINT,NewSignal);
  58. {$else}
  59. NewSignal:=SignalHandler(@CatchSignal);
  60. Signal (SIGSEGV,NewSignal);
  61. Signal (SIGINT,NewSignal);
  62. {$endif}
  63. end.
  64. {
  65. $Log$
  66. Revision 1.2 1998-09-08 13:01:09 michael
  67. Adapted to changed Signal call
  68. Revision 1.1.1.1 1998/03/25 11:18:12 root
  69. * Restored version
  70. Revision 1.5 1998/03/10 01:17:15 peter
  71. * all files have the same header
  72. * messages are fully implemented, EXTDEBUG uses Comment()
  73. + AG... files for the Assembler generation
  74. Revision 1.4 1998/03/02 01:48:07 peter
  75. * renamed target_DOS to target_GO32V1
  76. + new verbose system, merged old errors and verbose units into one new
  77. verbose.pas, so errors.pas is obsolete
  78. Revision 1.3 1998/02/13 10:34:37 daniel
  79. * Made Motorola version compilable.
  80. * Fixed optimizer
  81. Revision 1.2 1998/01/27 23:34:35 peter
  82. + SIGINT capture with exit. It works for linux and go32v2 (last one
  83. not 100% yet)
  84. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  85. FPC Compiler CVS start
  86. }