# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1370160753 18000
# Node ID 19914f7ee9e9e3807b30b95d5e2f53a08767564d
# Parent  736dca8371eee979e810c40865da592af24c8c11
Use gnulib utilities for signal definitions displayed by builtin SIG function

* bootstrap.conf (gnulib_modules): Add sig2str.
* sighandlers.cc (make_sig_struct): Include sig2str.h. Replace all uses of
SIGxxxx with loop that scans all signals from gnulib sig2str() function. Sort.
* siglist.h, siglist.c: Remove from project.
* libinterp/interp-core/module.mk (INTERP_CORE_INC): Remove siglist.h.
(C_INTERP_CORE_SRC): Remove siglist.c.
* sighandlers.h: Remove siglist.h from inclusion.
* octave.cc (octave_initialize_interpreter): Remove init_signals ().

diff --git a/bootstrap.conf b/bootstrap.conf
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -68,6 +68,7 @@
   round
   roundf
   select
+  sig2str
   sigaction
   signal
   sigprocmask
diff --git a/libinterp/interp-core/module.mk b/libinterp/interp-core/module.mk
--- a/libinterp/interp-core/module.mk
+++ b/libinterp/interp-core/module.mk
@@ -49,7 +49,6 @@
   interp-core/oct-strstrm.h \
   interp-core/oct.h \
   interp-core/procstream.h \
-  interp-core/siglist.h \
   interp-core/sparse-xdiv.h \
   interp-core/sparse-xpow.h \
   interp-core/txt-eng-ft.h \
@@ -70,7 +69,6 @@
 C_INTERP_CORE_SRC = \
   interp-core/cutils.c \
   interp-core/matherr.c \
-  interp-core/siglist.c \
   interp-core/xgl2ps.c
 
 INTERP_CORE_SRC = \
