1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
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
38 struct _m_
39 {
40 char* text;
41 char* name;
42 int value;
43 };
44
45 #define elementsof(x) (sizeof(x)/sizeof(x[0]))
46
47 static 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 gould
190 #define HAD_gould 1
191 "Stack overflow", "STKOV", 28,
192 #endif
193 #ifdef SIGSTOP
194 #define HAD_SIGSTOP 1
195 "Stopped (signal)", "STOP", SIGSTOP,
196 #endif
197 #ifdef SIGSYS
198 #define HAD_SIGSYS 1
199 "Bad system call", "SYS", SIGSYS,
200 #endif
201 #ifdef SIGTERM
202 #define HAD_SIGTERM 1
203 "Terminated", "TERM", SIGTERM,
204 #endif
205 #ifdef SIGTHAW
206 #define HAD_SIGTHAW 1
207 "CPR thaw", "THAW", SIGTHAW,
208 #endif
209 #ifdef SIGTINT
210 #define HAD_SIGTINT 1
211 "Interrupt (terminal)", "TINT", SIGTINT,
212 #endif
213 #ifdef SIGTRAP
214 #define HAD_SIGTRAP 1
215 "Trace trap", "TRAP", SIGTRAP,
216 #endif
217 #ifdef SIGTSTP
218 #define HAD_SIGTSTP 1
219 "Stopped", "TSTP", SIGTSTP,
220 #endif
221 #ifdef SIGTTIN
222 #define HAD_SIGTTIN 1
223 "Stopped (tty input)", "TTIN", SIGTTIN,
224 #endif
225 #ifdef SIGTTOU
226 #define HAD_SIGTTOU 1
227 "Stopped (tty output)", "TTOU", SIGTTOU,
228 #endif
229 #ifdef SIGURG
230 #define HAD_SIGURG 1
231 "Urgent IO", "URG", SIGURG,
232 #endif
233 #ifdef SIGUSR1
234 #define HAD_SIGUSR1 1
235 "User signal 1", "USR1", SIGUSR1,
236 #endif
237 #ifdef SIGUSR2
238 #define HAD_SIGUSR2 1
239 "User signal 2", "USR2", SIGUSR2,
240 #endif
241 #ifdef SIGVTALRM
242 #define HAD_SIGVTALRM 1
243 "Virtual timer alarm", "VTALRM", SIGVTALRM,
244 #endif
245 #ifdef SIGWAITING
246 #define HAD_SIGWAITING 1
247 "All threads blocked", "WAITING", SIGWAITING,
248 #endif
249 #ifdef SIGWINCH
250 #define HAD_SIGWINCH 1
251 "Window change", "WINCH", SIGWINCH,
252 #endif
253 #ifdef SIGWIND
254 #define HAD_SIGWIND 1
255 "Window change", "WIND", SIGWIND,
256 #endif
257 #ifdef SIGWINDOW
258 #define HAD_SIGWINDOW 1
259 "Window change", "WINDOW", SIGWINDOW,
260 #endif
261 #ifdef SIGXCPU
262 #define HAD_SIGXCPU 1
263 "CPU time limit", "XCPU", SIGXCPU,
264 #endif
265 #ifdef SIGXFSZ
266 #define HAD_SIGXFSZ 1
267 "File size limit", "XFSZ", SIGXFSZ,
268 #endif
269 #include "FEATURE/siglist"
270 0
271 };
272
273 #define RANGE_MIN (1<<14)
274 #define RANGE_MAX (1<<13)
275 #define RANGE_RT (1<<12)
276
277 #define RANGE_SIG (~(RANGE_MIN|RANGE_MAX|RANGE_RT))
278
279 static int mapindex[1024];
280
281 #if _lib_strsignal
282 extern char* strsignal(int);
283 #endif
284
285 int
main()286 main()
287 {
288 register int i;
289 register int j;
290 register int k;
291 int m;
292 int n;
293 #if _lib_strsignal
294 char* s;
295 #endif
296
297 k = 0;
298 for (i = 0; map[i].name; i++)
299 if ((j = map[i].value) > 0 && j < elementsof(mapindex) && !mapindex[j])
300 {
301 if (j > k)
302 k = j;
303 mapindex[j] = i;
304 }
305 #ifdef SIGRTMIN
306 i = SIGRTMIN;
307 #ifdef SIGRTMAX
308 j = SIGRTMAX;
309 #else
310 j = i;
311 #endif
312 if (j >= elementsof(mapindex))
313 j = elementsof(mapindex) - 1;
314 if (i <= j && i > 0 && i < elementsof(mapindex) && j > 0 && j < elementsof(mapindex))
315 {
316 if (j > k)
317 k = j;
318 mapindex[i] = RANGE_MIN | RANGE_RT;
319 n = 1;
320 while (++i < j)
321 mapindex[i] = RANGE_RT | n++;
322 mapindex[j] = RANGE_MAX | RANGE_RT | n;
323 }
324 #endif
325 printf("#pragma prototyped\n");
326 printf("#define SIG_MAX %d\n", k);
327 printf("\n");
328 printf("static const char* const sig_name[] =\n");
329 printf("{\n");
330 for (i = 0; i <= k; i++)
331 if (!(j = mapindex[i]))
332 printf(" \"%d\",\n", i);
333 else if (j & RANGE_RT)
334 {
335 if (j & RANGE_MIN)
336 printf(" \"RTMIN\",\n");
337 else if (j & RANGE_MAX)
338 printf(" \"RTMAX\",\n");
339 else
340 {
341 m = j & RANGE_SIG;
342 if (m > n / 2)
343 printf(" \"RTMAX-%d\",\n", n - m);
344 else
345 printf(" \"RTMIN+%d\",\n", m);
346 }
347 }
348 else
349 printf(" \"%s\",\n", map[j].name);
350 printf(" 0\n");
351 printf("};\n");
352 printf("\n");
353 printf("static const char* const sig_text[] =\n");
354 printf("{\n");
355 for (i = 0; i <= k; i++)
356 if (!(j = mapindex[i]))
357 printf(" \"Signal %d\",\n", i);
358 else if (j & RANGE_RT)
359 printf(" \"Realtime priority %d%s\",\n", j & RANGE_SIG, (j & RANGE_MIN) ? " (lo)" : (j & RANGE_MAX) ? " (hi)" : "");
360 else if (map[j].text)
361 printf(" \"%s\",\n", map[j].text);
362 #if _lib_strsignal
363 else if (s = strsignal(i))
364 printf(" \"%s\",\n", s);
365 #endif
366 else
367 printf(" \"Signal %d\",\n", i);
368 printf(" 0\n");
369 printf("};\n");
370 return 0;
371 }
372