xref: /csrg-svn/usr.bin/f77/libF77/signal_.c (revision 47940)
1*47940Sbostic /*-
2*47940Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic  * All rights reserved.
4*47940Sbostic  *
5*47940Sbostic  * %sccs.include.proprietary.c%
6*47940Sbostic  */
7*47940Sbostic 
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)signal_.c	5.4 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic 
1210546Sdlw /*
1310546Sdlw  * change the action for a specified signal
1410546Sdlw  *
1510546Sdlw  * calling sequence:
1610546Sdlw  *	integer cursig, signal, savsig
1710546Sdlw  *	external proc
1810546Sdlw  *	cursig = signal(signum, proc, flag)
1910546Sdlw  * where:
2010546Sdlw  *	'cursig' will receive the current value of signal(2)
2124696Smckusick  *	'signum' must be in the range 0 <= signum <= 32
2210546Sdlw  *
2310546Sdlw  *	If 'flag' is negative, 'proc' must be an external proceedure name.
2410546Sdlw  *
2510546Sdlw  *	If 'flag' is 0 or positive, it will be passed to signal(2) as the
2610546Sdlw  *	signal action flag. 0 resets the default action; 1 sets 'ignore'.
2710546Sdlw  *	'flag' may be the value returned from a previous call to signal.
2810546Sdlw  *
2910546Sdlw  * This routine arranges to trap user specified signals so that it can
3010546Sdlw  * pass the signum fortran style - by address. (boo)
3110546Sdlw  */
3210546Sdlw 
3310546Sdlw #include	"../libI77/f_errno.h"
3410546Sdlw 
3524696Smckusick static int (*dispatch[33])();
3610546Sdlw int (*signal())();
3710546Sdlw int sig_trap();
3810546Sdlw 
signal_(sigp,procp,flag)3910546Sdlw long signal_(sigp, procp, flag)
4010546Sdlw long *sigp, *flag;
4110546Sdlw int (*procp)();
4210546Sdlw {
4310546Sdlw 	int (*oldsig)();
4410546Sdlw 	int (*oldispatch)();
4510546Sdlw 
4610546Sdlw 	oldispatch = dispatch[*sigp];
4710546Sdlw 
4824696Smckusick 	if (*sigp < 0 || *sigp > 32)
4910546Sdlw 		return(-((long)(errno=F_ERARG)));
5010546Sdlw 
5110546Sdlw 	if (*flag < 0)	/* function address passed */
5210546Sdlw 	{
5310546Sdlw 		dispatch[*sigp] = procp;
5410546Sdlw 		oldsig = signal((int)*sigp, sig_trap);
5510546Sdlw 	}
5610546Sdlw 
5710546Sdlw 	else		/* integer value passed */
5810546Sdlw 		oldsig = signal((int)*sigp, (int)*flag);
5910546Sdlw 
6010546Sdlw 	if (oldsig == sig_trap)
6110546Sdlw 		return((long)oldispatch);
6210546Sdlw 	return((long)oldsig);
6310546Sdlw }
6410546Sdlw 
sig_trap(sn)6510546Sdlw sig_trap(sn)
6610546Sdlw int sn;
6710546Sdlw {
6810546Sdlw 	long lsn = (long)sn;
6910546Sdlw 	return((*dispatch[sn])(&lsn));
7010546Sdlw }
71