From 2422a3060d51448f727e1532e2fd19d14f44c80e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 25 Mar 2025 20:13:14 -0500 Subject: [PATCH] Use strany() instead of enum and strcmp staircase. --- lib/portability.h | 10 ---------- toys/android/log.c | 12 +++--------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/portability.h b/lib/portability.h index 55e3ab21..29d5469f 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -302,16 +302,6 @@ typedef enum android_LogPriority { ANDROID_LOG_FATAL, ANDROID_LOG_SILENT, } android_LogPriority; -typedef enum log_id { - LOG_ID_MAIN = 0, - LOG_ID_RADIO = 1, - LOG_ID_EVENTS = 2, - LOG_ID_SYSTEM = 3, - LOG_ID_CRASH = 4, - LOG_ID_STATS = 5, - LOG_ID_SECURITY = 6, - LOG_ID_KERNEL = 7, -} log_id_t; #endif #if !defined(__BIONIC__) || defined(__ANDROID_NDK__) // Android NDKv18 has liblog.so but not liblog.a for static builds. diff --git a/toys/android/log.c b/toys/android/log.c index 5c4dcd90..1b05f4e7 100644 --- a/toys/android/log.c +++ b/toys/android/log.c @@ -49,15 +49,9 @@ void log_main(void) ANDROID_LOG_VERBOSE, ANDROID_LOG_WARN}[i]; } if (!TT.t) TT.t = "log"; - if (!TT.b || !strcmp(TT.b, "main")) TT.buf = LOG_ID_MAIN; - else if (!strcmp(TT.b, "radio")) TT.buf = LOG_ID_RADIO; - else if (!strcmp(TT.b, "events")) TT.buf = LOG_ID_EVENTS; - else if (!strcmp(TT.b, "system")) TT.buf = LOG_ID_SYSTEM; - else if (!strcmp(TT.b, "crash")) TT.buf = LOG_ID_CRASH; - else if (!strcmp(TT.b, "stats")) TT.buf = LOG_ID_STATS; - else if (!strcmp(TT.b, "security")) TT.buf = LOG_ID_SECURITY; - else if (!strcmp(TT.b, "kernel")) TT.buf = LOG_ID_KERNEL; - else error_exit("unknown log buffer: %s", TT.b); + if (TT.b) TT.buf = anystr(TT.b, (char *[]){"main", "radio", "events", + "system", "crash", "stats", "security", "kernel", 0})-1; + if (TT.buf<0) error_exit("unknown log buffer: %s", TT.b); if (toys.optc) { for (i = 0; toys.optargs[i]; i++) { -- 2.39.5