~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/qmake/signame.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Convert between signal names and numbers.
 
2
   Copyright (C) 1990, 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
 
3
   This file is part of the GNU C Library.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.  */
 
19
 
 
20
#include "make.h"
 
21
 
 
22
#include <stdio.h>
 
23
#include <sys/types.h>          /* Some systems need this for <signal.h>.  */
 
24
#include <signal.h>
 
25
 
 
26
#ifdef HAVE_STRING_H
 
27
#include <string.h>
 
28
#endif
 
29
 
 
30
/* Some systems declare `sys_siglist in <unistd.h>; if
 
31
   configure defined SYS_SIGLIST_DECLARED, it may expect
 
32
   to find the declaration there.  */
 
33
#ifdef HAVE_UNISTD_H
 
34
#include <unistd.h>
 
35
#endif
 
36
 
 
37
 
 
38
/* Some systems do not define NSIG in <signal.h>.  */
 
39
#ifndef NSIG
 
40
#ifdef  _NSIG
 
41
#define NSIG    _NSIG
 
42
#else
 
43
#define NSIG    32
 
44
#endif
 
45
#endif
 
46
 
 
47
#if !__STDC__
 
48
#define const
 
49
#endif
 
50
 
 
51
#include "signame.h"
 
52
 
 
53
#ifndef HAVE_SYS_SIGLIST
 
54
/* There is too much variation in Sys V signal numbers and names, so
 
55
   we must initialize them at runtime.  */
 
56
 
 
57
static const char *undoc;
 
58
 
 
59
const char *sys_siglist[NSIG];
 
60
 
 
61
#else   /* HAVE_SYS_SIGLIST.  */
 
62
 
 
63
#ifndef SYS_SIGLIST_DECLARED
 
64
extern char *sys_siglist[];
 
65
#endif  /* Not SYS_SIGLIST_DECLARED.  */
 
66
 
 
67
#endif  /* Not HAVE_SYS_SIGLIST.  */
 
68
 
 
69
/* Table of abbreviations for signals.  Note:  A given number can
 
70
   appear more than once with different abbreviations.  */
 
71
#define SIG_TABLE_SIZE  (NSIG*2)
 
72
 
 
73
typedef struct
 
74
  {
 
75
    int number;
 
76
    const char *abbrev;
 
77
  } num_abbrev;
 
78
static num_abbrev sig_table[SIG_TABLE_SIZE];
 
79
/* Number of elements of sig_table used.  */
 
80
static int sig_table_nelts = 0;
 
81
 
 
82
/* Enter signal number NUMBER into the tables with ABBREV and NAME.  */
 
83
 
 
84
static void
 
85
init_sig (number, abbrev, name)
 
86
     int number;
 
87
     const char *abbrev;
 
88
     const char *name;
 
89
{
 
90
#ifndef HAVE_SYS_SIGLIST
 
91
  /* If this value is ever greater than NSIG it seems like it'd be a bug in
 
92
     the system headers, but... better safe than sorry.  We know, for
 
93
     example, that this isn't always true on VMS.  */
 
94
 
 
95
  if (number >= 0 && number < NSIG)
 
96
    sys_siglist[number] = name;
 
97
#endif
 
98
  if (sig_table_nelts < SIG_TABLE_SIZE)
 
99
    {
 
100
      sig_table[sig_table_nelts].number = number;
 
101
      sig_table[sig_table_nelts++].abbrev = abbrev;
 
102
    }
 
103
}
 
104
 
 
105
void
 
106
signame_init ()
 
