Exemple #1
0
int
capitalizeword(UNUSED(char **args))
{
    int first, n = zmult;
    int neg = n < 0, ocs = zlecs;

    if (neg)
	n = -n;
    while (n--) {
	first = 1;
	while (zlecs != zlell && !ZC_iword(zleline[zlecs]))
	    INCCS();
	while (zlecs != zlell && ZC_iword(zleline[zlecs]) && !ZC_ialpha(zleline[zlecs]))
	    INCCS();
	while (zlecs != zlell && ZC_iword(zleline[zlecs])) {
	    zleline[zlecs] = (first) ? ZC_toupper(zleline[zlecs]) :
		ZC_tolower(zleline[zlecs]);
	    first = 0;
	    INCCS();
	}
    }
    if (neg)
	zlecs = ocs;
    return 0;
}
Exemple #2
0
int
viforwardword(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = vibackwardword(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	int nl;
	int cc = wordclass(zleline[zlecs]);
	while (zlecs != zlell && wordclass(zleline[zlecs]) == cc) {
	    INCCS();
	}
	if (wordflag && !n)
	    return 0;
	nl = (zleline[zlecs] == ZWC('\n'));
	while (zlecs != zlell && nl < 2 && ZC_inblank(zleline[zlecs])) {
	    INCCS();
	    nl += (zleline[zlecs] == ZWC('\n'));
	}
    }
    return 0;
}
Exemple #3
0
int
viforwardword(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = backwardword(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	int nl;
	if (Z_vialnum(zleline[zlecs]))
	    while (zlecs != zlell && Z_vialnum(zleline[zlecs]))
		INCCS();
	else
	    while (zlecs != zlell && !Z_vialnum(zleline[zlecs]) &&
		    !ZC_inblank(zleline[zlecs]))
		INCCS();
	if (wordflag && !n)
	    return 0;
	nl = (zleline[zlecs] == ZWC('\n'));
	while (zlecs != zlell && nl < 2 && ZC_inblank(zleline[zlecs])) {
	    INCCS();
	    nl += (zleline[zlecs] == ZWC('\n'));
	}
    }
    return 0;
}
Exemple #4
0
int
transposechars(UNUSED(char **args))
{
    int ct;
    int n = zmult;
    int neg = n < 0;

    if (neg)
	n = -n;
    while (n--) {
	if (!(ct = zlecs) || zleline[zlecs - 1] == '\n') {
	    if (zlell == zlecs || zleline[zlecs] == '\n')
		return 1;
	    if (!neg)
		INCCS();
	    INCPOS(ct);
	}
	if (neg) {
	    if (zlecs && zleline[zlecs - 1] != '\n') {
		DECCS();
		if (ct > 1 && zleline[ct - 2] != '\n') {
		    DECPOS(ct);
		}
	    }
	} else {
	    if (zlecs != zlell && zleline[zlecs] != '\n')
		INCCS();
	}
	if (ct == zlell || zleline[ct] == '\n') {
	    DECPOS(ct);
	}
	if (ct < 1 || zleline[ct - 1] == '\n')
	    return 1;
#ifdef MULTIBYTE_SUPPORT
	{
	    /*
	     * We should keep any accents etc. on their original characters.
	     */
	    int start = ct, end = ct;
	    DECPOS(start);
	    INCPOS(end);

	    transpose_swap(start, ct, end);
	}
#else
	{
	    ZLE_CHAR_T cc = zleline[ct - 1];
	    zleline[ct - 1] = zleline[ct];
	    zleline[ct] = cc;
	}
#endif
    }
    return 0;
}
Exemple #5
0
int
vioperswapcase(UNUSED(char **args))
{
    int oldcs, c2, ret = 1;

    /* get the range */
    startvichange(1);
    if ((c2 = getvirange(0)) != -1) {
	oldcs = zlecs;
	/* swap the case of all letters within range */
	while (zlecs < c2) {
	    if (ZC_ilower(zleline[zlecs]))
		zleline[zlecs] = ZC_toupper(zleline[zlecs]);
	    else if (ZC_iupper(zleline[zlecs]))
		zleline[zlecs] = ZC_tolower(zleline[zlecs]);
	    INCCS();
	}
	/* go back to the first line of the range */
	zlecs = oldcs;
	ret = 0;
#if 0
	vifirstnonblank();
#endif
    }
    vichgflag = 0;
    return ret;
}
Exemple #6
0
int
killregion(UNUSED(char **args))
{
    if (mark > zlell)
	mark = zlell;
    if (region_active == 2) {
	int a, b;
	regionlines(&a, &b);
	zlecs = a;
	region_active = 0;
	cut(zlecs, b - zlecs, CUT_RAW);
	shiftchars(zlecs, b - zlecs);
	if (zlell) {
	    if (zlecs == zlell)
		DECCS();
	    foredel(1, 0);
	    vifirstnonblank(zlenoargs);
	}
    } else if (mark > zlecs) {
	if (invicmdmode())
	    INCPOS(mark);
	forekill(mark - zlecs, CUT_RAW);
    } else {
	if (invicmdmode())
	    INCCS();
	backkill(zlecs - mark, CUT_FRONT|CUT_RAW);
    }
    return 0;
}
Exemple #7
0
int
viforwardblankwordend(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = vibackwardblankwordend(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	while (zlecs != zlell) {
	    int pos = zlecs;
	    INCPOS(pos);
	    if (!ZC_inblank(zleline[pos]))
		break;
	    zlecs = pos;
	}
	while (zlecs != zlell) {
	    int pos = zlecs;
	    INCPOS(pos);
	    if (ZC_inblank(zleline[pos]))
		break;
	    zlecs = pos;
	}
    }
    if (zlecs != zlell && virangeflag)
	INCCS();
    return 0;
}
Exemple #8
0
int
viputafter(UNUSED(char **args))
{
    Cutbuffer buf = &cutbuf;
    int n = zmult;

    startvichange(-1);
    if (n < 0)
	return 1;
    if (zmod.flags & MOD_VIBUF)
	buf = &vibuf[zmod.vibuf];
    if (!buf->buf)
	return 1;
    if(buf->flags & CUTBUFFER_LINE) {
	zlecs = findeol();
	spaceinline(buf->len + 1);
	zleline[zlecs++] = ZWC('\n');
	ZS_memcpy(zleline + zlecs, buf->buf, buf->len);
	vifirstnonblank(zlenoargs);
    } else {
	if (zlecs != findeol())
	    INCCS();
	while (n--) {
	    spaceinline(buf->len);
	    ZS_memcpy(zleline + zlecs, buf->buf, buf->len);
	    zlecs += buf->len;
	}
	if (zlecs)
	    DECCS();
    }
    return 0;
}
Exemple #9
0
static int
dovilinerange(void)
{
    int pos = zlecs, n = zmult;

    /* A number of lines is taken as the range.  The current line *
     * is included.  If the repeat count is positive the lines go *
     * downward, otherwise upward.  The repeat count gives the    *
     * number of lines.                                           */
    vilinerange = 1;
    if (!n)
	return 1;
    if (n > 0) {
	while(n-- && zlecs <= zlell)
	    zlecs = findeol() + 1;
	if (n != -1) {
	    zlecs = pos;
	    return 1;
	}
	DECCS();
    } else {
	while(n++ && zlecs >= 0)
	    zlecs = findbol() - 1;
	if (n != 1) {
	    zlecs = pos;
	    return 1;
	}
	INCCS();
    }
    virangeflag = 2;
    return 0;
}
Exemple #10
0
int
viaddnext(UNUSED(char **args))
{
    if (zlecs != findeol())
	INCCS();
    startvitext(1);
    return 0;
}
Exemple #11
0
int
downcaseword(UNUSED(char **args))
{
    int n = zmult;
    int neg = n < 0, ocs = zlecs;

    if (neg)
	n = -n;
    while (n--) {
	while (zlecs != zlell && !ZC_iword(zleline[zlecs]))
	    INCCS();
	while (zlecs != zlell && ZC_iword(zleline[zlecs])) {
	    zleline[zlecs] = ZC_tolower(zleline[zlecs]);
	    INCCS();
	}
    }
    if (neg)
	zlecs = ocs;
    return 0;
}
Exemple #12
0
int
forwardword(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = backwardword(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	while (zlecs != zlell && ZC_iword(zleline[zlecs]))
	    INCCS();
	if (wordflag && !n)
	    return 0;
	while (zlecs != zlell && !ZC_iword(zleline[zlecs]))
	    INCCS();
    }
    return 0;
}
Exemple #13
0
int
gosmacstransposechars(UNUSED(char **args))
{
    if (zlecs < 2 || zleline[zlecs - 1] == '\n' || zleline[zlecs - 2] == '\n') {
	int twice = (zlecs == 0 || zleline[zlecs - 1] == '\n');

	if (zlecs == zlell || zleline[zlecs] == '\n')
	    return 1;

	INCCS();
	if (twice) {
	    if (zlecs == zlell || zleline[zlecs] == '\n')
		return 1;
	    INCCS();
	}
    }
#ifdef MULTIBYTE_SUPPORT
    {
	int start, middle;

	middle = zlecs;
	DECPOS(middle);

	start = middle;
	DECPOS(start);

	transpose_swap(start, middle, zlecs);
    }
#else
    {
	ZLE_CHAR_T cc = zleline[zlecs - 2];
	zleline[zlecs - 2] = zleline[zlecs - 1];
	zleline[zlecs - 1] = cc;
    }
#endif
    return 0;
}
Exemple #14
0
int
viforwardwordend(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = vibackwardwordend(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	int pos;
	while (zlecs != zlell) {
	    pos = zlecs;
	    INCPOS(pos);
	    if (!ZC_inblank(zleline[pos]))
		break;
	    zlecs = pos;
	}
	if (zlecs != zlell) {
	    pos = zlecs;
	    INCPOS(pos);
	    if (Z_vialnum(zleline[pos])) {
		for (;;) {
		    zlecs = pos;
		    if (zlecs == zlell)
			break;
		    INCPOS(pos);
		    if (!Z_vialnum(zleline[pos]))
			break;
		}
	    } else {
		for (;;) {
		    zlecs = pos;
		    if (zlecs == zlell)
			break;
		    INCPOS(pos);
		    if (Z_vialnum(zleline[pos]) || ZC_inblank(zleline[pos]))
			break;
		}
	    }
	}
    }
    if (zlecs != zlell && virangeflag)
	INCCS();
    return 0;
}
Exemple #15
0
int
vibackwardword(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = backwardword(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	int nl = 0;
	while (zlecs) {
	    DECCS();
	    if (!ZC_inblank(zleline[zlecs]))
		break;
	    nl += (zleline[zlecs] == ZWC('\n'));
	    if (nl == 2) {
		INCCS();
		break;
	    }
	}
	if (zlecs) {
	    int pos = zlecs;
	    if (Z_vialnum(zleline[pos])) {
		for (;;) {
		    zlecs = pos;
		    if (zlecs == 0)
			break;
		    DECPOS(pos);
		    if (!Z_vialnum(zleline[pos]))
			break;
		}
	    } else {
		for (;;) {
		    zlecs = pos;
		    if (zlecs == 0)
			break;
		    DECPOS(pos);
		    if (Z_vialnum(zleline[pos]) || ZC_inblank(zleline[pos]))
			break;
		}
	    }
	}
    }
    return 0;
}
Exemple #16
0
/* position: 0 is before, 1 after, 2 split the line */
static void pastebuf(Cutbuffer buf, int mult, int position)
{
    int cc;
    if (buf->flags & CUTBUFFER_LINE) {
	if (position == 2) {
	    if (!zlecs)
		position = 0;
	    else if (zlecs == zlell)
		position = 1;
	}
	if (position == 2) {
	    yankb = zlecs;
	    spaceinline(buf->len + 2);
	    zleline[zlecs++] = ZWC('\n');
	    ZS_memcpy(zleline + zlecs, buf->buf, buf->len);
	    zlecs += buf->len;
	    zleline[zlecs] = ZWC('\n');
	    yanke = zlecs + 1;
	} else if (position != 0) {
	    yankb = zlecs = findeol();
	    spaceinline(buf->len + 1);
	    zleline[zlecs++] = ZWC('\n');
	    yanke = zlecs + buf->len;
	    ZS_memcpy(zleline + zlecs, buf->buf, buf->len);
	} else {
	    yankb = zlecs = findbol();
	    spaceinline(buf->len + 1);
	    ZS_memcpy(zleline + zlecs, buf->buf, buf->len);
	    yanke = zlecs + buf->len + 1;
	    zleline[zlecs + buf->len] = ZWC('\n');
	}
	vifirstnonblank(zlenoargs);
    } else {
	if (position == 1 && zlecs != findeol())
	    INCCS();
	yankb = zlecs;
	cc = buf->len;
	while (mult--) {
	    spaceinline(cc);
	    ZS_memcpy(zleline + zlecs, buf->buf, cc);
	    zlecs += cc;
	}
	yanke = zlecs;
	if (zlecs && invicmdmode())
	    DECCS();
    }
}
Exemple #17
0
mod_export void
forekill(int ct, int flags)
{
    int i = zlecs;

    UNMETACHECK();
    if (!(flags & CUT_RAW)) {
	int n = ct;
	while (n--)
	    INCCS();
	ct = zlecs - i;
	zlecs = i;
    }

    cut(i, ct, flags);
    shiftchars(i, ct);
    CCRIGHT();
}
Exemple #18
0
int
viswapcase(UNUSED(char **args))
{
    int eol, n = zmult;

    startvichange(-1);
    if (n < 1)
	return 1;
    eol = findeol();
    while (zlecs < eol && n--) {
	if (ZC_ilower(zleline[zlecs]))
	    zleline[zlecs] = ZC_toupper(zleline[zlecs]);
	else if (ZC_iupper(zleline[zlecs]))
	    zleline[zlecs] = ZC_tolower(zleline[zlecs]);
	INCCS();
    }
    if (zlecs && zlecs == eol)
	DECCS();
    return 0;
}
Exemple #19
0
int
vidowncase(UNUSED(char **args))
{
    int oldcs, c2, ret = 1;

    /* get the range */
    startvichange(1);
    if ((c2 = getvirange(0)) != -1) {
	oldcs = zlecs;
	/* convert the case of all letters within range */
	while (zlecs < c2) {
	    zleline[zlecs] = ZC_tolower(zleline[zlecs]);
	    INCCS();
	}
	/* go back to the first line of the range */
	zlecs = oldcs;
	ret = 0;
    }
    vichgflag = 0;
    return ret;
}
Exemple #20
0
int
deletechar(char **args)
{
    int n;
    if (zmult < 0) {
	int ret;
	zmult = -zmult;
	ret = backwarddeletechar(args);
	zmult = -zmult;
	return ret;
    }

    n = zmult;
    while (n--) {
	if (zlecs == zlell)
	    return 1;
	INCCS();
    }
    backdel(zmult, 0);
    return 0;
}
Exemple #21
0
int
viforwardwordend(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = vibackwardwordend(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	int pos;
	while (zlecs != zlell) {
	    pos = zlecs;
	    INCPOS(pos);
	    if (!ZC_inblank(zleline[pos]))
		break;
	    zlecs = pos;
	}
	if (zlecs != zlell) {
	    int cc;
	    pos = zlecs;
	    INCPOS(pos);
	    cc = wordclass(zleline[pos]);
	    for (;;) {
		zlecs = pos;
		if (zlecs == zlell)
		    break;
		INCPOS(pos);
		if (wordclass(zleline[pos]) != cc)
			break;
	    }
	}
    }
    if (zlecs != zlell && virangeflag)
	INCCS();
    return 0;
}
Exemple #22
0
int
vibackwardword(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = viforwardword(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	int nl = 0;
	while (zlecs) {
	    DECCS();
	    if (!ZC_inblank(zleline[zlecs]))
		break;
	    nl += (zleline[zlecs] == ZWC('\n'));
	    if (nl == 2) {
		INCCS();
		break;
	    }
	}
	if (zlecs) {
	    int pos = zlecs;
	    int cc = wordclass(zleline[pos]);
	    for (;;) {
		zlecs = pos;
		if (zlecs == 0)
		    break;
		DECPOS(pos);
		if (wordclass(zleline[pos]) != cc || ZC_inblank(zleline[pos]))
		    break;
	    }
	}
    }
    return 0;
}
Exemple #23
0
mod_export void
foredel(int ct, int flags)
{
    if (flags & CUT_RAW) {
	if (zlemetaline != NULL) {
	    shiftchars(zlemetacs, ct);
	} else if (flags & CUT_RAW) {
	    shiftchars(zlecs, ct);
	    CCRIGHT();
	}
    } else {
	int origcs = zlecs;
	int n = ct;
	DPUTS(zlemetaline != NULL, "foredel needs CUT_RAW when metafied");
	while (n--)
	    INCCS();
	ct = zlecs - origcs;
	zlecs = origcs;
	shiftchars(zlecs, ct);
	CCRIGHT();
    }
}
Exemple #24
0
static int
getvirange(int wf)
{
    int pos = zlecs, ret = 0;
    int mult1 = zmult, hist1 = histline;
    Thingy k2;

    virangeflag = 1;
    wordflag = wf;
    /* Now we need to execute the movement command, to see where it *
     * actually goes.  virangeflag here indicates to the movement   *
     * function that it should place the cursor at the end of the   *
     * range, rather than where the cursor would actually go if it  *
     * were executed normally.  This makes a difference to some     *
     * commands, but not all.  For example, if searching forward    *
     * for a character, under normal circumstances the cursor lands *
     * on the character.  For a range, the range must include the   *
     * character, so the cursor gets placed after the character if  *
     * virangeflag is set.  vi-match-bracket needs to change the    *
     * value of virangeflag under some circumstances, meaning that  *
     * we need to change the *starting* position.                   */
    zmod.flags &= ~MOD_TMULT;
    do {
	vilinerange = 0;
	prefixflag = 0;
	if (!(k2 = getkeycmd()) || (k2->flags & DISABLED) ||
		k2 == Th(z_sendbreak)) {
	    wordflag = 0;
	    virangeflag = 0;
	    return -1;
	}
	/*
	 * With k2 == bindk, the command key is repeated:
	 * a number of lines is used.  If the function used
	 * returns 1, we fail.
	 */
	if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs, 1))
	    ret = -1;
	if(vichgrepeat)
	    zmult = mult1;
	else
	    zmult = mult1 * zmod.tmult;
    } while(prefixflag && !ret);
    wordflag = 0;
    virangeflag = 0;

    /* It is an error to use a non-movement command to delimit the *
     * range.  We here reject the case where the command modified  *
     * the line, or selected a different history line.             */
    if (histline != hist1 || zlell != lastll || memcmp(zleline, lastline, zlell)) {
	histline = hist1;
	ZS_memcpy(zleline, lastline, zlell = lastll);
	zlecs = pos;
	return -1;
    }

    /* Can't handle an empty file.  Also, if the movement command *
     * failed, or didn't move, it is an error.                    */
    if (!zlell || (zlecs == pos && virangeflag != 2) || ret == -1)
	return -1;

    /* vi-match-bracket changes the value of virangeflag when *
     * moving to the opening bracket, meaning that we need to *
     * change the *starting* position.                        */
    if(virangeflag == -1)
    {
	int origcs = zlecs;
	zlecs = pos;
	INCCS();
	pos = zlecs;
	zlecs = origcs;
    }

    /* Get the range the right way round.  zlecs is placed at the *
     * start of the range, and pos (the return value of this   *
     * function) is the end.                                   */
    if (zlecs > pos) {
	int tmp = zlecs;
	zlecs = pos;
	pos = tmp;
    }

    /* Was it a line-oriented move?  If so, the command will have set *
     * the vilinerange flag.  In this case, entire lines are taken,   *
     * rather than just the sequence of characters delimited by pos   *
     * and zlecs.  The terminating newline is left out of the range,     *
     * which the real command must deal with appropriately.  At this  *
     * point we just need to make the range encompass entire lines.   */
    if(vilinerange) {
	int newcs = findbol();
	zlecs = pos;
	pos = findeol();
	zlecs = newcs;
    }
    return pos;
}