initctl: Use printheader() from libite for table headings

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-07-04 12:37:20 +02:00
1 parent c4b6fab3f3
commit b06502b0cb
2 files changed
+11 -13

No files matched your search

+8 -9
View File
@@ -37,6 +37,9 @@
#include <sys/un.h> #include <sys/un.h>
#include <lite/lite.h> #include <lite/lite.h>
#define SCREEN_WIDTH 80 /* Calculate screen width as well, later */
#include <lite/conio.h>
#include "finit.h" #include "finit.h"
#include "cond.h" #include "cond.h"
#include "serv.h" #include "serv.h"
@@ -289,8 +292,7 @@ static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, st
static int do_cond_dump(char *arg) static int do_cond_dump(char *arg)
{ {
printf("Condition Status)\n"); printheader(NULL, "Condition Status", 0);
printf("===============================================================================\n");
if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) { if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) {
warnx("Failed parsing %s", _PATH_COND); warnx("Failed parsing %s", _PATH_COND);
@@ -305,8 +307,7 @@ static int do_cond_show(char *arg)
svc_t *svc; svc_t *svc;
enum cond_state cond; enum cond_state cond;
printf("PID Service Status Condition (+ on, ~ flux, - off)\n"); printheader(NULL, "PID Service Status Condition (+ on, ~ flux, - off)", 0);
printf("===============================================================================\n");
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
if (!svc->cond[0]) if (!svc->cond[0])
@@ -374,7 +375,7 @@ int utmp_show(char *file)
int pid; int pid;
char id[sizeof(ut->ut_id) + 1], user[sizeof(ut->ut_user) + 1], when[80]; char id[sizeof(ut->ut_id) + 1], user[sizeof(ut->ut_user) + 1], when[80];
printf("%s =============================================================================================\n", file); printheader(NULL, file, 0);
utmpname(file); utmpname(file);
setutent(); setutent();
@@ -491,10 +492,8 @@ static int show_status(char *arg)
return 0; return 0;
} }
if (!verbose) { if (!verbose)
printf("# Status PID Runlevels Service Description\n"); printheader(NULL, "# Status PID Runlevels Service Description", 0);
printf("===============================================================================\n");
}
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
char jobid[10], args[512] = "", *lvls; char jobid[10], args[512] = "", *lvls;
+3 -4
View File
@@ -29,6 +29,8 @@
#include <lite/lite.h> #include <lite/lite.h>
#define SCREEN_WIDTH 80 /* Calculate screen width as well, later */ #define SCREEN_WIDTH 80 /* Calculate screen width as well, later */
#include <lite/conio.h>
static const char *cwd; static const char *cwd;
static const char *available = FINIT_RCSD "/available"; static const char *available = FINIT_RCSD "/available";
@@ -66,7 +68,6 @@ static void do_list(const char *heading, const char *path)
int width; int width;
size_t i; size_t i;
glob_t gl; glob_t gl;
char h[SCREEN_WIDTH] = "===============================================================================";
pushd(path); pushd(path);
if (glob("*.conf", 0, NULL, &gl)) { if (glob("*.conf", 0, NULL, &gl)) {
@@ -77,9 +78,7 @@ static void do_list(const char *heading, const char *path)
if (gl.gl_pathc <= 0) if (gl.gl_pathc <= 0)
goto done; goto done;
num = snprintf(h, sizeof(h) - 1, "%s", path); printheader(NULL, path, 0);
h[num] = ' ';
puts(h);
width = calc_width(gl.gl_pathv, gl.gl_pathc); width = calc_width(gl.gl_pathv, gl.gl_pathc);
num = SCREEN_WIDTH / width; num = SCREEN_WIDTH / width;