mirror of
https://github.com/troglobit/finit.git
synced 2026-11-07 16:01:08 +00:00
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:
1 parent
7bc1470a1e
commit
522276b80d
7 files changed
+45
-40
No files matched your search
+5
-5
@@ -353,7 +353,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos)
|
|||||||
{
|
{
|
||||||
struct dirent **namelist = NULL;
|
struct dirent **namelist = NULL;
|
||||||
char s[32], r[32], l[32];
|
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 rlen = sizeof(row) - 1;
|
||||||
size_t rplen = rlen - 9;
|
size_t rplen = rlen - 9;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@@ -364,7 +364,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos)
|
|||||||
int i, n;
|
int i, n;
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
if (pos >= screen_rows)
|
if (pos >= ttrows)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (-1 == lstat(path, &st))
|
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) */
|
/* skip kernel threads for now (no cmdline) */
|
||||||
pid_comm(pid, comm, sizeof(comm));
|
pid_comm(pid, comm, sizeof(comm));
|
||||||
if (pid_cmdline(pid, buf, sizeof(buf))) {
|
if (pid_cmdline(pid, buf, sizeof(buf))) {
|
||||||
char proc[screen_cols];
|
char proc[ttcols];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@@ -513,7 +513,7 @@ int cgroup_tree(char *path, char *pfx, int mode, int pos)
|
|||||||
|
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
pos += i;
|
pos += i;
|
||||||
if (pos >= screen_rows)
|
if (pos >= ttrows)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -562,7 +562,7 @@ int show_cgtop(char *arg)
|
|||||||
arg = path;
|
arg = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hcreate(screen_rows + 25))
|
if (!hcreate(ttrows + 25))
|
||||||
err(1, "failed creating hash table");
|
err(1, "failed creating hash table");
|
||||||
|
|
||||||
sysinfo(&si);
|
sysinfo(&si);
|
||||||
|
|||||||
+5
-5
@@ -154,7 +154,7 @@ static void find_active_consoles(void)
|
|||||||
void console_init(void)
|
void console_init(void)
|
||||||
{
|
{
|
||||||
find_active_consoles();
|
find_active_consoles();
|
||||||
screen_init();
|
ttinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t cprintf(const char *fmt, ...)
|
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)
|
void print_banner(const char *heading)
|
||||||
{
|
{
|
||||||
char buf[4 * SCREEN_WIDTH];
|
char buf[4 * ttcols];
|
||||||
|
|
||||||
if (progress_style == PROGRESS_SILENT)
|
if (progress_style == PROGRESS_SILENT)
|
||||||
return;
|
return;
|
||||||
@@ -266,9 +266,9 @@ void print_banner(const char *heading)
|
|||||||
if (progress_style == PROGRESS_CLASSIC) {
|
if (progress_style == PROGRESS_CLASSIC) {
|
||||||
strlcat(buf, "\e[1m", sizeof(buf));
|
strlcat(buf, "\e[1m", sizeof(buf));
|
||||||
strlcat(buf, heading, sizeof(buf));
|
strlcat(buf, heading, sizeof(buf));
|
||||||
pad(buf, sizeof(buf), "=", SCREEN_WIDTH + 10);
|
pad(buf, sizeof(buf), "=", ttcols + 10);
|
||||||
} else {
|
} else {
|
||||||
size_t wmax = 80 <= SCREEN_WIDTH ? 80 : SCREEN_WIDTH;
|
size_t wmax = 80 <= ttcols ? 80 : ttcols;
|
||||||
|
|
||||||
/* • • • Foo System ═══════════════════════════════════════════════ */
|
/* • • • Foo System ═══════════════════════════════════════════════ */
|
||||||
/* ⬤ ⬤ ⬤ Foo System ═══════════════════════════════════════════════ */
|
/* ⬤ ⬤ ⬤ Foo System ═══════════════════════════════════════════════ */
|
||||||
@@ -331,7 +331,7 @@ static char *status(int rc)
|
|||||||
|
|
||||||
void printv(const char *fmt, va_list ap)
|
void printv(const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char buf[SCREEN_WIDTH];
|
char buf[ttcols];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (!fmt || progress_style == PROGRESS_SILENT)
|
if (!fmt || progress_style == PROGRESS_SILENT)
|
||||||
|
|||||||
+4
-4
@@ -102,11 +102,11 @@ void print_header(const char *fmt, ...)
|
|||||||
|
|
||||||
vfprintf(stdout, fmt, ap);
|
vfprintf(stdout, fmt, ap);
|
||||||
fputs("\n", stdout);
|
fputs("\n", stdout);
|
||||||
for (len = 0; len < screen_cols; len++)
|
for (len = 0; len < ttcols; len++)
|
||||||
fputc('=', stdout);
|
fputc('=', stdout);
|
||||||
fputs("\n", stdout);
|
fputs("\n", stdout);
|
||||||
} else {
|
} else {
|
||||||
char buf[screen_cols];
|
char buf[ttcols];
|
||||||
|
|
||||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
printheader(stdout, buf, 0);
|
printheader(stdout, buf, 0);
|
||||||
@@ -875,7 +875,7 @@ static int do_devel(char *arg)
|
|||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
printf("Screen %dx%d\n", screen_cols, screen_rows);
|
printf("Screen %dx%d\n", ttcols, ttrows);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1022,7 +1022,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (interactive)
|
if (interactive)
|
||||||
screen_init();
|
ttinit();
|
||||||
|
|
||||||
if (!has_utmp()) {
|
if (!has_utmp()) {
|
||||||
/* system w/o utmp support, disable 'utmp' command */
|
/* system w/o utmp support, disable 'utmp' command */
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void log_exit(void)
|
|||||||
* terminal may have been resized at runtime
|
* terminal may have been resized at runtime
|
||||||
*/
|
*/
|
||||||
if (!debug)
|
if (!debug)
|
||||||
screen_init();
|
ttinit();
|
||||||
|
|
||||||
enable_progress(1);
|
enable_progress(1);
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ void log_debug(void)
|
|||||||
loglevel = LOG_DEBUG;
|
loglevel = LOG_DEBUG;
|
||||||
} else {
|
} else {
|
||||||
loglevel = LOG_NOTICE;
|
loglevel = LOG_NOTICE;
|
||||||
screen_init();
|
ttinit();
|
||||||
}
|
}
|
||||||
log_open();
|
log_open();
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -89,8 +89,8 @@ static void do_list(const char *path)
|
|||||||
if (width <= 0)
|
if (width <= 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
num = (screen_cols - 2) / width;
|
num = (ttcols - 2) / width;
|
||||||
if ((num - 1) * 2 + num * width > screen_cols)
|
if ((num - 1) * 2 + num * width > ttcols)
|
||||||
num--;
|
num--;
|
||||||
|
|
||||||
prev = 0;
|
prev = 0;
|
||||||
|
|||||||
+17
-17
@@ -41,9 +41,9 @@
|
|||||||
#include <lite/lite.h> /* strlcat() */
|
#include <lite/lite.h> /* strlcat() */
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int screen_rows = 24;
|
int ttrows = 24;
|
||||||
int screen_cols = 80;
|
int ttcols = 80;
|
||||||
char *prognm = NULL;
|
char *prognm = NULL;
|
||||||
|
|
||||||
char *progname(char *arg0)
|
char *progname(char *arg0)
|
||||||
{
|
{
|
||||||
@@ -247,13 +247,13 @@ char *sanitize(char *arg, size_t len)
|
|||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_TERMIOS_H
|
||||||
/*
|
/*
|
||||||
* Called by initctl, and by finit at boot and shutdown, to
|
* Called by initctl, and by finit at boot and shutdown, to
|
||||||
* (re)initialize the screen size for print() et al.
|
* (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 pollfd fd = { STDIN_FILENO, POLLIN, 0 };
|
||||||
struct winsize ws = { 0 };
|
struct winsize ws = { 0 };
|
||||||
struct termios tc, saved;
|
struct termios tc, saved;
|
||||||
@@ -270,16 +270,16 @@ int screen_init(void)
|
|||||||
|
|
||||||
/* 1. Try TIOCWINSZ to query window size from kernel */
|
/* 1. Try TIOCWINSZ to query window size from kernel */
|
||||||
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
|
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
|
||||||
screen_rows = ws.ws_row;
|
ttrows = ws.ws_row;
|
||||||
screen_cols = ws.ws_col;
|
ttcols = ws.ws_col;
|
||||||
|
|
||||||
/* Likely doesn't work in PID 1 after kernel starts us ... */
|
/* Likely doesn't work in PID 1 after kernel starts us ... */
|
||||||
if (!ws.ws_row && !ws.ws_col)
|
if (!ws.ws_row && !ws.ws_col)
|
||||||
goto fallback;
|
goto fallback;
|
||||||
} else if (!isatty(STDOUT_FILENO)) {
|
} else if (!isatty(STDOUT_FILENO)) {
|
||||||
/* 2. We may be running under watch(1) */
|
/* 2. We may be running under watch(1) */
|
||||||
screen_cols = atonum(getenv("COLUMNS"));
|
ttcols = atonum(getenv("COLUMNS"));
|
||||||
screen_rows = atonum(getenv("LINES"));
|
ttrows = atonum(getenv("LINES"));
|
||||||
} else {
|
} else {
|
||||||
fallback:
|
fallback:
|
||||||
/* 3. ANSI goto + query cursor position trick as fallback */
|
/* 3. ANSI goto + query cursor position trick as fallback */
|
||||||
@@ -289,8 +289,8 @@ int screen_init(void)
|
|||||||
int row, col;
|
int row, col;
|
||||||
|
|
||||||
if (scanf("\e[%d;%dR", &row, &col) == 2) {
|
if (scanf("\e[%d;%dR", &row, &col) == 2) {
|
||||||
screen_cols = col;
|
ttcols = col;
|
||||||
screen_rows = row;
|
ttrows = row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,14 +301,14 @@ int screen_init(void)
|
|||||||
tcsetattr(STDERR_FILENO, TCSANOW, &saved);
|
tcsetattr(STDERR_FILENO, TCSANOW, &saved);
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (screen_cols <= 0)
|
if (ttcols <= 0)
|
||||||
screen_cols = 80;
|
ttcols = 80;
|
||||||
if (screen_rows <= 0)
|
if (ttrows <= 0)
|
||||||
screen_rows = 24;
|
ttrows = 24;
|
||||||
#endif
|
|
||||||
|
|
||||||
return screen_cols;
|
return ttcols;
|
||||||
}
|
}
|
||||||
|
#endif /* HAVE_TERMIOS_H */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
|
|||||||
+10
-5
@@ -25,7 +25,7 @@
|
|||||||
#define FINIT_UTIL_H_
|
#define FINIT_UTIL_H_
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef HAVE_TERMIOS_H /* for screen_width() */
|
#ifdef HAVE_TERMIOS_H
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
@@ -37,11 +37,12 @@
|
|||||||
#define RB_SW_SUSPEND 0xd000fce2
|
#define RB_SW_SUSPEND 0xd000fce2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int screen_rows;
|
extern int ttrows;
|
||||||
extern int screen_cols;
|
extern int ttcols;
|
||||||
extern char *prognm;
|
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>
|
#include <lite/conio.h>
|
||||||
|
|
||||||
char *progname (char *arg0);
|
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);
|
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)
|
static inline char *strterm(char *str, size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user