home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / amiga / ed-0.1-src.lha / ed-0.1 / signal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-19  |  2.8 KB  |  143 lines

  1. /* signal.c: This file contains the signal routines for the ed line editor. */
  2. /* ed line editor.
  3.    Copyright (C) 1993 Andrew Moore, Talke Studio
  4.    All Rights Reserved
  5.  
  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, or (at your option)
  9.    any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful, but
  12.    WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #ifndef lint
  22. static char *rcsid = "@(#)$Id: signal.c,v 1.4 1994/03/19 03:25:17 alm Exp $";
  23. #endif
  24.  
  25.  
  26. #include <setjmp.h>
  27.  
  28. #include "ed.h"
  29.  
  30.  
  31. void
  32. (*reliable_signal (sno, hndlr)) ()
  33.      int sno;
  34.      void (*hndlr) ();
  35. {
  36. #ifndef HAVE_SIGACTION
  37.   signal (sno, hndlr);
  38. #else
  39.   struct sigaction sa, osa;
  40.  
  41.   sa.sa_handler = hndlr;
  42.   sigemptyset (&sa.sa_mask);
  43.   sa.sa_flags = 0;
  44. #ifdef SA_RESTART
  45.       sa.sa_flags |= SA_RESTART;
  46. #endif
  47.   return (sigaction (sno, &sa, &osa) < 0) ?  SIG_ERR : osa.sa_handler;
  48. #endif /* HAVE_SIGACTION */
  49. }
  50.  
  51.  
  52. void
  53. signal_hup (signo)
  54.      int signo;
  55. {
  56.   if (mutex)
  57.     sigflags |= (1 << (signo - 1));
  58.   else
  59.     handle_hup (signo);
  60. }
  61.  
  62.  
  63. void
  64. signal_int (signo)
  65.      int signo;
  66. {
  67.   if (mutex)
  68.     sigflags |= (1 << (signo - 1));
  69.   else
  70.     handle_int (signo);
  71. }
  72.  
  73.  
  74. #ifdef HAVE_SIGSETJMP
  75. extern sigjmp_buf env;
  76. #else
  77. extern jmp_buf env;
  78. #endif
  79. extern int sigactive;
  80.  
  81. void
  82. handle_hup (signo)
  83.      int signo;
  84. {
  85.   char *hup = NULL;        /* hup filename */
  86.   char *s;
  87.   int n;
  88.  
  89.   if (!sigactive)
  90.     quit (1);
  91.   sigflags &= ~(1 << (signo - 1));
  92.   if (addr_last && write_file ("ed.hup", "w", 1, addr_last) < 0 &&
  93.       (s = getenv ("HOME")) != NULL &&
  94.       (n = strlen (s)) + 7 <= PATH_MAX &&    /* "ed.hup" + '/' */
  95.       (hup = (char *) malloc (n + 8)) != NULL)
  96.     {
  97.       strcpy (hup, s);
  98.       if (n && hup[n - 1] != '/')
  99.       hup[n++] = '/';
  100.       strcpy (hup + n, "ed.hup");
  101.       write_file (hup, "w", 1, addr_last);
  102.     }
  103.   quit (2);
  104. }
  105.  
  106.  
  107. void
  108. handle_int (signo)
  109.      int signo;
  110. {
  111.   if (!sigactive)
  112.     quit (1);
  113.   sigflags &= ~(1 << (signo - 1));
  114. #ifdef HAVE_SIGSETJMP
  115.   siglongjmp (env, -1);
  116. #else
  117.   longjmp (env, -1);
  118. #endif
  119. }
  120.  
  121.  
  122. int cols = 72;            /* wrap column */
  123.  
  124. void
  125. handle_winch (signo)
  126.      int signo;
  127. {
  128. #ifdef TIOCGWINSZ
  129.   struct winsize ws;        /* window size structure */
  130. #endif
  131.  
  132.   sigflags &= ~(1 << (signo - 1));
  133. #ifdef TIOCGWINSZ
  134.   if (ioctl (0, TIOCGWINSZ, (char *) &ws) >= 0)
  135.     {
  136.       if (ws.ws_row > 2)
  137.     rows = ws.ws_row - 2;
  138.       if (ws.ws_col > 8)
  139.     cols = ws.ws_col - 8;
  140.     }
  141. #endif
  142. }
  143.