#include "make.h"
#ifndef NSIG
#ifdef _NSIG
#define NSIG _NSIG
#else
#define NSIG 32
#endif
#endif
#if !__STDC__
#define const
#endif
#include "signame.h"
#ifndef HAVE_SYS_SIGLIST
static const char *undoc;
const char *sys_siglist[NSIG];
#else
#ifndef SYS_SIGLIST_DECLARED
extern char *sys_siglist[];
#endif
#endif
#define SIG_TABLE_SIZE (NSIG*2)
typedef struct
{
int number;
const char *abbrev;
} num_abbrev;
static num_abbrev sig_table[SIG_TABLE_SIZE];
static int sig_table_nelts = 0;
static void
init_sig (number, abbrev, name)
int number;
const char *abbrev;
const char *name;
{
#ifndef HAVE_SYS_SIGLIST
if (number >= 0 && number < NSIG)
sys_siglist[number] = name;
#endif
if (sig_table_nelts < SIG_TABLE_SIZE)
{
sig_table[sig_table_nelts].number = number;
sig_table[sig_table_nelts++].abbrev = abbrev;
}
}
void
signame_init ()
{
#ifndef HAVE_SYS_SIGLIST
int i;
char *u = _("unknown signal");
undoc = xstrdup(u);
for (i = 0; i < NSIG; i++)
sys_siglist[i] = undoc;
#endif
#if defined (SIGHUP)
init_sig (SIGHUP, "HUP", _("Hangup"));
#endif
#if defined (SIGINT)
init_sig (SIGINT, "INT", _("Interrupt"));
#endif
#if defined (SIGQUIT)
init_sig (SIGQUIT, "QUIT", _("Quit"));
#endif
#if defined (SIGILL)
init_sig (SIGILL, "ILL", _("Illegal Instruction"));
#endif
#if defined (SIGTRAP)
init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
#endif
#if defined (SIGABRT)
init_sig (SIGABRT, "ABRT", _("Aborted"));
#endif
#if defined (SIGIOT)
init_sig (SIGIOT, "IOT", _("IOT trap"));
#endif
#if defined (SIGEMT)
init_sig (SIGEMT, "EMT", _("EMT trap"));
#endif
#if defined (SIGFPE)
init_sig (SIGFPE, "FPE", _("Floating point exception"));
#endif
#if defined (SIGKILL)
init_sig (SIGKILL, "KILL", _("Killed"));
#endif
#if defined (SIGBUS)
init_sig (SIGBUS, "BUS", _("Bus error"));
#endif
#if defined (SIGSEGV)
init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
#endif
#if defined (SIGSYS)
init_sig (SIGSYS, "SYS", _("Bad system call"));
#endif
#if defined (SIGPIPE)
init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
#endif
#if defined (SIGALRM)
init_sig (SIGALRM, "ALRM", _("Alarm clock"));
#endif
#if defined (SIGTERM)
init_sig (SIGTERM, "TERM", _("Terminated"));
#endif
#if defined (SIGUSR1)
init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
#endif
#if defined (SIGUSR2)
init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
#endif
#if defined (SIGCHLD)
init_sig (SIGCHLD, "CHLD", _("Child exited"));
#endif
#if defined (SIGCLD)
init_sig (SIGCLD, "CLD", _("Child exited"));
#endif
#if defined (SIGPWR)
init_sig (SIGPWR, "PWR", _("Power failure"));
#endif
#if defined (SIGTSTP)
init_sig (SIGTSTP, "TSTP", _("Stopped"));
#endif
#if defined (SIGTTIN)
init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
#endif
#if defined (SIGTTOU)
init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
#endif
#if defined (SIGSTOP)
init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
#endif
#if defined (SIGXCPU)
init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
#endif
#if defined (SIGXFSZ)
init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
#endif
#if defined (SIGVTALRM)
init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
#endif
#if defined (SIGPROF)
init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
#endif
#if defined (SIGWINCH)
init_sig (SIGWINCH, "WINCH", _("Window changed"));
#endif
#if defined (SIGCONT)
init_sig (SIGCONT, "CONT", _("Continued"));
#endif
#if defined (SIGURG)
init_sig (SIGURG, "URG", _("Urgent I/O condition"));
#endif
#if defined (SIGIO)
init_sig (SIGIO, "IO", _("I/O possible"));
#endif
#if defined (SIGWIND)
init_sig (SIGWIND, "WIND", _("SIGWIND"));
#endif
#if defined (SIGPHONE)
init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
#endif
#if defined (SIGPOLL)
init_sig (SIGPOLL, "POLL", _("I/O possible"));
#endif
#if defined (SIGLOST)
init_sig (SIGLOST, "LOST", _("Resource lost"));
#endif
#if defined (SIGDANGER)
init_sig (SIGDANGER, "DANGER", _("Danger signal"));
#endif
#if defined (SIGINFO)
init_sig (SIGINFO, "INFO", _("Information request"));
#endif
#if defined (SIGNOFP)
init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
#endif
}
char *
sig_abbrev (number)
int number;
{
int i;
if (sig_table_nelts == 0)
signame_init ();
for (i = 0; i < sig_table_nelts; i++)
if (sig_table[i].number == number)
return (char *)sig_table[i].abbrev;
return NULL;
}
int
sig_number (abbrev)
const char *abbrev;
{
int i;
if (sig_table_nelts == 0)
signame_init ();
if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
abbrev += 3;
for (i = 0; i < sig_table_nelts; i++)
if (abbrev[0] == sig_table[i].abbrev[0]
&& strcmp (abbrev, sig_table[i].abbrev) == 0)
return sig_table[i].number;
return -1;
}
#ifndef HAVE_PSIGNAL
void
psignal (signal, message)
int signal;
const char *message;
{
if (signal <= 0 || signal >= NSIG)
fprintf (stderr, "%s: unknown signal", message);
else
fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
}
#endif
#ifndef HAVE_STRSIGNAL
char *
strsignal (signal)
int signal;
{
static char buf[] = "Signal 12345678901234567890";
if (signal > 0 || signal < NSIG)
return (char *) sys_siglist[signal];
sprintf (buf, "Signal %d", signal);
return buf;
}
#endif