From 9858e8390bbeb0a9860397e677ef18ccc6160e33 Mon Sep 17 00:00:00 2001 From: jewelcodes Date: Sun, 6 Oct 2024 00:12:38 -0400 Subject: [PATCH] luxfetch: stub for a neofetch-like app --- Makefile | 8 +++++++- luxfetch/Makefile | 23 +++++++++++++++++++++++ luxfetch/luxfetch.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 luxfetch/Makefile create mode 100644 luxfetch/luxfetch.c diff --git a/Makefile b/Makefile index aa5508a..11d7688 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ all: @make -C ls @echo "\x1B[0;1;35m make\x1B[0m utilities/cat" @make -C cat + @echo "\x1B[0;1;35m make\x1B[0m utilities/luxfetch" + @make -C luxfetch install: @mkdir -p out @@ -30,6 +32,8 @@ install: @make install -C ls @echo "\x1B[0;1;35m make\x1B[0m install utilities/cat" @make install -C cat + @echo "\x1B[0;1;35m make\x1B[0m install utilities/luxfetch" + @make install -C luxfetch clean: @echo "\x1B[0;1;35m make\x1B[0m clean utilities/hello" @@ -45,4 +49,6 @@ clean: @echo "\x1B[0;1;35m make\x1B[0m clean utilities/ls" @make clean -C ls @echo "\x1B[0;1;35m make\x1B[0m clean utilities/cat" - @make clean -C cat \ No newline at end of file + @make clean -C cat + @echo "\x1B[0;1;35m make\x1B[0m clean utilities/luxfetch" + @make clean -C luxfetch \ No newline at end of file diff --git a/luxfetch/Makefile b/luxfetch/Makefile new file mode 100644 index 0000000..f40c388 --- /dev/null +++ b/luxfetch/Makefile @@ -0,0 +1,23 @@ +PLATFORM=x86_64-lux +CCFLAGS=-Wall -c -O3 +LDFLAGS=-llux +CC=x86_64-lux-gcc +LD=x86_64-lux-gcc +SRC:=$(shell find . -type f -name "*.c") +OBJ:=$(SRC:.c=.o) + +all: luxfetch + +%.o: %.c + @echo "\x1B[0;1;32m cc \x1B[0m $<" + @$(CC) $(CCFLAGS) -o $@ $< + +luxfetch: $(OBJ) + @echo "\x1B[0;1;93m ld \x1B[0m luxfetch" + @$(LD) $(OBJ) -o luxfetch $(LDFLAGS) + +install: luxfetch + @cp luxfetch ../out/ + +clean: + @rm -f luxfetch $(OBJ) diff --git a/luxfetch/luxfetch.c b/luxfetch/luxfetch.c new file mode 100644 index 0000000..1859516 --- /dev/null +++ b/luxfetch/luxfetch.c @@ -0,0 +1,42 @@ +/* + * luxOS - a unix-like operating system + * Omar Elghoul, 2024 + * + * luxfetch: neofetch clone for luxOS + */ + +#include +#include +#include + +#define COLOR "\e[0;94m" +#define RESET "\e[0m" + +int main(void) { + // get kernel info + FILE *f = fopen("/proc/kernel", "r"); + if(!f) { + fprintf(stderr, "unable to open /proc/kernel for reading\n"); + return -1; + } + + fseek(f, 0, SEEK_END); + long size = ftell(f); + fseek(f, 0, SEEK_SET); + + char *kernel = calloc(1, size+1); + if(!kernel) { + fprintf(stderr, "failed to allocate memory\n"); + fclose(f); + return -1; + } + + if(fread(kernel, 1, size, f) != size) { + fprintf(stderr, "failed to read from /proc/kernel\n"); + fclose(f); + return -1; + } + + printf("%s\n", kernel); + return 0; +} \ No newline at end of file