diff --git a/doc/ACKNOWLEDGEMENTS.md b/doc/ACKNOWLEDGEMENTS.md index 12c2325..776f232 100644 --- a/doc/ACKNOWLEDGEMENTS.md +++ b/doc/ACKNOWLEDGEMENTS.md @@ -74,6 +74,7 @@ is acknowledged and greatly appreciated: * Jakub Wilk - corrected README encoding * [ikasty](https://github.com/ikasty) - added relative filename display to "`--watchfd`" * [Michael Weiß](https://github.com/quitschbo) - corrected behaviour when not attached to a terminal - * [christoph-zededa](https://github.com/christoph-zededa) - provided OS X suppot for "`--watchfd`" + * [christoph-zededa](https://github.com/christoph-zededa) - provided OS X support for "`--watchfd`" + * [Dave Beckett](https://github.com/dajobe)) - added "`@filename`" syntax to "`--size`" --- diff --git a/doc/NEWS.md b/doc/NEWS.md index c8cf89a..3acd2db 100644 --- a/doc/NEWS.md +++ b/doc/NEWS.md @@ -1,8 +1,9 @@ UNRELEASED * dropped: support for Red Hat Enterprise Linux and its derivatives has been dropped; removed the RPM spec file, and will no longer build binaries * fix: correction to `pv_in_foreground()` to behave as its comment block says it should, when not on a terminal - corrects [GH#19 "No output in Arch Linux initcpio after 1.6.6"](https://github.com/a-j-wood/pv/issues/19), [GH#55 "pv Stopped Working in the Background"](https://github.com/a-j-wood/pv/issues/55) (pull request [#64](https://github.com/a-j-wood/pv/pull/64) supplied by [Michael Weiß](https://github.com/quitschbo)) - * feature: the "`--watchfd`" option will now show relative filenames, if they are under the current directory (pull request [#66](https://github.com/a-j-wood/pv/pull/66) supplied by [ikasty](https://github.com/ikasty)) + * feature: the "`--size`" option now accepts "`@filename`" to use the size of another file (pull request [#57](https://github.com/a-j-wood/pv/pull/57) supplied by [Dave Beckett](https://github.com/dajobe)) * feature: the "`--watchfd`" option is now available on OS X (pull request [#60](https://github.com/a-j-wood/pv/pull/60) supplied by [christoph-zededa](https://github.com/christoph-zededa)) + * feature: the "`--watchfd`" option will now show relative filenames, if they are under the current directory (pull request [#66](https://github.com/a-j-wood/pv/pull/66) supplied by [ikasty](https://github.com/ikasty)) * docs: moved all open issues into GitHub and updated the TODO list * docs: renamed README to README.md and altered it to Markdown format * docs: moved contributors from the README to docs/ACKNOWLEDGEMENTS.md diff --git a/doc/quickref.1.in b/doc/quickref.1.in index a3131c9..588cf69 100644 --- a/doc/quickref.1.in +++ b/doc/quickref.1.in @@ -243,7 +243,18 @@ etc can be used as with .BR -L . .TP .B "" -Has no effect if used with +If +.B SIZE +starts with +.BR "@" , +the size of file whose name follows the +.B @ +will be used. +.TP +.B "" +Note that +.B \-\-size +has no effect if used with .B -d PID to watch all file descriptors of a process, but will work with .BR "-d PID:FD" . diff --git a/src/main/options.c b/src/main/options.c index 9a369f9..ff46c44 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -8,11 +8,13 @@ #include "options.h" #include "library/getopt.h" #include "pv.h" +#include "pv-internal.h" #include #include #include #include +#include #include @@ -138,6 +140,9 @@ opts_t opts_parse(int argc, char **argv) */ switch (c) { case 's': + /* "-s @" is valid, so allow it. */ + if ('@' == *optarg) + break; case 'A': case 'w': case 'H': @@ -257,7 +262,28 @@ opts_t opts_parse(int argc, char **argv) opts->delay_start = pv_getnum_d(optarg); break; case 's': - opts->size = pv_getnum_ull(optarg); + /* Permit "@" as well as just a number. */ + if ('@' == *optarg) { + const char *size_file = 1 + optarg; + struct stat64 sb; + int rc; + + rc = 0; + memset(&sb, 0, sizeof(sb)); + rc = stat64(size_file, &sb); + if (0 == rc) { + opts->size = sb.st_size; + } else { + fprintf(stderr, "%s: %s %s: %s\n", + opts->program_name, + _("failed to stat file"), + size_file, strerror(errno)); + opts_free(opts); + return NULL; + } + } else { + opts->size = pv_getnum_ull(optarg); + } break; case 'l': opts->linemode = true;