blob: 5618879a78ed142270bcddd3763ab401f97dce9d [file] [log] [blame]
Jari Aalto06285672006-10-10 14:15:34 +00001/* mksignames.c -- Create and write `signames.h', which contains an array of
Jari Aalto726f6381996-08-26 18:22:31 +00002 signal names. */
3
Jari Aalto06285672006-10-10 14:15:34 +00004/* Copyright (C) 1992-2006 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00005
6 This file is part of GNU Bash, the Bourne Again SHell.
7
Jari Aalto31859422009-01-12 13:36:28 +00008 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 Aalto726f6381996-08-26 18:22:31 +000012
Jari Aalto31859422009-01-12 13:36:28 +000013 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 Aalto726f6381996-08-26 18:22:31 +000017
Jari Aalto31859422009-01-12 13:36:28 +000018 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 Aalto726f6381996-08-26 18:22:31 +000021
Jari Aalto7117c2d2002-07-17 14:10:11 +000022#include <config.h>
Jari Aaltof73dda02001-11-13 17:56:06 +000023
Jari Aalto726f6381996-08-26 18:22:31 +000024#include <sys/types.h>
25#include <signal.h>
Jari Aalto06285672006-10-10 14:15:34 +000026
27#include <stdio.h>
Jari Aalto726f6381996-08-26 18:22:31 +000028#if defined (HAVE_STDLIB_H)
29# include <stdlib.h>
30#else
31# include "ansi_stdlib.h"
32#endif /* HAVE_STDLIB_H */
33
Jari Aalto06285672006-10-10 14:15:34 +000034/* Duplicated from signames.c */
Jari Aalto726f6381996-08-26 18:22:31 +000035#if !defined (NSIG)
36# define NSIG 64
37#endif
38
Jari Aaltob80f6442004-07-27 13:29:18 +000039#define LASTSIG NSIG+2
Jari Aaltof73dda02001-11-13 17:56:06 +000040
Jari Aalto06285672006-10-10 14:15:34 +000041/* Imported from signames.c */
42extern void initialize_signames ();
43extern char *signal_names[];
Jari Aalto28ef6c32001-04-06 19:14:31 +000044
Jari Aalto726f6381996-08-26 18:22:31 +000045char *progname;
46
Jari Aaltoccc6cda1996-12-23 17:02:34 +000047void
Jari Aalto726f6381996-08-26 18:22:31 +000048write_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 Ramey00018032011-11-21 20:51:19 -050055 fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n");
Jari Aalto726f6381996-08-26 18:22:31 +000056 fprintf (stream,
57 "/* A translation list so we can be polite to our users. */\n");
Jari Aalto06285672006-10-10 14:15:34 +000058#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 Aaltob80f6442004-07-27 13:29:18 +000062 fprintf (stream, "char *signal_names[NSIG + 4] = {\n");
Jari Aalto726f6381996-08-26 18:22:31 +000063
Jari Aaltof73dda02001-11-13 17:56:06 +000064 for (i = 0; i <= LASTSIG; i++)
Jari Aalto726f6381996-08-26 18:22:31 +000065 fprintf (stream, " \"%s\",\n", signal_names[i]);
66
Jari Aaltof73dda02001-11-13 17:56:06 +000067 fprintf (stream, " (char *)0x0\n");
Jari Aalto06285672006-10-10 14:15:34 +000068 fprintf (stream, "};\n\n");
69 fprintf (stream, "#define initialize_signames()\n\n");
70#endif
Jari Aalto726f6381996-08-26 18:22:31 +000071}
72
Jari Aaltoccc6cda1996-12-23 17:02:34 +000073int
Jari Aalto726f6381996-08-26 18:22:31 +000074main (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 Aaltoccc6cda1996-12-23 17:02:34 +0000101 fprintf (stderr, "%s: %s: cannot open for writing\n",
Jari Aalto726f6381996-08-26 18:22:31 +0000102 progname, stream_name);
103 exit (2);
104 }
105
Jari Aalto06285672006-10-10 14:15:34 +0000106#if !defined (CROSS_COMPILING)
Jari Aalto726f6381996-08-26 18:22:31 +0000107 initialize_signames ();
Jari Aalto06285672006-10-10 14:15:34 +0000108#endif
Jari Aalto726f6381996-08-26 18:22:31 +0000109 write_signames (stream);
110 exit (0);
111}