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