i

Owner: IIIlllIIIllI URL: git@github.com:nyangkosense/i.git

add ascii mapping

Commit 7e7e5e03cbbdd435ae05c135dfe196e02285beb5 by SeMi <sebastian.michalk@protonmail.com> on 2025-06-16 08:46:14 +0200
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..c2098a2
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,18 @@
+{
+  "configurations": [
+    {
+      "name": "linux-gcc-x64",
+      "includePath": [
+        "${workspaceFolder}/**"
+      ],
+      "compilerPath": "/usr/bin/gcc",
+      "cStandard": "${default}",
+      "cppStandard": "${default}",
+      "intelliSenseMode": "linux-gcc-x64",
+      "compilerArgs": [
+        ""
+      ]
+    }
+  ],
+  "version": 4
+}
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..ff9ac02
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,24 @@
+{
+  "version": "0.2.0",
+  "configurations": [
+    {
+      "name": "C/C++ Runner: Debug Session",
+      "type": "cppdbg",
+      "request": "launch",
+      "args": [],
+      "stopAtEntry": false,
+      "externalConsole": false,
+      "cwd": "/home/smooth/in/i",
+      "program": "/home/smooth/in/i/build/Debug/outDebug",
+      "MIMode": "gdb",
+      "miDebuggerPath": "gdb",
+      "setupCommands": [
+        {
+          "description": "Enable pretty-printing for gdb",
+          "text": "-enable-pretty-printing",
+          "ignoreFailures": true
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..bb879da
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,59 @@
+{
+  "C_Cpp_Runner.cCompilerPath": "gcc",
+  "C_Cpp_Runner.cppCompilerPath": "g++",
+  "C_Cpp_Runner.debuggerPath": "gdb",
+  "C_Cpp_Runner.cStandard": "",
+  "C_Cpp_Runner.cppStandard": "",
+  "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
+  "C_Cpp_Runner.useMsvc": false,
+  "C_Cpp_Runner.warnings": [
+    "-Wall",
+    "-Wextra",
+    "-Wpedantic",
+    "-Wshadow",
+    "-Wformat=2",
+    "-Wcast-align",
+    "-Wconversion",
+    "-Wsign-conversion",
+    "-Wnull-dereference"
+  ],
+  "C_Cpp_Runner.msvcWarnings": [
+    "/W4",
+    "/permissive-",
+    "/w14242",
+    "/w14287",
+    "/w14296",
+    "/w14311",
+    "/w14826",
+    "/w44062",
+    "/w44242",
+    "/w14905",
+    "/w14906",
+    "/w14263",
+    "/w44265",
+    "/w14928"
+  ],
+  "C_Cpp_Runner.enableWarnings": true,
+  "C_Cpp_Runner.warningsAsError": false,
+  "C_Cpp_Runner.compilerArgs": [],
+  "C_Cpp_Runner.linkerArgs": [],
+  "C_Cpp_Runner.includePaths": [],
+  "C_Cpp_Runner.includeSearch": [
+    "*",
+    "**/*"
+  ],
+  "C_Cpp_Runner.excludeSearch": [
+    "**/build",
+    "**/build/**",
+    "**/.*",
+    "**/.*/**",
+    "**/.vscode",
+    "**/.vscode/**"
+  ],
+  "C_Cpp_Runner.useAddressSanitizer": false,
+  "C_Cpp_Runner.useUndefinedSanitizer": false,
+  "C_Cpp_Runner.useLeakSanitizer": false,
+  "C_Cpp_Runner.showCompilationTime": false,
+  "C_Cpp_Runner.useLinkTimeOptimization": false,
+  "C_Cpp_Runner.msvcSecureNoWarnings": false
+}
\ No newline at end of file
diff --git a/config.def.h b/config.def.h
index 52f3ff4..a2fc288 100644
--- a/config.def.h
+++ b/config.def.h
@@ -9,6 +9,11 @@ static const double hex_refresh_interval = 0.5;
 /* enable terminal color display in hex background (1 = enabled, 0 = monochrome) */
 static const int enable_colored_hex = 1;
 
+typedef struct {
+	const char *name;
+	const char **art;
+} AsciiMapping;
+
 /* appearance */
 static const struct {
 	uint16_t fg;
@@ -39,6 +44,7 @@ static const char *reboot_cmd = "PATH=/usr/bin:/bin:/sbin:/usr/sbin doas reboot"
 static const char *shutdown_cmd = "PATH=/usr/bin:/bin:/sbin:/usr/sbin doas shutdown -h now";
 
 /* ASCII art definitions for different operating systems */
+
 static const char *ascii_alpine[] = {
 	"   /\\ /\\",
 	"  /./ \\  \\",
@@ -276,3 +282,29 @@ static const char *ascii_void[] = {
 	" -_______\\",
 	NULL
 };
+
+/* ASCII art mappings table */
+static const AsciiMapping ascii_mappings[] = {
+	{"alpine", ascii_alpine},
+	{"android", ascii_android},
+	{"arch", ascii_arch},
+	{"arco", ascii_arco},
+	{"artix", ascii_artix},
+	{"centos", ascii_centos},
+	{"darwin", ascii_macos},
+	{"debian", ascii_debian},
+	{"endeavouros", ascii_endeavour},
+	{"fedora", ascii_fedora},
+	{"freebsd", ascii_freebsd},
+	{"gentoo", ascii_gentoo},
+	{"linuxmint", ascii_linux_mint},
+	{"manjaro", ascii_manjaro},
+	{"nixos", ascii_nixos},
+	{"opensuse", ascii_opensuse},
+	{"pop", ascii_pop_os},
+	{"slackware", ascii_slackware},
+	{"solus", ascii_solus},
+	{"ubuntu", ascii_ubuntu},
+	{"void", ascii_void},
+	{NULL, NULL}
+};
diff --git a/main.c b/main.c
index 4ab9966..c69d9fe 100644
--- a/main.c
+++ b/main.c
@@ -30,6 +30,7 @@
 
 #define MAXSTRLEN 256
 
+/* Types */
 typedef struct {
 	char timestr[MAXSTRLEN];
 	char uptimestr[MAXSTRLEN];
@@ -44,6 +45,8 @@ typedef struct {
 	char dnsstr[MAXSTRLEN];
 } SysInfo;
 
+
+/* Function declarations */
 static void usage(void);
 static void die(const char *msg);
 static void printcenteredin(const char *str, int x, int y, int width, uint16_t fg, uint16_t bg);
@@ -266,7 +269,7 @@ getnetworkstatus(char *buffer)
 		int remaining;
 		
 		remaining = MAXSTRLEN - 12; /* "Connected: " = 11 chars + null */
-		if (strlen(interfacelist) >= remaining) {
+		if ((int)strlen(interfacelist) >= remaining) {
 			interfacelist[remaining - 1] = '\0'; /* Ensure it fits */
 		}
 		snprintf(buffer, MAXSTRLEN, "Connected: %s", interfacelist);
@@ -473,8 +476,6 @@ drawhexbanner(int x, int y, int width, uint16_t fg, uint16_t bg)
 static void
 drawhexbackground(int width, int height)
 {
-	char hexline[512];
-	char hexdata[128];
 	char asciidata[64];
 	int addr, i, j, bytes_per_line, max_bytes, pos;
 	unsigned char byte;
@@ -609,55 +610,20 @@ detectsystem(char *buffer)
 static const char **
 getasciiart(const char *system)
 {
+	int i;
+	
 	if (!system)
 		return ascii_linux;
 
-	if (strcmp(system, "alpine") == 0)
-		return ascii_alpine;
-	if (strcmp(system, "android") == 0)
-		return ascii_android;
-	if (strcmp(system, "arch") == 0)
-		return ascii_arch;
-	if (strcmp(system, "arco") == 0)
-		return ascii_arco;
-	if (strcmp(system, "artix") == 0)
-		return ascii_artix;
-	if (strcmp(system, "centos") == 0)
-		return ascii_centos;
-	if (strcmp(system, "debian") == 0)
-		return ascii_debian;
-	if (strcmp(system, "endeavouros") == 0)
-		return ascii_endeavour;
-	if (strcmp(system, "fedora") == 0)
-		return ascii_fedora;
-	if (strcmp(system, "freebsd") == 0)
-		return ascii_freebsd;
-	if (strcmp(system, "gentoo") == 0)
-		return ascii_gentoo;
-	if (strcmp(system, "linuxmint") == 0)
-		return ascii_linux_mint;
+	for (i = 0; ascii_mappings[i].name != NULL; i++) {
+		if (strcmp(system, ascii_mappings[i].name) == 0)
+			return ascii_mappings[i].art;
+	}
+	
 	if (strstr(system, "mint") != NULL)
 		return ascii_linux_mint;
-	if (strcmp(system, "darwin") == 0)
-		return ascii_macos;
-	if (strcmp(system, "manjaro") == 0)
-		return ascii_manjaro;
-	if (strcmp(system, "nixos") == 0)
-		return ascii_nixos;
-	if (strcmp(system, "opensuse") == 0)
-		return ascii_opensuse;
-	if (strcmp(system, "pop") == 0)
-		return ascii_pop_os;
 	if (strstr(system, "pop") != NULL)
 		return ascii_pop_os;
-	if (strcmp(system, "slackware") == 0)
-		return ascii_slackware;
-	if (strcmp(system, "solus") == 0)
-		return ascii_solus;
-	if (strcmp(system, "ubuntu") == 0)
-		return ascii_ubuntu;
-	if (strcmp(system, "void") == 0)
-		return ascii_void;
 
 	return ascii_linux;
 }