On Sat, Mar 02, 2013 at 03:08:44PM -0800, Philip Guenther wrote:
> On Sat, 2 Mar 2013, Andres Perera wrote:
> > On Sat, Mar 2, 2013 at 5:13 PM, Philip Guenther <guent...@sendmail.com> 
> > wrote:
> ...
> > > Hmm, this is actually changing two things: it's both fixing the problem
> > > that the code is not subtracting '0' from each character before doing the
> > > octal place conversion and it's also changing it to support octal
> > > sequences of fewer than 3 digits.  The latter seems unnecessary and isn't
> > > documented, do we really need/want to add it?
> > 
> > the behaviour is consistent with bash, which is the shell ksh took it from
> > 
> > in addition to that, it's consistent with c string literals and printf(1)
> > 
> > ksh having an doing things differently is a bigger bug than
> > precedence... ps1 isn't exactly crucial in scripts
> 
> Yet it wasn't important enough to mention or document.  Huh.  I'm not 
> interested without a manpage update to match.

new patch below

like before

* fix the bug with PS1 octal conversion

* add 1 .. 3 octal number feature as seen in bash, printf(1), etc.

aditionally

* document the new behaviour in ksh(1)

* change `c' to int; match other routines

Index: lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.46
diff -p -u -r1.46 lex.c
--- lex.c       20 Jan 2013 14:47:46 -0000      1.46
+++ lex.c       2 Mar 2013 23:07:19 -0000
@@ -1349,17 +1349,17 @@ dopprompt(const char *sp, int ntruncate,
                        case '4':
                        case '5':
                        case '6':
-                       case '7':
-                               if ((cp[1] > '7' || cp[1] < '0') ||
-                                   (cp[2] > '7' || cp[2] < '0')) {
-                                       snprintf(strbuf, sizeof strbuf,
-                                           "\\%c", *cp);
-                                       break;
-                               }
-                               n = cp[0] * 8 * 8 + cp[1] * 8 + cp[2];
-                               snprintf(strbuf, sizeof strbuf, "%c", n);
-                               cp += 2;
+                       case '7': {
+                               int     c = 0, i = 3;
+
+                               do
+                                       c = c * 8 + *cp - '0';
+                               while (--i && *++cp >= '0' && *cp <= '7');
+                               cp -= !!i;
+                               strbuf[0] = c;
+                               strbuf[1] = '\0';
                                break;
+                       }
                        case '\\':      /* '\' '\' */
                                strbuf[0] = '\\';
                                strbuf[1] = '\0';
Index: ksh.1
===================================================================
RCS file: /cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.145
diff -p -u -r1.145 ksh.1
--- ksh.1       17 Jan 2013 21:20:25 -0000      1.145
+++ ksh.1       2 Mar 2013 23:07:21 -0000
@@ -1662,7 +1662,7 @@ as a special character within double quo
 it is safer in this case to escape the backslash
 than to try quoting it.
 .It Li \e Ns Ar nnn
-The octal character
+The character whose octal value is the 1 to 3 (inclusive) digit number
 .Ar nnn .
 .It Li \e\e
 Insert a single backslash character.

Reply via email to