1*12487Ssam /* main.c 1.9 83/05/18 */ 22653Stoy 32653Stoy #include <stdio.h> 42653Stoy #include <ctype.h> 52653Stoy #include "y.tab.h" 62653Stoy #include "config.h" 72653Stoy 88892Sroot /* 98892Sroot * Config builds a set of files for building a UNIX 108892Sroot * system given a description of the desired system. 118892Sroot */ 122653Stoy main(argc, argv) 138892Sroot int argc; 148892Sroot char **argv; 152653Stoy { 168892Sroot 179597Ssam if (argc > 1 && eq("-p", argv[1])) { 189597Ssam profiling++; 199597Ssam argc--, argv++; 209597Ssam } 218892Sroot if (argc != 2) { 229597Ssam fprintf(stderr, "usage: config [ -p ] sysname\n"); 238892Sroot exit(1); 248892Sroot } 258892Sroot PREFIX = argv[1]; 268892Sroot if (freopen(argv[1], "r", stdin) == NULL) { 278892Sroot perror(argv[1]); 288892Sroot exit(2); 298892Sroot } 308892Sroot dtab = NULL; 31*12487Ssam confp = &conf_list; 328892Sroot if (yyparse()) 338892Sroot exit(3); 348892Sroot switch (machine) { 358892Sroot 368892Sroot case MACHINE_VAX: 378892Sroot vax_ioconf(); /* Print ioconf.c */ 388892Sroot ubglue(); /* Create ubglue.s */ 398892Sroot break; 408892Sroot 418892Sroot case MACHINE_SUN: 428892Sroot sun_ioconf(); 438892Sroot break; 448892Sroot 458892Sroot default: 468892Sroot printf("Specify machine type, e.g. ``machine vax''\n"); 478892Sroot exit(1); 488892Sroot } 492653Stoy makefile(); /* build Makefile */ 502653Stoy headers(); /* make a lot of .h files */ 51*12487Ssam swapconf(); /* swap config files */ 523156Stoy printf("Don't forget to run \"make depend\"\n"); 532653Stoy } 542653Stoy 552653Stoy /* 562653Stoy * get_word 572653Stoy * returns EOF on end of file 582653Stoy * NULL on end of line 592653Stoy * pointer to the word otherwise 602653Stoy */ 618892Sroot char * 628892Sroot get_word(fp) 638892Sroot register FILE *fp; 642653Stoy { 658892Sroot static char line[80]; 668892Sroot register int ch; 678892Sroot register char *cp; 682653Stoy 698892Sroot while ((ch = getc(fp)) != EOF) 708892Sroot if (ch != ' ' && ch != '\t') 718892Sroot break; 728892Sroot if (ch == EOF) 738900Sroot return ((char *)EOF); 748892Sroot if (ch == '\n') 758892Sroot return (NULL); 768892Sroot cp = line; 772653Stoy *cp++ = ch; 788892Sroot while ((ch = getc(fp)) != EOF) { 798892Sroot if (isspace(ch)) 808892Sroot break; 818892Sroot *cp++ = ch; 828892Sroot } 838892Sroot *cp = 0; 848892Sroot if (ch == EOF) 858900Sroot return ((char *)EOF); 868900Sroot (void) ungetc(ch, fp); 878892Sroot return (line); 882653Stoy } 892682Stoy 902682Stoy /* 918892Sroot * prepend the path to a filename 922682Stoy */ 938900Sroot char * 942682Stoy path(file) 958892Sroot char *file; 962682Stoy { 978892Sroot register char *cp; 982682Stoy 998900Sroot cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5)); 1008900Sroot (void) strcpy(cp, "../"); 1018900Sroot (void) strcat(cp, PREFIX); 1028900Sroot (void) strcat(cp, "/"); 1038900Sroot (void) strcat(cp, file); 1048892Sroot return (cp); 1052682Stoy } 106