Ejemplo n.º 1
0
void
virepeatsearch(void)
{
    int hl = histline;
    int t0;
    int n = zmult;
    char *s;

    if (!visrchstr) {
	feep();
	return;
    }
    if (zmult < 0) {
	n = -n;
	visrchsense = -visrchsense;
    }
    t0 = strlen(visrchstr);
    for (;;) {
	hl += visrchsense;
	if (!(s = zle_get_event(hl))) {
	    feep();
	    return;
	}
	if (!metadiffer(s, (char *) line, ll))
	    continue;
	if (*visrchstr == '^') {
	    if (strncmp(s, visrchstr + 1, t0 - 1) != 0)
		continue;
	} else if (!hstrnstr(s, 0, visrchstr, t0, 1, 1))
	    continue;
	if (--n <= 0)
	    break;
    }
    zle_goto_hist(hl);
}
Ejemplo n.º 2
0
void
virepeatfind(void)
{
    int ocs = cs;

    if (!vfinddir) {
	feep();
	return;
    }
    if (zmult < 0) {
	zmult = -zmult;
	virevrepeatfind();
	return;
    }
    while (zmult--) {
	do
	    cs += vfinddir;
	while (cs >= 0 && cs < ll && line[cs] != vfindchar && line[cs] != '\n');
	if (cs < 0 || cs >= ll || line[cs] == '\n') {
	    feep();
	    cs = ocs;
	    return;
	}
    }
    cs += tailadd;
    if (vfinddir == 1 && virangeflag)
	cs++;
}
Ejemplo n.º 3
0
void
vireplacechars(void)
{
    int ch;

    startvichange(1);
    /* get key */
    if((ch = vigetkey()) == -1) {
	vichgflag = 0;
	feep();
	return;
    }
    /* check argument range */
    if (zmult < 0 || zmult + cs > findeol()) {
	vichgflag = 0;
	feep();
	return;
    }
    /* do change */
    if (ch == '\r' || ch == '\n') {
	/* <return> handled specially */
	cs += zmult - 1;
	backkill(zmult - 1, 0);
	line[cs++] = '\n';
    } else {
	while (zmult--)
	    line[cs++] = ch;
	cs--;
    }
    vichgflag = 0;
}
Ejemplo n.º 4
0
void yank() /**/
{
int cc;
char *buf = cutbuf;

	if (!cutbuf) {
		feep();
		return;
	}
	if (mult < 0) return;
	if (vibufspec) {
		vibufspec = tolower(vibufspec);
		vibufspec += (idigit(vibufspec)) ? -'1'+26 : -'a';
		if (!(buf = vibuf[vibufspec])) {
			feep();
			vibufspec = 0;
			return;
		}
		vibufspec = 0;
	}
	yankb = cs;
	while (mult--) {
		kct = kringnum;
		cc = strlen(buf);
		spaceinline(cc);
		strncpy((char *) line+cs,buf,cc);
		cs += cc;
		yanke = cs;
	}
}
Ejemplo n.º 5
0
void
vigotomark(void)
{
    int ch;

    ch = getkey(0);
    if (ch == c)
	ch = 26;
    else {
	if (ch < 'a' || ch > 'z') {
	    feep();
	    return;
	}
	ch -= 'a';
    }
    if (!vimarkline[ch]) {
	feep();
	return;
    }
    if (curhist != vimarkline[ch]) {
	zmult = vimarkline[ch];
	gotmult = 1;
	lastcmd |= ZLE_ARG;
	vifetchhistory();
	if (histline != vimarkline[ch])
	    return;
    }
    cs = vimarkcs[ch];
    if (cs > ll)
	cs = ll;
}
Ejemplo n.º 6
0
void
vimatchbracket(void)
{
    int ocs = cs, dir, ct;
    unsigned char oth, me;

  otog:
    if (cs == ll || line[cs] == '\n') {
	feep();
	cs = ocs;
	return;
    }
    switch (me = line[cs]) {
    case '{':
	dir = 1;
	oth = '}';
	break;
    case /*{*/ '}':
	virangeflag = -virangeflag;
	dir = -1;
	oth = '{'; /*}*/
	break;
    case '(':
	dir = 1;
	oth = ')';
	break;
    case ')':
	virangeflag = -virangeflag;
	dir = -1;
	oth = '(';
	break;
    case '[':
	dir = 1;
	oth = ']';
	break;
    case ']':
	virangeflag = -virangeflag;
	dir = -1;
	oth = '[';
	break;
    default:
	cs++;
	goto otog;
    }
    ct = 1;
    while (cs >= 0 && cs < ll && ct) {
	cs += dir;
	if (line[cs] == oth)
	    ct--;
	else if (line[cs] == me)
	    ct++;
    }
    if (cs < 0 || cs >= ll) {
	feep();
	cs = ocs;
    } else if(dir > 0 && virangeflag)
	cs++;
}
Ejemplo n.º 7
0
void
insertlastword(void)
{
    int n;
    char *s, *t;
    int len;
    Histent he;

/* multiple calls will now search back through the history, pem */
    static char *lastinsert;
    static int lasthist, lastpos;
    int evhist = curhist - 1, save;

    if (lastinsert) {
	int lastlen = ztrlen(lastinsert);
	int pos = cs;

	if (lastpos <= pos &&
	    lastlen == pos - lastpos &&
	    memcmp(lastinsert, (char *)&line[lastpos], lastlen) == 0) {
	    evhist = --lasthist;
	    cs = lastpos;
	    foredel(pos - cs);
	}
	zsfree(lastinsert);
	lastinsert = NULL;
    }
    if (!(he = quietgethist(evhist)) || !he->nwords) {
	feep();
	return;
    }
    if (zmult > 0) {
	n = he->nwords - (zmult - 1);
    } else {
	n = 1 - zmult;
    }
    if (n < 1 || n > he->nwords) {
	feep();
	return;
    }
    s = he->text + he->words[2*n-2];
    t = he->text + he->words[2*n-1];
    save = *t;
    *t = '\0';			/* ignore trailing whitespace */

    lasthist = evhist;
    lastpos = cs;
    lastinsert = ztrdup(s);
    spaceinline(len = ztrlen(s));
    while (len--) {
	line[cs++] = *s == Meta ? *++s ^ 32 : *s;
	s++;
    }

    *t = save;
}
Ejemplo n.º 8
0
void
historybeginningsearchforward(void)
{
    int cpos = cs;		/* save cursor position */
    int hl = histline;
    int n = zmult;
    char *s;

    if (zmult < 0) {
	zmult = -n;
	historybeginningsearchbackward();
	zmult = n;
	return;
    }
    for (;;) {
	hl++;
	if (!(s = zle_get_event(hl))) {
	    feep();
	    return;
	}
	if (metadiffer(s, (char *)line, cs) < (hl == curhist) &&
	    metadiffer(s, (char *)line, ll) && --n <= 0)
	    break;
    }

    zle_goto_hist(hl);
    cs = cpos;
}
Ejemplo n.º 9
0
void
historysearchforward(void)
{
    int hl = histline;
    int n = zmult;
    int t0;
    char *s;

    if (zmult < 0) {
	zmult = -n;
	historysearchbackward();
	zmult = n;
	return;
    }
    if (lastcmd & ZLE_HISTSEARCH)
	t0 = histpos;
    else {
	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
	if (t0 < ll)
	    t0++;
	histpos = t0;
    }
    for (;;) {
	hl++;
	if (!(s = zle_get_event(hl))) {
	    feep();
	    return;
	}
	if (metadiffer(s, (char *) line, t0) < (hl == curhist) &&
	    metadiffer(s, (char *) line, ll) && --n <= 0)
	    break;
    }
    zle_goto_hist(hl);
}
Ejemplo n.º 10
0
void
viquotedinsert(void)
{
#ifndef WINNT
#ifndef HAS_TIO
    struct sgttyb sob;
#endif
#endif /* WINNT */

    spaceinline(1);
    line[cs] = '^';
    refresh();
#ifndef WINNT
#ifndef HAS_TIO
    sob = shttyinfo.sgttyb;
    sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO;
    ioctl(SHTTY, TIOCSETN, &sob);
#endif
#endif /* WINNT */
    c = getkey(0);
#ifndef WINNT
#ifndef HAS_TIO
    setterm();
#endif
#endif /* WINNT */
    foredel(1);
    if(c < 0)
	feep();
    else
	selfinsert();
}
Ejemplo n.º 11
0
void
viputafter(void)
{
    Cutbuffer buf = &cutbuf;

    startvichange(-1);
    if (zmult < 0)
	return;
    if (gotvibufspec)
	buf = &vibuf[vibufspec];
    if (!buf->buf) {
	feep();
	return;
    }
    vilinerange = !!(buf->flags & CUTBUFFER_LINE);
    if (vilinerange) {
	cs = findeol();
	spaceinline(buf->len + 1);
	line[cs++] = '\n';
	memcpy((char *)line + cs, buf->buf, buf->len);
	vifirstnonblank();
    } else {
	if (cs != findeol())
	    cs++;
	while (zmult--) {
	    spaceinline(buf->len);
	    memcpy((char *)line + cs, buf->buf, buf->len);
	    cs += buf->len;
	}
	if (cs)
	    cs--;
    }

}
Ejemplo n.º 12
0
void
viunindent(void)
{
    int oldcs = cs, c2;

    /* get the range */
    startvichange(1);
    if ((c2 = getvirange(0)) == -1) {
	vichgflag = vilinerange = 0;
	return;
    }
    vichgflag = 0;
    /* must be a line range */
    if (!vilinerange) {
	feep();
	cs = oldcs;
	return;
    }
    vilinerange = 0;
    oldcs = cs;
    /* remove a tab from the beginning of each line within range */
    while (cs < c2) {
	if (line[cs] == '\t')
	    foredel(1);
	cs = findeol() + 1;
    }
    /* go back to the first line of the range */
    cs = oldcs;
    vifirstnonblank();
}
Ejemplo n.º 13
0
void vibackwarddeletechar() /**/
{
	if (mult < 0) { mult = -mult; videletechar(); return; }
	if (mult > cs)
		mult = cs;
	if (cs-mult < viinsbegin) { feep(); return; }
	backkill(mult,1);
}
Ejemplo n.º 14
0
int
vigetkey(void)
{
    int cmd;

    if((c = getkey(0)) == EOF) {
	feep();
	return -1;
    }
    cmd = mainbindtab[c];
    if(cmd == z_prefix) {
	char buf[2];
	Key ky;
	buf[0] = c;
	buf[1] = 0;
	ky = (Key) keybindtab->getnode(keybindtab, buf);
	if(!ky)
	    cmd = z_undefinedkey;
	else
	    cmd = ky->func;
    }

    if (cmd < 0 || cmd == z_sendbreak) {
	feep();
	return -1;
    } else if (cmd == z_quotedinsert) {
	if ((c = getkey(0)) == EOF) {
	    feep();
	    return -1;
	}
    } else if(cmd == z_viquotedinsert) {
	char sav = line[cs];

	line[cs] = '^';
	refresh();
	c = getkey(0);
	line[cs] = sav;
	if(c == EOF) {
	    feep();
	    return -1;
	}
    } else if (cmd == z_vicmdmode)
	return -1;
    return c;
}
Ejemplo n.º 15
0
void
vikillline(void)
{
    if (viinsbegin > cs) {
	feep();
	return;
    }
    backdel(cs - viinsbegin);
}
Ejemplo n.º 16
0
void
viendofline(void)
{
    int oldcs = cs;

    if (zmult<1) {
	feep();
	return;
    }
    while(zmult--) {
	if (cs > ll) {
	    cs = oldcs;
	    feep();
	    return;
	}
	cs = findeol() + 1;
    }
    cs--;
}
Ejemplo n.º 17
0
void
vicapslockpanic(void)
{
    feep();
    statusline = "press a lowercase key to continue";
    statusll = strlen(statusline);
    refresh();
    while (!islower(getkey(0)));
    statusline = NULL;
}
Ejemplo n.º 18
0
void
infernexthistory(void)
{
    int t0;
    char *s;

    for (t0 = histline - 2;; t0--) {
	if (!(s = qgetevent(t0))) {
	    feep();
	    return;
	}
	if (! metadiffer(s, (char *) line, ll))
	    break;
    }
    if (!(s = qgetevent(t0 + 1))) {
	feep();
	return;
    }
    zle_goto_hist(t0 + 1);
}
Ejemplo n.º 19
0
void
viyankeol(void)
{
    int x = findeol();

    startvichange(-1);
    if (x == cs) {
	feep();
	return;
    }
    cut(cs, x - cs, 0);
}
Ejemplo n.º 20
0
void
visubstitute(void)
{
    startvichange(1);
    if (zmult < 0) {
	feep();
	return;
    }
    /* it is an error to be on the end of line */
    if (cs == ll || line[cs] == '\n') {
	feep();
	return;
    }
    /* Put argument into the acceptable range -- it is not an error to  *
     * specify a greater count than the number of available characters. */
    if (zmult > findeol() - cs)
	zmult = findeol() - cs;
    /* do the substitution */
    forekill(zmult, 0);
    startvitext(1);
}
Ejemplo n.º 21
0
void
vicmdmode(void)
{
    if (bindtab == altbindtab)
	feep();
    else {
	bindtab = altbindtab;
	undoing = 1;
	vichgflag = 0;
	if (cs != findbol())
	    cs--;
    }
}
Ejemplo n.º 22
0
void
acceptlineanddownhistory(void)
{
    char *s;

    if (!(s = zle_get_event(histline + 1))) {
	feep();
	return;
    }
    pushnode(bufstack, ztrdup(s));
    done = 1;
    stackhist = histline + 1;
}
Ejemplo n.º 23
0
void
visetmark(void)
{
    int ch;

    ch = getkey(0);
    if (ch < 'a' || ch > 'z') {
	feep();
	return;
    }
    ch -= 'a';
    vimarkcs[ch] = cs;
    vimarkline[ch] = histline;
}
Ejemplo n.º 24
0
void videletechar() /**/
{
	if (mult < 0) { mult = -mult; vibackwarddeletechar(); return; }
	if (c == 4 && !ll) {
		eofsent = 1;
		return;
	}
	if (!(cs+mult > ll || line[cs] == '\n')) {
		cs += mult;
		backkill(mult,0);
		if (cs && (cs == ll || line[cs] == '\n')) cs--;
	} else
		feep();
}
Ejemplo n.º 25
0
void quotedinsert() /**/
{
#ifndef TIO
struct sgttyb sob;
	sob = shttyinfo.sgttyb;
	sob.sg_flags = (sob.sg_flags|RAW) & ~ECHO;
	ioctl(SHTTY,TIOCSETN,&sob);
#endif
	c = getkey(0);
#ifndef TIO
	setterm();
#endif
	if (c) selfinsert(); else feep();
}
Ejemplo n.º 26
0
void
vikilleol(void)
{
    int n = findeol() - cs;

    startvichange(-1);
    if (!n) {
	/* error -- line already empty */
	feep();
	return;
    }
    /* delete to end of line */
    forekill(findeol() - cs, 0);
}
Ejemplo n.º 27
0
void viputafter() /**/
{
int cc;
char *buf = cutbuf;

	if (!cutbuf) {
		feep();
		return;
	}
	if (mult < 0) return;
	if (vibufspec) {
		vibufspec = tolower(vibufspec);
		vibufspec += (idigit(vibufspec)) ? -'1'+26 : -'a';
		if (!(buf = vibuf[vibufspec])) {
			feep();
			vibufspec = 0;
			return;
		}
		vibufspec = 0;
	}
	if (strchr(buf,'\n')) {
		cs = findeol();
		if (cs == ll) { spaceinline(1); line[cs] = '\n'; }
	}
	if (cs != ll) cs++;
	yankb = cs;
	while (mult--) {
		kct = kringnum;
		cc = strlen(buf);
		spaceinline(cc);
		strncpy((char *) line+cs,buf,cc);
		cs += cc;
		yanke = cs;
	}
	cs = yankb;
}
Ejemplo n.º 28
0
void
vifetchhistory(void)
{
    if (zmult < 0)
	return;
    if (histline == curhist) {
	if (!gotmult) {
	    cs = ll;
	    cs = findbol();
	    return;
	}
    }
    if (!zle_goto_hist(gotmult ? zmult : curhist) && isset(HISTBEEP))
	feep();
}
Ejemplo n.º 29
0
void deletechar() /**/
{
	if (mult < 0) { mult = -mult; backwarddeletechar(); return; }
	if (c == 4 && !ll)
		{
		eofsent = 1;
		return;
		}
	if (!(cs+mult > ll || line[cs] == '\n'))
		{
		cs += mult;
		backdel(mult);
		}
	else
		feep();
}
Ejemplo n.º 30
0
void
viforwardchar(void)
{
    int lim = findeol() - (bindtab == altbindtab);
    if (zmult < 0) {
	zmult = -zmult;
	vibackwardchar();
	return;
    }
    if (cs >= lim) {
	feep();
	return;
    }
    while (zmult-- && cs < lim)
	cs++;
}