2013-09-04 10:27:29 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2014-11-30 14:03:25 +00:00
|
|
|
#include <errno.h>
|
2013-09-04 10:27:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-09-04 10:27:29 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s [-t] [-n interval] command\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char cmd[BUFSIZ];
|
2014-11-30 14:03:25 +00:00
|
|
|
char *end;
|
|
|
|
useconds_t interval = 2 * 1E6;
|
|
|
|
float period;
|
|
|
|
int i;
|
2013-09-04 10:27:29 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 't':
|
|
|
|
break;
|
|
|
|
case 'n':
|
2014-11-30 14:03:25 +00:00
|
|
|
period = strtof(EARGF(usage()), &end);
|
|
|
|
if (*end != '\0' || errno != 0)
|
|
|
|
eprintf("invalid interval\n");
|
2014-11-30 14:08:20 +00:00
|
|
|
if (period < 0)
|
|
|
|
period = 0.1f;
|
2014-11-30 14:03:25 +00:00
|
|
|
interval = period * 1E6;
|
2013-09-04 10:27:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
2014-08-25 18:14:34 +00:00
|
|
|
if (strlcpy(cmd, argv[0], sizeof(cmd)) >= sizeof(cmd))
|
|
|
|
eprintf("command too long\n");
|
2013-09-04 10:27:29 +00:00
|
|
|
for (i = 1; i < argc; i++) {
|
2014-08-25 18:14:34 +00:00
|
|
|
if (strlcat(cmd, " ", sizeof(cmd)) >= sizeof(cmd))
|
|
|
|
eprintf("command too long\n");
|
|
|
|
if (strlcat(cmd, argv[i], sizeof(cmd)) >= sizeof(cmd))
|
|
|
|
eprintf("command too long\n");
|
2013-09-04 10:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2014-02-14 13:38:56 +00:00
|
|
|
printf("\x1b[2J\x1b[H"); /* clear */
|
2013-09-04 10:27:29 +00:00
|
|
|
fflush(NULL);
|
|
|
|
system(cmd);
|
2014-11-30 14:03:25 +00:00
|
|
|
usleep(interval);
|
2013-09-04 10:27:29 +00:00
|
|
|
}
|
2014-10-02 22:45:25 +00:00
|
|
|
return 0;
|
2013-09-04 10:27:29 +00:00
|
|
|
}
|