Skip to content

Commit

Permalink
Getting much closer to 'real' locale support now.
Browse files Browse the repository at this point in the history
git-svn-id: svn://rootdirectory.ddns.net/pdclib/trunk@743 bcf39385-58cc-4174-9fcf-14f50f90dd47
  • Loading branch information
DevSolar committed Jul 24, 2018
1 parent 5ec916b commit 81a24c0
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 328 deletions.
55 changes: 0 additions & 55 deletions functions/_PDCLIB/_PDCLIB_load_lc_all.c

This file was deleted.

10 changes: 8 additions & 2 deletions functions/_PDCLIB/_PDCLIB_load_lc_collate.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

#include "pdclib/_PDCLIB_int.h"

const char * _PDCLIB_load_lc_collate( const char * path, const char * locale )
struct _PDCLIB_lc_collate_t * _PDCLIB_load_lc_collate( const char * path, const char * locale )
{
struct _PDCLIB_lc_collate_t * rc = NULL;
const char * extension = "_collate.dat";
char * file = malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 );

Expand All @@ -28,13 +29,18 @@ const char * _PDCLIB_load_lc_collate( const char * path, const char * locale )

if ( ( fh = fopen( file, "rb" ) ) != NULL )
{
if ( ( rc = malloc( sizeof( struct _PDCLIB_lc_collate_t ) ) ) != NULL )
{
/* TODO */
}

fclose( fh );
}

free( file );
}

return locale;
return rc;
}

#endif
Expand Down
319 changes: 167 additions & 152 deletions functions/_PDCLIB/_PDCLIB_load_lc_ctype.c

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions functions/_PDCLIB/_PDCLIB_load_lc_messages.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* _PDCLIB_load_lc_messages( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/

#ifndef REGTEST

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "pdclib/_PDCLIB_int.h"

struct _PDCLIB_lc_messages_t * _PDCLIB_load_lc_messages( const char * path, const char * locale )
{
struct _PDCLIB_lc_messages_t * rc = NULL;
const char * extension = "_messages.dat";
char * file = malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 );

if ( file )
{
FILE * fh;

strcpy( file, path );
strcat( file, locale );
strcat( file, extension );

if ( ( fh = fopen( file, "rb" ) ) != NULL )
{
if ( ( rc = malloc( sizeof( struct _PDCLIB_lc_messages_t ) ) ) != NULL )
{
char * data = _PDCLIB_load_lines( fh, _PDCLIB_ERRNO_MAX );

rc->alloced = 1;

if ( data != NULL )
{
size_t i;

for ( i = 0; i < _PDCLIB_ERRNO_MAX; ++i )
{
rc->errno_texts[ i ] = data;
data += strlen( data ) + 1;
}
}
else
{
free( rc );
rc = NULL;
}
}

fclose( fh );
}

free( file );
}

return rc;
}

#endif

#ifdef TEST

#include "_PDCLIB_test.h"

int main( void )
{
#ifndef REGTEST
FILE * fh = fopen( "test_numeric.dat", "wb" );
struct _PDCLIB_lc_lconv_numeric_t * lc;
TESTCASE( fh != NULL );
TESTCASE( fputs( ",\n.\n\n", fh ) != EOF );
fclose( fh );
TESTCASE( ( lc = _PDCLIB_load_lc_numeric( "./", "test" ) ) );
remove( "test_numeric.dat" );
TESTCASE( strcmp( lc->decimal_point, "," ) == 0 );
TESTCASE( strcmp( lc->thousands_sep, "." ) == 0 );
TESTCASE( strcmp( lc->grouping, "" ) == 0 );
#endif

return TEST_RESULTS;
}

#endif
90 changes: 48 additions & 42 deletions functions/_PDCLIB/_PDCLIB_load_lc_monetary.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include "pdclib/_PDCLIB_int.h"

