sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 7e738fc56ece1d36cecb46370535eca400b8d310
parent fa2a28b10a4353ee7cbab547bb468383d73d3b45
Author: Madison Lynch <madi@mxdi.xyz>
Date:   Fri, 14 Jun 2024 13:08:19 -0700

[slstatus][patch][kanji] Overhauled kanji patch:

Code is now far more legible and efficient. Patch file has also been updated
to follow standards.

Diffstat:
Mtools.suckless.org/slstatus/patches/kanji/index.md | 5+++--
Atools.suckless.org/slstatus/patches/kanji/slstatus-kanji-20240614-f68f492.diff | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtools.suckless.org/slstatus/patches/kanji/slstatus-kanji.diff | 51---------------------------------------------------
3 files changed, 93 insertions(+), 53 deletions(-)

diff --git a/tools.suckless.org/slstatus/patches/kanji/index.md b/tools.suckless.org/slstatus/patches/kanji/index.md @@ -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 @@ -0,0 +1,90 @@ +From 3baa458322f4cf9bd4c7257d1250db490a30e8d8 Mon Sep 17 00:00:00 2001 +From: Madison Lynch <madi@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 +@@ -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 +@@ -0,0 +1,30 @@ ++/* Written by Madison Lynch <madi@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. ++* ++* @param unused (NULL) ++* @return the appropriate Kanji character (char) ++* @author Madison Lynch ++*/ ++const char * ++kanji(const char *unused) { ++ const time_t current_time = time(NULL); ++ const unsigned int weekday = localtime( ++ &current_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 +@@ -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 +@@ -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 @@ -1,51 +0,0 @@ ---- a/components/kanji.c -+++ b/components/kanji.c -@@ -0,0 +1,14 @@ -+/* Written by Madison Lynch <madi@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 -@@ -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 -@@ -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 -@@ -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);