Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/nvi PR/50484: Rin Okuyama: fix the script comma...



details:   https://anonhg.NetBSD.org/src/rev/3e17488cf2c6
branches:  trunk
changeset: 341901:3e17488cf2c6
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 28 13:20:02 2015 +0000

description:
PR/50484: Rin Okuyama: fix the script command of vi(1)

diffstat:

 external/bsd/nvi/Makefile.inc         |    4 +-
 external/bsd/nvi/dist/common/vi_db1.c |    6 +-
 external/bsd/nvi/dist/ex/ex_script.c  |  249 +++++++++++----------------------
 external/bsd/nvi/usr.bin/nvi/Makefile |    6 +-
 4 files changed, 91 insertions(+), 174 deletions(-)

diffs (truncated from 509 to 300 lines):

diff -r 6bc00bd564ad -r 3e17488cf2c6 external/bsd/nvi/Makefile.inc
--- a/external/bsd/nvi/Makefile.inc     Sat Nov 28 09:25:45 2015 +0000
+++ b/external/bsd/nvi/Makefile.inc     Sat Nov 28 13:20:02 2015 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.2 2015/11/25 20:25:20 christos Exp $
+#      $NetBSD: Makefile.inc,v 1.3 2015/11/28 13:20:02 christos Exp $
 
 .include <bsd.own.mk>
 
@@ -7,4 +7,4 @@
 BINDIR=/usr/bin
 
 CWARNFLAGS.clang+=     -Wno-error=unused-const-variable
-VERSION=1.81.6-2013-11-20nb1
+VERSION=1.81.6-2013-11-20nb2
diff -r 6bc00bd564ad -r 3e17488cf2c6 external/bsd/nvi/dist/common/vi_db1.c
--- a/external/bsd/nvi/dist/common/vi_db1.c     Sat Nov 28 09:25:45 2015 +0000
+++ b/external/bsd/nvi/dist/common/vi_db1.c     Sat Nov 28 13:20:02 2015 +0000
@@ -15,7 +15,7 @@
 static const char sccsid[] = "Id: db1.c,v 10.1 2002/03/09 12:53:57 skimo Exp  (Berkeley) Date: 2002/03/09 12:53:57 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: vi_db1.c,v 1.7 2014/01/26 21:43:45 christos Exp $");
