xref: /original-bsd/usr.sbin/config/main.c (revision 3708840b)
1 /*	main.c	1.9	83/05/18	*/
2 
3 #include <stdio.h>
4 #include <ctype.h>
5 #include "y.tab.h"
6 #include "config.h"
7 
8 /*
9  * Config builds a set of files for building a UNIX
10  * system given a description of the desired system.
11  */
12 main(argc, argv)
13 	int argc;
14 	char **argv;
15 {
16 
17 	if (argc > 1 && eq("-p", argv[1])) {
18 		profiling++;
19 		argc--, argv++;
20 	}
21 	if (argc != 2) {
22 		fprintf(stderr, "usage: config [ -p ] sysname\n");
23 		exit(1);
24 	}
25 	PREFIX = argv[1];
26 	if (freopen(argv[1], "r", stdin) == NULL) {
27 		perror(argv[1]);
28 		exit(2);
29 	}
30 	dtab = NULL;
31 	confp = &conf_list;
32 	if (yyparse())
33 		exit(3);
34 	switch (machine) {
35 
36 	case MACHINE_VAX:
37 		vax_ioconf();		/* Print ioconf.c */
38 		ubglue();		/* Create ubglue.s */
39 		break;
40 
41 	case MACHINE_SUN:
42 		sun_ioconf();
43 		break;
44 
45 	default:
46 		printf("Specify machine type, e.g. ``machine vax''\n");
47 		exit(1);
48 	}
49 	makefile();			/* build Makefile */
50 	headers();			/* make a lot of .h files */
51 	swapconf();			/* swap config files */
52 	printf("Don't forget to run \"make depend\"\n");
53 }
54 
55 /*
56  * get_word
57  *	returns EOF on end of file
58  *	NULL on end of line
59  *	pointer to the word otherwise
60  */
61 char *
62 get_word(fp)
63 	register FILE *fp;
64 {
65 	static char line[80];
66 	register int ch;
67 	register char *cp;
68 
69 	while ((ch = getc(fp)) != EOF)
70 		if (ch != ' ' && ch != '\t')
71 			break;
72 	if (ch == EOF)
73 		return ((char *)EOF);
74 	if (ch == '\n')
75 		return (NULL);
76 	cp = line;
77 	*cp++ = ch;
78 	while ((ch = getc(fp)) != EOF) {
79 		if (isspace(ch))
80 			break;
81 		*cp++ = ch;
82 	}
83 	*cp = 0;
84 	if (ch == EOF)
85 		return ((char *)EOF);
86 	(void) ungetc(ch, fp);
87 	return (line);
88 }
89 
90 /*
91  * prepend the path to a filename
92  */
93 char *
94 path(file)
95 	char *file;
96 {
97 	register char *cp;
98 
99 	cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
100 	(void) strcpy(cp, "../");
101 	(void) strcat(cp, PREFIX);
102 	(void) strcat(cp, "/");
103 	(void) strcat(cp, file);
104 	return (cp);
105 }
106