- if (!(term = getenv("TERM"))) {
- fprintf(stderr, "%s: TERM: parameter not set\n", *argv);
- exit(1);
- }
- if (!(mp = malloc((u_int)1024))) {
- fprintf(stderr, "%s: out of space.\n", *argv);
- exit(1);
- }
- if (tgetent(mp, term) <= 0) {
- fprintf(stderr, "%s: %s: unknown terminal type\n", *argv, term);
- exit(1);
- }
- tcp = tcb;
- if (!(CM = tgetstr("cm", &tcp))) {
- fprintf(stderr, "%s: terminal not capable of cursor motion\n", *argv);
- exit(1);
- }
- if (!(BC = tgetstr("bc", &tcp)))
- BC = "\b";
- if (!(DN = tgetstr("dn", &tcp)))
- DN = "\n";
- if (!(ND = tgetstr("nd", &tcp)))
- ND = " ";
-#ifdef TIOCGWINSZ
- if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) != -1 &&
- ws.ws_col && ws.ws_row) {
- cols = ws.ws_col;
- lines = ws.ws_row;
- } else
-#endif
- {
- if ((cols = tgetnum("co")) == -1)
- cols = 80;
- if ((lines = tgetnum("li")) == -1)
- lines = 24;
- }
- cols -= 4;
- lines -= 4;
- TE = tgetstr("te", &tcp);
- TI = tgetstr("ti", &tcp);
- UP = tgetstr("up", &tcp);
- if (!(LL = tgetstr("ll", &tcp))) {
- if (!(LL = malloc((u_int)10))) {
- fprintf(stderr, "%s: out of space.\n", *argv);
- exit(1);
+ while ((ch = getopt(argc, argv, "d:")) != -1)
+ switch (ch) {
+ case 'd':
+ val = strtoul(optarg, &ep, 0);
+ if (ep == optarg || *ep)
+ errx(1, "Invalid delay `%s'", optarg);
+ if (errno == ERANGE && val == ULONG_MAX)
+ err(1, "Invalid delay `%s'", optarg);
+ if (val >= 1000)
+ errx(1, "Invalid delay `%s' (1-999)", optarg);
+ delay = (unsigned int)val * 1000; /* ms -> us */
+ break;
+ default:
+ (void)fprintf(stderr, "Usage: %s [-d delay]\n",
+ getprogname());
+ return 1;