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