sed: add -u flag that flushes output buffers before reading in further input
This commit is contained in:
parent
20b945a382
commit
7ade57b678
2 changed files with 36 additions and 3 deletions
|
@ -10,6 +10,9 @@ sed \- stream editor
|
||||||
.B -g
|
.B -g
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
|
.B -u
|
||||||
|
]
|
||||||
|
[
|
||||||
.B -e
|
.B -e
|
||||||
.I script
|
.I script
|
||||||
]
|
]
|
||||||
|
@ -44,6 +47,11 @@ option suppresses the default output;
|
||||||
.B -g
|
.B -g
|
||||||
causes all substitutions to be global, as if suffixed
|
causes all substitutions to be global, as if suffixed
|
||||||
.BR g .
|
.BR g .
|
||||||
|
If
|
||||||
|
.B -u
|
||||||
|
is specified,
|
||||||
|
.I sed
|
||||||
|
flushes its output buffers before reading in further input.
|
||||||
.PP
|
.PP
|
||||||
A script consists of editing commands, one per line,
|
A script consists of editing commands, one per line,
|
||||||
of the following form:
|
of the following form:
|
||||||
|
@ -411,3 +419,8 @@ If input is from a pipe, buffering may consume
|
||||||
characters beyond a line on which a
|
characters beyond a line on which a
|
||||||
.L q
|
.L q
|
||||||
command is executed.
|
command is executed.
|
||||||
|
.PP
|
||||||
|
.B -u
|
||||||
|
does not work as expected if
|
||||||
|
.B $
|
||||||
|
addressing is used.
|
||||||
|
|
|
@ -96,6 +96,8 @@ SedCom pspace[MAXCMDS]; /* Command storage */
|
||||||
SedCom *pend = pspace+MAXCMDS; /* End of command storage */
|
SedCom *pend = pspace+MAXCMDS; /* End of command storage */
|
||||||
SedCom *rep = pspace; /* Current fill point */
|
SedCom *rep = pspace; /* Current fill point */
|
||||||
|
|
||||||
|
int dollars; /* Number of dollar addresses */
|
||||||
|
|
||||||
Reprog *lastre; /* Last regular expression */
|
Reprog *lastre; /* Last regular expression */
|
||||||
Resub subexp[MAXSUB]; /* sub-patterns of pattern match*/
|
Resub subexp[MAXSUB]; /* sub-patterns of pattern match*/
|
||||||
|
|
||||||
|
@ -136,6 +138,7 @@ Rune *hspend = holdsp; /* End of hold data */
|
||||||
|
|
||||||
int nflag; /* Command line flags */
|
int nflag; /* Command line flags */
|
||||||
int gflag;
|
int gflag;
|
||||||
|
int uflag;
|
||||||
|
|
||||||
int dolflag; /* Set when at true EOF */
|
int dolflag; /* Set when at true EOF */
|
||||||
int sflag; /* Set when substitution done */
|
int sflag; /* Set when substitution done */
|
||||||
|
@ -233,6 +236,9 @@ main(int argc, char **argv)
|
||||||
case 'n':
|
case 'n':
|
||||||
nflag++;
|
nflag++;
|
||||||
continue;
|
continue;
|
||||||
|
case 'u':
|
||||||
|
uflag++;
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
quit("Unknown flag: %c", ARGC());
|
quit("Unknown flag: %c", ARGC());
|
||||||
} ARGEND
|
} ARGEND
|
||||||
|
@ -681,6 +687,16 @@ regerror(char *s)
|
||||||
quit(CGMES, L"r.e.-using", linebuf);
|
quit(CGMES, L"r.e.-using", linebuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
flushout(Biobufhdr *bp, void *v, long n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < nfiles; i++)
|
||||||
|
Bflush(fcode[i]);
|
||||||
|
return read(bp->fid, v, n);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
newfile(enum PTYPE type, char *name)
|
newfile(enum PTYPE type, char *name)
|
||||||
{
|
{
|
||||||
|
@ -690,6 +706,7 @@ newfile(enum PTYPE type, char *name)
|
||||||
if ((prog.bp = Bopen(name, OREAD)) == 0)
|
if ((prog.bp = Bopen(name, OREAD)) == 0)
|
||||||
quit("Cannot open pattern-file: %s\n", name);
|
quit("Cannot open pattern-file: %s\n", name);
|
||||||
Blethal(prog.bp, nil);
|
Blethal(prog.bp, nil);
|
||||||
|
if(uflag) Biofn(prog.bp, flushout);
|
||||||
}
|
}
|
||||||
prog.type = type;
|
prog.type = type;
|
||||||
}
|
}
|
||||||
|
@ -748,9 +765,10 @@ address(Addr *ap)
|
||||||
int c;
|
int c;
|
||||||
long lno;
|
long lno;
|
||||||
|
|
||||||
if((c = *cp++) == '$')
|
if((c = *cp++) == '$'){
|
||||||
ap->type = A_DOL;
|
ap->type = A_DOL;
|
||||||
else if(c == '/') {
|
dollars++;
|
||||||
|
}else if(c == '/') {
|
||||||
seof = c;
|
seof = c;
|
||||||
if (ap->rp = compile())
|
if (ap->rp = compile())
|
||||||
ap->type = A_RE;
|
ap->type = A_RE;
|
||||||
|
@ -1341,6 +1359,7 @@ arout(void)
|
||||||
if((fi = Bopen(buf, OREAD)) == 0)
|
if((fi = Bopen(buf, OREAD)) == 0)
|
||||||
continue;
|
continue;
|
||||||
Blethal(fi, nil);
|
Blethal(fi, nil);
|
||||||
|
if(uflag) Biofn(fi, flushout);
|
||||||
while((c = Bgetc(fi)) >= 0)
|
while((c = Bgetc(fi)) >= 0)
|
||||||
Bputc(&fout, c);
|
Bputc(&fout, c);
|
||||||
Bterm(fi);
|
Bterm(fi);
|
||||||
|
@ -1389,7 +1408,7 @@ gline(Rune *addr)
|
||||||
p = addr;
|
p = addr;
|
||||||
for (c = (peekc? peekc: Bgetrune(f)); c >= 0; c = Bgetrune(f)) {
|
for (c = (peekc? peekc: Bgetrune(f)); c >= 0; c = Bgetrune(f)) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if ((peekc = Bgetrune(f)) < 0 && fhead == nil)
|
if (dollars != 0 && (peekc = Bgetrune(f)) < 0 && fhead == nil)
|
||||||
dolflag = 1;
|
dolflag = 1;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
return p;
|
return p;
|
||||||
|
@ -1445,6 +1464,7 @@ opendata(void)
|
||||||
f = &stdin;
|
f = &stdin;
|
||||||
}
|
}
|
||||||
Blethal(f, nil);
|
Blethal(f, nil);
|
||||||
|
if(uflag) Biofn(f, flushout);
|
||||||
fhead = fhead->next;
|
fhead = fhead->next;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue