Annotation of coherent/g/usr/bin/vsh/winlib/selbox.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *      Output a select box and select one option
        !             3:  *
        !             4:  *      Copyright (c) 1990-93 by Udo Munk
        !             5:  */
        !             6: 
        !             7: #ifdef AIX
        !             8: #define NLS
        !             9: #endif
        !            10: 
        !            11: #include <curses.h>
        !            12: #include <string.h>
        !            13: #include "winfun.h"
        !            14: 
        !            15: extern WINDOW *open_window();
        !            16: extern int close_window();
        !            17: 
        !            18: select_box(b, opt, attr)
        !            19: char *b[];
        !            20: int opt;
        !            21: chtype attr;
        !            22: {
        !            23:        register int i, j;
        !            24:        int bw, bh, nt, ni, ai, itoff, ilen, eoj;
        !            25:        WINDOW *w;
        !            26: 
        !            27:        i = bw = bh = 0;
        !            28:        ai = opt;
        !            29:        while (b[i] != NULL)
        !            30:                if ((j = strlen(b[i++]) + 2) > bw)
        !            31:                        bw = j; /* width of the box */
        !            32:        bh = i + 4;             /* high of the box */
        !            33:        nt = i;                 /* number of options */
        !            34:        itoff = ++i;
        !            35:        ilen = 0;
        !            36:        while (b[i] != NULL) {
        !            37:                ilen += strlen(b[i]) + 3;
        !            38:                i++;
        !            39:        }
        !            40:        ilen--;
        !            41:        ni = i - itoff;
        !            42:        if (ilen > (bw - 2))
        !            43:                bw = ilen + 2;
        !            44:        if ((w = open_window(bh, bw, (LINES-bh)/2, (COLS-bw)/2)) == (WINDOW *) 0)
        !            45:                nomem();
        !            46:        cursoroff();
        !            47:        leaveok(w, TRUE);
        !            48:        wattron(w, A_REVERSE);
        !            49:        for (i = 0; i < bh; i++)/* output the inverted box */
        !            50:                for (j = 0; j < bw; j++)
        !            51:                        mvwaddch(w, i, j, ' ');
        !            52:        for (i = 0; i < nt; i++)
        !            53:                mvwaddstr(w, i+1, 1, b[i]);
        !            54:        wattroff(w, A_REVERSE);
        !            55:        dialog_options(w, nt+2, (bw-ilen)/2, b, itoff, ai, attr);
        !            56:        eoj = 1;
        !            57:        while (eoj) {
        !            58:                switch (wgetch(w)) {
        !            59:                case ' ':
        !            60:                case W_KEY_TAB:
        !            61:                case KEY_RIGHT:
        !            62:                        ai++;
        !            63:                        if (ai > ni)
        !            64:                                ai = 1;
        !            65:                        dialog_options(w, nt+2, (bw-ilen)/2, b, itoff, ai, attr);
        !            66:                        break;
        !            67:                case W_KEY_BTAB:
        !            68:                case KEY_LEFT:
        !            69:                        ai--;
        !            70:                        if (ai < 1)
        !            71:                                ai = ni;
        !            72:                        dialog_options(w, nt+2, (bw-ilen)/2, b, itoff, ai, attr);
        !            73:                        break;
        !            74:                case '\r':
        !            75:                case KEY_ENTER:
        !            76:                        eoj = 0;
        !            77:                        break;
        !            78:                case W_KEY_REFR:
        !            79: #ifdef KEY_REFR
        !            80:                case KEY_REFR:
        !            81: #endif
        !            82:                        wrefresh(curscr);
        !            83:                        break;
        !            84:                default:
        !            85:                        break;
        !            86:                }
        !            87:        }
        !            88:        close_window(w);
        !            89:        return(ai);
        !            90: }
        !            91: 
        !            92: /*
        !            93:  *      output options in to the box
        !            94:  */
        !            95: static dialog_options(w, y, x, s, o, a, attr)
        !            96: WINDOW *w;
        !            97: char *s[];
        !            98: int y, x, o, a;
        !            99: chtype attr;
        !           100: {
        !           101:        register int j;
        !           102: 
        !           103:        j = 1;
        !           104:        wmove(w, y, x);
        !           105:        while (s[o] != NULL) {
        !           106:                waddch(w, ' ');
        !           107:                if (j == a) {
        !           108:                        wattron(w, attr);
        !           109:                        waddstr(w, s[o++]);
        !           110:                        wattroff(w, attr);
        !           111:                } else
        !           112:                        waddstr(w, s[o++]);
        !           113:                waddch(w, ' ');
        !           114:                wattron(w, A_REVERSE);
        !           115:                waddch(w, ' ');
        !           116:                wattroff(w, A_REVERSE);
        !           117:                j++;
        !           118:        }
        !           119:        wrefresh(w);
        !           120: }

unix.superglobalmegacorp.com

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