xref: /csrg-svn/usr.sbin/config/main.c (revision 19987)
1*19987Sdist /*
2*19987Sdist  * Copyright (c) 1980 Regents of the University of California.
3*19987Sdist  * All rights reserved.  The Berkeley software License Agreement
4*19987Sdist  * specifies the terms and conditions for redistribution.
5*19987Sdist  */
6*19987Sdist 
714557Ssam #ifndef lint
8*19987Sdist char copyright[] =
9*19987Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10*19987Sdist  All rights reserved.\n";
11*19987Sdist #endif not lint
122653Stoy 
13*19987Sdist #ifndef lint
14*19987Sdist static char sccsid[] = "@(#)main.c	5.1 (Berkeley) 05/08/85";
15*19987Sdist #endif not lint
16*19987Sdist 
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 
558892Sroot 	case MACHINE_SUN:
568892Sroot 		sun_ioconf();
578892Sroot 		break;
588892Sroot 
598892Sroot 	default:
608892Sroot 		printf("Specify machine type, e.g. ``machine vax''\n");
618892Sroot 		exit(1);
628892Sroot 	}
632653Stoy 	makefile();			/* build Makefile */
642653Stoy 	headers();			/* make a lot of .h files */
6512487Ssam 	swapconf();			/* swap config files */
663156Stoy 	printf("Don't forget to run \"make depend\"\n");
672653Stoy }
682653Stoy 
692653Stoy /*
702653Stoy  * get_word
712653Stoy  *	returns EOF on end of file
722653Stoy  *	NULL on end of line
732653Stoy  *	pointer to the word otherwise
742653Stoy  */
758892Sroot char *
768892Sroot get_word(fp)
778892Sroot 	register FILE *fp;
782653Stoy {
798892Sroot 	static char line[80];
808892Sroot 	register int ch;
818892Sroot 	register char *cp;
822653Stoy 
838892Sroot 	while ((ch = getc(fp)) != EOF)
848892Sroot 		if (ch != ' ' && ch != '\t')
858892Sroot 			break;
868892Sroot 	if (ch == EOF)
878900Sroot 		return ((char *)EOF);
888892Sroot 	if (ch == '\n')
898892Sroot 		return (NULL);
908892Sroot 	cp = line;
912653Stoy 	*cp++ = ch;
928892Sroot 	while ((ch = getc(fp)) != EOF) {
938892Sroot 		if (isspace(ch))
948892Sroot 			break;
958892Sroot 		*cp++ = ch;
968892Sroot 	}
978892Sroot 	*cp = 0;
988892Sroot 	if (ch == EOF)
998900Sroot 		return ((char *)EOF);
1008900Sroot 	(void) ungetc(ch, fp);
1018892Sroot 	return (line);
1022653Stoy }
1032682Stoy 
1042682Stoy /*
1058892Sroot  * prepend the path to a filename
1062682Stoy  */
1078900Sroot char *
1082682Stoy path(file)
1098892Sroot 	char *file;
1102682Stoy {
1118892Sroot 	register char *cp;
1122682Stoy 
1138900Sroot 	cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
1148900Sroot 	(void) strcpy(cp, "../");
1158900Sroot 	(void) strcat(cp, PREFIX);
1168900Sroot 	(void) strcat(cp, "/");
1178900Sroot 	(void) strcat(cp, file);
1188892Sroot 	return (cp);
1192682Stoy }
120