summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author諏訪子 <suwako@076.moe>2024-06-18 19:12:24 +0900
committer諏訪子 <suwako@076.moe>2024-06-18 19:12:24 +0900
commitb48f40f863c80c9f8394cfd5e8c3716191611888 (patch)
treea9ee6502cd5771bc0ed3a336e9b5cfdeaba86e63
parent79285280a55c9a420947620ae20d327563f9ce78 (diff)
パッケージ情報の追加
-rw-r--r--main.c7
-rw-r--r--src/distro.c9
-rw-r--r--src/host.c2
-rw-r--r--src/logo/openbsd.h2
-rw-r--r--src/packages.c48
-rw-r--r--src/packages.h6
6 files changed, 72 insertions, 2 deletions
diff --git a/main.c b/main.c
index 69a62fe..6a13b72 100644
--- a/main.c
+++ b/main.c
@@ -12,6 +12,7 @@
#if defined(__OpenBSD__)
#include "src/recording.h"
#endif
+#include "src/packages.h"
#include "src/cpu.h"
#include "src/memory.h"
@@ -114,6 +115,12 @@ int main(int argc, char *argv[]) {
#endif
printf("%s ", LOGO[lc]);
+ printf(COLOR"%s%s"RESET, "Packages", ": ");
+ display_packages();
+ printf("\n");
+ lc++;
+
+ printf("%s ", LOGO[lc]);
printf(COLOR"%s%s"RESET, "CPU", ": ");
display_cpu();
printf("\n");
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
diff --git a/src/host.c b/src/host.c
index 010af9e..03b2f2c 100644
--- a/src/host.c
+++ b/src/host.c
@@ -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