2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbx_local.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-02-12 02:53:46 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_LOCAL_C
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_common_buffer.h"
|
|
|
|
#include "gb_common_case.h"
|
|
|
|
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbx_value.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
#include <langinfo.h>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <libintl.h>
|
|
|
|
|
|
|
|
#include "gbx_math.h"
|
|
|
|
#include "gbx_date.h"
|
|
|
|
#include "gbx_string.h"
|
2015-07-12 00:44:09 +02:00
|
|
|
#include "gbx_c_string.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_api.h"
|
|
|
|
#include "gb_file.h"
|
|
|
|
#include "gbx_component.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_archive.h"
|
|
|
|
|
|
|
|
#include "gbx_local.h"
|
|
|
|
|
|
|
|
//#define DEBUG_LANG
|
|
|
|
|
|
|
|
#define buffer_init COMMON_buffer_init
|
|
|
|
#define look_char COMMON_look_char
|
|
|
|
#define put_char COMMON_put_char
|
|
|
|
#define get_current COMMON_get_current
|
|
|
|
#define buffer_pos COMMON_pos
|
|
|
|
#define get_size_left COMMON_get_size_left
|
|
|
|
|
2018-06-12 16:30:11 +02:00
|
|
|
static void add_string(const char *src, int len, int *before);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
/* System encoding*/
|
2008-01-17 22:39:26 +01:00
|
|
|
char *LOCAL_encoding = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/* If system encoding is UTF-8 */
|
2008-01-17 22:39:26 +01:00
|
|
|
bool LOCAL_is_UTF8;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/* Default 'C' localization */
|
2008-01-17 22:39:26 +01:00
|
|
|
LOCAL_INFO LOCAL_default = {
|
2010-08-28 14:33:05 +02:00
|
|
|
'.', '.',
|
2018-06-12 16:30:11 +02:00
|
|
|
NULL, 0, NULL, 0,
|
2010-08-28 14:33:05 +02:00
|
|
|
3, 3,
|
|
|
|
0,
|
2015-07-12 00:44:09 +02:00
|
|
|
'/', ':',
|
2010-08-28 14:33:05 +02:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
{ LO_MONTH, LO_DAY, LO_YEAR },
|
|
|
|
{ LO_HOUR, LO_MINUTE, LO_SECOND },
|
|
|
|
"dddd mmmm d yyyy",
|
2012-05-19 14:15:51 +02:00
|
|
|
"mmm d yyyy",
|
|
|
|
"mm/dd/yyyy",
|
2010-08-28 14:33:05 +02:00
|
|
|
"hh:nn:ss",
|
|
|
|
"hh:nn AM/PM",
|
|
|
|
"hh:nn",
|
2010-11-28 00:00:08 +01:00
|
|
|
"mm/dd/yyyy hh:nn:ss",
|
2010-08-28 14:33:05 +02:00
|
|
|
"(#,##0.##)",
|
2010-11-28 00:00:08 +01:00
|
|
|
"(#,##0.##)",
|
|
|
|
"True", 4,
|
|
|
|
"False", 5,
|
|
|
|
0
|
2010-08-28 14:33:05 +02:00
|
|
|
};
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/* User language localization */
|
2010-11-28 00:00:08 +01:00
|
|
|
LOCAL_INFO LOCAL_local = { 0 };
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
// First day of weekday
|
|
|
|
char LOCAL_first_day_of_week = -1;
|
|
|
|
|
2018-11-06 18:11:51 +01:00
|
|
|
static char *_rtl_lang[] = { "ar", "fa", "he", NULL };
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static bool _translation_loaded = FALSE;
|
|
|
|
|
|
|
|
static LOCAL_INFO *local_current;
|
|
|
|
|
2019-02-26 20:59:03 +01:00
|
|
|
static char env_LC_ALL[MAX_LANG + sizeof "LC_ALL" + 1];
|
|
|
|
static char env_LANGUAGE[MAX_LANG + sizeof "LANGUAGE" + 1];
|
|
|
|
static char env_LANG[MAX_LANG + sizeof "LANG" + 1];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static bool _currency;
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
static char *_lang = NULL;
|
|
|
|
|
2019-01-11 15:23:50 +01:00
|
|
|
extern char **environ;
|
|
|
|
static char **_environ;
|
|
|
|
|
2012-06-29 01:38:26 +02:00
|
|
|
#define add_currency_flag(_flag) (LOCAL_local.currency_flag <<= 1, LOCAL_local.currency_flag |= (!!(_flag)))
|
|
|
|
#define test_currency_flag(_negative, _space, _before, _intl) (!!(LOCAL_local.currency_flag & (1 << ((!!_negative) + ((!!_before) << 1) + ((!!_intl) << 2)))))
|
2008-11-24 15:11:01 +01:00
|
|
|
|
|
|
|
static void init_currency_flag(struct lconv *info)
|
|
|
|
{
|
2018-09-09 18:26:38 +02:00
|
|
|
#ifndef OS_BSD
|
2010-08-28 14:33:05 +02:00
|
|
|
add_currency_flag(info->int_n_cs_precedes); // 7
|
|
|
|
add_currency_flag(info->int_p_cs_precedes); // 6
|
2012-06-29 01:38:26 +02:00
|
|
|
#else
|
|
|
|
add_currency_flag(info->n_cs_precedes); // 7
|
|
|
|
add_currency_flag(info->p_cs_precedes); // 6
|
2018-09-09 18:26:38 +02:00
|
|
|
#endif
|
2012-06-29 01:38:26 +02:00
|
|
|
add_currency_flag(1); // 5
|
|
|
|
add_currency_flag(1); // 4
|
2010-08-28 14:33:05 +02:00
|
|
|
add_currency_flag(info->n_cs_precedes); // 3
|
|
|
|
add_currency_flag(info->p_cs_precedes); // 2
|
|
|
|
add_currency_flag(info->n_sep_by_space); // 1
|
|
|
|
add_currency_flag(info->p_sep_by_space); // 0
|
2008-11-24 15:11:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_currency_before(bool negative, bool intl)
|
|
|
|
{
|
2012-06-29 01:38:26 +02:00
|
|
|
return test_currency_flag(negative, FALSE, TRUE, intl);
|
2008-11-24 15:11:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_currency_space(bool negative, bool intl)
|
|
|
|
{
|
2012-06-29 01:38:26 +02:00
|
|
|
//fprintf(stderr, "%02X & %02X\n", LOCAL_local.currency_flag, (1 << ((!!negative) + ((!!0) << 1) + ((!!intl) << 2))));
|
|
|
|
return test_currency_flag(negative, TRUE, FALSE, intl);
|
2008-11-24 15:11:01 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 20:59:03 +01:00
|
|
|
static void my_setenv(const char *name, const char *value, char *ptr)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2019-02-26 20:59:03 +01:00
|
|
|
snprintf(ptr, MAX_LANG + strlen(name) + 1, "%s=%s", name, value);
|
|
|
|
putenv(ptr);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void begin(void)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
buffer_init(COMMON_buffer, COMMON_BUF_MAX - 4);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void end(char **str, int *len)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
*(get_current()) = 0;
|
|
|
|
*str = COMMON_buffer;
|
|
|
|
*len = buffer_pos;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void stradd_sep(char *dst, const char *src, const char *sep)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
if (*dst)
|
|
|
|
strcat(dst, sep);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-04-25 20:47:49 +02:00
|
|
|
strcat(dst, src);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_thousand_sep(int *before)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
int group;
|
2018-06-12 16:30:11 +02:00
|
|
|
const char *thsep;
|
|
|
|
int lthsep;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (before == NULL)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-06-12 16:30:11 +02:00
|
|
|
thsep = _currency ? local_current->thousand_sep : local_current->currency_thousand_sep;
|
|
|
|
lthsep = _currency ? local_current->len_thousand_sep : local_current->len_currency_thousand_sep;
|
|
|
|
|
|
|
|
if (thsep && thsep)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
|
|
|
group = _currency ? local_current->currency_group_size : local_current->group_size;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (group > 0 && (*before > 1) && ((*before - 1) == (((*before - 1) / group) * group)))
|
2009-11-15 14:53:37 +01:00
|
|
|
{
|
|
|
|
if (buffer_pos > 0 && (get_current()[-1] == ' '))
|
|
|
|
put_char(' ');
|
|
|
|
else
|
2018-06-12 16:30:11 +02:00
|
|
|
add_string(thsep, lthsep, NULL);
|
2009-11-15 14:53:37 +01:00
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
(*before)--;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_string(const char *src, int len, int *before)
|
|
|
|
{
|
2018-06-12 16:30:11 +02:00
|
|
|
if (len <= 0)
|
2010-08-28 14:33:05 +02:00
|
|
|
len = strlen(src);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
put_char(*src++);
|
|
|
|
len--;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (before)
|
|
|
|
add_thousand_sep(before);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2015-07-12 00:44:09 +02:00
|
|
|
static void add_unicode(uint unicode)
|
|
|
|
{
|
|
|
|
char str[8];
|
|
|
|
STRING_utf8_from_unicode(unicode, str);
|
|
|
|
add_string(str, STRING_utf8_get_char_length(*str), NULL);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void add_currency(const char *sym)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
const char *p = sym;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
c = *p++;
|
|
|
|
if (c == 0)
|
|
|
|
return;
|
|
|
|
if (c != ' ')
|
|
|
|
put_char(c);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-11 15:41:08 +01:00
|
|
|
static void add_char(char c, int count, int *before)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
put_char(c);
|
|
|
|
count--;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
add_thousand_sep(before);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-11-11 15:41:08 +01:00
|
|
|
static void add_zero(int count, int *before)
|
|
|
|
{
|
|
|
|
add_char('0', count, before);
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static void add_sign(char mode, int sign, bool after)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
if (after && mode != '(')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sign < 0)
|
|
|
|
{
|
|
|
|
if (mode == '(')
|
|
|
|
put_char(after ? ')' : '(');
|
|
|
|
else
|
|
|
|
put_char('-');
|
|
|
|
}
|
|
|
|
else if (mode != 0 && mode != '(')
|
|
|
|
{
|
|
|
|
if (sign > 0)
|
|
|
|
put_char(mode);
|
|
|
|
else
|
|
|
|
put_char(' ');
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *get_languages(void)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
char *lang;
|
|
|
|
char *lang_list = NULL;
|
|
|
|
char *src;
|
2019-06-22 01:20:38 +02:00
|
|
|
char *p;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
lang = STRING_new_temp_zero(LOCAL_get_lang());
|
2019-06-22 01:20:38 +02:00
|
|
|
p = index(lang, '.');
|
|
|
|
if (p) *p = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-09-07 14:38:29 +02:00
|
|
|
lang_list = STRING_add(lang_list, lang, 0);
|
|
|
|
lang_list = STRING_add_char(lang_list, ':');
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
src = index(lang, '_');
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
*src = 0;
|
2011-09-07 14:38:29 +02:00
|
|
|
lang_list = STRING_add(lang_list, lang, 0);
|
|
|
|
lang_list = STRING_add_char(lang_list, ':');
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
lang_list = STRING_add(lang_list, lang, 0);
|
|
|
|
lang_list = STRING_add(lang_list, "_*", 2);
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "Languages = %s\n", lang_list);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
return lang_list;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void free_local_info(void)
|
|
|
|
{
|
2010-11-28 00:00:08 +01:00
|
|
|
STRING_free(&LOCAL_local.true_str);
|
|
|
|
STRING_free(&LOCAL_local.false_str);
|
2010-08-28 14:33:05 +02:00
|
|
|
CLEAR(&LOCAL_local);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 16:30:11 +02:00
|
|
|
static const char *fix_separator(const char *str)
|
2015-09-17 00:51:31 +02:00
|
|
|
{
|
2018-06-12 16:30:11 +02:00
|
|
|
if (!str || !*str)
|
|
|
|
return " ";
|
|
|
|
|
2015-09-17 00:51:31 +02:00
|
|
|
if ((uchar)str[0] == 0xC2 && (uchar)str[1] == 0xA0 && str[2] == 0)
|
2018-06-12 16:30:11 +02:00
|
|
|
return " ";
|
|
|
|
|
|
|
|
if ((uchar)str[0] == 0xE2 && (uchar)str[1] == 0x80 && (uchar)str[2] == 0xAF && str[3] == 0)
|
|
|
|
return " ";
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2018-08-09 15:47:29 +02:00
|
|
|
return str[1] ? "_" : str;
|
2015-09-17 00:51:31 +02:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void fill_local_info(void)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
struct lconv *info;
|
|
|
|
char *p;
|
|
|
|
char c;
|
|
|
|
char *dp;
|
|
|
|
char *tp;
|
|
|
|
char *codeset;
|
|
|
|
const char *lang;
|
2012-04-25 20:47:49 +02:00
|
|
|
char *am_pm;
|
2015-08-27 19:18:59 +02:00
|
|
|
bool got_second;
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
free_local_info();
|
|
|
|
|
|
|
|
/* local encoding */
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2011-09-26 03:46:48 +02:00
|
|
|
if (!LOCAL_is_UTF8)
|
|
|
|
STRING_free(&LOCAL_encoding);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
codeset = nl_langinfo(CODESET);
|
|
|
|
if (!codeset || !*codeset)
|
|
|
|
codeset = "US-ASCII";
|
|
|
|
|
2011-09-26 03:46:48 +02:00
|
|
|
LOCAL_is_UTF8 = (strcasecmp(codeset, "UTF-8") == 0);
|
|
|
|
if (LOCAL_is_UTF8)
|
|
|
|
LOCAL_encoding = SC_UTF8;
|
|
|
|
else
|
|
|
|
LOCAL_encoding = STRING_new_zero(codeset);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_LANG
|
2013-12-13 23:13:48 +01:00
|
|
|
fprintf(stderr, "LOCAL_encoding = %s\n", LOCAL_encoding == SC_UTF8 ? "UTF-8" : LOCAL_encoding);
|
2010-08-28 14:33:05 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Numeric information */
|
|
|
|
|
|
|
|
info = localeconv();
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
//fprintf(stderr, "'%s' '%s' %d %d\n", info->thousands_sep, info->mon_thousands_sep, *info->thousands_sep, *info->grouping);
|
|
|
|
//fprintf(stderr, "'%s' '%s'\n", nl_langinfo(THOUSANDS_SEP), nl_langinfo(MON_THOUSANDS_SEP));
|
|
|
|
|
|
|
|
LOCAL_local.decimal_point = *(info->decimal_point);
|
2015-09-17 00:51:31 +02:00
|
|
|
LOCAL_local.thousand_sep = fix_separator(info->thousands_sep);
|
2018-06-12 16:30:11 +02:00
|
|
|
LOCAL_local.len_thousand_sep = strlen(LOCAL_local.thousand_sep);
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
LOCAL_local.group_size = *(info->grouping);
|
|
|
|
if (LOCAL_local.group_size == 0)
|
|
|
|
LOCAL_local.group_size = 3;
|
|
|
|
|
|
|
|
/*LOCAL_local.currency_symbol = STRING_conv_to_UTF8(info->currency_symbol, 0);
|
|
|
|
STRING_ref(LOCAL_local.currency_symbol);
|
|
|
|
LOCAL_local.intl_currency_symbol = STRING_conv_to_UTF8(info->int_curr_symbol, 0);
|
|
|
|
STRING_ref(LOCAL_local.intl_currency_symbol);*/
|
|
|
|
|
2013-03-18 23:24:18 +01:00
|
|
|
// Date format
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
p = nl_langinfo(D_FMT);
|
|
|
|
//fprintf(stderr, "date format: %s\n", p);
|
2010-08-28 14:33:05 +02:00
|
|
|
dp = LOCAL_local.date_order;
|
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
if (strcmp(p, "%D") == 0)
|
|
|
|
p = "%m/%d/%y";
|
|
|
|
else if (strcmp(p, "%F") == 0)
|
|
|
|
p = "%Y-%m-%d";
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
for (;;)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
|
|
|
c = *p++;
|
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
if (c == '%')
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2015-08-27 19:18:59 +02:00
|
|
|
c = *p++;
|
|
|
|
if (c != '%')
|
|
|
|
{
|
|
|
|
if (c == 'E' || c == 'O')
|
|
|
|
c = *p++;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
switch (c)
|
2013-03-18 23:24:18 +01:00
|
|
|
{
|
2015-08-27 19:18:59 +02:00
|
|
|
case 'y': case 'Y':
|
|
|
|
*dp++ = LO_YEAR;
|
|
|
|
stradd_sep(LOCAL_local.long_date, "yyyy", " ");
|
|
|
|
stradd_sep(LOCAL_local.medium_date, "yyyy", " ");
|
|
|
|
stradd_sep(LOCAL_local.short_date, "yyyy", "/");
|
|
|
|
stradd_sep(LOCAL_local.general_date, "yyyy", "/");
|
|
|
|
break;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
case 'b': case 'B': case 'h': case 'm':
|
|
|
|
*dp++ = LO_MONTH;
|
|
|
|
stradd_sep(LOCAL_local.long_date, "mmmm", " ");
|
|
|
|
stradd_sep(LOCAL_local.medium_date, "mmm", " ");
|
|
|
|
stradd_sep(LOCAL_local.short_date, "mm", "/");
|
|
|
|
stradd_sep(LOCAL_local.general_date, "mm", "/");
|
|
|
|
break;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
case 'd': case 'e':
|
|
|
|
*dp++ = LO_DAY;
|
|
|
|
stradd_sep(LOCAL_local.long_date, "dddd d", " ");
|
|
|
|
stradd_sep(LOCAL_local.medium_date, "dd", " ");
|
|
|
|
stradd_sep(LOCAL_local.short_date, "dd", "/");
|
|
|
|
stradd_sep(LOCAL_local.general_date, "dd", "/");
|
|
|
|
break;
|
2013-03-18 23:24:18 +01:00
|
|
|
}
|
2015-08-27 19:18:59 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-18 23:24:18 +01:00
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
if (dp != LOCAL_local.date_order && LOCAL_local.date_sep == 0)
|
|
|
|
LOCAL_local.date_sep = STRING_utf8_to_unicode(p - 1, STRING_utf8_get_char_length(c));
|
2013-03-18 23:24:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Time format
|
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
p = nl_langinfo(T_FMT);
|
|
|
|
//fprintf(stderr, "time format: %s\n", p);
|
2013-03-18 23:24:18 +01:00
|
|
|
tp = LOCAL_local.time_order;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
if (strcmp(p, "%T") == 0 || strcmp(p, "%R") == 0 || strcmp(p, "%r") == 0)
|
|
|
|
p = "%H:%M:%S";
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
got_second = FALSE;
|
2013-03-18 23:24:18 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
for (;;)
|
2013-03-18 23:24:18 +01:00
|
|
|
{
|
|
|
|
c = *p++;
|
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
if (c == '%')
|
2013-03-18 23:24:18 +01:00
|
|
|
{
|
2015-08-27 19:18:59 +02:00
|
|
|
c = *p++;
|
|
|
|
if (c != '%')
|
|
|
|
{
|
|
|
|
if (c == 'E' || c == 'O')
|
|
|
|
c = *p++;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
switch(c)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2015-08-27 19:18:59 +02:00
|
|
|
case 'H': case 'I': case 'k': case 'l':
|
|
|
|
*tp++ = LO_HOUR;
|
|
|
|
stradd_sep(LOCAL_local.long_time, "hh", ":");
|
|
|
|
stradd_sep(LOCAL_local.medium_time, "hh", ":");
|
|
|
|
stradd_sep(LOCAL_local.short_time, "hh", ":");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
*tp++ = LO_MINUTE;
|
|
|
|
stradd_sep(LOCAL_local.long_time, "nn", ":");
|
|
|
|
stradd_sep(LOCAL_local.medium_time, "nn", ":");
|
|
|
|
stradd_sep(LOCAL_local.short_time, "nn", ":");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
*tp++ = LO_SECOND;
|
|
|
|
stradd_sep(LOCAL_local.long_time, "ss", ":");
|
|
|
|
got_second = TRUE;
|
|
|
|
break;
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2015-08-27 19:18:59 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2015-08-27 19:18:59 +02:00
|
|
|
|
|
|
|
if (tp != LOCAL_local.time_order && LOCAL_local.time_sep == 0)
|
|
|
|
LOCAL_local.time_sep = STRING_utf8_to_unicode(p - 1, STRING_utf8_get_char_length(c));
|
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
// Fix missing seconds
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2015-08-27 19:18:59 +02:00
|
|
|
if (!got_second)
|
|
|
|
{
|
|
|
|
*tp++ = LO_SECOND;
|
|
|
|
stradd_sep(LOCAL_local.long_time, "ss", ":");
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-18 23:24:18 +01:00
|
|
|
// Fix the french date separator
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
lang = LOCAL_get_lang();
|
|
|
|
if (strcmp(lang, "fr") == 0 || strncmp(lang, "fr_", 3) == 0)
|
|
|
|
LOCAL_local.date_sep = '/';
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
stradd_sep(LOCAL_local.general_date, LOCAL_local.long_time, " ");
|
2012-04-25 20:47:49 +02:00
|
|
|
am_pm = nl_langinfo(AM_STR);
|
|
|
|
if (am_pm && *am_pm)
|
|
|
|
{
|
|
|
|
am_pm = nl_langinfo(PM_STR);
|
|
|
|
if (am_pm && *am_pm)
|
|
|
|
{
|
|
|
|
stradd_sep(LOCAL_local.medium_time, "AM/PM", " ");
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-18 23:24:18 +01:00
|
|
|
// Currency format
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-09-17 00:51:31 +02:00
|
|
|
LOCAL_local.currency_thousand_sep = fix_separator(info->mon_thousands_sep);
|
2018-06-12 16:30:11 +02:00
|
|
|
LOCAL_local.len_currency_thousand_sep = strlen(LOCAL_local.currency_thousand_sep);
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
LOCAL_local.currency_group_size = *(info->mon_grouping);
|
|
|
|
if (LOCAL_local.currency_group_size == 0)
|
|
|
|
LOCAL_local.currency_group_size = 3;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
LOCAL_local.currency_decimal_point = *(info->mon_decimal_point);
|
|
|
|
LOCAL_local.currency_symbol = info->currency_symbol;
|
|
|
|
LOCAL_local.intl_currency_symbol = info->int_curr_symbol;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-10-29 09:20:41 +01:00
|
|
|
strcpy(LOCAL_local.general_currency, "($,0.");
|
2011-09-23 22:17:57 +02:00
|
|
|
strncat(LOCAL_local.general_currency, "########", Min(8, info->frac_digits));
|
|
|
|
strcat(LOCAL_local.general_currency, ")");
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2019-10-29 09:20:41 +01:00
|
|
|
strcpy(LOCAL_local.intl_currency, "($$,0.");
|
2011-09-23 22:17:57 +02:00
|
|
|
strncat(LOCAL_local.intl_currency, "########", Min(8, info->int_frac_digits));
|
|
|
|
strcat(LOCAL_local.intl_currency, ")");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-11-24 15:11:01 +01:00
|
|
|
init_currency_flag(info);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-11-28 00:00:08 +01:00
|
|
|
LOCAL_local.true_str = STRING_new_zero(LOCAL_gettext(LOCAL_default.true_str));
|
|
|
|
LOCAL_local.len_true_str = STRING_length(LOCAL_local.true_str);
|
|
|
|
LOCAL_local.false_str = STRING_new_zero(LOCAL_gettext(LOCAL_default.false_str));
|
|
|
|
LOCAL_local.len_false_str = STRING_length(LOCAL_local.false_str);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void LOCAL_init(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2019-01-11 15:23:50 +01:00
|
|
|
_environ = environ;
|
2010-08-28 14:33:05 +02:00
|
|
|
LOCAL_set_lang(NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void LOCAL_exit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2019-02-26 20:59:03 +01:00
|
|
|
if (environ == _environ)
|
2018-12-24 17:57:36 +01:00
|
|
|
{
|
2019-02-26 20:59:03 +01:00
|
|
|
unsetenv("LANG");
|
|
|
|
unsetenv("LC_ALL");
|
|
|
|
unsetenv("LANGUAGE");
|
2018-12-24 17:57:36 +01:00
|
|
|
}
|
|
|
|
|
2011-09-26 03:46:48 +02:00
|
|
|
if (!LOCAL_is_UTF8)
|
|
|
|
STRING_free(&LOCAL_encoding);
|
2018-12-24 17:57:36 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
STRING_free(&_lang);
|
|
|
|
free_local_info();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *LOCAL_get_lang(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
char *lang;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
if (!_lang)
|
|
|
|
{
|
|
|
|
lang = getenv("LC_ALL");
|
|
|
|
if (!lang)
|
|
|
|
lang = getenv("LANG");
|
|
|
|
if (!lang || !*lang)
|
|
|
|
lang = "en_US";
|
2010-06-05 01:48:53 +02:00
|
|
|
_lang = STRING_new_zero(lang);
|
2008-03-19 15:32:30 +01:00
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
return _lang;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void LOCAL_set_lang(const char *lang)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
char **l;
|
|
|
|
int rtl;
|
|
|
|
char *var;
|
|
|
|
|
2019-02-26 20:59:03 +01:00
|
|
|
if (lang && (strlen(lang) > MAX_LANG))
|
|
|
|
THROW(E_ARG);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#ifdef DEBUG_LANG
|
2016-10-02 00:32:42 +02:00
|
|
|
fprintf(stderr, "******** LOCAL_set_lang: %s ********\n", lang);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (lang && *lang)
|
|
|
|
{
|
2019-02-26 20:59:03 +01:00
|
|
|
my_setenv("LANG", lang, env_LANG);
|
|
|
|
my_setenv("LC_ALL", lang, env_LC_ALL);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2018-11-06 18:11:51 +01:00
|
|
|
|
|
|
|
STRING_free(&_lang);
|
|
|
|
lang = LOCAL_get_lang();
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2018-11-06 18:11:51 +01:00
|
|
|
if (getenv("LANGUAGE"))
|
2019-02-26 20:59:03 +01:00
|
|
|
my_setenv("LANGUAGE", lang, env_LANGUAGE);
|
2019-06-22 01:20:38 +02:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (setlocale(LC_ALL, ""))
|
|
|
|
{
|
|
|
|
_translation_loaded = FALSE;
|
|
|
|
COMPONENT_translation_must_be_reloaded();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-22 01:20:38 +02:00
|
|
|
char *err = strerror(errno);
|
2013-12-13 23:13:48 +01:00
|
|
|
ERROR_warning("cannot switch to language '%s': %s. Did you install the corresponding locale packages?", lang ? lang : LOCAL_get_lang(), err);
|
2010-08-28 14:33:05 +02:00
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-04-10 13:07:38 +02:00
|
|
|
DATE_init_local();
|
2010-08-28 14:33:05 +02:00
|
|
|
fill_local_info();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
/* If language is right to left written */
|
|
|
|
|
|
|
|
rtl = FALSE;
|
2010-08-28 14:33:05 +02:00
|
|
|
for (l = _rtl_lang; *l; l++)
|
|
|
|
{
|
|
|
|
if (strncmp(*l, lang, 2) == 0)
|
|
|
|
{
|
|
|
|
rtl = TRUE;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
var = getenv("GB_REVERSE");
|
2013-12-09 20:42:30 +01:00
|
|
|
if (var && !(var[0] == '0' && var[1] == 0))
|
2010-08-28 14:33:05 +02:00
|
|
|
rtl = !rtl;
|
|
|
|
|
|
|
|
HOOK(lang)(lang, rtl);
|
|
|
|
LOCAL_local.rtl = rtl;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
|
|
|
|
static int int_to_string(uint64_t nbr, char **addr)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
static char buf[32];
|
|
|
|
char *ptr;
|
|
|
|
int digit, len;
|
|
|
|
bool neg;
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
len = 0;
|
|
|
|
ptr = &buf[sizeof(buf)];
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
if (nbr == 0)
|
|
|
|
{
|
|
|
|
ptr -= 2;
|
|
|
|
*addr = ptr;
|
|
|
|
ptr[0] = '0';
|
|
|
|
ptr[1] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
neg = (nbr & (1LL << 63)) != 0;
|
|
|
|
|
|
|
|
if (neg)
|
|
|
|
nbr = 1 + ~nbr;
|
|
|
|
|
|
|
|
while (nbr > 0)
|
|
|
|
{
|
|
|
|
digit = nbr % 10;
|
|
|
|
nbr /= 10;
|
|
|
|
|
|
|
|
ptr--;
|
|
|
|
len++;
|
|
|
|
|
|
|
|
*ptr = '0' + digit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (neg)
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
ptr--;
|
|
|
|
*ptr = '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
*addr = ptr;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LOCAL_format_number(double number, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str, bool local)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char c;
|
|
|
|
int n;
|
|
|
|
char *buf_addr;
|
2010-08-28 14:33:05 +02:00
|
|
|
int pos;
|
|
|
|
int thousand;
|
|
|
|
int *thousand_ptr;
|
|
|
|
char sign;
|
|
|
|
bool comma;
|
|
|
|
bool point;
|
|
|
|
int before, before_zero;
|
|
|
|
int after, after_zero;
|
2019-10-29 09:20:41 +01:00
|
|
|
char exponent;
|
2010-08-28 14:33:05 +02:00
|
|
|
int exp_zero;
|
2019-10-29 09:20:41 +01:00
|
|
|
bool exp_sign;
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
int number_sign;
|
2010-06-02 23:12:23 +02:00
|
|
|
uint64_t mantisse;
|
2011-04-08 01:24:11 +02:00
|
|
|
uint64_t power;
|
2010-08-28 14:33:05 +02:00
|
|
|
double number_mant;
|
|
|
|
int number_exp;
|
|
|
|
int number_real_exp;
|
|
|
|
int ndigit;
|
|
|
|
int pos_first_digit;
|
|
|
|
|
|
|
|
bool intl_currency;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (local)
|
|
|
|
local_current = &LOCAL_local;
|
|
|
|
else
|
|
|
|
local_current = &LOCAL_default;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
switch(fmt_type)
|
|
|
|
{
|
|
|
|
case LF_USER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_STANDARD:
|
|
|
|
case LF_GENERAL_NUMBER:
|
|
|
|
if ((number != 0.0) && ((fabs(number) < 1E-4) || (fabs(number) >= 1E10)))
|
2019-01-16 04:32:44 +01:00
|
|
|
fmt = "0.###############E+#";
|
2010-08-28 14:33:05 +02:00
|
|
|
else
|
2019-01-16 04:32:44 +01:00
|
|
|
fmt = "0.###############";
|
2010-08-28 14:33:05 +02:00
|
|
|
break;
|
|
|
|
|
2010-12-30 04:17:37 +01:00
|
|
|
case LF_SHORT_NUMBER:
|
|
|
|
if ((number != 0.0) && ((fabs(number) < 1E-4) || (fabs(number) >= 1E10)))
|
|
|
|
fmt = "0.#######E+#";
|
|
|
|
else
|
|
|
|
fmt = "0.#######";
|
|
|
|
break;
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case LF_FIXED:
|
|
|
|
fmt = "0.00";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_PERCENT:
|
|
|
|
fmt = "###%";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_SCIENTIFIC:
|
2019-05-09 00:04:18 +02:00
|
|
|
fmt = "0.################E+0";
|
2010-08-28 14:33:05 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_CURRENCY:
|
|
|
|
fmt = local_current->general_currency;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_INTERNATIONAL:
|
|
|
|
fmt = local_current->intl_currency;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len_fmt == 0)
|
|
|
|
len_fmt = strlen(fmt);
|
|
|
|
|
|
|
|
if (len_fmt >= COMMON_BUF_MAX)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
sign = 0;
|
|
|
|
comma = FALSE;
|
|
|
|
before = 0;
|
|
|
|
before_zero = 0;
|
|
|
|
point = FALSE;
|
|
|
|
after = 0;
|
|
|
|
after_zero = 0;
|
2019-10-29 09:20:41 +01:00
|
|
|
exponent = 0;
|
|
|
|
exp_sign = FALSE;
|
2010-08-28 14:33:05 +02:00
|
|
|
exp_zero = 0;
|
|
|
|
_currency = FALSE;
|
|
|
|
intl_currency = FALSE;
|
|
|
|
|
|
|
|
begin();
|
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
// Search for the first formatting character
|
|
|
|
|
|
|
|
for (i = 0; i < len_fmt; i++)
|
|
|
|
{
|
|
|
|
c = fmt[i];
|
|
|
|
if (c == '\\')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '-' || c == '+' || c == '#' || c == '0' || c == '.' || c == ',' || c == '(' || c == '$')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= len_fmt)
|
2010-08-28 14:33:05 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
pos = i;
|
2010-08-28 14:33:05 +02:00
|
|
|
if (pos > 0)
|
|
|
|
add_string(fmt, pos, NULL);
|
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
// Search if there is a percent format character
|
|
|
|
|
|
|
|
for (i = pos; i < len_fmt; i++)
|
|
|
|
{
|
|
|
|
c = fmt[i];
|
|
|
|
if (c == '\\')
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '%')
|
|
|
|
{
|
|
|
|
number *= 100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* specify the sign */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
if (fmt[pos] == '-')
|
|
|
|
{
|
|
|
|
sign = ' ';
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
else if (fmt[pos] == '+')
|
|
|
|
{
|
|
|
|
sign = '+';
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
else if (fmt[pos] == '(')
|
|
|
|
{
|
|
|
|
sign = '(';
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
return TRUE;
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* currency */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
if (fmt[pos] == '$')
|
|
|
|
{
|
|
|
|
_currency = TRUE;
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
if (fmt[pos] == '$')
|
|
|
|
{
|
|
|
|
intl_currency = TRUE;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* decimal digits */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
for(; pos < len_fmt; pos++)
|
|
|
|
{
|
|
|
|
c = fmt[pos];
|
|
|
|
|
|
|
|
if (c == ',')
|
|
|
|
{
|
|
|
|
comma = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '#' || c == '0')
|
|
|
|
{
|
|
|
|
before++;
|
|
|
|
if (c == '0' || before_zero > 0)
|
|
|
|
before_zero++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
goto _FORMAT;
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* the point */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
if (fmt[pos] != '.')
|
|
|
|
goto _FORMAT;
|
|
|
|
|
|
|
|
pos++;
|
|
|
|
point = TRUE;
|
|
|
|
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
goto _FORMAT;
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* digits after point */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
for(; pos < len_fmt; pos++)
|
|
|
|
{
|
|
|
|
c = fmt[pos];
|
|
|
|
|
|
|
|
if (c == '#' || c == '0')
|
|
|
|
{
|
|
|
|
after++;
|
|
|
|
if (c == '0')
|
|
|
|
after_zero = after;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
goto _FORMAT;
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* exponent */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
if (fmt[pos] == 'e' || fmt[pos] == 'E')
|
|
|
|
{
|
2019-10-29 09:20:41 +01:00
|
|
|
exponent = fmt[pos];
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
pos++;
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-10-29 09:20:41 +01:00
|
|
|
if (fmt[pos] == '-' || fmt[pos] == '+')
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2019-10-29 09:20:41 +01:00
|
|
|
exp_sign = TRUE;
|
2010-08-28 14:33:05 +02:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for(; pos < len_fmt; pos++)
|
|
|
|
{
|
|
|
|
c = fmt[pos];
|
|
|
|
|
|
|
|
if (c == '#' || c == '0')
|
|
|
|
{
|
|
|
|
if (c == '0' || exp_zero > 0)
|
|
|
|
exp_zero++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
_FORMAT:
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (before == 0 && after == 0)
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* sign */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
number_sign = fsgn(number);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
add_sign(sign, number_sign, FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
/* currency (before) */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (_currency && is_currency_before(number_sign < 0, intl_currency))
|
|
|
|
{
|
2008-11-24 15:11:01 +01:00
|
|
|
add_currency(intl_currency ? local_current->intl_currency_symbol : local_current->currency_symbol);
|
|
|
|
if (is_currency_space(number_sign < 0, intl_currency))
|
|
|
|
put_char(' ');
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* We note where the first digit will be printed */
|
2008-11-24 15:11:01 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
pos_first_digit = buffer_pos;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* the number */
|
2011-01-04 03:35:48 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (isfinite(number))
|
2011-04-08 01:24:11 +02:00
|
|
|
{
|
2012-01-31 03:33:01 +01:00
|
|
|
number_mant = frexp10(fabs(number), &number_exp);
|
|
|
|
ndigit = after;
|
2018-08-10 11:49:12 +02:00
|
|
|
|
2019-10-29 09:20:41 +01:00
|
|
|
if (!exponent)
|
2018-08-10 11:49:12 +02:00
|
|
|
ndigit += number_exp;
|
|
|
|
else
|
|
|
|
ndigit++;
|
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
ndigit = MinMax(ndigit, 0, MAX_FLOAT_DIGIT);
|
2012-04-28 17:08:24 +02:00
|
|
|
//fprintf(stderr, "number_mant = %.24g number_exp = %d ndigit = %d\n", number_mant, number_exp, ndigit);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-04-28 17:08:24 +02:00
|
|
|
power = pow10_uint64_p(ndigit + 1);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
mantisse = number_mant * power;
|
|
|
|
if ((mantisse % 10) >= 5)
|
|
|
|
mantisse += 10;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-04-28 17:08:24 +02:00
|
|
|
//fprintf(stderr, "-> power = %" PRId64 " mantisse = %" PRId64 "\n", power, mantisse);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (mantisse >= power)
|
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
ndigit = int_to_string(mantisse, &buf_addr);
|
|
|
|
buf_addr--;
|
|
|
|
buf_addr[0] = buf_addr[1];
|
|
|
|
buf_addr[1] = '.';
|
|
|
|
ndigit++;
|
2012-01-31 03:33:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
ndigit = int_to_string(mantisse, &buf_addr);
|
|
|
|
buf_addr -= 2;
|
|
|
|
buf_addr[0] = '0';
|
|
|
|
buf_addr[1] = '.';
|
|
|
|
ndigit += 2;
|
2012-01-31 03:33:01 +01:00
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
ndigit--;
|
2019-09-28 21:15:59 +02:00
|
|
|
buf_addr[ndigit] = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* 0.0 <= number_mant < 1.0 */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
//number_exp++; /* simplifie les choses */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
number_real_exp = number_exp;
|
2019-10-29 09:20:41 +01:00
|
|
|
if (exponent)
|
2012-01-31 03:33:01 +01:00
|
|
|
number_exp = number != 0.0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
// should return "0[.]...", or "1[.]..." if the number is rounded up.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
if (buf_addr[0] == '1') // the number has been rounded up.
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2019-10-29 09:20:41 +01:00
|
|
|
if (exponent)
|
2012-01-31 03:33:01 +01:00
|
|
|
number_real_exp++;
|
|
|
|
else
|
|
|
|
number_exp++;
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (ndigit > 1) // so there is a point
|
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
if (buf_addr[0] == '0')
|
2012-01-31 03:33:01 +01:00
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
buf_addr += 2;
|
2012-01-31 03:33:01 +01:00
|
|
|
ndigit -= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
buf_addr[1] = buf_addr[0];
|
2012-01-31 03:33:01 +01:00
|
|
|
ndigit--;
|
2019-09-28 21:15:59 +02:00
|
|
|
buf_addr++;
|
2012-01-31 03:33:01 +01:00
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
while (ndigit > 0 && buf_addr[ndigit - 1] == '0')
|
2012-01-31 03:33:01 +01:00
|
|
|
ndigit--;
|
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* digits before point */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
thousand = Max(before, Max(before_zero, number_exp));
|
|
|
|
thousand_ptr = comma ? &thousand : NULL;
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (number_exp > 0)
|
|
|
|
{
|
|
|
|
add_char(' ', before - Max(before_zero, number_exp), thousand_ptr);
|
|
|
|
add_zero(before_zero - number_exp, thousand_ptr);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-09-28 21:15:59 +02:00
|
|
|
add_string(buf_addr, Min(number_exp, ndigit), thousand_ptr);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (number_exp > ndigit)
|
|
|
|
add_zero(number_exp - ndigit, thousand_ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add_char(' ', before - before_zero, thousand_ptr);
|
|
|
|
add_zero(before_zero, thousand_ptr);
|
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* decimal point */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (point)
|
|
|
|
put_char(local_current->decimal_point);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* digits after the decimal point */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if ((ndigit - number_exp) > 0)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2012-01-31 03:33:01 +01:00
|
|
|
if (number_exp < 0)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2012-01-31 03:33:01 +01:00
|
|
|
n = Min(after, (- number_exp));
|
|
|
|
if (n == after)
|
|
|
|
{
|
|
|
|
add_zero(after_zero, NULL);
|
|
|
|
goto _EXPOSANT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add_zero(n, NULL);
|
|
|
|
after -= n;
|
|
|
|
after_zero -= n;
|
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2012-01-31 03:33:01 +01:00
|
|
|
|
|
|
|
if (number_exp > 0)
|
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
buf_addr += number_exp;
|
2012-01-31 03:33:01 +01:00
|
|
|
ndigit -= number_exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = Min(ndigit, after);
|
|
|
|
if (n > 0)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2019-09-28 21:15:59 +02:00
|
|
|
add_string(buf_addr, n, NULL);
|
2010-08-28 14:33:05 +02:00
|
|
|
after -= n;
|
|
|
|
after_zero -= n;
|
|
|
|
}
|
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
if (after_zero > 0)
|
|
|
|
add_zero(after_zero, NULL);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2012-01-31 03:33:01 +01:00
|
|
|
else
|
2010-08-28 14:33:05 +02:00
|
|
|
add_zero(after_zero, NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
_EXPOSANT:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* The decimal point is removed if it is located at the end */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
buffer_pos--;
|
|
|
|
if (look_char() != local_current->decimal_point)
|
|
|
|
buffer_pos++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-10-29 09:20:41 +01:00
|
|
|
/* exponent */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-10-29 09:20:41 +01:00
|
|
|
if (exponent != 0) // && number != 0.0)
|
2012-01-31 03:33:01 +01:00
|
|
|
{
|
2019-10-29 09:20:41 +01:00
|
|
|
put_char(exponent);
|
|
|
|
if (exp_sign && number_real_exp >= 1)
|
|
|
|
put_char('+');
|
2019-09-28 21:15:59 +02:00
|
|
|
n = int_to_string(number_real_exp - 1, &buf_addr);
|
|
|
|
while (exp_zero > n)
|
|
|
|
{
|
|
|
|
put_char('0');
|
|
|
|
exp_zero--;
|
|
|
|
}
|
|
|
|
add_string(buf_addr, n, NULL);
|
2012-01-31 03:33:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // isfinite
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2012-01-31 03:33:01 +01:00
|
|
|
if (isnan(number))
|
|
|
|
add_string("NaN", 3, NULL);
|
|
|
|
else if (isinf(number))
|
|
|
|
add_string("Inf", 3, NULL);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
/* currency (after) */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (_currency && !is_currency_before(number_sign < 0, intl_currency))
|
|
|
|
{
|
2008-11-24 15:11:01 +01:00
|
|
|
if (is_currency_space(number_sign < 0, intl_currency))
|
|
|
|
put_char(' ');
|
|
|
|
add_currency(intl_currency ? local_current->intl_currency_symbol : local_current->currency_symbol);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* The last format brace is ignored */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (sign == '(' && fmt[pos] == ')')
|
|
|
|
pos++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
/* The sign after */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
add_sign(sign, number_sign, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
/* print at least a zero */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (buffer_pos == pos_first_digit)
|
|
|
|
put_char('0');
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
/* suffixe de formatage */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (pos < len_fmt)
|
|
|
|
add_string(&fmt[pos], len_fmt - pos, NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* return the result */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
end(str, len_str);
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_strftime(const char *format, struct tm *tm)
|
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
int n;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
n = strftime(get_current(), get_size_left(), format, tm);
|
|
|
|
buffer_pos += n;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-21 14:42:56 +02:00
|
|
|
static void add_number(int value, int pad)
|
|
|
|
{
|
|
|
|
static char temp[8] = { 0 };
|
|
|
|
int i, n;
|
2011-10-24 16:56:41 +02:00
|
|
|
bool minus = FALSE;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2011-10-24 16:56:41 +02:00
|
|
|
if (value < 0)
|
|
|
|
{
|
|
|
|
value = (-value);
|
|
|
|
minus = TRUE;
|
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2011-09-21 14:42:56 +02:00
|
|
|
n = 0;
|
|
|
|
for (i = 7; i >= 0; i--)
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
if (value < 10)
|
|
|
|
{
|
|
|
|
temp[i] = value + '0';
|
|
|
|
value = 0;
|
|
|
|
if (n >= pad)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp[i] = (value % 10) + '0';
|
|
|
|
value /= 10;
|
|
|
|
}
|
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2011-10-24 16:56:41 +02:00
|
|
|
if (minus)
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
temp[i] = '-';
|
|
|
|
n++;
|
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2011-09-21 14:42:56 +02:00
|
|
|
add_string(&temp[i], n, NULL);
|
|
|
|
}
|
|
|
|
|
2012-02-05 09:08:27 +01:00
|
|
|
static bool add_date_token(DATE_SERIAL *date, char *token, int count)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
struct tm tm = {0};
|
|
|
|
char buf[8];
|
|
|
|
int n;
|
2012-02-05 20:30:30 +01:00
|
|
|
bool date_token;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (*token == 0)
|
2012-02-05 09:08:27 +01:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-02-05 20:30:30 +01:00
|
|
|
date_token = *token == 'd' || *token == 'm' || *token == 'y';
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-02-11 09:37:48 +01:00
|
|
|
if ((date_token && DATE_SERIAL_has_no_date(date))) // || (!date_token && DATE_SERIAL_has_no_time(date)))
|
2012-02-05 09:08:27 +01:00
|
|
|
{
|
|
|
|
*token = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
switch (*token)
|
|
|
|
{
|
|
|
|
case 'd':
|
|
|
|
|
|
|
|
if (count <= 2)
|
|
|
|
{
|
2011-09-21 14:42:56 +02:00
|
|
|
add_number(date->day, (count == 1 ? 0 : 2));
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
else if (count >= 3)
|
|
|
|
{
|
|
|
|
tm.tm_wday = date->weekday;
|
|
|
|
add_strftime(count == 3 ? "%a" : "%A", &tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
|
|
|
|
if (count <= 2)
|
|
|
|
{
|
2011-09-21 14:42:56 +02:00
|
|
|
add_number(date->month, (count == 1 ? 0 : 2));
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
else if (count >= 3)
|
|
|
|
{
|
|
|
|
tm.tm_mon = date->month - 1;
|
|
|
|
add_strftime(count == 3 ? "%b" : "%B", &tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y':
|
|
|
|
|
|
|
|
if (count <= 2 && date->year >= 1939 && date->year <= 2038)
|
2011-09-21 14:42:56 +02:00
|
|
|
add_number(date->year - (date->year >= 2000 ? 2000 : 1900), 2);
|
2010-08-28 14:33:05 +02:00
|
|
|
else
|
2018-03-16 01:45:32 +01:00
|
|
|
add_number(date->year, (count == 1 ? 0 : count));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case 'h':
|
|
|
|
case 'n':
|
|
|
|
case 's':
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-09-21 14:42:56 +02:00
|
|
|
add_number((*token == 'h') ? date->hour : ((*token == 'n') ? date->min : date->sec), (count == 1 ? 0 : 2));
|
2010-08-28 14:33:05 +02:00
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case 'u':
|
|
|
|
|
|
|
|
if (date->msec || count == 2)
|
|
|
|
{
|
2014-12-01 01:47:48 +01:00
|
|
|
if (count >= 2)
|
2011-09-21 14:42:56 +02:00
|
|
|
add_number(date->msec, 3);
|
|
|
|
else
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2011-09-21 14:42:56 +02:00
|
|
|
n = snprintf(buf, sizeof(buf), "%03d", date->msec);
|
2010-08-28 14:33:05 +02:00
|
|
|
while (buf[n - 1] == '0')
|
|
|
|
n--;
|
2011-09-21 14:42:56 +02:00
|
|
|
buf[n] = 0;
|
|
|
|
add_string(buf, n, NULL);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
break;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-02-25 16:16:10 +01:00
|
|
|
case 't':
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2012-02-25 16:16:10 +01:00
|
|
|
if (count <= 2)
|
|
|
|
{
|
2018-05-25 12:17:30 +02:00
|
|
|
time_t t = time(NULL);
|
2012-02-25 16:16:10 +01:00
|
|
|
localtime_r(&t, &tm);
|
|
|
|
add_strftime(count == 2 ? "%z" : "%Z", &tm);
|
|
|
|
}
|
|
|
|
break;
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
*token = 0;
|
2012-02-05 09:08:27 +01:00
|
|
|
return FALSE;
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2011-06-26 21:09:17 +02:00
|
|
|
bool LOCAL_format_date(const DATE_SERIAL *date, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str)
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
2011-06-26 21:09:17 +02:00
|
|
|
DATE_SERIAL vdate;
|
2010-08-28 14:33:05 +02:00
|
|
|
char c;
|
|
|
|
int pos;
|
|
|
|
int pos_ampm = -1;
|
|
|
|
struct tm date_tm;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
char token;
|
|
|
|
int token_count;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
local_current = &LOCAL_local;
|
2011-06-26 21:09:17 +02:00
|
|
|
vdate = *date;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
switch(fmt_type)
|
|
|
|
{
|
|
|
|
case LF_USER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_STANDARD:
|
|
|
|
case LF_GENERAL_DATE:
|
|
|
|
if (date->year == 0)
|
2012-02-05 09:08:27 +01:00
|
|
|
{
|
|
|
|
if (date->hour == 0 && date->min == 0 && date->sec == 0)
|
|
|
|
{
|
|
|
|
*str = NULL;
|
|
|
|
*len_str = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
fmt = local_current->long_time;
|
2012-02-05 09:08:27 +01:00
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
else
|
|
|
|
fmt = local_current->general_date;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case LF_LONG_DATE:
|
|
|
|
fmt = local_current->long_date;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case LF_MEDIUM_DATE:
|
|
|
|
fmt = local_current->medium_date;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case LF_SHORT_DATE:
|
|
|
|
fmt = local_current->short_date;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case LF_LONG_TIME:
|
|
|
|
fmt = local_current->long_time;
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
case LF_MEDIUM_TIME:
|
|
|
|
fmt = local_current->medium_time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LF_SHORT_TIME:
|
|
|
|
fmt = local_current->short_time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len_fmt == 0)
|
|
|
|
len_fmt = strlen(fmt);
|
|
|
|
|
|
|
|
if (len_fmt >= COMMON_BUF_MAX)
|
|
|
|
return TRUE;
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* looking for AM/PM */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
for (pos = 0; pos < len_fmt - 4; pos++)
|
|
|
|
{
|
|
|
|
if (fmt[pos] == '\\')
|
|
|
|
{
|
|
|
|
pos++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncasecmp(&fmt[pos], "am/pm", 5) == 0)
|
|
|
|
{
|
|
|
|
pos_ampm = pos;
|
2011-06-26 21:09:17 +02:00
|
|
|
if (vdate.hour > 12)
|
|
|
|
vdate.hour -= 12;
|
|
|
|
else if (vdate.hour == 0)
|
|
|
|
vdate.hour = 12;
|
2010-08-28 14:33:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* Formatting */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
begin();
|
|
|
|
|
|
|
|
token = 0;
|
|
|
|
token_count = 0;
|
|
|
|
|
|
|
|
for (pos = 0; pos < len_fmt; pos++)
|
|
|
|
{
|
|
|
|
c = fmt[pos];
|
|
|
|
if (c == '\\')
|
|
|
|
{
|
|
|
|
pos++;
|
|
|
|
if (pos >= len_fmt)
|
|
|
|
break;
|
2011-08-09 11:13:23 +02:00
|
|
|
add_date_token(&vdate, &token, token_count);
|
|
|
|
put_char(fmt[pos]);
|
|
|
|
continue;
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pos == pos_ampm)
|
|
|
|
{
|
2012-06-29 01:09:10 +02:00
|
|
|
add_date_token(&vdate, &token, token_count);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* convert to struct tm */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
date_tm.tm_sec = date->sec;
|
|
|
|
date_tm.tm_min = date->min;
|
2011-06-26 21:09:17 +02:00
|
|
|
date_tm.tm_hour = date->hour;
|
2010-08-28 14:33:05 +02:00
|
|
|
date_tm.tm_mday = 1;
|
|
|
|
date_tm.tm_mon = 0;
|
|
|
|
date_tm.tm_year = 0;
|
|
|
|
|
|
|
|
add_strftime((c == 'a' ? "%P" : "%p"), &date_tm);
|
|
|
|
|
|
|
|
pos += 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-02-25 16:16:10 +01:00
|
|
|
if (c == 'd' || c == 'm' || c == 'y' || c == 'h' || c == 'n' || c == 's' || c == 'u' || c == 't')
|
2010-08-28 14:33:05 +02:00
|
|
|
{
|
|
|
|
if (c != token)
|
|
|
|
{
|
2012-02-05 09:08:27 +01:00
|
|
|
add_date_token(&vdate, &token, token_count);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
token = c;
|
|
|
|
token_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
token_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-05 09:08:27 +01:00
|
|
|
if (!add_date_token(&vdate, &token, token_count))
|
|
|
|
{
|
|
|
|
if (c == '/')
|
2015-07-12 00:44:09 +02:00
|
|
|
add_unicode(local_current->date_sep);
|
2012-02-05 09:08:27 +01:00
|
|
|
else if (c == ':')
|
2015-07-12 00:44:09 +02:00
|
|
|
add_unicode(local_current->time_sep);
|
2012-02-05 09:08:27 +01:00
|
|
|
else
|
|
|
|
put_char(c);
|
|
|
|
}
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 21:09:17 +02:00
|
|
|
add_date_token(&vdate, &token, token_count);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2017-08-30 20:40:17 +02:00
|
|
|
/* return the result */
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
end(str, len_str);
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-11 04:40:50 +01:00
|
|
|
static void LOCAL_load_translation(ARCHIVE *arch)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
char *domain = NULL;
|
|
|
|
char *lang_list;
|
|
|
|
char *lang;
|
|
|
|
char *src;
|
|
|
|
char *test;
|
|
|
|
char c;
|
|
|
|
FILE *file;
|
|
|
|
char *addr;
|
|
|
|
int len;
|
|
|
|
COMPONENT *save = COMPONENT_current;
|
2019-06-22 01:20:38 +02:00
|
|
|
char *path;
|
|
|
|
const char *dir;
|
|
|
|
char *dst;
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
/* We must force GB_LoadFile() to look in our archive, because all translation
|
|
|
|
files of one language have the same path!
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (arch)
|
|
|
|
{
|
|
|
|
domain = arch->domain;
|
|
|
|
COMPONENT_current = COMPONENT_find(arch->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!domain)
|
|
|
|
domain = "gb";
|
|
|
|
|
|
|
|
#ifdef DEBUG_LANG
|
2016-10-02 00:32:42 +02:00
|
|
|
fprintf(stderr, "LOCAL_load_translation: %s / domain = %s\n", arch ? arch->name : "NULL", domain);
|
2010-08-28 14:33:05 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
lang_list = get_languages();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
lang = strtok(lang_list, ":");
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (!lang)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*lang)
|
|
|
|
{
|
2019-06-22 01:20:38 +02:00
|
|
|
test = STRING_new_zero(lang);
|
2010-08-28 14:33:05 +02:00
|
|
|
src = test;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
c = *src;
|
|
|
|
if (c == 0 || c == '_')
|
|
|
|
break;
|
|
|
|
*src = tolower(c);
|
|
|
|
src++;
|
|
|
|
}
|
2019-06-22 01:20:38 +02:00
|
|
|
|
|
|
|
test = STRING_add(test, ".mo", 3);
|
|
|
|
|
|
|
|
dir = arch ? ".lang" : ".../.lang";
|
2016-10-02 00:32:42 +02:00
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
FILE_dir_first(dir, test, 0);
|
|
|
|
STRING_free_real(test);
|
|
|
|
|
|
|
|
if (!FILE_dir_next(&path, &len))
|
|
|
|
{
|
|
|
|
dst = STRING_new_zero(dir);
|
|
|
|
dst = STRING_add_char(dst, '/');
|
|
|
|
dst = STRING_add(dst, path, len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if (!arch)
|
2016-10-02 00:32:42 +02:00
|
|
|
dst = FILE_cat("...", ".lang", test, NULL);
|
|
|
|
else
|
|
|
|
dst = FILE_cat(".lang", test, NULL);
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
dst = FILE_set_ext(dst, "mo");
|
|
|
|
|
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "trying %s\n", dst);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (FILE_exist(dst))
|
2019-06-22 01:20:38 +02:00
|
|
|
break;*/
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lang = strtok(NULL, ":");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lang)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "No translation\n");
|
|
|
|
#endif
|
|
|
|
goto __NOTRANS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "Loading %s\n", dst);
|
|
|
|
#endif
|
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
STRING_free_later(dst);
|
2010-08-28 14:33:05 +02:00
|
|
|
if (GB_LoadFile(dst, 0, &addr, &len))
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "Cannot load %s\n", dst);
|
|
|
|
#endif
|
|
|
|
goto __ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These temporary files have predictable names because they
|
|
|
|
// are *.mo files read by the gettext system.
|
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
dir = FILE_cat(FILE_make_temp(NULL, NULL), "tr", NULL);
|
|
|
|
mkdir(dir, S_IRWXU);
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
dir = FILE_cat(FILE_make_temp(NULL, NULL), "tr", setlocale(LC_ALL, NULL), NULL);
|
|
|
|
mkdir(dir, S_IRWXU);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
dir = FILE_cat(dir, "LC_MESSAGES", NULL);
|
|
|
|
mkdir(dir, S_IRWXU);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
dir = FILE_cat(dir, domain, NULL);
|
|
|
|
strcat((char *)dir, ".mo");
|
2010-08-28 14:33:05 +02:00
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
unlink(dir);
|
2010-08-28 14:33:05 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_LANG
|
2019-06-22 01:20:38 +02:00
|
|
|
fprintf(stderr, "Writing to %s (%d bytes)\n", dir, len);
|
2010-08-28 14:33:05 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// No need to test previous system calls as the failure will be detected now
|
|
|
|
|
2019-06-22 01:20:38 +02:00
|
|
|
file = fopen(dir, "w");
|
2010-08-28 14:33:05 +02:00
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
fwrite(addr, len, 1, file);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
GB_ReleaseFile(addr, len);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__ERROR:
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
// If the *.mo was not copied, then the following functions will failed
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
#ifdef DEBUG_LANG
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
fprintf(stderr, "bindtextdomain: %s\n", bindtextdomain(domain, FILE_cat(FILE_make_temp(NULL, NULL), "tr", NULL)));
|
|
|
|
fprintf(stderr, "bind_textdomain_codeset: %s\n", bind_textdomain_codeset(domain, "UTF-8"));
|
|
|
|
if (!arch)
|
|
|
|
fprintf(stderr, "textdomain: %s\n", textdomain(domain));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
#else
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
bindtextdomain(domain, FILE_cat(FILE_make_temp(NULL, NULL), "tr", NULL));
|
|
|
|
#ifdef OS_SOLARIS
|
|
|
|
fprintf(stderr, "Warning: bind_textdomain_codeset() unavailable.\n");
|
|
|
|
#else
|
|
|
|
bind_textdomain_codeset(domain, "UTF-8");
|
|
|
|
#endif
|
|
|
|
if (!arch)
|
|
|
|
textdomain(domain); /* default domain */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__NOTRANS:
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
STRING_free(&lang_list);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (arch)
|
|
|
|
arch->translation_loaded = TRUE;
|
|
|
|
else
|
|
|
|
_translation_loaded = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
COMPONENT_current = save;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *LOCAL_gettext(const char *msgid)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-08-28 14:33:05 +02:00
|
|
|
const char *tr = msgid;
|
|
|
|
ARCHIVE *arch = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
/*
|
|
|
|
If LOCAL_gettext() is called, then we are in the context of
|
|
|
|
the archive, so the translation loaded will be the good one.
|
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!msgid)
|
2011-08-02 01:36:41 +02:00
|
|
|
return "";
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (!ARCHIVE_get_current(&arch))
|
|
|
|
{
|
2016-10-02 00:32:42 +02:00
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "dgettext(\"%s\", \"%s\")\n", arch->domain, msgid);
|
|
|
|
#endif
|
2010-08-28 14:33:05 +02:00
|
|
|
if (!arch->translation_loaded)
|
|
|
|
LOCAL_load_translation(arch);
|
|
|
|
tr = dgettext(arch->domain, msgid);
|
|
|
|
}
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (tr == msgid)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_LANG
|
2016-10-02 00:32:42 +02:00
|
|
|
fprintf(stderr, "dgettext(\"%s\", \"%s\")\n", "gb", msgid);
|
2010-08-28 14:33:05 +02:00
|
|
|
#endif
|
2016-10-02 00:32:42 +02:00
|
|
|
if (!_translation_loaded)
|
|
|
|
LOCAL_load_translation(NULL);
|
|
|
|
tr = dgettext("gb", msgid);
|
|
|
|
//tr = gettext(msgid);
|
2010-08-28 14:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*printf("tr: %s -> %s\n", msgid, tr);*/
|
|
|
|
|
2011-08-02 01:36:41 +02:00
|
|
|
if (!tr || tr[0] == 0 || (tr[0] == '-' && (tr[1] == 0 || (tr[1] == '\n' && tr[2] == 0))))
|
|
|
|
tr = msgid;
|
|
|
|
|
2016-10-02 00:32:42 +02:00
|
|
|
#ifdef DEBUG_LANG
|
|
|
|
fprintf(stderr, "--> \"%s\"\n", tr);
|
|
|
|
#endif
|
|
|
|
|
2013-01-06 17:13:31 +01:00
|
|
|
return tr;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
int LOCAL_get_first_day_of_week()
|
|
|
|
{
|
|
|
|
const char *lang;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (LOCAL_first_day_of_week >= 0)
|
|
|
|
return LOCAL_first_day_of_week;
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
lang = LOCAL_get_lang();
|
2015-11-11 04:40:50 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
if (strcmp(lang, "en") == 0 || strncmp(lang, "en_", 3) == 0 || strcmp(lang, "C") == 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-28 14:33:05 +02:00
|
|
|
void LOCAL_set_first_day_of_week(char day)
|
|
|
|
{
|
|
|
|
if (day >= -1 && day <= 6)
|
|
|
|
LOCAL_first_day_of_week = day;
|
|
|
|
}
|