Submitted by: Joachim Kuebart, thanks.

Add -u option to force unbuffered output
This commit is contained in:
Wolfgang Helbig 1997-10-12 09:52:49 +00:00
parent 4dec470e39
commit 69bd8767a9
2 changed files with 23 additions and 11 deletions

View File

@ -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.

View File

@ -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 <locale.h>
@ -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);
}