1 /*
2 * This program must be called with the constant name as the CONSTANT_NAME
3 * define. If this is not the case, then a generic version which takes a
4 * symbol to undefine as the first argument will be built.
5 */
6
7 #include <config.h>
8
9 #ifdef HAVE_SYS_CONF_H
10 # ifdef HAVE_SYS_PARAM_H
11 # include <sys/param.h>
12 # endif
13 # ifdef HAVE_TIME_H
14 # include <time.h>
15 # endif
16 #include <sys/conf.h>
17 #endif
18
19 #ifdef HAVE_SYS_FILE_H
20 #include <sys/file.h>
21 #endif
22
23 #ifdef HAVE_SYS_IOCTL_H
24 #include <sys/ioctl.h>
25 #endif
26
27 #ifdef HAVE_SYS_SOCKET_H
28 #include <sys/socket.h>
29 #endif
30
31 #ifdef HAVE_SYS_SYSTEMINFO_H
32 #include <sys/systeminfo.h>
33 #endif
34
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38
39 #ifdef HAVE_ERRNO_H
40 #include <errno.h>
41 #endif
42
43 #ifdef HAVE_FCNTL_H
44 #include <fcntl.h>
45 #endif
46
47 #ifdef HAVE_NETDB_H
48 #include <netdb.h>
49 #endif
50
51 #ifdef HAVE_NETINET_IN_H
52 #include <netinet/in.h>
53 #endif
54
55 #ifdef HAVE_NETINET_TCP_H
56 #include <netinet/tcp.h>
57 #endif
58
59 #ifdef HAVE_POLL_H
60 #include <poll.h>
61 #endif
62
63 #ifdef HAVE_SIGNAL_H
64 #include <signal.h>
65 #endif
66
67 #ifdef HAVE_STDIO_H
68 #include <stdio.h>
69 #endif
70
71 #ifdef HAVE_STDLIB_H
72 #include <stdlib.h>
73 #endif
74
75 #ifdef HAVE_STRING_H
76 #include <string.h>
77 #endif
78
79 #ifdef HAVE_STROPTS_H
80 #include <stropts.h>
81 #endif
82
83 #ifdef HAVE_TERMIO_H
84 #include <termio.h>
85 #endif
86
87 #ifdef HAVE_TERMIOS_H
88 #include <termios.h>
89 #endif
90
91 #ifdef HAVE_LINUX_SOCKIOS_H
92 #include <linux/sockios.h>
93 #endif
94
95 #ifdef HAVE_WINDOWS_H
96 #define Win32_Winsock
97 #include <windows.h>
98 /* This directive is checked only for mingw32 2.8.1 */
99 #if (_WIN32_WINNT >= 0x0400)
100 #include <ws2tcpip.h>
101 #endif
102
103 /* Absent declarations */
104 #define POLLIN 1
105 #define POLLPRI 2
106 #define POLLOUT 4
107
108 /* Undefine cygwin specific declarations to replace them */
109 #undef EINTR
110 #undef EWOULDBLOCK
111 #undef EINPROGRESS
112 #undef EALREADY
113 #undef EISCONN
114 #undef ECONNREFUSED
115
116 /* Replace with Windows sockets declaration */
117 #define EINTR WSAEINTR
118 #define EWOULDBLOCK WSAEWOULDBLOCK
119 #define EINPROGRESS WSAEINPROGRESS
120 #define EALREADY WSAEALREADY
121 #define EISCONN WSAEISCONN
122 #define ECONNREFUSED WSAECONNREFUSED
123 #endif
124
125 #include <ctype.h>
126
127 static char *
capitalize(char * name)128 capitalize (char *name)
129 {
130 int beginning = 1;
131 char *result = (char *) malloc (strlen (name) + 1);
132 char *ptr;
133 for (ptr = result; *name; ptr++, name++) {
134 *ptr = *name;
135 if (beginning) {
136 beginning = 0;
137 } else if (*ptr == '_') {
138 beginning = 1;
139 } else if (isupper(*ptr)) {
140 *ptr = tolower(*ptr);
141 }
142 }
143 *ptr = '\0';
144 return result;
145 }
146
147 static void
output(char * name,int value)148 output (char *name, int value)
149 {
150 char *capitalized = capitalize (name);
151 if (value >= 0) {
152 printf (" %-20s : constant := 16#%04X#;\n", capitalized, value);
153 } else {
154 printf (" %-20s : constant := %d;\n", capitalized, value);
155 }
156 }
157
158 int
main(int argc,char * argv[])159 main (int argc, char *argv[])
160 {
161 #ifdef CONSTANT_NAME
162 output (argv[1], CONSTANT_NAME);
163 #else
164 output (argv[1], -1);
165 #endif
166 exit (0);
167 }
168