OSDN Git Service

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