]>
git.saurik.com Git - apple/xnu.git/blob - SETUP/config/mkheaders.c
e3d2f34acc3b599b452fabf44f216705f36596e0
2 * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Mach Operating System
26 * Copyright (c) 1990 Carnegie-Mellon University
27 * Copyright (c) 1989 Carnegie-Mellon University
28 * Copyright (c) 1988 Carnegie-Mellon University
29 * Copyright (c) 1987 Carnegie-Mellon University
30 * All rights reserved. The CMU software License Agreement specifies
31 * the terms and conditions for use and redistribution.
35 * Copyright (c) 1980 Regents of the University of California.
36 * All rights reserved.
38 * Redistribution and use in source and binary forms are permitted
39 * provided that the above copyright notice and this paragraph are
40 * duplicated in all such forms and that any documentation,
41 * advertising materials, and other materials related to such
42 * distribution and use acknowledge that the software was developed
43 * by the University of California, Berkeley. The name of the
44 * University may not be used to endorse or promote products derived
45 * from this software without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
48 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
52 static char sccsid
[] __attribute__((used
)) = "@(#)mkheaders.c 5.5 (Berkeley) 6/18/88";
56 * Make all the .h files for the optional entries
60 #include <unistd.h> /* unlink */
65 static void do_count(const char *dev
, const char *hname
, int search
);
66 static void do_header(const char *dev
, const char *hname
, int count
);
67 static char *toheader(const char *dev
);
68 static char *tomacro(const char *dev
);
75 for (fl
= ftab
; fl
!= 0; fl
= fl
->f_next
) {
76 if (fl
->f_needs
!= 0) {
77 do_count(fl
->f_needs
, fl
->f_needs
, 1);
83 * count all the devices of a certain type and recurse to count
84 * whatever the device is connected to
87 do_count(const char *dev
, const char *hname
, int search
)
92 for (count
= 0, dp
= dtab
; dp
!= 0; dp
= dp
->d_next
) {
93 if (eq(dp
->d_name
, dev
)) {
94 if (dp
->d_type
== PSEUDO_DEVICE
) {
96 dp
->d_slave
!= UNKNOWN
? dp
->d_slave
: 1;
104 do_header(dev
, hname
, count
);
108 do_header(const char *dev
, const char *hname
, int count
)
113 struct file_list
*fl
= NULL
; /* may exit for(;;) uninitted */
114 struct file_list
*fl_head
, *fl_prev
;
118 file
= toheader(hname
);
119 name
= tomacro(dev
?dev
:hname
) + (dev
== NULL
);
120 inf
= fopen(file
, "r");
124 outf
= fopen(file
, "w");
129 fprintf(outf
, "#define %s %d\n", name
, count
);
131 file
= path("meta_features.h");
132 outf
= fopen(file
, "a");
137 fprintf(outf
, "#include <%s.h>\n", hname
);
144 if ((inw
= get_word(inf
)) == 0 || inw
== (char *)EOF
) {
147 if ((inw
= get_word(inf
)) == 0 || inw
== (char *)EOF
) {
152 if (cp
== 0 || cp
== (char *)EOF
) {
156 if (eq(inwcopy
, name
)) {
161 if (cp
== (char *)EOF
) {
164 fl
= (struct file_list
*) malloc(sizeof *fl
);
167 fl
->f_next
= fl_head
;
171 if (count
== oldcount
) {
175 free((char *)fl_prev
);
179 if (oldcount
== -1) {
180 fl
= (struct file_list
*) malloc(sizeof *fl
);
183 fl
->f_next
= fl_head
;
187 outf
= fopen(file
, "w");
192 for (fl
= fl_head
; fl
!= 0; fl
= fl
->f_next
) {
193 fprintf(outf
, "#define %s %d\n",
194 fl
->f_fn
, count
? fl
->f_type
: 0);
201 * convert a dev name to a .h file name
204 toheader(const char *dev
)
206 static char hbuf
[MAXPATHLEN
];
207 (void) snprintf(hbuf
, sizeof hbuf
, "%s.h", path(dev
));
208 hbuf
[MAXPATHLEN
- 1] = '\0';
213 * convert a dev name to a macro name
216 tomacro(const char *dev
)
218 static char mbuf
[FILENAME_MAX
];
224 if (!islower(*dev
)) {
227 *cp
++ = toupper(*dev
++);