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