slstatus-kanji-20240614-f68f492.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       slstatus-kanji-20240614-f68f492.diff (2700B)
       ---
            1 From 3baa458322f4cf9bd4c7257d1250db490a30e8d8 Mon Sep 17 00:00:00 2001
            2 From: Madison Lynch <madi@mxdi.xyz>
            3 Date: Fri, 14 Jun 2024 13:00:02 -0700
            4 Subject: [PATCH] Overhauled kanji patch: cleaner code, faster execution
            5 
            6 ---
            7  Makefile           |  1 +
            8  components/kanji.c | 30 ++++++++++++++++++++++++++++++
            9  config.def.h       |  1 +
           10  slstatus.h         |  3 +++
           11  4 files changed, 35 insertions(+)
           12  create mode 100644 components/kanji.c
           13 
           14 diff --git a/Makefile b/Makefile
           15 index 7a18274..305ab91 100644
           16 --- a/Makefile
           17 +++ b/Makefile
           18 @@ -14,6 +14,7 @@ COM =\
           19          components/entropy\
           20          components/hostname\
           21          components/ip\
           22 +        components/kanji\
           23          components/kernel_release\
           24          components/keyboard_indicators\
           25          components/keymap\
           26 diff --git a/components/kanji.c b/components/kanji.c
           27 new file mode 100644
           28 index 0000000..2dbcd9a
           29 --- /dev/null
           30 +++ b/components/kanji.c
           31 @@ -0,0 +1,30 @@
           32 +/* Written by Madison Lynch <madi@mxdi.xyz> */
           33 +#include <time.h>
           34 +
           35 +static const char *symbols[] = {
           36 +        "日", // Sunday
           37 +        "月", // Monday
           38 +        "火", // Tuesday
           39 +        "水", // Wednesday
           40 +        "木", // Thursday
           41 +        "金", // Friday
           42 +        "土"  // Saturday
           43 +};
           44 +
           45 +/**
           46 +* Returns the appropriate Japanese Kanji character correlating with the current
           47 +* day of the week.
           48 +*
           49 +* @param  unused (NULL)
           50 +* @return the appropriate Kanji character (char)
           51 +* @author Madison Lynch
           52 +*/
           53 +const char *
           54 +kanji(const char *unused) { 
           55 +    const time_t current_time = time(NULL);
           56 +    const unsigned int weekday = localtime(
           57 +        &current_time
           58 +    )->tm_wday;
           59 +
           60 +    return (weekday < sizeof(symbols) / sizeof(char *)) ? symbols[weekday] : "?";
           61 +}
           62 diff --git a/config.def.h b/config.def.h
           63 index d805331..099ed79 100644
           64 --- a/config.def.h
           65 +++ b/config.def.h
           66 @@ -31,6 +31,7 @@ static const char unknown_str[] = "n/a";
           67   * hostname            hostname                        NULL
           68   * ipv4                IPv4 address                    interface name (eth0)
           69   * ipv6                IPv6 address                    interface name (eth0)
           70 + * kanji               current day of week kanji       NULL
           71   * kernel_release      `uname -r`                      NULL
           72   * keyboard_indicators caps/num lock indicators        format string (c?n?)
           73   *                                                     see keyboard_indicators.c
           74 diff --git a/slstatus.h b/slstatus.h
           75 index 8ef5874..dc927eb 100644
           76 --- a/slstatus.h
           77 +++ b/slstatus.h
           78 @@ -31,6 +31,9 @@ const char *hostname(const char *unused);
           79  const char *ipv4(const char *interface);
           80  const char *ipv6(const char *interface);
           81  
           82 +/* kanji */
           83 +const char *kanji(const char *unused);
           84 +
           85  /* kernel_release */
           86  const char *kernel_release(const char *unused);
           87  
           88 -- 
           89 2.45.2
           90