From 83aff5bda1784f7fcaf558d6fea76fe1052fdf4e Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Mon, 30 Jan 2023 18:27:51 +1100
Subject: [PATCH] only display service in function of the treename

---
 src/include/66/info.h                       |  8 ++---
 src/lib66/exec/ssexec_inservice.c           | 14 ++++-----
 src/lib66/info/info_graph_display.c         |  4 +--
 src/lib66/info/info_graph_display_service.c | 10 ++++---
 src/lib66/info/info_graph_display_tree.c    | 20 +++++++++----
 src/lib66/info/info_walk.c                  | 33 +++++++++++++--------
 6 files changed, 54 insertions(+), 35 deletions(-)

diff --git a/src/include/66/info.h b/src/include/66/info.h
index e00361da..5475b5a6 100644
--- a/src/include/66/info.h
+++ b/src/include/66/info.h
@@ -28,7 +28,7 @@
 #define INFO_FIELD_MAXLEN 30
 #define INFO_NKEY 150
 
-typedef int info_graph_func(char const *name, char const *obj) ;
+typedef int info_graph_func(char const *name) ;
 typedef info_graph_func *info_graph_func_t_ref ;
 
 typedef struct depth_s depth_t ;
@@ -81,8 +81,8 @@ extern void info_display_nline(char const *field,char const *str) ;
 
 extern depth_t info_graph_init(void) ;
 extern int info_walk(graph_t *g, char const *name, char const *obj, info_graph_func *func, uint8_t requiredby, uint8_t reverse, depth_t *depth, int padding, info_graph_style *style) ;
-extern int info_graph_display(char const *name, char const *obj, info_graph_func *func, depth_t *depth, int last, int padding, info_graph_style *style) ;
-extern int info_graph_display_service(char const *name, char const *obj) ;
-extern int info_graph_display_tree(char const *name, char const *obj) ;
+extern int info_graph_display(char const *name, info_graph_func *func, depth_t *depth, int last, int padding, info_graph_style *style) ;
+extern int info_graph_display_service(char const *name) ;
+extern int info_graph_display_tree(char const *name) ;
 
 #endif
diff --git a/src/lib66/exec/ssexec_inservice.c b/src/lib66/exec/ssexec_inservice.c
index 09d868f5..1388d05e 100644
--- a/src/lib66/exec/ssexec_inservice.c
+++ b/src/lib66/exec/ssexec_inservice.c
@@ -253,7 +253,7 @@ static void info_display_status(char const *field,resolve_service_t *res)
 
     disen = service_is(&ste, STATE_FLAGS_ISENABLED) ;
 
-    if (!bprintf(buffer_1,"%s%s%s%s", disen ? log_color->valid : log_color->error, disen ? "enabled" : "disabled", log_color->off, ", "))
+    if (!bprintf(buffer_1,"%s%s%s%s", disen ? log_color->valid : log_color->warning, disen ? "enabled" : "disabled", log_color->off, ", "))
         log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
 
     if (buffer_putsflush(buffer_1,"") == -1)
