FreeBSD Bugzilla – Attachment 11952 Details for
Bug 23321
[PATCH] reduce redundant code in /bin/cat
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 1.86 KB, created by
richards+bsd
on 2000-12-06 10:10:00 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
richards+bsd
Created:
2000-12-06 10:10:00 UTC
Size:
1.86 KB
patch
obsolete
>Index: cat.c >=================================================================== >RCS file: /home/ncvs/src/bin/cat/cat.c,v >retrieving revision 1.15 >diff -u -r1.15 cat.c >--- cat.c 2000/04/14 21:01:35 1.15 >+++ cat.c 2000/12/06 09:54:33 >@@ -63,10 +63,9 @@ > int rval; > const char *filename; > >-void cook_args __P((char *argv[])); >-void cook_buf __P((FILE *)); >+void cat_args __P((char *argv[], void (*cat)(int))); >+void cook_buf __P((int)); > int main __P((int argc, char *argv[])); >-void raw_args __P((char *argv[])); > void raw_cat __P((int)); > > int >@@ -109,46 +108,26 @@ > argv += optind; > > if (bflag || eflag || nflag || sflag || tflag || vflag) >- cook_args(argv); >+ cat_args(argv, cook_buf); > else >- raw_args(argv); >+ cat_args(argv, raw_cat); > if (fclose(stdout)) > err(1, "stdout"); > exit(rval); > } > > void >-cook_args(argv) >- char **argv; >+cook_buf(fd) >+ register int fd; > { > register FILE *fp; >- >- fp = stdin; >- filename = "stdin"; >- do { >- if (*argv) { >- if (!strcmp(*argv, "-")) >- fp = stdin; >- else if ((fp = fopen(*argv, "r")) == NULL) { >- warn("%s", *argv); >- rval = 1; >- ++argv; >- continue; >- } >- filename = *argv++; >- } >- cook_buf(fp); >- if (fp != stdin) >- (void)fclose(fp); >- } while (*argv); >-} >- >-void >-cook_buf(fp) >- register FILE *fp; >-{ > register int ch, gobble, line, prev; > >+ if ((fp = fdopen(fd, "r")) == NULL) { >+ warn("%s", filename); >+ rval = 1; >+ return; >+ } > line = gobble = 0; > for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) { > if (prev == '\n') { >@@ -205,11 +184,14 @@ > } > if (ferror(stdout)) > err(1, "stdout"); >+ if (fd != fileno(stdin)) >+ (void)fclose(fp); > } > > void >-raw_args(argv) >+cat_args(argv, cat) > char **argv; >+ void (*cat)(int); > { > register int fd; > >@@ -227,7 +209,7 @@ > } > filename = *argv++; > } >- raw_cat(fd); >+ cat(fd); > if (fd != fileno(stdin)) > (void)close(fd); > } while (*argv);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 23321
: 11952