]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Remove duplicate code of find_first_weekday()
authorWolfgang Stöggl <c72578@yahoo.de>
Sun, 8 Sep 2019 13:19:09 +0000 (15:19 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 10 Sep 2019 11:56:56 +0000 (13:56 +0200)
So far, the same code of find_first_weekday() was used in rrd_graph.c
and rrd_rpncalc.c
Remove duplicate code from rrd_graph.c and add find_first_weekday()
to rrd_rpncalc.h, which is included from rrd_graph.h

src/rrd_graph.c
src/rrd_rpncalc.c
src/rrd_rpncalc.h

index 64adcb275528752c428ced9e364d60f4b4307160..bf7742923624279370b668f659c9b9bb49722ff7 100644 (file)
@@ -45,7 +45,6 @@
 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 #include <io.h>
 #include <fcntl.h>
-#include <windows.h>    /* for GetLocaleInfoEx */
 #endif
 
 #include <time.h>
@@ -1540,56 +1539,6 @@ int data_proc(
     return 0;
 }
 
-static int find_first_weekday(
-    void)
-{
-    static int first_weekday = -1;
-
-    if (first_weekday == -1) {
-#ifdef HAVE__NL_TIME_WEEK_1STDAY
-        /* according to http://sourceware.org/ml/libc-locales/2009-q1/msg00011.html */
-        /* See correct way here http://pasky.or.cz/dev/glibc/first_weekday.c */
-        first_weekday = nl_langinfo(_NL_TIME_FIRST_WEEKDAY)[0];
-        int       week_1stday;
-        long      week_1stday_l = (long) nl_langinfo(_NL_TIME_WEEK_1STDAY);
-
-        if (week_1stday_l == 19971130
-#if SIZEOF_LONG_INT > 4
-            || week_1stday_l >> 32 == 19971130
-#endif
-            )
-            week_1stday = 0;    /* Sun */
-        else if (week_1stday_l == 19971201
-#if SIZEOF_LONG_INT > 4
-                 || week_1stday_l >> 32 == 19971201
-#endif
-            )
-            week_1stday = 1;    /* Mon */
-        else {
-            first_weekday = 1;
-            return first_weekday;   /* we go for a Monday default */
-        }
-        first_weekday = (week_1stday + first_weekday - 1) % 7;
-#elif defined(_WIN32) && defined(LOCALE_NAME_USER_DEFAULT)
-        DWORD     week_1stday;
-
-        GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
-                        LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
-                        (LPWSTR) & week_1stday,
-                        sizeof(week_1stday) / sizeof(WCHAR));
-        /* 0:Monday, ..., 6:Sunday. */
-        /* We need 1 for Monday, 0 for Sunday. */
-        first_weekday = (week_1stday + 1) % 7;
-#else
-        first_weekday = 0;
-#endif
-    }
-#ifdef DEBUG
-    printf("first_weekday = %d\n", first_weekday);
-#endif
-    return first_weekday;
-}
-
 /* identify the point where the first gridline, label ... gets placed */
 
 time_t find_first_time(
index 787d05fe17b4ec3d17d0402dd721bb40c20fb38c..2b0653a2c0780537de6f2dce38e6e4409ab615c0 100644 (file)
@@ -545,7 +545,7 @@ static int rpn_compare_double(
     return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
 }
 
-static int find_first_weekday(
+int find_first_weekday(
     void)
 {
     static int first_weekday = -1;
index 96541f461e236a086ad15c45c992e120c6f78a59..20c78b54ce2ef9300d7c13eb498b788608a7fa3c 100644 (file)
@@ -101,4 +101,7 @@ short     rpn_calc(
     int output_idx,
     int step_width);
 
+int       find_first_weekday(
+    void);
+
 #endif