diff --git a/src/cgutil.c b/src/cgutil.c index 9a8fd985..bc3053b8 100644 --- a/src/cgutil.c +++ b/src/cgutil.c @@ -353,7 +353,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos) { struct dirent **namelist = NULL; char s[32], r[32], l[32]; - char row[screen_cols + 9]; /* + control codes */ + char row[ttcols + 9]; /* + control codes */ size_t rlen = sizeof(row) - 1; size_t rplen = rlen - 9; struct stat st; @@ -364,7 +364,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos) int i, n; int num; - if (pos >= screen_rows) + if (pos >= ttrows) return 0; if (-1 == lstat(path, &st)) @@ -475,7 +475,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos) /* skip kernel threads for now (no cmdline) */ pid_comm(pid, comm, sizeof(comm)); if (pid_cmdline(pid, buf, sizeof(buf))) { - char proc[screen_cols]; + char proc[ttcols]; int len; switch (mode) { @@ -513,7 +513,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos) if (mode == 1) { pos += i; - if (pos >= screen_rows) + if (pos >= ttrows) break; } } @@ -562,7 +562,7 @@ int show_cgtop(char *arg) arg = path; } - if (!hcreate(screen_rows + 25)) + if (!hcreate(ttrows + 25)) err(1, "failed creating hash table"); sysinfo(&si); diff --git a/src/helpers.c b/src/helpers.c index afd2e5c1..24f86361 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -154,7 +154,7 @@ static void find_active_consoles(void) void console_init(void) { find_active_consoles(); - screen_init(); + ttinit(); } ssize_t cprintf(const char *fmt, ...) @@ -255,7 +255,7 @@ static char *pad(char *buf, size_t len, char *ch, size_t width) void print_banner(const char *heading) { - char buf[4 * SCREEN_WIDTH]; + char buf[4 * ttcols]; if (progress_style == PROGRESS_SILENT) return; @@ -266,9 +266,9 @@ void print_banner(const char *heading) if (progress_style == PROGRESS_CLASSIC) { strlcat(buf, "\e[1m", sizeof(buf)); strlcat(buf, heading, sizeof(buf)); - pad(buf, sizeof(buf), "=", SCREEN_WIDTH + 10); + pad(buf, sizeof(buf), "=", ttcols + 10); } else { - size_t wmax = 80 <= SCREEN_WIDTH ? 80 : SCREEN_WIDTH; + size_t wmax = 80 <= ttcols ? 80 : ttcols; /* • • • Foo System ═══════════════════════════════════════════════ */ /* ⬤ ⬤ ⬤ Foo System ═══════════════════════════════════════════════ */ @@ -331,7 +331,7 @@ static char *status(int rc) void printv(const char *fmt, va_list ap) { - char buf[SCREEN_WIDTH]; + char buf[ttcols]; size_t len; if (!fmt || progress_style == PROGRESS_SILENT) diff --git a/src/initctl.c b/src/initctl.c index 0433a85c..a9103029 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -102,11 +102,11 @@ void print_header(const char *fmt, ...) vfprintf(stdout, fmt, ap); fputs("\n", stdout); - for (len = 0; len < screen_cols; len++) + for (len = 0; len < ttcols; len++) fputc('=', stdout); fputs("\n", stdout); } else { - char buf[screen_cols]; + char buf[ttcols]; vsnprintf(buf, sizeof(buf), fmt, ap); printheader(stdout, buf, 0); @@ -875,7 +875,7 @@ static int do_devel(char *arg) { (void)arg; - printf("Screen %dx%d\n", screen_cols, screen_rows); + printf("Screen %dx%d\n", ttcols, ttrows); return 0; } @@ -1022,7 +1022,7 @@ int main(int argc, char *argv[]) } if (interactive) - screen_init(); + ttinit(); if (!has_utmp()) { /* system w/o utmp support, disable 'utmp' command */ diff --git a/src/log.c b/src/log.c index 5e82fb5f..20e91f0b 100644 --- a/src/log.c +++ b/src/log.c @@ -50,7 +50,7 @@ void log_exit(void) * terminal may have been resized at runtime */ if (!debug) - screen_init(); + ttinit(); enable_progress(1); } @@ -78,7 +78,7 @@ void log_debug(void) loglevel = LOG_DEBUG; } else { loglevel = LOG_NOTICE; - screen_init(); + ttinit(); } log_open(); diff --git a/src/serv.c b/src/serv.c index 1a3732c5..94422744 100644 --- a/src/serv.c +++ b/src/serv.c @@ -89,8 +89,8 @@ static void do_list(const char *path) if (width <= 0) goto done; - num = (screen_cols - 2) / width; - if ((num - 1) * 2 + num * width > screen_cols) + num = (ttcols - 2) / width; + if ((num - 1) * 2 + num * width > ttcols) num--; prev = 0; diff --git a/src/util.c b/src/util.c index 67a240f5..de880c0d 100644 --- a/src/util.c +++ b/src/util.c @@ -41,9 +41,9 @@ #include /* strlcat() */ #include "util.h" -int screen_rows = 24; -int screen_cols = 80; -char *prognm = NULL; +int ttrows = 24; +int ttcols = 80; +char *prognm = NULL; char *progname(char *arg0) { @@ -247,13 +247,13 @@ char *sanitize(char *arg, size_t len) return arg; } +#ifdef HAVE_TERMIOS_H /* * Called by initctl, and by finit at boot and shutdown, to * (re)initialize the screen size for print() et al. */ -int screen_init(void) +int ttinit(void) { -#ifdef HAVE_TERMIOS_H struct pollfd fd = { STDIN_FILENO, POLLIN, 0 }; struct winsize ws = { 0 }; struct termios tc, saved; @@ -270,16 +270,16 @@ int screen_init(void) /* 1. Try TIOCWINSZ to query window size from kernel */ if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) { - screen_rows = ws.ws_row; - screen_cols = ws.ws_col; + ttrows = ws.ws_row; + ttcols = ws.ws_col; /* Likely doesn't work in PID 1 after kernel starts us ... */ if (!ws.ws_row && !ws.ws_col) goto fallback; } else if (!isatty(STDOUT_FILENO)) { /* 2. We may be running under watch(1) */ - screen_cols = atonum(getenv("COLUMNS")); - screen_rows = atonum(getenv("LINES")); + ttcols = atonum(getenv("COLUMNS")); + ttrows = atonum(getenv("LINES")); } else { fallback: /* 3. ANSI goto + query cursor position trick as fallback */ @@ -289,8 +289,8 @@ int screen_init(void) int row, col; if (scanf("\e[%d;%dR", &row, &col) == 2) { - screen_cols = col; - screen_rows = row; + ttcols = col; + ttrows = row; } } @@ -301,14 +301,14 @@ int screen_init(void) tcsetattr(STDERR_FILENO, TCSANOW, &saved); /* Sanity check */ - if (screen_cols <= 0) - screen_cols = 80; - if (screen_rows <= 0) - screen_rows = 24; -#endif + if (ttcols <= 0) + ttcols = 80; + if (ttrows <= 0) + ttrows = 24; - return screen_cols; + return ttcols; } +#endif /* HAVE_TERMIOS_H */ /** * Local Variables: diff --git a/src/util.h b/src/util.h index e6a40593..5f038fc7 100644 --- a/src/util.h +++ b/src/util.h @@ -25,7 +25,7 @@ #define FINIT_UTIL_H_ #include "config.h" -#ifdef HAVE_TERMIOS_H /* for screen_width() */ +#ifdef HAVE_TERMIOS_H #include #include #include @@ -37,11 +37,12 @@ #define RB_SW_SUSPEND 0xd000fce2 #endif -extern int screen_rows; -extern int screen_cols; +extern int ttrows; +extern int ttcols; extern char *prognm; -#define SCREEN_WIDTH screen_cols +/* Define for printheader() from conio.h, used in initctl */ +#define SCREEN_WIDTH ttcols #include char *progname (char *arg0); @@ -59,7 +60,11 @@ char *memsz (uint64_t sz, char *buf, size_t len); char *sanitize (char *arg, size_t len); -int screen_init (void); +#ifdef HAVE_TERMIOS_H +int ttinit (void); +#else +#define ttinit() ttcols +#endif static inline char *strterm(char *str, size_t len) {