xref: /original-bsd/usr.bin/f77/libF77/signal_.c (revision bdc0a208)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)signal_.c	5.4 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 /*
13  * change the action for a specified signal
14  *
15  * calling sequence:
16  *	integer cursig, signal, savsig
17  *	external proc
18  *	cursig = signal(signum, proc, flag)
19  * where:
20  *	'cursig' will receive the current value of signal(2)
21  *	'signum' must be in the range 0 <= signum <= 32
22  *
23  *	If 'flag' is negative, 'proc' must be an external proceedure name.
24  *
25  *	If 'flag' is 0 or positive, it will be passed to signal(2) as the
26  *	signal action flag. 0 resets the default action; 1 sets 'ignore'.
27  *	'flag' may be the value returned from a previous call to signal.
28  *
29  * This routine arranges to trap user specified signals so that it can
30  * pass the signum fortran style - by address. (boo)
31  */
32 
33 #include	"../libI77/f_errno.h"
34 
35 static int (*dispatch[33])();
36 int (*signal())();
37 int sig_trap();
38 
39 long signal_(sigp, procp, flag)
40 long *sigp, *flag;
41 int (*procp)();
42 {
43 	int (*oldsig)();
44 	int (*oldispatch)();
45 
46 	oldispatch = dispatch[*sigp];
47 
48 	if (*sigp < 0 || *sigp > 32)
49 		return(-((long)(errno=F_ERARG)));
50 
51 	if (*flag < 0)	/* function address passed */
52 	{
53 		dispatch[*sigp] = procp;
54 		oldsig = signal((int)*sigp, sig_trap);
55 	}
56 
57 	else		/* integer value passed */
58 		oldsig = signal((int)*sigp, (int)*flag);
59 
60 	if (oldsig == sig_trap)
61 		return((long)oldispatch);
62 	return((long)oldsig);
63 }
64 
65 sig_trap(sn)
66 int sn;
67 {
68 	long lsn = (long)sn;
69 	return((*dispatch[sn])(&lsn));
70 }
71