|
| 1 | +/* Yash: yet another shell */ |
| 2 | +/* cross-signum.h: signum.h for cross-compiling */ |
| 3 | +/* (C) 2025 magicant */ |
| 4 | + |
| 5 | +/* This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 2 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 17 | + |
| 18 | + |
| 19 | +#ifndef CROSS_SIGNUM_H |
| 20 | +#define CROSS_SIGNUM_H |
| 21 | + |
| 22 | +#include <limits.h> |
| 23 | +#include <stddef.h> |
| 24 | +#include <signal.h> |
| 25 | + |
| 26 | +/* an injective function that returns an array index |
| 27 | + * corresponding to the given signal number, |
| 28 | + * which must be a valid non-realtime signal number |
| 29 | + * or zero. */ |
| 30 | +__attribute__((const)) |
| 31 | +static size_t sigindex(int signum) { |
| 32 | + // Not using the switch statement to avoid compiler errors that may happen |
| 33 | + // if some signal names share the same numeric values. |
| 34 | + if (signum == 0) |
| 35 | + return 0; |
| 36 | + if (signum == SIGHUP) |
| 37 | + return 1; |
| 38 | + if (signum == SIGINT) |
| 39 | + return 2; |
| 40 | + if (signum == SIGQUIT) |
| 41 | + return 3; |
| 42 | + if (signum == SIGILL) |
| 43 | + return 4; |
| 44 | +#ifdef SIGTRAP |
| 45 | + if (signum == SIGTRAP) |
| 46 | + return 5; |
| 47 | +#endif |
| 48 | + if (signum == SIGABRT) |
| 49 | + return 6; |
| 50 | + if (signum == SIGBUS) |
| 51 | + return 7; |
| 52 | + if (signum == SIGFPE) |
| 53 | + return 8; |
| 54 | + if (signum == SIGKILL) |
| 55 | + return 9; |
| 56 | + if (signum == SIGUSR1) |
| 57 | + return 10; |
| 58 | + if (signum == SIGSEGV) |
| 59 | + return 11; |
| 60 | + if (signum == SIGUSR2) |
| 61 | + return 12; |
| 62 | + if (signum == SIGPIPE) |
| 63 | + return 13; |
| 64 | + if (signum == SIGALRM) |
| 65 | + return 14; |
| 66 | + if (signum == SIGTERM) |
| 67 | + return 15; |
| 68 | +#ifdef SIGSTKFLT |
| 69 | + if (signum == SIGSTKFLT) |
| 70 | + return 16; |
| 71 | +#endif |
| 72 | + if (signum == SIGCHLD) |
| 73 | + return 17; |
| 74 | + if (signum == SIGCONT) |
| 75 | + return 18; |
| 76 | + if (signum == SIGSTOP) |
| 77 | + return 19; |
| 78 | + if (signum == SIGTSTP) |
| 79 | + return 20; |
| 80 | + if (signum == SIGTTIN) |
| 81 | + return 21; |
| 82 | + if (signum == SIGTTOU) |
| 83 | + return 22; |
| 84 | + if (signum == SIGURG) |
| 85 | + return 23; |
| 86 | +#ifdef SIGXCPU |
| 87 | + if (signum == SIGXCPU) |
| 88 | + return 24; |
| 89 | +#endif |
| 90 | +#ifdef SIGXFSZ |
| 91 | + if (signum == SIGXFSZ) |
| 92 | + return 25; |
| 93 | +#endif |
| 94 | +#ifdef SIGVTALRM |
| 95 | + if (signum == SIGVTALRM) |
| 96 | + return 26; |
| 97 | +#endif |
| 98 | +#ifdef SIGPROF |
| 99 | + if (signum == SIGPROF) |
| 100 | + return 27; |
| 101 | +#endif |
| 102 | +#ifdef SIGWINCH |
| 103 | + if (signum == SIGWINCH) |
| 104 | + return 28; |
| 105 | +#endif |
| 106 | +#ifdef SIGIO |
| 107 | + if (signum == SIGIO) |
| 108 | + return 29; |
| 109 | +#endif |
| 110 | +#ifdef SIGPWR |
| 111 | + if (signum == SIGPWR) |
| 112 | + return 30; |
| 113 | +#endif |
| 114 | +#ifdef SIGSYS |
| 115 | + if (signum == SIGSYS) |
| 116 | + return 31; |
| 117 | +#endif |
| 118 | +#ifdef SIGPOLL |
| 119 | + if (signum == SIGPOLL) |
| 120 | + return 32; |
| 121 | +#endif |
| 122 | +#ifdef SIGIOT |
| 123 | + if (signum == SIGIOT) |
| 124 | + return 33; |
| 125 | +#endif |
| 126 | +#ifdef SIGEMT |
| 127 | + if (signum == SIGEMT) |
| 128 | + return 34; |
| 129 | +#endif |
| 130 | +#ifdef SIGCLD |
| 131 | + if (signum == SIGCLD) |
| 132 | + return 35; |
| 133 | +#endif |
| 134 | +#ifdef SIGLOST |
| 135 | + if (signum == SIGLOST) |
| 136 | + return 36; |
| 137 | +#endif |
| 138 | +#ifdef SIGWINDOW |
| 139 | + if (signum == SIGWINDOW) |
| 140 | + return 37; |
| 141 | +#endif |
| 142 | +#ifdef SIGINFO |
| 143 | + if (signum == SIGINFO) |
| 144 | + return 38; |
| 145 | +#endif |
| 146 | +#ifdef SIGTHR |
| 147 | + if (signum == SIGTHR) |
| 148 | + return 39; |
| 149 | +#endif |
| 150 | +#ifdef SIGMSG |
| 151 | + if (signum == SIGMSG) |
| 152 | + return 40; |
| 153 | +#endif |
| 154 | +#ifdef SIGDANGER |
| 155 | + if (signum == SIGDANGER) |
| 156 | + return 41; |
| 157 | +#endif |
| 158 | +#ifdef SIGMIGRATE |
| 159 | + if (signum == SIGMIGRATE) |
| 160 | + return 42; |
| 161 | +#endif |
| 162 | +#ifdef SIGPRE |
| 163 | + if (signum == SIGPRE) |
| 164 | + return 43; |
| 165 | +#endif |
| 166 | +#ifdef SIGVIRT |
| 167 | + if (signum == SIGVIRT) |
| 168 | + return 44; |
| 169 | +#endif |
| 170 | +#ifdef SIGALRM1 |
| 171 | + if (signum == SIGALRM1) |
| 172 | + return 45; |
| 173 | +#endif |
| 174 | +#ifdef SIGWAITING |
| 175 | + if (signum == SIGWAITING) |
| 176 | + return 46; |
| 177 | +#endif |
| 178 | +#ifdef SIGKAP |
| 179 | + if (signum == SIGKAP) |
| 180 | + return 47; |
| 181 | +#endif |
| 182 | +#ifdef SIGGRANT |
| 183 | + if (signum == SIGGRANT) |
| 184 | + return 48; |
| 185 | +#endif |
| 186 | +#ifdef SIGRETRACT |
| 187 | + if (signum == SIGRETRACT) |
| 188 | + return 49; |
| 189 | +#endif |
| 190 | +#ifdef SIGSOUND |
| 191 | + if (signum == SIGSOUND) |
| 192 | + return 50; |
| 193 | +#endif |
| 194 | +#ifdef SIGSAK |
| 195 | + if (signum == SIGSAK) |
| 196 | + return 51; |
| 197 | +#endif |
| 198 | +#ifdef SIGLWP |
| 199 | + if (signum == SIGLWP) |
| 200 | + return 52; |
| 201 | +#endif |
| 202 | +#ifdef SIGFREEZE |
| 203 | + if (signum == SIGFREEZE) |
| 204 | + return 53; |
| 205 | +#endif |
| 206 | +#ifdef SIGTHAW |
| 207 | + if (signum == SIGTHAW) |
| 208 | + return 54; |
| 209 | +#endif |
| 210 | +#ifdef SIGCANCEL |
| 211 | + if (signum == SIGCANCEL) |
| 212 | + return 55; |
| 213 | +#endif |
| 214 | +#ifdef SIGXRES |
| 215 | + if (signum == SIGXRES) |
| 216 | + return 56; |
| 217 | +#endif |
| 218 | +#ifdef SIGRESERVE |
| 219 | + if (signum == SIGRESERVE) |
| 220 | + return 57; |
| 221 | +#endif |
| 222 | +#ifdef SIGDIL |
| 223 | + if (signum == SIGDIL) |
| 224 | + return 58; |
| 225 | +#endif |
| 226 | +#ifdef SIGUNUSED |
| 227 | + if (signum == SIGUNUSED) |
| 228 | + return 59; |
| 229 | +#endif |
| 230 | + |
| 231 | + /* assert(false); */ |
| 232 | + return 0; |
| 233 | +} |
| 234 | + |
| 235 | +/* max index returned by sigindex + 1 */ |
| 236 | +#define MAXSIGIDX 60 |
| 237 | + |
| 238 | +/* number of realtime signals that can be handled by yash */ |
| 239 | +#if defined(NSIG_MAX) && NSIG_MAX > 0 |
| 240 | +# define RTSIZE NSIG_MAX |
| 241 | +#else |
| 242 | +# define RTSIZE 100 |
| 243 | +#endif |
| 244 | + |
| 245 | +#endif /* CROSS_SIGNUM_H */ |
| 246 | + |
| 247 | +/* vim: set ts=8 sts=4 sw=4 et tw=80: */ |
0 commit comments