Index: src/gnu/usr.bin/rcs/ident/ident.c =================================================================== RCS file: /home/ncvs/src/gnu/usr.bin/rcs/ident/ident.c,v retrieving revision 1.8 diff -u -r1.8 ident.c --- src/gnu/usr.bin/rcs/ident/ident.c 10 Dec 2001 20:44:31 -0000 1.8 +++ src/gnu/usr.bin/rcs/ident/ident.c 9 Dec 2003 09:26:28 -0000 @@ -98,8 +98,8 @@ #include "rcsbase.h" -static int match P((FILE*)); -static int scanfile P((FILE*,char const*,int)); +static int match P((FILE*,char const*,int,int)); +static int scanfile P((FILE*,char const*,int,int)); static void reportError P((char const*)); mainProg(identId, "ident", "$FreeBSD: src/gnu/usr.bin/rcs/ident/ident.c,v 1.8 2001/12/10 20:44:31 peter Exp $") @@ -109,13 +109,17 @@ { FILE *fp; - int quiet = 0; + int quiet = 0, printfname = 0; int status = EXIT_SUCCESS; char const *a; while ((a = *++argv) && *a=='-') while (*++a) switch (*a) { + case 'f': + printfname = quiet = 1; + break; + case 'q': quiet = 1; break; @@ -127,7 +131,7 @@ default: VOID fprintf(stderr, - "ident: usage: ident -{qV} [file...]\n" + "ident: usage: ident -{fqV} [file...]\n" ); exitmain(EXIT_FAILURE); break; @@ -135,15 +139,15 @@ if (0 <= quiet) if (!a) - VOID scanfile(stdin, (char*)0, quiet); + VOID scanfile(stdin, (char*)0, quiet, printfname); else do { if (!(fp = fopen(a, FOPEN_RB))) { reportError(a); status = EXIT_FAILURE; } else if ( - scanfile(fp, a, quiet) != 0 - || (argv[1] && putchar('\n') == EOF) + scanfile(fp, a, quiet, printfname) != 0 + || (argv[1] && !quiet && putchar('\n') == EOF) ) break; } while ((a = *++argv)); @@ -176,26 +180,28 @@ static int -scanfile(file, name, quiet) +scanfile(file, name, quiet, printfname) register FILE *file; char const *name; - int quiet; + int quiet, printfname; /* Function: scan an open file with descriptor file for keywords. * Return -1 if there's a write error; exit immediately on a read error. */ { register int c; + int rquiet; - if (name) { + rquiet = quiet; + if (name && !quiet) { VOID printf("%s:\n", name); if (ferror(stdout)) return -1; - } else + } else if (!quiet) name = "standard input"; c = 0; while (c != EOF || ! (feof(file)|ferror(file))) { if (c == KDELIM) { - if ((c = match(file))) + if ((c = match(file, name, rquiet, printfname))) continue; if (ferror(stdout)) return -1; @@ -221,8 +227,10 @@ static int -match(fp) /* group substring between two KDELIM's; then do pattern match */ +match(fp, fname, quiet, printfname) /* group substring between two KDELIM's; then do pattern match */ register FILE *fp; + char const *fname; + int quiet, printfname; { char line[BUFSIZ]; register int c; @@ -265,6 +273,8 @@ return c; *tp++ = c; /*append trailing KDELIM*/ *tp = '\0'; - VOID printf(" %c%s\n", KDELIM, line); + if (printfname) + VOID printf("%s:", fname); + VOID printf("%s%c%s\n", quiet? "": " ", KDELIM, line); return 0; }