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