| 1 |
|
|---|
| 2 | #include "shinstance.h" /* for MSC */
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 |
|
|---|
| 6 | int main(int argc, char **argv)
|
|---|
| 7 | {
|
|---|
| 8 | char aszSigName[NSIG][16];
|
|---|
| 9 | FILE *pFile;
|
|---|
| 10 | int i;
|
|---|
| 11 |
|
|---|
| 12 | if (argc != 2 || *argv[1] == '\0')
|
|---|
| 13 | {
|
|---|
| 14 | fprintf(stderr, "syntax error: Expected exactly one parameter, the output-file!\n");
|
|---|
| 15 | return 2;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | /*
|
|---|
| 19 | * Populate the name array.
|
|---|
| 20 | */
|
|---|
| 21 | strcpy(aszSigName[0], "Signal 0");
|
|---|
| 22 | for (i = 1; i < NSIG; ++i)
|
|---|
| 23 | sprintf(aszSigName[i], "%i", i);
|
|---|
| 24 |
|
|---|
| 25 | #define SET_SIG_STR(sig) strcpy(aszSigName[SIG##sig], #sig);
|
|---|
| 26 |
|
|---|
| 27 | #if defined(SIGRTMIN) && defined(SIGRTMAX)
|
|---|
| 28 | if (SIGRTMIN < SIGRTMAX && SIGRTMAX < NSIG)
|
|---|
| 29 | {
|
|---|
| 30 | /* lets mimick what bash seems to be doing. */
|
|---|
| 31 | int const iMidWay = SIGRTMIN + (SIGRTMAX - SIGRTMIN) / 2;
|
|---|
| 32 | SET_SIG_STR(RTMIN);
|
|---|
| 33 | SET_SIG_STR(RTMAX);
|
|---|
| 34 |
|
|---|
| 35 | for (i = SIGRTMIN + 1; i <= iMidWay; i++)
|
|---|
| 36 | sprintf(aszSigName[i], "RTMIN+%i", (int)(i - SIGRTMIN));
|
|---|
| 37 | for (; i < SIGRTMAX; i++)
|
|---|
| 38 | sprintf(aszSigName[i], "RTMAX%i", (int)(i - SIGRTMAX));
|
|---|
| 39 | }
|
|---|
| 40 | else
|
|---|
| 41 | fprintf(stderr, "warning: SIGRTMIN=%d, SIGRTMAX=%d, NSIG=%d\n", (int)SIGRTMIN, (int)SIGRTMAX, (int)NSIG);
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | #ifdef SIGHUP
|
|---|
| 45 | SET_SIG_STR(HUP);
|
|---|
| 46 | #endif
|
|---|
| 47 | #ifdef SIGINT
|
|---|
| 48 | SET_SIG_STR(INT);
|
|---|
| 49 | #endif
|
|---|
| 50 | #ifdef SIGQUIT
|
|---|
| 51 | SET_SIG_STR(QUIT);
|
|---|
| 52 | #endif
|
|---|
| 53 | #ifdef SIGILL
|
|---|
| 54 | SET_SIG_STR(ILL);
|
|---|
| 55 | #endif
|
|---|
| 56 | #ifdef SIGTRAP
|
|---|
| 57 | SET_SIG_STR(TRAP);
|
|---|
| 58 | #endif
|
|---|
| 59 | #ifdef SIGABRT
|
|---|
| 60 | SET_SIG_STR(ABRT);
|
|---|
| 61 | #endif
|
|---|
| 62 | #ifdef SIGIOT
|
|---|
| 63 | SET_SIG_STR(IOT);
|
|---|
| 64 | #endif
|
|---|
| 65 | #ifdef SIGBUS
|
|---|
| 66 | SET_SIG_STR(BUS);
|
|---|
| 67 | #endif
|
|---|
| 68 | #ifdef SIGFPE
|
|---|
| 69 | SET_SIG_STR(FPE);
|
|---|
| 70 | #endif
|
|---|
| 71 | #ifdef SIGKILL
|
|---|
| 72 | SET_SIG_STR(KILL);
|
|---|
| 73 | #endif
|
|---|
| 74 | #ifdef SIGUSR1
|
|---|
| 75 | SET_SIG_STR(USR1);
|
|---|
| 76 | #endif
|
|---|
| 77 | #ifdef SIGSEGV
|
|---|
| 78 | SET_SIG_STR(SEGV);
|
|---|
| 79 | #endif
|
|---|
| 80 | #ifdef SIGUSR2
|
|---|
| 81 | SET_SIG_STR(USR2);
|
|---|
| 82 | #endif
|
|---|
| 83 | #ifdef SIGPIPE
|
|---|
| 84 | SET_SIG_STR(PIPE);
|
|---|
| 85 | #endif
|
|---|
| 86 | #ifdef SIGALRM
|
|---|
| 87 | SET_SIG_STR(ALRM);
|
|---|
| 88 | #endif
|
|---|
| 89 | #ifdef SIGTERM
|
|---|
| 90 | SET_SIG_STR(TERM);
|
|---|
| 91 | #endif
|
|---|
| 92 | #ifdef SIGSTKFLT
|
|---|
| 93 | SET_SIG_STR(STKFLT);
|
|---|
| 94 | #endif
|
|---|
| 95 | #ifdef SIGCHLD
|
|---|
| 96 | SET_SIG_STR(CHLD);
|
|---|
| 97 | #endif
|
|---|
| 98 | #ifdef SIGCONT
|
|---|
| 99 | SET_SIG_STR(CONT);
|
|---|
| 100 | #endif
|
|---|
| 101 | #ifdef SIGSTOP
|
|---|
| 102 | SET_SIG_STR(STOP);
|
|---|
| 103 | #endif
|
|---|
| 104 | #ifdef SIGTSTP
|
|---|
| 105 | SET_SIG_STR(TSTP);
|
|---|
| 106 | #endif
|
|---|
| 107 | #ifdef SIGTTIN
|
|---|
| 108 | SET_SIG_STR(TTIN);
|
|---|
| 109 | #endif
|
|---|
| 110 | #ifdef SIGTTOU
|
|---|
| 111 | SET_SIG_STR(TTOU);
|
|---|
| 112 | #endif
|
|---|
| 113 | #ifdef SIGURG
|
|---|
| 114 | SET_SIG_STR(URG);
|
|---|
| 115 | #endif
|
|---|
| 116 | #ifdef SIGXCPU
|
|---|
| 117 | SET_SIG_STR(XCPU);
|
|---|
| 118 | #endif
|
|---|
| 119 | #ifdef SIGXFSZ
|
|---|
| 120 | SET_SIG_STR(XFSZ);
|
|---|
| 121 | #endif
|
|---|
| 122 | #ifdef SIGVTALRM
|
|---|
| 123 | SET_SIG_STR(VTALRM);
|
|---|
| 124 | #endif
|
|---|
| 125 | #ifdef SIGPROF
|
|---|
| 126 | SET_SIG_STR(PROF);
|
|---|
| 127 | #endif
|
|---|
| 128 | #ifdef SIGWINCH
|
|---|
| 129 | SET_SIG_STR(WINCH);
|
|---|
| 130 | #endif
|
|---|
| 131 | #ifdef SIGIO
|
|---|
| 132 | SET_SIG_STR(IO);
|
|---|
| 133 | #endif
|
|---|
| 134 | #ifdef SIGPWR
|
|---|
| 135 | SET_SIG_STR(PWR);
|
|---|
| 136 | #endif
|
|---|
| 137 | #ifdef SIGSYS
|
|---|
| 138 | SET_SIG_STR(SYS);
|
|---|
| 139 | #endif
|
|---|
| 140 | #ifdef SIGBREAK
|
|---|
| 141 | SET_SIG_STR(BREAK);
|
|---|
| 142 | #endif
|
|---|
| 143 | #undef SET_SIG_STR
|
|---|
| 144 |
|
|---|
| 145 | /*
|
|---|
| 146 | * Write out the list.
|
|---|
| 147 | */
|
|---|
| 148 | pFile = fopen(argv[1], "w");
|
|---|
| 149 | if (!pFile)
|
|---|
| 150 | {
|
|---|
| 151 | fprintf(stderr, "error: failed to open '%s' for writing\n", argv[1]);
|
|---|
| 152 | return 1;
|
|---|
| 153 | }
|
|---|
| 154 | fputs("/* autogenerate */\n"
|
|---|
| 155 | "\n"
|
|---|
| 156 | "#include \"shinstance.h\"\n"
|
|---|
| 157 | "\n"
|
|---|
| 158 | "const char * const sys_signame[NSIG] = \n"
|
|---|
| 159 | "{\n"
|
|---|
| 160 | , pFile);
|
|---|
| 161 | for (i = 0; i < NSIG; i++)
|
|---|
| 162 | fprintf(pFile, " \"%s\",\n", aszSigName[i]);
|
|---|
| 163 | fputs("};\n", pFile);
|
|---|
| 164 |
|
|---|
| 165 | if (fclose(pFile) != 0)
|
|---|
| 166 | {
|
|---|
| 167 | fprintf(stderr, "error: error writing/closing '%s' after writing it\n", argv[1]);
|
|---|
| 168 | return 1;
|
|---|
| 169 | }
|
|---|
| 170 | return 0;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|