]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
show-status: fold two bool flags function arguments into a flags
authorLennart Poettering <lennart@poettering.net>
Fri, 23 Nov 2018 16:18:48 +0000 (17:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Nov 2018 17:24:12 +0000 (18:24 +0100)
parameter

src/core/main.c
src/core/manager.c
src/core/show-status.c
src/core/show-status.h

index 34794ccdd18c94abe881bb69ec20d71fbbf1fc5c..6d03b066847d5c45c5c52b1e64f7fc2a28a26f46 100644 (file)
@@ -1371,12 +1371,12 @@ static int status_welcome(void) {
                                "Failed to read os-release file, ignoring: %m");
 
         if (log_get_show_color())
-                return status_printf(NULL, false, false,
+                return status_printf(NULL, 0,
                                      "\nWelcome to \x1B[%sm%s\x1B[0m!\n",
                                      isempty(ansi_color) ? "1" : ansi_color,
                                      isempty(pretty_name) ? "Linux" : pretty_name);
         else
-                return status_printf(NULL, false, false,
+                return status_printf(NULL, 0,
                                      "\nWelcome to %s!\n",
                                      isempty(pretty_name) ? "Linux" : pretty_name);
 }
index e2de1c84b91c1face2dd88c8849522451bd4be69..5f11515b3d198f2c8d25a39e043de2d79693e6ba 100644 (file)
@@ -4156,7 +4156,7 @@ void manager_status_printf(Manager *m, StatusType type, const char *status, cons
                 return;
 
         va_start(ap, format);
-        status_vprintf(status, true, type == STATUS_TYPE_EPHEMERAL, format, ap);
+        status_vprintf(status, SHOW_STATUS_ELLIPSIZE|(type == STATUS_TYPE_EPHEMERAL ? SHOW_STATUS_EPHEMERAL : 0), format, ap);
         va_end(ap);
 }
 
index d8d2317d38ef1f1763c78da2457f8b9e94357224..e8ac004903e2c054a46dd1a391380256359d623e 100644 (file)
@@ -32,7 +32,7 @@ int parse_show_status(const char *v, ShowStatus *ret) {
         return 0;
 }
 
-int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) {
+int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
         static const char status_indent[] = "         "; /* "[" STATUS "] " */
         _cleanup_free_ char *s = NULL;
         _cleanup_close_ int fd = -1;
@@ -57,7 +57,7 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
         if (fd < 0)
                 return fd;
 
-        if (ellipse) {
+        if (FLAGS_SET(flags, SHOW_STATUS_ELLIPSIZE)) {
                 char *e;
                 size_t emax, sl;
                 int c;
@@ -94,9 +94,9 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
         iovec[n++] = IOVEC_MAKE_STRING(s);
         iovec[n++] = IOVEC_MAKE_STRING("\n");
 
-        if (prev_ephemeral && !ephemeral)
+        if (prev_ephemeral && !FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL))
                 iovec[n++] = IOVEC_MAKE_STRING(ANSI_ERASE_TO_END_OF_LINE);
-        prev_ephemeral = ephemeral;
+        prev_ephemeral = FLAGS_SET(flags, SHOW_STATUS_EPHEMERAL) ;
 
         if (writev(fd, iovec, n) < 0)
                 return -errno;
@@ -104,14 +104,14 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
         return 0;
 }
 
-int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) {
+int status_printf(const char *status, ShowStatusFlags flags, const char *format, ...) {
         va_list ap;
         int r;
 
         assert(format);
 
         va_start(ap, format);
-        r = status_vprintf(status, ellipse, ephemeral, format, ap);
+        r = status_vprintf(status, flags, format, ap);
         va_end(ap);
 
         return r;
index ac590303c112993de6970647442f808b0cafe6fa..f574d92d8465258cb2dedfc663b050dbd385b29d 100644 (file)
@@ -16,9 +16,14 @@ typedef enum ShowStatus {
         _SHOW_STATUS_INVALID = -1,
 } ShowStatus;
 
+typedef enum ShowStatusFlags {
+        SHOW_STATUS_ELLIPSIZE = 1 << 0,
+        SHOW_STATUS_EPHEMERAL = 1 << 1,
+} ShowStatusFlags;
+
 ShowStatus show_status_from_string(const char *v) _const_;
 const char* show_status_to_string(ShowStatus s) _pure_;
 int parse_show_status(const char *v, ShowStatus *ret);
 
-int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
-int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
+int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) _printf_(3,0);
+int status_printf(const char *status, ShowStatusFlags flags, const char *format, ...) _printf_(3,4);