Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtksh / ksh93 / src / lib / libast / features / signal.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: signal.c /main/2 1996/05/08 19:42:38 drk $ */
24 /***************************************************************
25 *                                                              *
26 *                      AT&T - PROPRIETARY                      *
27 *                                                              *
28 *         THIS IS PROPRIETARY SOURCE CODE LICENSED BY          *
29 *                          AT&T CORP.                          *
30 *                                                              *
31 *                Copyright (c) 1995 AT&T Corp.                 *
32 *                     All Rights Reserved                      *
33 *                                                              *
34 *           This software is licensed by AT&T Corp.            *
35 *       under the terms and conditions of the license in       *
36 *       http://www.research.att.com/orgs/ssr/book/reuse        *
37 *                                                              *
38 *               This software was created by the               *
39 *           Software Engineering Research Department           *
40 *                    AT&T Bell Laboratories                    *
41 *                                                              *
42 *               For further information contact                *
43 *                     gsf@research.att.com                     *
44 *                                                              *
45 ***************************************************************/
46
47 /* : : generated by proto : : */
48
49 #if !defined(__PROTO__)
50 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
51 #if defined(__cplusplus)
52 #define __MANGLE__      "C"
53 #else
54 #define __MANGLE__
55 #endif
56 #define __STDARG__
57 #define __PROTO__(x)    x
58 #define __OTORP__(x)
59 #define __PARAM__(n,o)  n
60 #if !defined(__STDC__) && !defined(__cplusplus)
61 #if !defined(c_plusplus)
62 #define const
63 #endif
64 #define signed
65 #define void            int
66 #define volatile
67 #define __V_            char
68 #else
69 #define __V_            void
70 #endif
71 #else
72 #define __PROTO__(x)    ()
73 #define __OTORP__(x)    x
74 #define __PARAM__(n,o)  o
75 #define __MANGLE__
76 #define __V_            char
77 #define const
78 #define signed
79 #define void            int
80 #define volatile
81 #endif
82 #if defined(__cplusplus) || defined(c_plusplus)
83 #define __VARARG__      ...
84 #else
85 #define __VARARG__
86 #endif
87 #if defined(__STDARG__)
88 #define __VA_START__(p,a)       va_start(p,a)
89 #else
90 #define __VA_START__(p,a)       va_start(p)
91 #endif
92 #endif
93 #include <signal.h>
94
95 struct _m_
96 {
97         char*           text;
98         char*           name;
99         int             value;
100 };
101
102 #define elementsof(x)   (sizeof(x)/sizeof(x[0]))
103
104 static struct _m_ map[] =
105 {
106 #ifdef SIGABRT
107 "Abort",                        "ABRT",         SIGABRT,
108 #endif
109 #ifdef SIGAIO
110 "Asynchronous I/O",             "AIO",          SIGAIO,
111 #endif
112 #ifdef SIGALRM
113 "Alarm call",                   "ALRM",         SIGALRM,
114 #endif
115 #ifdef SIGAPOLLO
116 "Apollo",                       "APOLLO",       SIGAPOLLO,
117 #endif
118 #ifdef SIGBUS
119 "Bus error",                    "BUS",          SIGBUS,
120 #endif
121 #ifdef SIGCHLD
122 "Child status change",          "CHLD",         SIGCHLD,
123 #endif
124 #ifdef SIGCLD
125 "Death of child",               "CLD",          SIGCLD,
126 #endif
127 #ifdef SIGCONT
128 "Stopped process continued",    "CONT",         SIGCONT,
129 #endif
130 #ifdef SIGDANGER
131 "System crash soon",            "DANGER",       SIGDANGER,
132 #endif
133 #ifdef SIGDEBUG
134 "Debug trap",                   "DEBUG",        SIGDEBUG,
135 #endif
136 #ifdef SIGDIL
137 "DIL trap",                     "DIL",          SIGDIL,
138 #endif
139 #ifdef SIGEMT
140 "EMT trap",                     "EMT",          SIGEMT,
141 #endif
142 #ifdef SIGERR
143 "ERR trap",                     "ERR",          SIGERR,
144 #endif
145 #ifdef SIGEXIT
146 "Exit",                         "EXIT",         SIGEXIT,
147 #endif
148 #ifdef SIGFPE
149 "Floating exception",           "FPE",          SIGFPE,
150 #endif
151 #ifdef SIGFREEZE
152 "CPR freeze",                   "FREEZE",       SIGFREEZE,
153 #endif
154 #ifdef SIGHUP
155 "Hangup",                       "HUP",          SIGHUP,
156 #endif
157 #ifdef SIGILL
158 "Illegal instruction",          "ILL",          SIGILL,
159 #endif
160 #ifdef SIGINT
161 "Interrupt",                    "INT",          SIGINT,
162 #endif
163 #ifdef SIGIO
164 "IO possible",                  "IO",           SIGIO,
165 #endif
166 #ifdef SIGIOT
167 "IOT trap",                     "IOT",          SIGIOT,
168 #endif
169 #ifdef SIGKILL
170 "Killed",                       "KILL",         SIGKILL,
171 #endif
172 #ifdef SIGLAB
173 "Security label changed",       "LAB",          SIGLAB,
174 #endif
175 #ifdef SIGLOST
176 "Resources lost",               "LOST",         SIGLOST,
177 #endif
178 #ifdef SIGLWP
179 "Thread event",                 "LWP",          SIGLWP,
180 #endif
181 #ifdef SIGMIGRATE
182 "Migrate process",              "MIGRATE",      SIGMIGRATE,
183 #endif
184 #ifdef SIGPHONE
185 "Phone status change",          "PHONE",        SIGPHONE,
186 #endif
187 #ifdef SIGPIPE
188 "Broken pipe",                  "PIPE",         SIGPIPE,
189 #endif
190 #ifdef SIGPOLL
191 "Poll event",                   "POLL",         SIGPOLL,
192 #endif
193 #ifdef SIGPROF
194 "Profile timer alarm",          "PROF",         SIGPROF,
195 #endif
196 #ifdef SIGPWR
197 "Power fail",                   "PWR",          SIGPWR,
198 #endif
199 #ifdef SIGQUIT
200 "Quit",                         "QUIT",         SIGQUIT,
201 #endif
202 #ifdef SIGSEGV
203 "Memory fault",                 "SEGV",         SIGSEGV,
204 #endif
205 #ifdef SIGSOUND
206 "Sound completed",              "SOUND",        SIGSOUND,
207 #endif
208 #ifdef SIGSSTOP
209 "Sendable stop",                "SSTOP",        SIGSSTOP,
210 #endif
211 #ifdef gould
212 "Stack overflow",               "STKOV",        28,
213 #endif
214 #ifdef SIGSTOP
215 "Stopped (signal)",             "STOP",         SIGSTOP,
216 #endif
217 #ifdef SIGSYS
218 "Bad system call",              "SYS",          SIGSYS,
219 #endif
220 #ifdef SIGTERM
221 "Terminated",                   "TERM",         SIGTERM,
222 #endif
223 #ifdef SIGTHAW
224 "CPR thaw",                     "THAW",         SIGTHAW,
225 #endif
226 #ifdef SIGTINT
227 "Interrupt (terminal)",         "TINT",         SIGTINT,
228 #endif
229 #ifdef SIGTRAP
230 "Trace trap",                   "TRAP",         SIGTRAP,
231 #endif
232 #ifdef SIGTSTP
233 "Stopped",                      "TSTP",         SIGTSTP,
234 #endif
235 #ifdef SIGTTIN
236 "Stopped (tty input)",          "TTIN",         SIGTTIN,
237 #endif
238 #ifdef SIGTTOU
239 "Stopped (tty output)",         "TTOU",         SIGTTOU,
240 #endif
241 #ifdef SIGURG
242 "Urgent IO",                    "URG",          SIGURG,
243 #endif
244 #ifdef SIGUSR1
245 "User signal 1",                "USR1",         SIGUSR1,
246 #endif
247 #ifdef SIGUSR2
248 "User signal 2",                "USR2",         SIGUSR2,
249 #endif
250 #ifdef SIGVTALRM
251 "Virtual timer alarm",          "VTALRM",       SIGVTALRM,
252 #endif
253 #ifdef SIGWAITING
254 "All threads blocked",          "WAITING",      SIGWAITING,
255 #endif
256 #ifdef SIGWINCH
257 "Window change",                "WINCH",        SIGWINCH,
258 #endif
259 #ifdef SIGWIND
260 "Window change",                "WIND",         SIGWIND,
261 #endif
262 #ifdef SIGWINDOW
263 "Window change",                "WINDOW",       SIGWINDOW,
264 #endif
265 #ifdef SIGXCPU
266 "CPU time limit",               "XCPU",         SIGXCPU,
267 #endif
268 #ifdef SIGXFSZ
269 "File size limit",              "XFSZ",         SIGXFSZ,
270 #endif
271 0
272 };
273
274 #define RANGE_MIN       (1<<14)
275 #define RANGE_MAX       (1<<13)
276 #define RANGE_RT        (1<<12)
277
278 #define RANGE_SIG       (~(RANGE_MIN|RANGE_MAX|RANGE_RT))
279
280 static int              index[64];
281
282 extern __MANGLE__ int           printf __PROTO__((const char*, ...));
283
284 main()
285 {
286         register int    i;
287         register int    j;
288         register int    k;
289         int             n;
290
291         k = 0;
292         for (i = 0; map[i].name; i++)
293                 if ((j = map[i].value) > 0 && j < elementsof(index) && !index[j])
294                 {
295                         if (j > k) k = j;
296                         index[j] = i;
297                 }
298 #ifdef SIGRTMIN
299         i = SIGRTMIN;
300 #ifdef SIGRTMAX
301         j = SIGRTMAX;
302 #else
303         j = i;
304 #endif
305         if (j >= elementsof(index)) j = elementsof(index) - 1;
306         if (i <= j && i > 0 && i < elementsof(index) && j > 0 && j < elementsof(index))
307         {
308                 if (j > k) k = j;
309                 index[i] = RANGE_MIN | RANGE_RT;
310                 n = 1;
311                 while (++i < j)
312                         index[i] = RANGE_RT | n++;
313                 index[j] = RANGE_MAX | RANGE_RT | n;
314         }
315 #endif
316         printf("#pragma prototyped\n");
317         printf("#define SIG_MAX %d\n", k);
318         printf("\n");
319         printf("static const char* const        sig_name[] =\n");
320         printf("{\n");
321         for (i = 0; i <= k; i++)
322                 if (!(j = index[i])) printf("   \"%d\",\n", i);
323                 else if (j & RANGE_RT)
324                 {
325                         if (j & RANGE_MIN) printf("     \"RTMIN\",\n");
326                         else if (j & RANGE_MAX) printf("        \"RTMAX\",\n");
327                         else printf("   \"RT%d\",\n", j & RANGE_SIG);
328                 }
329                 else printf("   \"%s\",\n", map[j].name);
330         printf("        0\n");
331         printf("};\n");
332         printf("\n");
333         printf("static const char* const        sig_text[] =\n");
334         printf("{\n");
335         for (i = 0; i <= k; i++)
336                 if (!(j = index[i])) printf("   \"Signal %d\",\n", i);
337                 else if (j & RANGE_RT) printf(" \"Realtime priority %d%s\",\n", j & RANGE_SIG, (j & RANGE_MIN) ? " (lo)" : (j & RANGE_MAX) ? " (hi)" : "");
338                 else printf("   \"%s\",\n", map[j].text);
339         printf("        0\n");
340         printf("};\n");
341         return(0);
342 }