FreeBSD Bugzilla – Attachment 10945 Details for
Bug 21766
[PATCH] add -s (skip) flag to head(1)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 2.99 KB, created by
Peter Pentchev
on 2000-10-05 14:00:04 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Peter Pentchev
Created:
2000-10-05 14:00:04 UTC
Size:
2.99 KB
patch
obsolete
>diff -urN src/usr.bin/head/head.1 mysrc/usr.bin/head/head.1 >--- src/usr.bin/head/head.1 Sat Aug 28 04:01:58 1999 >+++ mysrc/usr.bin/head/head.1 Thu Oct 5 15:43:08 2000 >@@ -42,6 +42,7 @@ > .Nm head > .Op Fl n Ar count > .Op Fl c Ar bytes >+.Op Fl s Ar skipcount > .Op Ar file ... > .Sh DESCRIPTION > This filter displays the first >@@ -60,6 +61,14 @@ > where > .Dq XXX > is the name of the file. >+.Pp >+If >+.Ar skipcount >+is specified, the >+.Nm head >+utility skips the specified number of lines or bytes before displaying >+the requested >+.Ar count . > .Pp > The > .Nm head >diff -urN src/usr.bin/head/head.c mysrc/usr.bin/head/head.c >--- src/usr.bin/head/head.c Sat Aug 28 04:01:58 1999 >+++ mysrc/usr.bin/head/head.c Thu Oct 5 15:37:31 2000 >@@ -60,8 +60,8 @@ > * Bill Joy UCB August 24, 1977 > */ > >-void head __P((FILE *, int)); >-void head_bytes __P((FILE *, int)); >+void head __P((FILE *, int, int)); >+void head_bytes __P((FILE *, int, int)); > void obsolete __P((char *[])); > void usage __P((void)); > >@@ -74,11 +74,11 @@ > { > register int ch; > FILE *fp; >- int first, linecnt = -1, bytecnt = -1; >+ int first, linecnt = -1, bytecnt = -1, skipcnt = 0; > char *ep; > > obsolete(argv); >- while ((ch = getopt(argc, argv, "n:c:")) != -1) >+ while ((ch = getopt(argc, argv, "n:c:s:")) != -1) > switch(ch) { > case 'c': > bytecnt = strtol(optarg, &ep, 10); >@@ -90,6 +90,11 @@ > if (*ep || linecnt <= 0) > errx(1, "illegal line count -- %s", optarg); > break; >+ case 's': >+ skipcnt = strtol(optarg, &ep, 10); >+ if (*ep || skipcnt <= 0) >+ errx(1, "illegal skip count -- %s", optarg); >+ break; > case '?': > default: > usage(); >@@ -113,40 +118,49 @@ > first ? "" : "\n", *argv); > first = 0; > } >- if (bytecnt == -1) >- head(fp, linecnt); >- else >- head_bytes(fp, bytecnt); >+ if (bytecnt == -1) { >+ if (skipcnt) head(fp, skipcnt, 0); >+ head(fp, linecnt, 1); >+ } else { >+ if (skipcnt) head_bytes(fp, skipcnt, 0); >+ head_bytes(fp, bytecnt, 1); >+ } > (void)fclose(fp); > } > } >- else if (bytecnt == -1) >- head(stdin, linecnt); >- else >- head_bytes(stdin, bytecnt); >+ else if (bytecnt == -1) { >+ if (skipcnt) head(stdin, skipcnt, 0); >+ head(stdin, linecnt, 1); >+ } else { >+ if (skipcnt) head_bytes(stdin, skipcnt, 0); >+ head_bytes(stdin, bytecnt, 1); >+ } > > exit(eval); > } > > void >-head(fp, cnt) >+head(fp, cnt, out) > FILE *fp; > register int cnt; >+ int out; > { > register int ch; > > while (cnt && (ch = getc(fp)) != EOF) { >+ if (out) > if (putchar(ch) == EOF) > err(1, "stdout"); >- if (ch == '\n') >- cnt--; >- } >+ if (ch == '\n') >+ cnt--; >+ } > } > > void >-head_bytes(fp, cnt) >+head_bytes(fp, cnt, out) > FILE *fp; > register int cnt; >+ int out; > { > char buf[4096]; > register int readlen; >@@ -159,8 +173,9 @@ > readlen = fread(buf, sizeof(char), readlen, fp); > if (readlen == 0) > break; >- if (fwrite(buf, sizeof(char), readlen, stdout) != readlen) >- err(1, "stdout"); >+ if (out) >+ if (fwrite(buf, sizeof(char), readlen, stdout) != readlen) >+ err(1, "stdout"); > cnt -= readlen; > } > }
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 21766
: 10945