4c6831f5924e82f0ddf4e0db5d2d1656e68d06fe
[sbcl.git] / tools-for-build / grovel_headers.c
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  */
7
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <sys/times.h>
11 #include <sys/stat.h>
12 #include <fcntl.h>
13
14 #define DEFTYPE(lispname,cname) { cname foo; \
15     printf("(def-alien-type "##lispname##" (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
16
17 void
18 defconstant(char* lisp_name, long unix_number)
19 {
20     printf("(defconstant %s %ld) ; #x%lx\n",
21            lisp_name, unix_number, unix_number);
22 }
23
24 int
25 main(int argc, char *argv[])
26 {
27     /* don't need no steenking command line arguments */
28     if (1 != argc) {
29         fprintf(stderr, "argh! command line argument(s)\n");
30         exit(1);
31     }
32
33     /* don't need no steenking hand-editing */
34     printf(
35 ";;;; This is an automatically generated file, please do not hand-edit it.
36 ;;;; See the program \"grovel_headers.c\".
37
38 ");
39
40     printf("(in-package \"SB!UNIX\")\n\n");
41
42     printf(";;; types, types, types\n");
43     DEFTYPE("dev-t",   dev_t);
44     DEFTYPE("ino-t",   ino_t);
45     DEFTYPE("mode-t",  mode_t);
46     DEFTYPE("nlink-t", nlink_t);
47     DEFTYPE("uid-t",   uid_t);
48     DEFTYPE("gid-t",   gid_t);
49     DEFTYPE("clock-t", clock_t);
50     DEFTYPE("off-t",   off_t);
51     DEFTYPE("time-t",  time_t);
52     printf("\n");
53
54     printf(";;; fcntl.h\n");
55     defconstant("r_ok", R_OK);
56     defconstant("w_ok", W_OK);
57     defconstant("x_ok", X_OK);
58     defconstant("f_ok", F_OK);
59     printf("\n");
60
61     printf(";;; fcntlbits.h\n");
62     defconstant("o_rdonly",  O_RDONLY);
63     defconstant("o_wronly",  O_WRONLY);
64     defconstant("o_rdwr",    O_RDWR);
65     defconstant("o_accmode", O_ACCMODE);
66     defconstant("o_creat",   O_CREAT);
67     defconstant("o_excl",    O_EXCL);
68     defconstant("o_noctty",  O_NOCTTY);
69     defconstant("o_trunc",   O_TRUNC);
70     defconstant("o_append",  O_APPEND);
71     printf(";;;\n");
72     defconstant( "s-ifmt",  S_IFMT);
73     defconstant( "s-ififo", S_IFIFO);
74     defconstant( "s-ifchr", S_IFCHR);
75     defconstant( "s-ifdir", S_IFDIR);
76     defconstant( "s-ifblk", S_IFBLK);
77     defconstant( "s-ifreg", S_IFREG);
78     printf("\n");
79   
80     defconstant( "s-iflnk",  S_IFLNK);
81     defconstant( "s-ifsock", S_IFSOCK);
82     printf("\n");
83
84     return 0;
85 }