107
{
 
108
#ifndef HAVE_SYS_SIGLIST
 
109
  int i;
 
110
  char *u = _("unknown signal");
 
111
 
 
112
  undoc = xstrdup(u);
 
113
 
 
114
  /* Initialize signal names.  */
 
115
  for (i = 0; i < NSIG; i++)
 
116
    sys_siglist[i] = undoc;
 
117
#endif /* !HAVE_SYS_SIGLIST */
 
118
 
 
119
  /* Initialize signal names.  */
 
120
#if defined (SIGHUP)
 
121
  init_sig (SIGHUP, "HUP", _("Hangup"));
 
122
#endif
 
123
#if defined (SIGINT)
 
124
  init_sig (SIGINT, "INT", _("Interrupt"));
 
125
#endif
 
126
#if defined (SIGQUIT)
 
127
  init_sig (SIGQUIT, "QUIT", _("Quit"));
 
128
#endif
 
129
#if defined (SIGILL)
 
130
  init_sig (SIGILL, "ILL", _("Illegal Instruction"));
 
131
#endif
 
132
#if defined (SIGTRAP)
 
133
  init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
 
134
#endif
 
135
  /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
 
136
     SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't.  */
 
137
#if defined (SIGABRT)
 
138
  init_sig (SIGABRT, "ABRT", _("Aborted"));
 
139
#endif
 
140
#if defined (SIGIOT)
 
141
  init_sig (SIGIOT, "IOT", _("IOT trap"));
 
142
#endif
 
143
#if defined (SIGEMT)
 
144
  init_sig (SIGEMT, "EMT", _("EMT trap"));
 
145
#endif
 
146
#if defined (SIGFPE)
 
147
  init_sig (SIGFPE, "FPE", _("Floating point exception"));
 
148
#endif
 
149
#if defined (SIGKILL)
 
150
  init_sig (SIGKILL, "KILL", _("Killed"));
 
151
#endif
 
152
#if defined (SIGBUS)
 
153
  init_sig (SIGBUS, "BUS", _("Bus error"));
 
154
#endif
 
155
#if defined (SIGSEGV)
 
156
  init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
 
157
#endif
 
158
#if defined (SIGSYS)
 
159
  init_sig (SIGSYS, "SYS", _("Bad system call"));
 
160
#endif
 
161
#if defined (SIGPIPE)
 
162
  init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
 
163
#endif
 
164
#if defined (SIGALRM)
 
165
  init_sig (SIGALRM, "ALRM", _("Alarm clock"));
 
166
#endif
 
167
#if defined (SIGTERM)
 
168
  init_sig (SIGTERM, "TERM", _("Terminated"));
 
169
#endif
 
170
#if defined (SIGUSR1)
 
171
  init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
 
172
#endif
 
173
#if defined (SIGUSR2)
 
174
  init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
 
175
#endif
 
176
  /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
 
177
     is what is in POSIX.1.  */
 
178
#if defined (SIGCHLD)
 
179
  init_sig (SIGCHLD, "CHLD", _("Child exited"));
 
180
#endif
 
181
#if defined (SIGCLD)
 
182
  init_sig (SIGCLD, "CLD", _("Child exited"));
 
183
#endif
 
184
#if defined (SIGPWR)
 
185
  init_sig (SIGPWR, "PWR", _("Power failure"));
 
186
#endif
 
187
#if defined (SIGTSTP)
 
188
  init_sig (SIGTSTP, "TSTP", _("Stopped"));
 
189
#endif
 
190
#if defined (SIGTTIN)
 
191
  init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
 
192
#endif
 
193
#if defined (SIGTTOU)
 
194
  init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
 
195
#endif
 
196
#if defined (SIGSTOP)
 
197
  init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
 
198
#endif
 
199
#if defined (SIGXCPU)
 
200
  init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
 
201
#endif
 
202
#if defined (SIGXFSZ)
 
203
  init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
 
204
#endif
 
205
#if defined (SIGVTALRM)
 
206
  init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
 
207
#endif
 
208
#if defined (SIGPROF)
 
209
  init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
 
210
#endif
 
211
#if defined (SIGWINCH)
 
212
  /* "Window size changed" might be more accurate, but even if that
 
213
     is all that it means now, perhaps in the future it will be
 
214
     extended to cover other kinds of window changes.  */
 
215
  init_sig (SIGWINCH, "WINCH", _("Window changed"));
 
216
#endif
 
217
#if defined (SIGCONT)
 
218
  init_sig (SIGCONT, "CONT", _("Continued"));
 
219
#endif
 
220
#if defined (SIGURG)
 
221
  init_sig (SIGURG, "URG", _("Urgent I/O condition"));
 
222
#endif
 
223
#if defined (SIGIO)
 
224
  /* "I/O pending" has also been suggested.  A disadvantage is
 
225
     that signal only happens when the process has
 
226
     asked for it, not everytime I/O is pending.  Another disadvantage
 
227
     is the confusion from giving it a different name than under Unix.  */
 
228
  init_sig (SIGIO, "IO", _("I/O possible"));
 
229
#endif
 
230
#if defined (SIGWIND)
 
231
  init_sig (SIGWIND, "WIND", _("SIGWIND"));
 
232
#endif
 
233
#if defined (SIGPHONE)
 
234
  init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
 
235
#endif
 
236
#if defined (SIGPOLL)
 
237
  init_sig (SIGPOLL, "POLL", _("I/O possible"));
 
238
#endif
 
239
#if defined (SIGLOST)
 
240
  init_sig (SIGLOST, "LOST", _("Resource lost"));
 
241
#endif
 
242
#if defined (SIGDANGER)
 
243
  init_sig (SIGDANGER, "DANGER", _("Danger signal"));
 
244
#endif
 
245
#if defined (SIGINFO)
 
246
  init_sig (SIGINFO, "INFO", _("Information request"));
 
247
#endif
 
248
#if defined (SIGNOFP)
 
249
  init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
 
250
#endif
 
251
}
 
