Ejemplo n.º 1
0
int
var_CBUFNAME(TBUFF **rp, const char *vp)
{
    if (rp) {
	tb_scopy(rp, valid_buffer(curbp) ? curbp->b_bname : "");
	return TRUE;
    } else if (vp) {
	if (valid_buffer(curbp)) {
	    set_bname(curbp, vp);
	    curwp->w_flag |= WFMODE;
	}
	return TRUE;
    } else {
	return FALSE;
    }
}
Ejemplo n.º 2
0
int
var_BUF_FNAME_EXPR(TBUFF **rp, const char *vp)
{
    return any_ro_STR(rp, vp, (valid_buffer(curbp)
			       ? get_buf_fname_expr(curbp)->pat
			       : ""));
}
Ejemplo n.º 3
0
int
var_BUFNAME(TBUFF **rp, const char *vp)
{
    return any_REGEX_MATCH(rp, vp, (valid_buffer(curbp)
				    ? b_val_rexp(curbp, VAL_BUFNAME_EXPR)
				    : (REGEXVAL *) 0));
}
Ejemplo n.º 4
0
int
var_BLINES(TBUFF **rp, const char *vp)
{
    bsizes(curbp);
    return (valid_buffer(curbp)
	    ? any_ro_INT(rp, vp, curbp->b_linecount)
	    : FALSE);
}
Ejemplo n.º 5
0
int
var_BCHARS(TBUFF **rp, const char *vp)
{
    bsizes(curbp);
    return (valid_buffer(curbp)
	    ? any_ro_ULONG(rp, vp, curbp->b_bytecount)
	    : FALSE);
}
Ejemplo n.º 6
0
int
check_editable(BUFFER *bp)
{
    int status = TRUE;
    if (valid_buffer(bp) && b_val(bp, MDVIEW))
	status = rdonly();
    return status;
}
Ejemplo n.º 7
0
static void
attach_attrib(BUFFER *bp, AREGION * arp)
{
    if (valid_buffer(bp)) {
	arp->ar_next = bp->b_attribs;
	bp->b_attribs = arp;
	mark_buffers_windows(bp);
	arp->ar_region.r_attr_id = (USHORT) assign_attr_id();
    }
}
Ejemplo n.º 8
0
static int
any_REGEX_MATCH(TBUFF **rp, const char *vp, REGEXVAL * rexp)
{
    if (rp) {
	(void) vl_regex2tbuff(rp, rexp, vl_get_it_all);
	return TRUE;
    } else if (vp && valid_buffer(curbp)) {
	return lrepl_regex(rexp, vp, (int) strlen(vp));
    } else {
	return FALSE;
    }
}
Ejemplo n.º 9
0
static int
any_CTYPE_MATCH(TBUFF **rp, const char *vp, CHARTYPE type)
{
    int whole_line = adjust_chartype(&type);

    if (rp) {
	(void) vl_ctype2tbuff(rp, type, whole_line);
	return TRUE;
    } else if (vp && valid_buffer(curbp)) {
	return lrepl_ctype(type, vp, (int) strlen(vp));
    } else {
	return FALSE;
    }
}
Ejemplo n.º 10
0
static int
attribute_directly(void)
{
    BUFFER *bp = curbp;
    int code = FALSE;

#if OPT_MAJORMODE
    if (valid_buffer(bp)) {
#if OPT_AUTOCOLOR
	VL_ELAPSED begin_time;
	(void) vl_elapsed(&begin_time, TRUE);
#endif
	discard_syntax_highlighting();
	if (b_val(bp, MDHILITE)) {
	    char *filtername = 0;
	    TBUFF *token = 0;

	    if (clexec || isnamedcmd)
		filtername = mac_unquotedarg(&token);

	    if (filtername == 0
		&& bp->majr != 0)
		filtername = bp->majr->shortname;

	    if (filtername != 0
		&& flt_start(filtername)) {
		TRACE(("attribute_directly(%s) using %s\n",
		       bp->b_bname,
		       filtername));
		flt_finish();
		code = TRUE;
	    }
	    tb_free(&token);
	}
	attach_attrib(selbufp, &selregion);
	attach_attrib(startbufp, &startregion);
#if OPT_HILITEMATCH
	if (bp->b_highlight & HILITE_ON) {
	    bp->b_highlight |= HILITE_DIRTY;
	    attrib_matches();
	}
#endif
#if OPT_AUTOCOLOR
	bp->last_autocolor_time = vl_elapsed(&begin_time, FALSE);
	bp->next_autocolor_time = 0;
#endif
    }
#endif
    return code;
}
Ejemplo n.º 11
0
/*
 * Create the message-buffer if it doesn't already exist
 */
