#!/bin/sh # generate rc's internal signal table from signal.h exec > sigmsgs.c echo '#include "sigmsgs.h"' echo echo 'Sigmsgs signals[] = {' sed ' s/\/\*[ ]*// s/[ ]*\*\/// s/([@*+!]) // s/[ ]*([a-zA-Z,->& ]*)[ ]*// s/^[ ]*\#[ ]*define/\#define/ s/[ ]*signal$//' $1 | awk ' BEGIN { # assign to nomesg["SIGNAME"] to suppress a long message nomesg["SIGINT"] = 1 nomesg["SIGPIPE"] = 1 # assign to mesg["SIGNAME"] to override a message mesg["SIGHUP"] = "hangup" mesg["SIGKILL"] = "killed" mesg["SIGQUIT"] = "quit" mesg["SIGTERM"] = "terminated" mesg["SIGURG"] = "urgent condition on i/o channel" mesg["SIGSTOP"] = "stop signal not from tty" mesg["SIGTSTP"] = "stopped" mesg["SIGCONT"] = "continue" mesg["SIGCHLD"] = "child stop or exit" mesg["SIGTTIN"] = "background tty read" mesg["SIGTTOU"] = "background tty write" # assign to ignore["SIGNAME"] to explicitly ignore a named signal ignore["SIGMAX"] = 1 } $1 == "#define" && $2 == "NSIG" && $3 ~ /^[0-9]+$/ { nsig = $3 } $1 == "#define" && $2 ~ /^SIG/ && $3 ~ /^[0-9]+$/ && sig[$3] == "" && ignore[$2] == 0 { sig[$3] = $2 if ($3 > max) max = $3 if (mesg[$2] == "" && nomesg[$2] == 0) { str = $4 for (i = 5; i <= NF; i++) str = str " " $i mesg[$2] = str } } END { if (nsig == 0) nsig = max + 1 printf " {!!, !!},\n" for (i = 1; i < nsig; i++) { if (sig[i] == "") printf " {!!, !!},\n" else printf " {!%s!, !%s!},\n", sig[i], mesg[sig[i]] } } ' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!' 'abcdefghijklmnopqrstuvwxyz"' echo '};' exec > sigmsgs.h echo 'typedef struct {' echo ' char *name, *msg;' echo '} Sigmsgs;' echo 'extern Sigmsgs signals[];' grep '^ ' sigmsgs.c | # the thing in quotes is ^<tab> awk ' { sum = sum + 1; } END { print "#define NUMOFSIGNALS", sum } '