#
# SCCS:  @(#)sigtool	1.3
#
# (C) Copyright 1997 X/Open Company Limited
#
# All rights reserved.  No part of this source code may be reproduced,
# stored in a retrieval system, or transmitted, in any form or by any
# means, electronic, mechanical, photocopying, recording or otherwise,
# except as stated in the end-user licence agreement, without the prior
# permission of the copyright owners.
# A copy of the end-user licence agreement is contained in the file
# Licence which accompanies this distribution.
#
# X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
# the UK and other countries.
#
# ************************************************************************
# The sigtool script generates the signal parameters automatically
# and outputs these on standard output.
#
# This can be used to parameterize a new port when creating 
# a defines.mk file for your platform.
#
# SH_STD_SIGNALS: standard signal numbers 
# SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGPIPE, SIGALRM,
# SIGTERM, SIGUSR1, SIGUSR2, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU
#
# SH_SPEC_SIGNALS:  signals that are always unhandled 
# May need to include SIGSEGV and others if the shell can't trap them
# SIGKILL, SIGCHLD, SIGSTOP, (SIGSEGV, ...)
#
# SH_NSIG: May need to be less than the value specified with -DNSIG in CDEFS
# if the shell can't trap higher signal numbers 
#
# Change History
#
# 18 Sep 1997  Andrew Josey
# Change cat to use sed so it copes with header files which have
# a space between the # and define statements.
#
# Note that on IRIX there is a signal called SIG32 which confuses this
# script.
#
case `uname -s` in
        Windows_NT|Windows_95|DOS)
                # on a WIN32 system
		echo "No signal support on a WIN32 system"
		exit 1
                ;;
        *)
                # on a UNIX system
                ;;
esac   
                                                             
usrinclude="/usr/include"
tmpfile=/tmp/sg$$
: generate list of signal names
#first try /usr/include
#assume no more than 128 signals
    sed 's/^#[ 	]*define/#define/'  $usrinclude/signal.h $usrinclude/sys/signal.h 2>&1 | awk '
$1 ~ /^#define$/ && $2 ~ /^SIG[A-Z0-9]*$/ && $3 ~ /^[1-9][0-9]*$/ {
    sig[$3] = substr($2,4,20)
    if (max < $3 && $3 < 128) {
	max = $3
    }
}

END {
    for (i=1; i<=max; i++) {
	if (sig[i] == "")
	     ;
	else
	    printf "%s=%d\n", sig[i], i
	if (i < max)
	    printf ""
    }
    printf "\n"
	printf "NSIG=%d\n", max+1
}
' > $tmpfile


# source in signal names and values
. $tmpfile
rm $tmpfile

echo "SH_STD_SIGNALS = ${HUP} ${INT} ${QUIT} ${ILL} ${ABRT} ${FPE} ${PIPE} ${ALRM} ${TERM} ${USR1} ${USR2} ${TSTP} ${CONT} ${TTIN} ${TTOU}"

echo "SH_SPEC_SIGNALS = ${KILL} ${CHLD} ${STOP} ${SEGV}"

echo "SH_NSIG = ${NSIG}"

# if part of the build process then this can be hooked
# into  make as follows:
#make SH_NSIG="${NSIG}" SH_SPEC_SIGNALS="${KILL} ${CHLD} ${STOP} ${SEGV}" SH_STD_SIGNALS="${HUP} ${INT} ${QUIT} ${ILL} ${ABRT} ${FPE} ${PIPE} ${ALRM} ${TERM} ${USR1} ${USR2} ${TSTP} ${CONT} ${TTIN} ${TTOU}"
