diff --git a/CHANGELOG.md b/CHANGELOG.md index 71be3bc..44e169c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * 色コンフィグの追加 * カスタムロゴコンフィグの追加 * モジュールのキャッシングの追加(それでスピードアップする) +* コンフィグでロゴの設定の追加(隠し・表示、大・小、カスタムロゴ、LinuxとIllumosの場合:ディストロロゴ) # 0.2.0 * Manjaroのロゴの追加 diff --git a/main.c b/main.c index 60f7bcf..2b2572e 100644 --- a/main.c +++ b/main.c @@ -57,6 +57,8 @@ void flags(int opt) { #if defined(__linux__) || defined(__sunos) case 'l': islogo = 1; + islogodistro = 0; + islogocustom = 0; break; #endif #if !defined(__HAIKU__) @@ -171,10 +173,18 @@ int main(int argc, char *argv[]) { if (islogo) { logoname = argv[2]; getDistro(logoname); + } else if (islogodistro) { + logoname = distrostring; + getDistro(logoname); + free(distrostring); } #endif - if (issmall || islogos) { + bool smol = false; + if (issmall && !islogos) smol = true; + else if (!issmall && islogos) smol = true; + + if (smol) { size_t ne = sizeof(LOGO_SMALL) / sizeof(LOGO_SMALL[0]); for (size_t i = 0; i < ne; i++) { LOGO[i] = LOGO_SMALL[i]; diff --git a/src/config.c b/src/config.c index d7e1ee3..8850af1 100644 --- a/src/config.c +++ b/src/config.c @@ -15,6 +15,7 @@ #include "logo/freebsd.h" #elif defined(__linux__) #include "logo/linux.h" +#include "distro.h" #elif defined(__sun) #include "logo/sunos.h" #elif defined(__APPLE__) @@ -27,6 +28,10 @@ bool islogob = true; bool islogos = false; bool islogod = true; bool islogocustom = false; +#if defined(__linux__) || defined(__sunos) +bool islogodistro = false; +char *distrostring; +#endif bool isos = true; bool ishost = true; #if defined(__linux__) || defined(__sunos) @@ -56,6 +61,15 @@ const char *customtitlecolor; const char *customlogobig; const char *customlogosmall; +void rmstr(char *str, const char *sub) { + char *pos; + size_t len = strlen(sub); + + while ((pos = strstr(str, sub)) != NULL) { + memmove(pos, pos + len, strlen(pos + len) + 1); + } +} + const char *applycolor(const char *color) { if (strncmp(color, "grey", 4) == 0) return GREY; else if (strncmp(color, "red", 3) == 0) return RED; @@ -188,20 +202,32 @@ void getconf() { // デフォルトは大きいロゴ if (strstr(line, "show logo") != NULL) { - puts("show logo"); if (containvocab(line, "small")) { - puts("small"); islogob = false; islogos = true; } else { - puts("big"); islogob = true; islogos = false; } if (containvocab(line, "custom")) { - puts("custom"); islogocustom = true; +#if defined(__linux__) || defined(__sunos) + } else { + distrostring = strdup(line); + if (!distrostring) { + perror("メモリの役割に失敗"); + return; + } + rmstr(distrostring, "show logo"); + if (containvocab(line, "small")) rmstr(distrostring, "small"); + else rmstr(distrostring, "big"); + rmstr(distrostring, "\n"); + rmstr(distrostring, " "); + + if (is_distro(distrostring)) islogodistro = true; + else distrostring = NULL; +#endif } } @@ -235,6 +261,7 @@ void getconf() { LOGO[biglogoi][len - 1] = '\0'; } biglogoi++; + free(LOGO[biglogoi]); } } @@ -260,6 +287,7 @@ void getconf() { LOGO_SMALL[smalllogoi][len - 1] = '\0'; } smalllogoi++; + free(LOGO[smalllogoi]); } } } diff --git a/src/config.h b/src/config.h index 1afda6c..bc12b12 100644 --- a/src/config.h +++ b/src/config.h @@ -8,6 +8,10 @@ extern bool islogob; extern bool islogos; extern bool islogod; extern bool islogocustom; +#if defined(__linux__) || defined(__sunos) +extern bool islogodistro; +extern char *distrostring; +#endif extern bool isos; extern bool ishost; #if defined(__linux__) || defined(__sunos) diff --git a/src/distro.c b/src/distro.c index b9a7336..ba96bfe 100644 --- a/src/distro.c +++ b/src/distro.c @@ -9,6 +9,39 @@ const char *distroname; +bool is_distro(const char *buf) { +#if defined(__sunos) + if (strncmp(buf, "openindiana") == 0) return 1; + else if (strncmp(buf, "omnios") == 0) return 1; + else if (strncmp(buf, "solaris") == 0) return 1; +#else + if (strncmp(buf, "alpine", sizeof("alpine")) == 0) return 1; + else if (strncmp(buf, "arch", sizeof("arch")) == 0) return 1; + else if (strncmp(buf, "arco", sizeof("arco")) == 0) return 1; + else if (strncmp(buf, "artix", sizeof("artix")) == 0) return 1; + else if (strncmp(buf, "centos", sizeof("centos")) == 0) return 1; + else if (strncmp(buf, "crux", sizeof("crux")) == 0) return 1; + else if (strncmp(buf, "debian", sizeof("debian")) == 0) return 1; + else if (strncmp(buf, "devuan", sizeof("devuan")) == 0) return 1; + else if (strncmp(buf, "fedora", sizeof("fedora")) == 0) return 1; + else if (strncmp(buf, "gentoo", sizeof("gentoo")) == 0) return 1; + else if (strncmp(buf, "hyperbola", sizeof("hyperbola")) == 0) return 1; + else if (strncmp(buf, "linuxmint", sizeof("linuxmint")) == 0) return 1; + else if (strncmp(buf, "manjaro", sizeof("manjaro")) == 0) return 1; + else if (strncmp(buf, "opensuse", sizeof("opensuse")) == 0) return 1; + else if (strncmp(buf, "parabola", sizeof("parabola")) == 0) return 1; + else if (strncmp(buf, "popos", sizeof("popos")) == 0) return 1; + else if (strncmp(buf, "postmarketos", sizeof("postmarketos")) == 0) return 1; + else if (strncmp(buf, "redhat", sizeof("redhat")) == 0) return 1; + else if (strncmp(buf, "rocky", sizeof("rocky")) == 0) return 1; + else if (strncmp(buf, "ubuntu", sizeof("ubuntu")) == 0) return 1; + else if (strncmp(buf, "void", sizeof("void")) == 0) return 1; + else if (strncmp(buf, "linux", sizeof("linux"))) return 1; +#endif + + return 0; +} + const char *display_distro() { char buf[1288]; char *out = NULL; @@ -108,7 +141,8 @@ void get_distro() { else if (strstr(buf, "Hyperbola") != NULL) distroname = "hyperbola"; else if (strstr(buf, "Linux Mint") != NULL) distroname = "linuxmint"; else if (strstr(buf, "Manjaro") != NULL) distroname = "manjaro"; - else if (strstr(buf, "opensuse") != NULL) distroname = "opensuse"; + else if (strstr(buf, "OpenIndiana") != NULL) distroname = "openindiana"; + else if (strstr(buf, "openSUSE") != NULL) distroname = "opensuse"; else if (strstr(buf, "OmniOS") != NULL) distroname = "omnios"; else if (strstr(buf, "Parabola") != NULL) distroname = "parabola"; else if (strstr(buf, "Pop!_OS") != NULL) distroname = "popos"; diff --git a/src/distro.h b/src/distro.h index 4807840..22c4d89 100644 --- a/src/distro.h +++ b/src/distro.h @@ -2,6 +2,9 @@ #ifndef DISTRO_H #define DISTRO_H +#include + +bool is_distro(const char *buf); const char *display_distro(); void get_distro();