Add a -q option to suppress header lines when multiple files are specified
  (and fixes from Ruslan).

      src/usr.bin/tail/extern.h: rev 1.9 -> 1.10
      src/usr.bin/tail/tail.1: rev 1.12 -> 1.13
      src/usr.bin/tail/forward.c: rev 1.39 -> 1.40
      src/usr.bin/tail/tail.c: rev 1.21 -> 1.22
This commit is contained in:
flz 2006-07-06 12:56:38 +00:00
parent f1f47c97e3
commit 3a998b0102
4 changed files with 19 additions and 9 deletions

View File

@ -72,5 +72,5 @@ void oerr(void);
int mapprint(struct mapinfo *, off_t, off_t);
int maparound(struct mapinfo *, off_t);
extern int Fflag, fflag, rflag, rval, no_files;
extern int Fflag, fflag, qflag, rflag, rval, no_files;
extern const char *fname;

View File

@ -249,7 +249,8 @@ show(file_info_t *file)
while ((ch = getc(file->fp)) != EOF) {
if (last != file && no_files > 1) {
(void)printf("\n==> %s <==\n", file->file_name);
if (!qflag)
(void)printf("\n==> %s <==\n", file->file_name);
last = file;
}
if (putchar(ch) == EOF)
@ -322,7 +323,7 @@ follow(file_info_t *files, enum STYLE style, off_t off)
if (file->fp) {
active = 1;
n++;
if (no_files > 1)
if (no_files > 1 && !qflag)
(void)printf("\n==> %s <==\n", file->file_name);
forward(file->fp, style, off, &file->st);
if (Fflag && fileno(file->fp) != STDIN_FILENO)

View File

@ -35,7 +35,7 @@
.\" @(#)tail.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
.Dd June 6, 1993
.Dd July 6, 2006
.Dt TAIL 1
.Os
.Sh NAME
@ -48,6 +48,7 @@
.Fl f |
.Fl r
.Oc
.Op Fl q
.Oo
.Fl b Ar number |
.Fl c Ar number |
@ -114,6 +115,8 @@ option is ignored if reading from standard input rather than a file.
The location is
.Ar number
lines.
.It Fl q
Suppresses printing of headers when multiple files are being examined.
.It Fl r
The
.Fl r
@ -139,7 +142,9 @@ header consisting of the string
.Dq ==> XXX <==
where
.Dq XXX
is the name of the file.
is the name of the file unless
.Fl q
flag is specified.
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO

View File

@ -60,7 +60,7 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93";
#include "extern.h"
int Fflag, fflag, rflag, rval, no_files;
int Fflag, fflag, qflag, rflag, rval, no_files;
const char *fname;
file_info_t *files;
@ -114,7 +114,7 @@ main(int argc, char *argv[])
obsolete(argv);
style = NOTSET;
while ((ch = getopt(argc, argv, "Fb:c:fn:r")) != -1)
while ((ch = getopt(argc, argv, "Fb:c:fn:qr")) != -1)
switch(ch) {
case 'F': /* -F is superset of (and implies) -f */
Fflag = fflag = 1;
@ -131,6 +131,9 @@ main(int argc, char *argv[])
case 'n':
ARG(1, FLINES, RLINES);
break;
case 'q':
qflag = 1;
break;
case 'r':
rflag = 1;
break;
@ -199,7 +202,7 @@ main(int argc, char *argv[])
ierr();
continue;
}
if (argc > 1) {
if (argc > 1 && !qflag) {
(void)printf("%s==> %s <==\n",
first ? "" : "\n", fname);
first = 0;
@ -329,6 +332,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
"usage: tail [-F | -f | -r] [-b # | -c # | -n #] [file ...]\n");
"usage: tail [-F | -f | -r] [-q] [-b # | -c # | -n #]"
" [file ...]\n");
exit(1);
}