Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 1 | /* mksignames.c -- Create and write `signames.h', which contains an array of |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 2 | signal names. */ |
| 3 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 4 | /* Copyright (C) 1992-2006 Free Software Foundation, Inc. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 5 | |
| 6 | This file is part of GNU Bash, the Bourne Again SHell. |
| 7 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 8 | Bash is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 12 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 13 | Bash is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 17 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 18 | You should have received a copy of the GNU General Public License |
| 19 | along with Bash. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 21 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 22 | #include <config.h> |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 23 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <signal.h> |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 26 | |
| 27 | #include <stdio.h> |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 28 | #if defined (HAVE_STDLIB_H) |
| 29 | # include <stdlib.h> |
| 30 | #else |
| 31 | # include "ansi_stdlib.h" |
| 32 | #endif /* HAVE_STDLIB_H */ |
| 33 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 34 | /* Duplicated from signames.c */ |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 35 | #if !defined (NSIG) |
| 36 | # define NSIG 64 |
| 37 | #endif |
| 38 | |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 39 | #define LASTSIG NSIG+2 |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 40 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 41 | /* Imported from signames.c */ |
| 42 | extern void initialize_signames (); |
| 43 | extern char *signal_names[]; |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 44 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 45 | char *progname; |
| 46 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 47 | void |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 48 | write_signames (stream) |
| 49 | FILE *stream; |
| 50 | { |
| 51 | register int i; |
| 52 | |
| 53 | fprintf (stream, "/* This file was automatically created by %s.\n", |
| 54 | progname); |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 55 | fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n"); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 56 | fprintf (stream, |
| 57 | "/* A translation list so we can be polite to our users. */\n"); |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 58 | #if defined (CROSS_COMPILING) |
| 59 | fprintf (stream, "extern char *signal_names[];\n\n"); |
| 60 | fprintf (stream, "extern void initialize_signames __P((void));\n\n"); |
| 61 | #else |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 62 | fprintf (stream, "char *signal_names[NSIG + 4] = {\n"); |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 63 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 64 | for (i = 0; i <= LASTSIG; i++) |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 65 | fprintf (stream, " \"%s\",\n", signal_names[i]); |
| 66 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 67 | fprintf (stream, " (char *)0x0\n"); |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 68 | fprintf (stream, "};\n\n"); |
| 69 | fprintf (stream, "#define initialize_signames()\n\n"); |
| 70 | #endif |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 73 | int |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 74 | main (argc, argv) |
| 75 | int argc; |
| 76 | char **argv; |
| 77 | { |
| 78 | char *stream_name; |
| 79 | FILE *stream; |
| 80 | |
| 81 | progname = argv[0]; |
| 82 | |
| 83 | if (argc == 1) |
| 84 | { |
| 85 | stream_name = "stdout"; |
| 86 | stream = stdout; |
| 87 | } |
| 88 | else if (argc == 2) |
| 89 | { |
| 90 | stream_name = argv[1]; |
| 91 | stream = fopen (stream_name, "w"); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | fprintf (stderr, "Usage: %s [output-file]\n", progname); |
| 96 | exit (1); |
| 97 | } |
| 98 | |
| 99 | if (!stream) |
| 100 | { |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 101 | fprintf (stderr, "%s: %s: cannot open for writing\n", |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 102 | progname, stream_name); |
| 103 | exit (2); |
| 104 | } |
| 105 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 106 | #if !defined (CROSS_COMPILING) |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 107 | initialize_signames (); |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 108 | #endif |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 109 | write_signames (stream); |
| 110 | exit (0); |
| 111 | } |