4.2 distribution
[unix-history] / usr / src / usr.sbin / config / main.c
CommitLineData
36edb824 1/* main.c 1.9 83/05/18 */
ca5d0476
MT
2
3#include <stdio.h>
4#include <ctype.h>
5#include "y.tab.h"
6#include "config.h"
7
9995ca8d
BJ
8/*
9 * Config builds a set of files for building a UNIX
10 * system given a description of the desired system.
11 */
ca5d0476 12main(argc, argv)
9995ca8d
BJ
13 int argc;
14 char **argv;
ca5d0476 15{
9995ca8d 16
73845e07
SL
17 if (argc > 1 && eq("-p", argv[1])) {
18 profiling++;
19 argc--, argv++;
20 }
9995ca8d 21 if (argc != 2) {
73845e07 22 fprintf(stderr, "usage: config [ -p ] sysname\n");
9995ca8d
BJ
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;
36edb824 31 confp = &conf_list;
9995ca8d
BJ
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 }
ca5d0476
MT
49 makefile(); /* build Makefile */
50 headers(); /* make a lot of .h files */
36edb824 51 swapconf(); /* swap config files */
94e09492 52 printf("Don't forget to run \"make depend\"\n");
ca5d0476
MT
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 */
9995ca8d
BJ
61char *
62get_word(fp)
63 register FILE *fp;
ca5d0476 64{
9995ca8d
BJ
65 static char line[80];
66 register int ch;
67 register char *cp;
ca5d0476 68
9995ca8d
BJ
69 while ((ch = getc(fp)) != EOF)
70 if (ch != ' ' && ch != '\t')
71 break;
72 if (ch == EOF)
22d68ad0 73 return ((char *)EOF);
9995ca8d
BJ
74 if (ch == '\n')
75 return (NULL);
76 cp = line;
ca5d0476 77 *cp++ = ch;
9995ca8d
BJ
78 while ((ch = getc(fp)) != EOF) {
79 if (isspace(ch))
80 break;
81 *cp++ = ch;
82 }
83 *cp = 0;
84 if (ch == EOF)
22d68ad0
BJ
85 return ((char *)EOF);
86 (void) ungetc(ch, fp);
9995ca8d 87 return (line);
ca5d0476 88}
0a2de74e
MT
89
90/*
9995ca8d 91 * prepend the path to a filename
0a2de74e 92 */
22d68ad0 93char *
0a2de74e 94path(file)
9995ca8d 95 char *file;
0a2de74e 96{
9995ca8d 97 register char *cp;
0a2de74e 98
22d68ad0
BJ
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);
9995ca8d 104 return (cp);
0a2de74e 105}