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