siglist.sh revision 1.13 1 #!/bin/sh
2 # $NetBSD: siglist.sh,v 1.13 2021/02/23 01:31:30 christos 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 : ${SED:=sed}
12
13 in=tmpi$$.c
14 out=tmpo$$.c
15 ecode=1
16 trapsigs='0 1 2 13 15'
17 trap 'rm -f $in $out; trap 0; exit $ecode' $trapsigs
18
19 CPP="${1-cc -E}"
20
21 # The trap here to make up for a bug in bash (1.14.3(1)) that calls the trap
22 (trap $trapsigs;
23 echo '#include "sh.h"';
24 echo ' { QwErTy /* dummy for sed sillies */ },';
25 ${SED} -e '/^[ ]*#/d' -e 's/^[ ]*\([^ ][^ ]*\)[ ][ ]*\(.*[^ ]\)[ ]*$/#ifdef SIG\1\
26 { QwErTy .signal = SIG\1 , .name = "\1", .mess = "\2" },\
27 #endif/') > $in
28 echo ' { QwErTy .signal = SIGNALS , .name = "DUMMY", .mess = "hook to expand array to total signals" },' >> $in
29 # work around for gcc > 5
30 $CPP $in | grep -v '^#' | tr -d '\n' | ${SED} 's/},/},\
31 /g' > $out
32 ${SED} -n 's/{ QwErTy/{/p' < $out | ${AWK} '{print NR, $0}' | sort -k 5n -k 1n |
33 ${SED} -E -e 's/^[0-9]* //' -e 's/ +/ /' |
34 ${AWK} 'BEGIN { last=0; }
35 {
36 if ($4 ~ /^[0-9][0-9]*$/ && $5 == ",") {
37 n = $4;
38 if (n > 0 && n != last) {
39 while (++last < n) {
40 printf "\t{ .signal = %d , .name = NULL, .mess = `Signal %d` } ,\n", last, last;
41 }
42 print;
43 }
44 }
45 }' |
46 tr '`' '"' | grep -v '"DUMMY"'
47 ecode=0
48