diff options
| -rw-r--r-- | main.c | 7 | ||||
| -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 | 
6 files changed, 72 insertions, 2 deletions
@@ -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 @@ -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  | 
