Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/sed Merge our changes.



details:   https://anonhg.NetBSD.org/src/rev/6044ccdc30af
branches:  trunk
changeset: 329731:6044ccdc30af
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jun 06 00:13:13 2014 +0000

description:
Merge our changes.

diffstat:

 usr.bin/sed/Makefile  |    3 +-
 usr.bin/sed/POSIX     |   18 +-
 usr.bin/sed/compile.c |  517 +++++++++++++++++++++++++++----------------------
 usr.bin/sed/defs.h    |   83 ++-----
 usr.bin/sed/extern.h  |   60 +----
 usr.bin/sed/main.c    |  383 ++++++++++++++++++++++--------------
 usr.bin/sed/misc.c    |   99 ++------
 usr.bin/sed/process.c |  501 ++++++++++++++++++++++++++++--------------------
 usr.bin/sed/sed.1     |  319 +++++++++++++++++++++---------
 9 files changed, 1111 insertions(+), 872 deletions(-)

diffs (truncated from 3373 to 300 lines):

diff -r efb5a7c51788 -r 6044ccdc30af usr.bin/sed/Makefile
--- a/usr.bin/sed/Makefile      Fri Jun 06 00:11:19 2014 +0000
+++ b/usr.bin/sed/Makefile      Fri Jun 06 00:13:13 2014 +0000
@@ -1,7 +1,8 @@
-#      $NetBSD: Makefile,v 1.14 2009/04/14 22:15:26 lukem Exp $
+#      $NetBSD: Makefile,v 1.15 2014/06/06 00:13:13 christos Exp $
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
 
 .include <bsd.own.mk>
+WARNS=6
 
 PROG=  sed
 SRCS=  compile.c main.c misc.c process.c
diff -r efb5a7c51788 -r 6044ccdc30af usr.bin/sed/POSIX
--- a/usr.bin/sed/POSIX Fri Jun 06 00:11:19 2014 +0000
+++ b/usr.bin/sed/POSIX Fri Jun 06 00:13:13 2014 +0000
@@ -1,5 +1,6 @@
-#      $NetBSD: POSIX,v 1.4 1997/01/09 20:21:25 tls Exp $
-#      from: @(#)POSIX 8.1 (Berkeley) 6/6/93
+# $NetBSD: POSIX,v 1.5 2014/06/06 00:13:13 christos Exp $
+#      @(#)POSIX       8.1 (Berkeley) 6/6/93
+# $FreeBSD: head/usr.bin/sed/POSIX 168417 2007-04-06 08:43:30Z yar $
 
 Comments on the IEEE P1003.2 Draft 12
      Part 2: Shell and Utilities
@@ -118,10 +119,15 @@
        1,3c\
                text
 
-       Historic implementations, and this implementation, do not output
-       the text in the above example.  The general rule, therefore,
-       is that a range whose second address is never matched extends to
-       the end of the input.
+       Historic implementations did not output the text in the above
+       example.  Therefore it was believed that a range whose second
+       address was never matched extended to the end of the input.
+       However, the current practice adopted by this implementation,
+       as well as by those from GNU and SUN, is as follows:  The text
+       from the 'c' command still isn't output because the second address
+       isn't actually matched; but the range is reset after all if its
+       second address is a line number.  In the above example, only the
+       first line of the input will be deleted.
 
 13.    Historical implementations allow an output suppressing #n at the
        beginning of -e arguments as well as in a script file.  POSIX
diff -r efb5a7c51788 -r 6044ccdc30af usr.bin/sed/compile.c
--- a/usr.bin/sed/compile.c     Fri Jun 06 00:11:19 2014 +0000
+++ b/usr.bin/sed/compile.c     Fri Jun 06 00:13:13 2014 +0000
@@ -1,6 +1,7 @@
-/*     $NetBSD: compile.c,v 1.40 2014/05/05 17:12:11 christos Exp $    */
+/*     $NetBSD: compile.c,v 1.41 2014/06/06 00:13:13 christos Exp $    */
 
 /*-
+ * Copyright (c) 1992 Diomidis Spinellis.
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -32,58 +33,25 @@
  * SUCH DAMAGE.
  */
 
