Annotation of coherent/b/etc/Build_401/kbdinstall.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * kbdinstall.c
        !             3:  * 07/26/92
        !             4:  * Keyboard support installation, including virtual console questions.
        !             5:  *
        !             6:  * cc kbdinstall.c -lcurses [-lterm]
        !             7:  * Usage: kbdinstall [ -bu ]
        !             8:  * Options:
        !             9:  *     -b      invoked from build
        !            10:  *     -u      invoked from update install, don't patch running system
        !            11:  */
        !            12: 
        !            13: #include <stdio.h>
        !            14: #include <string.h>
        !            15: #include <curses.h>
        !            16: #include "build0.h"
        !            17: 
        !            18: extern char    *fgets();
        !            19: extern char    *malloc();
        !            20: 
        !            21: #define        VERSION "3.4"                   /* Version number.      */
        !            22: #define        KBDDIR  "/conf/kbd"             /* Keyboard directory.  */
        !            23: #define        KBDLIST "/conf/kbd/.list"       /* List of keyboards.   */
        !            24: #define        KBDFILE "/tmp/kbd"              /* File of driver object name(s) */
        !            25: #define        KBDY    4                       /* y-coordinate of keyboard list. */
        !            26: #define        NLINE   512                     /* Line length.         */
        !            27: #define        NKBDS   (24-KBDY)               /* Max number of keyboards */
        !            28: #define        USAGE   "Usage: /etc/kbdinstall [-bu]\n"
        !            29: 
        !            30: /* Keyboard list file entries. */
        !            31: typedef        struct  kline   {
        !            32:        int     k_loadable;             /* True: loadable tables supported */
        !            33:        char    *k_driver;              /* Name of keyboard driver object */
        !            34:        char    *k_table;               /* Keyboard table name  */
        !            35:        char    *k_desc;                /* Keyboard description */
        !            36: }      KLINE;
        !            37: 
        !            38: /* Forward */
        !            39: char   *copystr();
        !            40: void   display_line();
        !            41: void   display_rev();
        !            42: void   fatal();
        !            43: void   my_fatal();                     /* handles window cleanup */
        !            44: void   format_error();
        !            45: void   nonfatal();
        !            46: void   my_nonfatal();                  /* handles window cleanup */
        !            47: void   read_klist();
        !            48: 
        !            49: /* Globals. */
        !            50: int    bflag;                          /* Invoked from build.  */
        !            51: char   buf[NBUF];                      /* Input buffer.        */
        !            52: KLINE  klist[NKBDS];                   /* Keyboard list.       */
        !            53: int    nkbds;                          /* Number of keyboards. */
        !            54: int    initflag;                       /* Curses initialized.  */
        !            55: int    uflag;                          /* Invoked from update. */
        !            56: int    virtual;                        /* Virtual consoles wanted */
        !            57: int    default_entry = -1;             /* Which entry to default to */
        !            58: int    color_sessions;                 /* number of color sessions */
        !            59: int    mono_sessions;                  /* number of mono sessions */
        !            60: 
        !            61: main(argc, argv) int argc; char *argv[];
        !            62: {
        !            63:        register int n, c, i;
        !            64:        char *s;
        !            65: 
        !            66:        /* Process command line options. */
        !            67:        while (argc > 1 && argv[1][0] == '-') {
        !            68:                for (s = &argv[1][1]; *s != '\0'; s++) {
        !            69:                        switch (*s) {
        !            70:                        case 'b':       ++bflag;                        break;
        !            71:                        case 'u':       ++uflag;                        break;
        !            72:                        case 'V':       nonfatal("V%s", VERSION);       break;
        !            73:                        default:
        !            74:                                fprintf(stderr, USAGE);
        !            75:                                exit(1);
        !            76:                        }
        !            77:                }
        !            78:                --argc;
        !            79:                ++argv;
        !            80:        }
        !            81: 
        !            82:        if (bflag && uflag) {
        !            83:                fprintf(stderr, USAGE);
        !            84:                exit(1);
        !            85:        }
        !            86: 
        !            87:        /* Initialize screen and terminal modes. */
        !            88:        initscr();
        !            89:        initflag = 1;
        !            90:        noecho();
        !            91:        raw();
        !            92:        clear();
        !            93: 
        !            94: #if _I386
        !            95:        if (bflag || uflag) {
        !            96:                /*
        !            97:                 * If 386 and invoked from "build" or "install", output some
        !            98:                 * info about virtual consoles.  Prompt the user if he/she
        !            99:                 * wants V.C. support and set variable "virtual" as needed.
        !           100:                 */
        !           101:                mvaddstr(0, 0,
        !           102: "This release of COHERENT supports multiple simultaneous sessions on the");
        !           103:                mvaddstr(1, 0,
        !           104: "system console.  This feature, known as virtual consoles, supports both");
        !           105:                mvaddstr(2, 0,
        !           106: "monochrome and color video cards (text mode only) with multiple \"login\"");
        !           107:                mvaddstr(3, 0,
        !           108: "sessions on each, depending upon your hardware configuration.  If you have");
        !           109:                mvaddstr(4, 0,
        !           110: "both color and monochrome adapters on your system, you can run multiple");
        !           111:                mvaddstr(5, 0,
        !           112: "sessions on each of them at the same time.");
        !           113:                mvaddstr(6, 0,
        !           114: "Virtual console support only works with systems which have at least one");
        !           115:                mvaddstr(7, 0,
        !           116: "megabyte of usable system memory, and with keyboards which are 100% IBM AT");
        !           117:                mvaddstr(8, 0,
        !           118: "hardware compatible.  If you are using a low cost clone keyboard which is not");
        !           119:                mvaddstr(9, 0,
        !           120: "100% hardware compatible (i.e., does not correctly support scan code set 3");
        !           121:                mvaddstr(10, 0,
        !           122: "operation), you will not be able to use COHERENT's virtual console features,");
        !           123:                mvaddstr(11, 0,
        !           124: "nor will you be able to use COHERENT's \"loadable\" keyboard driver.");
        !           125:                mvaddstr(13, 0,
        !           126: "Do you wish to include support for virtual consoles? [y or n] ");
        !           127:                refresh();
        !           128:                echo();
        !           129:                for (;;) {
        !           130:                        c = getch();
        !           131:                        switch (c) {
        !           132:                        case 'Y':
        !           133:                        case 'y':
        !           134:                                ++virtual;
        !           135:                                break;
        !           136:                        case 'N':
        !           137:                        case 'n':
        !           138:                                break;
        !           139:                        default:
        !           140:                                continue;
        !           141:                        }
        !           142:                        noecho();
        !           143:                        refresh();
        !           144:                        mvaddstr(14, 0, "Please hit <Enter> ...");
        !           145:                        refresh();
        !           146:                        while ((c = getch()) != '\r' && c != '\n')
        !           147:                                ;
        !           148:                        mvaddstr(14, 0, "One moment, please ....");
        !           149:                        refresh();
        !           150:                        break;
        !           151:                }
        !           152:                clear();
        !           153:        }
        !           154: #endif
        !           155: 
        !           156:        /* Read the keyboard list file. */
        !           157:        read_klist();
        !           158: 
        !           159:        /* Display instructions at top of screen. */
        !           160:        mvaddstr(0, 0,
        !           161: "Select the entry below which indentifies your keyboard type.  Hit <Enter> to");
        !           162:        mvaddstr(1, 0,
        !           163: "select the highlighted entry.  Hit <space> to move to the next entry.");
        !           164: 
        !           165:        /* Display choices. */
        !           166:        for (n = 0; n < nkbds; n++)
        !           167:                display_line(n);
        !           168: 
        !           169:        /* Interactive input loop: display choice n highlighted. */
        !           170:        for (n = (default_entry >= 0) ? default_entry : 0; ; ) {
        !           171:                display_rev(n);         /* display default choice in reverse */
        !           172:                refresh();
        !           173:                switch (c = getch()) {
        !           174:                case 'A':               /* n.b.:  ESC [ A is Up Arrow key */
        !           175:                        if (--n < 0)
        !           176:                                n = nkbds - 1;
        !           177:                        continue;
        !           178:                case ' ':               /* space/Down Arrow: try next choice */
        !           179:                case 'B':               /* n.b.:  ESC [ B is Down Arrow key */
        !           180:                        if (++n >= nkbds)
        !           181:                                n = 0;
        !           182:                        continue;
        !           183:                case '\n':
        !           184:                case '\r':              /* enter: take default value */
        !           185:                        break;
        !           186:                default:
        !           187:                        continue;       /* ignore */
        !           188:                }
        !           189:                break;                  /* done, choice is in n */
        !           190:        }
        !           191:        endwin();
        !           192: 
        !           193:        /*
        !           194:         * Execute the keyboard table file only if invoked by the user
        !           195:         * (i.e., not Build nor Update).
        !           196:         */
        !           197:        if (!uflag && !bflag) {
        !           198:                if (klist[n].k_loadable) {
        !           199:                        sprintf(buf, "%s/%s", KBDDIR, klist[n].k_table);
        !           200:                        if (system(buf) != 0)
        !           201:                            fatal("Loadable keyboard tables not supported by this kernel", buf);
        !           202:                } else {
        !           203:                        fatal("Selected entry is not a loadable keyboard table");
        !           204:                }
        !           205:                exit(0);
        !           206:        }
        !           207: 
        !           208:        /*
        !           209:         * Build or Update:
        !           210:         *      Store keyboard driver name in file specified by KBDFILE.
        !           211:         *      If loadable keyboard table selected, store name of keyboard
        !           212:         *      table into /tmp/drvld.all (386),
        !           213:         *      or to /etc/drvld.all (286 update).
        !           214:         */
        !           215: 
        !           216: /*
        !           217:  * COH 4.2 adds vt support with non-loadable tables. If such a keyboard is
        !           218:  * selected by the user, then the table field will be "nl". In this instance,
        !           219:  * we don't want to build a drvld entry.  bob h 7/14/93
        !           220:  */
        !           221:        if (klist[n].k_loadable) {
        !           222:                sprintf(buf,"/bin/echo %s >%s",(virtual)?klist[n].k_driver : "nkb.a mm.a", KBDFILE);
        !           223:                if(strcmp(klist[n].k_table,"nl")){
        !           224:                        sprintf(buf,"/bin/echo %s/%s >>%s/drvld.all",
        !           225:                                KBDDIR, klist[n].k_table,
        !           226: #if _I386
        !           227:                                "/tmp");
        !           228: 
        !           229: #else
        !           230:                                (bflag) ? "/tmp" : "/etc");
        !           231: #endif
        !           232: 
        !           233:                }
        !           234:        } else {
        !           235:                sprintf(buf, "/bin/echo %s mm.a >%s",
        !           236:                        klist[n].k_driver, KBDFILE);
        !           237:        }
        !           238:        sys(buf, S_FATAL);
        !           239: 
        !           240:        printf( "Your keyboard selection will not take effect until after\n"
        !           241:                "your system %s has completed and the system has rebooted!\n\n",
        !           242:                bflag ? "installation" : "update");
        !           243: 
        !           244:        /*
        !           245:         * During installation, if V.C.'s are in use,
        !           246:         * don't provide the console device.
        !           247:         */
        !           248:        if (bflag && !virtual) {
        !           249:                sprintf(cmd, "/bin/echo \"1lPconsole\" >/tmp/ttys");
        !           250:                sys(cmd, S_FATAL);
        !           251:        }
        !           252: 
        !           253: again:
        !           254:        mono_sessions = 0;
        !           255:        if (virtual && yes_no("\nDoes this system have a monochrome (i.e., MDA) video adapter")) {
        !           256:                mono_sessions = get_int(1, 4,
        !           257:                "How many active virtual console sessions would you like on your\n"
        !           258:                "monochrome video adapter card [1-4]?");
        !           259:                for (i = 0; i < mono_sessions; ++i) {
        !           260:                        sprintf(cmd, "/bin/echo \"1lPmono%d\" >>%s/ttys",
        !           261: #if _I386
        !           262:                                i, "/tmp");
        !           263: #else
        !           264:                                i, (bflag) ? "/tmp" : "/etc");
        !           265: #endif
        !           266:                        sys(cmd, S_FATAL);
        !           267:                }
        !           268:        }
        !           269: 
        !           270:        color_sessions = 0;
        !           271:        if (virtual && yes_no("\nDoes this system have a color (i.e., CGA/EGA/VGA) video adapter")) {
        !           272:                color_sessions = get_int(1, 4,
        !           273:                "How many active virtual console sessions would you like on your\n"
        !           274:                "color video adapter card [1-4]?");
        !           275:                for (i = 0; i < color_sessions; ++i) {
        !           276:                        sprintf(cmd, "/bin/echo \"1lPcolor%d\" >>%s/ttys",
        !           277: #if _I386
        !           278:                                i, "/tmp");
        !           279: #else
        !           280:                                i, (bflag) ? "/tmp" : "/etc");
        !           281: #endif
        !           282:                        sys(cmd, S_FATAL);
        !           283:                }
        !           284:        }
        !           285: 
        !           286:        if (virtual && (mono_sessions + color_sessions) == 0) {
        !           287:                printf("\nYou must select either a monochrome or a color video adapter!\n");
        !           288:                goto again;
        !           289:        }
        !           290: 
        !           291:        /*
        !           292:         * After linking new kernel, will patch it for number of mono
        !           293:         * and color sessions.  Do the patch even if number of sessions
        !           294:         * for the given type is zero.
        !           295:         */
        !           296:        if (virtual) {
        !           297:                sprintf(cmd,
        !           298:          "echo /conf/patch /mnt/coherent VTMONO=%d:c VTVGA=%d:c >> %s\n",
        !           299:                  mono_sessions, color_sessions, PATCHFILE);
        !           300:                sys(cmd, S_FATAL);
        !           301:        }
        !           302: 
        !           303:        /* Done. */
        !           304:        exit(0);
        !           305: }
        !           306: 
        !           307: /*
        !           308:  * Allocate a copy of a string and return a pointer to it.
        !           309:  */
        !           310: char *
        !           311: copystr(s) register char *s;
        !           312: {
        !           313:        register char *cp;
        !           314: 
        !           315:        if ((cp = malloc(strlen(s) + 1)) == NULL)
        !           316:                my_fatal("no space for string \"%s\"");
        !           317:        strcpy(cp, s);
        !           318:        return cp;
        !           319: }
        !           320: 
        !           321: /*
        !           322:  * Display choice n.
        !           323:  */
        !           324: void
        !           325: display_line(n) register int n;
        !           326: {
        !           327:        mvaddstr(KBDY+n, 12, klist[n].k_desc);
        !           328: }
        !           329: 
        !           330: /*
        !           331:  * Display choice n in reverse video.
        !           332:  */
        !           333: void
        !           334: display_rev(n) int n;
        !           335: {
        !           336:        static int last = -1;
        !           337: 
        !           338:        if (last != -1)
        !           339:                display_line(last);     /* redisplay last in normal */
        !           340:        standout();
        !           341:        display_line(n);                /* display n in reverse */
        !           342:        standend();
        !           343:        last = n;
        !           344: }
        !           345: 
        !           346: /*
        !           347:  * Cry and die.
        !           348:  */
        !           349: /* VARARGS */
        !           350: void
        !           351: my_fatal(s) char *s;
        !           352: {
        !           353:        if (initflag)
        !           354:                endwin();
        !           355:        fprintf(stderr, "kbdinstall: %r\n", &s);
        !           356:        exit(1);
        !           357: }
        !           358: 
        !           359: /*
        !           360:  * Issue nonfatal informative message.
        !           361:  */
        !           362: /* VARARGS */
        !           363: void
        !           364: my_nonfatal(s) char *s;
        !           365: {
        !           366:        if (initflag)
        !           367:                endwin();
        !           368:        fprintf(stderr, "kbdinstall: %r\n", &s);
        !           369: }
        !           370: 
        !           371: /*
        !           372:  * Read a file containing keyboard file names and descriptions,
        !           373:  * build a keyboard list.
        !           374:  *
        !           375:  * Format of input is:
        !           376:  *     # Comment line
        !           377:  * or
        !           378:  *     Default <tab> Loadable <tab> Driver <tab> Table <tab> Descr.
        !           379:  */
        !           380: void
        !           381: read_klist()
        !           382: {
        !           383:        register FILE *fp;
        !           384:        register unsigned char *s, *s1;
        !           385: 
        !           386:        if ((fp = fopen(KBDLIST, "r")) == NULL)
        !           387:                my_fatal("cannot open \"%s\"", KBDLIST);
        !           388:        while (fgets(buf, sizeof buf, fp) != NULL) {
        !           389:                if (buf[0] == '#')
        !           390:                        continue;               /* ignore comments */
        !           391:                if (nkbds == NKBDS) {
        !           392:                        my_nonfatal("more than %d keyboard entries", NKBDS-1);
        !           393:                        continue;
        !           394:                }
        !           395: 
        !           396:                /*
        !           397:                 * Parse input lines and emit error messages if input bad.
        !           398:                 */
        !           399:                if (buf[0] == 'Y' || buf[0] == 'y')
        !           400:                        default_entry = nkbds;
        !           401:                if ((s = strchr(buf, '\t')) == NULL) {
        !           402:                        format_error(buf);
        !           403:                        continue;
        !           404:                }
        !           405: 
        !           406:                switch (*++s) {
        !           407:                case 'Y': case 'y':
        !           408:                        klist[nkbds].k_loadable = TRUE;
        !           409:                        break;
        !           410:                case 'N': case 'n':
        !           411:                        if ((!bflag && !uflag) || virtual)
        !           412:                                continue;       /* ignore if interactive ... */
        !           413:                        break;                  /* ... or if VC's desired */
        !           414:                default:
        !           415:                        format_error(buf);
        !           416:                        continue;
        !           417:                }
        !           418:                if ((s = strchr(++s, '\t')) == NULL) {
        !           419:                        format_error(buf);
        !           420:                        continue;
        !           421:                }
        !           422:                if ((s1 = strchr(++s, '\t')) == NULL) {
        !           423:                        format_error(buf);
        !           424:                        continue;
        !           425:                }
        !           426:                *s1++ = '\0';
        !           427:                klist[nkbds].k_driver = copystr(s);     /* keyboard driver */
        !           428:                if ((s = strchr(s1, '\t')) == NULL) {
        !           429:                        format_error(s1);
        !           430:                        continue;
        !           431:                }
        !           432:                *s++ = '\0';
        !           433:                klist[nkbds].k_table = copystr(s1);     /* keyboard table */
        !           434:                if ((s1 = strchr(s, '\n')) == NULL) {
        !           435:                        my_nonfatal("no newline in \"%s\"", s);
        !           436:                        continue;
        !           437:                }
        !           438:                *s1 = '\0';
        !           439:                klist[nkbds].k_desc = copystr(s);       /* kbd description */
        !           440: 
        !           441:                nkbds++;
        !           442:        }
        !           443:        fclose(fp);
        !           444: }
        !           445: 
        !           446: /*
        !           447:  * Input error found: display an error message and continue.
        !           448:  */
        !           449: void
        !           450: format_error(line)
        !           451: char *line;
        !           452: {
        !           453:        my_nonfatal("Input format error found in \"%s\" -- ignored.", line);
        !           454: }
        !           455: 
        !           456: /* end of kbdinstall.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.