From ba81afcca2690699f66af2c102b1650bb4a03c0e Mon Sep 17 00:00:00 2001 From: helbig Date: Sun, 12 Oct 1997 09:52:49 +0000 Subject: [PATCH] Submitted by: Joachim Kuebart, thanks. Add -u option to force unbuffered output --- usr.bin/tr/tr.1 | 19 ++++++++++++++----- usr.bin/tr/tr.c | 15 +++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/usr.bin/tr/tr.1 b/usr.bin/tr/tr.1 index 77790736c0aa..ae6b4845d106 100644 --- a/usr.bin/tr/tr.1 +++ b/usr.bin/tr/tr.1 @@ -34,7 +34,7 @@ .\" .\" @(#)tr.1 8.1 (Berkeley) 6/6/93 .\" -.Dd June 6, 1993 +.Dd October 11, 1997 .Dt TR 1 .Os .Sh NAME @@ -42,18 +42,18 @@ .Nd translate characters .Sh SYNOPSIS .Nm tr -.Op Fl cs +.Op Fl csu .Ar string1 string2 .Nm tr -.Op Fl c +.Op Fl cu .Fl d .Ar string1 .Nm tr -.Op Fl c +.Op Fl cu .Fl s .Ar string1 .Nm tr -.Op Fl c +.Op Fl cu .Fl ds .Ar string1 string2 .Sh DESCRIPTION @@ -82,6 +82,10 @@ or .Ar string2 ) in the input into a single instance of the character. This occurs after all deletion and translation is completed. +.It Fl u +The +.Fl u +option guarantees that any output is unbuffered. .El .Pp In the first synopsis form, the characters in @@ -290,3 +294,8 @@ has less characters than is permitted by POSIX but is not required. Shell scripts attempting to be portable to other POSIX systems should use the ``[#*]'' convention instead of relying on this behavior. +The +.Fl u +option is an extension to the +.St -p1003.2 +standard. diff --git a/usr.bin/tr/tr.c b/usr.bin/tr/tr.c index fd176371c179..52ccb1a1c8c8 100644 --- a/usr.bin/tr/tr.c +++ b/usr.bin/tr/tr.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; #endif static const char rcsid[] = - "$Id$"; + "$Id: tr.c,v 1.6 1997/08/18 07:24:58 charnier Exp $"; #endif /* not lint */ #include @@ -108,7 +108,7 @@ main(argc, argv) (void) setlocale(LC_CTYPE, ""); cflag = dflag = sflag = 0; - while ((ch = getopt(argc, argv, "cds")) != -1) + while ((ch = getopt(argc, argv, "cdsu")) != -1) switch((char)ch) { case 'c': cflag = 1; @@ -119,6 +119,9 @@ main(argc, argv) case 's': sflag = 1; break; + case 'u': + setbuf(stdout, (char *)NULL); + break; case '?': default: usage(); @@ -262,9 +265,9 @@ static void usage() { (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", - "usage: tr [-cs] string1 string2", - " tr [-c] -d string1", - " tr [-c] -s string1", - " tr [-c] -ds string1 string2"); + "usage: tr [-csu] string1 string2", + " tr [-cu] -d string1", + " tr [-cu] -s string1", + " tr [-cu] -ds string1 string2"); exit(1); }