-/*-
- * Copyright (c) 1992 Diomidis Spinellis.
- *
- * This code is derived from software contributed to Berkeley by
- * Diomidis Spinellis of Imperial College, University of London.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
 #if HAVE_NBTOOL_CONFIG_H
 #include "nbtool_config.h"
 #endif
 
 #include <sys/cdefs.h>
+__RCSID("$NetBSD: compile.c,v 1.41 2014/06/06 00:13:13 christos Exp $");
+#ifdef __FBSDID
+__FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 259132 2013-12-09 18:57:20Z eadler $");
+#endif
+
 #ifndef lint
-#if 0
-static char sccsid[] = "@(#)compile.c  8.2 (Berkeley) 4/28/95";
-#else
-__RCSID("$NetBSD: compile.c,v 1.40 2014/05/05 17:12:11 christos Exp $");
+static const char sccsid[] = "@(#)compile.c    8.1 (Berkeley) 6/6/93";
 #endif
-#endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
 #include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -91,14 +59,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <wchar.h>
 
 #include "defs.h"
 #include "extern.h"
 
-#ifndef _POSIX2_LINE_MAX
-#define _POSIX2_LINE_MAX (2 * BUFSIZ)
-#endif
-
 #define LHSZ   128
 #define        LHMASK  (LHSZ - 1)
 static struct labhash {
@@ -110,12 +75,12 @@
 
 static char     *compile_addr(char *, struct s_addr *);
 static char     *compile_ccl(char **, char *);
-static char     *compile_delimited(char *, char *);
+static char     *compile_delimited(char *, char *, int);
 static char     *compile_flags(char *, struct s_subst *);
-static char     *compile_re(char *, regex_t **);
+static regex_t  *compile_re(char *, int);
 static char     *compile_subst(char *, struct s_subst *);
 static char     *compile_text(void);
-static char     *compile_tr(char *, char **);
+static char     *compile_tr(char *, struct s_tr **);
 static struct s_command
                **compile_stream(struct s_command **);
 static char     *duptoeol(char *, const char *);
@@ -184,39 +149,43 @@
        match = xmalloc((maxnsub + 1) * sizeof(regmatch_t));
 }
 
-#define EATSPACE()                                             \
-       while (*p && isascii((unsigned char)*p) &&              \
-           isspace((unsigned char)*p))                         \
-               p++                                             \
+#define EATSPACE() do {                                                        \
+       if (p)                                                          \
+               while (*p && isspace((unsigned char)*p))                \
+                       p++;                                            \
+       } while (0)
 
 static struct s_command **
 compile_stream(struct s_command **link)
 {
        char *p;
-       static char *lbuf;      /* To avoid excessive malloc calls */
-       static size_t bufsize;
+       static char lbuf[_POSIX2_LINE_MAX + 1]; /* To save stack */
        struct s_command *cmd, *cmd2, *stack;
        struct s_format *fp;
