* Rework phrasing to allow for better translations.
[make.git] / signame.c
blob7d12f8876b528eafa7a8c3b6041c8fda917bb0c6
1 /* Convert between signal names and numbers.
2 Copyright (C) 1990,92,93,95,96,99 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
21 /* In the GNU make version, all the headers we need are provided by make.h. */
22 #include "make.h"
25 /* Some systems do not define NSIG in <signal.h>. */
26 #ifndef NSIG
27 #ifdef _NSIG
28 #define NSIG _NSIG
29 #else
30 #define NSIG 32
31 #endif
32 #endif
34 #if !__STDC__
35 #define const
36 #endif
38 #include "signame.h"
40 #ifndef HAVE_SYS_SIGLIST
41 /* There is too much variation in Sys V signal numbers and names, so
42 we must initialize them at runtime. */
44 static const char *undoc;
46 const char *sys_siglist[NSIG];
48 #else /* HAVE_SYS_SIGLIST. */
50 #ifndef SYS_SIGLIST_DECLARED
51 extern char *sys_siglist[];
52 #endif /* Not SYS_SIGLIST_DECLARED. */
54 #endif /* Not HAVE_SYS_SIGLIST. */
56 /* Table of abbreviations for signals. Note: A given number can
57 appear more than once with different abbreviations. */
58 #define SIG_TABLE_SIZE (NSIG*2)
60 typedef struct
62 int number;
63 const char *abbrev;
64 } num_abbrev;
65 static num_abbrev sig_table[SIG_TABLE_SIZE];
66 /* Number of elements of sig_table used. */
67 static int sig_table_nelts = 0;
69 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
71 static void
72 init_sig (number, abbrev, name)
73 int number;
74 const char *abbrev;
75 const char *name;
77 #ifndef HAVE_SYS_SIGLIST
78 /* If this value is ever greater than NSIG it seems like it'd be a bug in
79 the system headers, but... better safe than sorry. We know, for
80 example, that this isn't always true on VMS. */
82 if (number >= 0 && number < NSIG)
83 sys_siglist[number] = name;
84 #endif
85 if (sig_table_nelts < SIG_TABLE_SIZE)
87 sig_table[sig_table_nelts].number = number;
88 sig_table[sig_table_nelts++].abbrev = abbrev;
92 void
93 signame_init ()
95 #ifndef HAVE_SYS_SIGLIST
96 int i;
97 char *u = _("unknown signal");
99 undoc = xstrdup(u);
101 /* Initialize signal names. */
102 for (i = 0; i < NSIG; i++)
103 sys_siglist[i] = undoc;
104 #endif /* !HAVE_SYS_SIGLIST */
106 /* Initialize signal names. */
107 #if defined (SIGHUP)
108 init_sig (SIGHUP, "HUP", _("Hangup"));
109 #endif
110 #if defined (SIGINT)
111 init_sig (SIGINT, "INT", _("Interrupt"));
112 #endif
113 #if defined (SIGQUIT)
114 init_sig (SIGQUIT, "QUIT", _("Quit"));
115 #endif
116 #if defined (SIGILL)
117 init_sig (SIGILL, "ILL", _("Illegal Instruction"));
118 #endif
119 #if defined (SIGTRAP)
120 init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
121 #endif
122 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
123 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
124 #if defined (SIGABRT)
125 init_sig (SIGABRT, "ABRT", _("Aborted"));
126 #endif
127 #if defined (SIGIOT)
128 init_sig (SIGIOT, "IOT", _("IOT trap"));
129 #endif
130 #if defined (SIGEMT)
131 init_sig (SIGEMT, "EMT", _("EMT trap"));
132 #endif
133 #if defined (SIGFPE)
134 init_sig (SIGFPE, "FPE", _("Floating point exception"));
135 #endif
136 #if defined (SIGKILL)
137 init_sig (SIGKILL, "KILL", _("Killed"));
138 #endif
139 #if defined (SIGBUS)
140 init_sig (SIGBUS, "BUS", _("Bus error"));
141 #endif
142 #if defined (SIGSEGV)
143 init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
144 #endif
145 #if defined (SIGSYS)
146 init_sig (SIGSYS, "SYS", _("Bad system call"));
147 #endif
148 #if defined (SIGPIPE)
149 init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
150 #endif
151 #if defined (SIGALRM)
152 init_sig (SIGALRM, "ALRM", _("Alarm clock"));
153 #endif
154 #if defined (SIGTERM)
155 init_sig (SIGTERM, "TERM", _("Terminated"));
156 #endif
157 #if defined (SIGUSR1)
158 init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
159 #endif
160 #if defined (SIGUSR2)
161 init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
162 #endif
163 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
164 is what is in POSIX.1. */
165 #if defined (SIGCHLD)
166 init_sig (SIGCHLD, "CHLD", _("Child exited"));
167 #endif
168 #if defined (SIGCLD)
169 init_sig (SIGCLD, "CLD", _("Child exited"));
170 #endif
171 #if defined (SIGPWR)
172 init_sig (SIGPWR, "PWR", _("Power failure"));
173 #endif
174 #if defined (SIGTSTP)
175 init_sig (SIGTSTP, "TSTP", _("Stopped"));
176 #endif
177 #if defined (SIGTTIN)
178 init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
179 #endif
180 #if defined (SIGTTOU)
181 init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
182 #endif
183 #if defined (SIGSTOP)
184 init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
185 #endif
186 #if defined (SIGXCPU)
187 init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
188 #endif
189 #if defined (SIGXFSZ)
190 init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
191 #endif
192 #if defined (SIGVTALRM)
193 init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
194 #endif
195 #if defined (SIGPROF)
196 init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
197 #endif
198 #if defined (SIGWINCH)
199 /* "Window size changed" might be more accurate, but even if that
200 is all that it means now, perhaps in the future it will be
201 extended to cover other kinds of window changes. */
202 init_sig (SIGWINCH, "WINCH", _("Window changed"));
203 #endif
204 #if defined (SIGCONT)
205 init_sig (SIGCONT, "CONT", _("Continued"));
206 #endif
207 #if defined (SIGURG)
208 init_sig (SIGURG, "URG", _("Urgent I/O condition"));
209 #endif
210 #if defined (SIGIO)
211 /* "I/O pending" has also been suggested. A disadvantage is
212 that signal only happens when the process has
213 asked for it, not everytime I/O is pending. Another disadvantage
214 is the confusion from giving it a different name than under Unix. */
215 init_sig (SIGIO, "IO", _("I/O possible"));
216 #endif
217 #if defined (SIGWIND)
218 init_sig (SIGWIND, "WIND", _("SIGWIND"));
219 #endif
220 #if defined (SIGPHONE)
221 init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
222 #endif
223 #if defined (SIGPOLL)
224 init_sig (SIGPOLL, "POLL", _("I/O possible"));
225 #endif
226 #if defined (SIGLOST)
227 init_sig (SIGLOST, "LOST", _("Resource lost"));
228 #endif
229 #if defined (SIGDANGER)
230 init_sig (SIGDANGER, "DANGER", _("Danger signal"));
231 #endif
232 #if defined (SIGINFO)
233 init_sig (SIGINFO, "INFO", _("Information request"));
234 #endif
235 #if defined (SIGNOFP)
236 init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
237 #endif
240 /* Return the abbreviation for signal NUMBER. */
242 char *
243 sig_abbrev (number)
244 int number;
246 int i;
248 if (sig_table_nelts == 0)
249 signame_init ();
251 for (i = 0; i < sig_table_nelts; i++)
252 if (sig_table[i].number == number)
253 return (char *)sig_table[i].abbrev;
254 return NULL;
257 /* Return the signal number for an ABBREV, or -1 if there is no
258 signal by that name. */
261 sig_number (abbrev)
262 const char *abbrev;
264 int i;
266 if (sig_table_nelts == 0)
267 signame_init ();
269 /* Skip over "SIG" if present. */
270 if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
271 abbrev += 3;
273 for (i = 0; i < sig_table_nelts; i++)
274 if (abbrev[0] == sig_table[i].abbrev[0]
275 && strcmp (abbrev, sig_table[i].abbrev) == 0)
276 return sig_table[i].number;
277 return -1;
280 #ifndef HAVE_PSIGNAL
281 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
282 a colon, and followed by a newline. */
284 void
285 psignal (signal, message)
286 int signal;
287 const char *message;
289 if (signal <= 0 || signal >= NSIG)
290 fprintf (stderr, "%s: unknown signal", message);
291 else
292 fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
294 #endif
296 #ifndef HAVE_STRSIGNAL
297 /* Return the string associated with the signal number. */
299 char *
300 strsignal (signal)
301 int signal;
303 static char buf[] = "Signal 12345678901234567890";
305 if (signal > 0 || signal < NSIG)
306 return (char *) sys_siglist[signal];
308 sprintf (buf, "Signal %d", signal);
309 return buf;
311 #endif