From c35df8829e3b2651e05237b42233fc8986b22436 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wolfgang=20St=C3=B6ggl?= Date: Sun, 8 Sep 2019 15:19:09 +0200 Subject: [PATCH] Remove duplicate code of find_first_weekday() 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 | 51 ----------------------------------------------- src/rrd_rpncalc.c | 2 +- src/rrd_rpncalc.h | 3 +++ 3 files changed, 4 insertions(+), 52 deletions(-) diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 64adcb27..bf774292 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -45,7 +45,6 @@ #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include -#include /* for GetLocaleInfoEx */ #endif #include @@ -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( diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index 787d05fe..2b0653a2 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -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; diff --git a/src/rrd_rpncalc.h b/src/rrd_rpncalc.h index 96541f46..20c78b54 100644 --- a/src/rrd_rpncalc.h +++ b/src/rrd_rpncalc.h @@ -101,4 +101,7 @@ short rpn_calc( int output_idx, int step_width); +int find_first_weekday( + void); + #endif -- 2.47.2