1/***********************************************************************
2*                                                                      *
3*               This software is part of the ast package               *
4*          Copyright (c) 1985-2012 AT&T Intellectual Property          *
5*                      and is licensed under the                       *
6*                 Eclipse Public License, Version 1.0                  *
7*                    by AT&T Intellectual Property                     *
8*                                                                      *
9*                A copy of the License is available at                 *
10*          http://www.eclipse.org/org/documents/epl-v10.html           *
11*         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12*                                                                      *
13*              Information and Software Systems Research               *
14*                            AT&T Research                             *
15*                           Florham Park NJ                            *
16*                                                                      *
17*                 Glenn Fowler <gsf@research.att.com>                  *
18*                  David Korn <dgk@research.att.com>                   *
19*                   Phong Vo <kpv@research.att.com>                    *
20*                                                                      *
21***********************************************************************/
22#pragma prototyped
23/*
24 * Glenn Fowler
25 * AT&T Research
26 *
27 * generate signal features
28 */
29
30#include "FEATURE/standards"
31
32#define strsignal	______strsignal
33
34#include <signal.h>
35
36#undef	strsignal
37
38struct _m_
39{
40	char*		text;
41	char*		name;
42	int		value;
43};
44
45#define elementsof(x)	(sizeof(x)/sizeof(x[0]))
46
47static struct _m_ map[] =
48{
49#ifdef SIGABRT
50#define HAD_SIGABRT	1
51"Abort",			"ABRT",		SIGABRT,
52#endif
53#ifdef SIGAIO
54#define HAD_SIGAIO	1
55"Asynchronous I/O",		"AIO",		SIGAIO,
56#endif
57#ifdef SIGALRM
58#define HAD_SIGALRM	1
59"Alarm call",			"ALRM",		SIGALRM,
60#endif
61#ifdef SIGAPOLLO
62#define HAD_SIGAPOLLO	1
63"Apollo",			"APOLLO",	SIGAPOLLO,
64#endif
65#ifdef SIGBUS
66#define HAD_SIGBUS	1
67"Bus error",			"BUS",		SIGBUS,
68#endif
69#ifdef SIGCHLD
70#define HAD_SIGCHLD	1
71"Child status change",		"CHLD",		SIGCHLD,
72#endif
73#ifdef SIGCLD
74#define HAD_SIGCLD	1
75"Death of child", 		"CLD",		SIGCLD,
76#endif
77#ifdef SIGCONT
78#define HAD_SIGCONT	1
79"Stopped process continued",	"CONT",		SIGCONT,
80#endif
81#ifdef SIGDANGER
82#define HAD_SIGDANGER	1
83"System crash soon",		"DANGER",	SIGDANGER,
84#endif
85#ifdef SIGDEBUG
86#define HAD_SIGDEBUG	1
87"Debug trap",			"DEBUG",	SIGDEBUG,
88#endif
89#ifdef SIGDIL
90#define HAD_SIGDIL	1
91"DIL trap",			"DIL",		SIGDIL,
92#endif
93#ifdef SIGEMT
94#define HAD_SIGEMT	1
95"EMT trap",			"EMT",		SIGEMT,
96#endif
97#ifdef SIGERR
98#define HAD_SIGERR	1
99"ERR trap",			"ERR",		SIGERR,
100#endif
101#ifdef SIGEXIT
102#define HAD_SIGEXIT	1
103"Exit",				"EXIT",		SIGEXIT,
104#endif
105#ifdef SIGFPE
106#define HAD_SIGFPE	1
107"Floating exception",		"FPE",		SIGFPE,
108#endif
109#ifdef SIGFREEZE
110#define HAD_SIGFREEZE	1
111"CPR freeze",			"FREEZE",	SIGFREEZE,
112#endif
113#ifdef SIGHUP
114#define HAD_SIGHUP	1
115"Hangup",			"HUP",		SIGHUP,
116#endif
117#ifdef SIGILL
118#define HAD_SIGILL	1
119"Illegal instruction",		"ILL",		SIGILL,
120#endif
121#ifdef SIGINT
122#define HAD_SIGINT	1
123"Interrupt",			"INT",		SIGINT,
124#endif
125#ifdef SIGIO
126#define HAD_SIGIO	1
127"IO possible",			"IO",		SIGIO,
128#endif
129#ifdef SIGIOT
130#define HAD_SIGIOT	1
131"IOT trap",			"IOT",		SIGIOT,
132#endif
133#ifdef SIGKILL
134#define HAD_SIGKILL	1
135"Killed",			"KILL",		SIGKILL,
136#endif
137#ifdef SIGLAB
138#define HAD_SIGLAB	1
139"Security label changed",	"LAB",		SIGLAB,
140#endif
141#ifdef SIGLOST
142#define HAD_SIGLOST	1
143"Resources lost",		"LOST",		SIGLOST,
144#endif
145#ifdef SIGLWP
146#define HAD_SIGLWP	1
147"Thread event",			"LWP",		SIGLWP,
148#endif
149#ifdef SIGMIGRATE
150#define HAD_SIGMIGRATE	1
151"Migrate process",		"MIGRATE",	SIGMIGRATE,
152#endif
153#ifdef SIGPHONE
154#define HAD_SIGPHONE	1
155"Phone status change",		"PHONE",	SIGPHONE,
156#endif
157#ifdef SIGPIPE
158#define HAD_SIGPIPE	1
159"Broken pipe",			"PIPE",		SIGPIPE,
160#endif
161#ifdef SIGPOLL
162#define HAD_SIGPOLL	1
163"Poll event",			"POLL",		SIGPOLL,
164#endif
165#ifdef SIGPROF
166#define HAD_SIGPROF	1
167"Profile timer alarm",		"PROF",		SIGPROF,
168#endif
169#ifdef SIGPWR
170#define HAD_SIGPWR	1
171"Power fail",			"PWR",		SIGPWR,
172#endif
173#ifdef SIGQUIT
174#define HAD_SIGQUIT	1
175"Quit",				"QUIT",		SIGQUIT,
176#endif
177#ifdef SIGSEGV
178#define HAD_SIGSEGV	1
179"Memory fault",			"SEGV",		SIGSEGV,
180#endif
181#ifdef SIGSOUND
182#define HAD_SIGSOUND	1
183"Sound completed",		"SOUND",	SIGSOUND,
184#endif
185#ifdef SIGSSTOP
186#define HAD_SIGSSTOP	1
187"Sendable stop",		"SSTOP",	SIGSSTOP,
188#endif
189#ifdef SIGSTKFLT
190#define HAD_SIGSTKFLT	1
191"Stack fault",			"STKFLT",	SIGSTKFLT,
192#endif
193#ifdef gould
194#define HAD_gould	1
195"Stack overflow",		"STKOV",	28,
196#endif
197#ifdef SIGSTOP
198#define HAD_SIGSTOP	1
199"Stopped (signal)",		"STOP",		SIGSTOP,
200#endif
201#ifdef SIGSYS
202#define HAD_SIGSYS	1
203"Bad system call", 		"SYS",		SIGSYS,
204#endif
205#ifdef SIGTERM
206#define HAD_SIGTERM	1
207"Terminated",			"TERM",		SIGTERM,
208#endif
209#ifdef SIGTHAW
210#define HAD_SIGTHAW	1
211"CPR thaw",			"THAW",		SIGTHAW,
212#endif
213#ifdef SIGTINT
214#define HAD_SIGTINT	1
215"Interrupt (terminal)",		"TINT",		SIGTINT,
216#endif
217#ifdef SIGTRAP
218#define HAD_SIGTRAP	1
219"Trace trap",			"TRAP",		SIGTRAP,
220#endif
221#ifdef SIGTSTP
222#define HAD_SIGTSTP	1
223"Stopped",			"TSTP",		SIGTSTP,
224#endif
225#ifdef SIGTTIN
226#define HAD_SIGTTIN	1
227"Stopped (tty input)",		"TTIN",		SIGTTIN,
228#endif
229#ifdef SIGTTOU
230#define HAD_SIGTTOU	1
231"Stopped (tty output)",		"TTOU",		SIGTTOU,
232#endif
233#ifdef SIGURG
234#define HAD_SIGURG	1
235"Urgent IO",			"URG",		SIGURG,
236#endif
237#ifdef SIGUSR1
238#define HAD_SIGUSR1	1
239"User signal 1",		"USR1",		SIGUSR1,
240#endif
241#ifdef SIGUSR2
242#define HAD_SIGUSR2	1
243"User signal 2",		"USR2",		SIGUSR2,
244#endif
245#ifdef SIGVTALRM
246#define HAD_SIGVTALRM	1
247"Virtual timer alarm",		"VTALRM",	SIGVTALRM,
248#endif
249#ifdef SIGWAITING
250#define HAD_SIGWAITING	1
251"All threads blocked",		"WAITING",	SIGWAITING,
252#endif
253#ifdef SIGWINCH
254#define HAD_SIGWINCH	1
255"Window change", 		"WINCH",	SIGWINCH,
256#endif
257#ifdef SIGWIND
258#define HAD_SIGWIND	1
259"Window change",		"WIND",		SIGWIND,
260#endif
261#ifdef SIGWINDOW
262#define HAD_SIGWINDOW	1
263"Window change",		"WINDOW",	SIGWINDOW,
264#endif
265#ifdef SIGXCPU
266#define HAD_SIGXCPU	1
267"CPU time limit",		"XCPU",		SIGXCPU,
268#endif
269#ifdef SIGXFSZ
270#define HAD_SIGXFSZ	1
271"File size limit",		"XFSZ",		SIGXFSZ,
272#endif
273#include "FEATURE/siglist"
2740
275};
276
277#define RANGE_MIN	(1<<14)
278#define RANGE_MAX	(1<<13)
279#define RANGE_RT	(1<<12)
280
281#define RANGE_SIG	(~(RANGE_MIN|RANGE_MAX|RANGE_RT))
282
283static int		mapindex[1024];
284
285#if _lib_strsignal
286extern char*		strsignal(int);
287#endif
288
289int
290main()
291{
292	register int	i;
293	register int	j;
294	register int	k;
295	int		m;
296	int		n;
297#if _lib_strsignal
298	char*		s;
299#endif
300
301	k = 0;
302	for (i = 0; map[i].name; i++)
303		if ((j = map[i].value) > 0 && j < elementsof(mapindex) && !mapindex[j])
304		{
305			if (j > k)
306				k = j;
307			mapindex[j] = i;
308		}
309#ifdef SIGRTMIN
310	i = SIGRTMIN;
311#ifdef SIGRTMAX
312	j = SIGRTMAX;
313#else
314	j = i;
315#endif
316	if (j >= elementsof(mapindex))
317		j = elementsof(mapindex) - 1;
318	if (i <= j && i > 0 && i < elementsof(mapindex) && j > 0 && j < elementsof(mapindex))
319	{
320		if (j > k)
321			k = j;
322		mapindex[i] = RANGE_MIN | RANGE_RT;
323		n = 1;
324		while (++i < j)
325			mapindex[i] = RANGE_RT | n++;
326		mapindex[j] = RANGE_MAX | RANGE_RT | n;
327	}
328#endif
329	printf("#pragma prototyped\n");
330	printf("#define SIG_MAX	%d\n", k);
331	printf("\n");
332	printf("static const char* const	sig_name[] =\n");
333	printf("{\n");
334	for (i = 0; i <= k; i++)
335		if (!(j = mapindex[i]))
336			printf("	\"%d\",\n", i);
337		else if (j & RANGE_RT)
338		{
339			if (j & RANGE_MIN)
340				printf("	\"RTMIN\",\n");
341			else if (j & RANGE_MAX)
342				printf("	\"RTMAX\",\n");
343			else
344			{
345				m = j & RANGE_SIG;
346				if (m > n / 2)
347					printf("	\"RTMAX-%d\",\n", n - m);
348				else
349					printf("	\"RTMIN+%d\",\n", m);
350			}
351		}
352		else
353			printf("	\"%s\",\n", map[j].name);
354	printf("	0\n");
355	printf("};\n");
356	printf("\n");
357	printf("static const char* const	sig_text[] =\n");
358	printf("{\n");
359	for (i = 0; i <= k; i++)
360		if (!(j = mapindex[i]))
361			printf("	\"Signal %d\",\n", i);
362		else if (j & RANGE_RT)
363			printf("	\"Realtime priority %d%s\",\n", j & RANGE_SIG, (j & RANGE_MIN) ? " (lo)" : (j & RANGE_MAX) ? " (hi)" : "");
364		else if (map[j].text)
365			printf("	\"%s\",\n", map[j].text);
366#if _lib_strsignal
367		else if (s = strsignal(i))
368			printf("	\"%s\",\n", s);
369#endif
370		else
371			printf("	\"Signal %d\",\n", i);
372	printf("	0\n");
373	printf("};\n");
374	return 0;
375}
376