aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ascii.c3
-rw-r--r--src/cfetch.c16
-rw-r--r--src/sysinfo.c32
-rw-r--r--src/utils.c24
4 files changed, 52 insertions, 23 deletions
diff --git a/src/ascii.c b/src/ascii.c
index 2fee648..f1acce7 100644
--- a/src/ascii.c
+++ b/src/ascii.c
@@ -66,6 +66,7 @@ void print_ascii_art(system_info_t *info, int art)
// get_max_ascii_length
// und dann get_line_length?
// alles im struct speicher?
+/*
void get_line_length(ascii_art_t *ascii, const char **line)
{
size_t length = 0;
@@ -84,4 +85,4 @@ void get_line_length(ascii_art_t *ascii, const char **line)
}
}
}
-
+*/
diff --git a/src/cfetch.c b/src/cfetch.c
index caabbc9..66d115d 100644
--- a/src/cfetch.c
+++ b/src/cfetch.c
@@ -25,10 +25,22 @@ int main(void) {
// set systeminformation
// use // to uncomment or comment
- get_os(&info);
- get_memory(&info);
+ // get_os: Ubuntu <version>
+ // get_host: Laptop name? Precision 7680
+ get_kernel(&info);
+ // get_uptime
+ // get_packages
+ // get_shell
+ // get_resolution
+ // get_de
+ // get_wm
+ // get_terminal
get_cpu(&info);
+ //get_gpu
+ get_memory(&info);
+
print_ascii_art(&info, art_logo);
+ // get_colours ?
return 0;
}
diff --git a/src/sysinfo.c b/src/sysinfo.c
index bb7f20d..f402741 100644
--- a/src/sysinfo.c
+++ b/src/sysinfo.c
@@ -1,12 +1,14 @@
#include "../include/cfetch.h"
+#include <stdio.h>
#include <sys/utsname.h>
-void get_os(system_info_t *info) {
+void get_kernel(system_info_t *info) {
#ifdef __linux__
struct utsname u;
if (uname(&u) == 0) {
- size_t length = printf("OS: %s %s %s %s\n", u.sysname, u.release, u.version, u.machine);
+ snprintf(info->kernel, sizeof(info->kernel), "%.30s %.30s", u.sysname, u.release);
+ printf("Kernel: %s\n", info->kernel);
} else {
perror("Error while accessing uname");
return;
@@ -20,39 +22,29 @@ void get_cpu(system_info_t *info) {
//check file existence
if (!file) {
- perror("/proc/cpuinfo not found");
+ snprintf(info->cpu, sizeof(info->cpu), "Unknown");
return;
}
char line[256];
- char *model_name = NULL;
+ char cpu_name[256] = "Unknown";
+ char *colon = NULL;
//read per line
while (fgets(line, sizeof(line), file)) {
char* p = strstr(line, "model name");
if (p != NULL) {
- model_name = strchr(p, ':') + 1; //skip :
+ colon = strchr(p, ':') + 1; //skip :
break;
}
}
- if (model_name != NULL) {
- char *string = string_format(model_name);
-
- if (string == NULL) {
- printf("CPU: Error string not found.\n");
- free(string);
- model_name = NULL;
- } else {
- printf("CPU: %s\n", string);
- free(string);
- model_name = NULL;
- }
+ if (colon != NULL) {
+ snprintf(info->cpu, sizeof(info->cpu), "%s", trim_whitespace(colon));
- } else {
- printf("CPU: Error model_name not found.\n");
- }
+ printf("CPU: %s\n", info->cpu);
+ }
fclose(file);
return;
diff --git a/src/utils.c b/src/utils.c
index 5fba4dc..56cca93 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,4 +1,5 @@
#include "../include/cfetch.h"
+#include <string.h>
/* function: char *string_format(char* string)
* input: pointer to a null-terminated string (must not be NULL)
@@ -109,3 +110,26 @@ char *concat(const char *s1, const char *s2) {
memcpy(result + len1, s2, len2 + 1); // +1 for null-terminator
return result; //caller needs to free memory
}
+
+
+char *trim_whitespace(char* str)
+{
+ char *end;
+
+ // Trim leading spaces
+ while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r') {
+ str++;
+ }
+
+ if (*str == '\0') return str; // all spaces
+
+ // Trim trailing space
+ end = str + strlen(str) - 1;
+
+ while (end > str && (*end == ' ' || *end == '\t' || *end == '\r' || *end == '\n')) end--;
+
+ // Write new null terminator character
+ end[1] = '\0';
+
+ return str;
+}