Ypnose discovered a problem with multi-line prompts and SIGWINCH

related to caching some values (downside, pprompt gets back doprint option)
This commit is contained in:
tg 2013-08-16 10:59:03 +00:00
parent bf94b7e2ec
commit 5eb6995d75
4 changed files with 24 additions and 20 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.629 2013/08/14 20:26:15 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.630 2013/08/16 10:58:59 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -31,7 +31,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R48 2013/08/14
@(#)MIRBSD KSH R48 2013/08/16
description:
Check version of shell.
stdin:
@ -40,7 +40,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R48 2013/08/14
@(#)LEGACY KSH R48 2013/08/16
description:
Check version of legacy shell.
stdin:

18
edit.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: edit.c,v 1.38 2013/06/03 15:41:59 tedu Exp $ */
;/* $OpenBSD: edit.c,v 1.38 2013/06/03 15:41:59 tedu Exp $ */
/* $OpenBSD: edit.h,v 1.9 2011/05/30 17:14:35 martynas Exp $ */
/* $OpenBSD: emacs.c,v 1.44 2011/09/05 04:50:33 marco Exp $ */
/* $OpenBSD: vi.c,v 1.26 2009/06/29 22:50:19 martynas Exp $ */
@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.270 2013/08/14 20:26:17 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.271 2013/08/16 10:59:01 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -82,7 +82,7 @@ static int x_basename(const char *, const char *);
static void x_free_words(int, char **);
static int x_escape(const char *, size_t, int (*)(const char *, size_t));
static int x_emacs(char *);
static void x_init_prompt(void);
static void x_init_prompt(bool);
#if !MKSH_S_NOVI
static int x_vi(char *);
#endif
@ -148,6 +148,7 @@ x_getc(void)
if (x_cols != xx_cols && editmode == 1) {
/* redraw line in Emacs mode */
xx_cols = x_cols;
x_init_prompt(false);
x_e_rebuildline(MKSH_CLRTOEOL_STRING);
}
}
@ -1167,16 +1168,17 @@ x_e_getmbc(char *sbuf)
}
static void
x_init_prompt(void)
x_init_prompt(bool doprint)
{
prompt_trunc = pprompt(prompt, 0);
prompt_trunc = pprompt(prompt, doprint ? 0 : -1);
pwidth = prompt_trunc % x_cols;
prompt_trunc -= pwidth;
if ((mksh_uari_t)pwidth > ((mksh_uari_t)x_cols - 3 - MIN_EDIT_SPACE)) {
/* force newline after prompt */
prompt_trunc = -1;
pwidth = 0;
x_e_putc2('\n');
if (doprint)
x_e_putc2('\n');
}
}
@ -1196,7 +1198,7 @@ x_emacs(char *buf)
x_histp = histptr + 1;
x_last_command = XFUNC_error;
x_init_prompt();
x_init_prompt(true);
x_displen = (xx_cols = x_cols) - 2 - (x_col = pwidth);
x_adj_done = 0;
x_adj_ok = true;
@ -3535,7 +3537,7 @@ x_vi(char *buf)
es = &ebuf;
undo = &undobuf;
x_init_prompt();
x_init_prompt(true);
x_col = pwidth;
if (wbuf_len != x_cols - 3 && ((wbuf_len = x_cols - 3))) {

16
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.188 2013/08/10 13:44:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.189 2013/08/16 10:59:03 tg Exp $");
/*
* states while lexing word
@ -1521,9 +1521,10 @@ set_prompt(int to, Source *s)
int
pprompt(const char *cp, int ntruncate)
{
int columns = 0, lines = 0;
bool indelimit = false;
char delimiter = 0;
bool doprint = (ntruncate != -1);
bool indelimit = false;
int columns = 0, lines = 0;
/*
* Undocumented AT&T ksh feature:
@ -1552,18 +1553,19 @@ pprompt(const char *cp, int ntruncate)
else if (UTFMODE && ((unsigned char)*cp > 0x7F)) {
const char *cp2;
columns += utf_widthadj(cp, &cp2);
if (indelimit ||
(ntruncate < (x_cols * lines + columns)))
if (doprint && (indelimit ||
(ntruncate < (x_cols * lines + columns))))
shf_write(cp, cp2 - cp, shl_out);
cp = cp2 - /* loop increment */ 1;
continue;
} else
columns++;
if ((*cp != delimiter) &&
if (doprint && (*cp != delimiter) &&
(indelimit || (ntruncate < (x_cols * lines + columns))))
shf_putc(*cp, shl_out);
}
shf_flush(shl_out);
if (doprint)
shf_flush(shl_out);
return (x_cols * lines + columns);
}

4
sh.h
View File

@ -164,9 +164,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.667 2013/08/14 20:26:19 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.668 2013/08/16 10:59:03 tg Exp $");
#endif
#define MKSH_VERSION "R48 2013/08/14"
#define MKSH_VERSION "R48 2013/08/16"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES