ARM Technical Support Knowledge Articles

How do I customize locales?

Applies to: DS-5, RealView Development Suite (RVDS)

Answer

This FAQ describes how to customize locales using the ARM assembler and some things you must take care of. The following assembler code shows an example of customizing numeric locales:

     GET C:\Program Files\ARM\RVCT\Data\5.0\90\include\windows\rt_locale.s
     AREA my_locales, DATA, READONLY
 my_numeric_locales
     LC_NUMERIC_begin c_numeric_locale,"C"
     LC_NUMERIC_point "."
     LC_NUMERIC_thousands ""
     LC_NUMERIC_grouping ""
     LC_NUMERIC_end
     LC_NUMERIC_begin my_first_numeric_locale,"MyLocale1"
     LC_NUMERIC_point ","
     LC_NUMERIC_thousands ""
     LC_NUMERIC_grouping ""
     LC_NUMERIC_end
     LC_index_end
     AREA my_locale_func, CODE, READONLY
     EXPORT _get_lc_numeric
     IMPORT _findlocale
 _get_lc_numeric FUNCTION
     LDR r0, =my_numeric_locales
     B _findlocale
     ENDFUNC
     END

The ARM Compiler toolchain's Using the ARM C/C++ libraries_and floating point support document[1] describes how to customize your own locales. However there are some other things to take care of:

  1. Make sure that the file rt_locale.s, which has all the locale category macros, is correctly included in the customized locale assembler file

  2. If there are multiple locales implemented, you should make sure LC_index_end is used to prevent an endless loop while the function _findlocale searches for the requested locale

  3. Make sure the _get_lc_CATEGORY functions listed in rt_locale.h, for example, _get_lc_numeric, are implemented. If these are implemented with assembler, you need to export the function to be linked.

  4. If you implement your own locales and still want the standard ones, you need to re-implement the standard ones, for example, C and UTF-8, as well, since the newly implemented _get_lc_CATEGORY functions will hide the original functions thatsearches default locales.

For testing your customized locales, you can do as in the following C code does:

     char * current_locale; 

     current_locale = setlocale(LC_NUMERIC, NULL); 
     // Get the first locale name in your locale data structure.
     if(current_locale != NULL) 
     { 
          printf("1 current Numeric locale is : %s \n", current_locale); 
     } 
     printf(" (1/1234567) = %f \n", 2.0/1234567.0+3456.23);

     current_locale = setlocale(LC_NUMERIC, "MyLocale1");  
     // Set your own numeric locale, and get the current locale name.            
     if(current_locale != NULL)
     {          
          printf("2 current Numeric locale is : %s \n", current_locale);    
     }    
     printf("(1/1234567) = %f \n",2.0/1234567.0+3456.23);

Note that calling ARM C library function setlocale(LC_ALL, NULL) will return a pointer that points to a "non-human-readable" value prefixed with a *, followed by five hex-formatted pointer values, which is used as an input to another call to setlocale(). This behaviour might differ slightly to other C libraries.

C macros

It was possible to use C macros to customize locales[2] in RVCT 3.1.  However, the locale data structure must appear in a particular order, which was not easily supportable.  Therefore, this was made obsolete in RVCT 4.0 and later. Using assembler macros will lay out a data section exactly how you want it, and guarantees that all data is laid out in the the correct order. Using assembler macros is now recommended.

References:

1. Assembler macros that tailor locale functions in the C library
2. Tailoring locale and CTYPE using C macros.

Article last edited on: 2011-08-22 10:36:50

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential