Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / ada / gen-soccon.c
blobec513f61935e8b8dc3dfb5119fa9b77f64a9cb70
1 /****************************************************************************
2 * *
3 * GNAT SYSTEM UTILITIES *
4 * *
5 * G E N - S O C C O N *
6 * *
7 * Copyright (C) 2004-2007, 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 struct line {
55 char *text;
56 char *value;
57 char *comment;
58 struct line *next;
61 struct line *first = NULL, *last = NULL;
63 #define TXT(_text) add_line(_text, NULL, NULL);
64 /* Plain text */
66 #define _NL TXT("")
67 /* Empty line */
69 #define itoad(n) f_itoa ("%d", (n))
70 #define itoax(n) f_itoa ("16#%08x#", (n))
72 #define CND(name,comment) add_line(#name, itoad (name), comment);
73 /* Constant (decimal) */
75 #define CNX(name,comment) add_line(#name, itoax (name), comment);
76 /* Constant (hexadecimal) */
78 #define CN_(name,comment) add_line(#name, name, comment);
79 /* Constant (generic) */
81 #define STR(p) STR1(p)
82 #define STR1(p) #p
84 void output (void);
85 /* Generate output spec */
87 char *f_itoa (char *, int);
88 /* int to string */
90 void add_line (char *, char*, char*);
92 #ifdef __MINGW32__
93 unsigned int _CRT_fmode = _O_BINARY;
94 #endif
96 int
97 main (void) {
99 TXT("------------------------------------------------------------------------------")
100 TXT("-- --")
101 TXT("-- GNAT COMPILER COMPONENTS --")
102 TXT("-- --")
103 TXT("-- G N A T . S O C K E T S . C O N S T A N T S --")
104 TXT("-- --")
105 TXT("-- S p e c --")
106 TXT("-- --")
107 TXT("-- Copyright (C) 2000-2007, Free Software Foundation, Inc. --")
108 TXT("-- --")
109 TXT("-- GNAT is free software; you can redistribute it and/or modify it under --")
110 TXT("-- terms of the GNU General Public License as published by the Free Soft- --")
111 TXT("-- ware Foundation; either version 2, or (at your option) any later ver- --")
112 TXT("-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --")
113 TXT("-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --")
114 TXT("-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --")
115 TXT("-- for more details. You should have received a copy of the GNU General --")
116 TXT("-- Public License distributed with GNAT; see file COPYING. If not, write --")
117 TXT("-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --")
118 TXT("-- Boston, MA 02110-1301, USA. --")
119 TXT("-- --")
120 TXT("-- As a special exception, if other files instantiate generics from this --")
121 TXT("-- unit, or you link this unit with other files to produce an executable, --")
122 TXT("-- this unit does not by itself cause the resulting executable to be --")
123 TXT("-- covered by the GNU General Public License. This exception does not --")
124 TXT("-- however invalidate any other reasons why the executable file might be --")
125 TXT("-- covered by the GNU Public License. --")
126 TXT("-- --")
127 TXT("-- GNAT was originally developed by the GNAT team at New York University. --")
128 TXT("-- Extensive contributions were provided by Ada Core Technologies Inc. --")
129 TXT("-- --")
130 TXT("------------------------------------------------------------------------------")
132 TXT("-- This package provides target dependent definitions of constant for use")
133 TXT("-- by the GNAT.Sockets package (g-socket.ads). This package should not be")
134 TXT("-- directly with'ed by an applications program.")
136 TXT("-- This is the version for " TARGET)
137 TXT("-- This file is generated automatically, do not modify it by hand! Instead,")
138 TXT("-- make changes to gen-soccon.c and re-run it on each target.")
140 TXT("package GNAT.Sockets.Constants is")
142 TXT(" --------------")
143 TXT(" -- Families --")
144 TXT(" --------------")
147 #ifndef AF_INET
148 #define AF_INET -1
149 #endif
150 CND(AF_INET, "IPv4 address family")
152 #ifndef AF_INET6
153 #define AF_INET6 -1
154 #endif
155 CND(AF_INET6, "IPv6 address family")
157 TXT(" -----------")
158 TXT(" -- Modes --")
159 TXT(" -----------")
162 #ifndef SOCK_STREAM
163 #define SOCK_STREAM -1
164 #endif
165 CND(SOCK_STREAM, "Stream socket")
167 #ifndef SOCK_DGRAM
168 #define SOCK_DGRAM -1
169 #endif
170 CND(SOCK_DGRAM, "Datagram socket")
172 TXT(" -------------------")
173 TXT(" -- Socket errors --")
174 TXT(" -------------------")
177 #ifndef EACCES
178 #define EACCES -1
179 #endif
180 CND(EACCES, "Permission denied")
182 #ifndef EADDRINUSE
183 #define EADDRINUSE -1
184 #endif
185 CND(EADDRINUSE, "Address already in use")
187 #ifndef EADDRNOTAVAIL
188 #define EADDRNOTAVAIL -1
189 #endif
190 CND(EADDRNOTAVAIL, "Cannot assign address")
192 #ifndef EAFNOSUPPORT
193 #define EAFNOSUPPORT -1
194 #endif
195 CND(EAFNOSUPPORT, "Addr family not supported")
197 #ifndef EALREADY
198 #define EALREADY -1
199 #endif
200 CND(EALREADY, "Operation in progress")
202 #ifndef EBADF
203 #define EBADF -1
204 #endif
205 CND(EBADF, "Bad file descriptor")
207 #ifndef ECONNABORTED
208 #define ECONNABORTED -1
209 #endif
210 CND(ECONNABORTED, "Connection aborted")
212 #ifndef ECONNREFUSED
213 #define ECONNREFUSED -1
214 #endif
215 CND(ECONNREFUSED, "Connection refused")
217 #ifndef ECONNRESET
218 #define ECONNRESET -1
219 #endif
220 CND(ECONNRESET, "Connection reset by peer")
222 #ifndef EDESTADDRREQ
223 #define EDESTADDRREQ -1
224 #endif
225 CND(EDESTADDRREQ, "Destination addr required")
227 #ifndef EFAULT
228 #define EFAULT -1
229 #endif
230 CND(EFAULT, "Bad address")
232 #ifndef EHOSTDOWN
233 #define EHOSTDOWN -1
234 #endif
235 CND(EHOSTDOWN, "Host is down")
237 #ifndef EHOSTUNREACH
238 #define EHOSTUNREACH -1
239 #endif
240 CND(EHOSTUNREACH, "No route to host")
242 #ifndef EINPROGRESS
243 #define EINPROGRESS -1
244 #endif
245 CND(EINPROGRESS, "Operation now in progress")
247 #ifndef EINTR
248 #define EINTR -1
249 #endif
250 CND(EINTR, "Interrupted system call")
252 #ifndef EINVAL
253 #define EINVAL -1
254 #endif
255 CND(EINVAL, "Invalid argument")
257 #ifndef EIO
258 #define EIO -1
259 #endif
260 CND(EIO, "Input output error")
262 #ifndef EISCONN
263 #define EISCONN -1
264 #endif
265 CND(EISCONN, "Socket already connected")
267 #ifndef ELOOP
268 #define ELOOP -1
269 #endif
270 CND(ELOOP, "Too many symbolic lynks")
272 #ifndef EMFILE
273 #define EMFILE -1
274 #endif
275 CND(EMFILE, "Too many open files")
277 #ifndef EMSGSIZE
278 #define EMSGSIZE -1
279 #endif
280 CND(EMSGSIZE, "Message too long")
282 #ifndef ENAMETOOLONG
283 #define ENAMETOOLONG -1
284 #endif
285 CND(ENAMETOOLONG, "Name too long")
287 #ifndef ENETDOWN
288 #define ENETDOWN -1
289 #endif
290 CND(ENETDOWN, "Network is down")
292 #ifndef ENETRESET
293 #define ENETRESET -1
294 #endif
295 CND(ENETRESET, "Disconn. on network reset")
297 #ifndef ENETUNREACH
298 #define ENETUNREACH -1
299 #endif
300 CND(ENETUNREACH, "Network is unreachable")
302 #ifndef ENOBUFS
303 #define ENOBUFS -1
304 #endif
305 CND(ENOBUFS, "No buffer space available")
307 #ifndef ENOPROTOOPT
308 #define ENOPROTOOPT -1
309 #endif
310 CND(ENOPROTOOPT, "Protocol not available")
312 #ifndef ENOTCONN
313 #define ENOTCONN -1
314 #endif
315 CND(ENOTCONN, "Socket not connected")
317 #ifndef ENOTSOCK
318 #define ENOTSOCK -1
319 #endif
320 CND(ENOTSOCK, "Operation on non socket")
322 #ifndef EOPNOTSUPP
323 #define EOPNOTSUPP -1
324 #endif
325 CND(EOPNOTSUPP, "Operation not supported")
327 #ifndef EPFNOSUPPORT
328 #define EPFNOSUPPORT -1
329 #endif
330 CND(EPFNOSUPPORT, "Unknown protocol family")
332 #ifndef EPROTONOSUPPORT
333 #define EPROTONOSUPPORT -1
334 #endif
335 CND(EPROTONOSUPPORT, "Unknown protocol")
337 #ifndef EPROTOTYPE
338 #define EPROTOTYPE -1
339 #endif
340 CND(EPROTOTYPE, "Unknown protocol type")
342 #ifndef ESHUTDOWN
343 #define ESHUTDOWN -1
344 #endif
345 CND(ESHUTDOWN, "Cannot send once shutdown")
347 #ifndef ESOCKTNOSUPPORT
348 #define ESOCKTNOSUPPORT -1
349 #endif
350 CND(ESOCKTNOSUPPORT, "Socket type not supported")
352 #ifndef ETIMEDOUT
353 #define ETIMEDOUT -1
354 #endif
355 CND(ETIMEDOUT, "Connection timed out")
357 #ifndef ETOOMANYREFS
358 #define ETOOMANYREFS -1
359 #endif
360 CND(ETOOMANYREFS, "Too many references")
362 #ifndef EWOULDBLOCK
363 #define EWOULDBLOCK -1
364 #endif
365 CND(EWOULDBLOCK, "Operation would block")
367 TXT(" -----------------")
368 TXT(" -- Host errors --")
369 TXT(" -----------------")
372 #ifndef HOST_NOT_FOUND
373 #define HOST_NOT_FOUND -1
374 #endif
375 CND(HOST_NOT_FOUND, "Unknown host")
377 #ifndef TRY_AGAIN
378 #define TRY_AGAIN -1
379 #endif
380 CND(TRY_AGAIN, "Host name lookup failure")
382 #ifndef NO_DATA
383 #define NO_DATA -1
384 #endif
385 CND(NO_DATA, "No data record for name")
387 #ifndef NO_RECOVERY
388 #define NO_RECOVERY -1
389 #endif
390 CND(NO_RECOVERY, "Non recoverable errors")
392 TXT(" -------------------")
393 TXT(" -- Control flags --")
394 TXT(" -------------------")
397 #ifndef FIONBIO
398 #define FIONBIO -1
399 #endif
400 CND(FIONBIO, "Set/clear non-blocking io")
402 #ifndef FIONREAD
403 #define FIONREAD -1
404 #endif
405 CND(FIONREAD, "How many bytes to read")
407 TXT(" --------------------")
408 TXT(" -- Shutdown modes --")
409 TXT(" --------------------")
412 #ifndef SHUT_RD
413 #define SHUT_RD -1
414 #endif
415 CND(SHUT_RD, "No more recv")
417 #ifndef SHUT_WR
418 #define SHUT_WR -1
419 #endif
420 CND(SHUT_WR, "No more send")
422 #ifndef SHUT_RDWR
423 #define SHUT_RDWR -1
424 #endif
425 CND(SHUT_RDWR, "No more recv/send")
427 TXT(" ---------------------")
428 TXT(" -- Protocol levels --")
429 TXT(" ---------------------")
432 #ifndef SOL_SOCKET
433 #define SOL_SOCKET -1
434 #endif
435 CND(SOL_SOCKET, "Options for socket level")
437 #ifndef IPPROTO_IP
438 #define IPPROTO_IP -1
439 #endif
440 CND(IPPROTO_IP, "Dummy protocol for IP")
442 #ifndef IPPROTO_UDP
443 #define IPPROTO_UDP -1
444 #endif
445 CND(IPPROTO_UDP, "UDP")
447 #ifndef IPPROTO_TCP
448 #define IPPROTO_TCP -1
449 #endif
450 CND(IPPROTO_TCP, "TCP")
452 TXT(" -------------------")
453 TXT(" -- Request flags --")
454 TXT(" -------------------")
457 #ifndef MSG_OOB
458 #define MSG_OOB -1
459 #endif
460 CND(MSG_OOB, "Process out-of-band data")
462 #ifndef MSG_PEEK
463 #define MSG_PEEK -1
464 #endif
465 CND(MSG_PEEK, "Peek at incoming data")
467 #ifndef MSG_EOR
468 #define MSG_EOR -1
469 #endif
470 CND(MSG_EOR, "Send end of record")
472 #ifndef MSG_WAITALL
473 #define MSG_WAITALL -1
474 #endif
475 CND(MSG_WAITALL, "Wait for full reception")
477 #ifndef MSG_NOSIGNAL
478 #define MSG_NOSIGNAL -1
479 #endif
480 CND(MSG_NOSIGNAL, "No SIGPIPE on send")
482 #ifdef __linux__
483 # define MSG_Forced_Flags "MSG_NOSIGNAL"
484 #else
485 # define MSG_Forced_Flags "0"
486 #endif
487 CN_(MSG_Forced_Flags, "")
488 TXT(" -- Flags set on all send(2) calls")
491 TXT(" --------------------")
492 TXT(" -- Socket options --")
493 TXT(" --------------------")
496 #ifndef TCP_NODELAY
497 #define TCP_NODELAY -1
498 #endif
499 CND(TCP_NODELAY, "Do not coalesce packets")
501 #ifndef SO_REUSEADDR
502 #define SO_REUSEADDR -1
503 #endif
504 CND(SO_REUSEADDR, "Bind reuse local address")
506 #ifndef SO_REUSEPORT
507 #define SO_REUSEPORT -1
508 #endif
509 CND(SO_REUSEPORT, "Bind reuse port number")
511 #ifndef SO_KEEPALIVE
512 #define SO_KEEPALIVE -1
513 #endif
514 CND(SO_KEEPALIVE, "Enable keep-alive msgs")
516 #ifndef SO_LINGER
517 #define SO_LINGER -1
518 #endif
519 CND(SO_LINGER, "Defer close to flush data")
521 #ifndef SO_BROADCAST
522 #define SO_BROADCAST -1
523 #endif
524 CND(SO_BROADCAST, "Can send broadcast msgs")
526 #ifndef SO_SNDBUF
527 #define SO_SNDBUF -1
528 #endif
529 CND(SO_SNDBUF, "Set/get send buffer size")
531 #ifndef SO_RCVBUF
532 #define SO_RCVBUF -1
533 #endif
534 CND(SO_RCVBUF, "Set/get recv buffer size")
536 #ifndef SO_SNDTIMEO
537 #define SO_SNDTIMEO -1
538 #endif
539 CND(SO_SNDTIMEO, "Emission timeout")
541 #ifndef SO_RCVTIMEO
542 #define SO_RCVTIMEO -1
543 #endif
544 CND(SO_RCVTIMEO, "Reception timeout")
546 #ifndef SO_ERROR
547 #define SO_ERROR -1
548 #endif
549 CND(SO_ERROR, "Get/clear error status")
551 #ifndef IP_MULTICAST_IF
552 #define IP_MULTICAST_IF -1
553 #endif
554 CND(IP_MULTICAST_IF, "Set/get mcast interface")
556 #ifndef IP_MULTICAST_TTL
557 #define IP_MULTICAST_TTL -1
558 #endif
559 CND(IP_MULTICAST_TTL, "Set/get multicast TTL")
561 #ifndef IP_MULTICAST_LOOP
562 #define IP_MULTICAST_LOOP -1
563 #endif
564 CND(IP_MULTICAST_LOOP, "Set/get mcast loopback")
566 #ifndef IP_ADD_MEMBERSHIP
567 #define IP_ADD_MEMBERSHIP -1
568 #endif
569 CND(IP_ADD_MEMBERSHIP, "Join a multicast group")
571 #ifndef IP_DROP_MEMBERSHIP
572 #define IP_DROP_MEMBERSHIP -1
573 #endif
574 CND(IP_DROP_MEMBERSHIP, "Leave a multicast group")
576 #ifndef IP_PKTINFO
577 #define IP_PKTINFO -1
578 #endif
579 CND(IP_PKTINFO, "Get datagram info")
582 TXT(" -------------------")
583 TXT(" -- System limits --")
584 TXT(" -------------------")
587 #ifndef IOV_MAX
588 #define IOV_MAX INT_MAX
589 #endif
590 CND(IOV_MAX, "Maximum writev iovcnt")
593 TXT(" ----------------------")
594 TXT(" -- Type definitions --")
595 TXT(" ----------------------")
599 struct timeval tv;
600 TXT(" -- Sizes (in bytes) of the components of struct timeval")
602 #define SIZEOF_tv_sec (sizeof tv.tv_sec)
603 CND(SIZEOF_tv_sec, "tv_sec")
604 #define SIZEOF_tv_usec (sizeof tv.tv_usec)
605 CND(SIZEOF_tv_usec, "tv_usec")
609 TXT(" ----------------------------------------")
610 TXT(" -- Properties of supported interfaces --")
611 TXT(" ----------------------------------------")
614 CND(Need_Netdb_Buffer, "Need buffer for Netdb ops")
616 #ifdef __vxworks
618 TXT(" --------------------------------")
619 TXT(" -- VxWorks-specific constants --")
620 TXT(" --------------------------------")
622 TXT(" -- These constants may be used only within the VxWorks version of")
623 TXT(" -- GNAT.Sockets.Thin.")
626 CND(OK, "VxWorks generic success")
627 CND(ERROR, "VxWorks generic error")
628 #endif
630 #ifdef __MINGW32__
632 TXT(" ------------------------------")
633 TXT(" -- MinGW-specific constants --")
634 TXT(" ------------------------------")
636 TXT(" -- These constants may be used only within the MinGW version of")
637 TXT(" -- GNAT.Sockets.Thin.")
640 CND(WSASYSNOTREADY, "System not ready")
641 CND(WSAVERNOTSUPPORTED, "Version not supported")
642 CND(WSANOTINITIALISED, "Winsock not intialized")
643 CND(WSAEDISCON, "Disconnected")
645 #endif
648 TXT(" ----------------------")
649 TXT(" -- Additional flags --")
650 TXT(" ----------------------")
652 TXT(" Thread_Blocking_IO : constant Boolean := True;")
653 TXT(" -- Set False for contexts where socket i/o are process blocking")
656 TXT("end GNAT.Sockets.Constants;")
658 output ();
659 return 0;
662 void
663 output (void) {
664 int text_max = 0, value_max = 0, l;
665 struct line *p;
666 char fmt[64];
667 #define UPD_MAX(x) do { \
668 l = strlen (p->x); \
669 if (l > x ## _max) x ## _max = l; \
670 } while (0)
672 for (p = first; p != NULL; p = p->next) {
673 if (p->value != NULL) {
674 UPD_MAX(text);
675 UPD_MAX(value);
678 sprintf (fmt, " %%-%ds : constant := %%%ds;%%s%%s\n",
679 text_max, value_max);
681 for (p = first; p != NULL; p = p->next) {
682 if (p->value == NULL) {
683 printf ("%s\n", p->text);
684 } else {
685 char *comment_sep = (strlen (p->comment) > 0)
686 ? " -- " : "";
687 printf (fmt, p->text, p->value, comment_sep, p->comment);
692 char *
693 f_itoa (char *fmt, int n) {
694 char buf[32], *ret;
695 sprintf (buf, fmt, n);
696 ret = malloc (strlen (buf) + 1);
697 if (ret != NULL)
698 strcpy (ret, buf);
699 return ret;
702 void
703 add_line (char *_text, char *_value, char *_comment) {
704 struct line *l = (struct line *) malloc (sizeof (struct line));
706 l->text = _text;
707 l->value = _value;
708 l->comment = _comment;
709 l->next = NULL;
710 if (last == NULL)
711 first = last = l;
712 else {
713 last->next = l;
714 last = l;