예제 #1
0
파일: zle_misc.c 프로젝트: zsh-users/zsh
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;
}
예제 #2
0
파일: zle_vi.c 프로젝트: MPOWER4RU/zsh
int
viyank(UNUSED(char **args))
{
    int c2, ret = 1;

    startvichange(1);
    if ((c2 = getvirange(0)) != -1) {
	cut(zlecs, c2 - zlecs, CUT_YANK);
	ret = 0;
    }
    vichgflag = 0;
    /* cursor now at the start of the range yanked. For line mode
     * restore the column position */
    if (vilinerange && lastcol != -1) {
	int x = findeol();

	if ((zlecs += lastcol) >= x) {
	    zlecs = x;
	    if (zlecs > findbol() && invicmdmode())
		DECCS();
	}
#ifdef MULTIBYTE_SUPPORT
	else
	    CCRIGHT();
#endif
	lastcol = -1;
    }
    return ret;
}
예제 #3
0
파일: zle_vi.c 프로젝트: MPOWER4RU/zsh
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;
}
예제 #4
0
파일: zle_misc.c 프로젝트: MPOWER4RU/zsh
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;
}
예제 #5
0
파일: zle_vi.c 프로젝트: Osse/zsh
int
vicmdmode(UNUSED(char **args))
{
    if (invicmdmode() || selectkeymap("vicmd", 0))
	return 1;
    mergeundo();
    vichgflag = 0;
    if (zlecs != findbol())
	DECCS();
    return 0;
}
예제 #6
0
파일: zle_word.c 프로젝트: zsh-users/zsh
int
vibackwardblankwordend(char **args)
{
    int n = zmult;

    if (n < 0) {
	int ret;
	zmult = -n;
	ret = viforwardblankwordend(args);
	zmult = n;
	return ret;
    }
    while (n--) {
	while (zlecs && !ZC_inblank(zleline[zlecs]))
	    DECCS();
	while (zlecs && ZC_inblank(zleline[zlecs]))
	    DECCS();
    }
    return 0;
}
예제 #7
0
파일: zle_word.c 프로젝트: AMDmi3/zsh
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;
}
예제 #8
0
파일: zle_misc.c 프로젝트: MPOWER4RU/zsh
/* 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();
    }
}
예제 #9
0
파일: zle_utils.c 프로젝트: Lujaw/zsh
mod_export void
backkill(int ct, int flags)
{
    UNMETACHECK();
    if (flags & CUT_RAW) {
	zlecs -= ct;
    } else {
	int origcs = zlecs;
	while (ct--)
	    DECCS();
	ct = origcs - zlecs;
    }

    cut(zlecs, ct, flags);
    shiftchars(zlecs, ct);
    CCRIGHT();
}
예제 #10
0
파일: zle_utils.c 프로젝트: Lujaw/zsh
mod_export void
backdel(int ct, int flags)
{
    if (flags & CUT_RAW) {
	if (zlemetaline != NULL) {
	    shiftchars(zlemetacs -= ct, ct);
	} else {
	    shiftchars(zlecs -= ct, ct);
	    CCRIGHT();
	}
    } else {
	int n = ct, origcs = zlecs;
	DPUTS(zlemetaline != NULL, "backdel needs CUT_RAW when metafied");
	while (n--)
	    DECCS();
	shiftchars(zlecs, origcs - zlecs);
	CCRIGHT();
    }
}
예제 #11
0
파일: zle_vi.c 프로젝트: Osse/zsh
int
videlete(UNUSED(char **args))
{
    int c2, ret = 1;

    startvichange(1);
    if ((c2 = getvirange(0)) != -1) {
	forekill(c2 - zlecs, CUT_RAW);
	ret = 0;
	if (vilinerange && zlell) {
	    if (zlecs == zlell)
		DECCS();
	    foredel(1, 0);
	    vifirstnonblank(zlenoargs);
	}
    }
    vichgflag = 0;
    return ret;
}
예제 #12
0
파일: zle_vi.c 프로젝트: Osse/zsh
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;
}
예제 #13
0
파일: zle_word.c 프로젝트: zsh-users/zsh
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;
}
예제 #14
0
void
zlecore(void)
{
    Keymap km;
#if !defined(HAVE_POLL) && defined(HAVE_SELECT)
    struct timeval tv;
    fd_set foofd;

    FD_ZERO(&foofd);
#endif

    pushheap();

    /*
     * A widget function may decide to exit the shell.
     * We never exit directly from functions, to allow
     * the shell to tidy up, so we have to test for
     * that explicitly.
     */
    while (!done && !errflag && !exit_pending) {
	UNMETACHECK();

	statusline = NULL;
	vilinerange = 0;
	reselectkeymap();
	selectlocalmap(invicmdmode() && region_active && (km = openkeymap("visual"))
	    ? km : NULL);
	bindk = getkeycmd();
	selectlocalmap(NULL);
	if (bindk) {
	    if (!zlell && isfirstln && !(zlereadflags & ZLRF_IGNOREEOF) &&
		lastchar == eofchar) {
		/*
		 * Slight hack: this relies on getkeycmd returning
		 * a value for the EOF character.  However,
		 * undefined-key is fine.  That's necessary because
		 * otherwise we can't distinguish this case from
		 * a ^C.
		 */
		eofsent = 1;
		break;
	    }
	    if (execzlefunc(bindk, zlenoargs, 0)) {
		handlefeep(zlenoargs);
		if (eofsent)
		    break;
	    }
	    handleprefixes();
	    /* for vi mode, make sure the cursor isn't somewhere illegal */
	    if (invicmdmode() && zlecs > findbol() &&
		(zlecs == zlell || zleline[zlecs] == ZWC('\n')))
		DECCS();
	    handleundo();
	} else {
	    errflag |= ERRFLAG_ERROR;
	    break;
	}
#ifdef HAVE_POLL
	if (baud && !(lastcmd & ZLE_MENUCMP)) {
	    struct pollfd pfd;
	    int to = cost * costmult / 1000; /* milliseconds */

	    if (to > 500)
		to = 500;
	    pfd.fd = SHTTY;
	    pfd.events = POLLIN;
	    if (!kungetct && poll(&pfd, 1, to) <= 0)
		zrefresh();
	} else
#else
# ifdef HAVE_SELECT
	if (baud && !(lastcmd & ZLE_MENUCMP)) {
	    FD_SET(SHTTY, &foofd);
	    tv.tv_sec = 0;
	    if ((tv.tv_usec = cost * costmult) > 500000)
		tv.tv_usec = 500000;
	    if (!kungetct && select(SHTTY+1, (SELECT_ARG_2_T) & foofd,
				    NULL, NULL, &tv) <= 0)
		zrefresh();
	} else
# endif
#endif
	    if (!kungetct)
		zrefresh();

	freeheap();
    }

    region_active = 0;
    popheap();
}