source: trunk/src/kash/bld_signames.c@ 3409

Last change on this file since 3409 was 3409, checked in by bird, 5 years ago

kash: Generate the signal names at compile time rather than lazily at runtime. This should be more efficient, though may cause trouble if cross building.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1
2#include "shinstance.h" /* for MSC */
3#include <string.h>
4#include <stdio.h>
5
6int 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#ifdef SIGHUP
27 SET_SIG_STR(HUP);
28#endif
29#ifdef SIGINT
30 SET_SIG_STR(INT);
31#endif
32#ifdef SIGQUIT
33 SET_SIG_STR(QUIT);
34#endif
35#ifdef SIGILL
36 SET_SIG_STR(ILL);
37#endif
38#ifdef SIGTRAP
39 SET_SIG_STR(TRAP);
40#endif
41#ifdef SIGABRT
42 SET_SIG_STR(ABRT);
43#endif
44#ifdef SIGIOT
45 SET_SIG_STR(IOT);
46#endif
47#ifdef SIGBUS
48 SET_SIG_STR(BUS);
49#endif
50#ifdef SIGFPE
51 SET_SIG_STR(FPE);
52#endif
53#ifdef SIGKILL
54 SET_SIG_STR(KILL);
55#endif
56#ifdef SIGUSR1
57 SET_SIG_STR(USR1);
58#endif
59#ifdef SIGSEGV
60 SET_SIG_STR(SEGV);
61#endif
62#ifdef SIGUSR2
63 SET_SIG_STR(USR2);
64#endif
65#ifdef SIGPIPE
66 SET_SIG_STR(PIPE);
67#endif
68#ifdef SIGALRM
69 SET_SIG_STR(ALRM);
70#endif
71#ifdef SIGTERM
72 SET_SIG_STR(TERM);
73#endif
74#ifdef SIGSTKFLT
75 SET_SIG_STR(STKFLT);
76#endif
77#ifdef SIGCHLD
78 SET_SIG_STR(CHLD);
79#endif
80#ifdef SIGCONT
81 SET_SIG_STR(CONT);
82#endif
83#ifdef SIGSTOP
84 SET_SIG_STR(STOP);
85#endif
86#ifdef SIGTSTP
87 SET_SIG_STR(TSTP);
88#endif
89#ifdef SIGTTIN
90 SET_SIG_STR(TTIN);
91#endif
92#ifdef SIGTTOU
93 SET_SIG_STR(TTOU);
94#endif
95#ifdef SIGURG
96 SET_SIG_STR(URG);
97#endif
98#ifdef SIGXCPU
99 SET_SIG_STR(XCPU);
100#endif
101#ifdef SIGXFSZ
102 SET_SIG_STR(XFSZ);
103#endif
104#ifdef SIGVTALRM
105 SET_SIG_STR(VTALRM);
106#endif
107#ifdef SIGPROF
108 SET_SIG_STR(PROF);
109#endif
110#ifdef SIGWINCH
111 SET_SIG_STR(WINCH);
112#endif
113#ifdef SIGIO
114 SET_SIG_STR(IO);
115#endif
116#ifdef SIGPWR
117 SET_SIG_STR(PWR);
118#endif
119#ifdef SIGSYS
120 SET_SIG_STR(SYS);
121#endif
122#ifdef SIGBREAK
123 SET_SIG_STR(BREAK);
124#endif
125#undef SET_SIG_STR
126
127 /*
128 * Write out the list.
129 */
130 pFile = fopen(argv[1], "w");
131 if (!pFile)
132 {
133 fprintf(stderr, "error: failed to open '%s' for writing\n", argv[1]);
134 return 1;
135 }
136 fputs("/* autogenerate */\n"
137 "\n"
138 "#include \"shinstance.h\"\n"
139 "\n"
140 "const char * const sys_signame[NSIG] = \n"
141 "{\n"
142 , pFile);
143 for (i = 0; i < NSIG; i++)
144 fprintf(pFile, " \"%s\",\n", aszSigName[i]);
145 fputs("};\n", pFile);
146
147 if (fclose(pFile) != 0)
148 {
149 fprintf(stderr, "error: error writing/closing '%s' after writing it\n", argv[1]);
150 return 1;
151 }
152 return 0;
153}
154
Note: See TracBrowser for help on using the repository browser.