From b06502b0cbeb6323b5fad66c04c7f3f25b97293f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 4 Jul 2017 12:37:20 +0200 Subject: [PATCH] initctl: Use printheader() from libite for table headings Signed-off-by: Joachim Nilsson --- src/initctl.c | 17 ++++++++--------- src/serv.c | 7 +++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/initctl.c b/src/initctl.c index fa607f44..d9b35bc6 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -37,6 +37,9 @@ #include #include +#define SCREEN_WIDTH 80 /* Calculate screen width as well, later */ +#include + #include "finit.h" #include "cond.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) { - printf("Condition Status)\n"); - printf("===============================================================================\n"); + printheader(NULL, "Condition Status", 0); if (nftw(_PATH_COND, dump_one_cond, 20, 0) == -1) { warnx("Failed parsing %s", _PATH_COND); @@ -305,8 +307,7 @@ static int do_cond_show(char *arg) svc_t *svc; enum cond_state cond; - printf("PID Service Status Condition (+ on, ~ flux, - off)\n"); - printf("===============================================================================\n"); + printheader(NULL, "PID Service Status Condition (+ on, ~ flux, - off)", 0); for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { if (!svc->cond[0]) @@ -374,7 +375,7 @@ int utmp_show(char *file) int pid; 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); setutent(); @@ -491,10 +492,8 @@ static int show_status(char *arg) return 0; } - if (!verbose) { - printf("# Status PID Runlevels Service Description\n"); - printf("===============================================================================\n"); - } + if (!verbose) + printheader(NULL, "# Status PID Runlevels Service Description", 0); for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) { char jobid[10], args[512] = "", *lvls; diff --git a/src/serv.c b/src/serv.c index a5e976fc..82bb4916 100644 --- a/src/serv.c +++ b/src/serv.c @@ -29,6 +29,8 @@ #include #define SCREEN_WIDTH 80 /* Calculate screen width as well, later */ +#include + static const char *cwd; static const char *available = FINIT_RCSD "/available"; @@ -66,7 +68,6 @@ static void do_list(const char *heading, const char *path) int width; size_t i; glob_t gl; - char h[SCREEN_WIDTH] = "==============================================================================="; pushd(path); 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) goto done; - num = snprintf(h, sizeof(h) - 1, "%s", path); - h[num] = ' '; - puts(h); + printheader(NULL, path, 0); width = calc_width(gl.gl_pathv, gl.gl_pathc); num = SCREEN_WIDTH / width;