1[= AutoGen5 template  -*- Mode: html -*-
2
3h
4
5##  This file is part of AutoGen.
6##  AutoGen Copyright (C) 1992-2018 by Bruce Korb - all rights reserved
7##
8##  AutoGen is free software: you can redistribute it and/or modify it
9##  under the terms of the GNU General Public License as published by the
10##  Free Software Foundation, either version 3 of the License, or
11##  (at your option) any later version.
12##
13##  AutoGen is distributed in the hope that it will be useful, but
14##  WITHOUT ANY WARRANTY; without even the implied warranty of
15##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16##  See the GNU General Public License for more details.
17##
18##  You should have received a copy of the GNU General Public License along
19##  with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21(setenv "SHELL" "/bin/sh")
22
23=]
24[=(dne " *  " "/*  ")=]
25 *
26 *  Generated for a [=`uname -r`=] [=`uname`=] platform
27 *
28 *  strsignal Copyright (C) 1992-2017 by Bruce Korb - all rights reserved
29 *
30[=(gpl "AutoGen" " *  ")=]
31 */
32#ifndef MAX_SIGNAL_NUMBER
33#define MAX_SIGNAL_NUMBER   [= (high-lim "signal") =]
34#define SIGNAL_IN_RANGE(s)  (((unsigned)s) <= MAX_SIGNAL_NUMBER)
35#define SIGNAL_NAME(s)      (zSigNames + sigNameOffset[s])
36#define SIGNAL_INFO(s)      (zSigInfo  + sigInfoOffset[s])[=
37
38(define sig-names "\"INVALID\\0\"\n")
39(define name-refs "")
40(define name-ix   (- (string-length sig-names) 4))
41(define tmp-text  "")
42
43(define sig-info  "")
44(define info-refs "")
45(define info-ix   0)
46
47(define add-string (lambda()
48  (if (exist? "signame")
49      (begin
50        (set! tmp-text  (string-append "\"SIG" (get "signame") "\\0\"\n"))
51        (set! sig-names (string-append sig-names tmp-text))
52        (set! name-refs (string-append name-refs
53                        (sprintf "%d\n" name-ix)  ))
54        (set! name-ix   (+ name-ix (string-length tmp-text) -4))
55
56        (set! tmp-text  (sprintf "/* %3d */ \"%s\\0\"\n"
57                                 (for-index) (get "sigtext")))
58      )
59
60      (begin
61        (set! name-refs (string-append name-refs "0\n"))
62        (set! tmp-text  (sprintf "/* %1$3d */ \"Signal %1$d invalid\\0\"\n"
63                                 (for-index)))
64  )   )
65
66  (set! sig-info  (string-append sig-info tmp-text))
67  (set! info-refs (string-append info-refs
68                  (sprintf "%d\n" info-ix)  ))
69  (set! info-ix   (+ info-ix (string-length tmp-text) -14))
70))                      =][=
71
72FOR signal (for-from 0) (for-by 1) =][=
73
74  (add-string)          =][=
75
76ENDFOR signal           =]
77
78static char const zSigNames[] =
79[=(shell (string-append
80  "columns -I4 --spread=1 <<'_EOF_'\n"
81  sig-names
82  "_EOF_"  ))           =];
83
84static const unsigned int sigNameOffset[] = {
85[=(shell (string-append
86  "columns -I4 -S, --spread=1 <<'_EOF_'\n"
87  name-refs
88  "_EOF_"  ))           =] };
89
90#ifndef HAVE_SYS_SIGLIST
91static char const zSigInfo[] =
92[=(shell (string-append
93  "columns -I4 --spread=1 <<'_EOF_'\n"
94  sig-info
95  "_EOF_"  ))           =];
96
97static const unsigned int sigInfoOffset[] = {
98[=(shell (string-append
99  "columns -I4 -S, --spread=1 <<'_EOF_'\n"
100  info-refs
101  "_EOF_"  ))           =] };
102
103#endif /* MAX_SIGNAL_NUMBER */
104
105#ifndef HAVE_STRSIGNAL
106extern char * strsignal( int signo );
107#endif
108
109#ifdef DEBUG_STRSIGNAL
110#include <stdio.h>
111
112int
113main(int argc, char ** argv)
114{
115    int sig = 0;
116    fputs( "Sig  Sig-Name    Description\n"
117           "===  ========    ===========\n", stdout );
118    do {
119        printf( "%3d  %-10s  %s\n", sig, SIGNAL_NAME(sig),
120                SIGNAL_INFO(sig) );
121        ++sig;
122    } while (SIGNAL_IN_RANGE(sig));
123    return 0;
124}
125#endif /* DEBUG */
126#endif /* MAX_SIGNAL_NUMBER */
127