@@ -317,12 +317,12 @@ static void info_display_requiredby(char const *field, resolve_service_t *res)
 
     if (GRAPH) {
 
-        if (!bprintf(buffer_1,"%s\n","/"))
+        if (!bprintf(buffer_1,"%s\n","\\"))
             log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
 
         depth_t d = info_graph_init() ;
 
-        if (!info_walk(&graph, res->sa.s + res->name, res->sa.s + res->treename, &info_graph_display_service, 1, REVERSE, &d, padding, S_STYLE))
+        if (!info_walk(&graph, res->sa.s + res->name, 0, &info_graph_display_service, 1, REVERSE, &d, padding, S_STYLE))
             log_dieu(LOG_EXIT_SYS,"display the requiredby list") ;
 
         goto freed ;
@@ -349,7 +349,7 @@ static void info_display_requiredby(char const *field, resolve_service_t *res)
     empty:
         if (GRAPH)
         {
-            if (!bprintf(buffer_1,"%s\n","/"))
+            if (!bprintf(buffer_1,"%s\n","\\"))
                 log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
             if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", S_STYLE->last, log_color->warning,"None",log_color->off))
                 log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
@@ -394,12 +394,12 @@ static void info_display_deps(char const *field, resolve_service_t *res)
 
     if (GRAPH)
     {
-        if (!bprintf(buffer_1,"%s\n","/"))
+        if (!bprintf(buffer_1,"%s\n","\\"))
             log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
 
         depth_t d = info_graph_init() ;
 
-        if (!info_walk(&graph, res->sa.s + res->name, res->sa.s + res->treename, &info_graph_display_service, 0, REVERSE, &d, padding, S_STYLE))
+        if (!info_walk(&graph, res->sa.s + res->name, 0, &info_graph_display_service, 0, REVERSE, &d, padding, S_STYLE))
             log_dieu(LOG_EXIT_SYS,"display the dependencies list") ;
 
         goto freed ;
@@ -424,7 +424,7 @@ static void info_display_deps(char const *field, resolve_service_t *res)
     empty:
         if (GRAPH)
         {
-            if (!bprintf(buffer_1,"%s\n","/"))
+            if (!bprintf(buffer_1,"%s\n","\\"))
                 log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
 
             if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", S_STYLE->last, log_color->warning,"None",log_color->off))
diff --git a/src/lib66/info/info_graph_display.c b/src/lib66/info/info_graph_display.c
index c7ff2ad0..10bff9e9 100644
--- a/src/lib66/info/info_graph_display.c
+++ b/src/lib66/info/info_graph_display.c
@@ -19,7 +19,7 @@
 
 #include <66/info.h>
 
-int info_graph_display(char const *name, char const *obj, info_graph_func *func, depth_t *depth, int last, int padding, info_graph_style *style)
+int info_graph_display(char const *name, info_graph_func *func, depth_t *depth, int last, int padding, info_graph_style *style)
 {
     log_flow() ;
 
@@ -46,7 +46,7 @@ int info_graph_display(char const *name, char const *obj, info_graph_func *func,
                 style->indent * (depth->level - level), "", \
                 tip)) return 0 ;
 
-    int r = (*func)(name, obj) ;
+    int r = (*func)(name) ;
     if (!r) return 0 ;
     if (buffer_putsflush(buffer_1,"\n") < 0)
         return 0 ;
diff --git a/src/lib66/info/info_graph_display_service.c b/src/lib66/info/info_graph_display_service.c
index 4f1cc5d5..94788903 100644
--- a/src/lib66/info/info_graph_display_service.c
+++ b/src/lib66/info/info_graph_display_service.c
@@ -89,19 +89,21 @@ int info_graph_display_service(char const *name, char const *obj)
 
     dis:
 
-    if (!bprintf(buffer_1,"(%s%s%s,%s%s%s,%s) %s", \
+    if (!bprintf(buffer_1," %s (%s%s%s,%s%s%s,%s%s%s,%s:%s)", \
+
+        name, \
 
         pid_color > 1 ? log_color->valid : pid_color ? log_color->error : log_color->warning, \
         ppid, \
         log_color->off, \
 
-        service_is(&sta, STATE_FLAGS_ISENABLED) ? log_color->off : log_color->error, \
+        service_is(&sta, STATE_FLAGS_ISENABLED) ? log_color->off : log_color->warning, \
         service_is(&sta, STATE_FLAGS_ISENABLED) ? "Enabled" : "Disabled", \
         log_color->off, \
 
-        get_key_by_enum(ENUM_TYPE,res.type), \
+        log_color->blue, get_key_by_enum(ENUM_TYPE,res.type), log_color->off, \
 
-        name))
+        "tree", res.sa.s + res.treename ))
             goto freed ;
 
     err = 1 ;
diff --git a/src/lib66/info/info_graph_display_tree.c b/src/lib66/info/info_graph_display_tree.c
index f9233130..5ecbb90d 100644
--- a/src/lib66/info/info_graph_display_tree.c
+++ b/src/lib66/info/info_graph_display_tree.c
@@ -28,7 +28,7 @@
 #include <66/constants.h>
 #include <66/info.h>
 
-int info_graph_display_tree(char const *name, char const *obj)
+int info_graph_display_tree(char const *name)
 {
     log_flow() ;
 
@@ -67,21 +67,31 @@ int info_graph_display_tree(char const *name, char const *obj)
     if (init < 0)
         goto freed ;
 
+    int up = tres.supervised ;
+    if (up < 0)
+        goto freed ;
+
     int enabled = tree_isenabled(base, name) ;
     if (enabled < 0)
         goto freed ;
 
-    if (!bprintf(buffer_1,"(%s%s%s,%s%s%s) %s", \
+    if (!bprintf(buffer_1," %s (%s%s%s,%s%s%s,%s%s%s)", \
+
+                name, \
 
                 init ? log_color->valid : log_color->warning, \
                 init ? "Initialized" : "Unitialized", \
                 log_color->off, \
 
-                enabled ? log_color->valid : log_color->error, \
-                enabled ? "Enabled" : "Disabled", \
+                up ? log_color->valid : log_color->error, \
+                up ? "Up" : "Down", \
                 log_color->off, \
 
-                name))
+
+                enabled ? log_color->valid : log_color->warning, \
+                enabled ? "Enabled" : "Disabled", \
+                log_color->off))
+
                     goto freed ;
 
     err = 1 ;
diff --git a/src/lib66/info/info_walk.c b/src/lib66/info/info_walk.c
index b5fd1a8e..bc6d72b9 100644
--- a/src/lib66/info/info_walk.c
+++ b/src/lib66/info/info_walk.c
@@ -23,7 +23,7 @@
 #include <66/info.h>
 #include <66/graph.h>
 
-int info_walk(graph_t *g, char const *name, char const *obj, info_graph_func *func, uint8_t requiredby, uint8_t reverse, depth_t *depth, int padding, info_graph_style *style)
+int info_walk(graph_t *g, char const *name, char const *treename, info_graph_func *func, uint8_t requiredby, uint8_t reverse, depth_t *depth, int padding, info_graph_style *style)
 {
     log_flow() ;
 
@@ -40,7 +40,7 @@ int info_walk(graph_t *g, char const *name, char const *obj, info_graph_func *fu
             stralloc_free(&sa) ;
             return e ;
         }
-        count = sastr_len(&sa) ;
+        count = sastr_nelement(&sa) ;
 
     } else {
 
@@ -70,35 +70,42 @@ int info_walk(graph_t *g, char const *name, char const *obj, info_graph_func *fu
         int last =  idx + 1 < count  ? 0 : 1 ;
         char *name = vertex + pos ;
 
-        if (!info_graph_display(name, obj, func, depth, last, padding, style))
+        if (depth->level == 1 && treename) {
+            char atree[SS_MAX_TREENAME + 1] ;
+
+            service_is_g(atree, name, 0) ;
+
+            if (strcmp(treename, atree))
+                continue ;
+        }
+
+        if (!info_graph_display(name, func, depth, last, padding, style))
             goto err ;
 
         if (graph_matrix_get_edge_g_sorted_sa(&sa, g, name, requiredby, 0) == -1)
             goto err ;
 
-        if (sa.len)
-        {
-            depth_t d =
-            {
+        if (sa.len) {
+
+            depth_t d = {
                 depth,
                 NULL,
                 depth->level + 1
             } ;
             depth->next = &d;
 
-            if(last)
-            {
-                if(depth->prev)
-                {
+            if(last) {
+
+                if(depth->prev) {
+
                     depth->prev->next = &d;
                     d.prev = depth->prev;
                     depth = &d;
-
                 }
                 else
                     d.prev = NULL;
             }
-            if (!info_walk(g, name, obj, func, requiredby, reverse, &d, padding, style))
+            if (!info_walk(g, name, treename, func, requiredby, reverse, &d, padding, style))
                 goto err ;
             depth->next = NULL ;
         }
-- 
GitLab