0.7.10.21:
[sbcl/lichteblau.git] / tools-for-build / grovel_headers.c
blob0184bfaef202804691c7d3a9c222ac97e6b31e3f
1 /*
2 * Rummage through the system header files using the C compiler itself
3 * as a parser, extracting stuff like preprocessor constants and the
4 * sizes and signedness of basic system types, and write it out as
5 * Lisp code.
6 */
8 /*
9 * This software is part of the SBCL system. See the README file for
10 * more information.
12 * While most of SBCL is derived from the CMU CL system, many
13 * utilities for the build process (like this one) were written from
14 * scratch after the fork from CMU CL.
16 * This software is in the public domain and is provided with
17 * absolutely no warranty. See the COPYING and CREDITS files for
18 * more information.
21 #include <stdio.h>
22 #include <sys/types.h>
23 #include <sys/times.h>
24 #include <sys/stat.h>
25 #include <sys/wait.h>
26 #include <sys/ioctl.h>
27 #include <sys/termios.h>
28 #include <fcntl.h>
29 #include <unistd.h>
31 #define DEFTYPE(lispname,cname) { cname foo; \
32 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
34 void
35 defconstant(char* lisp_name, long unix_number)
37 printf("(defconstant %s %ld) ; #x%lx\n",
38 lisp_name, unix_number, unix_number);
41 int
42 main(int argc, char *argv[])
44 /* don't need no steenking command line arguments */
45 if (1 != argc) {
46 fprintf(stderr, "argh! command line argument(s)\n");
47 exit(1);
50 /* don't need no steenking hand-editing */
51 printf(
52 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
53 ;;;; See the program \"grovel_headers.c\".\n\
54 \n\
55 ");
57 printf("(in-package \"SB!UNIX\")\n\n");
59 printf(";;; types, types, types\n");
60 DEFTYPE("clock-t", clock_t);
61 DEFTYPE("dev-t", dev_t);
62 DEFTYPE("gid-t", gid_t);
63 DEFTYPE("ino-t", ino_t);
64 DEFTYPE("mode-t", mode_t);
65 DEFTYPE("nlink-t", nlink_t);
66 DEFTYPE("off-t", off_t);
67 DEFTYPE("size-t", size_t);
68 DEFTYPE("time-t", time_t);
69 DEFTYPE("uid-t", uid_t);
70 printf("\n");
72 printf(";;; fcntl.h (or unistd.h on OpenBSD)\n");
73 defconstant("r_ok", R_OK);
74 defconstant("w_ok", W_OK);
75 defconstant("x_ok", X_OK);
76 defconstant("f_ok", F_OK);
77 printf("\n");
79 printf(";;; fcntlbits.h\n");
80 defconstant("o_rdonly", O_RDONLY);
81 defconstant("o_wronly", O_WRONLY);
82 defconstant("o_rdwr", O_RDWR);
83 defconstant("o_accmode", O_ACCMODE);
84 defconstant("o_creat", O_CREAT);
85 defconstant("o_excl", O_EXCL);
86 defconstant("o_noctty", O_NOCTTY);
87 defconstant("o_trunc", O_TRUNC);
88 defconstant("o_append", O_APPEND);
89 printf(";;;\n");
90 defconstant("s-ifmt", S_IFMT);
91 defconstant("s-ififo", S_IFIFO);
92 defconstant("s-ifchr", S_IFCHR);
93 defconstant("s-ifdir", S_IFDIR);
94 defconstant("s-ifblk", S_IFBLK);
95 defconstant("s-ifreg", S_IFREG);
96 printf("\n");
98 defconstant("s-iflnk", S_IFLNK);
99 defconstant("s-ifsock", S_IFSOCK);
100 printf("\n");
102 printf(";;; for wait3(2) in run-program.lisp\n");
103 defconstant("wnohang", WNOHANG);
104 defconstant("wuntraced", WUNTRACED);
105 printf("\n");
107 printf(";;; various ioctl(2) flags\n");
108 defconstant("tiocnotty", TIOCNOTTY);
109 defconstant("tiocgwinsz", TIOCGWINSZ);
110 defconstant("tiocswinsz", TIOCSWINSZ);
111 defconstant("tiocgpgrp", TIOCGPGRP);
112 defconstant("tiocspgrp", TIOCSPGRP);
113 /* KLUDGE: These are referenced by old CMUCL-derived code, but
114 * Linux doesn't define them.
116 * I think these are the BSD names, but I don't know what the
117 * corresponding SysV/Linux names are. As a point of reference,
118 * CMUCL doesn't have these defined either (although the defining
119 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
120 * so bad about not hunting them down. Insight into renamed
121 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
123 * I note that the first one I grepped for, TIOCSIGSEND, is
124 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
125 * Oxbridge know more about things like that? And even if they
126 * don't, one benefit of the Rhodes crusade to heal the worthy
127 * ports should be that afterwards, if we grep for something like
128 * this in CVS and it's not there, we can lightheartedly nuke it.
129 * -- WHN 2002-08-30 */
131 defconstant("tiocsigsend", TIOCSIGSEND);
132 defconstant("tiocflush", TIOCFLUSH);
133 defconstant("tiocgetp", TIOCGETP);
134 defconstant("tiocsetp", TIOCSETP);
135 defconstant("tiocgetc", TIOCGETC);
136 defconstant("tiocsetc", TIOCSETC);
137 defconstant("tiocgltc", TIOCGLTC);
138 defconstant("tiocsltc", TIOCSLTC);
140 printf("\n");
142 return 0;