1autogen definitions strsignal;
2
3/*
4 *  Dynamic definitions for creating the strsignal.h header file
5 *
6 *  This file is part of AutoGen.
7 *
8 *  AutoGen Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
9 *
10 *  AutoGen is free software: you can redistribute it and/or modify it
11 *  under the terms of the GNU General Public License as published by the
12 *  Free Software Foundation, either version 3 of the License, or
13 *  (at your option) any later version.
14 *
15 *  AutoGen is distributed in the hope that it will be useful, but
16 *  WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 *  See the GNU General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public License along
21 *  with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#shell
25
26RE_sigfind=$'[A-Z12]+[ \t]+[1-9][0-9]*'
27RE_sigdef=$'^#[ \t]*define[ \t][ \t]*_*SIG'
28RE_inc=$'^#[ \t]*include[ \t][ \t]*<'
29
30threshold=5             # minimum number of signals to accept
31num=0                   # number of signals defined in this file
32seen=""                 # include files already searched
33files="sys/signal.h"    # initial files to search
34
35cd /usr/include
36while test -n "$files"
37do
38    for file in $files; do
39        # look for $threshold or more matches in one of the search files
40        test -f $file || continue
41        sigs=`egrep "$RE_sigdef$RE_sigfind" $file|sed "s,$RE_sigdef,,"`
42        test -z "$sigs" || num=`echo "$sigs" | wc -l`
43        test $num -lt $threshold || break
44        seen="$file $seen"
45    done
46    test $num -lt $threshold || break
47
48    # IF no file has $threshold or better SIG matches;
49    # generate a new search list from all files #included from the old list
50    newfiles=""
51    for file in $files; do
52        test -f $file || continue
53        new=`egrep "$RE_inc" $file|sed "s,$RE_inc,,"';s,>.*$,,'`
54        newfiles=" $new $newfiles"
55    done
56
57    # remove any files that have been searched previously
58    for file in $seen; do
59        newfiles=`echo "$newfiles"|sed "s, $file , ,g"`
60    done
61
62    # set the search list for the next iteration
63    files="$newfiles"
64    num=0
65done
66
67if test $num -lt $threshold
68then
69  echo "WARNING: cannot find signal definitions in $seen" >&2
70  echo "using POSIX + ANSI signal definitions" >&2
71  cat <<- _EOF_
72	signal[  1 ] = { signame = SIGHUP;
73	                 sigtext = "Hangup (POSIX)."; };
74	signal[  2 ] = { signame = SIGINT;
75	                 sigtext = "Interrupt (ANSI)."; };
76	signal[  3 ] = { signame = SIGQUIT;
77	                 sigtext = "Quit (POSIX)."; };
78	signal[  4 ] = { signame = SIGILL;
79	                 sigtext = "Illegal instruction (ANSI)."; };
80	signal[  5 ] = { signame = SIGTRAP;
81	                 sigtext = "Trace trap (POSIX)."; };
82	signal[  6 ] = { signame = SIGABRT;
83	                 sigtext = "Abort (ANSI)."; };
84	signal[  8 ] = { signame = SIGFPE;
85	                 sigtext = "Floating-point exception (ANSI)."; };
86	signal[  9 ] = { signame = SIGKILL;
87	                 sigtext = "Kill, unblockable (POSIX)."; };
88	signal[ 10 ] = { signame = SIGUSR1;
89	                 sigtext = "User-defined signal 1 (POSIX)."; };
90	signal[ 11 ] = { signame = SIGSEGV;
91	                 sigtext = "Segmentation violation (ANSI)."; };
92	signal[ 12 ] = { signame = SIGUSR2;
93	                 sigtext = "User-defined signal 2 (POSIX)."; };
94	signal[ 13 ] = { signame = SIGPIPE;
95	                 sigtext = "Broken pipe (POSIX)."; };
96	signal[ 14 ] = { signame = SIGALRM;
97	                 sigtext = "Alarm clock (POSIX)."; };
98	signal[ 15 ] = { signame = SIGTERM;
99	                 sigtext = "Termination (ANSI)."; };
100	signal[ 17 ] = { signame = SIGCHLD;
101	                 sigtext = "Child status has changed (POSIX)."; };
102	signal[ 18 ] = { signame = SIGCONT;
103	                 sigtext = "Continue (POSIX)."; };
104	signal[ 19 ] = { signame = SIGSTOP;
105	                 sigtext = "Stop, unblockable (POSIX)."; };
106	signal[ 20 ] = { signame = SIGTSTP;
107	                 sigtext = "Keyboard stop (POSIX)."; };
108	signal[ 21 ] = { signame = SIGTTIN;
109	                 sigtext = "Background read from tty (POSIX)."; };
110	signal[ 22 ] = { signame = SIGTTOU;
111	                 sigtext = "Background write to tty (POSIX)."; };
112_EOF_
113
114else
115  echo "$sigs" |
116  while read SIG NUM f
117  do
118    #  IF the "signal number" is octal or hex or non-numeric,
119    #  THEN we know it is a value we are not interested in
120    #
121    case ${NUM} in
122    *[A-Za-z_]* )
123       continue ;;
124    esac
125
126    #  Sometimes, there are aliases.  Accept only the first.
127    #
128    if eval test ! -z \"\$HAVE_${NUM}\"
129    then continue ; fi
130
131    #  We also know we are not interested in super large numbers
132    #  (e.g. SIGSTKSZ 8192)
133    #
134    if test ${NUM} -gt 127
135    then continue ; fi
136
137    eval HAVE_${NUM}=1
138    f=`echo "$f" | sed -e 's;/\*[ 	]*;;' -e 's;[ 	]*\*/;;'`
139    if test -z "$f"
140    then f="Undescribed:  SIG${SIG} (${NUM})" ; fi
141
142    cat  <<-    _EOF_
143	signal[ ${NUM} ] = {
144	    signame = ${SIG};
145	    sigtext = "$f";
146	};
147
148	_EOF_
149  done
150fi
151#endshell
152