home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / bmd-1.0beta.tar.Z / bmd-1.0beta.tar / bmd-1.0beta / app / omtd / sig-handler.c < prev    next >
C/C++ Source or Header  |  1991-01-13  |  1KB  |  63 lines

  1. /*
  2.  * Copyright (c) 1990 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Lawrence Berkeley Laboratory,
  11.  * Berkeley, CA.  The name of the University may not be used to
  12.  * endorse or promote products derived from this software without
  13.  * specific prior written permission.
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  */
  18. #include <signal.h>
  19. #include <setjmp.h>
  20.  
  21. struct fnlist {
  22.     int (*f)();
  23.     struct fnlist *next;
  24. };
  25.  
  26. struct fnlist *fns;
  27.  
  28. static void
  29. sigint()
  30. {
  31.     struct fnlist *p;
  32.  
  33.     putchar('\n');
  34.     for (p = fns; p != 0; p = p->next) 
  35.         if ((*p->f)())
  36.             break;
  37. }
  38.  
  39. sigint_push(fn)
  40.     int (*fn)();
  41. {
  42.     struct fnlist *p = (struct fnlist *)malloc(sizeof(*p));
  43.  
  44.     p->f = fn;
  45.     p->next = fns;
  46.     fns = p;
  47. }
  48.  
  49. sigint_pop(fn)
  50.     int (*fn)();
  51. {
  52.     struct fnlist *p = fns;
  53.  
  54.     fns = fns->next;
  55.     free((char *)p);
  56. }
  57.  
  58. init_sigint_handler()
  59. {
  60.     signal(SIGINT, sigint);
  61. }
  62.  
  63.