1*8892Sroot /* main.c 1.6 82/10/24 */ 22653Stoy 32653Stoy #include <stdio.h> 42653Stoy #include <ctype.h> 52653Stoy #include "y.tab.h" 62653Stoy #include "config.h" 72653Stoy 8*8892Sroot /* 9*8892Sroot * Config builds a set of files for building a UNIX 10*8892Sroot * system given a description of the desired system. 11*8892Sroot */ 122653Stoy main(argc, argv) 13*8892Sroot int argc; 14*8892Sroot char **argv; 152653Stoy { 16*8892Sroot 17*8892Sroot if (argc != 2) { 18*8892Sroot fprintf(stderr, "usage: config sysname\n"); 19*8892Sroot exit(1); 20*8892Sroot } 21*8892Sroot PREFIX = argv[1]; 22*8892Sroot if (freopen(argv[1], "r", stdin) == NULL) { 23*8892Sroot perror(argv[1]); 24*8892Sroot exit(2); 25*8892Sroot } 26*8892Sroot dtab = NULL; 27*8892Sroot if (yyparse()) 28*8892Sroot exit(3); 29*8892Sroot switch (machine) { 30*8892Sroot 31*8892Sroot case MACHINE_VAX: 32*8892Sroot vax_ioconf(); /* Print ioconf.c */ 33*8892Sroot ubglue(); /* Create ubglue.s */ 34*8892Sroot break; 35*8892Sroot 36*8892Sroot case MACHINE_SUN: 37*8892Sroot sun_ioconf(); 38*8892Sroot break; 39*8892Sroot 40*8892Sroot default: 41*8892Sroot printf("Specify machine type, e.g. ``machine vax''\n"); 42*8892Sroot exit(1); 43*8892Sroot } 442653Stoy makefile(); /* build Makefile */ 452653Stoy headers(); /* make a lot of .h files */ 463156Stoy printf("Don't forget to run \"make depend\"\n"); 472653Stoy } 482653Stoy 492653Stoy /* 502653Stoy * get_word 512653Stoy * returns EOF on end of file 522653Stoy * NULL on end of line 532653Stoy * pointer to the word otherwise 542653Stoy */ 55*8892Sroot char * 56*8892Sroot get_word(fp) 57*8892Sroot register FILE *fp; 582653Stoy { 59*8892Sroot static char line[80]; 60*8892Sroot register int ch; 61*8892Sroot register char *cp; 622653Stoy 63*8892Sroot while ((ch = getc(fp)) != EOF) 64*8892Sroot if (ch != ' ' && ch != '\t') 65*8892Sroot break; 66*8892Sroot if (ch == EOF) 67*8892Sroot return (EOF); 68*8892Sroot if (ch == '\n') 69*8892Sroot return (NULL); 70*8892Sroot cp = line; 712653Stoy *cp++ = ch; 72*8892Sroot while ((ch = getc(fp)) != EOF) { 73*8892Sroot if (isspace(ch)) 74*8892Sroot break; 75*8892Sroot *cp++ = ch; 76*8892Sroot } 77*8892Sroot *cp = 0; 78*8892Sroot if (ch == EOF) 79*8892Sroot return (EOF); 80*8892Sroot ungetc(ch, fp); 81*8892Sroot return (line); 822653Stoy } 832682Stoy 842682Stoy /* 85*8892Sroot * prepend the path to a filename 862682Stoy */ 872682Stoy path(file) 88*8892Sroot char *file; 892682Stoy { 90*8892Sroot register char *cp; 912682Stoy 92*8892Sroot cp = malloc(strlen(PREFIX)+strlen(file)+5); 93*8892Sroot strcpy(cp, "../"); 94*8892Sroot strcat(cp, PREFIX); 95*8892Sroot strcat(cp, "/"); 96*8892Sroot strcat(cp, file); 97*8892Sroot return (cp); 982682Stoy } 99