Skip to content

Commit

Permalink
get_pkgs mechanism switched back to shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdotx committed Oct 11, 2022
1 parent 70141dc commit 01f1de1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
25 changes: 9 additions & 16 deletions cinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* path: /home/klassiker/.local/share/repos/cinfo/cinfo.c
* author: klassiker [mrdotx]
* github: https://github.com/mrdotx/cinfo
* date: 2022-09-08T11:56:32+0200
* date: 2022-10-11T12:34:44+0200
*/

#include <stddef.h>
Expand Down Expand Up @@ -120,28 +120,21 @@ void *get_pkgs() {
pkgs_count = 0;

FILE *file;
DIR *dir;

struct dirent *entry;

if ((file = fopen(CACHE_PKGS_PATH, "r"))) {
if (fscanf(file, "%d", &pkgs_count)) {
fclose(file);
}
} else {
if ((dir = opendir(PKGS_PATH)) == NULL) return 0;

while ((entry = readdir(dir)) != NULL) {
if (0 == strcmp(entry->d_name,".") ||
0 == strcmp(entry->d_name,"..")) continue;
if (entry->d_type == DT_DIR) {
pkgs_count++;
if ((file = popen(PKGS_CMD, "r"))) {
if (fscanf(file, "%d", &pkgs_count)) {
fclose(file);
}

file = fopen(CACHE_PKGS_PATH, "w");
fprintf(file, "%d", pkgs_count);
fclose(file);
}
file = fopen(CACHE_PKGS_PATH, "w");
fprintf(file, "%d", pkgs_count);
fclose(file);
closedir(dir);
}

snprintf(g_pkgs, max_len, "%d%s", pkgs_count, PKGS_DESC);
Expand Down Expand Up @@ -503,6 +496,7 @@ void *get_shell() {

void get_infos(void *print()) {
const void *routines[] = {
get_pkgs,
get_cpu,
get_mem,
get_uptime,
Expand All @@ -511,7 +505,6 @@ void get_infos(void *print()) {
get_distro,
get_kernel,
get_model,
get_pkgs,
get_shell,
get_user
};
Expand Down
4 changes: 2 additions & 2 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* path: /home/klassiker/.local/share/repos/cinfo/config.def.h
* author: klassiker [mrdotx]
* github: https://github.com/mrdotx/cinfo
* date: 2022-08-23T14:11:55+0200
* date: 2022-10-11T12:42:02+0200
*/

/* packages */
static const char *PKGS_PATH = "/var/lib/pacman/local",
static const char *PKGS_CMD = "ls -p /var/lib/pacman/local | grep -c /",
*PKGS_DESC = " [pacman]";

/* cpu */
Expand Down

0 comments on commit 01f1de1

Please sign in to comment.