diff options
author | 諏訪子 <suwako@076.moe> | 2024-06-18 19:12:24 +0900 |
---|---|---|
committer | 諏訪子 <suwako@076.moe> | 2024-06-18 19:12:24 +0900 |
commit | b48f40f863c80c9f8394cfd5e8c3716191611888 (patch) | |
tree | a9ee6502cd5771bc0ed3a336e9b5cfdeaba86e63 /src | |
parent | 79285280a55c9a420947620ae20d327563f9ce78 (diff) |
パッケージ情報の追加
Diffstat (limited to 'src')
-rw-r--r-- | src/distro.c | 9 | ||||
-rw-r--r-- | src/host.c | 2 | ||||
-rw-r--r-- | src/logo/openbsd.h | 2 | ||||
-rw-r--r-- | src/packages.c | 48 | ||||
-rw-r--r-- | src/packages.h | 6 |
5 files changed, 65 insertions, 2 deletions
diff --git a/src/distro.c b/src/distro.c index 845f85e..f39d1ea 100644 --- a/src/distro.c +++ b/src/distro.c @@ -51,9 +51,16 @@ void display_distro() { while (fgets(buf, sizeof(buf), p) != NULL) { buf[strcspn(buf, "\n")] = '\0'; printf("%s", buf); - distroname = buf; } + if (strstr(buf, "Devuan") != NULL) distroname = "devuan"; + else if (strstr(buf, "Void Linux") != NULL) distroname = "void"; + else if (strstr(buf, "Debian") != NULL) distroname = "debian"; + else if (strstr(buf, "Arch Linux") != NULL) distroname = "arch"; + else if (strstr(buf, "Artix Linux") != NULL) distroname = "artix"; + else if (strstr(buf, "CRUX") != NULL) distroname = "crux"; + else distroname = "linux"; + pclose(p); } #endif @@ -54,7 +54,7 @@ const char *run_host_command(const char *command) { out = nout; - memcpy(out + outsize, buf, len); + memccpy(out + outsize, buf, sizeof(buf), len); outsize += len; out[outsize] = '\0'; } diff --git a/src/logo/openbsd.h b/src/logo/openbsd.h index 8a58da2..bbd4df4 100644 --- a/src/logo/openbsd.h +++ b/src/logo/openbsd.h @@ -41,5 +41,7 @@ YELLOW " | " RESET "O O" YELLOW" | " RESET, YELLOW " |_ < ) 3 ) " RESET, YELLOW " / \\ / " RESET, YELLOW " /-_____-\\ " RESET, +YELLOW " " RESET, +YELLOW " " RESET, YELLOW " " RESET }; diff --git a/src/packages.c b/src/packages.c new file mode 100644 index 0000000..835aac4 --- /dev/null +++ b/src/packages.c @@ -0,0 +1,48 @@ +#include "packages.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +const char *run_package_command(const char *command) { + char buf[64]; + char *out = NULL; + size_t outsize = 0; + + FILE *p = popen(command, "r"); + if (!p) { + fprintf(stderr, "パッケージコマンドを実効に失敗: %s", command); + return NULL; + } + + while (fgets(buf, sizeof(buf), p) != NULL) { + buf[strcspn(buf, "\n")] = '\0'; + + size_t len = strlen(buf); + char *nout = realloc(out, outsize + len + 1); + if (nout == NULL) { + perror("メモリの役割に失敗"); + free(out); + pclose(p); + return NULL; + } + + out = nout; + + memccpy(out + outsize, buf, sizeof(buf), len); + outsize += len; + out[outsize] = '\0'; + } + + pclose(p); + + return out; +} + +void display_packages() { +#if defined(__OpenBSD__) || defined(__NetBSD__) + printf("%s (pkg_info)", run_package_command("pkg_info -a | wc -l | sed \"s/ //g\"")); +#elif defined(__FreeBSD__) || defined(__DragonFly__) + printf("%s (pkg)", run_package_command("pkg info -a | wc -l | sed \"s/ //g\"")); +#endif +} diff --git a/src/packages.h b/src/packages.h new file mode 100644 index 0000000..0733f34 --- /dev/null +++ b/src/packages.h @@ -0,0 +1,6 @@ +#ifndef PACKAGES_H +#define PACKAGES_H + +void display_packages(); + +#endif |