xref: /csrg-svn/usr.sbin/config/main.c (revision 29841)
119987Sdist /*
219987Sdist  * Copyright (c) 1980 Regents of the University of California.
319987Sdist  * All rights reserved.  The Berkeley software License Agreement
419987Sdist  * specifies the terms and conditions for redistribution.
519987Sdist  */
619987Sdist 
714557Ssam #ifndef lint
819987Sdist char copyright[] =
919987Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1019987Sdist  All rights reserved.\n";
1119987Sdist #endif not lint
122653Stoy 
1319987Sdist #ifndef lint
14*29841Ssam static char sccsid[] = "@(#)main.c	5.3 (Berkeley) 10/13/86";
1519987Sdist #endif not lint
1619987Sdist 
172653Stoy #include <stdio.h>
182653Stoy #include <ctype.h>
192653Stoy #include "y.tab.h"
202653Stoy #include "config.h"
212653Stoy 
228892Sroot /*
238892Sroot  * Config builds a set of files for building a UNIX
248892Sroot  * system given a description of the desired system.
258892Sroot  */
262653Stoy main(argc, argv)
278892Sroot 	int argc;
288892Sroot 	char **argv;
292653Stoy {
308892Sroot 
319597Ssam 	if (argc > 1 && eq("-p", argv[1])) {
329597Ssam 		profiling++;
339597Ssam 		argc--, argv++;
349597Ssam 	}
358892Sroot 	if (argc != 2) {
369597Ssam 		fprintf(stderr, "usage: config [ -p ] sysname\n");
378892Sroot 		exit(1);
388892Sroot 	}
398892Sroot 	PREFIX = argv[1];
408892Sroot 	if (freopen(argv[1], "r", stdin) == NULL) {
418892Sroot 		perror(argv[1]);
428892Sroot 		exit(2);
438892Sroot 	}
448892Sroot 	dtab = NULL;
4512487Ssam 	confp = &conf_list;
468892Sroot 	if (yyparse())
478892Sroot 		exit(3);
488892Sroot 	switch (machine) {
498892Sroot 
508892Sroot 	case MACHINE_VAX:
518892Sroot 		vax_ioconf();		/* Print ioconf.c */
528892Sroot 		ubglue();		/* Create ubglue.s */
538892Sroot 		break;
548892Sroot 
55*29841Ssam 	case MACHINE_TAHOE:
56*29841Ssam 		tahoe_ioconf();
57*29841Ssam 		vbglue();
588892Sroot 		break;
598892Sroot 
608892Sroot 	default:
618892Sroot 		printf("Specify machine type, e.g. ``machine vax''\n");
628892Sroot 		exit(1);
638892Sroot 	}
6425844Slepreau 	symlink("../h", path("sys"));	/* make genassym.c work */
652653Stoy 	makefile();			/* build Makefile */
662653Stoy 	headers();			/* make a lot of .h files */
6712487Ssam 	swapconf();			/* swap config files */
683156Stoy 	printf("Don't forget to run \"make depend\"\n");
692653Stoy }
702653Stoy 
712653Stoy /*
722653Stoy  * get_word
732653Stoy  *	returns EOF on end of file
742653Stoy  *	NULL on end of line
752653Stoy  *	pointer to the word otherwise
762653Stoy  */
778892Sroot char *
788892Sroot get_word(fp)
798892Sroot 	register FILE *fp;
802653Stoy {
818892Sroot 	static char line[80];
828892Sroot 	register int ch;
838892Sroot 	register char *cp;
842653Stoy 
858892Sroot 	while ((ch = getc(fp)) != EOF)
868892Sroot 		if (ch != ' ' && ch != '\t')
878892Sroot 			break;
888892Sroot 	if (ch == EOF)
898900Sroot 		return ((char *)EOF);
908892Sroot 	if (ch == '\n')
918892Sroot 		return (NULL);
928892Sroot 	cp = line;
932653Stoy 	*cp++ = ch;
948892Sroot 	while ((ch = getc(fp)) != EOF) {
958892Sroot 		if (isspace(ch))
968892Sroot 			break;
978892Sroot 		*cp++ = ch;
988892Sroot 	}
998892Sroot 	*cp = 0;
1008892Sroot 	if (ch == EOF)
1018900Sroot 		return ((char *)EOF);
1028900Sroot 	(void) ungetc(ch, fp);
1038892Sroot 	return (line);
1042653Stoy }
1052682Stoy 
1062682Stoy /*
1078892Sroot  * prepend the path to a filename
1082682Stoy  */
1098900Sroot char *
1102682Stoy path(file)
1118892Sroot 	char *file;
1122682Stoy {
1138892Sroot 	register char *cp;
1142682Stoy 
1158900Sroot 	cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
1168900Sroot 	(void) strcpy(cp, "../");
1178900Sroot 	(void) strcat(cp, PREFIX);
1188900Sroot 	(void) strcat(cp, "/");
1198900Sroot 	(void) strcat(cp, file);
1208892Sroot 	return (cp);
1212682Stoy }
122