From 1547b04e66e0f01ed6795f95c9111bdae3a078f2 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 5 Nov 2006 12:11:14 +0000 Subject: [PATCH] add new "set -o utf8-hack", currently no effect set automatically on startup if we have locale functions (on MirOS) --- Makefile | 4 ++-- check.t | 4 ++-- main.c | 23 ++++++++++++++++++++++- misc.c | 3 ++- sh.h | 5 +++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index bcf6dd0..3170e45 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -# $MirOS: src/bin/mksh/Makefile,v 1.12 2006/08/26 20:30:27 tg Exp $ +# $MirOS: src/bin/mksh/Makefile,v 1.13 2006/11/05 12:11:13 tg Exp $ PROG= mksh SRCS= alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c \ jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c -CPPFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_ARC4RANDOM_PUSH +CPPFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_ARC4RANDOM_PUSH -DHAVE_LANGSTUFF CDIAGFLAGS+= -Wno-cast-qual LINKS+= ${BINDIR}/${PROG} ${BINDIR}/sh diff --git a/check.t b/check.t index 54906e1..4dbdee2 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.67 2006/09/30 02:13:20 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.68 2006/11/05 12:11:13 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 $ @@ -3872,5 +3872,5 @@ category: pdksh stdin: echo $KSH_VERSION expected-stdout: - @(#)MIRBSD KSH R28 2006/09/30 + @(#)MIRBSD KSH R28 2006/11/05 --- diff --git a/main.c b/main.c index 94c81e9..4da821c 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,12 @@ #define EXTERN #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.49 2006/09/30 02:13:21 tg Exp $"); +#if (HAVE_LANGSTUFF - 0) +#include +#include +#endif + +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.50 2006/11/05 12:11:14 tg Exp $"); extern char **environ; @@ -60,6 +65,9 @@ main(int argc, char *argv[]) pid_t ppid; struct tbl *vp; struct stat s_stdin; +#if (HAVE_LANGSTUFF - 0) + const char *cc; +#endif /* make sure argv[] is sane */ if (!*argv) { @@ -134,6 +142,19 @@ main(int argc, char *argv[]) setstr(vp, def_path, KSH_RETURN_ERROR); +#if (HAVE_LANGSTUFF - 0) + /* Check if we're in an UTF-8 locale */ + cc = setlocale(LC_CTYPE, ""); +#ifdef CODESET + if (strcasecmp(cc, "UTF-8") && strcasecmp(cc, "utf8") && + strcasecmp(cc, "CESU-8") && strcasecmp(cc, "cesu8")) + cc = nl_langinfo(CODESET); +#endif + if (!strcasecmp(cc, "UTF-8") || !strcasecmp(cc, "utf8") || + !strcasecmp(cc, "CESU-8") || !strcasecmp(cc, "cesu8")) + Flag(FUTFHACK) = 1; +#endif + /* Turn on nohup by default for now - will change to off * by default once people are aware of its existence * (at&t ksh does not have a nohup option - it always sends diff --git a/misc.c b/misc.c index 8250e18..a94b4a9 100644 --- a/misc.c +++ b/misc.c @@ -3,7 +3,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.16 2006/08/24 20:32:53 tg Exp $\t" +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.17 2006/11/05 12:11:14 tg Exp $\t" MKSH_SH_H_ID); short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */ @@ -142,6 +142,7 @@ const struct option options[] = { { "sh", 0, OF_ANY }, /* non-standard */ { "stdin", 's', OF_CMDLINE }, /* pseudo non-standard */ { "trackall", 'h', OF_ANY }, + { "utf8-hack", 0, OF_ANY }, /* non-standard */ { "verbose", 'v', OF_ANY }, { "vi", 0, OF_ANY }, { "viraw", 0, OF_ANY }, /* no effect */ diff --git a/sh.h b/sh.h index ac5a014..07575b9 100644 --- a/sh.h +++ b/sh.h @@ -8,8 +8,8 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.47 2006/10/03 19:46:14 tg Exp $" -#define MKSH_VERSION "R28 2006/09/30" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.48 2006/11/05 12:11:14 tg Exp $" +#define MKSH_VERSION "R28 2006/11/05" #include #if !defined(__RCSID) || !defined(__SCCSID) @@ -283,6 +283,7 @@ enum sh_flag { FSH, /* -o sh (dummy, for pdksh compatibility) */ FSTDIN, /* -s: (invocation) parse stdin */ FTRACKALL, /* -h: create tracked aliases for all commands */ + FUTFHACK, /* utf-8 hack for command line editing */ FVERBOSE, /* -v: echo input */ FVI, /* vi command editing */ FVIRAW, /* always read in raw mode (ignored) */