xref: /netbsd/bin/ksh/siglist.sh (revision bf9ec67e)
1#!/bin/sh
2#	$NetBSD: siglist.sh,v 1.2 1997/01/12 19:12:18 tls Exp $
3#
4# Script to generate a sorted, complete list of signals, suitable
5# for inclusion in trap.c as array initializer.
6#
7
8set -e
9
10in=tmpi$$.c
11out=tmpo$$.c
12ecode=1
13trapsigs='0 1 2 13 15'
14trap 'rm -f $in $out; trap 0; exit $ecode' $trapsigs
15
16CPP="${1-cc -E}"
17
18# The trap here to make up for a bug in bash (1.14.3(1)) that calls the trap
19(trap $trapsigs;
20 echo '#include "sh.h"';
21 echo '	{ QwErTy SIGNALS , "DUMMY" , "hook for number of signals" },';
22 sed -e '/^[	 ]*#/d' -e 's/^[	 ]*\([^ 	][^ 	]*\)[	 ][	 ]*\(.*[^ 	]\)[ 	]*$/#ifdef SIG\1\
23	{ QwErTy SIG\1 , "\1", "\2" },\
24#endif/') > $in
25$CPP $in  > $out
26sed -n 's/{ QwErTy/{/p' < $out | awk '{print NR, $0}' | sort +2n +0n |
27    sed 's/^[0-9]* //' |
28    awk 'BEGIN { last=0; nsigs=0; }
29	{
30	    if ($2 ~ /^[0-9][0-9]*$/ && $3 == ",") {
31		n = $2;
32		if (n > 0 && n != last) {
33		    while (++last < n) {
34			printf "\t{ %d , (char *) 0, `Signal %d` } ,\n", last, last;
35		    }
36		    print;
37		}
38	    }
39	}' |
40    tr '`' '"' | grep -v '"DUMMY"'
41ecode=0
42