Annotation of 43BSDReno/usr.bin/window/lcmd1.c, revision 1.1

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

unix.superglobalmegacorp.com

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