From 4e6d1d305adcde0070a1637d2d39a2f2128c021e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 17 Jul 2024 21:02:39 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=95=E3=82=A3=E3=82=B0?= =?UTF-8?q?=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=EF=BC=88os=E3=81=A8host=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=95?= =?UTF-8?q?=E3=83=AA=E3=82=AF=E3=83=88=EF=BC=89=20(#40)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/config.c | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1d3e37..725948f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.3.0 * macOSでOS情報の修正 * macOS: 解像度の追加 +* コンフィグのエラーの修正(osとhostのコンフリクト) # 0.2.0 * Manjaroのロゴの追加 diff --git a/src/config.c b/src/config.c index 54e5b0f..c18feee 100644 --- a/src/config.c +++ b/src/config.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "config.h" @@ -24,6 +26,21 @@ bool isgpu = true; bool ismemory = true; bool isstorage = true; +bool containvocab(const char *line, const char *word) { + const char *p = line; + size_t len = strlen(word); + while ((p = strstr(p, word)) != NULL) { + if ( + (p == line || !isalnum((unsigned char)p[-1])) && + !isalnum((unsigned char)p[len]) + ) return true; + + p += len; + } + + return false; +} + void getconf() { char *homedir = getenv("HOME"); if (homedir == NULL) { @@ -61,24 +78,24 @@ void getconf() { while (fgets(line, sizeof(line), file)) { if (line[0] == '#' || line[0] == '\n') continue; if (strstr(line, "hide ") != NULL) { - if (strstr(line, "os") != NULL) isos = false; - if (strstr(line, "host") != NULL) ishost = false; + if (containvocab(line, "os")) isos = false; + if (containvocab(line, "host")) ishost = false; #if defined(__linux__) || defined(__sunos) - if (strstr(line, "distro") != NULL) isdistro = false; + if (containvocab(line, "distro")) isdistro = false; #endif - if (strstr(line, "uptime") != NULL) isuptime = false; + if (containvocab(line, "uptime")) isuptime = false; #if defined (__OpenBSD__) - if (strstr(line, "recording") != NULL) isrecording = false; + if (containvocab(line, "recording")) isrecording = false; #endif - if (strstr(line, "packages") != NULL) ispackages = false; - if (strstr(line, "libc") != NULL) islibc = false; - if (strstr(line, "resolution") != NULL) isresolution = false; - if (strstr(line, "wm") != NULL) iswm = false; - if (strstr(line, "shell") != NULL) isshell = false; - if (strstr(line, "cpu") != NULL) iscpu = false; - if (strstr(line, "gpu") != NULL) isgpu = false; - if (strstr(line, "memory") != NULL) ismemory = false; - if (strstr(line, "storage") != NULL) isstorage = false; + if (containvocab(line, "packages")) ispackages = false; + if (containvocab(line, "libc")) islibc = false; + if (containvocab(line, "resolution")) isresolution = false; + if (containvocab(line, "wm")) iswm = false; + if (containvocab(line, "shell")) isshell = false; + if (containvocab(line, "cpu")) iscpu = false; + if (containvocab(line, "gpu")) isgpu = false; + if (containvocab(line, "memory")) ismemory = false; + if (containvocab(line, "storage")) isstorage = false; } }