示例#1
0
文件: zle_misc.c 项目: MPOWER4RU/zsh
int
copyregionaskill(char **args)
{
    int start, end;
    if (*args) {
        int len;
        ZLE_STRING_T line = stringaszleline(*args, 0, &len, NULL, NULL);
	cuttext(line, len, CUT_REPLACE);
	free(line);
    } else {
	if (mark > zlell)
	    mark = zlell;
	if (mark > zlecs) {
	    start = zlecs;
	    end = mark;
	} else {
	    start = mark;
	    end = zlecs;
	}
	if (invicmdmode())
	    INCPOS(end);
	cut(start, end - start, mark > zlecs ? 0 : CUT_FRONT);
    }
    return 0;
}
示例#2
0
文件: zle_misc.c 项目: MPOWER4RU/zsh
int
bracketedpaste(char **args)
{
    char *pbuf = bracketedstring();

    if (*args) {
	setsparam(*args, pbuf);
    } else {
	int n;
	ZLE_STRING_T wpaste;
	wpaste = stringaszleline((zmult == 1) ? pbuf :
	    quotestring(pbuf, NULL, QT_SINGLE_OPTIONAL), 0, &n, NULL, NULL);
	cuttext(wpaste, n, CUT_REPLACE);
	if (!(zmod.flags & MOD_VIBUF)) {
	    kct = -1;
	    kctbuf = &cutbuf;
	    zmult = 1;
	    if (region_active)
		killregion(zlenoargs);
	    yankcs = yankb = zlecs;
	    doinsert(wpaste, n);
	    yanke = zlecs;
	}
	free(pbuf); free(wpaste);
    }
    return 0;
}
示例#3
0
文件: zle_utils.c 项目: Lujaw/zsh
void
setline(char *s, int flags)
{
    char *scp;

    UNMETACHECK();
    if (flags & ZSL_COPY)
	scp = ztrdup(s);
    else
	scp = s;
    /*
     * TBD: we could make this more efficient by passing the existing
     * allocated line to stringaszleline.
     */
    free(zleline);

    zleline = stringaszleline(scp, 0, &zlell, &linesz, NULL);

    if ((flags & ZSL_TOEND) && (zlecs = zlell) && invicmdmode())
	DECCS();
    else if (zlecs > zlell)
	zlecs = zlell;
    CCRIGHT();
    if (flags & ZSL_COPY)
	free(scp);
}
示例#4
0
文件: zle_misc.c 项目: MPOWER4RU/zsh
int
copyprevshellword(UNUSED(char **args))
{
    LinkList l;
    LinkNode n;
    int i;
    char *p = NULL;

    if (zmult <= 0)
	return 1;

    if ((l = bufferwords(NULL, NULL, &i, LEXFLAGS_ZLE))) {
	i -= (zmult-1);
	if (i < 0)
	    return 1;
        for (n = firstnode(l); n; incnode(n))
            if (!i--) {
                p = getdata(n);
                break;
            }
    }

    if (p) {
	int len;
	ZLE_STRING_T lineadd = stringaszleline(p, 0, &len, NULL, NULL);

	spaceinline(len);
	ZS_memcpy(zleline + zlecs, lineadd, len);
	zlecs += len;

	free(lineadd);
    }
    return 0;
}
示例#5
0
文件: zle_misc.c 项目: Jaharmi/zsh
mod_export void
makesuffixstr(char *f, char *s, int n)
{
    if (f) {
	zsfree(suffixfunc);
	suffixfunc = ztrdup(f);
	suffixfunclen = n;
    } else if (s) {
	int inv, i, z = 0;
	ZLE_STRING_T ws, lasts, wptr;

	if (*s == '^' || *s == '!') {
	    inv = 1;
	    s++;
	} else
	    inv = 0;
	s = getkeystring(s, &i, GETKEYS_SUFFIX, &z);
	s = metafy(s, i, META_USEHEAP);
	ws = stringaszleline(s, 0, &i, NULL, NULL);

	if (z)
	    suffixnoinslen = inv ? 0 : n;
	else if (inv) {
	    /*
	     * negative match, \- wasn't present, so it *should*
	     * have this suffix length
	     */
	    suffixnoinslen = n;
	}

	lasts = wptr = ws;
	while (i) {
	    if (i >= 3 && wptr[1] == ZWC('-')) {
		ZLE_CHAR_T str[2];

		if (wptr > lasts)
		    addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, 0,
			      lasts, wptr - lasts, n);
		str[0] = *wptr;
		str[1] = wptr[2];
		addsuffix(inv ? SUFTYP_NEGRNG : SUFTYP_POSRNG, 0,
			  str, 2, n);

		wptr += 3;
		i -= 3;
		lasts = wptr;
	    } else {
		wptr++;
		i--;
	    }
	}
	if (wptr > lasts)
	    addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, 0,
		      lasts, wptr - lasts, n);
	free(ws);
    } else
	makesuffix(n);
}
示例#6
0
文件: zle_misc.c 项目: MPOWER4RU/zsh
mod_export void
makesuffixstr(char *f, char *s, int n)
{
    if (f) {
	zsfree(suffixfunc);
	suffixfunc = ztrdup(f);
	suffixfunclen = n;
    } else if (s) {
	int inv, i, z = 0;
	ZLE_STRING_T ws, lasts, wptr;

	if (*s == '^' || *s == '!') {
	    inv = 1;
	    s++;
	} else
	    inv = 0;
	s = getkeystring(s, &i, GETKEYS_SUFFIX, &z);
	s = metafy(s, i, META_USEHEAP);
	ws = stringaszleline(s, 0, &i, NULL, NULL);

	/* Remove suffix on uninsertable characters if  \- was given *
	 * and the character class wasn't negated -- or vice versa.  */
	suffixnoinsrem = z ^ inv;
	suffixlen = n;

	lasts = wptr = ws;
	while (i) {
	    if (i >= 3 && wptr[1] == ZWC('-')) {
		ZLE_CHAR_T str[2];

		if (wptr > lasts)
		    addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, 0,
			      lasts, wptr - lasts, n);
		str[0] = *wptr;
		str[1] = wptr[2];
		addsuffix(inv ? SUFTYP_NEGRNG : SUFTYP_POSRNG, 0,
			  str, 2, n);

		wptr += 3;
		i -= 3;
		lasts = wptr;
	    } else {
		wptr++;
		i--;
	    }
	}
	if (wptr > lasts)
	    addsuffix(inv ? SUFTYP_NEGSTR : SUFTYP_POSSTR, 0,
		      lasts, wptr - lasts, n);
	free(ws);
    } else
	makesuffix(n);
}
示例#7
0
文件: zle_misc.c 项目: MPOWER4RU/zsh
mod_export void
addsuffixstring(int tp, int flags, char *chars, int lensuf)
{
    int slen, alloclen;
    ZLE_STRING_T suffixstr;

    /* string needs to be writable... I've been regretting this for years.. */
    chars = ztrdup(chars);
    suffixstr = stringaszleline(chars, 0, &slen, &alloclen, NULL);
    addsuffix(tp, flags, suffixstr, slen, lensuf);
    zfree(suffixstr, alloclen);
    zsfree(chars);
}
示例#8
0
static void
set_prepost(ZLE_STRING_T *textvar, int *lenvar, char *x)
{
    if (*lenvar) {
	free(*textvar);
	*textvar = NULL;
	*lenvar = 0;
    }
    if (x) {
	*textvar = stringaszleline(x, 0, lenvar, NULL, NULL);
	free(x);
    }
}
示例#9
0
static void
set_cutbuffer(UNUSED(Param pm), char *x)
{
    if (cutbuf.buf)
	free(cutbuf.buf);
    cutbuf.flags = 0;
    if (x) {
	int n;
	cutbuf.buf = stringaszleline(x, 0, &n, NULL, NULL);
	cutbuf.len = n;
	free(x);
    } else {
	cutbuf.buf = NULL;
	cutbuf.len = 0;
    }
}
示例#10
0
static zlong
get_cursor(UNUSED(Param pm))
{
    if (zlemetaline != NULL) {
	/* A lot of work for one number, but still... */
	ZLE_STRING_T tmpline;
	int tmpcs, tmpll, tmpsz;
	char *tmpmetaline = ztrdup(zlemetaline);
	tmpline = stringaszleline(tmpmetaline, zlemetacs,
				  &tmpll, &tmpsz, &tmpcs);
	free(tmpmetaline);
	free(tmpline);
	return tmpcs;
    }
    return zlecs;
}
示例#11
0
static void
set_rbuffer(UNUSED(Param pm), char *x)
{
    ZLE_STRING_T y;
    int len;

    if (x && *x != ZWC('\0'))
	y = stringaszleline(x, 0, &len, NULL, NULL);
    else
	y = ZWS(""), len = 0;
    sizeline(zlell = zlecs + len);
    ZS_memcpy(zleline + zlecs, y, len);
    zsfree(x);
    if (len)
	free(y);
    fixsuffix();
    menucmp = 0;
}
示例#12
0
文件: zle_misc.c 项目: Jaharmi/zsh
int
copyregionaskill(char **args)
{
    if (*args) {
        int len;
        ZLE_STRING_T line = stringaszleline(*args, 0, &len, NULL, NULL);
	cuttext(line, len, CUT_REPLACE);
	free(line);
    } else {
	if (mark > zlell)
	    mark = zlell;
	if (mark > zlecs)
	    cut(zlecs, mark - zlecs, 0);
	else
	    cut(mark, zlecs - mark, CUT_FRONT);
    }
    return 0;
}
示例#13
0
static void
set_killring(UNUSED(Param pm), char **x)
{
    int kcnt;
    Cutbuffer kptr;
    char **p;

    if (kring) {
	for (kptr = kring, kcnt = 0; kcnt < kringsize; kcnt++, kptr++)
	    if (kptr->buf)
		free(kptr->buf);
	zfree(kring, kringsize * sizeof(struct cutbuffer));
	kring = NULL;
	kringsize = kringnum = 0;
    }
    if (x) {
	/*
	 * Insert the elements into the kill ring.
	 * Regardless of the old order, we number it with the current
	 * entry first.
	 *
	 * Be careful to add elements by looping backwards; this
	 * fits in with how we cycle the ring.
	 */
	int kpos = 0;
	kringsize = arrlen(x);
	if (kringsize != 0) {
	    kring = (Cutbuffer)zshcalloc(kringsize * sizeof(struct cutbuffer));
	    for (p = x; *p; p++) {
		int n, len = strlen(*p);
		kptr = kring + kpos;

		kptr->buf = stringaszleline(*p, 0, &n, NULL, NULL);
		kptr->len = n;

		zfree(*p, len+1);
		kpos = (kpos + kringsize -1 ) % kringsize;
	    }
	}
	free(x);
    }
}