OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / ada / gen-soccon.c
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  ****************************************************************************/
24
25 /* This program generates g-soccon.ads */
26
27 /*
28  * To build using DEC C:
29  *
30  * CC/DEFINE="TARGET=""OpenVMS""" gen-soccon
31  * LINK gen-soccon
32  * RUN gen-soccon
33  *
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.
37  */
38
39 #ifndef TARGET
40 # error Please define TARGET
41 #endif
42
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <limits.h>
47
48 #ifdef __MINGW32__
49 #include <fcntl.h>
50 #endif
51
52 #include "gsocket.h"
53
54 struct line {
55   char *text;
56   char *value;
57   char *comment;
58   struct line *next;
59 };
60
61 struct line *first = NULL, *last = NULL;
62
63 #define TXT(_text) add_line(_text, NULL, NULL);
64 /* Plain text */
65
66 #define _NL TXT("")
67 /* Empty line */
68
69 #define itoad(n) f_itoa ("%d", (n))
70 #define itoax(n) f_itoa ("16#%08x#", (n))
71
72 #define CND(name,comment) add_line(#name, itoad (name), comment);
73 /* Constant (decimal) */
74
75 #define CNX(name,comment) add_line(#name, itoax (name), comment);
76 /* Constant (hexadecimal) */
77
78 #define CN_(name,comment) add_line(#name, name, comment);
79 /* Constant (generic) */
80
81 #define STR(p) STR1(p)
82 #define STR1(p) #p
83
84 void output (void);
85 /* Generate output spec */
86
87 char *f_itoa (char *, int);
88 /* int to string */
89
90 void add_line (char *, char*, char*);
91
92 #ifdef __MINGW32__
93 unsigned int _CRT_fmode = _O_BINARY;
94 #endif
95
96 int
97 main (void) {
98
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("------------------------------------------------------------------------------")
131 _NL
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.")
135 _NL
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.")
139 _NL
140 TXT("package GNAT.Sockets.Constants is")
141 _NL
142 TXT("   --------------")
143 TXT("   -- Families --")
144 TXT("   --------------")
145 _NL
146
147 #ifndef AF_INET
148 #define AF_INET -1
149 #endif
150 CND(AF_INET, "IPv4 address family")
151
152 #ifndef AF_INET6
153 #define AF_INET6 -1
154 #endif
155 CND(AF_INET6, "IPv6 address family")
156 _NL
157 TXT("   -----------")
158 TXT("   -- Modes --")
159 TXT("   -----------")
160 _NL
161
162 #ifndef SOCK_STREAM
163 #define SOCK_STREAM -1
164 #endif
165 CND(SOCK_STREAM, "Stream socket")
166
167 #ifndef SOCK_DGRAM
168 #define SOCK_DGRAM -1
169 #endif
170 CND(SOCK_DGRAM, "Datagram socket")
171 _NL
172 TXT("   -------------------")
173 TXT("   -- Socket errors --")
174 TXT("   -------------------")
175 _NL
176
177 #ifndef EACCES
178 #define EACCES -1
179 #endif
180 CND(EACCES, "Permission denied")
181
182 #ifndef EADDRINUSE
183 #define EADDRINUSE -1
184 #endif
185 CND(EADDRINUSE, "Address already in use")
186
187 #ifndef EADDRNOTAVAIL
188 #define EADDRNOTAVAIL -1
189 #endif
190 CND(EADDRNOTAVAIL, "Cannot assign address")
191
192 #ifndef EAFNOSUPPORT
193 #define EAFNOSUPPORT -1
194 #endif
195 CND(EAFNOSUPPORT, "Addr family not supported")
196
197 #ifndef EALREADY
198 #define EALREADY -1
199 #endif
200 CND(EALREADY, "Operation in progress")
201
202 #ifndef EBADF
203 #define EBADF -1
204 #endif
205 CND(EBADF, "Bad file descriptor")
206
207 #ifndef ECONNABORTED
208 #define ECONNABORTED -1
209 #endif
210 CND(ECONNABORTED, "Connection aborted")
211
212 #ifndef ECONNREFUSED
213 #define ECONNREFUSED -1
214 #endif
215 CND(ECONNREFUSED, "Connection refused")
216
217 #ifndef ECONNRESET
218 #define ECONNRESET -1
219 #endif
220 CND(ECONNRESET, "Connection reset by peer")
221
222 #ifndef EDESTADDRREQ
223 #define EDESTADDRREQ -1
224 #endif
225 CND(EDESTADDRREQ, "Destination addr required")
226
227 #ifndef EFAULT
228 #define EFAULT -1
229 #endif
230 CND(EFAULT, "Bad address")
231
232 #ifndef EHOSTDOWN
233 #define EHOSTDOWN -1
234 #endif
235 CND(EHOSTDOWN, "Host is down")
236
237 #ifndef EHOSTUNREACH
238 #define EHOSTUNREACH -1
239 #endif
240 CND(EHOSTUNREACH, "No route to host")
241
242 #ifndef EINPROGRESS
243 #define EINPROGRESS -1
244 #endif
245 CND(EINPROGRESS, "Operation now in progress")
246
247 #ifndef EINTR
248 #define EINTR -1
249 #endif
250 CND(EINTR, "Interrupted system call")
251
252 #ifndef EINVAL
253 #define EINVAL -1
254 #endif
255 CND(EINVAL, "Invalid argument")
256
257 #ifndef EIO
258 #define EIO -1
259 #endif
260 CND(EIO, "Input output error")
261
262 #ifndef EISCONN
263 #define EISCONN -1
264 #endif
265 CND(EISCONN, "Socket already connected")
266
267 #ifndef ELOOP
268 #define ELOOP -1
269 #endif
270 CND(ELOOP, "Too many symbolic lynks")
271
272 #ifndef EMFILE
273 #define EMFILE -1
274 #endif
275 CND(EMFILE, "Too many open files")
276
277 #ifndef EMSGSIZE
278 #define EMSGSIZE -1
279 #endif
280 CND(EMSGSIZE, "Message too long")
281
282 #ifndef ENAMETOOLONG
283 #define ENAMETOOLONG -1
284 #endif
285 CND(ENAMETOOLONG, "Name too long")
286
287 #ifndef ENETDOWN
288 #define ENETDOWN -1
289 #endif
290 CND(ENETDOWN, "Network is down")
291
292 #ifndef ENETRESET
293 #define ENETRESET -1
294 #endif
295 CND(ENETRESET, "Disconn. on network reset")
296
297 #ifndef ENETUNREACH
298 #define ENETUNREACH -1
299 #endif
300 CND(ENETUNREACH, "Network is unreachable")
301
302 #ifndef ENOBUFS
303 #define ENOBUFS -1
304 #endif
305 CND(ENOBUFS, "No buffer space available")
306
307 #ifndef ENOPROTOOPT
308 #define ENOPROTOOPT -1
309 #endif
310 CND(ENOPROTOOPT, "Protocol not available")
311
312 #ifndef ENOTCONN
313 #define ENOTCONN -1
314 #endif
315 CND(ENOTCONN, "Socket not connected")
316
317 #ifndef ENOTSOCK
318 #define ENOTSOCK -1
319 #endif
320 CND(ENOTSOCK, "Operation on non socket")
321
322 #ifndef EOPNOTSUPP
323 #define EOPNOTSUPP -1
324 #endif
325 CND(EOPNOTSUPP, "Operation not supported")
326
327 #ifndef EPFNOSUPPORT
328 #define EPFNOSUPPORT -1
329 #endif
330 CND(EPFNOSUPPORT, "Unknown protocol family")
331
332 #ifndef EPROTONOSUPPORT
333 #define EPROTONOSUPPORT -1
334 #endif
335 CND(EPROTONOSUPPORT, "Unknown protocol")
336
337 #ifndef EPROTOTYPE
338 #define EPROTOTYPE -1
339 #endif
340 CND(EPROTOTYPE, "Unknown protocol type")
341
342 #ifndef ESHUTDOWN
343 #define ESHUTDOWN -1
344 #endif
345 CND(ESHUTDOWN, "Cannot send once shutdown")
346
347 #ifndef ESOCKTNOSUPPORT
348 #define ESOCKTNOSUPPORT -1
349 #endif
350 CND(ESOCKTNOSUPPORT, "Socket type not supported")
351
352 #ifndef ETIMEDOUT
353 #define ETIMEDOUT -1
354 #endif
355 CND(ETIMEDOUT, "Connection timed out")
356
357 #ifndef ETOOMANYREFS
358 #define ETOOMANYREFS -1
359 #endif
360 CND(ETOOMANYREFS, "Too many references")
361
362 #ifndef EWOULDBLOCK
363 #define EWOULDBLOCK -1
364 #endif
365 CND(EWOULDBLOCK, "Operation would block")
366 _NL
367 TXT("   -----------------")
368 TXT("   -- Host errors --")
369 TXT("   -----------------")
370 _NL
371
372 #ifndef HOST_NOT_FOUND
373 #define HOST_NOT_FOUND -1
374 #endif
375 CND(HOST_NOT_FOUND, "Unknown host")
376
377 #ifndef TRY_AGAIN
378 #define TRY_AGAIN -1
379 #endif
380 CND(TRY_AGAIN, "Host name lookup failure")
381
382 #ifndef NO_DATA
383 #define NO_DATA -1
384 #endif
385 CND(NO_DATA, "No data record for name")
386
387 #ifndef NO_RECOVERY
388 #define NO_RECOVERY -1
389 #endif
390 CND(NO_RECOVERY, "Non recoverable errors")
391 _NL
392 TXT("   -------------------")
393 TXT("   -- Control flags --")
394 TXT("   -------------------")
395 _NL
396
397 #ifndef FIONBIO
398 #define FIONBIO -1
399 #endif
400 CND(FIONBIO, "Set/clear non-blocking io")
401
402 #ifndef FIONREAD
403 #define FIONREAD -1
404 #endif
405 CND(FIONREAD, "How many bytes to read")
406 _NL
407 TXT("   --------------------")
408 TXT("   -- Shutdown modes --")
409 TXT("   --------------------")
410 _NL
411
412 #ifndef SHUT_RD
413 #define SHUT_RD -1
414 #endif
415 CND(SHUT_RD, "No more recv")
416
417 #ifndef SHUT_WR
418 #define SHUT_WR -1
419 #endif
420 CND(SHUT_WR, "No more send")
421
422 #ifndef SHUT_RDWR
423 #define SHUT_RDWR -1
424 #endif
425 CND(SHUT_RDWR, "No more recv/send")
426 _NL
427 TXT("   ---------------------")
428 TXT("   -- Protocol levels --")
429 TXT("   ---------------------")
430 _NL
431
432 #ifndef SOL_SOCKET
433 #define SOL_SOCKET -1
434 #endif
435 CND(SOL_SOCKET, "Options for socket level")
436
437 #ifndef IPPROTO_IP
438 #define IPPROTO_IP -1
439 #endif
440 CND(IPPROTO_IP, "Dummy protocol for IP")
441
442 #ifndef IPPROTO_UDP
443 #define IPPROTO_UDP -1
444 #endif
445 CND(IPPROTO_UDP, "UDP")
446
447 #ifndef IPPROTO_TCP
448 #define IPPROTO_TCP -1
449 #endif
450 CND(IPPROTO_TCP, "TCP")
451 _NL
452 TXT("   -------------------")
453 TXT("   -- Request flags --")
454 TXT("   -------------------")
455 _NL
456
457 #ifndef MSG_OOB
458 #define MSG_OOB -1
459 #endif
460 CND(MSG_OOB, "Process out-of-band data")
461
462 #ifndef MSG_PEEK
463 #define MSG_PEEK -1
464 #endif
465 CND(MSG_PEEK, "Peek at incoming data")
466
467 #ifndef MSG_EOR
468 #define MSG_EOR -1
469 #endif
470 CND(MSG_EOR, "Send end of record")
471
472 #ifndef MSG_WAITALL
473 #define MSG_WAITALL -1
474 #endif
475 CND(MSG_WAITALL, "Wait for full reception")
476
477 #ifndef MSG_NOSIGNAL
478 #define MSG_NOSIGNAL -1
479 #endif
480 CND(MSG_NOSIGNAL, "No SIGPIPE on send")
481
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")
489
490 _NL
491 TXT("   --------------------")
492 TXT("   -- Socket options --")
493 TXT("   --------------------")
494 _NL
495
496 #ifndef TCP_NODELAY
497 #define TCP_NODELAY -1
498 #endif
499 CND(TCP_NODELAY, "Do not coalesce packets")
500
501 #ifndef SO_REUSEADDR
502 #define SO_REUSEADDR -1
503 #endif
504 CND(SO_REUSEADDR, "Bind reuse local address")
505
506 #ifndef SO_REUSEPORT
507 #define SO_REUSEPORT -1
508 #endif
509 CND(SO_REUSEPORT, "Bind reuse port number")
510
511 #ifndef SO_KEEPALIVE
512 #define SO_KEEPALIVE -1
513 #endif
514 CND(SO_KEEPALIVE, "Enable keep-alive msgs")
515
516 #ifndef SO_LINGER
517 #define SO_LINGER -1
518 #endif
519 CND(SO_LINGER, "Defer close to flush data")
520
521 #ifndef SO_BROADCAST
522 #define SO_BROADCAST -1
523 #endif
524 CND(SO_BROADCAST, "Can send broadcast msgs")
525
526 #ifndef SO_SNDBUF
527 #define SO_SNDBUF -1
528 #endif
529 CND(SO_SNDBUF, "Set/get send buffer size")
530
531 #ifndef SO_RCVBUF
532 #define SO_RCVBUF -1
533 #endif
534 CND(SO_RCVBUF, "Set/get recv buffer size")
535
536 #ifndef SO_SNDTIMEO
537 #define SO_SNDTIMEO -1
538 #endif
539 CND(SO_SNDTIMEO, "Emission timeout")
540
541 #ifndef SO_RCVTIMEO
542 #define SO_RCVTIMEO -1
543 #endif
544 CND(SO_RCVTIMEO, "Reception timeout")
545
546 #ifndef SO_ERROR
547 #define SO_ERROR -1
548 #endif
549 CND(SO_ERROR, "Get/clear error status")
550
551 #ifndef IP_MULTICAST_IF
552 #define IP_MULTICAST_IF -1
553 #endif
554 CND(IP_MULTICAST_IF, "Set/get mcast interface")
555
556 #ifndef IP_MULTICAST_TTL
557 #define IP_MULTICAST_TTL -1
558 #endif
559 CND(IP_MULTICAST_TTL, "Set/get multicast TTL")
560
561 #ifndef IP_MULTICAST_LOOP
562 #define IP_MULTICAST_LOOP -1
563 #endif
564 CND(IP_MULTICAST_LOOP, "Set/get mcast loopback")
565
566 #ifndef IP_ADD_MEMBERSHIP
567 #define IP_ADD_MEMBERSHIP -1
568 #endif
569 CND(IP_ADD_MEMBERSHIP, "Join a multicast group")
570
571 #ifndef IP_DROP_MEMBERSHIP
572 #define IP_DROP_MEMBERSHIP -1
573 #endif
574 CND(IP_DROP_MEMBERSHIP, "Leave a multicast group")
575
576 _NL
577 TXT("   -------------------")
578 TXT("   -- System limits --")
579 TXT("   -------------------")
580 _NL
581
582 #ifndef IOV_MAX
583 #define IOV_MAX INT_MAX
584 #endif
585 CND(IOV_MAX, "Maximum writev iovcnt")
586
587 _NL
588 TXT("   ----------------------")
589 TXT("   -- Type definitions --")
590 TXT("   ----------------------")
591 _NL
592
593 {
594   struct timeval tv;
595 TXT("   --  Sizes (in bytes) of the components of struct timeval")
596 _NL
597 #define SIZEOF_tv_sec (sizeof tv.tv_sec)
598 CND(SIZEOF_tv_sec, "tv_sec")
599 #define SIZEOF_tv_usec (sizeof tv.tv_usec)
600 CND(SIZEOF_tv_usec, "tv_usec")
601 }
602
603 _NL
604 TXT("   ----------------------------------------")
605 TXT("   -- Properties of supported interfaces --")
606 TXT("   ----------------------------------------")
607 _NL
608
609 CND(Need_Netdb_Buffer, "Need buffer for Netdb ops")
610
611 #ifdef __vxworks
612 _NL
613 TXT("   --------------------------------")
614 TXT("   -- VxWorks-specific constants --")
615 TXT("   --------------------------------")
616 _NL
617 TXT("   --  These constants may be used only within the VxWorks version of")
618 TXT("   --  GNAT.Sockets.Thin.")
619 _NL
620
621 CND(OK,    "VxWorks generic success")
622 CND(ERROR, "VxWorks generic error")
623 #endif
624
625 #ifdef __MINGW32__
626 _NL
627 TXT("   ------------------------------")
628 TXT("   -- MinGW-specific constants --")
629 TXT("   ------------------------------")
630 _NL
631 TXT("   --  These constants may be used only within the MinGW version of")
632 TXT("   --  GNAT.Sockets.Thin.")
633 _NL
634
635 CND(WSASYSNOTREADY,     "System not ready")
636 CND(WSAVERNOTSUPPORTED, "Version not supported")
637 CND(WSANOTINITIALISED,  "Winsock not intialized")
638 CND(WSAEDISCON,         "Disconnected")
639
640 #endif
641
642 _NL
643 TXT("   ----------------------")
644 TXT("   -- Additional flags --")
645 TXT("   ----------------------")
646 _NL
647 TXT("   Thread_Blocking_IO : constant Boolean := True;")
648 TXT("   --  Set False for contexts where socket i/o are process blocking")
649
650 _NL
651 TXT("end GNAT.Sockets.Constants;")
652
653   output ();
654   return 0;
655 }
656
657 void
658 output (void) {
659   int text_max = 0, value_max = 0, l;
660   struct line *p;
661   char fmt[64];
662 #define UPD_MAX(x) do { \
663   l = strlen (p->x); \
664   if (l > x ## _max) x ## _max = l; \
665 } while (0)
666
667   for (p = first; p != NULL; p = p->next) {
668     if (p->value != NULL) {
669       UPD_MAX(text);
670       UPD_MAX(value);
671     }
672   }
673   sprintf (fmt, "   %%-%ds : constant := %%%ds;%%s%%s\n",
674     text_max, value_max);
675
676   for (p = first; p != NULL; p = p->next) {
677     if (p->value == NULL) {
678       printf ("%s\n", p->text);
679     } else {
680       char *comment_sep = (strlen (p->comment) > 0)
681                           ? " --  " : "";
682       printf (fmt, p->text, p->value, comment_sep, p->comment);
683     }
684   }
685 }
686
687 char *
688 f_itoa (char *fmt, int n) {
689   char buf[32], *ret;
690   sprintf (buf, fmt, n);
691   ret = malloc (strlen (buf) + 1);
692   if (ret != NULL)
693     strcpy (ret, buf);
694   return ret;
695 }
696
697 void
698 add_line (char *_text, char *_value, char *_comment) {
699   struct line *l = (struct line *) malloc (sizeof (struct line));
700
701   l->text = _text;
702   l->value = _value;
703   l->comment = _comment;
704   l->next = NULL;
705   if (last == NULL)
706     first = last = l;
707   else {
708     last->next = l;
709     last = l;
710   }
711 }