summaryrefslogtreecommitdiff
path: root/compat/strsignal.def
blob: f645d109488923754b07133d8139706c363ff013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
autogen definitions strsignal;

/*
 *  Dynamic definitions for creating the strsignal.h header file
 *
 *  This file is part of AutoGen.
 *
 *  AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
 *
 *  AutoGen 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.
 *
 *  AutoGen 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#shell

RE_sigfind='[A-Z12]+[ 	]+[1-9][0-9]*'
RE_sigdef='^#[ 	]*define[ 	][ 	]*_*SIG'
RE_inc='^#[ 	]*include[ 	][ 	]*<'

threshold=5             # minimum number of signals to accept
num=0                   # number of signals defined in this file
seen=""                 # include files already searched
files="sys/signal.h"    # initial files to search

cd /usr/include
while test -n "$files"
do
    for file in $files; do
        # look for $threshold or more matches in one of the search files
        test -f $file || continue
        sigs=`egrep "$RE_sigdef$RE_sigfind" $file|sed "s,$RE_sigdef,,"`
        test -z "$sigs" || num=`echo "$sigs" | wc -l`
        test $num -lt $threshold || break
        seen="$file $seen"
    done
    test $num -lt $threshold || break

    # IF no file has $threshold or better SIG matches;
    # generate a new search list from all files #included from the old list
    newfiles=""
    for file in $files; do
        test -f $file || continue
        new=`egrep "$RE_inc" $file|sed "s,$RE_inc,,"';s,>.*$,,'`
        newfiles=" $new $newfiles"
    done

    # remove any files that have been searched previously
    for file in $seen; do
        newfiles=`echo "$newfiles"|sed "s, $file , ,g"`
    done

    # set the search list for the next iteration
    files="$newfiles"
    num=0
done

if test $num -lt $threshold
then
  echo "WARNING: cannot find signal definitions in $seen" >&2
  echo "using POSIX + ANSI signal definitions" >&2
  cat <<- _EOF_
	signal[  1 ] = { signame = SIGHUP;
	                 sigtext = "Hangup (POSIX)."; };
	signal[  2 ] = { signame = SIGINT;
	                 sigtext = "Interrupt (ANSI)."; };
	signal[  3 ] = { signame = SIGQUIT;
	                 sigtext = "Quit (POSIX)."; };
	signal[  4 ] = { signame = SIGILL;
	                 sigtext = "Illegal instruction (ANSI)."; };
	signal[  5 ] = { signame = SIGTRAP;
	                 sigtext = "Trace trap (POSIX)."; };
	signal[  6 ] = { signame = SIGABRT;
	                 sigtext = "Abort (ANSI)."; };
	signal[  8 ] = { signame = SIGFPE;
	                 sigtext = "Floating-point exception (ANSI)."; };
	signal[  9 ] = { signame = SIGKILL;
	                 sigtext = "Kill, unblockable (POSIX)."; };
	signal[ 10 ] = { signame = SIGUSR1;
	                 sigtext = "User-defined signal 1 (POSIX)."; };
	signal[ 11 ] = { signame = SIGSEGV;
	                 sigtext = "Segmentation violation (ANSI)."; };
	signal[ 12 ] = { signame = SIGUSR2;
	                 sigtext = "User-defined signal 2 (POSIX)."; };
	signal[ 13 ] = { signame = SIGPIPE;
	                 sigtext = "Broken pipe (POSIX)."; };
	signal[ 14 ] = { signame = SIGALRM;
	                 sigtext = "Alarm clock (POSIX)."; };
	signal[ 15 ] = { signame = SIGTERM;
	                 sigtext = "Termination (ANSI)."; };
	signal[ 17 ] = { signame = SIGCHLD;
	                 sigtext = "Child status has changed (POSIX)."; };
	signal[ 18 ] = { signame = SIGCONT;
	                 sigtext = "Continue (POSIX)."; };
	signal[ 19 ] = { signame = SIGSTOP;
	                 sigtext = "Stop, unblockable (POSIX)."; };
	signal[ 20 ] = { signame = SIGTSTP;
	                 sigtext = "Keyboard stop (POSIX)."; };
	signal[ 21 ] = { signame = SIGTTIN;
	                 sigtext = "Background read from tty (POSIX)."; };
	signal[ 22 ] = { signame = SIGTTOU;
	                 sigtext = "Background write to tty (POSIX)."; };
_EOF_

else
  echo "$sigs" |
  while read SIG NUM f
  do
    #  IF the "signal number" is octal or hex or non-numeric,
    #  THEN we know it is a value we are not interested in
    #
    case ${NUM} in
    *[A-Za-z_]* )
       continue ;;
    esac

    #  Sometimes, there are aliases.  Accept only the first.
    #
    if eval test ! -z \"\$HAVE_${NUM}\"
    then continue ; fi

    #  We also know we are not interested in super large numbers
    #  (e.g. SIGSTKSZ 8192)
    #
    if test ${NUM} -gt 127
    then continue ; fi

    eval HAVE_${NUM}=1
    f=`echo "$f" | sed -e 's;/\*[ 	]*;;' -e 's;[ 	]*\*/;;'`
    if test -z "$f"
    then f="Undescribed:  SIG${SIG} (${NUM})" ; fi

    cat  <<-    _EOF_
	signal[ ${NUM} ] = {
	    signame = ${SIG};
	    sigtext = "$f";
	};

	_EOF_
  done
fi
#endshell