Submitted by: Joachim Kuebart, thanks.

Add -u option to force unbuffered output
This commit is contained in:
helbig 1997-10-12 09:52:49 +00:00
parent 7694ff8663
commit ba81afcca2
2 changed files with 23 additions and 11 deletions

View File

@ -34,7 +34,7 @@
.\" .\"
.\" @(#)tr.1 8.1 (Berkeley) 6/6/93 .\" @(#)tr.1 8.1 (Berkeley) 6/6/93
.\" .\"
.Dd June 6, 1993 .Dd October 11, 1997
.Dt TR 1 .Dt TR 1
.Os .Os
.Sh NAME .Sh NAME
@ -42,18 +42,18 @@
.Nd translate characters .Nd translate characters
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm tr .Nm tr
.Op Fl cs .Op Fl csu
.Ar string1 string2 .Ar string1 string2
.Nm tr .Nm tr
.Op Fl c .Op Fl cu
.Fl d .Fl d
.Ar string1 .Ar string1
.Nm tr .Nm tr
.Op Fl c .Op Fl cu
.Fl s .Fl s
.Ar string1 .Ar string1
.Nm tr .Nm tr
.Op Fl c .Op Fl cu
.Fl ds .Fl ds
.Ar string1 string2 .Ar string1 string2
.Sh DESCRIPTION .Sh DESCRIPTION
@ -82,6 +82,10 @@ or
.Ar string2 ) .Ar string2 )
in the input into a single instance of the character. in the input into a single instance of the character.
This occurs after all deletion and translation is completed. This occurs after all deletion and translation is completed.
.It Fl u
The
.Fl u
option guarantees that any output is unbuffered.
.El .El
.Pp .Pp
In the first synopsis form, the characters in In the first synopsis form, the characters in
@ -290,3 +294,8 @@ has less characters than
is permitted by POSIX but is not required. is permitted by POSIX but is not required.
Shell scripts attempting to be portable to other POSIX systems should use Shell scripts attempting to be portable to other POSIX systems should use
the ``[#*]'' convention instead of relying on this behavior. the ``[#*]'' convention instead of relying on this behavior.
The
.Fl u
option is an extension to the
.St -p1003.2
standard.

View File

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id$"; "$Id: tr.c,v 1.6 1997/08/18 07:24:58 charnier Exp $";
#endif /* not lint */ #endif /* not lint */
#include <locale.h> #include <locale.h>
@ -108,7 +108,7 @@ main(argc, argv)
(void) setlocale(LC_CTYPE, ""); (void) setlocale(LC_CTYPE, "");
cflag = dflag = sflag = 0; cflag = dflag = sflag = 0;
while ((ch = getopt(argc, argv, "cds")) != -1) while ((ch = getopt(argc, argv, "cdsu")) != -1)
switch((char)ch) { switch((char)ch) {
case 'c': case 'c':
cflag = 1; cflag = 1;
@ -119,6 +119,9 @@ main(argc, argv)
case 's': case 's':
sflag = 1; sflag = 1;
break; break;
case 'u':
setbuf(stdout, (char *)NULL);
break;
case '?': case '?':
default: default:
usage(); usage();
@ -262,9 +265,9 @@ static void
usage() usage()
{ {
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n", (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: tr [-cs] string1 string2", "usage: tr [-csu] string1 string2",
" tr [-c] -d string1", " tr [-cu] -d string1",
" tr [-c] -s string1", " tr [-cu] -s string1",
" tr [-c] -ds string1 string2"); " tr [-cu] -ds string1 string2");
exit(1); exit(1);
} }