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