[wiki] [sites] [slstatus][patch][kanji] Overhauled kanji patch: || Madison Lynch
commit 7e738fc56ece1d36cecb46370535eca400b8d310
Author: Madison Lynch <madi_AT_mxdi.xyz>
Date: Fri Jun 14 13:08:19 2024 -0700
[slstatus][patch][kanji] Overhauled kanji patch:
Code is now far more legible and efficient. Patch file has also been updated
to follow standards.
diff --git a/tools.suckless.org/slstatus/patches/kanji/index.md b/tools.suckless.org/slstatus/patches/kanji/index.md
index bb2fd6fe..951f509b 100644
--- a/tools.suckless.org/slstatus/patches/kanji/index.md
+++ b/tools.suckless.org/slstatus/patches/kanji/index.md
_AT_@ -3,11 +3,12 @@ kanji
Description
-----------
-This patch implements functionality to display the Japanese Kanji character corresponding with the current day of the week.
+This patch implements a function that displays the Japanese Kanji for the
+current day of the week.
Download
--------
-* [slstatus-kanji.diff](slstatus-kanji.diff)
+* [slstatus-kanji-20240614-f68f492.diff](slstatus-kanji-20240614-f68f492.diff)
Author
------
diff --git a/tools.suckless.org/slstatus/patches/kanji/slstatus-kanji-20240614-f68f492.diff b/tools.suckless.org/slstatus/patches/kanji/slstatus-kanji-20240614-f68f492.diff
new file mode 100644
index 00000000..79eeb5db
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/kanji/slstatus-kanji-20240614-f68f492.diff
_AT_@ -0,0 +1,90 @@
+From 3baa458322f4cf9bd4c7257d1250db490a30e8d8 Mon Sep 17 00:00:00 2001
+From: Madison Lynch <madi_AT_mxdi.xyz>
+Date: Fri, 14 Jun 2024 13:00:02 -0700
+Subject: [PATCH] Overhauled kanji patch: cleaner code, faster execution
+
+---
+ Makefile | 1 +
+ components/kanji.c | 30 ++++++++++++++++++++++++++++++
+ config.def.h | 1 +
+ slstatus.h | 3 +++
+ 4 files changed, 35 insertions(+)
+ create mode 100644 components/kanji.c
+
+diff --git a/Makefile b/Makefile
+index 7a18274..305ab91 100644
+--- a/Makefile
++++ b/Makefile
+_AT_@ -14,6 +14,7 @@ COM =\
+ components/entropy\
+ components/hostname\
+ components/ip\
++ components/kanji\
+ components/kernel_release\
+ components/keyboard_indicators\
+ components/keymap\
+diff --git a/components/kanji.c b/components/kanji.c
+new file mode 100644
+index 0000000..2dbcd9a
+--- /dev/null
++++ b/components/kanji.c
+_AT_@ -0,0 +1,30 @@
++/* Written by Madison Lynch <madi_AT_mxdi.xyz> */
++#include <time.h>
++
++static const char *symbols[] = {
++ "日", // Sunday
++ "月", // Monday
++ "火", // Tuesday
++ "水", // Wednesday
++ "木", // Thursday
++ "金", // Friday
++ "土" // Saturday
++};
++
++/**
++* Returns the appropriate Japanese Kanji character correlating with the current
++* day of the week.
++*
++* _AT_param unused (NULL)
++* _AT_return the appropriate Kanji character (char)
++* _AT_author Madison Lynch
++*/
++const char *
++kanji(const char *unused) {
++ const time_t current_time = time(NULL);
++ const unsigned int weekday = localtime(
++ ¤t_time
++ )->tm_wday;
++
++ return (weekday < sizeof(symbols) / sizeof(char *)) ? symbols[weekday] : "?";
++}
+diff --git a/config.def.h b/config.def.h
+index d805331..099ed79 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -31,6 +31,7 @@ static const char unknown_str[] = "n/a";
+ * hostname hostname NULL
+ * ipv4 IPv4 address interface name (eth0)
+ * ipv6 IPv6 address interface name (eth0)
++ * kanji current day of week kanji NULL
+ * kernel_release `uname -r` NULL
+ * keyboard_indicators caps/num lock indicators format string (c?n?)
+ * see keyboard_indicators.c
+diff --git a/slstatus.h b/slstatus.h
+index 8ef5874..dc927eb 100644
+--- a/slstatus.h
++++ b/slstatus.h
+_AT_@ -31,6 +31,9 @@ const char *hostname(const char *unused);
+ const char *ipv4(const char *interface);
+ const char *ipv6(const char *interface);
+
++/* kanji */
++const char *kanji(const char *unused);
++
+ /* kernel_release */
+ const char *kernel_release(const char *unused);
+
+--
+2.45.2
+
diff --git a/tools.suckless.org/slstatus/patches/kanji/slstatus-kanji.diff b/tools.suckless.org/slstatus/patches/kanji/slstatus-kanji.diff
deleted file mode 100644
index f72cb8f9..00000000
--- a/tools.suckless.org/slstatus/patches/kanji/slstatus-kanji.diff
+++ /dev/null
_AT_@ -1,51 +0,0 @@
---- a/components/kanji.c
-+++ b/components/kanji.c
-_AT_@ -0,0 +1,14 @@
-+/* Written by Madison Lynch <madi_AT_mxdi.xyz> */
-+#include <time.h>
-+
-+const char *
-+kanji(const char *unused) {
-+ char *kanji[] = {"日", "月", "火", "水", "木", "金", "土"};
-+ time_t t=time(NULL);
-+ struct tm tm=*localtime(&t);
-+ int map[]={0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4},
-+ m=tm.tm_mon+1,
-+ y=tm.tm_year+1900-(m<3),
-+ wd=(y+y/4-y/100+y/400+map[m-1]+tm.tm_mday)%7;
-+ return kanji[wd];
-+}
-
---- a/config.def.h
-+++ b/config.def.h
-_AT_@ -31,6 +31,7 @@
- * hostname hostname NULL
- * ipv4 IPv4 address interface name (eth0)
- * ipv6 IPv6 address interface name (eth0)
-+ * kanji japanese day of week kanji NULL
- * kernel_release `uname -r` NULL
- * keyboard_indicators caps/num lock indicators format string (c?n?)
- * see keyboard_indicators.c
-
---- a/Makefile
-+++ b/Makefile
-_AT_@ -14,6 +14,7 @@
- components/entropy\
- components/hostname\
- components/ip\
-+ components/kanji\
- components/kernel_release\
- components/keyboard_indicators\
- components/keymap\
-
---- a/slstatus.h
-+++ b/slstatus.h
-_AT_@ -31,6 +31,9 @@
- const char *ipv4(const char *interface);
- const char *ipv6(const char *interface);
-
-+/* kanji */
-+const char *kanji(const char *unused);
-+
- /* kernel_release */
- const char *kernel_release(const char *unused);
Received on Fri Jun 14 2024 - 22:13:54 CEST
This archive was generated by hypermail 2.3.0
: Fri Jun 14 2024 - 22:24:50 CEST