From b21b4fa52697a8ed3e81b984cd61e8168e318dec Mon Sep 17 00:00:00 2001 From: sorgelig Date: Wed, 1 Jul 2020 05:10:45 +0800 Subject: [PATCH] input: some cleanup. --- input.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/input.cpp b/input.cpp index 176bf4c..46eca9f 100644 --- a/input.cpp +++ b/input.cpp @@ -2664,9 +2664,12 @@ void mergedevs() static char str[1024]; char phys[64] = {}; char uniq[64] = {}; + while (fgets(str, sizeof(str), f)) { int len = strlen(str); + while (len && str[len - 1] == '\n') str[--len] = 0; + if (!len) { phys[0] = 0; @@ -2674,19 +2677,10 @@ void mergedevs() } else { - if (!strncmp("P: Phys", str, 7)) - { - char *p = strchr(str, '='); - snprintf(phys, sizeof(phys), "%s", p + 1); - if (phys[strlen(phys) - 1] == '\n') phys[strlen(phys) - 1] = 0; - } - else if (!strncmp("U: Uniq", str, 7)) - { - char *p = strchr(str, '='); - snprintf(uniq, sizeof(uniq), "%s", p + 1); - if (uniq[strlen(uniq) - 1] == '\n') uniq[strlen(uniq) - 1] = 0; - } - else if (!strncmp("H: ", str, 3) && phys[0]) + if (!strncmp("P: Phys", str, 7)) snprintf(phys, sizeof(phys), "%s", strchr(str, '=') + 1); + if (!strncmp("U: Uniq", str, 7)) snprintf(uniq, sizeof(uniq), "%s", strchr(str, '=') + 1); + + if (!strncmp("H: ", str, 3) && phys[0]) { char *handlers = strchr(str, '='); if (handlers)