+       char re[_POSIX2_LINE_MAX + 1];
        int naddr;                              /* Number of addresses */
 
        stack = 0;
        for (;;) {
-               if ((p = cu_fgets(&lbuf, &bufsize)) == NULL) {
+               if ((p = cu_fgets(lbuf, sizeof(lbuf), NULL)) == NULL) {
                        if (stack != 0)
-                               err(COMPILE, "unexpected EOF (pending }'s)");
+                               errx(1, "%lu: %s: unexpected EOF (pending }'s)",
+                                                       linenum, fname);
                        return (link);
                }
 
 semicolon:     EATSPACE();
-               if (*p == '#' || *p == '\0')
-                       continue;
-               else if (*p == ';') {
-                       p++;
-                       goto semicolon;
+               if (p) {
+                       if (*p == '#' || *p == '\0')
+                               continue;
+                       else if (*p == ';') {
+                               p++;
+                               goto semicolon;
+                       }
                }
                *link = cmd = xmalloc(sizeof(struct s_command));
                link = &cmd->next;
-               cmd->nonsel = cmd->inrange = 0;
+               cmd->startline = cmd->nonsel = 0;
                /* First parse the addresses */
                naddr = 0;
 
@@ -241,16 +210,17 @@
 
 nonsel:                /* Now parse the command */
                if (!*p)
-                       err(COMPILE, "command expected");
+                       errx(1, "%lu: %s: command expected", linenum, fname);
                cmd->code = *p;
                for (fp = cmd_fmts; fp->code; fp++)
                        if (fp->code == *p)
                                break;
                if (!fp->code)
-                       err(COMPILE, "invalid command code %c", *p);
+                       errx(1, "%lu: %s: invalid command code %c", linenum, fname, *p);
                if (naddr > fp->naddr)
-                       err(COMPILE,
-"command %c expects up to %d address(es), found %d", *p, fp->naddr, naddr);
+                       errx(1,
+                               "%lu: %s: command %c expects up to %d address(es), found %d",
+                               linenum, fname, *p, fp->naddr, naddr);
                switch (fp->args) {
                case NONSEL:                    /* ! */
                        p++;
@@ -273,7 +243,7 @@
                         */
                        cmd->nonsel = 1;
                        if (stack == 0)
-                               err(COMPILE, "unexpected }");
+                               errx(1, "%lu: %s: unexpected }", linenum, fname);
                        cmd2 = stack;
                        stack = cmd2->next;
                        cmd2->next = cmd;
@@ -291,21 +261,22 @@
                        case '\0':
                                break;
                        default:
-                               err(COMPILE,
-"extra characters at the end of %c command", cmd->code);
+                               errx(1, "%lu: %s: extra characters at the end of %c command",
+                                               linenum, fname, cmd->code);
                        }
                        break;
                case TEXT:                      /* a c i */
                        p++;
                        EATSPACE();
                        if (*p != '\\')
-                               err(COMPILE,
-"command %c expects \\ followed by text", cmd->code);
+                               errx(1,
+"%lu: %s: command %c expects \\ followed by text", linenum, fname, cmd->code);
                        p++;
                        EATSPACE();
                        if (*p)
-                               err(COMPILE,
-"extra characters after \\ at the end of %c command", cmd->code);
+                               errx(1,
+                               "%lu: %s: extra characters after \\ at the end of %c command",
+                               linenum, fname, cmd->code);
                        cmd->t = compile_text();
                        break;
                case COMMENT:                   /* \0 # */
@@ -314,20 +285,20 @@
                        p++;
                        EATSPACE();
                        if (*p == '\0')
-                               err(COMPILE, "filename expected");
+                               errx(1, "%lu: %s: filename expected", linenum, fname);
                        cmd->t = duptoeol(p, "w command");
                        if (aflag)
                                cmd->u.fd = -1;
-                       else if ((cmd->u.fd = open(p, 
+                       else if ((cmd->u.fd = open(p,
                            O_WRONLY|O_APPEND|O_CREAT|O_TRUNC,
                            DEFFILEMODE)) == -1)
-                               err(FATAL, "%s: %s", p, strerror(errno));
+                               err(1, "%s", p);
                        break;
                case RFILE:                     /* r */
                        p++;
                        EATSPACE();
                        if (*p == '\0')
-                               err(COMPILE, "filename expected");
+                               errx(1, "%lu: %s: filename expected", linenum, fname);
                        else
                                cmd->t = duptoeol(p, "read command");
                        break;
@@ -344,21 +315,35 @@
                        EATSPACE();



Home | Main Index | Thread Index | Old Index