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