install correct aliases file
[unix-history] / usr / src / usr.sbin / config / main.c
index de296d8..be2966f 100644 (file)
 /*
 /*
- * main.c      1.4     81/03/09
- * Config
- *     Do system configuration for VAX/UNIX
- *             1) Build system data structures
- *             2) Build makefile
- *             3) Create header files for devices
- *     Michael Toy -- Berkeley -- 1981
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c     5.9 (Berkeley) %G%";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
 #include <stdio.h>
 #include <ctype.h>
 #include "y.tab.h"
 #include "config.h"
 
 #include <stdio.h>
 #include <ctype.h>
 #include "y.tab.h"
 #include "config.h"
 
+static char *PREFIX;
+
+/*
+ * Config builds a set of files for building a UNIX
+ * system given a description of the desired system.
+ */
 main(argc, argv)
 main(argc, argv)
-int argc;
-char **argv;
+       int argc;
+       char **argv;
 {
 {
-    if (argc != 2)
-    {
-       fprintf(stderr, "usage: config <sysname>\n");
-       exit(1);
-    }
-    PREFIX = argv[1];
-    if (freopen(argv[1], "r", stdin) == NULL)
-    {
-       perror(argv[1]);
-       exit(2);
-    }
-    dtab = NULL;
-    if (yyparse())
-       exit(3);
-    else
-    {
-       ioconf();                       /* Print ioconf.c */
-       ubglue();                       /* Create ubglue.s */
+
+       extern char *optarg;
+       extern int optind;
+       struct stat buf;
+       int ch;
+       char *p;
+
+       while ((ch = getopt(argc, argv, "p")) != EOF)
+               switch((char)ch) {
+               case 'p':
+                       profiling++;
+                       break;
+               case '?':
+               default:
+                       goto usage;
+               }
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 1) {
+usage:         fputs("usage: config [-p] sysname\n", stderr);
+               exit(1);
+       }
+
+       if (freopen(PREFIX = *argv, "r", stdin) == NULL) {
+               perror(PREFIX);
+               exit(2);
+       }
+       if (stat(p = path((char *)NULL), &buf)) {
+               if (mkdir(p, 0755)) {
+                       perror(p);
+                       exit(2);
+               }
+       }
+       else if ((buf.st_mode & S_IFMT) != S_IFDIR) {
+               fprintf(stderr, "config: %s isn't a directory.\n", p);
+               exit(2);
+       }
+
+       dtab = NULL;
+       confp = &conf_list;
+       if (yyparse())
+               exit(3);
+       switch (machine) {
+
+       case MACHINE_VAX:
+               vax_ioconf();           /* Print ioconf.c */
+               ubglue();               /* Create ubglue.s */
+               break;
+
+       case MACHINE_TAHOE:
+               tahoe_ioconf();
+               vbglue();
+               break;
+
+       default:
+               printf("Specify machine type, e.g. ``machine vax''\n");
+               exit(1);
+       }
+       /*
+        * make symbolic links in compilation directory
+        * for "sys" (to make genassym.c work along with #include <sys/xxx>)
+        * and similarly for "machine".
+        */
+       {
+       char xxx[80];
+
+       (void) symlink("../h", path("sys"));
+       (void) sprintf(xxx, "../%s", machinename);
+       (void) symlink(xxx, path("machine"));
+       }
        makefile();                     /* build Makefile */
        headers();                      /* make a lot of .h files */
        makefile();                     /* build Makefile */
        headers();                      /* make a lot of .h files */
+       swapconf();                     /* swap config files */
        printf("Don't forget to run \"make depend\"\n");
        printf("Don't forget to run \"make depend\"\n");
-    }
+       exit(0);
 }
 
 /*
 }
 
 /*
@@ -47,50 +127,50 @@ char **argv;
  *     NULL on end of line
  *     pointer to the word otherwise
  */
  *     NULL on end of line
  *     pointer to the word otherwise
  */
-
-char *get_word(fp)
-register FILE *fp;
+char *
+get_word(fp)
+       register FILE *fp;
 {
 {
-    static char line[80];
-    register int ch;
-    register char *cp;
-
-    while((ch = getc(fp)) != EOF)
-       if (ch != ' ' && ch != '\t')
-           break;
-    if (ch == EOF)
-       return EOF;
-    if (ch == '\n')
-       return NULL;
-    cp = line;
-    *cp++ = ch;
-    while((ch = getc(fp)) != EOF)
-    {
-       if (isspace(ch))
-           break;
+       static char line[80];
+       register int ch;
+       register char *cp;
+
+       while ((ch = getc(fp)) != EOF)
+               if (ch != ' ' && ch != '\t')
+                       break;
+       if (ch == EOF)
+               return ((char *)EOF);
+       if (ch == '\n')
+               return (NULL);
+       cp = line;
        *cp++ = ch;
        *cp++ = ch;
-    }
-    *cp = '\0';
-    if (ch == EOF)
-       return EOF;
-    ungetc(ch, fp);
-    return line;
+       while ((ch = getc(fp)) != EOF) {
+               if (isspace(ch))
+                       break;
+               *cp++ = ch;
+       }
+       *cp = 0;
+       if (ch == EOF)
+               return ((char *)EOF);
+       (void) ungetc(ch, fp);
+       return (line);
 }
 
 /*
 }
 
 /*
- * path:
- *     Prepend the path to a filename
+ * prepend the path to a filename
  */
  */
-
+char *
 path(file)
 path(file)
-char *file;
+       char *file;
 {
 {
-    register char *cp;
-
-    cp = malloc(strlen(PREFIX)+strlen(file)+5);
-    strcpy(cp, "../");
-    strcat(cp, PREFIX);
-    strcat(cp, "/");
-    strcat(cp, file);
-    return cp;
+       register char *cp;
+
+       cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
+       (void) strcpy(cp, "../");
+       (void) strcat(cp, PREFIX);
+       if (file) {
+               (void) strcat(cp, "/");
+               (void) strcat(cp, file);
+       }
+       return (cp);
 }
 }