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