252
 
 
253
/* Return the abbreviation for signal NUMBER.  */
 
254
 
 
255
char *
 
256
sig_abbrev (number)
 
257
     int number;
 
258
{
 
259
  int i;
 
260
 
 
261
  if (sig_table_nelts == 0)
 
262
    signame_init ();
 
263
 
 
264
  for (i = 0; i < sig_table_nelts; i++)
 
265
    if (sig_table[i].number == number)
 
266
      return (char *)sig_table[i].abbrev;
 
267
  return NULL;
 
268
}
 
269
 
 
270
/* Return the signal number for an ABBREV, or -1 if there is no
 
271
   signal by that name.  */
 
272
 
 
273
int
 
274
sig_number (abbrev)
 
275
     const char *abbrev;
 
276
{
 
277
  int i;
 
278
 
 
279
  if (sig_table_nelts == 0)
 
280
    signame_init ();
 
281
 
 
282
  /* Skip over "SIG" if present.  */
 
283
  if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
 
284
    abbrev += 3;
 
285
 
 
286
  for (i = 0; i < sig_table_nelts; i++)
 
287
    if (abbrev[0] == sig_table[i].abbrev[0]
 
288
        && strcmp (abbrev, sig_table[i].abbrev) == 0)
 
289
      return sig_table[i].number;
 
290
  return -1;
 
291
}
 
292
 
 
293
#ifndef HAVE_PSIGNAL
 
294
/* Print to standard error the name of SIGNAL, preceded by MESSAGE and
 
295
   a colon, and followed by a newline.  */
 
296
 
 
297
void
 
298
psignal (signal, message)
 
299
     int signal;
 
300
     const char *message;
 
301
{
 
302
  if (signal <= 0 || signal >= NSIG)
 
303
    fprintf (stderr, "%s: unknown signal", message);
 
304
  else
 
305
    fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
 
306
}
 
307
#endif
 
308
 
 
309
#ifndef HAVE_STRSIGNAL
 
310
/* Return the string associated with the signal number.  */
 
311
 
 
312
char *
 
313
strsignal (signal)
 
314
     int signal;
 
315
{
 
316
  static char buf[] = "Signal 12345678901234567890";
 
317
 
 
318
  if (signal > 0 || signal < NSIG)
 
319
    return (char *) sys_siglist[signal];
 
320
 
 
321
  sprintf (buf, "Signal %d", signal);
 
322
  return buf;
 
323
}
 
324
#endif