2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / gen-soccon.c
blob62629651384862e6b4b82cea2945f4671b3c9c37
1 /****************************************************************************
2 * *
3 * GNAT SYSTEM UTILITIES *
4 * *
5 * G E N - S O C C O N *
6 * *
7 * Copyright (C) 2004-2008, Free Software Foundation, Inc. *
8 * *
9 * GNAT is free software; you can redistribute it and/or modify it under *
10 * terms of the GNU General Public License as published by the Free Soft- *
11 * ware Foundation; either version 2, or (at your option) any later ver- *
12 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
13 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
15 * for more details. You should have received a copy of the GNU General *
16 * Public License distributed with GNAT; see file COPYING. If not, write *
17 * to the Free Software Foundation, 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301, USA. *
19 * *
20 * GNAT was originally developed by the GNAT team at New York University. *
21 * Extensive contributions were provided by Ada Core Technologies Inc. *
22 * *
23 ****************************************************************************/
25 /* This program generates g-soccon.ads */
28 * To build using DEC C:
30 * CC/DEFINE="TARGET=""OpenVMS""" gen-soccon
31 * LINK gen-soccon
32 * RUN gen-soccon
34 * Note: OpenVMS versions older than 8.3 provide an incorrect value in
35 * the DEC C header files for MSG_WAITALL. To generate the VMS version
36 * of g-soccon.ads, gen-soccon should be run on an 8.3 or later machine.
39 #ifndef TARGET
40 # error Please define TARGET
41 #endif
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <limits.h>
48 #ifdef __MINGW32__
49 #include <fcntl.h>
50 #endif
52 #include "gsocket.h"
54 typedef enum { NUM, TXT } kind_t;
56 struct line {
57 char *text;
58 char *value;
59 char *comment;
60 kind_t kind;
61 struct line *next;
64 struct line *first = NULL, *last = NULL;
66 #define TXT(_text) add_line(_text, NULL, NULL, TXT);
67 /* Plain text */
69 #define _NL TXT("")
70 /* Empty line */
72 #define itoad(n) f_itoa ("%d", (n))
73 #define itoax(n) f_itoa ("16#%08x#", (n))
75 #define CND(name,comment) add_line(#name, itoad (name), comment, NUM);
76 /* Constant (decimal) */
78 #define CNX(name,comment) add_line(#name, itoax (name), comment, NUM);
79 /* Constant (hexadecimal) */
81 #define CN_(name,comment) add_line(#name, name, comment, TXT);
82 /* Constant (generic) */
84 #define STR(p) STR1(p)
85 #define STR1(p) #p
87 void output (void);
88 /* Generate output spec */
90 char *f_itoa (char *, int);
91 /* int to string */
93 void add_line (char *, char*, char*, kind_t);
95 #ifdef __MINGW32__
96 unsigned int _CRT_fmode = _O_BINARY;
97 #endif
99 int
100 main (void) {
102 TXT("------------------------------------------------------------------------------")
103 TXT("-- --")
104 TXT("-- GNAT COMPILER COMPONENTS --")
105 TXT("-- --")
106 TXT("-- G N A T . S O C K E T S . C O N S T A N T S --")
107 TXT("-- --")
108 TXT("-- S p e c --")
109 TXT("-- --")
110 TXT("-- Copyright (C) 2000-2008, Free Software Foundation, Inc. --")
111 TXT("-- --")
112 TXT("-- GNAT is free software; you can redistribute it and/or modify it under --")
113 TXT("-- terms of the GNU General Public License as published by the Free Soft- --")
114 TXT("-- ware Foundation; either version 2, or (at your option) any later ver- --")
115 TXT("-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --")
116 TXT("-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --")
117 TXT("-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --")
118 TXT("-- for more details. You should have received a copy of the GNU General --")
119 TXT("-- Public License distributed with GNAT; see file COPYING. If not, write --")
120 TXT("-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --")
121 TXT("-- Boston, MA 02110-1301, USA. --")
122 TXT("-- --")
123 TXT("-- As a special exception, if other files instantiate generics from this --")
124 TXT("-- unit, or you link this unit with other files to produce an executable, --")
125 TXT("-- this unit does not by itself cause the resulting executable to be --")
126 TXT("-- covered by the GNU General Public License. This exception does not --")
127 TXT("-- however invalidate any other reasons why the executable file might be --")
128 TXT("-- covered by the GNU Public License. --")
129 TXT("-- --")
130 TXT("-- GNAT was originally developed by the GNAT team at New York University. --")
131 TXT("-- Extensive contributions were provided by Ada Core Technologies Inc. --")
132 TXT("-- --")
133 TXT("------------------------------------------------------------------------------")
135 TXT("-- This package provides target dependent definitions of constant for use")
136 TXT("-- by the GNAT.Sockets package (g-socket.ads). This package should not be")
137 TXT("-- directly with'ed by an applications program.")
139 TXT("-- This is the version for " TARGET)
140 TXT("-- This file is generated automatically, do not modify it by hand! Instead,")
141 TXT("-- make changes to gen-soccon.c and re-run it on each target.")
143 TXT("with Interfaces.C;")
144 TXT("package GNAT.Sockets.Constants is")
146 TXT(" --------------")
147 TXT(" -- Families --")
148 TXT(" --------------")
151 #ifndef AF_INET
152 # define AF_INET -1
153 #endif
154 CND(AF_INET, "IPv4 address family")
156 #ifndef AF_INET6
157 # define AF_INET6 -1
158 #else
159 # define HAVE_AF_INET6 1
160 #endif
161 CND(AF_INET6, "IPv6 address family")
163 TXT(" -----------")
164 TXT(" -- Modes --")
165 TXT(" -----------")
168 #ifndef SOCK_STREAM
169 #define SOCK_STREAM -1
170 #endif
171 CND(SOCK_STREAM, "Stream socket")
173 #ifndef SOCK_DGRAM
174 #define SOCK_DGRAM -1
175 #endif
176 CND(SOCK_DGRAM, "Datagram socket")
178 TXT(" -------------------")
179 TXT(" -- Socket errors --")
180 TXT(" -------------------")
183 #ifndef EACCES
184 #define EACCES -1
185 #endif
186 CND(EACCES, "Permission denied")
188 #ifndef EADDRINUSE
189 #define EADDRINUSE -1
190 #endif
191 CND(EADDRINUSE, "Address already in use")
193 #ifndef EADDRNOTAVAIL
194 #define EADDRNOTAVAIL -1
195 #endif
196 CND(EADDRNOTAVAIL, "Cannot assign address")
198 #ifndef EAFNOSUPPORT
199 #define EAFNOSUPPORT -1
200 #endif
201 CND(EAFNOSUPPORT, "Addr family not supported")
203 #ifndef EALREADY
204 #define EALREADY -1
205 #endif
206 CND(EALREADY, "Operation in progress")
208 #ifndef EBADF
209 #define EBADF -1
210 #endif
211 CND(EBADF, "Bad file descriptor")
213 #ifndef ECONNABORTED
214 #define ECONNABORTED -1
215 #endif
216 CND(ECONNABORTED, "Connection aborted")
218 #ifndef ECONNREFUSED
219 #define ECONNREFUSED -1
220 #endif
221 CND(ECONNREFUSED, "Connection refused")
223 #ifndef ECONNRESET
224 #define ECONNRESET -1
225 #endif
226 CND(ECONNRESET, "Connection reset by peer")
228 #ifndef EDESTADDRREQ
229 #define EDESTADDRREQ -1
230 #endif
231 CND(EDESTADDRREQ, "Destination addr required")
233 #ifndef EFAULT
234 #define EFAULT -1
235 #endif
236 CND(EFAULT, "Bad address")
238 #ifndef EHOSTDOWN
239 #define EHOSTDOWN -1
240 #endif
241 CND(EHOSTDOWN, "Host is down")
243 #ifndef EHOSTUNREACH
244 #define EHOSTUNREACH -1
245 #endif
246 CND(EHOSTUNREACH, "No route to host")
248 #ifndef EINPROGRESS
249 #define EINPROGRESS -1
250 #endif
251 CND(EINPROGRESS, "Operation now in progress")
253 #ifndef EINTR
254 #define EINTR -1
255 #endif
256 CND(EINTR, "Interrupted system call")
258 #ifndef EINVAL
259 #define EINVAL -1
260 #endif
261 CND(EINVAL, "Invalid argument")
263 #ifndef EIO
264 #define EIO -1
265 #endif
266 CND(EIO, "Input output error")
268 #ifndef EISCONN
269 #define EISCONN -1
270 #endif
271 CND(EISCONN, "Socket already connected")
273 #ifndef ELOOP
274 #define ELOOP -1
275 #endif
276 CND(ELOOP, "Too many symbolic links")
278 #ifndef EMFILE
279 #define EMFILE -1
280 #endif
281 CND(EMFILE, "Too many open files")
283 #ifndef EMSGSIZE
284 #define EMSGSIZE -1
285 #endif
286 CND(EMSGSIZE, "Message too long")
288 #ifndef ENAMETOOLONG
289 #define ENAMETOOLONG -1
290 #endif
291 CND(ENAMETOOLONG, "Name too long")
293 #ifndef ENETDOWN
294 #define ENETDOWN -1
295 #endif
296 CND(ENETDOWN, "Network is down")
298 #ifndef ENETRESET
299 #define ENETRESET -1
300 #endif
301 CND(ENETRESET, "Disconn. on network reset")
303 #ifndef ENETUNREACH
304 #define ENETUNREACH -1
305 #endif
306 CND(ENETUNREACH, "Network is unreachable")
308 #ifndef ENOBUFS
309 #define ENOBUFS -1
310 #endif
311 CND(ENOBUFS, "No buffer space available")
313 #ifndef ENOPROTOOPT
314 #define ENOPROTOOPT -1
315 #endif
316 CND(ENOPROTOOPT, "Protocol not available")
318 #ifndef ENOTCONN
319 #define ENOTCONN -1
320 #endif
321 CND(ENOTCONN, "Socket not connected")
323 #ifndef ENOTSOCK
324 #define ENOTSOCK -1
325 #endif
326 CND(ENOTSOCK, "Operation on non socket")
328 #ifndef EOPNOTSUPP
329 #define EOPNOTSUPP -1
330 #endif
331 CND(EOPNOTSUPP, "Operation not supported")
333 #ifndef EPFNOSUPPORT
334 #define EPFNOSUPPORT -1
335 #endif
336 CND(EPFNOSUPPORT, "Unknown protocol family")
338 #ifndef EPROTONOSUPPORT
339 #define EPROTONOSUPPORT -1
340 #endif
341 CND(EPROTONOSUPPORT, "Unknown protocol")
343 #ifndef EPROTOTYPE
344 #define EPROTOTYPE -1
345 #endif
346 CND(EPROTOTYPE, "Unknown protocol type")
348 #ifndef ESHUTDOWN
349 #define ESHUTDOWN -1
350 #endif
351 CND(ESHUTDOWN, "Cannot send once shutdown")
353 #ifndef ESOCKTNOSUPPORT
354 #define ESOCKTNOSUPPORT -1
355 #endif
356 CND(ESOCKTNOSUPPORT, "Socket type not supported")
358 #ifndef ETIMEDOUT
359 #define ETIMEDOUT -1
360 #endif
361 CND(ETIMEDOUT, "Connection timed out")
363 #ifndef ETOOMANYREFS
364 #define ETOOMANYREFS -1
365 #endif
366 CND(ETOOMANYREFS, "Too many references")
368 #ifndef EWOULDBLOCK
369 #define EWOULDBLOCK -1
370 #endif
371 CND(EWOULDBLOCK, "Operation would block")
373 TXT(" -----------------")
374 TXT(" -- Host errors --")
375 TXT(" -----------------")
378 #ifndef HOST_NOT_FOUND
379 #define HOST_NOT_FOUND -1
380 #endif
381 CND(HOST_NOT_FOUND, "Unknown host")
383 #ifndef TRY_AGAIN
384 #define TRY_AGAIN -1
385 #endif
386 CND(TRY_AGAIN, "Host name lookup failure")
388 #ifndef NO_DATA
389 #define NO_DATA -1
390 #endif
391 CND(NO_DATA, "No data record for name")
393 #ifndef NO_RECOVERY
394 #define NO_RECOVERY -1
395 #endif
396 CND(NO_RECOVERY, "Non recoverable errors")
398 TXT(" -------------------")
399 TXT(" -- Control flags --")
400 TXT(" -------------------")
403 #ifndef FIONBIO
404 #define FIONBIO -1
405 #endif
406 CND(FIONBIO, "Set/clear non-blocking io")
408 #ifndef FIONREAD
409 #define FIONREAD -1
410 #endif
411 CND(FIONREAD, "How many bytes to read")
413 TXT(" --------------------")
414 TXT(" -- Shutdown modes --")
415 TXT(" --------------------")
418 #ifndef SHUT_RD
419 #define SHUT_RD -1
420 #endif
421 CND(SHUT_RD, "No more recv")
423 #ifndef SHUT_WR
424 #define SHUT_WR -1
425 #endif
426 CND(SHUT_WR, "No more send")
428 #ifndef SHUT_RDWR
429 #define SHUT_RDWR -1
430 #endif
431 CND(SHUT_RDWR, "No more recv/send")
433 TXT(" ---------------------")
434 TXT(" -- Protocol levels --")
435 TXT(" ---------------------")
438 #ifndef SOL_SOCKET
439 #define SOL_SOCKET -1
440 #endif
441 CND(SOL_SOCKET, "Options for socket level")
443 #ifndef IPPROTO_IP
444 #define IPPROTO_IP -1
445 #endif
446 CND(IPPROTO_IP, "Dummy protocol for IP")
448 #ifndef IPPROTO_UDP
449 #define IPPROTO_UDP -1
450 #endif
451 CND(IPPROTO_UDP, "UDP")
453 #ifndef IPPROTO_TCP
454 #define IPPROTO_TCP -1
455 #endif
456 CND(IPPROTO_TCP, "TCP")
458 TXT(" -------------------")
459 TXT(" -- Request flags --")
460 TXT(" -------------------")
463 #ifndef MSG_OOB
464 #define MSG_OOB -1
465 #endif
466 CND(MSG_OOB, "Process out-of-band data")
468 #ifndef MSG_PEEK
469 #define MSG_PEEK -1
470 #endif
471 CND(MSG_PEEK, "Peek at incoming data")
473 #ifndef MSG_EOR
474 #define MSG_EOR -1
475 #endif
476 CND(MSG_EOR, "Send end of record")
478 #ifndef MSG_WAITALL
479 #define MSG_WAITALL -1
480 #endif
481 CND(MSG_WAITALL, "Wait for full reception")
483 #ifndef MSG_NOSIGNAL
484 #define MSG_NOSIGNAL -1
485 #endif
486 CND(MSG_NOSIGNAL, "No SIGPIPE on send")
488 #ifdef __linux__
489 # define MSG_Forced_Flags "MSG_NOSIGNAL"
490 #else
491 # define MSG_Forced_Flags "0"
492 #endif
493 CN_(MSG_Forced_Flags, "")
494 TXT(" -- Flags set on all send(2) calls")
497 TXT(" --------------------")
498 TXT(" -- Socket options --")
499 TXT(" --------------------")
502 #ifndef TCP_NODELAY
503 #define TCP_NODELAY -1
504 #endif
505 CND(TCP_NODELAY, "Do not coalesce packets")
507 #ifndef SO_REUSEADDR
508 #define SO_REUSEADDR -1
509 #endif
510 CND(SO_REUSEADDR, "Bind reuse local address")
512 #ifndef SO_REUSEPORT
513 #define SO_REUSEPORT -1
514 #endif
515 CND(SO_REUSEPORT, "Bind reuse port number")
517 #ifndef SO_KEEPALIVE
518 #define SO_KEEPALIVE -1
519 #endif
520 CND(SO_KEEPALIVE, "Enable keep-alive msgs")
522 #ifndef SO_LINGER
523 #define SO_LINGER -1
524 #endif
525 CND(SO_LINGER, "Defer close to flush data")
527 #ifndef SO_BROADCAST
528 #define SO_BROADCAST -1
529 #endif
530 CND(SO_BROADCAST, "Can send broadcast msgs")
532 #ifndef SO_SNDBUF
533 #define SO_SNDBUF -1
534 #endif
535 CND(SO_SNDBUF, "Set/get send buffer size")
537 #ifndef SO_RCVBUF
538 #define SO_RCVBUF -1
539 #endif
540 CND(SO_RCVBUF, "Set/get recv buffer size")
542 #ifndef SO_SNDTIMEO
543 #define SO_SNDTIMEO -1
544 #endif
545 CND(SO_SNDTIMEO, "Emission timeout")
547 #ifndef SO_RCVTIMEO
548 #define SO_RCVTIMEO -1
549 #endif
550 CND(SO_RCVTIMEO, "Reception timeout")
552 #ifndef SO_ERROR
553 #define SO_ERROR -1
554 #endif
555 CND(SO_ERROR, "Get/clear error status")
557 #ifndef IP_MULTICAST_IF
558 #define IP_MULTICAST_IF -1
559 #endif
560 CND(IP_MULTICAST_IF, "Set/get mcast interface")
562 #ifndef IP_MULTICAST_TTL
563 #define IP_MULTICAST_TTL -1
564 #endif
565 CND(IP_MULTICAST_TTL, "Set/get multicast TTL")
567 #ifndef IP_MULTICAST_LOOP
568 #define IP_MULTICAST_LOOP -1
569 #endif
570 CND(IP_MULTICAST_LOOP, "Set/get mcast loopback")
572 #ifndef IP_ADD_MEMBERSHIP
573 #define IP_ADD_MEMBERSHIP -1
574 #endif
575 CND(IP_ADD_MEMBERSHIP, "Join a multicast group")
577 #ifndef IP_DROP_MEMBERSHIP
578 #define IP_DROP_MEMBERSHIP -1
579 #endif
580 CND(IP_DROP_MEMBERSHIP, "Leave a multicast group")
582 #ifndef IP_PKTINFO
583 #define IP_PKTINFO -1
584 #endif
585 CND(IP_PKTINFO, "Get datagram info")
588 TXT(" -------------------")
589 TXT(" -- System limits --")
590 TXT(" -------------------")
593 #ifndef IOV_MAX
594 #define IOV_MAX INT_MAX
595 #endif
596 CND(IOV_MAX, "Maximum writev iovcnt")
599 TXT(" ----------------------")
600 TXT(" -- Type definitions --")
601 TXT(" ----------------------")
605 struct timeval tv;
606 TXT(" -- Sizes (in bytes) of the components of struct timeval")
608 #define SIZEOF_tv_sec (sizeof tv.tv_sec)
609 CND(SIZEOF_tv_sec, "tv_sec")
610 #define SIZEOF_tv_usec (sizeof tv.tv_usec)
611 CND(SIZEOF_tv_usec, "tv_usec")
614 TXT(" -- Sizes of protocol specific address types (for sockaddr.sa_len)")
616 #define SIZEOF_sockaddr_in (sizeof (struct sockaddr_in))
617 CND(SIZEOF_sockaddr_in, "struct sockaddr_in")
618 #ifdef HAVE_AF_INET6
619 # define SIZEOF_sockaddr_in6 (sizeof (struct sockaddr_in6))
620 #else
621 # define SIZEOF_sockaddr_in6 0
622 #endif
623 CND(SIZEOF_sockaddr_in6, "struct sockaddr_in6")
625 TXT(" -- Size of file descriptor sets")
627 #define SIZEOF_fd_set (sizeof (fd_set))
628 CND(SIZEOF_fd_set, "fd_set");
630 TXT(" -- Fields of struct hostent")
632 #ifdef __MINGW32__
633 # define h_addrtype_t "short"
634 # define h_length_t "short"
635 #else
636 # define h_addrtype_t "int"
637 # define h_length_t "int"
638 #endif
639 TXT(" subtype H_Addrtype_T is Interfaces.C." h_addrtype_t ";")
640 TXT(" subtype H_Length_T is Interfaces.C." h_length_t ";")
642 TXT(" ----------------------------------------")
643 TXT(" -- Properties of supported interfaces --")
644 TXT(" ----------------------------------------")
647 CND(Need_Netdb_Buffer, "Need buffer for Netdb ops")
648 CND(Has_Sockaddr_Len, "Sockaddr has sa_len field")
650 TXT(" Thread_Blocking_IO : constant Boolean := True;")
651 TXT(" -- Set False for contexts where socket i/o are process blocking")
653 #ifdef __vxworks
655 TXT(" --------------------------------")
656 TXT(" -- VxWorks-specific constants --")
657 TXT(" --------------------------------")
659 TXT(" -- These constants may be used only within the VxWorks version of")
660 TXT(" -- GNAT.Sockets.Thin.")
663 CND(OK, "VxWorks generic success")
664 CND(ERROR, "VxWorks generic error")
665 #endif
667 #ifdef __MINGW32__
669 TXT(" ------------------------------")
670 TXT(" -- MinGW-specific constants --")
671 TXT(" ------------------------------")
673 TXT(" -- These constants may be used only within the MinGW version of")
674 TXT(" -- GNAT.Sockets.Thin.")
677 CND(WSASYSNOTREADY, "System not ready")
678 CND(WSAVERNOTSUPPORTED, "Version not supported")
679 CND(WSANOTINITIALISED, "Winsock not initialized")
680 CND(WSAEDISCON, "Disconnected")
681 #endif
684 TXT("end GNAT.Sockets.Constants;")
686 output ();
687 return 0;
690 void
691 output (void) {
692 int text_max = 0, value_max = 0, l;
693 struct line *p;
694 char fmt[64];
695 #define UPD_MAX(x) do { \
696 l = strlen (p->x); \
697 if (l > x ## _max) x ## _max = l; \
698 } while (0)
700 for (p = first; p != NULL; p = p->next) {
701 if (p->value != NULL) {
702 UPD_MAX(text);
703 if (p->kind == NUM)
704 UPD_MAX(value);
707 sprintf (fmt, " %%-%ds : constant := %%%ds;%%s%%s\n",
708 text_max, value_max);
710 for (p = first; p != NULL; p = p->next) {
711 if (p->value == NULL) {
712 printf ("%s\n", p->text);
713 } else {
714 char *comment_sep = (strlen (p->comment) > 0)
715 ? " -- " : "";
716 printf (fmt, p->text, p->value, comment_sep, p->comment);
721 char *
722 f_itoa (char *fmt, int n) {
723 char buf[32], *ret;
724 sprintf (buf, fmt, n);
725 ret = malloc (strlen (buf) + 1);
726 if (ret != NULL)
727 strcpy (ret, buf);
728 return ret;
731 void
732 add_line (char *_text, char *_value, char *_comment, kind_t _kind) {
733 struct line *l = (struct line *) malloc (sizeof (struct line));
735 l->text = _text;
736 l->value = _value;
737 l->comment = _comment;
738 l->kind = _kind;
739 l->next = NULL;
741 if (last == NULL)
742 first = last = l;
743 else {
744 last->next = l;
745 last = l;