clean up and support missing locale

This commit is contained in:
Vítor Santos Costa 2014-03-15 22:29:04 +00:00
parent 6d2e2597b1
commit 5491abdeeb
3 changed files with 18 additions and 9 deletions

View File

@ -671,7 +671,7 @@ PRED_IMPL("normalize_space", 2, normalize_space, 0)
* LOCALE *
*******************************/
#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
#if O_LOCALE
#include <locale.h>
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -843,15 +843,20 @@ static const enc_map map[] =
IOENC
initEncoding(void)
{ GET_LD
#if HAVE_SETLOCALE
char *enc;
#endif
if ( LD )
{ if ( !LD->encoding )
{ char *enc, *encp;
{
if ( !init_locale() )
{ LD->encoding = ENC_ISO_LATIN_1;
#if HAVE_SETLOCALE
} else if ( (enc = setlocale(LC_CTYPE, NULL)) )
{ LD->encoding = ENC_ANSI; /* text encoding */
{ char *encp;
LD->encoding = ENC_ANSI; /* text encoding */
if ( (encp = strchr(enc, '.')) )
{ const enc_map *m;
@ -874,8 +879,8 @@ initEncoding(void)
}
}
}
} else
{ LD->encoding = ENC_ISO_LATIN_1;
#endif
} else { LD->encoding = ENC_ISO_LATIN_1;
}
}

View File

@ -1115,6 +1115,7 @@ formatInteger(PL_locale *locale, int div, int radix, bool smll, Number i,
}
}
#if O_LOCALE
static int
countGroups(const char *grouping, int len)
@ -1141,7 +1142,6 @@ countGroups(const char *grouping, int len)
return groups;
}
static int
ths_to_utf8(char *u8, const wchar_t *s, size_t len)
{ char *e = u8+len-7;
@ -1153,7 +1153,6 @@ ths_to_utf8(char *u8, const wchar_t *s, size_t len)
return *s == 0;
}
static int
same_decimal_point(PL_locale *l1, PL_locale *l2)
{ if ( l1->decimal_point && l2->decimal_point &&
@ -1165,7 +1164,6 @@ same_decimal_point(PL_locale *l1, PL_locale *l2)
return FALSE;
}
static int
utf8_dp(PL_locale *l, char *s, int *len)
{ if ( l->decimal_point )
@ -1227,7 +1225,6 @@ localizeDecimalPoint(PL_locale *locale, Buffer b)
return TRUE;
}
static int
groupDigits(PL_locale *locale, Buffer b)
{ if ( locale->thousands_sep && locale->thousands_sep[0] &&
@ -1278,6 +1275,7 @@ groupDigits(PL_locale *locale, Buffer b)
return TRUE;
}
#endif
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1477,11 +1475,13 @@ formatFloat(PL_locale *locale, int how, int arg, Number f, Buffer out)
return NULL;
}
#if O_LOCALE
if ( locale )
{ if ( !localizeDecimalPoint(locale, out) ||
!groupDigits(locale, out) )
return NULL;
}
#endif
return baseBuffer(out, char);
}

View File

@ -57,7 +57,9 @@ locking is required.
#endif
#define PL_KERNEL 1
#if HAVE_LOCALE_H && HAVE_SETLOCALE
#define O_LOCALE 1
#endif
#include <wchar.h>
#define NEEDS_SWINSOCK
#include "SWI-Stream.h"
@ -1800,8 +1802,10 @@ Sclose(IOSTREAM *s)
if ( s->message )
free(s->message);
#if O_LOCALE
if ( s->locale )
releaseLocale(s->locale);
#endif
if ( s->references == 0 )
unallocStream(s);
else