Home | History | Annotate | Line # | Download | only in ksh
siglist.sh revision 1.5
      1 #!/bin/sh
      2 #	$NetBSD: siglist.sh,v 1.5 2006/11/14 19:10:55 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 in=tmpi$$.c
     11 out=tmpo$$.c
     12 ecode=1
     13 trapsigs='0 1 2 13 15'
     14 trap 'rm -f $in $out; trap 0; exit $ecode' $trapsigs
     15 
     16 CPP="${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 .signal = SIG\1 , .name = "\1", .mess = "\2" },\
     24 #endif/') > $in
     25 $CPP $in  > $out
     26 sed -n 's/{ QwErTy/{/p' < $out | awk '{print NR, $0}' | sort -k3n -k1n |
     27     sed 's/^[0-9]* //' |
     28     awk 'BEGIN { last=0; nsigs=0; }
     29 	{
     30 	    if ($4 ~ /^[0-9][0-9]*$/ && $5 == ",") {
     31 		n = $4;
     32 		if (n > 0 && n != last) {
     33 		    while (++last < n) {
     34 			printf "\t{ .signal = %d , .name = NULL, .mess = `Signal %d` } ,\n", last, last;
     35 		    }
     36 		    print;
     37 		}
     38 	    }
     39 	}' |
     40     tr '`' '"' | grep -v '"DUMMY"'
     41 ecode=0
     42