Annotation of 43BSDReno/usr.bin/window/context.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[] = "@(#)context.c  3.12 (Berkeley) 6/6/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include "value.h"
        !            28: #include "string.h"
        !            29: #include "context.h"
        !            30: 
        !            31: /*
        !            32:  * Context push/pop for nested command files.
        !            33:  */
        !            34: 
        !            35: char *malloc();
        !            36: 
        !            37: cx_alloc()
        !            38: {
        !            39:        register struct context *xp;
        !            40: 
        !            41:        if (cx.x_type != 0) {
        !            42:                xp = (struct context *)
        !            43:                        malloc((unsigned) sizeof (struct context));
        !            44:                if (xp == 0)
        !            45:                        return -1;
        !            46:                *xp = cx;
        !            47:                cx.x_link = xp;
        !            48:                cx.x_type = 0;
        !            49:        }
        !            50:        cx.x_erred = 0;
        !            51:        cx.x_synerred = 0;
        !            52:        cx.x_abort = 0;
        !            53:        return 0;
        !            54: }
        !            55: 
        !            56: cx_free()
        !            57: {
        !            58:        struct context *xp;
        !            59: 
        !            60:        if ((xp = cx.x_link) != 0) {
        !            61:                cx = *xp;
        !            62:                free((char *)xp);
        !            63:        } else
        !            64:                cx.x_type = 0;
        !            65: }
        !            66: 
        !            67: cx_beginfile(filename)
        !            68: char *filename;
        !            69: {
        !            70:        if (cx_alloc() < 0)
        !            71:                return -1;
        !            72:        cx.x_type = X_FILE;
        !            73:        if ((cx.x_filename = str_cpy(filename)) == 0)
        !            74:                goto bad;
        !            75:        cx.x_fp = fopen(filename, "r");
        !            76:        if (cx.x_fp == 0)
        !            77:                goto bad;
        !            78:        cx.x_bol = 1;
        !            79:        cx.x_lineno = 0;
        !            80:        cx.x_errwin = 0;
        !            81:        cx.x_noerr = 0;
        !            82:        return 0;
        !            83: bad:
        !            84:        if (cx.x_filename != 0)
        !            85:                str_free(cx.x_filename);
        !            86:        cx_free();
        !            87:        return -1;
        !            88: }
        !            89: 
        !            90: cx_beginbuf(buf, arg, narg)
        !            91: char *buf;
        !            92: struct value *arg;
        !            93: int narg;
        !            94: {
        !            95:        if (cx_alloc() < 0)
        !            96:                return -1;
        !            97:        cx.x_type = X_BUF;
        !            98:        cx.x_bufp = cx.x_buf = buf;
        !            99:        cx.x_arg = arg;
        !           100:        cx.x_narg = narg;
        !           101:        return 0;
        !           102: }
        !           103: 
        !           104: cx_end()
        !           105: {
        !           106:        switch (cx.x_type) {
        !           107:        case X_BUF:
        !           108:                break;
        !           109:        case X_FILE:
        !           110:                (void) fclose(cx.x_fp);
        !           111:                str_free(cx.x_filename);
        !           112:                break;
        !           113:        }
        !           114:        cx_free();
        !           115: }

unix.superglobalmegacorp.com

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