home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume20 / rc / part04 / mksignal < prev    next >
Encoding:
Text File  |  1991-05-22  |  1.6 KB  |  70 lines

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