diff --git a/libinterp/interp-core/siglist.c b/libinterp/interp-core/siglist.c
deleted file mode 100644
--- a/libinterp/interp-core/siglist.c
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
-
-Copyright (C) 2000-2012 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or (at your
-option) any later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <signal.h>
-
-#include "siglist.h"
-
-/* The following is all borrowed from Emacs.  */
-
-#if ! (defined HAVE_STRSIGNAL || HAVE_DECL_SYS_SIGLIST)
-
-static char *my_sys_siglist[NSIG];
-
-#ifdef sys_siglist
-#undef sys_siglist
-#endif
-#define sys_siglist my_sys_siglist
-
-#endif
-
-void
-init_signals (void)
-{
-#if ! (defined HAVE_STRSIGNAL || HAVE_DECL_SYS_SIGLIST)
-
-  static int initialized = 0;
-
-  if (! initialized)
-    {
-      initialized = 1;
-
-# ifdef SIGABRT
-      sys_siglist[SIGABRT] = "Aborted";
-# endif
-# ifdef SIGAIO
-      sys_siglist[SIGAIO] = "LAN I/O interrupt";
-# endif
-# ifdef SIGALRM
-      sys_siglist[SIGALRM] = "Alarm clock";
-# endif
-# ifdef SIGBUS
-      sys_siglist[SIGBUS] = "Bus error";
-# endif
-# ifdef SIGCLD
-      sys_siglist[SIGCLD] = "Child status changed";
-# endif
-# ifdef SIGCHLD
-      sys_siglist[SIGCHLD] = "Child status changed";
-# endif
-# ifdef SIGCONT
-      sys_siglist[SIGCONT] = "Continued";
-# endif
-# ifdef SIGDANGER
-      sys_siglist[SIGDANGER] = "Swap space dangerously low";
-# endif
-# ifdef SIGDGNOTIFY
-      sys_siglist[SIGDGNOTIFY] = "Notification message in queue";
-# endif
-# ifdef SIGEMT
-      sys_siglist[SIGEMT] = "Emulation trap";
-# endif
-# ifdef SIGFPE
-      sys_siglist[SIGFPE] = "Arithmetic exception";
-# endif
-# ifdef SIGFREEZE
-      sys_siglist[SIGFREEZE] = "SIGFREEZE";
-# endif
-# ifdef SIGGRANT
-      sys_siglist[SIGGRANT] = "Monitor mode granted";
-# endif
-# ifdef SIGHUP
-      sys_siglist[SIGHUP] = "Hangup";
-# endif
-# ifdef SIGILL
-      sys_siglist[SIGILL] = "Illegal instruction";
-# endif
-# ifdef SIGINT
-      sys_siglist[SIGINT] = "Interrupt";
-# endif
-# ifdef SIGIO
-      sys_siglist[SIGIO] = "I/O possible";
-# endif
-# ifdef SIGIOINT
-      sys_siglist[SIGIOINT] = "I/O intervention required";
-# endif
-# ifdef SIGIOT
-      sys_siglist[SIGIOT] = "IOT trap";
-# endif
-# ifdef SIGKILL
-      sys_siglist[SIGKILL] = "Killed";
-# endif
-# ifdef SIGLOST
-      sys_siglist[SIGLOST] = "Resource lost";
-# endif
-# ifdef SIGLWP
-      sys_siglist[SIGLWP] = "SIGLWP";
-# endif
-# ifdef SIGMSG
-      sys_siglist[SIGMSG] = "Monitor mode data available";
-# endif
-# ifdef SIGPHONE
-      sys_siglist[SIGPHONE] = "SIGPHONE";
-# endif
-# ifdef SIGPIPE
-      sys_siglist[SIGPIPE] = "Broken pipe";
-# endif
-# ifdef SIGPOLL
-      sys_siglist[SIGPOLL] = "Pollable event occurred";
-# endif
-# ifdef SIGPROF
-      sys_siglist[SIGPROF] = "Profiling timer expired";
-# endif
-# ifdef SIGPTY
-      sys_siglist[SIGPTY] = "PTY I/O interrupt";
-# endif
-# ifdef SIGPWR
-      sys_siglist[SIGPWR] = "Power-fail restart";
-# endif
-# ifdef SIGQUIT
-      sys_siglist[SIGQUIT] = "Quit";
-# endif
-# ifdef SIGRETRACT
-      sys_siglist[SIGRETRACT] = "Need to relinguish monitor mode";
-# endif
-# ifdef SIGSAK
-      sys_siglist[SIGSAK] = "Secure attention";
-# endif
-# ifdef SIGSEGV
-      sys_siglist[SIGSEGV] = "Segmentation violation";
-# endif
-# ifdef SIGSOUND
-      sys_siglist[SIGSOUND] = "Sound completed";
-# endif
-# ifdef SIGSTKFLT
-      sys_siglist[SIGSTKFLT] = "Stack fault";
-# endif
-# ifdef SIGSTOP
-      sys_siglist[SIGSTOP] = "Stopped (signal)";
-# endif
-# ifdef SIGSTP
-      sys_siglist[SIGSTP] = "Stopped (user)";
-# endif
-# ifdef SIGSYS
-      sys_siglist[SIGSYS] = "Bad argument to system call";
-# endif
-# ifdef SIGTERM
-      sys_siglist[SIGTERM] = "Terminated";
-# endif
-# ifdef SIGTHAW
-      sys_siglist[SIGTHAW] = "SIGTHAW";
-# endif
-# ifdef SIGTRAP
-      sys_siglist[SIGTRAP] = "Trace/breakpoint trap";
-# endif
-# ifdef SIGTSTP
-      sys_siglist[SIGTSTP] = "Stopped (user)";
-# endif
-# ifdef SIGTTIN
-      sys_siglist[SIGTTIN] = "Stopped (tty input)";
-# endif
-# ifdef SIGTTOU
-      sys_siglist[SIGTTOU] = "Stopped (tty output)";
-# endif
-# ifdef SIGUNUSED
-      sys_siglist[SIGUNUSED] = "SIGUNUSED";
-# endif
-# ifdef SIGURG
-      sys_siglist[SIGURG] = "Urgent I/O condition";
-# endif
-# ifdef SIGUSR1
-      sys_siglist[SIGUSR1] = "User defined signal 1";
-# endif
-# ifdef SIGUSR2
-      sys_siglist[SIGUSR2] = "User defined signal 2";
-# endif
-# ifdef SIGVTALRM
-      sys_siglist[SIGVTALRM] = "Virtual timer expired";
-# endif
-# ifdef SIGWAITING
-      sys_siglist[SIGWAITING] = "Process's LWPs are blocked";
-# endif
-# ifdef SIGWINCH
-      sys_siglist[SIGWINCH] = "Window size changed";
-# endif
-# ifdef SIGWIND
-      sys_siglist[SIGWIND] = "SIGWIND";
-# endif
-# ifdef SIGXCPU
-      sys_siglist[SIGXCPU] = "CPU time limit exceeded";
-# endif
-# ifdef SIGXFSZ
-      sys_siglist[SIGXFSZ] = "File size limit exceeded";
-# endif
-    }
-
-#endif
-}
-
-#if ! defined (HAVE_STRSIGNAL)
-
-char *
-strsignal (int code)
-{
-  char *signame = "";
-
-  if (0 <= code && code < NSIG)
-    {
-      /* Cast to suppress warning if the table has const char *.  */
-      signame = (char *) sys_siglist[code];
-    }
-
-  return signame;
-}
-
-#endif
diff --git a/libinterp/interp-core/siglist.h b/libinterp/interp-core/siglist.h
deleted file mode 100644
--- a/libinterp/interp-core/siglist.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-
-Copyright (C) 2000-2012 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or (at your
-option) any later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#if !defined (octave_siglist_h)
-#define octave_siglist_h 1
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/* This is borrowed from Emacs.  */
-
-#if ! defined (HAVE_DECL_SYS_SIGLIST)
-extern char *sys_siglist[];
-#endif
-
-extern void init_signals (void);
-
-#if ! defined (HAVE_STRSIGNAL)
-extern char *strsignal (int);
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/libinterp/interpfcn/sighandlers.cc b/libinterp/interpfcn/sighandlers.cc
--- a/libinterp/interpfcn/sighandlers.cc
+++ b/libinterp/interpfcn/sighandlers.cc
@@ -53,6 +53,8 @@
 #include "utils.h"
 #include "variables.h"
 
