Update some NEWS and README nits, and add new gettext macros to config's
[make.git] / signame.c
blobf7128dfd51007cdd7ebf23db6bfcf659c788524b
1 /* Convert between signal names and numbers.
2 Copyright (C) 1990,92,93,95,96,99, 2002 Free Software Foundation, Inc.
3 This file was part of the GNU C Library, but is now part of GNU make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Make 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include "make.h"
22 /* If the system provides strsignal, we don't need it. */
24 #if !defined(HAVE_STRSIGNAL)
26 /* If the system provides sys_siglist, we'll use that.
27 Otherwise create our own.
30 #if !defined(SYS_SIGLIST_DECLARED)
32 /* Some systems do not define NSIG in <signal.h>. */
33 #ifndef NSIG
34 #ifdef _NSIG
35 #define NSIG _NSIG
36 #else
37 #define NSIG 32
38 #endif
39 #endif
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 static const char *sys_siglist[NSIG];
48 /* Table of abbreviations for signals. Note: A given number can
49 appear more than once with different abbreviations. */
50 #define SIG_TABLE_SIZE (NSIG*2)
52 typedef struct
54 int number;
55 const char *abbrev;
56 } num_abbrev;
58 static num_abbrev sig_table[SIG_TABLE_SIZE];
60 /* Number of elements of sig_table used. */
61 static int sig_table_nelts = 0;
63 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
65 static void
66 init_sig (number, abbrev, name)
67 int number;
68 const char *abbrev;
69 const char *name;
71 /* If this value is ever greater than NSIG it seems like it'd be a bug in
72 the system headers, but... better safe than sorry. We know, for
73 example, that this isn't always true on VMS. */
75 if (number >= 0 && number < NSIG)
76 sys_siglist[number] = name;
78 if (sig_table_nelts < SIG_TABLE_SIZE)
80 sig_table[sig_table_nelts].number = number;
81 sig_table[sig_table_nelts++].abbrev = abbrev;
85 static int
86 signame_init ()
88 int i;
89 char *u = _("unknown signal");
91 undoc = xstrdup(u);
93 /* Initialize signal names. */
94 for (i = 0; i < NSIG; i++)
95 sys_siglist[i] = undoc;
97 /* Initialize signal names. */
98 #if defined (SIGHUP)
99 init_sig (SIGHUP, "HUP", _("Hangup"));
100 #endif
101 #if defined (SIGINT)
102 init_sig (SIGINT, "INT", _("Interrupt"));
103 #endif
104 #if defined (SIGQUIT)
105 init_sig (SIGQUIT, "QUIT", _("Quit"));
106 #endif
107 #if defined (SIGILL)
108 init_sig (SIGILL, "ILL", _("Illegal Instruction"));
109 #endif
110 #if defined (SIGTRAP)
111 init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
112 #endif
113 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
114 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
115 #if defined (SIGABRT)
116 init_sig (SIGABRT, "ABRT", _("Aborted"));
117 #endif
118 #if defined (SIGIOT)
119 init_sig (SIGIOT, "IOT", _("IOT trap"));
120 #endif
121 #if defined (SIGEMT)
122 init_sig (SIGEMT, "EMT", _("EMT trap"));
123 #endif
124 #if defined (SIGFPE)
125 init_sig (SIGFPE, "FPE", _("Floating point exception"));
126 #endif
127 #if defined (SIGKILL)
128 init_sig (SIGKILL, "KILL", _("Killed"));
129 #endif
130 #if defined (SIGBUS)
131 init_sig (SIGBUS, "BUS", _("Bus error"));
132 #endif
133 #if defined (SIGSEGV)
134 init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
135 #endif
136 #if defined (SIGSYS)
137 init_sig (SIGSYS, "SYS", _("Bad system call"));
138 #endif
139 #if defined (SIGPIPE)
140 init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
141 #endif
142 #if defined (SIGALRM)
143 init_sig (SIGALRM, "ALRM", _("Alarm clock"));
144 #endif
145 #if defined (SIGTERM)
146 init_sig (SIGTERM, "TERM", _("Terminated"));
147 #endif
148 #if defined (SIGUSR1)
149 init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
150 #endif
151 #if defined (SIGUSR2)
152 init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
153 #endif
154 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
155 is what is in POSIX.1. */
156 #if defined (SIGCHLD)
157 init_sig (SIGCHLD, "CHLD", _("Child exited"));
158 #endif
159 #if defined (SIGCLD)
160 init_sig (SIGCLD, "CLD", _("Child exited"));
161 #endif
162 #if defined (SIGPWR)
163 init_sig (SIGPWR, "PWR", _("Power failure"));
164 #endif
165 #if defined (SIGTSTP)
166 init_sig (SIGTSTP, "TSTP", _("Stopped"));
167 #endif
168 #if defined (SIGTTIN)
169 init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
170 #endif
171 #if defined (SIGTTOU)
172 init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
173 #endif
174 #if defined (SIGSTOP)
175 init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
176 #endif
177 #if defined (SIGXCPU)
178 init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
179 #endif
180 #if defined (SIGXFSZ)
181 init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
182 #endif
183 #if defined (SIGVTALRM)
184 init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
185 #endif
186 #if defined (SIGPROF)
187 init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
188 #endif
189 #if defined (SIGWINCH)
190 /* "Window size changed" might be more accurate, but even if that
191 is all that it means now, perhaps in the future it will be
192 extended to cover other kinds of window changes. */
193 init_sig (SIGWINCH, "WINCH", _("Window changed"));
194 #endif
195 #if defined (SIGCONT)
196 init_sig (SIGCONT, "CONT", _("Continued"));
197 #endif
198 #if defined (SIGURG)
199 init_sig (SIGURG, "URG", _("Urgent I/O condition"));
200 #endif
201 #if defined (SIGIO)
202 /* "I/O pending" has also been suggested. A disadvantage is
203 that signal only happens when the process has
204 asked for it, not everytime I/O is pending. Another disadvantage
205 is the confusion from giving it a different name than under Unix. */
206 init_sig (SIGIO, "IO", _("I/O possible"));
207 #endif
208 #if defined (SIGWIND)
209 init_sig (SIGWIND, "WIND", _("SIGWIND"));
210 #endif
211 #if defined (SIGPHONE)
212 init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
213 #endif
214 #if defined (SIGPOLL)
215 init_sig (SIGPOLL, "POLL", _("I/O possible"));
216 #endif
217 #if defined (SIGLOST)
218 init_sig (SIGLOST, "LOST", _("Resource lost"));
219 #endif
220 #if defined (SIGDANGER)
221 init_sig (SIGDANGER, "DANGER", _("Danger signal"));
222 #endif
223 #if defined (SIGINFO)
224 init_sig (SIGINFO, "INFO", _("Information request"));
225 #endif
226 #if defined (SIGNOFP)
227 init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
228 #endif
230 return 1;
233 #endif /* SYS_SIGLIST_DECLARED */
236 char *
237 strsignal (signal)
238 int signal;
240 static char buf[] = "Signal 12345678901234567890";
242 #if !defined(SYS_SIGLIST_DECLARED)
243 static char sig_initted = 0;
245 if (!sig_initted)
246 sig_initted = signame_init ();
247 #endif
249 if (signal > 0 || signal < NSIG)
250 return (char *) sys_siglist[signal];
252 sprintf (buf, "Signal %d", signal);
253 return buf;
256 #endif /* HAVE_STRSIGNAL */