date and time created 83/01/21 11:19:18 by dlw
authorDavid Wasley <dlw@ucbvax.Berkeley.EDU>
Sat, 22 Jan 1983 03:19:18 +0000 (19:19 -0800)
committerDavid Wasley <dlw@ucbvax.Berkeley.EDU>
Sat, 22 Jan 1983 03:19:18 +0000 (19:19 -0800)
SCCS-vsn: usr.bin/f77/libF77/signal_.c 1.1

usr/src/usr.bin/f77/libF77/signal_.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/f77/libF77/signal_.c b/usr/src/usr.bin/f77/libF77/signal_.c
new file mode 100644 (file)
index 0000000..43331ac
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *     "@(#)signal_.c  1.1"
+ *
+ * change the action for a specified signal
+ *
+ * calling sequence:
+ *     integer cursig, signal, savsig
+ *     external proc
+ *     cursig = signal(signum, proc, flag)
+ * where:
+ *     'cursig' will receive the current value of signal(2)
+ *     'signum' must be in the range 0 <= signum <= 16
+ *
+ *     If 'flag' is negative, 'proc' must be an external proceedure name.
+ *     
+ *     If 'flag' is 0 or positive, it will be passed to signal(2) as the
+ *     signal action flag. 0 resets the default action; 1 sets 'ignore'.
+ *     'flag' may be the value returned from a previous call to signal.
+ *
+ * This routine arranges to trap user specified signals so that it can
+ * pass the signum fortran style - by address. (boo)
+ */
+
+#include       "../libI77/f_errno.h"
+
+static int (*dispatch[17])();
+int (*signal())();
+int sig_trap();
+
+long signal_(sigp, procp, flag)
+long *sigp, *flag;
+int (*procp)();
+{
+       int (*oldsig)();
+       int (*oldispatch)();
+
+       oldispatch = dispatch[*sigp];
+
+       if (*sigp < 0 || *sigp > 16)
+               return(-((long)(errno=F_ERARG)));
+
+       if (*flag < 0)  /* function address passed */
+       {
+               dispatch[*sigp] = procp;
+               oldsig = signal((int)*sigp, sig_trap);
+       }
+
+       else            /* integer value passed */
+               oldsig = signal((int)*sigp, (int)*flag);
+
+       if (oldsig == sig_trap)
+               return((long)oldispatch);
+       return((long)oldsig);
+}
+
+sig_trap(sn)
+int sn;
+{
+       long lsn = (long)sn;
+       return((*dispatch[sn])(&lsn));
+}