This commit is contained in:
tg 2005-05-25 23:39:10 +00:00
parent cd54ef8f51
commit 541c0caead
1 changed files with 95 additions and 93 deletions

188
edit.c
View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/edit.c,v 1.4 2005/05/25 23:31:05 tg Exp $ */ /** $MirOS: src/bin/mksh/edit.c,v 1.5 2005/05/25 23:39:10 tg Exp $ */
/* $OpenBSD: edit.c,v 1.29 2005/04/13 02:33:08 deraadt Exp $ */ /* $OpenBSD: edit.c,v 1.29 2005/04/13 02:33:08 deraadt Exp $ */
/* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */ /* $OpenBSD: edit.h,v 1.8 2005/03/28 21:28:22 deraadt Exp $ */
/* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: emacs.c,v 1.37 2005/03/30 17:16:37 deraadt Exp $ */
@ -10,7 +10,7 @@
#include <ctype.h> #include <ctype.h>
#include <libgen.h> #include <libgen.h>
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.4 2005/05/25 23:31:05 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.5 2005/05/25 23:39:10 tg Exp $");
#define BEL 0x07 #define BEL 0x07
@ -87,28 +87,27 @@ x_sigwinch(int sig __attribute__((unused)))
static void static void
check_sigwinch(void) check_sigwinch(void)
{ {
struct winsize ws; struct winsize ws;
got_sigwinch = 0; got_sigwinch = 0;
if (procpid == kshpid && ioctl(tty_fd, TIOCGWINSZ, &ws) >= 0) { if (procpid == kshpid && ioctl(tty_fd, TIOCGWINSZ, &ws) >= 0) {
struct tbl *vp; struct tbl *vp;
/* Do NOT export COLUMNS/LINES. Many applications /* Do NOT export COLUMNS/LINES. Many applications
* check COLUMNS/LINES before checking ws.ws_col/row, * check COLUMNS/LINES before checking ws.ws_col/row,
* so if the app is started with C/L in the environ * so if the app is started with C/L in the environ
* and the window is then resized, the app won't * and the window is then resized, the app won't
* see the change cause the environ doesn't change. * see the change cause the environ doesn't change.
*/ */
if (ws.ws_col) { if (ws.ws_col) {
x_cols = ws.ws_col < MIN_COLS ? MIN_COLS : x_cols = ws.ws_col < MIN_COLS ? MIN_COLS : ws.ws_col;
ws.ws_col;
if ((vp = typeset("COLUMNS", 0, 0, 0, 0))) if ((vp = typeset("COLUMNS", 0, 0, 0, 0)))
setint(vp, (long) ws.ws_col); setint(vp, (long) ws.ws_col);
}
if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
setint(vp, (long) ws.ws_row);
} }
if (ws.ws_row && (vp = typeset("LINES", 0, 0, 0, 0)))
setint(vp, (long) ws.ws_row);
}
} }
/* /*
@ -224,9 +223,8 @@ x_mode(bool onoff)
if (memcmp(&edchars, &oldchars, sizeof(edchars)) != 0) { if (memcmp(&edchars, &oldchars, sizeof(edchars)) != 0) {
x_emacs_keys(&edchars); x_emacs_keys(&edchars);
} }
} else { } else
tcsetattr(tty_fd, TCSADRAIN, &tty_state); tcsetattr(tty_fd, TCSADRAIN, &tty_state);
}
return prev; return prev;
} }
@ -3965,89 +3963,94 @@ vi_cmd(int argcnt, const char *cmd)
ohnum = hnum; ohnum = hnum;
} }
break; break;
case '_': { case '_':
int inspace; {
char *p, *sp; int inspace;
char *p, *sp;
if (histnum(-1) < 0) if (histnum(-1) < 0)
return -1; return -1;
p = *histpos(); p = *histpos();
#define issp(c) (isspace((c)) || (c) == '\n') #define issp(c) (isspace((c)) || (c) == '\n')
if (argcnt) { if (argcnt) {
while (*p && issp(*p))
p++;
while (*p && --argcnt) {
while (*p && !issp(*p))
p++;
while (*p && issp(*p)) while (*p && issp(*p))
p++; p++;
} while (*p && --argcnt) {
if (!*p) while (*p && !issp(*p))
return -1; p++;
sp = p; while (*p && issp(*p))
} else { p++;
sp = p;
inspace = 0;
while (*p) {
if (issp(*p))
inspace = 1;
else if (inspace) {
inspace = 0;
sp = p;
} }
if (!*p)
return -1;
sp = p;
} else {
sp = p;
inspace = 0;
while (*p) {
if (issp(*p))
inspace = 1;
else if (inspace) {
inspace = 0;
sp = p;
}
p++;
}
p = sp;
}
modified = 1;
hnum = hlast;
if (es->cursor != es->linelen)
es->cursor++;
while (*p && !issp(*p)) {
argcnt++;
p++; p++;
} }
p = sp; if (putbuf(space, 1, 0) != 0)
} argcnt = -1;
modified = 1; hnum = hlast; else if (putbuf(sp, argcnt, 0) != 0)
if (es->cursor != es->linelen) argcnt = -1;
es->cursor++; if (argcnt < 0) {
while (*p && !issp(*p)) { if (es->cursor != 0)
argcnt++; es->cursor--;
p++; return -1;
}
if (putbuf(space, 1, 0) != 0)
argcnt = -1;
else if (putbuf(sp, argcnt, 0) != 0)
argcnt = -1;
if (argcnt < 0) {
if (es->cursor != 0)
es->cursor--;
return -1;
}
insert = INSERT;
}
break;
case '~': {
char *p;
int i;
if (es->linelen == 0)
return -1;
for (i = 0; i < argcnt; i++) {
p = &es->cbuf[es->cursor];
if (islower(*p)) {
modified = 1; hnum = hlast;
*p = toupper(*p);
} else if (isupper(*p)) {
modified = 1; hnum = hlast;
*p = tolower(*p);
} }
if (es->cursor < es->linelen - 1) insert = INSERT;
es->cursor++;
} }
break; break;
case '~':
{
char *p;
int i;
if (es->linelen == 0)
return -1;
for (i = 0; i < argcnt; i++) {
p = &es->cbuf[es->cursor];
if (islower(*p)) {
modified = 1;
hnum = hlast;
*p = toupper(*p);
} else if (isupper(*p)) {
modified = 1;
hnum = hlast;
*p = tolower(*p);
}
if (es->cursor < es->linelen - 1)
es->cursor++;
}
break;
} }
case '#': case '#':
{ {
int ret = x_do_comment(es->cbuf, es->cbufsize, int ret = x_do_comment(es->cbuf, es->cbufsize,
&es->linelen); &es->linelen);
if (ret >= 0) if (ret >= 0)
es->cursor = 0; es->cursor = 0;
return ret; return ret;
} }
case '=': /* at&t ksh */ case '=': /* at&t ksh */
case Ctrl('e'): /* Nonstandard vi/ksh */ case Ctrl('e'): /* Nonstandard vi/ksh */
@ -4088,7 +4091,6 @@ domove(int argcnt, const char *cmd, int sub)
int ncursor = 0; int ncursor = 0;
switch (*cmd) { switch (*cmd) {
case 'b': case 'b':
if (!sub && es->cursor == 0) if (!sub && es->cursor == 0)
return -1; return -1;