xref: /xnu-10002.1.13/SETUP/config/mkioconf.c (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
1*1031c584SApple OSS Distributions /*
2*1031c584SApple OSS Distributions  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3*1031c584SApple OSS Distributions  *
4*1031c584SApple OSS Distributions  * @APPLE_LICENSE_HEADER_START@
5*1031c584SApple OSS Distributions  *
6*1031c584SApple OSS Distributions  * "Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
7*1031c584SApple OSS Distributions  * Reserved.  This file contains Original Code and/or Modifications of
8*1031c584SApple OSS Distributions  * Original Code as defined in and that are subject to the Apple Public
9*1031c584SApple OSS Distributions  * Source License Version 1.0 (the 'License').  You may not use this file
10*1031c584SApple OSS Distributions  * except in compliance with the License.  Please obtain a copy of the
11*1031c584SApple OSS Distributions  * License at http://www.apple.com/publicsource and read it before using
12*1031c584SApple OSS Distributions  * this file.
13*1031c584SApple OSS Distributions  *
14*1031c584SApple OSS Distributions  * The Original Code and all software distributed under the License are
15*1031c584SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16*1031c584SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17*1031c584SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18*1031c584SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
19*1031c584SApple OSS Distributions  * License for the specific language governing rights and limitations
20*1031c584SApple OSS Distributions  * under the License."
21*1031c584SApple OSS Distributions  *
22*1031c584SApple OSS Distributions  * @APPLE_LICENSE_HEADER_END@
23*1031c584SApple OSS Distributions  */
24*1031c584SApple OSS Distributions /*
25*1031c584SApple OSS Distributions  * Mach Operating System
26*1031c584SApple OSS Distributions  * Copyright (c) 1990 Carnegie-Mellon University
27*1031c584SApple OSS Distributions  * Copyright (c) 1989 Carnegie-Mellon University
28*1031c584SApple OSS Distributions  * Copyright (c) 1988 Carnegie-Mellon University
29*1031c584SApple OSS Distributions  * Copyright (c) 1987 Carnegie-Mellon University
30*1031c584SApple OSS Distributions  * All rights reserved.  The CMU software License Agreement specifies
31*1031c584SApple OSS Distributions  * the terms and conditions for use and redistribution.
32*1031c584SApple OSS Distributions  */
33*1031c584SApple OSS Distributions 
34*1031c584SApple OSS Distributions /*
35*1031c584SApple OSS Distributions  * Copyright (c) 1980 Regents of the University of California.
36*1031c584SApple OSS Distributions  * All rights reserved.
37*1031c584SApple OSS Distributions  *
38*1031c584SApple OSS Distributions  * Redistribution and use in source and binary forms are permitted
39*1031c584SApple OSS Distributions  * provided that the above copyright notice and this paragraph are
40*1031c584SApple OSS Distributions  * duplicated in all such forms and that any documentation,
41*1031c584SApple OSS Distributions  * advertising materials, and other materials related to such
42*1031c584SApple OSS Distributions  * distribution and use acknowledge that the software was developed
43*1031c584SApple OSS Distributions  * by the University of California, Berkeley.  The name of the
44*1031c584SApple OSS Distributions  * University may not be used to endorse or promote products derived
45*1031c584SApple OSS Distributions  * from this software without specific prior written permission.
46*1031c584SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
47*1031c584SApple OSS Distributions  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
48*1031c584SApple OSS Distributions  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
49*1031c584SApple OSS Distributions  */
50*1031c584SApple OSS Distributions 
51*1031c584SApple OSS Distributions #include <stdio.h>
52*1031c584SApple OSS Distributions #include <unistd.h>     /* for unlink */
53*1031c584SApple OSS Distributions #include "parser.h"
54*1031c584SApple OSS Distributions #include "config.h"
55*1031c584SApple OSS Distributions 
56*1031c584SApple OSS Distributions /*
57*1031c584SApple OSS Distributions  * build the ioconf.c file
58*1031c584SApple OSS Distributions  */
59*1031c584SApple OSS Distributions void    pseudo_inits(FILE *fp);
60*1031c584SApple OSS Distributions 
61*1031c584SApple OSS Distributions void
mkioconf(void)62*1031c584SApple OSS Distributions mkioconf(void)
63*1031c584SApple OSS Distributions {
64*1031c584SApple OSS Distributions 	FILE *fp;
65*1031c584SApple OSS Distributions 
66*1031c584SApple OSS Distributions 	unlink(path("ioconf.c"));
67*1031c584SApple OSS Distributions 	fp = fopen(path("ioconf.c"), "w");
68*1031c584SApple OSS Distributions 	if (fp == 0) {
69*1031c584SApple OSS Distributions 		perror(path("ioconf.c"));
70*1031c584SApple OSS Distributions 		exit(1);
71*1031c584SApple OSS Distributions 	}
72*1031c584SApple OSS Distributions 	fprintf(fp, "#include <dev/busvar.h>\n");
73*1031c584SApple OSS Distributions 	fprintf(fp, "\n");
74*1031c584SApple OSS Distributions 	pseudo_inits(fp);
75*1031c584SApple OSS Distributions 	(void) fclose(fp);
76*1031c584SApple OSS Distributions }
77*1031c584SApple OSS Distributions 
78*1031c584SApple OSS Distributions void
pseudo_inits(FILE * fp)79*1031c584SApple OSS Distributions pseudo_inits(FILE *fp)
80*1031c584SApple OSS Distributions {
81*1031c584SApple OSS Distributions 	struct device *dp;
82*1031c584SApple OSS Distributions 	int count;
83*1031c584SApple OSS Distributions 
84*1031c584SApple OSS Distributions 	fprintf(fp, "\n");
85*1031c584SApple OSS Distributions 	for (dp = dtab; dp != 0; dp = dp->d_next) {
86*1031c584SApple OSS Distributions 		if (dp->d_type != PSEUDO_DEVICE || dp->d_init == 0) {
87*1031c584SApple OSS Distributions 			continue;
88*1031c584SApple OSS Distributions 		}
89*1031c584SApple OSS Distributions 		fprintf(fp, "extern int %s(int);\n", dp->d_init);
90*1031c584SApple OSS Distributions 	}
91*1031c584SApple OSS Distributions 	fprintf(fp, "\nstruct pseudo_init pseudo_inits[] = {\n");
92*1031c584SApple OSS Distributions 	for (dp = dtab; dp != 0; dp = dp->d_next) {
93*1031c584SApple OSS Distributions 		if (dp->d_type != PSEUDO_DEVICE || dp->d_init == 0) {
94*1031c584SApple OSS Distributions 			continue;
95*1031c584SApple OSS Distributions 		}
96*1031c584SApple OSS Distributions 		count = dp->d_slave;
97*1031c584SApple OSS Distributions 		if (count <= 0) {
98*1031c584SApple OSS Distributions 			count = 1;
99*1031c584SApple OSS Distributions 		}
100*1031c584SApple OSS Distributions 		fprintf(fp, "\t{%d,\t%s},\n", count, dp->d_init);
101*1031c584SApple OSS Distributions 	}
102*1031c584SApple OSS Distributions 	fprintf(fp, "\t{0,\t0},\n};\n");
103*1031c584SApple OSS Distributions }
104