home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / bin / sh / mksignames.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-15  |  5.2 KB  |  198 lines

  1. /*-
  2.  * Copyright (c) 1991 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Kenneth Almquist.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  */
  36.  
  37. #ifndef lint
  38. char copyright[] =
  39. "@(#) Copyright (c) 1991 The Regents of the University of California.\n\
  40.  All rights reserved.\n";
  41. #endif /* not lint */
  42.  
  43. #ifndef lint
  44. static char sccsid[] = "@(#)mksignames.c    5.1 (Berkeley) 3/7/91";
  45. #endif /* not lint */
  46.  
  47. /*
  48.  * This program generates the signames.h and signames.c files.
  49.  */
  50. #include <stdio.h>
  51. #include <signal.h>
  52.  
  53.  
  54.  
  55. struct sig {
  56.     int signo;        /* signal number */
  57.     char *name;        /* signal name (without leading "SIG") */
  58.     char *mesg;        /* description */
  59. };
  60.  
  61.  
  62. struct sig sigtab[] = {
  63.     SIGHUP, "HUP", "Hangup",
  64.     SIGINT, "INT", "Interrupt",    /* normally don't print message */
  65.     SIGQUIT, "QUIT", "Quit",
  66.     SIGILL, "ILL", "Illegal instruction",
  67.     SIGTRAP, "TRAP", "Trace/BPT trap",
  68. #ifdef SIGABRT
  69.     SIGABRT, "ABRT", "abort",
  70. #endif
  71. #if defined(SIGIOT) && (! defined(SIGABRT) || SIGABRT != SIGIOT)
  72.     SIGIOT, "IOT", "abort",
  73. #endif
  74. #ifdef SIGEMT
  75.     SIGEMT, "EMT", "EMT trap",
  76. #endif
  77.     SIGFPE, "FPE", "Floating exception",
  78.     SIGKILL, "KILL", "Killed",
  79.     SIGBUS, "BUS", "Bus error",
  80.     SIGSEGV, "SEGV", "Memory fault",
  81.     SIGSYS, "SYS", "Bad system call",
  82.     SIGPIPE, "PIPE", "Broken pipe",    /* normally don't print message */
  83.     SIGALRM, "ALRM", "Alarm call",
  84.     SIGTERM, "TERM", "Terminated",
  85. #ifdef SIGUSR1
  86.     SIGUSR1, "USR1", "User signal 1",
  87. #endif
  88. #ifdef SIGUSR2
  89.     SIGUSR2, "USR2", "User signal 2",
  90. #endif
  91. #ifdef SIGCLD
  92.     SIGCLD, "CLD", NULL,
  93. #endif
  94. #if defined(SIGCHLD) && ! defined(SIGCLD)
  95.     SIGCHLD, "CLD", NULL,
  96. #endif
  97. #ifdef SIGPWR
  98.     SIGPWR, "PWR", "Power fail",
  99. #endif
  100. #ifdef SIGPOLL
  101.     SIGPOLL, "POLL", "Poll",
  102. #endif
  103.     /* Now for the BSD signals */
  104. #ifdef SIGURG
  105.     SIGURG, "URG", NULL,
  106. #endif
  107. #ifdef SIGSTOP
  108.     SIGSTOP, "STOP", "Stopped",
  109. #endif
  110. #ifdef SIGTSTP
  111.     SIGTSTP, "TSTP", "Stopped",
  112. #endif
  113. #ifdef SIGCONT
  114.     SIGCONT, "CONT", NULL,
  115. #endif
  116. #ifdef SIGTTIN
  117.     SIGTTIN, "TTIN", "Stopped (input)",
  118. #endif
  119. #ifdef SIGTTOU
  120.     SIGTTOU, "TTOU", "Stopped (output)",
  121. #endif
  122. #ifdef SIGIO
  123.     SIGIO, "IO", NULL,
  124. #endif
  125. #ifdef SIGXCPU
  126.     SIGXCPU, "XCPU", "Time limit exceeded",
  127. #endif
  128. #ifdef SIGXFSZ
  129.     SIGXFSZ, "XFSZ", NULL,
  130. #endif
  131. #ifdef SIGVTALARM
  132.     SIGVTALARM, "VTALARM", "Virtual alarm",
  133. #endif
  134. #ifdef SIGPROF
  135.     SIGPROF, "PROF", "Profiling alarm",
  136. #endif
  137. #ifdef SIGWINCH
  138.     SIGWINCH, "WINCH", NULL,
  139. #endif
  140.     0, NULL, NULL
  141. };
  142.  
  143.  
  144. #define MAXSIG 64
  145.  
  146.  
  147. char *sigmesg[MAXSIG + 1];
  148.  
  149.  
  150. char writer[] = "\
  151. /*\n\
  152.  * This file was generated by the mksignames program.\n\
  153.  */\n\
  154. \n";
  155.  
  156.  
  157.  
  158. main(argc, argv)  char **argv; {
  159.     FILE *cfile, *hfile;    
  160.     struct sig *sigp;
  161.     int maxsig;
  162.     int i;
  163.  
  164.     if ((cfile = fopen("signames.c", "w")) == NULL) {
  165.         fputs("Can't create signames.c\n", stderr);
  166.         exit(2);
  167.     }
  168.     if ((hfile = fopen("signames.h", "w")) == NULL) {
  169.         fputs("Can't create signames.h\n", stderr);
  170.         exit(2);
  171.     }
  172.     maxsig = 0;
  173.     for (sigp = sigtab ; sigp->signo != 0 ; sigp++) {
  174.         if (sigp->signo < 0 || sigp->signo > MAXSIG)
  175.             continue;
  176.         sigmesg[sigp->signo] = sigp->mesg;
  177.         if (maxsig < sigp->signo)
  178.             maxsig = sigp->signo;
  179.     }
  180.  
  181.     fputs(writer, hfile);
  182.     fprintf(hfile, "#define MAXSIG %d\n\n", maxsig);
  183.     fprintf(hfile, "extern char *const sigmesg[MAXSIG+1];\n");
  184.  
  185.     fputs(writer, cfile);
  186.     fprintf(cfile, "#include \"shell.h\"\n\n");
  187.     fprintf(cfile, "char *const sigmesg[%d] = {\n", maxsig + 1);
  188.     for (i = 0 ; i <= maxsig ; i++) {
  189.         if (sigmesg[i] == NULL) {
  190.             fprintf(cfile, "      0,\n");
  191.         } else {
  192.             fprintf(cfile, "      \"%s\",\n", sigmesg[i]);
  193.         }
  194.     }
  195.     fprintf(cfile, "};\n");
  196.     exit(0);
  197. }
  198.