static BUFFER *
create_msgs(void)
{
    BUFFER *bp = 0;

    if (wheadp != 0) {		/* we need windows before creating buffers */
	bp = bfind(MESSAGES_BufName, BFINVS);

	if (valid_buffer(bp)) {
	    b_set_invisible(bp);
	    bp->b_active = TRUE;
	}
    }
    return bp;
}
Ejemplo n.º 12
0
/*
 * If no warning messages were encountered during startup, and the popup-msgs
 * mode wasn't enabled, discard the informational messages that are there
 * already.
 */
void
purge_msgs(void)
{
    TRACE(("purge_msgs mode:%d, warnings:%d\n",
	   global_g_val(GMDPOPUP_MSGS), warnings));

    if ((global_g_val(GMDPOPUP_MSGS) == -TRUE)
	&& (warnings == 0)) {
	BUFFER *bp = find_b_name(MESSAGES_BufName);
	if (valid_buffer(bp)
	    && bp->b_nwnd == 0) {
	    (void) zotbuf(bp);
	}
	set_global_g_val(GMDPOPUP_MSGS, FALSE);
    }
}
Ejemplo n.º 13
0
void
find_release_attr(BUFFER *bp, REGION * rp)
{
    if (valid_buffer(bp)) {
	AREGION **rpp = &bp->b_attribs;
	AREGION *ap;

	while ((ap = *rpp) != NULL) {
	    if (ap->ar_region.r_attr_id == rp->r_attr_id) {
		free_attrib2(bp, rpp);
		break;
	    } else
		rpp = &ap->ar_next;
	}
    }
}
Ejemplo n.º 14
0
static void
detach_attrib(BUFFER *bp, AREGION * arp)
{
    if (find_bp(bp) != 0) {
	if (valid_buffer(bp)) {
	    AREGION **rpp;
	    mark_buffers_windows(bp);
	    rpp = &bp->b_attribs;
	    while (*rpp != NULL) {
		if (*rpp == arp) {
		    *rpp = (*rpp)->ar_next;
		    arp->ar_region.r_attr_id = 0;
		    break;
		} else
		    rpp = &(*rpp)->ar_next;
	    }
	}
    }
}
Ejemplo n.º 15
0
int
var_CHAR(TBUFF **rp, const char *vp)
{
    int status = FALSE;

    if (rp) {
	if (valid_buffer(curbp) && !is_empty_buf(curbp)) {
	    render_int(rp, CharAtDot());
	} else {
	    tb_scopy(rp, error_val);
	}
	status = TRUE;
    } else if (vp) {
	if ((status = check_editable(curbp)) == TRUE) {
	    int c;
	    mayneedundo();
	    (void) ldel_chars(1L, FALSE);	/* delete 1 char */
	    c = scan_int(vp);
	    if ((status = bputc(c)) == TRUE)
		(void) backchar(FALSE, 1);
	}
    }
    return status;
}
Ejemplo n.º 16
0
int main(int argc, char * argv[])
{
        int i;
        int read_write_error;
        int input_stat[2] = {0};
        int output_stat[2] = {0};

        int flags = 0;
        int count = -1;
        int skip = 0, seek = 0;
        int bs = -1, ibs = 4096, obs = 4096;
        int buffer_size = 0;
        int count_read, count_write;
        time_t time_start, time_finish, time_use;

        const char * input_path = "-";
        const char * output_path = "-";
        const char * input_device = NULL;
        const char * output_device = NULL;

        struct io_base *input_handle, *output_handle;
        char * buffer_read, * buffer_write, * buffer_alloc;

        for (i = 1; i < argc; i++) {
                char * argline = argv[i];
                char * optvalue = getoptvalue(argv[i]);

                ARG_INT(&ibs, 1, "ibs=");
                ARG_INT(&obs, 2, "obs=");
                ARG_INT(&bs, (1 | 2), "bs=");
                ARG_INT(&seek, 4, "seek=");
                ARG_INT(&skip, 8, "skip=");
                ARG_INT(&count, 16, "count=");
                ARG_STRING(&input_path, 32, "if=");
                ARG_STRING(&output_path, 64, "of=");
                ARG_STRING(&input_device, 128, "kin=");
                ARG_STRING(&output_device, 256, "kout=");

                fprintf(stderr, "unkown operand %s", argline);
                exit(-1);
        }

        if (bs != -1) {
                ibs = bs;
                obs = bs;
        }

        valid_size("invalid input block size", ibs);
        valid_size("invalid output block size", obs);

        input_handle = open_file(input_path, GENERIC_READ);
        valid_handle("invalid input handle", input_handle);

        output_handle = open_file(output_path, GENERIC_WRITE);
        valid_handle("invalid output handle", output_handle);

        buffer_size = (ibs < obs? obs: ibs) * 2;
        buffer_alloc = (char *)malloc(buffer_size);
        valid_buffer("alloc buffer fail", buffer_alloc);

        if (seek > 0) {
				off_t posnew = seek * (off_t)(obs);
				off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR);
                valid_size("seek output file fail", posnew == poscur);
        }

        if (skip > 0) {
				off_t posnew = skip * (off_t)(ibs);
				off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR);
                valid_size("skip input file fail", posnew == poscur);
        }

        read_write_error = 0;
        count_read = count_write = 0;
        buffer_read = buffer_write = buffer_alloc;

        time_start = time(NULL);
        while (read_write_error == 0) {
                size_t transfer = 0;

                while (buffer_read < buffer_alloc + obs) {
                        if (!io_read(input_handle, buffer_read, ibs, &transfer)) {
                                read_write_error = 2;
                                break;
                        }

                        if (transfer == 0) {
                                read_write_error = 1;
                                break;
                        }

                        buffer_read += transfer;
                        count_read += transfer;

                        input_stat[transfer == ibs]++;
                        if (input_stat[0] + input_stat[1] == count) {
                                read_write_error = 1;
                                break;
                        }
                }

                while (buffer_write + obs <= buffer_read) {
                        if (!io_write(output_handle, buffer_write, obs, &transfer)) {
                                read_write_error = 2;
                                break;
                        }

                        if (transfer == 0) {
                                read_write_error = 2;
                                break;
                        }

                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                }

                memmove(buffer_alloc, buffer_write, count_read - count_write);
                buffer_read = buffer_alloc + (count_read - count_write);
                buffer_write = buffer_alloc;
        }

        while (read_write_error == 1 &&
                        count_write < count_read) {
                size_t transfer = (count_read - count_write);

                valid_size("internal error", transfer < obs);
                if (io_write(output_handle, buffer_write, transfer, &transfer)) {
                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                        continue;
                }

                if (io_write(output_handle, buffer_write, obs, &transfer)) {
                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                        continue;
                }
           
                read_write_error = 3;
                break;
        }
        time_finish = time(NULL);

        io_close(output_handle);
        io_close(input_handle);
        free(buffer_alloc);

        time_use = time_finish > time_start? time_finish - time_start: 1;
        fprintf(stderr, "%d+%d records in\n", input_stat[1], input_stat[0]);
        fprintf(stderr, "%d+%d records out\n", output_stat[1], output_stat[0]);
        fprintf(stderr, "%d bytes transferred in %ld secs (%ld bytes/sec)\n",
                        count_read, time_use, count_read / time_use);
        return 0;
}
Ejemplo n.º 17
0
BUFFER *
sel_buffer(void)
{
    return valid_buffer(startbufp) ? startbufp : selbufp;
}
Ejemplo n.º 18
0
/* Extend the current selection to dot */
int
sel_extend(int wiping, int include_dot)
{
    BUFFER *bp = curbp;
    REGIONSHAPE save_shape = regionshape;
    REGION a, b;
    MARK saved_dot;
    MARK working_dot;

    saved_dot = DOT;
    if (valid_buffer(startbufp)) {
	detach_attrib(selbufp, &selregion);
	selbufp = startbufp;
	selregion = startregion;
	attach_attrib(selbufp, &selregion);
	detach_attrib(startbufp, &startregion);
	startbufp = NULL;
    }

    if (curwp->w_bufp != selbufp)
	return FALSE;		/* handles NULL case also */

    fix_dot();
    regionshape = selregion.ar_shape;

    if (wiping && whichend == END_FIXED)
	MK = selregion.ar_region.r_end;
    else
	MK = selregion.ar_region.r_orig;

    /* FIXME: Make sure DOT and MK are in the same buffer */

    /*
     * If we're extending in the positive direction, we want to include DOT
     * in the selection.  To include DOT, we must advance it one char since
     * a region runs from r_orig up to but not including r_end.
     */
    working_dot = DOT;
    if (include_dot
	&& (selregion.ar_shape == rgn_EXACT)
	&& dot_vs_mark() >= 0) {
	if (samepoint(MK, orig_region)) {
	    DOT.o += BytesAt(DOT.l, DOT.o);
	} else if (samepoint(MK, plus_region)) {
	    DOT.o += BytesAt(DOT.l, DOT.o);
	    MK = orig_region;
	}
    }
    if (getregion(bp, &a) == FALSE) {
	return FALSE;
    }
    DOT = working_dot;

    /*
     * Build a second region in the "opposite" direction.
     */
    if (wiping && whichend == ORIG_FIXED)
	MK = selregion.ar_region.r_orig;
    else
	MK = selregion.ar_region.r_end;

    if (include_dot) {
	if (selregion.ar_shape == rgn_EXACT) {
	    if (dot_vs_mark() <= 0) {
		if (samepoint(MK, orig_region))
		    MK.o += BytesAt(MK.l, MK.o);
	    }
	} else if (selregion.ar_shape == rgn_RECTANGLE) {
	    if (samepoint(MK, DOT)) {	/* avoid making empty-region */
		MK = orig_region;
		DOT = plus_region;
	    }
	}
    }
    if (getregion(bp, &b) == FALSE) {
	return FALSE;
    }

    /*
     * The two regions, 'a' and 'b' are _usually_ identical, except for the
     * special case where we've extended one to the right to include the
     * right endpoint of the region.
     *
     * For rgn_EXACT selections, setting 'whichend' to ORIG_FIXED means that
     * we're selecting from the anchor point right/down.  Conversely,
     * setting it to END_FIXED means that we selecting left/up.
     *
     * Rectangles are specified by making MK the opposite corner from DOT.
     * If DOT is below MK, we'll say that the selection region is
     * ORIG_FIXED so that the next call on this function will build the
     * regions a/b consistently.
     *
     * If the regions a/b are empty, we've made a mistake; this will cause
     * the selection to be dropped in xvile.
     */

    if (a.r_size > b.r_size) {
	whichend = ORIG_FIXED;
	selregion.ar_region = a;
    } else {
	if (selregion.ar_shape == rgn_RECTANGLE) {
	    if (dot_vs_mark() < 0)
		whichend = END_FIXED;
	    else
		whichend = ORIG_FIXED;
	} else {		/* exact or full-line */
	    whichend = END_FIXED;
	}
	selregion.ar_region = b;
    }

    selregion.ar_vattr = VASEL | VOWN_SELECT;
    mark_buffers_windows(selbufp);

    show_selection_position(FALSE);

    regionshape = save_shape;
    DOT = saved_dot;
    OWN_SELECTION();
    return TRUE;
}
Ejemplo n.º 19
0
int
var_BCHANGED(TBUFF **rp, const char *vp)
{
    return any_ro_BOOL(rp, vp, valid_buffer(curbp) && b_is_changed(curbp));
}