implement “live” SIGWINCH handling in the Emacs editing mode
for winstonw from IRC #!/bin/mksh
This commit is contained in:
parent
e520cee572
commit
30046ffcf2
4
Build.sh
4
Build.sh
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.453 2010/07/04 17:33:53 tg Exp $'
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.454 2010/07/04 17:45:10 tg Exp $'
|
||||
#-
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
@ -29,7 +29,7 @@ srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.453 2010/07/04 17:33:53 tg Exp $'
|
||||
# MKSH_CONSERVATIVE_FDS MKSH_MIDNIGHTBSD01ASH_COMPAT
|
||||
# MKSH_NOPWNAM MKSH_NO_LIMITS MKSH_SMALL MKSH_S_NOVI
|
||||
# MKSH_UNEMPLOYED MKSH_DEFAULT_EXECSHELL MKSHRC_PATH
|
||||
# MKSH_DEFAULT_TMPDIR
|
||||
# MKSH_DEFAULT_TMPDIR MKSH_CLRTOEOL_STRING
|
||||
|
||||
LC_ALL=C
|
||||
export LC_ALL
|
||||
|
4
check.t
4
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.378 2010/05/22 12:49:13 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.379 2010/07/04 17:45:11 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 $
|
||||
@ -25,7 +25,7 @@
|
||||
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R39 2010/05/22
|
||||
@(#)MIRBSD KSH R39 2010/07/04
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
|
58
edit.c
58
edit.c
@ -25,7 +25,20 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.192 2010/05/22 12:37:49 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.193 2010/07/04 17:45:12 tg Exp $");
|
||||
|
||||
/*
|
||||
* in later versions we might use libtermcap for this, but since external
|
||||
* dependencies are problematic, this has not yet been decided on; another
|
||||
* good string is "\033c" except on hardware terminals like the DEC VT420
|
||||
* which do a full power cycle then...
|
||||
*/
|
||||
#ifndef MKSH_CLS_STRING
|
||||
#define MKSH_CLS_STRING "\033[;H\033[J"
|
||||
#endif
|
||||
#ifndef MKSH_CLRTOEOL_STRING
|
||||
#define MKSH_CLRTOEOL_STRING "\033[K"
|
||||
#endif
|
||||
|
||||
/* tty driver characters we are interested in */
|
||||
typedef struct {
|
||||
@ -45,6 +58,7 @@ static X_chars edchars;
|
||||
#define XCF_FULLPATH BIT(2) /* command completion: store full path */
|
||||
#define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE)
|
||||
|
||||
static char editmode;
|
||||
static int modified; /* buffer has been "modified" */
|
||||
static char holdbuf[LINE]; /* place to hold last edit buffer */
|
||||
|
||||
@ -67,7 +81,11 @@ static int x_vi(char *, size_t);
|
||||
#endif
|
||||
|
||||
#define x_flush() shf_flush(shl_out)
|
||||
#ifdef MKSH_SMALL
|
||||
#define x_putc(c) x_putcf(c)
|
||||
#else
|
||||
#define x_putc(c) shf_putc((c), shl_out)
|
||||
#endif
|
||||
|
||||
static int path_order_cmp(const void *aa, const void *bb);
|
||||
static char *add_glob(const char *, int)
|
||||
@ -84,6 +102,7 @@ static int x_command_glob(int, const char *, int, char ***)
|
||||
static int x_locate_word(const char *, int, int, int *, bool *);
|
||||
|
||||
static int x_e_getmbc(char *);
|
||||
static int x_e_rebuildline(const char *);
|
||||
|
||||
/* +++ generic editing functions +++ */
|
||||
|
||||
@ -96,7 +115,6 @@ x_init(void)
|
||||
edchars.eof = -2;
|
||||
/* default value for deficient systems */
|
||||
edchars.werase = 027; /* ^W */
|
||||
change_winsz();
|
||||
x_init_emacs();
|
||||
}
|
||||
|
||||
@ -118,8 +136,8 @@ x_read(char *buf, size_t len)
|
||||
#endif
|
||||
else
|
||||
i = -1; /* internal error */
|
||||
editmode = 0;
|
||||
x_mode(false);
|
||||
change_winsz();
|
||||
return (i);
|
||||
}
|
||||
|
||||
@ -1091,6 +1109,7 @@ x_emacs(char *buf, size_t len)
|
||||
x_load_hist(histptr - off);
|
||||
x_nextcmd = -1;
|
||||
}
|
||||
editmode = 1;
|
||||
while (1) {
|
||||
x_flush();
|
||||
if ((c = x_e_getc()) < 0)
|
||||
@ -1922,23 +1941,18 @@ x_draw_line(int c MKSH_A_UNUSED)
|
||||
return (KSTD);
|
||||
}
|
||||
|
||||
static int
|
||||
x_e_rebuildline(const char *clrstr)
|
||||
{
|
||||
shf_fprintf(shl_out, clrstr);
|
||||
x_adjust();
|
||||
return (KSTD);
|
||||
}
|
||||
|
||||
static int
|
||||
x_cls(int c MKSH_A_UNUSED)
|
||||
{
|
||||
/*
|
||||
* in later versions we might use libtermcap for this, but since external
|
||||
* dependencies are problematic, this has not yet been decided on; another
|
||||
* good string is "\033c" except on hardware terminals like the DEC VT420
|
||||
* which do a full power cycle then...
|
||||
*/
|
||||
#ifndef MKSH_CLS_STRING
|
||||
#define MKSH_CLS_STRING "\033[;H\033[J"
|
||||
#endif
|
||||
shf_fprintf(shl_out, MKSH_CLS_STRING);
|
||||
x_putc('\r');
|
||||
x_init_prompt();
|
||||
x_redraw(0);
|
||||
return (KSTD);
|
||||
return (x_e_rebuildline(MKSH_CLS_STRING));
|
||||
}
|
||||
|
||||
/* Redraw (part of) the line. If limit is < 0, the everything is redrawn
|
||||
@ -3096,6 +3110,15 @@ x_mode(bool onoff)
|
||||
static bool x_cur_mode;
|
||||
bool prev;
|
||||
|
||||
if (onoff && got_winch) {
|
||||
change_winsz();
|
||||
if (x_cols != xx_cols && editmode == 1) {
|
||||
/* redraw line in Emacs mode */
|
||||
xx_cols = x_cols;
|
||||
x_e_rebuildline(MKSH_CLRTOEOL_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
if (x_cur_mode == onoff)
|
||||
return (x_cur_mode);
|
||||
prev = x_cur_mode;
|
||||
@ -3381,6 +3404,7 @@ x_vi(char *buf, size_t len)
|
||||
lastref = 1;
|
||||
holdlen = 0;
|
||||
|
||||
editmode = 2;
|
||||
x_flush();
|
||||
while (1) {
|
||||
if (macro.p) {
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.95 2010/07/04 13:36:42 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.96 2010/07/04 17:45:14 tg Exp $");
|
||||
|
||||
/*-
|
||||
* MirOS: This is the default mapping type, and need not be specified.
|
||||
@ -1433,9 +1433,10 @@ setsig(Trap *p, sig_t f, int flags)
|
||||
setexecsig(p, flags & SS_RESTORE_MASK);
|
||||
|
||||
/*
|
||||
* This is here 'cause there should be a way of clearing shtraps,
|
||||
* but don't know if this is a sane way of doing it. At the moment,
|
||||
* all users of shtrap are lifetime users (SIGCHLD, SIGALRM).
|
||||
* This is here 'cause there should be a way of clearing
|
||||
* shtraps, but don't know if this is a sane way of doing
|
||||
* it. At the moment, all users of shtrap are lifetime
|
||||
* users (SIGALRM, SIGCHLD, SIGWINCH).
|
||||
*/
|
||||
if (!(flags & SS_USER))
|
||||
p->shtrap = (sig_t)NULL;
|
||||
|
4
lex.c
4
lex.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.113 2010/04/08 13:21:06 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.114 2010/07/04 17:45:14 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -1406,6 +1406,8 @@ getsc_line(Source *s)
|
||||
xp += nread;
|
||||
} else {
|
||||
if (interactive) {
|
||||
if (got_winch)
|
||||
change_winsz();
|
||||
pprompt(prompt, 0);
|
||||
} else
|
||||
s->line++;
|
||||
|
21
main.c
21
main.c
@ -33,7 +33,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.166 2010/07/04 17:33:55 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.167 2010/07/04 17:45:15 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -54,6 +54,9 @@ static void reclaim(void);
|
||||
static void remove_temps(struct temp *);
|
||||
void chvt_reinit(void);
|
||||
Source *mksh_init(int, const char *[]);
|
||||
#ifdef SIGWINCH
|
||||
static void x_sigwinch(int);
|
||||
#endif
|
||||
|
||||
static const char initifs[] = "IFS= \t\n";
|
||||
|
||||
@ -399,6 +402,12 @@ mksh_init(int argc, const char *argv[])
|
||||
x_init();
|
||||
}
|
||||
|
||||
#ifdef SIGWINCH
|
||||
sigtraps[SIGWINCH].flags |= TF_SHELL_USES;
|
||||
setsig(&sigtraps[SIGWINCH], x_sigwinch,
|
||||
SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP);
|
||||
#endif
|
||||
|
||||
l = e->loc;
|
||||
l->argv = &argv[argi - 1];
|
||||
l->argc = argc - argi;
|
||||
@ -1459,3 +1468,13 @@ ktsort(struct table *tp)
|
||||
p[i] = NULL;
|
||||
return (p);
|
||||
}
|
||||
|
||||
#ifdef SIGWINCH
|
||||
static void
|
||||
x_sigwinch(int sig MKSH_A_UNUSED)
|
||||
{
|
||||
/* this runs inside interrupt context, with errno saved */
|
||||
|
||||
got_winch = 1;
|
||||
}
|
||||
#endif
|
||||
|
13
sh.h
13
sh.h
@ -150,9 +150,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.394 2010/07/04 17:33:57 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.395 2010/07/04 17:45:16 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R39 2010/05/22"
|
||||
#define MKSH_VERSION "R39 2010/07/04"
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
@ -665,7 +665,7 @@ typedef struct trap {
|
||||
#define SS_RESTORE_IGN 3 /* restore to SIG_IGN */
|
||||
#define SS_FORCE BIT(3) /* set signal even if original signal ignored */
|
||||
#define SS_USER BIT(4) /* user is doing the set (ie, trap command) */
|
||||
#define SS_SHTRAP BIT(5) /* trap for internal use (SIGCHLD, SIGALRM) */
|
||||
#define SS_SHTRAP BIT(5) /* trap for internal use (ALRM, CHLD, WINCH) */
|
||||
|
||||
#define SIGEXIT_ 0 /* for trap EXIT */
|
||||
#define SIGERR_ NSIG /* for trap ERR */
|
||||
@ -675,6 +675,13 @@ EXTERN volatile sig_atomic_t intrsig; /* pending trap interrupts command */
|
||||
EXTERN volatile sig_atomic_t fatal_trap;/* received a fatal signal */
|
||||
extern Trap sigtraps[NSIG+1];
|
||||
|
||||
/* got_winch = 1 when needing to re-adjust the window size */
|
||||
#ifdef SIGWINCH
|
||||
EXTERN volatile sig_atomic_t got_winch I__(1);
|
||||
#else
|
||||
#define got_winch true
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TMOUT support
|
||||
*/
|
||||
|
6
var.c
6
var.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.105 2010/07/04 17:33:58 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.106 2010/07/04 17:45:17 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -1440,6 +1440,10 @@ change_winsz(void)
|
||||
x_cols = 80;
|
||||
if (x_lins < MIN_LINS)
|
||||
x_lins = 24;
|
||||
|
||||
#ifdef SIGWINCH
|
||||
got_winch = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
Loading…
x
Reference in New Issue
Block a user