+__RCSID("$NetBSD: vi_db1.c,v 1.8 2015/11/28 13:20:03 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -421,10 +421,10 @@
  * db_set --
  *     Store a line in the file.
  *
- * PUBLIC: int db_set __P((SCR *, db_recno_t, CHAR_T *, size_t));
+ * PUBLIC: int db_set __P((SCR *, db_recno_t, const CHAR_T *, size_t));
  */
 int
-db_set(SCR *sp, db_recno_t lno, CHAR_T *p, size_t len)
+db_set(SCR *sp, db_recno_t lno, const CHAR_T *p, size_t len)
 {
        DBT data, key;
        EXF *ep;
diff -r 6bc00bd564ad -r 3e17488cf2c6 external/bsd/nvi/dist/ex/ex_script.c
--- a/external/bsd/nvi/dist/ex/ex_script.c      Sat Nov 28 09:25:45 2015 +0000
+++ b/external/bsd/nvi/dist/ex/ex_script.c      Sat Nov 28 13:20:02 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ex_script.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
+/*     $NetBSD: ex_script.c,v 1.5 2015/11/28 13:20:03 christos Exp $ */
 /*-
  * Copyright (c) 1992, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
@@ -19,7 +19,7 @@
 static const char sccsid[] = "Id: ex_script.c,v 10.38 2001/06/25 15:19:19 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:19 ";
 #endif /* not lint */
 #else
-__RCSID("$NetBSD: ex_script.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
+__RCSID("$NetBSD: ex_script.c,v 1.5 2015/11/28 13:20:03 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -29,7 +29,7 @@
 #include <sys/select.h>
 #endif
 #include <sys/stat.h>
-#if defined(HAVE_SYS5_PTY) && !defined(__NetBSD__)
+#if defined(HAVE_SYS5_PTY)
 #include <sys/stropts.h>
 #endif
 #include <sys/time.h>
@@ -45,6 +45,9 @@
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
+#ifdef __NetBSD__
+#include <util.h>
+#endif
 
 #include "../common/common.h"
 #include "../vi/vi.h"
@@ -55,9 +58,12 @@
 static int     sscr_getprompt __P((SCR *));
 static int     sscr_init __P((SCR *));
 static int     sscr_insert __P((SCR *));
-static int     sscr_matchprompt __P((SCR *, CHAR_T *, size_t, size_t *));
+#ifdef __NetBSD__
+#define        sscr_pty openpty
+#else
 static int     sscr_pty __P((int *, int *, char *, struct termios *, void *));
-static int     sscr_setprompt __P((SCR *, CHAR_T *, size_t));
+#endif
+static int     sscr_setprompt __P((SCR *, char *, size_t));
 
 /*
  * ex_script -- : sc[ript][!] [file]
@@ -75,6 +81,17 @@
                return (1);
        }
 
+       /* Avoid double run. */
+       if (F_ISSET(sp, SC_SCRIPT)) {
+               msgq(sp, M_ERR,
+                   "The script command is already runninng");
+               return (1);
+       }
+
+       /* We're going to need a shell. */
+       if (opts_empty(sp, O_SHELL, 0))
+               return (1);
+
        /* Switch to the new file. */
        if (cmdp->argc != 0 && ex_edit(sp, cmdp))
                return (1);
@@ -96,10 +113,6 @@
        SCRIPT *sc;
        const char *sh, *sh_path;
 
-       /* We're going to need a shell. */
-       if (opts_empty(sp, O_SHELL, 0))
-               return (1);
-
        MALLOC_RET(sp, sc, SCRIPT *, sizeof(SCRIPT));
        sp->script = sc;
        sc->sh_prompt = NULL;
@@ -209,89 +222,28 @@
 sscr_getprompt(SCR *sp)
 {
        struct timeval tv;
-       CHAR_T *endp, *p, *t, buf[1024];
-       SCRIPT *sc;
        fd_set fdset;
-       db_recno_t lline;
-       size_t llen, len;
-       e_key_t value;
-       int nr;
-
-       FD_ZERO(&fdset);
-       endp = buf;
-       len = sizeof(buf);
+       int master;
 
        /* Wait up to a second for characters to read. */
        tv.tv_sec = 5;
        tv.tv_usec = 0;
-       sc = sp->script;
-       FD_SET(sc->sh_master, &fdset);
-       switch (select(sc->sh_master + 1, &fdset, NULL, NULL, &tv)) {
+       master = sp->script->sh_master;
+       FD_ZERO(&fdset);
+       FD_SET(master, &fdset);
+       switch (select(master + 1, &fdset, NULL, NULL, &tv)) {
        case -1:                /* Error or interrupt. */
                msgq(sp, M_SYSERR, "select");
-               goto prompterr;
+               break;
        case  0:                /* Timeout */
                msgq(sp, M_ERR, "Error: timed out");
-               goto prompterr;
+               break;
        case  1:                /* Characters to read. */
-               break;
-       }
-
-       /* Read the characters. */
-more:  len = sizeof(buf) - (endp - buf);
-       switch (nr = read(sc->sh_master, endp, len)) {
-       case  0:                        /* EOF. */
-               msgq(sp, M_ERR, "Error: shell: EOF");
-               goto prompterr;
-       case -1:                        /* Error or interrupt. */
-               msgq(sp, M_SYSERR, "shell");
-               goto prompterr;
-       default:
-               endp += nr;
-               break;
+               return (sscr_insert(sp) || sp->script == NULL);
        }
 
-       /* If any complete lines, push them into the file. */
-       for (p = t = buf; p < endp; ++p) {
-               value = KEY_VAL(sp, *p);
-               if (value == K_CR || value == K_NL) {
-                       if (db_last(sp, &lline) ||
-                           db_append(sp, 0, lline, t, p - t))
-                               goto prompterr;
-                       t = p + 1;
-               }
-       }
-       if (p > buf) {
-               MEMMOVE(buf, t, endp - t);
-               endp = buf + (endp - t);
-       }
-       if (endp == buf)
-               goto more;
-
-       /* Wait up 1/10 of a second to make sure that we got it all. */
-       tv.tv_sec = 0;
-       tv.tv_usec = 100000;
-       switch (select(sc->sh_master + 1, &fdset, NULL, NULL, &tv)) {
-       case -1:                /* Error or interrupt. */
-               msgq(sp, M_SYSERR, "select");
-               goto prompterr;
-       case  0:                /* Timeout */
-               break;
-       case  1:                /* Characters to read. */
-               goto more;
-       }
-
-       /* Timed out, so theoretically we have a prompt. */
-       llen = endp - buf;
-       endp = buf;
-
-       /* Append the line into the file. */
-       if (db_last(sp, &lline) || db_append(sp, 0, lline, buf, llen)) {
-prompterr:     sscr_end(sp);
-               return (1);
-       }
-
-       return (sscr_setprompt(sp, buf, llen));
+       sscr_end(sp);
+       return (1);
 }
 
 /*
@@ -305,47 +257,53 @@
 {
        SCRIPT *sc;
        db_recno_t last_lno;
-       size_t blen, len, last_len, tlen;
+       size_t blen, len, last_len;
        int isempty, matchprompt, rval;
        ssize_t nw;
-       CHAR_T *bp = NULL;
-       CHAR_T *p;
+       char *bp = NULL;
+       const char *p;
+       const CHAR_T *ip;
+       size_t ilen;
+
+       sc = sp->script;
 
        /* If there's a prompt on the last line, append the command. */
        if (db_last(sp, &last_lno))
                return (1);
-       if (db_get(sp, last_lno, DBG_FATAL, &p, &last_len))
+       if (db_get(sp, last_lno, DBG_FATAL, __UNCONST(&ip), &ilen))
                return (1);
-       if (sscr_matchprompt(sp, p, last_len, &tlen) && tlen == 0) {
+       INT2CHAR(sp, ip, ilen, p, last_len);
+       if (last_len == sc->sh_prompt_len &&
+           strnstr(p, sc->sh_prompt, last_len) == p) {
                matchprompt = 1;
-               GET_SPACE_RETW(sp, bp, blen, last_len + 128);
-               MEMMOVEW(bp, p, last_len);
+               GET_SPACE_RETC(sp, bp, blen, last_len + 128);
+               memmove(bp, p, last_len);
        } else
                matchprompt = 0;
 
        /* Get something to execute. */
-       if (db_eget(sp, lno, &p, &len, &isempty)) {
+       if (db_eget(sp, lno, __UNCONST(&ip), &ilen, &isempty)) {
                if (isempty)
                        goto empty;
                goto err1;
        }
 
        /* Empty lines aren't interesting. */
-       if (len == 0)
+       if (ilen == 0)
                goto empty;
+       INT2CHAR(sp, ip, ilen, p, len);
 
        /* Delete any prompt. */
-       if (sscr_matchprompt(sp, p, len, &tlen)) {
-               if (tlen == len) {
+       if (sc->sh_prompt != NULL && strnstr(p, sc->sh_prompt, len) == p) {
+               len -= sc->sh_prompt_len;
+               if (len == 0) {
 empty:                 msgq(sp, M_BERR, "151|No command to execute");
                        goto err1;
                }
-               p += (len - tlen);
-               len = tlen;
+               p += sc->sh_prompt_len;
        }
 
        /* Push the line to the shell. */
-       sc = sp->script;
        if ((size_t)(nw = write(sc->sh_master, p, len)) != len)
                goto err2;
        rval = 0;
@@ -357,13 +315,14 @@
        }
 
        if (matchprompt) {
-               ADD_SPACE_RETW(sp, bp, blen, last_len + len);
-               MEMMOVEW(bp + last_len, p, len);
-               if (db_set(sp, last_lno, bp, last_len + len))
+               ADD_SPACE_GOTO(sp, char, bp, blen, last_len + len);
+               memmove(bp + last_len, p, len);
+               CHAR2INT(sp, bp, last_len + len, ip, ilen);
+               if (db_set(sp, last_lno, ip, ilen))



Home | Main Index | Thread Index | Old Index