Minor, rename internal functions/variables screen_* -> tt*

- Shorter
 - Follows old UNIX tradition
 - Lines up with next commit

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-04-07 10:06:01 +02:00
parent 7bc1470a1e
commit 522276b80d
7 changed files with 45 additions and 40 deletions
+5 -5
View File
@@ -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);
+5 -5
View File
@@ -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)
+4 -4
View File
@@ -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 */
+2 -2
View File
@@ -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();
+2 -2
View File
@@ -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;
+17 -17
View File
@@ -41,9 +41,9 @@
#include <lite/lite.h> /* 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:
+10 -5
View File
@@ -25,7 +25,7 @@
#define FINIT_UTIL_H_
#include "config.h"
#ifdef HAVE_TERMIOS_H /* for screen_width() */
#ifdef HAVE_TERMIOS_H
#include <poll.h>
#include <stdio.h>
#include <sys/reboot.h>
@@ -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 <lite/conio.h>
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)
{