+#include "sig2str.h"
+
 // Nonzero means we have already printed a message for this series of
 // SIGPIPES.  We assume that the writer will eventually give up.
 int pipe_handler_error_count = 0;
@@ -580,161 +582,29 @@
 static octave_scalar_map
 make_sig_struct (void)
 {
-  octave_scalar_map m;
+  octave_scalar_map m, m_namesort;
 
-#ifdef SIGABRT
-  m.assign ("ABRT", SIGABRT);
-#endif
+  // Scan for signal names, inherently arranged by number.  The sig2str
+  // routine, at the time, forced EXIT to be signal 0 even though no
+  // such signal is defined in the system kernel header file.  Skip 0.
+  for (int i = 1; i < _NSIG; i++)
+    {
+      char signame[SIG2STR_MAX];
+      // sig2str assigns strings for unused signals as RTMIN+# or RTMAX-#.
+      // Ignore these unused signals.
+      if (! sig2str (i, signame) && strncmp (signame, "RTMIN", 5)
+                                 && strncmp (signame, "RTMAX", 5))
+        m.assign (signame, i);
+    }
 
-#ifdef SIGALRM
-  m.assign ("ALRM", SIGALRM);
-#endif
+  // Create a structure sorted by name.
+  Array<octave_idx_type> sidx;
+  string_vector fnames = m.fieldnames ();
+  Array<std::string> sfnames = fnames.Array<std::string>::sort (sidx, 0, ASCENDING);
+  for (int i = 0; i < sidx.length (); i++)
+    m_namesort.assign (sfnames.elem (i), m.contents (sidx (i)));
 
-#ifdef SIGBUS
-  m.assign ("BUS", SIGBUS);
-#endif
-
-#ifdef SIGCHLD
-  m.assign ("CHLD", SIGCHLD);
-#endif
-
-#ifdef SIGCLD
-  m.assign ("CLD", SIGCLD);
-#endif
-
-#ifdef SIGCONT
-  m.assign ("CONT", SIGCONT);
-#endif
-
-#ifdef SIGEMT
-  m.assign ("EMT", SIGEMT);
-#endif
-
-#ifdef SIGFPE
-  m.assign ("FPE", SIGFPE);
-#endif
-
-#ifdef SIGHUP
-  m.assign ("HUP", SIGHUP);
-#endif
-
-#ifdef SIGILL
-  m.assign ("ILL", SIGILL);
-#endif
-
-#ifdef SIGINFO
-  m.assign ("INFO", SIGINFO);
-#endif
-
-#ifdef SIGINT
-  m.assign ("INT", SIGINT);
-#endif
-
-#ifdef SIGIO
-  m.assign ("IO", SIGIO);
-#endif
-
-#ifdef SIGIOT
-  m.assign ("IOT", SIGIOT);
-#endif
-
-#ifdef SIGKILL
-  m.assign ("KILL", SIGKILL);
-#endif
-
-#ifdef SIGLOST
-  m.assign ("LOST", SIGLOST);
-#endif
-
-#ifdef SIGPIPE
-  m.assign ("PIPE", SIGPIPE);
-#endif
-
-#ifdef SIGPOLL
-  m.assign ("POLL", SIGPOLL);
-#endif
-
-#ifdef SIGPROF
-  m.assign ("PROF", SIGPROF);
-#endif
-
-#ifdef SIGPWR
-  m.assign ("PWR", SIGPWR);
-#endif
-
-#ifdef SIGQUIT
-  m.assign ("QUIT", SIGQUIT);
-#endif
-
-#ifdef SIGSEGV
-  m.assign ("SEGV", SIGSEGV);
-#endif
-
-#ifdef SIGSTKFLT
-  m.assign ("STKFLT", SIGSTKFLT);
-#endif
-
-#ifdef SIGSTOP
-  m.assign ("STOP", SIGSTOP);
-#endif
-
-#ifdef SIGSYS
-  m.assign ("SYS", SIGSYS);
-#endif
-
-#ifdef SIGTERM
-  m.assign ("TERM", SIGTERM);
-#endif
-
-#ifdef SIGTRAP
-  m.assign ("TRAP", SIGTRAP);
-#endif
-
-#ifdef SIGTSTP
-  m.assign ("TSTP", SIGTSTP);
-#endif
-
-#ifdef SIGTTIN
-  m.assign ("TTIN", SIGTTIN);
-#endif
-
-#ifdef SIGTTOU
-  m.assign ("TTOU", SIGTTOU);
-#endif
-
-#ifdef SIGUNUSED
-  m.assign ("UNUSED", SIGUNUSED);
-#endif
-
-#ifdef SIGURG
-  m.assign ("URG", SIGURG);
-#endif
-
-#ifdef SIGUSR1
-  m.assign ("USR1", SIGUSR1);
-#endif
-
-#ifdef SIGUSR2
-  m.assign ("USR2", SIGUSR2);
-#endif
-
-#ifdef SIGVTALRM
-  m.assign ("VTALRM", SIGVTALRM);
-#endif
-
-#ifdef SIGWINCH
-  m.assign ("WINCH", SIGWINCH);
-#endif
-
-#ifdef SIGXCPU
-  m.assign ("XCPU", SIGXCPU);
-#endif
-
-#ifdef SIGXFSZ
-  m.assign ("XFSZ", SIGXFSZ);
-#endif
-
-  return m;
+  return m_namesort;
 }
 
 octave_child_list::octave_child_list_rep *octave_child_list::instance = 0;
diff --git a/libinterp/interpfcn/sighandlers.h b/libinterp/interpfcn/sighandlers.h
--- a/libinterp/interpfcn/sighandlers.h
+++ b/libinterp/interpfcn/sighandlers.h
@@ -39,7 +39,6 @@
 #include <signal.h>
 
 #include "syswait.h"
-#include "siglist.h"
 
 #include "base-list.h"
 
diff --git a/libinterp/octave.cc b/libinterp/octave.cc
--- a/libinterp/octave.cc
+++ b/libinterp/octave.cc
@@ -857,8 +857,6 @@
   if (traditional)
     maximum_braindamage ();
 
-  init_signals ();
-
   octave_ieee_init ();
 
   // The idea here is to force xerbla to be referenced so that we will
