OSDN Git Service

Upgrade to mksh 51.
[android-x86/external-mksh.git] / src / lex.c
index 305f5a4..fb80244 100644 (file)
--- a/src/lex.c
+++ b/src/lex.c
@@ -23,7 +23,7 @@
 
 #include "sh.h"
 
-__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.193.2.5 2015/04/19 19:18:19 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.204 2015/07/05 19:53:46 tg Exp $");
 
 /*
  * states while lexing word
@@ -920,7 +920,7 @@ yylex(int cf)
                                goto no_iop;
                        if (!ksh_isdigit(dp[c2 + 1]))
                                goto no_iop;
-                       iop->unit = (iop->unit * 10) + dp[c2 + 1] - '0';
+                       iop->unit = iop->unit * 10 + ksh_numdig(dp[c2 + 1]);
                        if (iop->unit >= FDBASE)
                                goto no_iop;
                }
@@ -1461,16 +1461,23 @@ getsc_line(Source *s)
                if (s->type == SFILE)
                        shf_fdclose(s->u.shf);
                s->str = NULL;
-       } else if (interactive && *s->str &&
-           (cur_prompt != PS1 || !ctype(*s->str, C_IFS | C_IFSWS))) {
-               histsave(&s->line, s->str, true, true);
+       } else if (interactive && *s->str) {
+               if (cur_prompt != PS1)
+                       histsave(&s->line, s->str, HIST_APPEND, true);
+               else if (!ctype(*s->str, C_IFS | C_IFSWS))
+                       histsave(&s->line, s->str, HIST_QUEUE, true);
 #if !defined(MKSH_SMALL) && HAVE_PERSISTENT_HISTORY
+               else
+                       goto check_for_sole_return;
        } else if (interactive && cur_prompt == PS1) {
+ check_for_sole_return:
                cp = Xstring(s->xs, xp);
                while (*cp && ctype(*cp, C_IFSWS))
                        ++cp;
-               if (!*cp)
+               if (!*cp) {
+                       histsave(&s->line, NULL, HIST_FLUSH, true);
                        histsync();
+               }
 #endif
        }
        if (interactive)
@@ -1495,6 +1502,7 @@ set_prompt(int to, Source *s)
                        struct shf *shf;
                        char * volatile ps1;
                        Area *saved_atemp;
+                       int saved_lineno;
 
                        ps1 = str_val(global("PS1"));
                        shf = shf_sopen(NULL, strlen(ps1) * 2,
@@ -1506,6 +1514,9 @@ set_prompt(int to, Source *s)
                                        shf_fprintf(shf, "%lu", s ?
                                            (unsigned long)s->line + 1 : 0UL);
                        ps1 = shf_sclose(shf);
+                       saved_lineno = current_lineno;
+                       if (s)
+                               current_lineno = s->line + 1;
                        saved_atemp = ATEMP;
                        newenv(E_ERRH);
                        if (kshsetjmp(e->jbuf)) {
@@ -1521,6 +1532,7 @@ set_prompt(int to, Source *s)
                                char *cp = substitute(ps1, 0);
                                strdupx(prompt, cp, saved_atemp);
                        }
+                       current_lineno = saved_lineno;
                        quitenv(NULL);
                }
                break;