diff options
author | Roy Marples <roy@marples.name> | 2007-07-06 15:50:40 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-07-06 15:50:40 +0000 |
commit | 809b5286b65b5f74c9968925546f11857e6dc36a (patch) | |
tree | ed0500d1819f0786dc4e153cf6d34dc9126c72ff | |
parent | 090090328ac149766f5ffe49bd21a1f8d92a4c6d (diff) |
Make the prefix length dynamic
-rw-r--r-- | src/runscript.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/runscript.c b/src/runscript.c index 94df6fcc..dd0acb37 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -299,7 +299,6 @@ static void cleanup (void) static int write_prefix (int fd, const char *buffer, size_t bytes, bool *prefixed) { unsigned int i; - int j; const char *ec; const char *ec_normal = ecolor (ecolor_normal); ssize_t ret = 0; @@ -316,11 +315,9 @@ static int write_prefix (int fd, const char *buffer, size_t bytes, bool *prefixe if (! *prefixed) { ret += write (fd, ec, strlen (ec)); - ret += write (fd, applet, strlen (applet)); - for (j = strlen (applet); j < 11; j++) - ret += write (fd, " ", 1); + ret += write (fd, prefix, strlen (prefix)); ret += write (fd, ec_normal, strlen (ec_normal)); - ret += write (fd, " |", 2); + ret += write (fd, "|", 2); *prefixed = true; } @@ -1082,11 +1079,23 @@ int main (int argc, char **argv) /* eprefix is kinda klunky, but it works for our purposes */ if (rc_is_env ("RC_PREFIX", "yes")) { - int l = strlen (applet); - if (l < 13) - l = 13; - prefix = rc_xmalloc (sizeof (char *) * l); - snprintf (prefix, l, "%s%s", applet, " "); + int l = 0; + char *svc; + + /* Get the longest service name */ + services = rc_services_in_runlevel (NULL); + STRLIST_FOREACH (services, svc, i) { + int ll = strlen (svc); + if (ll > l) + l = ll; + } + // rc_strlist_free (services); + + svc = prefix = rc_xmalloc (sizeof (char *) * l); + svc += strlcpy (prefix, applet, l); + i = l - strlen (prefix); + memset (svc, ' ', i); + memset (svc + i, 0, 1); eprefix (prefix); } |