aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-05-19 18:22:21 +0200
committerDuncaen <mail@duncano.de>2017-05-19 18:41:03 +0200
commit03e13129a4c0a9756b6d6599e55a189daf5faf4e (patch)
tree4dbff98ee6238e4d6873ebafd5e5ac844916d009
parentb3fb7ce077d38f802225feeba316a4528bc2e646 (diff)
downloadlobase-03e13129a4c0a9756b6d6599e55a189daf5faf4e.tar.gz
usr.bin/sed: update to OPENBSD_6_1
-rw-r--r--usr.bin/sed/compile.c10
-rw-r--r--usr.bin/sed/defs.h3
-rw-r--r--usr.bin/sed/extern.h5
-rw-r--r--usr.bin/sed/main.c9
-rw-r--r--usr.bin/sed/misc.c21
-rw-r--r--usr.bin/sed/process.c17
-rw-r--r--usr.bin/sed/sed.114
7 files changed, 44 insertions, 35 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index b2f7d36..2d5007e 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compile.c,v 1.40 2015/10/26 22:24:44 jca Exp $ */
+/* $OpenBSD: compile.c,v 1.41 2017/01/20 10:26:16 krw Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -520,14 +520,12 @@ compile_subst(char *p, struct s_subst *s)
} else if (*p == '\n') {
error(COMPILE,
"unescaped newline inside substitute pattern");
- /* NOTREACHED */
}
*sp++ = *p;
}
size += sp - op;
} while ((p = cu_fgets(&lbuf, &bufsize)));
error(COMPILE, "unterminated substitute in regular expression");
- /* NOTREACHED */
}
/*
@@ -578,7 +576,7 @@ compile_flags(char *p, struct s_subst *s)
p++;
#ifdef HISTORIC_PRACTICE
if (*p != ' ') {
- error(WARNING, "space missing before w wfile");
+ warning("space missing before w wfile");
return (p);
}
#endif
@@ -750,7 +748,7 @@ duptoeol(char *s, char *ctype, char **semi)
*s = '\0';
}
if (ws)
- error(WARNING, "whitespace after %s", ctype);
+ warning("whitespace after %s", ctype);
len = s - start + 1;
if (semi)
*semi = s;
@@ -854,7 +852,7 @@ uselabel(void)
for (lh = labels[i]; lh != NULL; lh = next) {
next = lh->lh_next;
if (!lh->lh_ref)
- error(WARNING, "unused label '%s'",
+ warning("unused label '%s'",
lh->lh_cmd->t);
free(lh);
}
diff --git a/usr.bin/sed/defs.h b/usr.bin/sed/defs.h
index f7089ce..4864d62 100644
--- a/usr.bin/sed/defs.h
+++ b/usr.bin/sed/defs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: defs.h,v 1.7 2015/10/26 22:24:44 jca Exp $ */
+/* $OpenBSD: defs.h,v 1.8 2017/01/20 10:26:16 krw Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
* Copyright (c) 1992, 1993
@@ -136,7 +136,6 @@ typedef struct {
/*
* Error severity codes:
*/
-#define WARNING 0 /* Just print the warning */
#define FATAL 1 /* Exit immediately with 1 */
#define COMPILE 2 /* Print error, count and finish script */
diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h
index ea51bdb..ae3cc69 100644
--- a/usr.bin/sed/extern.h
+++ b/usr.bin/sed/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.11 2015/10/26 14:08:47 mmcc Exp $ */
+/* $OpenBSD: extern.h,v 1.12 2017/01/20 10:26:16 krw Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
* Copyright (c) 1992, 1993
@@ -48,7 +48,8 @@ void cfclose(struct s_command *, struct s_command *);
void compile(void);
void cspace(SPACE *, const char *, size_t, enum e_spflag);
char *cu_fgets(char **, size_t *);
-void error(int, const char *, ...);
+__dead void error(int, const char *, ...);
+void warning(const char *, ...);
int mf_fgets(SPACE *, enum e_spflag);
int lastline(void);
void process(void);
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index cddafbb..bd69dc8 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.33 2016/07/14 08:31:18 semarie Exp $ */
+/* $OpenBSD: main.c,v 1.34 2017/01/20 10:26:16 krw Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -285,7 +285,8 @@ again:
}
}
}
- /* NOTREACHED */
+
+ return (NULL);
}
/*
@@ -329,7 +330,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
fclose(infile);
if (*oldfname != '\0') {
if (rename(fname, oldfname) != 0) {
- error(WARNING, "rename()");
+ warning("rename()");
unlink(tmpfname);
exit(1);
}
@@ -389,7 +390,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
outfname = "stdout";
}
if ((infile = fopen(fname, "r")) == NULL) {
- error(WARNING, "%s", strerror(errno));
+ warning("%s", strerror(errno));
rval = 1;
continue;
}
diff --git a/usr.bin/sed/misc.c b/usr.bin/sed/misc.c
index e0611b8..99ff1fd 100644
--- a/usr.bin/sed/misc.c
+++ b/usr.bin/sed/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.11 2015/10/26 14:08:47 mmcc Exp $ */
+/* $OpenBSD: misc.c,v 1.12 2017/01/20 10:26:16 krw Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -101,7 +101,7 @@ strregerror(int errcode, regex_t *preg)
/*
* Error reporting function
*/
-void
+__dead void
error(int severity, const char *fmt, ...)
{
va_list ap;
@@ -109,15 +109,24 @@ error(int severity, const char *fmt, ...)
va_start(ap, fmt);
(void)fprintf(stderr, "sed: ");
switch (severity) {
- case WARNING:
case COMPILE:
(void)fprintf(stderr, "%lu: %s: ", linenum, fname);
}
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
- if (severity == WARNING)
- return;
exit(1);
- /* NOTREACHED */
+}
+
+void
+warning(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void)fprintf(stderr, "sed: ");
+ (void)fprintf(stderr, "%lu: %s: ", linenum, fname);
+ (void)vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ (void)fprintf(stderr, "\n");
}
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index 6ccd51d..d8192aa 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process.c,v 1.28 2016/05/30 18:10:29 martijn Exp $ */
+/* $OpenBSD: process.c,v 1.32 2017/02/22 14:09:09 tom Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -89,7 +89,6 @@ process(void)
SPACE tspace;
size_t len, oldpsl;
char *p;
- int oldpsanl;
for (linenum = 0; mf_fgets(&PS, REPLACE);) {
pd = 0;
@@ -185,7 +184,6 @@ redirect:
break;
if ((p = memchr(ps, '\n', psl)) != NULL) {
oldpsl = psl;
- oldpsanl = psanl;
psl = p - ps;
psanl = 1;
OUT();
@@ -393,7 +391,7 @@ substitute(struct s_command *cp)
else
slen--;
if (*s != '\0') {
- cspace(&SS, s++, 1, APPEND);
+ cspace(&SS, s++, 1, APPEND);
le++;
}
lastempty = 1;
@@ -404,7 +402,7 @@ substitute(struct s_command *cp)
regexec_e(re, ps, REG_NOTBOL, 0, le, psl));
/* Did not find the requested number of matches. */
- if (n > 1)
+ if (n > 0)
return (0);
/* Copy the trailing retained string. */
@@ -539,7 +537,6 @@ regexec_e(regex_t *preg, const char *string, int eflags,
return (0);
}
error(FATAL, "RE error: %s", strregerror(eval, defpreg));
- /* NOTREACHED */
}
/*
@@ -569,12 +566,12 @@ regsub(SPACE *sp, char *string, char *src)
else
no = -1;
if (no < 0) { /* Ordinary character. */
- if (c == '\\' && (*src == '\\' || *src == '&'))
- c = *src++;
+ if (c == '\\' && (*src == '\\' || *src == '&'))
+ c = *src++;
NEEDSP(1);
- *dst++ = c;
+ *dst++ = c;
++sp->len;
- } else if (match[no].rm_so != -1 && match[no].rm_eo != -1) {
+ } else if (match[no].rm_so != -1 && match[no].rm_eo != -1) {
len = match[no].rm_eo - match[no].rm_so;
NEEDSP(len);
memmove(dst, string + match[no].rm_so, len);
diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1
index 1e15fcb..334553b 100644
--- a/usr.bin/sed/sed.1
+++ b/usr.bin/sed/sed.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sed.1,v 1.48 2016/03/17 05:27:10 bentley Exp $
+.\" $OpenBSD: sed.1,v 1.49 2016/10/26 00:46:01 schwarze Exp $
.\"
.\" Copyright (c) 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" from: @(#)sed.1 8.2 (Berkeley) 12/30/93
.\"
-.Dd $Mdocdate: March 17 2016 $
+.Dd $Mdocdate: October 26 2016 $
.Dt SED 1
.Os
.Sh NAME
@@ -442,9 +442,13 @@ The value of
.Ar flags
in the substitute function is zero or more of the following:
.Bl -tag -width "XXXXXX" -offset indent
-.It Cm 0 No ... Cm 9
-Make the substitution only for the N'th occurrence of the regular
-expression in the pattern space.
+.It Ar N
+Make the substitution only for the
+.Ar N Ap th
+occurrence of the regular expression in the pattern space, where
+.Ar N
+is a positive integer starting with
+.Cm 1 No ... Cm 9 .
.It Cm g
Make the substitution for all non-overlapping matches of the
regular expression, not just the first one.