OSDN Git Service

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