bool _PDCLIB_load_lc_monetary( const char * path, const char * locale )
struct _PDCLIB_lc_lconv_monetary_t * _PDCLIB_load_lc_monetary( const char * path, const char * locale )
{
bool rc = false;
struct _PDCLIB_lc_lconv_monetary_t * rc = NULL;
const char * extension = "_monetary.dat";
char * file = malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 );

Expand All @@ -30,48 +30,55 @@ bool _PDCLIB_load_lc_monetary( const char * path, const char * locale )

if ( ( fh = fopen( file, "rb" ) ) != NULL )
{
char buffer[ 14 ];
char * data = _PDCLIB_load_lines( fh, 7 );

if ( data != NULL )
if ( ( rc = malloc( sizeof( struct _PDCLIB_lc_lconv_monetary_t ) ) ) != NULL )
{
if ( fread( buffer, 1, 14, fh ) == 14 )
char buffer[ 14 ];
char * data = _PDCLIB_load_lines( fh, 7 );

if ( data != NULL )
{
_PDCLIB_lc_numeric_monetary.monetary_alloced = 1;
_PDCLIB_lc_numeric_monetary.lconv->mon_decimal_point = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->mon_thousands_sep = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->mon_grouping = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->positive_sign = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->negative_sign = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->currency_symbol = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->int_curr_symbol = data;

_PDCLIB_lc_numeric_monetary.lconv->frac_digits = buffer[ 0 ];
_PDCLIB_lc_numeric_monetary.lconv->p_cs_precedes = buffer[ 1 ];
_PDCLIB_lc_numeric_monetary.lconv->n_cs_precedes = buffer[ 2 ];
_PDCLIB_lc_numeric_monetary.lconv->p_sep_by_space = buffer[ 3 ];
_PDCLIB_lc_numeric_monetary.lconv->n_sep_by_space = buffer[ 4 ];
_PDCLIB_lc_numeric_monetary.lconv->p_sign_posn = buffer[ 5 ];
_PDCLIB_lc_numeric_monetary.lconv->n_sign_posn = buffer[ 6 ];
_PDCLIB_lc_numeric_monetary.lconv->int_frac_digits = buffer[ 7 ];
_PDCLIB_lc_numeric_monetary.lconv->int_p_cs_precedes = buffer[ 8 ];
_PDCLIB_lc_numeric_monetary.lconv->int_n_cs_precedes = buffer[ 9 ];
_PDCLIB_lc_numeric_monetary.lconv->int_p_sep_by_space = buffer[ 10 ];
_PDCLIB_lc_numeric_monetary.lconv->int_n_sep_by_space = buffer[ 11 ];
_PDCLIB_lc_numeric_monetary.lconv->int_p_sign_posn = buffer[ 12 ];
_PDCLIB_lc_numeric_monetary.lconv->int_n_sign_posn= buffer[ 13 ];

rc = true;
if ( fread( buffer, 1, 14, fh ) == 14 )
{
rc->mon_decimal_point = data;
data += strlen( data ) + 1;
rc->mon_thousands_sep = data;
data += strlen( data ) + 1;
rc->mon_grouping = data;
data += strlen( data ) + 1;
rc->positive_sign = data;
data += strlen( data ) + 1;
rc->negative_sign = data;
data += strlen( data ) + 1;
rc->currency_symbol = data;
data += strlen( data ) + 1;
rc->int_curr_symbol = data;

rc->frac_digits = buffer[ 0 ];
rc->p_cs_precedes = buffer[ 1 ];
rc->n_cs_precedes = buffer[ 2 ];
rc->p_sep_by_space = buffer[ 3 ];
rc->n_sep_by_space = buffer[ 4 ];
rc->p_sign_posn = buffer[ 5 ];
rc->n_sign_posn = buffer[ 6 ];
rc->int_frac_digits = buffer[ 7 ];
rc->int_p_cs_precedes = buffer[ 8 ];
rc->int_n_cs_precedes = buffer[ 9 ];
rc->int_p_sep_by_space = buffer[ 10 ];
rc->int_n_sep_by_space = buffer[ 11 ];
rc->int_p_sign_posn = buffer[ 12 ];
rc->int_n_sign_posn= buffer[ 13 ];
}
else
{
free( data );
free( rc );
rc = NULL;
}
}
else
{
free( data );
free( rc );
rc = NULL;
}
}

Expand All @@ -94,7 +101,7 @@ int main( void )
{
#ifndef REGTEST
FILE * fh = fopen( "test_monetary.dat", "wb" );
struct lconv * lc;
struct _PDCLIB_lc_lconv_monetary_t * lc;
TESTCASE( fh != NULL );
fprintf( fh, "%s\n", "," ); /* mon_decimal_point */
fprintf( fh, "%s\n", "." ); /* mon_thousands_sep */
Expand All @@ -119,9 +126,8 @@ int main( void )
fputc( 1, fh ); /* int_n_sign_posn */
fprintf( fh, "\n" );
fclose( fh );
TESTCASE( _PDCLIB_load_lc_monetary( "./", "test" ) );
TESTCASE( ( lc = _PDCLIB_load_lc_monetary( "./", "test" ) ) );
remove( "test_monetary.dat" );
lc = localeconv();
TESTCASE( strcmp( lc->mon_decimal_point, "," ) == 0 );
TESTCASE( strcmp( lc->mon_thousands_sep, "." ) == 0 );
TESTCASE( strcmp( lc->mon_grouping, "3" ) == 0 );
Expand Down
37 changes: 20 additions & 17 deletions functions/_PDCLIB/_PDCLIB_load_lc_numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
#ifndef REGTEST

#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "pdclib/_PDCLIB_int.h"

bool _PDCLIB_load_lc_numeric( const char * path, const char * locale )
struct _PDCLIB_lc_lconv_numeric_t * _PDCLIB_load_lc_numeric( const char * path, const char * locale )
{
bool rc = false;
struct _PDCLIB_lc_lconv_numeric_t * rc = NULL;
const char * extension = "_numeric.dat";
char * file = malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 );

Expand All @@ -30,18 +29,23 @@ bool _PDCLIB_load_lc_numeric( const char * path, const char * locale )

if ( ( fh = fopen( file, "rb" ) ) != NULL )
{
char * data = _PDCLIB_load_lines( fh, 3 );

if ( data != NULL )
if ( ( rc = malloc( sizeof( struct _PDCLIB_lc_lconv_numeric_t ) ) ) != NULL )
{
_PDCLIB_lc_numeric_monetary.numeric_alloced = 1;
_PDCLIB_lc_numeric_monetary.lconv->decimal_point = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->thousands_sep = data;
data += strlen( data ) + 1;
_PDCLIB_lc_numeric_monetary.lconv->grouping = data;

rc = true;
char * data = _PDCLIB_load_lines( fh, 3 );

if ( data != NULL )
{
rc->decimal_point = data;
data += strlen( data ) + 1;
rc->thousands_sep = data;
data += strlen( data ) + 1;
rc->grouping = data;
}
else
{
free( rc );
rc = NULL;
}
}

fclose( fh );
Expand All @@ -63,13 +67,12 @@ int main( void )
{
#ifndef REGTEST
FILE * fh = fopen( "test_numeric.dat", "wb" );
struct lconv * lc;
struct _PDCLIB_lc_lconv_numeric_t * lc;
TESTCASE( fh != NULL );
TESTCASE( fputs( ",\n.\n\n", fh ) != EOF );
fclose( fh );
TESTCASE( _PDCLIB_load_lc_numeric( "./", "test" ) );
TESTCASE( ( lc = _PDCLIB_load_lc_numeric( "./", "test" ) ) );
remove( "test_numeric.dat" );
lc = localeconv();
TESTCASE( strcmp( lc->decimal_point, "," ) == 0 );
TESTCASE( strcmp( lc->thousands_sep, "." ) == 0 );
TESTCASE( strcmp( lc->grouping, "" ) == 0 );
Expand Down
Loading

0 comments on commit 81a24c0

Please sign in to comment.