typedef int (sort_fp)(const struct irq_info *, const struct irq_info *);
struct irqtop_ctl {
- WINDOW *win;
int cols;
int rows;
struct itimerspec timer;
}
}
-static inline void print_line(struct irqtop_ctl const *const ctl,
- char const *const fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- if (ctl->run_once)
- vprintf(fmt, args);
- else
- vw_printw(ctl->win, fmt, args);
- va_end(args);
-}
-
-static int update_screen(struct irqtop_ctl *const ctl)
+static int update_screen(struct irqtop_ctl *const ctl, WINDOW *win)
{
struct irq_stat *stat;
move(0, 0);
strtime_iso(&now, ISO_TIMESTAMP, timestr, sizeof(timestr));
- print_line(ctl, _("irqtop | total: %ld delta: %ld | %s | %s\n\n"),
+ wprintw(win, _("irqtop | total: %ld delta: %ld | %s | %s\n\n"),
stat->total_irq, stat->delta_irq, ctl->hostname, timestr);
}
/* body */
char *data;
scols_print_table_to_string(ctl->table, &data);
- print_line(ctl, "%s", data);
+ wprintw(win, "%s", data);
free(data);
}
/* clean up */
return 0;
}
-static int event_loop(struct irqtop_ctl *const ctl)
+static int event_loop(struct irqtop_ctl *const ctl, WINDOW *win)
{
int efd, sfd, tfd;
sigset_t sigmask;
if (epoll_ctl(efd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) != 0)
err(EXIT_FAILURE, _("epoll_ctl failed"));
- retval |= update_screen(ctl);
+ retval |= update_screen(ctl, win);
refresh();
while (!ctl->request_exit) {
parse_input(ctl, c);
} else
abort();
- retval |= update_screen(ctl);
+ retval |= update_screen(ctl, win);
refresh();
}
}
int main(int argc, char **argv)
{
+ WINDOW *win = NULL;
int is_tty = 0;
int retval = EXIT_SUCCESS;
struct termios saved_tty;
if (is_tty && tcgetattr(STDIN_FILENO, &saved_tty) == -1)
fputs(_("terminal setting retrieval"), stdout);
- ctl.win = initscr();
+ win = initscr();
get_terminal_dimension(&ctl.cols, &ctl.rows);
resizeterm(ctl.rows, ctl.cols);
curs_set(0);
ctl.hostname = xgethostname();
if (ctl.run_once)
- retval = update_screen(&ctl);
+ retval = update_screen(&ctl, NULL);
else
- event_loop(&ctl);
+ event_loop(&ctl, win);
free_irqinfo(ctl.prev_stat);
free(ctl.hostname);
- if (ctl.win) {
+ if (win) {
if (is_tty)
tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tty);
- delwin(ctl.win);
+ delwin(win);
endwin();
}
return retval;