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