File: siglist.sh

package info (click to toggle)
posh 0.12.3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,328 kB
  • ctags: 1,621
  • sloc: ansic: 14,596; xml: 1,604; sh: 1,365; perl: 964; makefile: 131
file content (41 lines) | stat: -rwxr-xr-x 1,053 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh

#
# Script to generate a sorted, complete list of signals, suitable
# for inclusion in trap.c as array initializer.
#

set -e

in=tmpi$$.c
out=tmpo$$.c
ecode=1
trapsigs='EXIT HUP INT PIPE TERM'
trap 'rm -f $in $out; trap - EXIT; exit $ecode' $trapsigs

CPP="${1-cc -E}"

# The trap here to make up for a bug in bash (1.14.3(1)) that calls the trap
(trap $trapsigs;
 echo '#include "sh.h"';
 echo '	{ QwErTy SIGNALS , "DUMMY" , "hook for number of signals" },';
 sed -e '/^[	 ]*#/d' -e 's/^[	 ]*\([^ 	][^ 	]*\)[	 ][	 ]*\(.*[^ 	]\)[ 	]*$/#ifdef SIG\1\
	{ QwErTy SIG\1 , "\1", "\2", 0, 0, 0, 0, 0 },\
#endif/') > $in
$CPP $in  > $out
sed -n 's/{ QwErTy/{/p' < $out | awk '{print NR, $0}' | sort -n -k 3 -k 1 |
    sed 's/^[0-9]* //' |
    awk 'BEGIN { last=0; nsigs=0; }
	{
	    if ($2 ~ /^[0-9][0-9]*$/ && $3 == ",") {
		n = $2;
		if (n > 0 && n != last) {
		    while (++last < n) {
			printf "\t{ %d , (char *) 0, `Signal %d`, 0, 0, 0, 0, 0 } ,\n", last, last;
		    }
		    print;
		}
	    }
	}' |
    tr '`' '"' | grep -v '"DUMMY"'
ecode=0