On Fri, May 08, 2015 at 08:27:55PM -0500, Tim Chase wrote:
> On 2015-05-08 14:30, Todd C. Miller wrote:
> > Solaris and Linux also produce "x\ny\nz\n" so that is likely the
> > expected behavior.
>
> I bumped against it while testing some scripts across various
> platforms where I saw Linux & FreeBSD yielding "x\ny\nz\n", while
> OpenBSD was the only anomaly, producing "xy\nz". Thanks for testing
> Solaris.
>
Hi,
Here a small patch to sed to make 'i' and 'a' command to always append
"\n" after 'text'.
While here, remove 'len' field from 'struct s_appends'. It was just used
for AP_STRING (used for 'a' command), and the switch from fwrite to
printf permit to not use it.
--
Sébastien Marie
Index: defs.h
===================================================================
RCS file: /cvs/src/usr.bin/sed/defs.h,v
retrieving revision 1.5
diff -u -p -r1.5 defs.h
--- defs.h 19 Jan 2015 15:30:52 -0000 1.5
+++ defs.h 9 May 2015 04:41:32 -0000
@@ -113,7 +113,6 @@ enum e_args {
struct s_appends {
enum {AP_STRING, AP_FILE} type;
char *s;
- size_t len;
};
enum e_spflag {
Index: process.c
===================================================================
RCS file: /cvs/src/usr.bin/sed/process.c,v
retrieving revision 1.23
diff -u -p -r1.23 process.c
--- process.c 18 Apr 2015 18:28:37 -0000 1.23
+++ process.c 9 May 2015 04:41:32 -0000
@@ -109,7 +109,6 @@ redirect:
}
appends[appendx].type = AP_STRING;
appends[appendx].s = cp->t;
- appends[appendx].len = strlen(cp->t);
appendx++;
break;
case 'b':
@@ -151,7 +150,7 @@ redirect:
cspace(&HS, ps, psl, 0);
break;
case 'i':
- (void)printf("%s", cp->t);
+ (void)printf("%s\n", cp->t);
break;
case 'l':
lputs(ps);
@@ -204,7 +203,6 @@ redirect:
}
appends[appendx].type = AP_FILE;
appends[appendx].s = cp->t;
- appends[appendx].len = strlen(cp->t);
appendx++;
break;
case 's':
@@ -424,8 +422,7 @@ flush_appends(void)
for (i = 0; i < appendx; i++)
switch (appends[i].type) {
case AP_STRING:
- fwrite(appends[i].s, sizeof(char), appends[i].len,
- stdout);
+ (void)printf("%s\n", appends[i].s);
break;
case AP_FILE:
/*