tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: sed -u option
On Tue, 17 Jun 2014 12:30:35 -0400, christos%zoulas.com@localhost (Christos
Zoulas) wrote:
> Yes. Follow GNU. No point in making -u line-buffered, when we have -l for it!
> Also what does 'u' stand for on OpenBSD? 'U'npredictable?
How about this patch?
Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/sed/main.c,v
retrieving revision 1.24
diff -u -r1.24 main.c
--- main.c 6 Jun 2014 12:46:54 -0000 1.24
+++ main.c 25 Jun 2014 13:27:56 -0000
@@ -105,6 +105,7 @@
int aflag, eflag, nflag;
int rflags = 0;
+static int uflag;
static int rval; /* Exit status */
static int ispan; /* Whether inplace editing spans across files */
@@ -137,7 +138,7 @@
fflag = 0;
inplace = NULL;
- while ((c = getopt(argc, argv, "EI::ae:f:i::lnr")) != -1)
+ while ((c = getopt(argc, argv, "EI::ae:f:i::lnru")) != -1)
switch (c) {
case 'r': /* Gnu sed compat */
case 'E':
@@ -165,6 +166,14 @@
inplace = optarg ? optarg : __UNCONST("");
ispan = 0; /* don't span across input files */
break;
+ case 'u':
+ uflag = 1;
+#ifdef _IONBF
+ c = setvbuf(stdout, NULL, _IONBF, 0);
+ if (c)
+ warn("setting no buffered output failed");
+#endif
+ break;
case 'l':
#ifdef _IOLBF
c = setvbuf(stdout, NULL, _IOLBF, 0);
@@ -209,8 +218,8 @@
usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
- "usage: sed script [-Ealn] [-i extension] [file ...]",
- " sed [-Ealn] [-i extension] [-e script] ... [-f
script_file] ... [file ...]");
+ "usage: sed script [-Ealnru] [-i extension] [file ...]",
+ " sed [-Ealnru] [-i extension] [-e script] ... [-f
script_file] ... [file ...]");
exit(1);
}
@@ -434,6 +443,13 @@
rval = 1;
continue;
}
+ if (uflag) {
+#ifdef _IONBF
+ c = setvbuf(infile, NULL, _IONBF, 0);
+ if (c)
+ warn("setting no buffered input failed");
+#endif
+ }
}
/*
* We are here only when infile is open and we still have something
Index: sed.1
===================================================================
RCS file: /cvsroot/src/usr.bin/sed/sed.1,v
retrieving revision 1.34
diff -u -r1.34 sed.1
--- sed.1 6 Jun 2014 14:36:38 -0000 1.34
+++ sed.1 25 Jun 2014 13:27:56 -0000
@@ -40,11 +40,11 @@
.Nd stream editor
.Sh SYNOPSIS
.Nm
-.Op Fl Ealnr
+.Op Fl Ealnru
.Ar command
.Op Ar
.Nm
-.Op Fl Ealnr
+.Op Fl Ealnru
.Op Fl e Ar command
.Op Fl f Ar command_file
.Op Fl I Op Ar extension
@@ -149,6 +149,8 @@
Same as
.Fl E
for compatibility with GNU sed.
+.It Fl u
+Unbuffered input and output.
.El
.Pp
The form of a
@@ -599,9 +601,9 @@
specification.
.Pp
The
-.Fl E , I , a
+.Fl E , I , a , i , l , r
and
-.Fl i
+.Fl u
options, the prefixing
.Dq \&+
in the second member of an address range,
Home |
Main Index |
Thread Index |
Old Index