/* The name this program was run with. */
char *program_name;
+/* The number of seconds to sleep between accesses. */
+static unsigned int sleep_interval = 1;
+
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
{"lines", required_argument, NULL, 'n'},
{"quiet", no_argument, NULL, 'q'},
{"silent", no_argument, NULL, 'q'},
+ {"sleep-interval", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
-f, --follow output appended data as the file grows\n\
-n, --lines=N output the last N lines, instead of last 10\n\
-q, --quiet, --silent never output headers giving file names\n\
+ -s, --sleep-interval=S with -f, sleep S seconds between iterations\n\
-v, --verbose always output headers giving file names\n\
--help display this help and exit\n\
--version output version information and exit\n\
if (forever)
{
fflush (stdout);
- sleep (1);
+ sleep (sleep_interval);
goto output;
}
else
/* If none of the files changed size, sleep. */
if (! changed)
- sleep (1);
+ sleep (sleep_interval);
}
}
if (argc < 2)
return 0;
- /* If I were implementing this in Perl, the rest of this function
- would be essentially this single statement:
- return $p ne '-' && $p ne '-c' && $p =~ /^[+-]\d*[cl]?f?$/; */
-
- /* Test this:
- if (STREQ (p, "-") || STREQ (p, "-c"))
- but without using strcmp. */
- if (p[0] == '-' && (p[1] == 0 || (p[1] == 'c' && p[2] == 0)))
+ if ( ! (p[0] == '+' || (p[0] == '-' && ISDIGIT (p[1])))
return 0;
if (*p == '+')
count_lines = 1;
forever = forever_multiple = from_start = print_headers = 0;
- while ((c = getopt_long (argc, argv, "c:n:fqv", long_options, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "c:n:fqs:v", long_options, NULL)) != -1)
{
switch (c)
{
*header_mode = never;
break;
+ case 's':
+ {
+ strtol_error s_err;
+ unsigned long int tmp_ulong;
+ s_err = xstrtoul (optarg, NULL, 0, &tmp_ulong, "");
+ if (s_err != LONGINT_OK || tmp_ulong > UINT_MAX)
+ {
+ error (EXIT_FAILURE, 0,
+ _("%s: invalid number of seconds"), optarg);
+ }
+ sleep_interval = tmp_ulong;
+ }
+ break;
+
case 'v':
*header_mode = always;
break;