OILS / _gen / frontend / signal.cc View on Github | oilshell.org

205 lines, 167 significant
1#include "signal.h"
2
3#include <signal.h> // SIG*
4#include <stdio.h> // printf
5
6namespace signal_def {
7
8
9void PrintSignals() {
10#ifdef SIGHUP
11 printf("%2d SIGHUP\n", SIGHUP);
12#endif
13#ifdef SIGINT
14 printf("%2d SIGINT\n", SIGINT);
15#endif
16#ifdef SIGQUIT
17 printf("%2d SIGQUIT\n", SIGQUIT);
18#endif
19#ifdef SIGILL
20 printf("%2d SIGILL\n", SIGILL);
21#endif
22#ifdef SIGTRAP
23 printf("%2d SIGTRAP\n", SIGTRAP);
24#endif
25#ifdef SIGABRT
26 printf("%2d SIGABRT\n", SIGABRT);
27#endif
28#ifdef SIGBUS
29 printf("%2d SIGBUS\n", SIGBUS);
30#endif
31#ifdef SIGFPE
32 printf("%2d SIGFPE\n", SIGFPE);
33#endif
34#ifdef SIGUSR1
35 printf("%2d SIGUSR1\n", SIGUSR1);
36#endif
37#ifdef SIGSEGV
38 printf("%2d SIGSEGV\n", SIGSEGV);
39#endif
40#ifdef SIGUSR2
41 printf("%2d SIGUSR2\n", SIGUSR2);
42#endif
43#ifdef SIGPIPE
44 printf("%2d SIGPIPE\n", SIGPIPE);
45#endif
46#ifdef SIGALRM
47 printf("%2d SIGALRM\n", SIGALRM);
48#endif
49#ifdef SIGTERM
50 printf("%2d SIGTERM\n", SIGTERM);
51#endif
52#ifdef SIGCHLD
53 printf("%2d SIGCHLD\n", SIGCHLD);
54#endif
55#ifdef SIGCONT
56 printf("%2d SIGCONT\n", SIGCONT);
57#endif
58#ifdef SIGSTOP
59 printf("%2d SIGSTOP\n", SIGSTOP);
60#endif
61#ifdef SIGTSTP
62 printf("%2d SIGTSTP\n", SIGTSTP);
63#endif
64#ifdef SIGTTIN
65 printf("%2d SIGTTIN\n", SIGTTIN);
66#endif
67#ifdef SIGTTOU
68 printf("%2d SIGTTOU\n", SIGTTOU);
69#endif
70#ifdef SIGURG
71 printf("%2d SIGURG\n", SIGURG);
72#endif
73#ifdef SIGXCPU
74 printf("%2d SIGXCPU\n", SIGXCPU);
75#endif
76#ifdef SIGXFSZ
77 printf("%2d SIGXFSZ\n", SIGXFSZ);
78#endif
79#ifdef SIGVTALRM
80 printf("%2d SIGVTALRM\n", SIGVTALRM);
81#endif
82#ifdef SIGWINCH
83 printf("%2d SIGWINCH\n", SIGWINCH);
84#endif
85#ifdef SIGSYS
86 printf("%2d SIGSYS\n", SIGSYS);
87#endif
88}
89
90int GetNumber(BigStr* sig_spec) {
91 int length = len(sig_spec);
92 if (length == 0) {
93 return NO_SIGNAL;
94 }
95
96 const char* data = sig_spec->data_;
97
98 if ((length == 6 && memcmp("SIGHUP", data, 6) == 0) ||
99 (length == 3 && memcmp("HUP", data, 3) == 0)) {
100 return SIGHUP;
101 }
102 if ((length == 6 && memcmp("SIGINT", data, 6) == 0) ||
103 (length == 3 && memcmp("INT", data, 3) == 0)) {
104 return SIGINT;
105 }
106 if ((length == 7 && memcmp("SIGQUIT", data, 7) == 0) ||
107 (length == 4 && memcmp("QUIT", data, 4) == 0)) {
108 return SIGQUIT;
109 }
110 if ((length == 6 && memcmp("SIGILL", data, 6) == 0) ||
111 (length == 3 && memcmp("ILL", data, 3) == 0)) {
112 return SIGILL;
113 }
114 if ((length == 7 && memcmp("SIGTRAP", data, 7) == 0) ||
115 (length == 4 && memcmp("TRAP", data, 4) == 0)) {
116 return SIGTRAP;
117 }
118 if ((length == 7 && memcmp("SIGABRT", data, 7) == 0) ||
119 (length == 4 && memcmp("ABRT", data, 4) == 0)) {
120 return SIGABRT;
121 }
122 if ((length == 6 && memcmp("SIGBUS", data, 6) == 0) ||
123 (length == 3 && memcmp("BUS", data, 3) == 0)) {
124 return SIGBUS;
125 }
126 if ((length == 6 && memcmp("SIGFPE", data, 6) == 0) ||
127 (length == 3 && memcmp("FPE", data, 3) == 0)) {
128 return SIGFPE;
129 }
130 if ((length == 7 && memcmp("SIGUSR1", data, 7) == 0) ||
131 (length == 4 && memcmp("USR1", data, 4) == 0)) {
132 return SIGUSR1;
133 }
134 if ((length == 7 && memcmp("SIGSEGV", data, 7) == 0) ||
135 (length == 4 && memcmp("SEGV", data, 4) == 0)) {
136 return SIGSEGV;
137 }
138 if ((length == 7 && memcmp("SIGUSR2", data, 7) == 0) ||
139 (length == 4 && memcmp("USR2", data, 4) == 0)) {
140 return SIGUSR2;
141 }
142 if ((length == 7 && memcmp("SIGPIPE", data, 7) == 0) ||
143 (length == 4 && memcmp("PIPE", data, 4) == 0)) {
144 return SIGPIPE;
145 }
146 if ((length == 7 && memcmp("SIGALRM", data, 7) == 0) ||
147 (length == 4 && memcmp("ALRM", data, 4) == 0)) {
148 return SIGALRM;
149 }
150 if ((length == 7 && memcmp("SIGTERM", data, 7) == 0) ||
151 (length == 4 && memcmp("TERM", data, 4) == 0)) {
152 return SIGTERM;
153 }
154 if ((length == 7 && memcmp("SIGCHLD", data, 7) == 0) ||
155 (length == 4 && memcmp("CHLD", data, 4) == 0)) {
156 return SIGCHLD;
157 }
158 if ((length == 7 && memcmp("SIGCONT", data, 7) == 0) ||
159 (length == 4 && memcmp("CONT", data, 4) == 0)) {
160 return SIGCONT;
161 }
162 if ((length == 7 && memcmp("SIGSTOP", data, 7) == 0) ||
163 (length == 4 && memcmp("STOP", data, 4) == 0)) {
164 return SIGSTOP;
165 }
166 if ((length == 7 && memcmp("SIGTSTP", data, 7) == 0) ||
167 (length == 4 && memcmp("TSTP", data, 4) == 0)) {
168 return SIGTSTP;
169 }
170 if ((length == 7 && memcmp("SIGTTIN", data, 7) == 0) ||
171 (length == 4 && memcmp("TTIN", data, 4) == 0)) {
172 return SIGTTIN;
173 }
174 if ((length == 7 && memcmp("SIGTTOU", data, 7) == 0) ||
175 (length == 4 && memcmp("TTOU", data, 4) == 0)) {
176 return SIGTTOU;
177 }
178 if ((length == 6 && memcmp("SIGURG", data, 6) == 0) ||
179 (length == 3 && memcmp("URG", data, 3) == 0)) {
180 return SIGURG;
181 }
182 if ((length == 7 && memcmp("SIGXCPU", data, 7) == 0) ||
183 (length == 4 && memcmp("XCPU", data, 4) == 0)) {
184 return SIGXCPU;
185 }
186 if ((length == 7 && memcmp("SIGXFSZ", data, 7) == 0) ||
187 (length == 4 && memcmp("XFSZ", data, 4) == 0)) {
188 return SIGXFSZ;
189 }
190 if ((length == 9 && memcmp("SIGVTALRM", data, 9) == 0) ||
191 (length == 6 && memcmp("VTALRM", data, 6) == 0)) {
192 return SIGVTALRM;
193 }
194 if ((length == 8 && memcmp("SIGWINCH", data, 8) == 0) ||
195 (length == 5 && memcmp("WINCH", data, 5) == 0)) {
196 return SIGWINCH;
197 }
198 if ((length == 6 && memcmp("SIGSYS", data, 6) == 0) ||
199 (length == 3 && memcmp("SYS", data, 3) == 0)) {
200 return SIGSYS;
201 }
202 return NO_SIGNAL;
203}
204
205} // namespace signal_def