OSDN Git Service

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