home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume30 / rc / part06 / mksignal < prev    next >
Encoding:
Text File  |  1992-05-30  |  1.8 KB  |  76 lines

  1. #!/bin/sh
  2. # generate rc's internal signal table from signal.h
  3.  
  4. exec > sigmsgs.c
  5.  
  6. echo '#include "sigmsgs.h"'
  7. echo
  8. echo 'Sigmsgs signals[] = {'
  9.  
  10. sed '    s/\/\*[     ]*//
  11.     s/[     ]*\*\///
  12.     s/([@*+!]) //
  13.     s/[     ]*([a-zA-Z,->& ]*)[     ]*//
  14.     s/^[     ]*\#[     ]*define/\#define/
  15.     s/[     ]*signal$//' $1 |
  16. awk '
  17.     BEGIN {
  18.         # assign to nomesg["SIGNAME"] to suppress a long message
  19.         nomesg["SIGINT"] = 1
  20.         nomesg["SIGPIPE"] = 1
  21.         # assign to mesg["SIGNAME"] to override a message
  22.         mesg["SIGHUP"] = "hangup"
  23.         mesg["SIGKILL"] = "killed"
  24.         mesg["SIGQUIT"] = "quit"
  25.         mesg["SIGTERM"] = "terminated"
  26.         mesg["SIGURG"] = "urgent condition on i/o channel"
  27.         mesg["SIGSTOP"] = "stop signal not from tty"
  28.         mesg["SIGTSTP"] = "stopped"
  29.         mesg["SIGCONT"] = "continue"
  30.         mesg["SIGCHLD"] = "child stop or exit"
  31.         mesg["SIGTTIN"] = "background tty read"
  32.         mesg["SIGTTOU"] = "background tty write"
  33.         # assign to ignore["SIGNAME"] to explicitly ignore a named signal
  34.         ignore["SIGMAX"] = 1
  35.     }
  36.     $1 == "#define" && $2 == "NSIG" && $3 ~ /^[0-9]+$/ { nsig = $3 }
  37.     $1 == "#define" && $2 ~ /^SIG/ && $3 ~ /^[0-9]+$/ && sig[$3] == "" && ignore[$2] == 0 {
  38.         sig[$3] = $2
  39.         if ($3 > max)
  40.             max = $3
  41.         if (mesg[$2] == "" && nomesg[$2] == 0) {
  42.             str = $4
  43.             for (i = 5; i <= NF; i++)
  44.                 str = str " " $i
  45.             mesg[$2] = str
  46.         }
  47.     }
  48.     END {
  49.         if (nsig == 0)
  50.             nsig = max + 1
  51.         printf "    {!!,        !!},\n"
  52.         for (i = 1; i < nsig; i++) {
  53.             if (sig[i] == "")
  54.                 printf "    {!!,        !!},\n"
  55.             else
  56.                 printf "    {!%s!,    !%s!},\n", sig[i], mesg[sig[i]]
  57.         }
  58.     }
  59. ' |
  60. tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!' 'abcdefghijklmnopqrstuvwxyz"'
  61.  
  62. echo '};'
  63.  
  64. exec > sigmsgs.h
  65.  
  66. echo 'typedef struct {'
  67. echo '    char *name, *msg;'
  68. echo '} Sigmsgs;'
  69. echo 'extern Sigmsgs signals[];'
  70.  
  71. grep '^    ' sigmsgs.c |        # the thing in quotes is ^<tab>
  72. awk '
  73.         { sum = sum + 1; }
  74.     END    { print "#define NUMOFSIGNALS", sum }
  75. '
  76.