]> git.ipfire.org Git - thirdparty/bash.git/blob - signames.c
f5216d5aefa28b8bfb0daa06093b5ab63ebf55ea
[thirdparty/bash.git] / signames.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 initialize_signames ()
40 {
41 register int i;
42
43 for (i = 1; i < sizeof(signal_names)/sizeof(signal_names[0]); i++)
44 signal_names[i] = (char *)NULL;
45
46 /* `signal' 0 is what we do on exit. */
47 signal_names[0] = "EXIT";
48
49 /* Place signal names which can be aliases for more common signal
50 names first. This allows (for example) SIGEMT to overwrite SIGGRANT. */
51 #if defined (SIGGRANT) /* HFT monitor mode granted */
52 signal_names[SIGGRANT] = "SIGGRANT";
53 #endif
54
55 #if defined (SIGRETRACT) /* HFT monitor mode retracted */
56 signal_names[SIGRETRACT] = "SIGRETRACT";
57 #endif
58
59 #if defined (SIGHUP) /* hangup */
60 signal_names[SIGHUP] = "SIGHUP";
61 #endif
62
63 #if defined (SIGINT) /* interrupt */
64 signal_names[SIGINT] = "SIGINT";
65 #endif
66
67 #if defined (SIGQUIT) /* quit */
68 signal_names[SIGQUIT] = "SIGQUIT";
69 #endif
70
71 #if defined (SIGILL) /* illegal instruction (not reset when caught) */
72 signal_names[SIGILL] = "SIGILL";
73 #endif
74
75 #if defined (SIGTRAP) /* trace trap (not reset when caught) */
76 signal_names[SIGTRAP] = "SIGTRAP";
77 #endif
78
79 #if defined (SIGABRT) /* Cause current process to dump core. */
80 signal_names[SIGABRT] = "SIGABRT";
81 #endif
82
83 #if defined (SIGIOT) /* IOT instruction */
84 signal_names[SIGIOT] = "SIGIOT";
85 #endif
86
87 #if defined (SIGEMT) /* EMT instruction */
88 signal_names[SIGEMT] = "SIGEMT";
89 #endif
90
91 #if defined (SIGFPE) /* floating point exception */
92 signal_names[SIGFPE] = "SIGFPE";
93 #endif
94
95 #if defined (SIGKILL) /* kill (cannot be caught or ignored) */
96 signal_names[SIGKILL] = "SIGKILL";
97 #endif
98
99 #if defined (SIGBUS) /* bus error */
100 signal_names[SIGBUS] = "SIGBUS";
101 #endif
102
103 #if defined (SIGSEGV) /* segmentation violation */
104 signal_names[SIGSEGV] = "SIGSEGV";
105 #endif
106
107 #if defined (SIGSYS) /* bad argument to system call */
108 signal_names[SIGSYS] = "SIGSYS";
109 #endif
110
111 #if defined (SIGPIPE) /* write on a pipe with no one to read it */
112 signal_names[SIGPIPE] = "SIGPIPE";
113 #endif
114
115 #if defined (SIGALRM) /* alarm clock */
116 signal_names[SIGALRM] = "SIGALRM";
117 #endif
118
119 #if defined (SIGTERM) /* software termination signal from kill */
120 signal_names[SIGTERM] = "SIGTERM";
121 #endif
122
123 #if defined (SIGCLD) /* Like SIGCHLD. */
124 signal_names[SIGCLD] = "SIGCLD";
125 #endif
126
127 #if defined (SIGPWR) /* Magic thing for some machines. */
128 signal_names[SIGPWR] = "SIGPWR";
129 #endif
130
131 #if defined (SIGPOLL) /* For keyboard input? */
132 signal_names[SIGPOLL] = "SIGPOLL";
133 #endif
134
135 #if defined (SIGURG) /* urgent condition on IO channel */
136 signal_names[SIGURG] = "SIGURG";
137 #endif
138
139 #if defined (SIGSTOP) /* sendable stop signal not from tty */
140 signal_names[SIGSTOP] = "SIGSTOP";
141 #endif
142
143 #if defined (SIGTSTP) /* stop signal from tty */
144 signal_names[SIGTSTP] = "SIGTSTP";
145 #endif
146
147 #if defined (SIGCONT) /* continue a stopped process */
148 signal_names[SIGCONT] = "SIGCONT";
149 #endif
150
151 #if defined (SIGCHLD) /* to parent on child stop or exit */
152 signal_names[SIGCHLD] = "SIGCHLD";
153 #endif
154
155 #if defined (SIGTTIN) /* to readers pgrp upon background tty read */
156 signal_names[SIGTTIN] = "SIGTTIN";
157 #endif
158
159 #if defined (SIGTTOU) /* like TTIN for output if (tp->t_local&LTOSTOP) */
160 signal_names[SIGTTOU] = "SIGTTOU";
161 #endif
162
163 #if defined (SIGIO) /* input/output possible signal */
164 signal_names[SIGIO] = "SIGIO";
165 #endif
166
167 #if defined (SIGXCPU) /* exceeded CPU time limit */
168 signal_names[SIGXCPU] = "SIGXCPU";
169 #endif
170
171 #if defined (SIGXFSZ) /* exceeded file size limit */
172 signal_names[SIGXFSZ] = "SIGXFSZ";
173 #endif
174
175 #if defined (SIGVTALRM) /* virtual time alarm */
176 signal_names[SIGVTALRM] = "SIGVTALRM";
177 #endif
178
179 #if defined (SIGPROF) /* profiling time alarm */
180 signal_names[SIGPROF] = "SIGPROF";
181 #endif
182
183 #if defined (SIGWINCH) /* window changed */
184 signal_names[SIGWINCH] = "SIGWINCH";
185 #endif
186
187 #if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
188 signal_names[SIGLOST] = "SIGLOST";
189 #endif
190
191 #if defined (SIGUSR1) /* user defined signal 1 */
192 signal_names[SIGUSR1] = "SIGUSR1";
193 #endif
194
195 #if defined (SIGUSR2) /* user defined signal 2 */
196 signal_names[SIGUSR2] = "SIGUSR2";
197 #endif
198
199 #if defined (SIGMSG) /* HFT input data pending */
200 signal_names[SIGMSG] = "SIGMSG";
201 #endif
202
203 #if defined (SIGPWR) /* power failure imminent (save your data) */
204 signal_names[SIGPWR] = "SIGPWR";
205 #endif
206
207 #if defined (SIGDANGER) /* system crash imminent */
208 signal_names[SIGDANGER] = "SIGDANGER";
209 #endif
210
211 #if defined (SIGMIGRATE) /* migrate process to another CPU */
212 signal_names[SIGMIGRATE] = "SIGMIGRATE";
213 #endif
214
215 #if defined (SIGPRE) /* programming error */
216 signal_names[SIGPRE] = "SIGPRE";
217 #endif
218
219 #if defined (SIGSOUND) /* HFT sound sequence has completed */
220 signal_names[SIGSOUND] = "SIGSOUND";
221 #endif
222
223 #if defined (SIGWINDOW)
224 signal_names[SIGWINDOW] = "SIGWINDOW";
225 #endif
226
227 #if defined (SIGDIL)
228 signal_names[SIGDIL] = "SIGDIL";
229 #endif
230
231 #if defined (SIGSAK) /* Secure Attention Key */
232 signal_names[SIGSAK] = "SIGSAK";
233 #endif
234
235 for (i = 0; i < NSIG; i++)
236 if (signal_names[i] == (char *)NULL)
237 {
238 signal_names[i] = (char *)malloc (18);
239 sprintf (signal_names[i], "SIGJUNK(%d)", i);
240 }
241 }
242
243 write_signames (stream)
244 FILE *stream;
245 {
246 register int i;
247
248 fprintf (stream, "/* This file was automatically created by %s.\n",
249 progname);
250 fprintf (stream, " Do not edit. Edit signames.c instead. */\n\n");
251 fprintf (stream,
252 "/* A translation list so we can be polite to our users. */\n");
253 fprintf (stream, "char *signal_names[NSIG + 2] = {\n");
254
255 for (i = 0; i < NSIG; i++)
256 fprintf (stream, " \"%s\",\n", signal_names[i]);
257
258 fprintf (stream, " (char *)0x0,\n");
259 fprintf (stream, "};\n");
260 }
261
262 main (argc, argv)
263 int argc;
264 char **argv;
265 {
266 char *stream_name;
267 FILE *stream;
268
269 progname = argv[0];
270
271 if (argc == 1)
272 {
273 stream_name = "stdout";
274 stream = stdout;
275 }
276 else if (argc == 2)
277 {
278 stream_name = argv[1];
279 stream = fopen (stream_name, "w");
280 }
281 else
282 {
283 fprintf (stderr, "Usage: %s [output-file]\n", progname);
284 exit (1);
285 }
286
287 if (!stream)
288 {
289 fprintf (stderr, "%s: %s Cannot be opened or written to.\n",
290 progname, stream_name);
291 exit (2);
292 }
293
294 initialize_signames ();
295 write_signames (stream);
296 exit (0);
297 }