fix 'mksh -U -i' and 'mksh +U -i'

This commit is contained in:
tg 2009-11-28 15:38:30 +00:00
parent a09f05e77a
commit fa3acb939b
3 changed files with 55 additions and 16 deletions

23
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.345 2009/11/28 14:27:58 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.346 2009/11/28 15:38:28 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 2009/11/22
@(#)MIRBSD KSH R39 2009/11/28
description:
Check version of shell.
stdin:
@ -4832,6 +4832,25 @@ expected-stdout:
expected-stderr-pattern:
/(# )*/
---
name: utf8opt-3
description:
Ensure ±U on the command line is honoured
(this test may pass falsely depending on CPPFLAGS)
stdin:
export i=0
code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
let i++; "$__progname" -U -c "$code"
let i++; "$__progname" +U -c "$code"
let i++; "$__progname" -U -ic "$code"
let i++; "$__progname" +U -ic "$code"
echo $((++i)) done
expected-stdout:
1 on
2 off
3 on
4 off
5 done
---
name: aliases-1
description:
Check if built-in shell aliases are okay

44
main.c
View File

@ -33,7 +33,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.154 2009/10/30 14:37:42 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.155 2009/11/28 15:38:29 tg Exp $");
extern char **environ;
@ -45,6 +45,7 @@ extern gid_t kshgid, kshegid;
static void reclaim(void);
static void remove_temps(struct temp *);
void chvt_reinit(void);
Source *mksh_init(int, const char *[]);
static const char initifs[] = "IFS= \t\n";
@ -99,13 +100,13 @@ chvt_reinit(void)
#endif
}
int
main(int argc, const char *argv[])
Source *
mksh_init(int argc, const char *argv[])
{
int argi, i;
Source *s;
struct block *l;
unsigned char restricted, errexit;
unsigned char restricted, errexit, utf_flag;
const char **wp;
struct tbl *vp;
struct stat s_stdin;
@ -140,7 +141,7 @@ main(int argc, const char *argv[])
argi = parse_args(argv, OF_FIRSTTIME, NULL);
if (argi < 0)
exit(1);
return (NULL);
initvar();
@ -305,9 +306,16 @@ main(int argc, const char *argv[])
#ifndef MKSH_UNEMPLOYED
Flag(FMONITOR) = 127;
#endif
/* this to note if utf-8 mode is set on command line (see below) */
UTFMODE = 2;
argi = parse_args(argv, OF_CMDLINE, NULL);
if (argi < 0)
exit(1);
return (NULL);
/* process this later only, default to off (hysterical raisins) */
utf_flag = UTFMODE;
UTFMODE = 0;
if (Flag(FCOMMAND)) {
s = pushs(SSTRING, ATEMP);
@ -355,13 +363,15 @@ main(int argc, const char *argv[])
/* initialise job control */
j_init();
/* set: 0/1; unset: 2->0 */
UTFMODE = utf_flag & 1;
/* Do this after j_init(), as tty_fd is not initialised until then */
if (Flag(FTALKING)) {
if (utf_flag == 2) {
#ifndef MKSH_ASSUME_UTF8
#define isuc(x) (((x) != NULL) && \
(stristr((x), "UTF-8") || stristr((x), "utf8")))
/* Check if we're in a UTF-8 locale */
if (!UTFMODE) {
const char *ccp;
#if HAVE_SETLOCALE_CTYPE
@ -379,13 +389,13 @@ main(int argc, const char *argv[])
ccp = str_val(global("LANG"));
#endif
UTFMODE = isuc(ccp);
}
#undef isuc
#elif MKSH_ASSUME_UTF8
UTFMODE = 1;
UTFMODE = 1;
#else
UTFMODE = 0;
UTFMODE = 0;
#endif
}
x_init();
}
@ -443,8 +453,18 @@ main(int argc, const char *argv[])
} else
Flag(FTRACKALL) = 1; /* set after ENV */
shell(s, true); /* doesn't return */
return (0);
return (s);
}
int
main(int argc, const char *argv[])
{
Source *s;
if ((s = mksh_init(argc, argv)))
/* doesnt return */
shell(s, true);
return (1);
}
int

4
sh.h
View File

@ -134,9 +134,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.364 2009/11/28 14:28:02 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.365 2009/11/28 15:38:30 tg Exp $");
#endif
#define MKSH_VERSION "R39 2009/11/22"
#define MKSH_VERSION "R39 2009/11/28"
#ifndef MKSH_INCLUDES_ONLY