Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / build-support / grovel.c
blobdb16aa9bca3493e9e84498f5b0659e5176d5b4ba
1 #include <stdio.h>
2 #include <sys/event.h>
4 #if defined(__FreeBSD__)
5 #define BSD
6 #define FREEBSD
7 #define UNIX
8 #endif
10 #if defined(__NetBSD__)
11 #define BSD
12 #define NETBSD
13 #define UNIX
14 #endif
16 #if defined(__OpenBSD__)
17 #define BSD
18 #define OPENBSD
19 #define UNIX
20 #endif
22 #if defined(__APPLE__)
23 #define BSD
24 #define MACOSX
25 #define UNIX
26 #endif
28 #if defined(linux)
29 #define LINUX
30 #define UNIX
31 #endif
33 #if defined(__amd64__) || defined(__x86_64__)
34 #define BIT64
35 #else
36 #define BIT32
37 #endif
39 #if defined(UNIX)
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <sys/socket.h>
43 #include <sys/errno.h>
44 #include <sys/mman.h>
45 #include <sys/syslimits.h>
46 #include <fcntl.h>
47 #include <unistd.h>
48 #endif
50 #define BL printf(" ");
51 #define QUOT printf("\"");
52 #define NL printf("\n");
53 #define LB printf("{"); BL
54 #define RB BL printf("}");
55 #define SEMI printf(";");
56 #define grovel(t) printf("TYPEDEF: "); printf("%d", sizeof(t)); BL printf(#t); NL
57 #define grovel2impl(t,n) BL BL BL BL LB QUOT printf(#t); QUOT BL QUOT printf((n)); QUOT RB
58 #define grovel2(t,n) grovel2impl(t,n) NL
59 #define grovel2end(t,n) grovel2impl(t,n) BL SEMI NL
60 #define header(os) printf("vvv %s vvv", (os)); NL
61 #define footer(os) printf("^^^ %s ^^^", (os)); NL
62 #define header2(os,struct) printf("vvv %s %s vvv", (os), (struct)); NL
63 #define footer2(os,struct) printf("^^^ %s %s ^^^", (os), (struct)); NL
64 #define struct(n) printf("C-STRUCT: %s\n", (n));
65 #define constant(n) printf("#define "); printf(#n); printf(" %d (HEX: %04x)", (n), (n)); NL
67 void openbsd_types()
69 header2("openbsd", "types");
70 grovel(dev_t);
71 grovel(gid_t);
72 grovel(ino_t);
73 grovel(int32_t);
74 grovel(int64_t);
75 grovel(mode_t);
76 grovel(nlink_t);
77 grovel(off_t);
78 grovel(struct timespec);
79 grovel(uid_t);
80 footer2("openbsd", "types");
83 void openbsd_stat()
85 header2("openbsd", "stat");
86 struct("stat");
87 grovel2(dev_t, "st_dev");
88 grovel2(ino_t, "st_ino");
89 grovel2(mode_t, "st_mode");
90 grovel2(nlink_t, "st_nlink");
91 grovel2(uid_t, "st_uid");
92 grovel2(gid_t, "st_gid");
93 grovel2(dev_t, "st_rdev");
94 grovel2(int32_t, "st_lspare0");
95 grovel2(struct timespec, "st_atim");
96 grovel2(struct timespec, "st_mtim");
97 grovel2(struct timespec, "st_ctim");
98 grovel2(off_t, "st_size");
99 grovel2(int64_t, "st_blocks");
100 grovel2(u_int32_t, "st_blksize");
101 grovel2(u_int32_t, "st_flags");
102 grovel2(u_int32_t, "st_gen");
103 grovel2(int32_t, "st_lspare1");
104 grovel2(struct timespec, "st_birthtimespec");
105 grovel2(int64_t, "st_qspare1");
106 grovel2end(int64_t, "st_qspare2");
107 footer2("openbsd", "stat");
110 void unix_types()
112 grovel(dev_t);
113 grovel(gid_t);
114 grovel(ino_t);
115 grovel(int32_t);
116 grovel(int64_t);
117 grovel(mode_t);
118 grovel(nlink_t);
119 grovel(off_t);
120 grovel(struct timespec);
121 grovel(struct stat);
122 grovel(time_t);
123 grovel(uid_t);
126 void unix_constants()
128 constant(O_RDONLY);
129 constant(O_WRONLY);
130 constant(O_RDWR);
131 constant(O_APPEND);
132 constant(O_CREAT);
133 constant(O_TRUNC);
134 constant(O_EXCL);
135 constant(FD_SETSIZE);
136 constant(SOL_SOCKET);
137 constant(SO_REUSEADDR);
138 constant(SO_OOBINLINE);
139 constant(SO_SNDTIMEO);
140 constant(SO_RCVTIMEO);
141 constant(F_SETFL);
142 constant(O_NONBLOCK);
143 constant(EINTR);
144 constant(EAGAIN);
145 constant(EINPROGRESS);
146 constant(PROT_READ);
147 constant(PROT_WRITE);
148 constant(MAP_FILE);
149 constant(MAP_SHARED);
150 constant(PATH_MAX);
151 grovel(pid_t);
155 int main() {
156 #ifdef FREEBSD
157 grovel(blkcnt_t);
158 grovel(blksize_t);
159 grovel(fflags_t);
160 #endif
162 #ifdef OPENBSD
163 openbsd_stat();
164 openbsd_types();
165 #endif
166 grovel(blkcnt_t);
167 grovel(blksize_t);
168 //grovel(fflags_t);
169 grovel(ssize_t);
171 grovel(size_t);
172 grovel(struct kevent);
173 #ifdef UNIX
174 unix_types();
175 unix_constants();
176 #endif
178 return 0;