From 8d3614674d35895e018c51ad7802c0cedb4eb763 Mon Sep 17 00:00:00 2001 From: dqnk Date: Fri, 2 Apr 2021 09:41:03 +0200 Subject: [PATCH 1/3] Fixed issue with printing ram #59 --- uwufetch.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 85cc253..809dc23 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -41,8 +41,10 @@ struct utsname sys_var; struct sysinfo sys; struct winsize win; +// all possible ram values obtainable with free command +int ram_total, ram_used, ram_free, shared, buff_cache, available = 0; // initialise the variables to store data, gpu array can hold up to 8 gpus -int ram_max = 0, ram_free = 0, pkgs, a_i_flag = 0, target_width = 0; +int pkgs, a_i_flag = 0, target_width = 0; char user[32], host[256], shell[64], version_name[64], cpu_model[256], gpu_model[8][256] = {{'0'},{'0'},{'0'},{'0'},{'0'},{'0'},{'0'},{'0'}}, pkgman_name[64], image_name[32]; int pkgman(); @@ -161,7 +163,7 @@ void print_info() { // print ram to uptime and colors printf("\033[18C%s%sWAM %s%i MB/%i MB\n", - NORMAL, BOLD, NORMAL, (ram_max - ram_free), ram_max); + NORMAL, BOLD, NORMAL, (ram_used), ram_total); printf("\033[18C%s%sSHELL %s%s\n", NORMAL, BOLD, NORMAL, shell); printf("\033[18C%s%sPKGS %s%s%d %s\n", @@ -218,14 +220,23 @@ void get_info() { // get all necessary info truncate_name(sys_var.machine); // ram - FILE *meminfo = fopen("/proc/meminfo", "r"); + + + FILE *meminfo; + + meminfo = popen("free 2> /dev/null", "r"); while (fgets(line, sizeof(line), meminfo)) { - sscanf(line, "MemFree: %d kB", &ram_free); - sscanf(line, "MemTotal: %d kB", &ram_max); - if (ram_max > 0 && ram_free > 0) { - ram_max *= 0.001024; - ram_free *= 0.001024; - break; + // free command prints like this: "Mem:" total used free shared buff/cache available + + if(sscanf(line, "Mem: %d %d %d %d %d %d", &ram_total, &ram_used, &ram_free, &shared, &buff_cache, &available)){ + // convert to megabytes + if (ram_total > 0 && ram_free > 0) { + // data is in bytes + ram_total /= 1024; + ram_free /= 1024; + ram_used /= 1024; + break; + } } } fclose(meminfo); From 38030b0080eb08693b1d271b678e580cd10fff38 Mon Sep 17 00:00:00 2001 From: dqnk <64268180+dqnk@users.noreply.github.com> Date: Fri, 2 Apr 2021 09:47:48 +0200 Subject: [PATCH 2/3] removed calculation with unused variable --- uwufetch.c | 1 - 1 file changed, 1 deletion(-) diff --git a/uwufetch.c b/uwufetch.c index 809dc23..437735e 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -233,7 +233,6 @@ void get_info() { // get all necessary info if (ram_total > 0 && ram_free > 0) { // data is in bytes ram_total /= 1024; - ram_free /= 1024; ram_used /= 1024; break; } From b25524a976f0384a1ebf002be87c988531e4f277 Mon Sep 17 00:00:00 2001 From: dqnk Date: Fri, 2 Apr 2021 09:52:20 +0200 Subject: [PATCH 3/3] removed more unused variables --- uwufetch.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 809dc23..d382ef2 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -42,7 +42,7 @@ struct sysinfo sys; struct winsize win; // all possible ram values obtainable with free command -int ram_total, ram_used, ram_free, shared, buff_cache, available = 0; +int ram_total, ram_used = 0; // initialise the variables to store data, gpu array can hold up to 8 gpus int pkgs, a_i_flag = 0, target_width = 0; char user[32], host[256], shell[64], version_name[64], cpu_model[256], gpu_model[8][256] = {{'0'},{'0'},{'0'},{'0'},{'0'},{'0'},{'0'},{'0'}}, pkgman_name[64], image_name[32]; @@ -228,12 +228,11 @@ void get_info() { // get all necessary info while (fgets(line, sizeof(line), meminfo)) { // free command prints like this: "Mem:" total used free shared buff/cache available - if(sscanf(line, "Mem: %d %d %d %d %d %d", &ram_total, &ram_used, &ram_free, &shared, &buff_cache, &available)){ + if(sscanf(line, "Mem: %d %d", &ram_total, &ram_used)){ // convert to megabytes - if (ram_total > 0 && ram_free > 0) { + if (ram_total > 0 && ram_used > 0) { // data is in bytes ram_total /= 1024; - ram_free /= 1024; ram_used /= 1024; break; }