align with C standard (optional C style); document differences to C style

for print builtin (align with ksh93 ipv GNU bash)
This commit is contained in:
tg 2009-09-19 19:08:48 +00:00
parent 7806fe510a
commit c8eb13a13f
4 changed files with 36 additions and 13 deletions

View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.131 2009/09/19 15:16:02 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.132 2009/09/19 19:08:46 tg Exp $");
#if HAVE_KILLPG
/*
@ -604,7 +604,7 @@ c_print(const char **wp)
while ((c = *s++) != '\0') {
Xcheck(xs, xp);
if ((flags & PO_EXPAND) && c == '\\') {
if ((c = unbksl(&s)) == -1) {
if ((c = unbksl(&s, false)) == -1) {
/* rejected by generic function */
switch ((c = *s++)) {
case 'c':

31
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.119 2009/09/19 15:16:03 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.120 2009/09/19 19:08:47 tg Exp $");
#undef USE_CHVT
/* XXX conditions correct? */
@ -1456,7 +1456,7 @@ getrusage(int what, struct rusage *ru)
* unprocessed character (unchanged if rv=-1)
*/
int
unbksl(const char **sp)
unbksl(const char **sp, bool cstyle)
{
int wc, i;
const char *cp = (*sp);
@ -1490,7 +1490,21 @@ unbksl(const char **sp)
/* assume ASCII here as well */
wc = 11;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (!cstyle)
return (-1);
/* FALLTHROUGH */
case '0':
if (cstyle)
--cp;
/*
* look for an octal number with up to three
* digits, not counting the leading zero;
@ -1510,12 +1524,13 @@ unbksl(const char **sp)
if (0)
/* FALLTHROUGH */
case 'x':
i = 2;
i = cstyle ? -1 : 2;
/*
* x: look for a hexadecimal number with up to
* two digits; convert to raw octet
* u: look for a hexadecimal number with up to
* four (U: eight) digits; convert to Unicode
* x: look for a hexadecimal number with up to
* two (C style: arbitrary) digits; convert
* to raw octet (C style: Unicode)
* u/U: look for a hexadecimal number with up to
* four (U: eight) digits; convert to Unicode
*/
wc = 0;
while (i--) {
@ -1531,7 +1546,7 @@ unbksl(const char **sp)
break;
}
}
if (**sp != 'x')
if (cstyle || **sp != 'x')
/* Unicode marker */
wc += 0x100;
break;

10
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.186 2009/09/19 18:36:58 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.187 2009/09/19 19:08:47 tg Exp $
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
@ -884,6 +884,11 @@ In places where backslashes are expanded, certain C and
or GNU
.Nm bash
style escapes are translated.
Explicitly excluded are
.Ql \e" ,
.Ql \e' ,
and
.Ql \e? .
These include
.Ql \ea ,
.Ql \eb ,
@ -3308,6 +3313,9 @@ above, as well as
which is equivalent to using the
.Fl n
option.
Contrary to C escapes, the backslash is retained if followed by an
unsupported escape character; octal sequences must be preceded by a
.Sq 0 .
.Ql \e
expansion may be inhibited with the
.Fl r

4
sh.h
View File

@ -134,7 +134,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.341 2009/09/19 15:16:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.342 2009/09/19 19:08:48 tg Exp $");
#endif
#define MKSH_VERSION "R39 2009/09/07"
@ -1587,7 +1587,7 @@ void set_current_wd(char *);
char *strdup_(const char *, Area *);
char *strndup_(const char *, size_t, Area *);
#endif
int unbksl(const char **);
int unbksl(const char **, bool);
/* shf.c */
struct shf *shf_open(const char *, int, int, int);
struct shf *shf_fdopen(int, int, struct shf *);