OSDN Git Service

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