lobase

Linux port of OpenBSDs userland.
Log | Files | Refs | README

commit 8e2d83e858e6cf48ae4301766044206f0b238c06
parent 0732705d3cc6232c5ef68dd2e57e5c9cd47ea9dc
Author: Duncaen <mail@duncano.de>
Date:   Wed, 24 May 2017 02:59:59 +0200

bin/ed: update to OPENBSD_6_1

Diffstat:
bin/ed/ed.1 | 10++--------
bin/ed/main.c | 7++++---
bin/ed/sub.c | 55++++++++++++++++++++++++++++++-------------------------
3 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/bin/ed/ed.1 b/bin/ed/ed.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ed.1,v 1.67 2015/11/20 20:13:32 tb Exp $ +.\" $OpenBSD: ed.1,v 1.68 2016/09/23 06:17:43 jmc Exp $ .\" .\" Copyright (c) 1993 Andrew Moore, Talke Studio. .\" All rights reserved. @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: November 20 2015 $ +.Dd $Mdocdate: September 23 2016 $ .Dt ED 1 .Os .Sh NAME @@ -444,12 +444,6 @@ in subsequent commands. The mark is not cleared until the line is deleted or otherwise modified. .It (.,.) Ns Ic l Prints the addressed lines unambiguously. -If a single line fills more than one screen (as might be the case -when viewing a binary file, for instance), a -.Dq --More-- -prompt is printed on the last line. -.Nm -waits until the RETURN key is pressed before displaying the next screen. The current address is set to the last line printed. .It (.,.) Ns Ic m Ns (.) Moves lines in the buffer. diff --git a/bin/ed/main.c b/bin/ed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.57 2016/03/22 17:58:28 mmcc Exp $ */ +/* $OpenBSD: main.c,v 1.59 2017/01/03 20:24:29 tb Exp $ */ /* $NetBSD: main.c,v 1.3 1995/03/21 09:04:44 cgd Exp $ */ /* main.c: This file contains the main control and user-interface routines @@ -383,7 +383,8 @@ next_addr(void) ibufp++; addr_cnt++; second_addr = (c == ';') ? current_addr : 1; - addr = addr_last; + if ((addr = next_addr()) < 0) + addr = addr_last; break; } /* FALLTHROUGH */ @@ -859,7 +860,7 @@ exec_command(void) if ((addr = write_file(*fnp ? fnp : old_filename, (c == 'W') ? "a" : "w", first_addr, second_addr)) < 0) return ERR; - else if (addr == addr_last) + else if (addr == addr_last && *fnp != '!') modified = 0; else if (modified && !scripted && n == 'q') gflag = EMOD; diff --git a/bin/ed/sub.c b/bin/ed/sub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sub.c,v 1.15 2016/03/22 17:58:28 mmcc Exp $ */ +/* $OpenBSD: sub.c,v 1.18 2016/10/11 06:54:05 martijn Exp $ */ /* $NetBSD: sub.c,v 1.4 1995/03/21 09:04:50 cgd Exp $ */ /* sub.c: This file contains the substitution routines for the ed @@ -173,7 +173,8 @@ search_and_replace(regex_t *pat, int gflag, int kth) /* substitute_matching_text: replace text matched by a pattern according to - a substitution template; return pointer to the modified text */ + a substitution template; return length of rbuf if changed, 0 if unchanged, or + ERR on error */ static int substitute_matching_text(regex_t *pat, line_t *lp, int gflag, int kth) { @@ -181,48 +182,52 @@ substitute_matching_text(regex_t *pat, line_t *lp, int gflag, int kth) int changed = 0; int matchno = 0; int i = 0; + int nempty = -1; regmatch_t rm[SE_MAX]; char *txt; - char *eot; + char *eot, *eom; - if ((txt = get_sbuf_line(lp)) == NULL) + if ((eom = txt = get_sbuf_line(lp)) == NULL) return ERR; if (isbinary) NUL_TO_NEWLINE(txt, lp->len); eot = txt + lp->len; if (!regexec(pat, txt, SE_MAX, rm, 0)) { do { +/* Don't do a 0-length match directly after a non-0-length */ + if (rm[0].rm_eo == nempty) { + rm[0].rm_so++; + rm[0].rm_eo = lp->len; + continue; + } if (!kth || kth == ++matchno) { - changed++; - i = rm[0].rm_so; + changed = 1; + i = rm[0].rm_so - (eom - txt); REALLOC(rbuf, rbufsz, off + i, ERR); if (isbinary) - NEWLINE_TO_NUL(txt, rm[0].rm_eo); - memcpy(rbuf + off, txt, i); + NEWLINE_TO_NUL(eom, + rm[0].rm_eo - (eom - txt)); + memcpy(rbuf + off, eom, i); off += i; if ((off = apply_subst_template(txt, rm, off, pat->re_nsub)) < 0) return ERR; - } else { - i = rm[0].rm_eo; - REALLOC(rbuf, rbufsz, off + i, ERR); - if (isbinary) - NEWLINE_TO_NUL(txt, i); - memcpy(rbuf + off, txt, i); - off += i; + eom = txt + rm[0].rm_eo; + if (kth) + break; } - txt += rm[0].rm_eo; - } while (*txt && (!changed || ((gflag & GSG) && rm[0].rm_eo)) && - !regexec(pat, txt, SE_MAX, rm, REG_NOTBOL)); - i = eot - txt; + if (rm[0].rm_so == rm[0].rm_eo) + rm[0].rm_so = rm[0].rm_eo + 1; + else + nempty = rm[0].rm_so = rm[0].rm_eo; + rm[0].rm_eo = lp->len; + } while (rm[0].rm_so < lp->len && (gflag & GSG || kth) && + !regexec(pat, txt, SE_MAX, rm, REG_STARTEND | REG_NOTBOL)); + i = eot - eom; REALLOC(rbuf, rbufsz, off + i + 2, ERR); - if (i > 0 && !rm[0].rm_eo && (gflag & GSG)) { - seterrmsg("infinite substitution loop"); - return ERR; - } if (isbinary) - NEWLINE_TO_NUL(txt, i); - memcpy(rbuf + off, txt, i); + NEWLINE_TO_NUL(eom, i); + memcpy(rbuf + off, eom, i); memcpy(rbuf + off + i, "\n", 2); } return changed ? off + i + 1 : 0;