diff options
author | Maxim Sobolev <sobomax@FreeBSD.org> | 2002-06-28 12:04:39 +0000 |
---|---|---|
committer | Maxim Sobolev <sobomax@FreeBSD.org> | 2002-06-28 12:04:39 +0000 |
commit | 3dfd43f2197955adf86c01328c7adc3b3b1d04a1 (patch) | |
tree | 4962cbba7ffb5584c752ea76ec6d7851d589e346 /textproc | |
parent | f1bd7e458770077e23213a67cf23627a544046d2 (diff) | |
download | ports-3dfd43f2197955adf86c01328c7adc3b3b1d04a1.tar.gz ports-3dfd43f2197955adf86c01328c7adc3b3b1d04a1.zip |
Notes
Diffstat (limited to 'textproc')
-rw-r--r-- | textproc/sed_inplace/Makefile | 4 | ||||
-rw-r--r-- | textproc/sed_inplace/src/main.c | 2 | ||||
-rw-r--r-- | textproc/sed_inplace/src/process.c | 29 |
3 files changed, 20 insertions, 15 deletions
diff --git a/textproc/sed_inplace/Makefile b/textproc/sed_inplace/Makefile index 0ec69500276a..4494303348ce 100644 --- a/textproc/sed_inplace/Makefile +++ b/textproc/sed_inplace/Makefile @@ -6,7 +6,7 @@ # PORTNAME= sed_inplace -PORTVERSION= 2002.06.17 +PORTVERSION= 2002.06.28 CATEGORIES= textproc MASTER_SITES= # DISTFILES= # @@ -21,7 +21,7 @@ MAKE_ENV= PKGDIR="${PKGDIR}" .include <bsd.port.pre.mk> .if ${OSVERSION} > 500033 -IGNORE= "is in the base system" +#IGNORE= "is in the base system" .endif do-install: diff --git a/textproc/sed_inplace/src/main.c b/textproc/sed_inplace/src/main.c index 61990adddeb8..3646a1435f7e 100644 --- a/textproc/sed_inplace/src/main.c +++ b/textproc/sed_inplace/src/main.c @@ -361,6 +361,8 @@ mf_fgets(sp, spflag) p = fgetln(f, &len); if (ferror(f)) errx(1, "%s: %s", fname, strerror(errno ? errno : EIO)); + if (len != 0 && p[len - 1] == '\n') + len--; cspace(sp, p, len, spflag); linenum++; diff --git a/textproc/sed_inplace/src/process.c b/textproc/sed_inplace/src/process.c index 4212cb3b9794..2e166a451204 100644 --- a/textproc/sed_inplace/src/process.c +++ b/textproc/sed_inplace/src/process.c @@ -85,7 +85,7 @@ static regex_t *defpreg; size_t maxnsub; regmatch_t *match; -#define OUT(s) { fwrite(s, sizeof(u_char), psl, stdout); } +#define OUT(s) { fwrite(s, sizeof(u_char), psl, stdout); putchar('\n'); } void process() @@ -148,14 +148,14 @@ redirect: cspace(&PS, hs, hsl, REPLACE); break; case 'G': - if (hs == NULL) - cspace(&HS, "\n", 1, REPLACE); + cspace(&PS, "\n", 1, 0); cspace(&PS, hs, hsl, 0); break; case 'h': cspace(&HS, ps, psl, REPLACE); break; case 'H': + cspace(&HS, "\n", 1, 0); cspace(&HS, ps, psl, 0); break; case 'i': @@ -174,6 +174,7 @@ redirect: break; case 'N': flush_appends(); + cspace(&PS, "\n", 1, 0); if (!mf_fgets(&PS, 0)) { if (!nflag && !pd) OUT(ps) @@ -191,7 +192,7 @@ redirect: if (psl != 0 && (p = memchr(ps, '\n', psl - 1)) != NULL) { oldpsl = psl; - psl = (p + 1) - ps; + psl = p - ps; } OUT(ps) if (p != NULL) @@ -230,12 +231,11 @@ redirect: O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) err(1, "%s", cp->t); - if (write(cp->u.fd, ps, psl) != psl) + if (write(cp->u.fd, ps, psl) != psl || + write(cp->u.fd, "\n", 1) != 1) err(1, "%s", cp->t); break; case 'x': - if (hs == NULL) - cspace(&HS, "\n", 1, REPLACE); tspace = PS; PS = HS; HS = tspace; @@ -243,7 +243,7 @@ redirect: case 'y': if (pd || psl == 0) break; - for (p = ps, len = psl; --len; ++p) + for (p = ps, len = psl; len--; ++p) *p = cp->u.y[(unsigned char)*p]; break; case ':': @@ -418,7 +418,8 @@ substitute(cp) if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) err(1, "%s", cp->u.s->wfile); - if (write(cp->u.s->wfd, ps, psl) != psl) + if (write(cp->u.s->wfd, ps, psl) != psl || + write(cp->u.s->wfd, "\n", 1) != 1) err(1, "%s", cp->u.s->wfile); } return (1); @@ -489,7 +490,11 @@ lputs(s) if (isprint((unsigned char)*s) && *s != '\\') { (void)putchar(*s); count++; - } else if (*s != '\n') { + } else if (*s == '\n') { + (void)putchar('$'); + (void)putchar('\n'); + count = 0; + } else { escapes = "\\\a\b\f\r\t\v"; (void)putchar('\\'); if ((p = strchr(escapes, *s))) { @@ -522,9 +527,7 @@ regexec_e(preg, string, eflags, nomatch, slen) } else defpreg = preg; - /* Set anchors, discounting trailing newline (if any). */ - if (slen > 0 && string[slen - 1] == '\n') - slen--; + /* Set anchors */ match[0].rm_so = 0; match[0].rm_eo = slen; |