xref: /csrg-svn/usr.sbin/config/main.c (revision 2682)
12653Stoy /*
2*2682Stoy  * main.c	1.2	81/02/25
32653Stoy  * Config
42653Stoy  *	Do system configuration for VAX/UNIX
52653Stoy  *		1) Build system data structures
62653Stoy  *		2) Build makefile
72653Stoy  *		3) Create header files for devices
82653Stoy  *	Michael Toy -- Berkeley -- 1981
92653Stoy  */
102653Stoy 
112653Stoy #include <stdio.h>
122653Stoy #include <ctype.h>
132653Stoy #include "y.tab.h"
142653Stoy #include "config.h"
152653Stoy 
162653Stoy main(argc, argv)
172653Stoy int argc;
182653Stoy char **argv;
192653Stoy {
202653Stoy     if (argc != 2)
212653Stoy     {
222653Stoy 	fprintf(stderr, "usage: config <sysname>\n");
232653Stoy 	exit(1);
242653Stoy     }
25*2682Stoy     PREFIX = argv[1];
262653Stoy     if (freopen(argv[1], "r", stdin) == NULL)
272653Stoy     {
282653Stoy 	perror(argv[1]);
292653Stoy 	exit(2);
302653Stoy     }
312653Stoy     dtab = NULL;
322653Stoy     if (yyparse())
332653Stoy 	exit(3);
342653Stoy     else
352653Stoy     {
362653Stoy 	ioconf();			/* Print ioconf.c */
372653Stoy 	ubglue();			/* Create ubglue.s */
382653Stoy 	makefile();			/* build Makefile */
392653Stoy 	headers();			/* make a lot of .h files */
402653Stoy     }
412653Stoy }
422653Stoy 
432653Stoy /*
442653Stoy  * get_word
452653Stoy  *	returns EOF on end of file
462653Stoy  *	NULL on end of line
472653Stoy  *	pointer to the word otherwise
482653Stoy  */
492653Stoy 
502653Stoy char *get_word(fp)
512653Stoy register FILE *fp;
522653Stoy {
532653Stoy     static char line[80];
542653Stoy     register int ch;
552653Stoy     register char *cp;
562653Stoy 
572653Stoy     while((ch = getc(fp)) != EOF)
582653Stoy 	if (ch != ' ' && ch != '\t')
592653Stoy 	    break;
602653Stoy     if (ch == EOF)
612653Stoy 	return EOF;
622653Stoy     if (ch == '\n')
632653Stoy 	return NULL;
642653Stoy     cp = line;
652653Stoy     *cp++ = ch;
662653Stoy     while((ch = getc(fp)) != EOF)
672653Stoy     {
682653Stoy 	if (isspace(ch))
692653Stoy 	    break;
702653Stoy 	*cp++ = ch;
712653Stoy     }
722653Stoy     *cp = '\0';
732653Stoy     if (ch == EOF)
742653Stoy 	return EOF;
752653Stoy     ungetc(ch, fp);
762653Stoy     return line;
772653Stoy }
78*2682Stoy 
79*2682Stoy /*
80*2682Stoy  * path:
81*2682Stoy  *	Prepend the path to a filename
82*2682Stoy  */
83*2682Stoy 
84*2682Stoy path(file)
85*2682Stoy char *file;
86*2682Stoy {
87*2682Stoy     register char *cp;
88*2682Stoy 
89*2682Stoy     cp = malloc(strlen(PREFIX)+strlen(file)+1);
90*2682Stoy     strcpy(cp, PREFIX);
91*2682Stoy     strcpy(cp, file);
92*2682Stoy     return cp;
93*2682Stoy }
94