655485bdc989a590cd0646b73a5e00e16114cbc7
[platform/upstream/bash.git] / support / mksignames.c
1 /* signames.c -- Create and write `signames.h', which contains an array of
2    signal names. */
3
4 /* Copyright (C) 1992 Free Software Foundation, Inc.
5
6    This file is part of GNU Bash, the Bourne Again SHell.
7
8    Bash is free software; you can redistribute it and/or modify it under
9    the terms of the GNU General Public License as published by the Free
10    Software Foundation; either version 1, or (at your option) any later
11    version.
12
13    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14    WARRANTY; without even the implied warranty of MERCHANTABILITY or
15    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16    for more details.
17
18    You should have received a copy of the GNU General Public License along
19    with Bash; see the file COPYING.  If not, write to the Free Software
20    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <signal.h>
25 #if defined (HAVE_STDLIB_H)
26 #  include <stdlib.h>
27 #else
28 #  include "ansi_stdlib.h"
29 #endif /* HAVE_STDLIB_H */
30
31 #if !defined (NSIG)
32 #  define NSIG 64
33 #endif
34
35 char *signal_names[2 * NSIG];
36
37 char *progname;
38
39 void
40 initialize_signames ()
41 {
42   register int i;
43
44   for (i = 1; i < sizeof(signal_names)/sizeof(signal_names[0]); i++)
45     signal_names[i] = (char *)NULL;
46
47   /* `signal' 0 is what we do on exit. */
48   signal_names[0] = "EXIT";
49
50   /* Place signal names which can be aliases for more common signal
51      names first.  This allows (for example) SIGEMT to overwrite SIGGRANT. */
52 #if defined (SIGGRANT)  /* HFT monitor mode granted */
53   signal_names[SIGGRANT] = "SIGGRANT";
54 #endif
55
56 #if defined (SIGRETRACT) /* HFT monitor mode retracted */
57   signal_names[SIGRETRACT] = "SIGRETRACT";
58 #endif
59
60 #if defined (SIGHUP)    /* hangup */
61   signal_names[SIGHUP] = "SIGHUP";
62 #endif
63
64 #if defined (SIGINT)    /* interrupt */
65   signal_names[SIGINT] = "SIGINT";
66 #endif
67
68 #if defined (SIGQUIT)   /* quit */
69   signal_names[SIGQUIT] = "SIGQUIT";
70 #endif
71
72 #if defined (SIGILL)    /* illegal instruction (not reset when caught) */
73   signal_names[SIGILL] = "SIGILL";
74 #endif
75
76 #if defined (SIGTRAP)   /* trace trap (not reset when caught) */
77   signal_names[SIGTRAP] = "SIGTRAP";
78 #endif
79
80 #if defined (SIGABRT)   /* Cause current process to dump core. */
81   signal_names[SIGABRT] = "SIGABRT";
82 #endif
83
84 #if defined (SIGIOT)    /* IOT instruction */
85   signal_names[SIGIOT] = "SIGIOT";
86 #endif
87
88 #if defined (SIGEMT)    /* EMT instruction */
89   signal_names[SIGEMT] = "SIGEMT";
90 #endif
91
92 #if defined (SIGFPE)    /* floating point exception */
93   signal_names[SIGFPE] = "SIGFPE";
94 #endif
95
96 #if defined (SIGKILL)   /* kill (cannot be caught or ignored) */
97   signal_names[SIGKILL] = "SIGKILL";
98 #endif
99
100 #if defined (SIGBUS)    /* bus error */
101   signal_names[SIGBUS] = "SIGBUS";
102 #endif
103
104 #if defined (SIGSEGV)   /* segmentation violation */
105   signal_names[SIGSEGV] = "SIGSEGV";
106 #endif
107
108 #if defined (SIGSYS)    /* bad argument to system call */
109   signal_names[SIGSYS] = "SIGSYS";
110 #endif
111
112 #if defined (SIGPIPE)   /* write on a pipe with no one to read it */
113   signal_names[SIGPIPE] = "SIGPIPE";
114 #endif
115
116 #if defined (SIGALRM)   /* alarm clock */
117   signal_names[SIGALRM] = "SIGALRM";
118 #endif
119
120 #if defined (SIGTERM)   /* software termination signal from kill */
121   signal_names[SIGTERM] = "SIGTERM";
122 #endif
123
124 #if defined (SIGCLD)    /* Like SIGCHLD.  */
125   signal_names[SIGCLD] = "SIGCLD";
126 #endif
127
128 #if defined (SIGPWR)    /* Magic thing for some machines. */
129   signal_names[SIGPWR] = "SIGPWR";
130 #endif
131
132 #if defined (SIGPOLL)   /* For keyboard input?  */
133   signal_names[SIGPOLL] = "SIGPOLL";
134 #endif
135
136 #if defined (SIGURG)    /* urgent condition on IO channel */
137   signal_names[SIGURG] = "SIGURG";
138 #endif
139
140 #if defined (SIGSTOP)   /* sendable stop signal not from tty */
141   signal_names[SIGSTOP] = "SIGSTOP";
142 #endif
143
144 #if defined (SIGTSTP)   /* stop signal from tty */
145   signal_names[SIGTSTP] = "SIGTSTP";
146 #endif
147
148 #if defined (SIGCONT)   /* continue a stopped process */
149   signal_names[SIGCONT] = "SIGCONT";
150 #endif
151
152 #if defined (SIGCHLD)   /* to parent on child stop or exit */
153   signal_names[SIGCHLD] = "SIGCHLD";
154 #endif
155
156 #if defined (SIGTTIN)   /* to readers pgrp upon background tty read */
157   signal_names[SIGTTIN] = "SIGTTIN";
158 #endif
159
160 #if defined (SIGTTOU)   /* like TTIN for output if (tp->t_local&LTOSTOP) */
161   signal_names[SIGTTOU] = "SIGTTOU";
162 #endif
163
164 #if defined (SIGIO)     /* input/output possible signal */
165   signal_names[SIGIO] = "SIGIO";
166 #endif
167
168 #if defined (SIGXCPU)   /* exceeded CPU time limit */
169   signal_names[SIGXCPU] = "SIGXCPU";
170 #endif
171
172 #if defined (SIGXFSZ)   /* exceeded file size limit */
173   signal_names[SIGXFSZ] = "SIGXFSZ";
174 #endif
175
176 #if defined (SIGVTALRM) /* virtual time alarm */
177   signal_names[SIGVTALRM] = "SIGVTALRM";
178 #endif
179
180 #if defined (SIGPROF)   /* profiling time alarm */
181   signal_names[SIGPROF] = "SIGPROF";
182 #endif
183
184 #if defined (SIGWINCH)  /* window changed */
185   signal_names[SIGWINCH] = "SIGWINCH";
186 #endif
187
188 #if defined (SIGLOST)   /* resource lost (eg, record-lock lost) */
189   signal_names[SIGLOST] = "SIGLOST";
190 #endif
191
192 #if defined (SIGUSR1)   /* user defined signal 1 */
193   signal_names[SIGUSR1] = "SIGUSR1";
194 #endif
195
196 #if defined (SIGUSR2)   /* user defined signal 2 */
197   signal_names[SIGUSR2] = "SIGUSR2";
198 #endif
199
200 #if defined (SIGMSG)    /* HFT input data pending */
201   signal_names[SIGMSG] = "SIGMSG";
202 #endif
203
204 #if defined (SIGPWR)    /* power failure imminent (save your data) */
205   signal_names[SIGPWR] = "SIGPWR";
206 #endif
207
208 #if defined (SIGDANGER) /* system crash imminent */
209   signal_names[SIGDANGER] = "SIGDANGER";
210 #endif
211
212 #if defined (SIGMIGRATE) /* migrate process to another CPU */
213   signal_names[SIGMIGRATE] = "SIGMIGRATE";
214 #endif
215
216 #if defined (SIGPRE)    /* programming error */
217   signal_names[SIGPRE] = "SIGPRE";
218 #endif
219
220 #if defined (SIGSOUND)  /* HFT sound sequence has completed */
221   signal_names[SIGSOUND] = "SIGSOUND";
222 #endif
223
224 #if defined (SIGWINDOW)
225   signal_names[SIGWINDOW] = "SIGWINDOW";
226 #endif
227
228 #if defined (SIGDIL)
229   signal_names[SIGDIL] = "SIGDIL";
230 #endif
231
232 #if defined (SIGSAK)    /* Secure Attention Key */
233   signal_names[SIGSAK] = "SIGSAK";
234 #endif
235
236   for (i = 0; i < NSIG; i++)
237     if (signal_names[i] == (char *)NULL)
238       {
239         signal_names[i] = (char *)malloc (18);
240         sprintf (signal_names[i], "SIGJUNK(%d)", i);
241       }
242
243   signal_names[NSIG] = "DEBUG";
244 }
245
246 void
247 write_signames (stream)
248      FILE *stream;
249 {
250   register int i;
251
252   fprintf (stream, "/* This file was automatically created by %s.\n",
253            progname);
254   fprintf (stream, "   Do not edit.  Edit support/mksignames.c instead. */\n\n");
255   fprintf (stream,
256            "/* A translation list so we can be polite to our users. */\n");
257   fprintf (stream, "char *signal_names[NSIG + 2] = {\n");
258
259   for (i = 0; i <= NSIG; i++)
260     fprintf (stream, "    \"%s\",\n", signal_names[i]);
261
262   fprintf (stream, "    (char *)0x0,\n");
263   fprintf (stream, "};\n");
264 }
265
266 int
267 main (argc, argv)
268      int argc;
269      char **argv;
270 {
271   char *stream_name;
272   FILE *stream;
273
274   progname = argv[0];
275
276   if (argc == 1)
277     {
278       stream_name = "stdout";
279       stream = stdout;
280     }
281   else if (argc == 2)
282     {
283       stream_name = argv[1];
284       stream = fopen (stream_name, "w");
285     }
286   else
287     {
288       fprintf (stderr, "Usage: %s [output-file]\n", progname);
289       exit (1);
290     }
291
292   if (!stream)
293     {
294       fprintf (stderr, "%s: %s: cannot open for writing\n",
295                progname, stream_name);
296       exit (2);
297     }
298
299   initialize_signames ();
300   write_signames (stream);
301   exit (0);
302 }