xref: /original-bsd/usr.sbin/config/main.c (revision 0b685140)
1 /*
2  * main.c	1.4	81/03/09
3  * Config
4  *	Do system configuration for VAX/UNIX
5  *		1) Build system data structures
6  *		2) Build makefile
7  *		3) Create header files for devices
8  *	Michael Toy -- Berkeley -- 1981
9  */
10 
11 #include <stdio.h>
12 #include <ctype.h>
13 #include "y.tab.h"
14 #include "config.h"
15 
16 main(argc, argv)
17 int argc;
18 char **argv;
19 {
20     if (argc != 2)
21     {
22 	fprintf(stderr, "usage: config <sysname>\n");
23 	exit(1);
24     }
25     PREFIX = argv[1];
26     if (freopen(argv[1], "r", stdin) == NULL)
27     {
28 	perror(argv[1]);
29 	exit(2);
30     }
31     dtab = NULL;
32     if (yyparse())
33 	exit(3);
34     else
35     {
36 	ioconf();			/* Print ioconf.c */
37 	ubglue();			/* Create ubglue.s */
38 	makefile();			/* build Makefile */
39 	headers();			/* make a lot of .h files */
40 	printf("Don't forget to run \"make depend\"\n");
41     }
42 }
43 
44 /*
45  * get_word
46  *	returns EOF on end of file
47  *	NULL on end of line
48  *	pointer to the word otherwise
49  */
50 
51 char *get_word(fp)
52 register FILE *fp;
53 {
54     static char line[80];
55     register int ch;
56     register char *cp;
57 
58     while((ch = getc(fp)) != EOF)
59 	if (ch != ' ' && ch != '\t')
60 	    break;
61     if (ch == EOF)
62 	return EOF;
63     if (ch == '\n')
64 	return NULL;
65     cp = line;
66     *cp++ = ch;
67     while((ch = getc(fp)) != EOF)
68     {
69 	if (isspace(ch))
70 	    break;
71 	*cp++ = ch;
72     }
73     *cp = '\0';
74     if (ch == EOF)
75 	return EOF;
76     ungetc(ch, fp);
77     return line;
78 }
79 
80 /*
81  * path:
82  *	Prepend the path to a filename
83  */
84 
85 path(file)
86 char *file;
87 {
88     register char *cp;
89 
90     cp = malloc(strlen(PREFIX)+strlen(file)+5);
91     strcpy(cp, "../");
92     strcat(cp, PREFIX);
93     strcat(cp, "/");
94     strcat(cp, file);
95     return cp;
96 }
97