]> git.ipfire.org Git - thirdparty/bash.git/blame - support/mksignames.c
Imported from ../bash-2.05.tar.gz.
[thirdparty/bash.git] / support / mksignames.c
CommitLineData
726f6388
JA
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
bb70624e 10 Software Foundation; either version 2, or (at your option) any later
726f6388
JA
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
bb70624e 20 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
726f6388
JA
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
35char *signal_names[2 * NSIG];
36
28ef6c31
JA
37#define signal_names_size (sizeof(signal_names)/sizeof(signal_names[0]))
38
726f6388
JA
39char *progname;
40
28ef6c31
JA
41/* AIX 4.3 defines SIGRTMIN and SIGRTMAX as 888 and 999 respectively.
42 I don't want to allocate so much unused space for the intervening signal
43 numbers, so we just punt if SIGRTMAX is past the bounds of the
44 signal_names array (handled in configure). */
45#if defined (SIGRTMAX) && defined (UNUSABLE_RT_SIGNALS)
46# undef SIGRTMAX
47# undef SIGRTMIN
48#endif
49
bb70624e
JA
50#if defined (SIGRTMAX) || defined (SIGRTMIN)
51# define RTLEN 14
52# define RTLIM 256
53#endif
54
ccc6cda3 55void
726f6388
JA
56initialize_signames ()
57{
58 register int i;
bb70624e
JA
59#if defined (SIGRTMAX) || defined (SIGRTMIN)
60 int rtmin, rtmax, rtcnt;
61#endif
726f6388 62
28ef6c31 63 for (i = 1; i < signal_names_size; i++)
726f6388
JA
64 signal_names[i] = (char *)NULL;
65
66 /* `signal' 0 is what we do on exit. */
67 signal_names[0] = "EXIT";
68
69 /* Place signal names which can be aliases for more common signal
d166f048 70 names first. This allows (for example) SIGABRT to overwrite SIGLOST. */
bb70624e
JA
71
72 /* POSIX 1003.1b-1993 real time signals, but take care of incomplete
73 implementations. Acoording to the standard, both, SIGRTMIN and
74 SIGRTMAX must be defined, SIGRTMIN must be stricly less than
75 SIGRTMAX, and the difference must be at least 7, that is, there
76 must be at least eight distinct real time signals. */
77
78 /* The generated signal names are SIGRTMIN, SIGRTMIN+1, ...,
79 SIGRTMIN+x, SIGRTMAX-x, ..., SIGRTMAX-1, SIGRTMAX. If the number
80 of RT signals is odd, there is an extra SIGRTMIN+(x+1).
81 These names are the ones used by ksh and /usr/xpg4/bin/sh on SunOS5. */
82
83#if defined (SIGRTMIN)
84 rtmin = SIGRTMIN;
85 signal_names[rtmin] = "SIGRTMIN";
86#endif
87
88#if defined (SIGRTMAX)
89 rtmax = SIGRTMAX;
90 signal_names[rtmax] = "SIGRTMAX";
91#endif
92
93#if defined (SIGRTMAX) && defined (SIGRTMIN)
94 if (rtmax > rtmin)
95 {
96 rtcnt = (rtmax - rtmin - 1) / 2;
97 /* croak if there are too many RT signals */
98 if (rtcnt >= RTLIM/2)
99 {
100 rtcnt = RTLIM/2-1;
101 fprintf(stderr, "%s: error: more than %i real time signals, fix `%s'\n",
102 progname, RTLIM, progname);
103 }
104
105 for (i = 1; i <= rtcnt; i++)
106 {
107 signal_names[rtmin+i] = (char *)malloc(RTLEN);
108 sprintf (signal_names[rtmin+i], "SIGRTMIN+%d", i);
109 signal_names[rtmax-i] = (char *)malloc(RTLEN);
110 sprintf (signal_names[rtmax-i], "SIGRTMAX-%d", i);
111 }
112
113 if (rtcnt < RTLIM/2-1 && rtcnt != (rtmax-rtmin)/2)
114 {
115 /* Need an extra RTMIN signal */
116 signal_names[rtmin+rtcnt+1] = (char *)malloc(RTLEN);
117 sprintf (signal_names[rtmin+rtcnt+1], "SIGRTMIN+%d", rtcnt+1);
118 }
119 }
120#endif /* SIGRTMIN && SIGRTMAX */
121
d166f048
JA
122/* AIX */
123#if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
124 signal_names[SIGLOST] = "SIGLOST";
125#endif
126
127#if defined (SIGMSG) /* HFT input data pending */
128 signal_names[SIGMSG] = "SIGMSG";
129#endif
130
131#if defined (SIGDANGER) /* system crash imminent */
132 signal_names[SIGDANGER] = "SIGDANGER";
133#endif
134
135#if defined (SIGMIGRATE) /* migrate process to another CPU */
136 signal_names[SIGMIGRATE] = "SIGMIGRATE";
137#endif
138
139#if defined (SIGPRE) /* programming error */
140 signal_names[SIGPRE] = "SIGPRE";
141#endif
142
143#if defined (SIGVIRT) /* AIX virtual time alarm */
144 signal_names[SIGVIRT] = "SIGVIRT";
145#endif
146
147#if defined (SIGALRM1) /* m:n condition variables */
148 signal_names[SIGALRM1] = "SIGALRM1";
149#endif
150
151#if defined (SIGWAITING) /* m:n scheduling */
152 signal_names[SIGWAITING] = "SIGWAITING";
153#endif
154
726f6388
JA
155#if defined (SIGGRANT) /* HFT monitor mode granted */
156 signal_names[SIGGRANT] = "SIGGRANT";
157#endif
158
d166f048
JA
159#if defined (SIGKAP) /* keep alive poll from native keyboard */
160 signal_names[SIGKAP] = "SIGKAP";
161#endif
162
726f6388
JA
163#if defined (SIGRETRACT) /* HFT monitor mode retracted */
164 signal_names[SIGRETRACT] = "SIGRETRACT";
165#endif
166
d166f048
JA
167#if defined (SIGSOUND) /* HFT sound sequence has completed */
168 signal_names[SIGSOUND] = "SIGSOUND";
169#endif
170
171#if defined (SIGSAK) /* Secure Attention Key */
172 signal_names[SIGSAK] = "SIGSAK";
173#endif
174
175/* SunOS5 */
176#if defined (SIGLWP) /* special signal used by thread library */
177 signal_names[SIGLWP] = "SIGLWP";
178#endif
179
180#if defined (SIGFREEZE) /* special signal used by CPR */
181 signal_names[SIGFREEZE] = "SIGFREEZE";
182#endif
183
184#if defined (SIGTHAW) /* special signal used by CPR */
185 signal_names[SIGTHAW] = "SIGTHAW";
186#endif
187
188#if defined (SIGCANCEL) /* thread cancellation signal used by libthread */
189 signal_names[SIGCANCEL] = "SIGCANCEL";
190#endif
191
192/* HP-UX */
193#if defined (SIGDIL) /* DIL signal (?) */
194 signal_names[SIGDIL] = "SIGDIL";
195#endif
196
197/* System V */
198#if defined (SIGCLD) /* Like SIGCHLD. */
199 signal_names[SIGCLD] = "SIGCLD";
200#endif
201
202#if defined (SIGPWR) /* power state indication */
203 signal_names[SIGPWR] = "SIGPWR";
204#endif
205
206#if defined (SIGPOLL) /* Pollable event (for streams) */
207 signal_names[SIGPOLL] = "SIGPOLL";
208#endif
209
210/* Unknown */
211#if defined (SIGWINDOW)
212 signal_names[SIGWINDOW] = "SIGWINDOW";
213#endif
214
215/* Common */
726f6388
JA
216#if defined (SIGHUP) /* hangup */
217 signal_names[SIGHUP] = "SIGHUP";
218#endif
219
220#if defined (SIGINT) /* interrupt */
221 signal_names[SIGINT] = "SIGINT";
222#endif
223
224#if defined (SIGQUIT) /* quit */
225 signal_names[SIGQUIT] = "SIGQUIT";
226#endif
227
228#if defined (SIGILL) /* illegal instruction (not reset when caught) */
229 signal_names[SIGILL] = "SIGILL";
230#endif
231
232#if defined (SIGTRAP) /* trace trap (not reset when caught) */
233 signal_names[SIGTRAP] = "SIGTRAP";
234#endif
235
726f6388
JA
236#if defined (SIGIOT) /* IOT instruction */
237 signal_names[SIGIOT] = "SIGIOT";
238#endif
239
d166f048
JA
240#if defined (SIGABRT) /* Cause current process to dump core. */
241 signal_names[SIGABRT] = "SIGABRT";
242#endif
243
726f6388
JA
244#if defined (SIGEMT) /* EMT instruction */
245 signal_names[SIGEMT] = "SIGEMT";
246#endif
247
248#if defined (SIGFPE) /* floating point exception */
249 signal_names[SIGFPE] = "SIGFPE";
250#endif
251
252#if defined (SIGKILL) /* kill (cannot be caught or ignored) */
253 signal_names[SIGKILL] = "SIGKILL";
254#endif
255
256#if defined (SIGBUS) /* bus error */
257 signal_names[SIGBUS] = "SIGBUS";
258#endif
259
260#if defined (SIGSEGV) /* segmentation violation */
261 signal_names[SIGSEGV] = "SIGSEGV";
262#endif
263
264#if defined (SIGSYS) /* bad argument to system call */
265 signal_names[SIGSYS] = "SIGSYS";
266#endif
267
268#if defined (SIGPIPE) /* write on a pipe with no one to read it */
269 signal_names[SIGPIPE] = "SIGPIPE";
270#endif
271
272#if defined (SIGALRM) /* alarm clock */
273 signal_names[SIGALRM] = "SIGALRM";
274#endif
275
276#if defined (SIGTERM) /* software termination signal from kill */
277 signal_names[SIGTERM] = "SIGTERM";
278#endif
279
726f6388
JA
280#if defined (SIGURG) /* urgent condition on IO channel */
281 signal_names[SIGURG] = "SIGURG";
282#endif
283
284#if defined (SIGSTOP) /* sendable stop signal not from tty */
285 signal_names[SIGSTOP] = "SIGSTOP";
286#endif
287
288#if defined (SIGTSTP) /* stop signal from tty */
289 signal_names[SIGTSTP] = "SIGTSTP";
290#endif
291
292#if defined (SIGCONT) /* continue a stopped process */
293 signal_names[SIGCONT] = "SIGCONT";
294#endif
295
296#if defined (SIGCHLD) /* to parent on child stop or exit */
297 signal_names[SIGCHLD] = "SIGCHLD";
298#endif
299
300#if defined (SIGTTIN) /* to readers pgrp upon background tty read */
301 signal_names[SIGTTIN] = "SIGTTIN";
302#endif
303
304#if defined (SIGTTOU) /* like TTIN for output if (tp->t_local&LTOSTOP) */
305 signal_names[SIGTTOU] = "SIGTTOU";
306#endif
307
308#if defined (SIGIO) /* input/output possible signal */
309 signal_names[SIGIO] = "SIGIO";
310#endif
311
312#if defined (SIGXCPU) /* exceeded CPU time limit */
313 signal_names[SIGXCPU] = "SIGXCPU";
314#endif
315
316#if defined (SIGXFSZ) /* exceeded file size limit */
317 signal_names[SIGXFSZ] = "SIGXFSZ";
318#endif
319
320#if defined (SIGVTALRM) /* virtual time alarm */
321 signal_names[SIGVTALRM] = "SIGVTALRM";
322#endif
323
324#if defined (SIGPROF) /* profiling time alarm */
325 signal_names[SIGPROF] = "SIGPROF";
326#endif
327
328#if defined (SIGWINCH) /* window changed */
329 signal_names[SIGWINCH] = "SIGWINCH";
330#endif
331
d166f048 332/* 4.4 BSD */
b72432fd 333#if defined (SIGINFO) && !defined (_SEQUENT_) /* information request */
d166f048 334 signal_names[SIGINFO] = "SIGINFO";
726f6388
JA
335#endif
336
337#if defined (SIGUSR1) /* user defined signal 1 */
338 signal_names[SIGUSR1] = "SIGUSR1";
339#endif
340
341#if defined (SIGUSR2) /* user defined signal 2 */
342 signal_names[SIGUSR2] = "SIGUSR2";
343#endif
344
b72432fd
JA
345#if defined (SIGKILLTHR) /* BeOS: Kill Thread */
346 signal_names[SIGKILLTHR] = "SIGKILLTHR";
347#endif
348
726f6388
JA
349 for (i = 0; i < NSIG; i++)
350 if (signal_names[i] == (char *)NULL)
351 {
352 signal_names[i] = (char *)malloc (18);
353 sprintf (signal_names[i], "SIGJUNK(%d)", i);
354 }
ccc6cda3
JA
355
356 signal_names[NSIG] = "DEBUG";
726f6388
JA
357}
358
ccc6cda3 359void
726f6388
JA
360write_signames (stream)
361 FILE *stream;
362{
363 register int i;
364
365 fprintf (stream, "/* This file was automatically created by %s.\n",
366 progname);
ccc6cda3 367 fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n");
726f6388
JA
368 fprintf (stream,
369 "/* A translation list so we can be polite to our users. */\n");
370 fprintf (stream, "char *signal_names[NSIG + 2] = {\n");
371
ccc6cda3 372 for (i = 0; i <= NSIG; i++)
726f6388
JA
373 fprintf (stream, " \"%s\",\n", signal_names[i]);
374
375 fprintf (stream, " (char *)0x0,\n");
376 fprintf (stream, "};\n");
377}
378
ccc6cda3 379int
726f6388
JA
380main (argc, argv)
381 int argc;
382 char **argv;
383{
384 char *stream_name;
385 FILE *stream;
386
387 progname = argv[0];
388
389 if (argc == 1)
390 {
391 stream_name = "stdout";
392 stream = stdout;
393 }
394 else if (argc == 2)
395 {
396 stream_name = argv[1];
397 stream = fopen (stream_name, "w");
398 }
399 else
400 {
401 fprintf (stderr, "Usage: %s [output-file]\n", progname);
402 exit (1);
403 }
404
405 if (!stream)
406 {
ccc6cda3 407 fprintf (stderr, "%s: %s: cannot open for writing\n",
726f6388
JA
408 progname, stream_name);
409 exit (2);
410 }
411
412 initialize_signames ();
413 write_signames (stream);
414 exit (0);
415}