Annotation of 43BSDTahoe/ucb/window/lcmd1.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: static char sccsid[] = "@(#)lcmd1.c    3.33 (Berkeley) 6/29/88";
                     20: #endif /* not lint */
                     21: 
                     22: #include "defs.h"
                     23: #include "string.h"
                     24: #include "value.h"
                     25: #include "lcmd.h"
                     26: #include "var.h"
                     27: 
                     28: struct lcmd_arg arg_window[] = {
                     29:        { "row",        1,      ARG_NUM },
                     30:        { "column",     1,      ARG_NUM },
                     31:        { "nrows",      2,      ARG_NUM },
                     32:        { "ncols",      2,      ARG_NUM },
                     33:        { "nlines",     2,      ARG_NUM },
                     34:        { "label",      1,      ARG_STR },
                     35:        { "pty",        1,      ARG_ANY },
                     36:        { "frame",      1,      ARG_ANY },
                     37:        { "mapnl",      1,      ARG_ANY },
                     38:        { "keepopen",   1,      ARG_ANY },
                     39:        { "smooth",     1,      ARG_ANY },
                     40:        { "shell",      1,      ARG_STR|ARG_LIST },
                     41:        0
                     42: };
                     43: 
                     44: l_window(v, a)
                     45: struct value *v;
                     46: register struct value *a;
                     47: {
                     48:        struct ww *w;
                     49:        int col, row, ncol, nrow, id, nline;
                     50:        char *label;
                     51:        char haspty, hasframe, mapnl, keepopen, smooth;
                     52:        char *shf, **sh;
                     53:        char *argv[sizeof shell / sizeof *shell];
                     54:        register char **pp;
                     55: 
                     56:        if ((id = findid()) < 0)
                     57:                return;
                     58:        row = a->v_type == V_ERR ? 1 : a->v_num;
                     59:        a++;
                     60:        col = a->v_type == V_ERR ? 0 : a->v_num;
                     61:        a++;
                     62:        nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num;
                     63:        a++;
                     64:        ncol = a->v_type == V_ERR ? wwncol - col : a->v_num;
                     65:        a++;
                     66:        nline = a->v_type == V_ERR ? nbufline : a->v_num;
                     67:        a++;
                     68:        label = a->v_type == V_ERR ? 0 : a->v_str;
                     69:        if ((haspty = vtobool(++a, 1, -1)) < 0)
                     70:                return;
                     71:        if ((hasframe = vtobool(++a, 1, -1)) < 0)
                     72:                return;
                     73:        if ((mapnl = vtobool(++a, !haspty, -1)) < 0)
                     74:                return;
                     75:        if ((keepopen = vtobool(++a, 0, -1)) < 0)
                     76:                return;
                     77:        if ((smooth = vtobool(++a, 1, -1)) < 0)
                     78:                return;
                     79:        if ((++a)->v_type != V_ERR) {
                     80:                for (pp = argv; a->v_type != V_ERR &&
                     81:                     pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++)
                     82:                        *pp = a->v_str;
                     83:                *pp = 0;
                     84:                shf = *(sh = argv);
                     85:                if (*sh = rindex(shf, '/'))
                     86:                        (*sh)++;
                     87:                else
                     88:                        *sh = shf;
                     89:        } else {
                     90:                sh = shell;
                     91:                shf = shellfile;
                     92:        }
                     93:        if ((w = openwin(id, row, col, nrow, ncol, nline, label, haspty,
                     94:            hasframe, shf, sh)) == 0)
                     95:                return;
                     96:        w->ww_mapnl = mapnl;
                     97:        w->ww_keepopen = keepopen;
                     98:        w->ww_noupdate = !smooth;
                     99:        v->v_type = V_NUM;
                    100:        v->v_num = id + 1;
                    101: }
                    102: 
                    103: struct lcmd_arg arg_nline[] = {
                    104:        { "nlines",     1,      ARG_NUM },
                    105:        0
                    106: };
                    107: 
                    108: l_nline(v, a)
                    109: register struct value *v, *a;
                    110: {
                    111:        v->v_num = nbufline;
                    112:        v->v_type = V_NUM;
                    113:        if (a->v_type != V_ERR)
                    114:                nbufline = a->v_num;
                    115: }
                    116: 
                    117: struct lcmd_arg arg_smooth[] = {
                    118:        { "window",     1,      ARG_NUM },
                    119:        { "flag",       1,      ARG_ANY },
                    120:        0
                    121: };
                    122: 
                    123: l_smooth(v, a)
                    124: register struct value *v, *a;
                    125: {
                    126:        struct ww *w;
                    127: 
                    128:        v->v_type = V_NUM;
                    129:        v->v_num = 0;
                    130:        if ((w = vtowin(a++, selwin)) == 0)
                    131:                return;
                    132:        v->v_num = !w->ww_noupdate;
                    133:        w->ww_noupdate = !vtobool(a, v->v_num, v->v_num);
                    134: }
                    135: 
                    136: struct lcmd_arg arg_select[] = {
                    137:        { "window",     1,      ARG_NUM },
                    138:        0
                    139: };
                    140: 
                    141: l_select(v, a)
                    142: register struct value *v, *a;
                    143: {
                    144:        struct ww *w;
                    145: 
                    146:        v->v_type = V_NUM;
                    147:        v->v_num = selwin ? selwin->ww_id + 1 : -1;
                    148:        if (a->v_type == V_ERR)
                    149:                return;
                    150:        if ((w = vtowin(a, (struct ww *)0)) == 0)
                    151:                return;
                    152:        setselwin(w);
                    153: }
                    154: 
                    155: struct lcmd_arg arg_debug[] = {
                    156:        { "flag",       1,      ARG_ANY },
                    157:        0
                    158: };
                    159: 
                    160: l_debug(v, a)
                    161: register struct value *v, *a;
                    162: {
                    163:        v->v_type = V_NUM;
                    164:        v->v_num = debug;
                    165:        debug = vtobool(a, debug, debug);
                    166: }
                    167: 
                    168: struct lcmd_arg arg_escape[] = {
                    169:        { "escapec",    1,      ARG_STR },
                    170:        0
                    171: };
                    172: 
                    173: l_escape(v, a)
                    174: register struct value *v, *a;
                    175: {
                    176:        char buf[2];
                    177: 
                    178:        buf[0] = escapec;
                    179:        buf[1] = 0;
                    180:        if ((v->v_str = str_cpy(buf)) == 0) {
                    181:                error("Out of memory.");
                    182:                return;
                    183:        }
                    184:        v->v_type = V_STR;
                    185:        if (a->v_type != V_ERR)
                    186:                setescape(a->v_str);
                    187: }
                    188: 
                    189: struct lcmd_arg arg_label[] = {
                    190:        { "window",     1,      ARG_NUM },
                    191:        { "label",      1,      ARG_STR },
                    192:        0
                    193: };
                    194: 
                    195: /*ARGSUSED*/
                    196: l_label(v, a)
                    197: struct value *v;
                    198: register struct value *a;
                    199: {
                    200:        struct ww *w;
                    201: 
                    202:        if ((w = vtowin(a, selwin)) == 0)
                    203:                return;
                    204:        if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0)
                    205:                error("Out of memory.");
                    206:        reframe();
                    207: }
                    208: 
                    209: struct lcmd_arg arg_foreground[] = {
                    210:        { "window",     1,      ARG_NUM },
                    211:        { "flag",       1,      ARG_ANY },
                    212:        0
                    213: };
                    214: 
                    215: l_foreground(v, a)
                    216: register struct value *v, *a;
                    217: {
                    218:        struct ww *w;
                    219:        char flag;
                    220: 
                    221:        if ((w = vtowin(a, selwin)) == 0)
                    222:                return;
                    223:        v->v_type = V_NUM;
                    224:        v->v_num = isfg(w);
                    225:        flag = vtobool(++a, v->v_num, v->v_num);
                    226:        if (flag == v->v_num)
                    227:                return;
                    228:        deletewin(w);
                    229:        addwin(w, flag);
                    230:        reframe();
                    231: }
                    232: 
                    233: struct lcmd_arg arg_terse[] = {
                    234:        { "flag",       1,      ARG_ANY },
                    235:        0
                    236: };
                    237: 
                    238: l_terse(v, a)
                    239: register struct value *v, *a;
                    240: {
                    241:        v->v_type = V_NUM;
                    242:        v->v_num = terse;
                    243:        setterse(vtobool(a, terse, terse));
                    244: }
                    245: 
                    246: struct lcmd_arg arg_source[] = {
                    247:        { "filename",   1,      ARG_STR },
                    248:        0
                    249: };
                    250: 
                    251: l_source(v, a)
                    252: register struct value *v, *a;
                    253: {
                    254:        v->v_type = V_NUM;
                    255:        if (a->v_type != V_ERR && dosource(a->v_str) < 0) {
                    256:                error("Can't open %s.", a->v_str);
                    257:                v->v_num = -1;
                    258:        } else
                    259:                v->v_num = 0;
                    260: }
                    261: 
                    262: struct lcmd_arg arg_write[] = {
                    263:        { "window",     1,      ARG_NUM },
                    264:        { "",           0,      ARG_ANY|ARG_LIST },
                    265:        0
                    266: };
                    267: 
                    268: /*ARGSUSED*/
                    269: l_write(v, a)
                    270: struct value *v;
                    271: register struct value *a;
                    272: {
                    273:        char buf[20];
                    274:        struct ww *w;
                    275: 
                    276:        if ((w = vtowin(a++, selwin)) == 0)
                    277:                return;
                    278:        while (a->v_type != V_ERR) {
                    279:                if (a->v_type == V_NUM) {
                    280:                        (void) sprintf(buf, "%d", a->v_num);
                    281:                        (void) write(w->ww_pty, buf, strlen(buf));
                    282:                } else
                    283:                        (void) write(w->ww_pty, a->v_str, strlen(a->v_str));
                    284:                if ((++a)->v_type != V_ERR)
                    285:                        (void) write(w->ww_pty, " ", 1);
                    286:        }
                    287: }
                    288: 
                    289: struct lcmd_arg arg_close[] = {
                    290:        { "window",     1,      ARG_ANY|ARG_LIST },
                    291:        0
                    292: };
                    293: 
                    294: /*ARGSUSED*/
                    295: l_close(v, a)
                    296: struct value *v;
                    297: register struct value *a;
                    298: {
                    299:        struct ww *w;
                    300: 
                    301:        if (a->v_type == V_STR && str_match(a->v_str, "all", 3))
                    302:                closewin((struct ww *)0);
                    303:        else
                    304:                for (; a->v_type != V_ERR; a++)
                    305:                        if ((w = vtowin(a, (struct ww *)0)) != 0)
                    306:                                closewin(w);
                    307: }
                    308: 
                    309: struct lcmd_arg arg_cursormodes[] = {
                    310:        { "modes",      1,      ARG_NUM },
                    311:        0
                    312: };
                    313: 
                    314: l_cursormodes(v, a)
                    315: register struct value *v, *a;
                    316: {
                    317: 
                    318:        v->v_type = V_NUM;
                    319:        v->v_num = wwcursormodes;
                    320:        if (a->v_type != V_ERR)
                    321:                wwsetcursormodes(a->v_num);
                    322: }
                    323: 
                    324: struct lcmd_arg arg_unset[] = {
                    325:        { "variable",   1,      ARG_ANY },
                    326:        0
                    327: };
                    328: 
                    329: l_unset(v, a)
                    330: register struct value *v, *a;
                    331: {
                    332:        v->v_type = V_NUM;
                    333:        switch (a->v_type) {
                    334:        case V_ERR:
                    335:                v->v_num = -1;
                    336:                return;
                    337:        case V_NUM:
                    338:                if ((a->v_str = str_itoa(a->v_num)) == 0) {
                    339:                        error("Out of memory.");
                    340:                        v->v_num = -1;
                    341:                        return;
                    342:                }
                    343:                a->v_type = V_STR;
                    344:                break;
                    345:        }
                    346:        v->v_num = var_unset(a->v_str);
                    347: }
                    348: 
                    349: struct ww *
                    350: vtowin(v, w)
                    351: register struct value *v;
                    352: struct ww *w;
                    353: {
                    354:        switch (v->v_type) {
                    355:        case V_ERR:
                    356:                if (w != 0)
                    357:                        return w;
                    358:                error("No window specified.");
                    359:                return 0;
                    360:        case V_STR:
                    361:                error("%s: No such window.", v->v_str);
                    362:                return 0;
                    363:        }
                    364:        if (v->v_num < 1 || v->v_num > NWINDOW
                    365:            || (w = window[v->v_num - 1]) == 0) {
                    366:                error("%d: No such window.", v->v_num);
                    367:                return 0;
                    368:        }
                    369:        return w;
                    370: }
                    371: 
                    372: vtobool(v, def, err)
                    373: register struct value *v;
                    374: char def, err;
                    375: {
                    376:        switch (v->v_type) {
                    377:        case V_NUM:
                    378:                return v->v_num != 0;
                    379:        case V_STR:
                    380:                if (str_match(v->v_str, "true", 1)
                    381:                    || str_match(v->v_str, "on", 2)
                    382:                    || str_match(v->v_str, "yes", 1))
                    383:                        return 1;
                    384:                else if (str_match(v->v_str, "false", 1)
                    385:                    || str_match(v->v_str, "off", 2)
                    386:                    || str_match(v->v_str, "no", 1))
                    387:                        return 0;
                    388:                else {
                    389:                        error("%s: Illegal boolean value.", v->v_str);
                    390:                        return err;
                    391:                }
                    392:                /*NOTREACHED*/
                    393:        case V_ERR:
                    394:                return def;
                    395:        }
                    396:        /*NOTREACHED*/
                    397: }

unix.superglobalmegacorp.com

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