1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/templates/native/locale.c Sun Dec 11 18:07:32 2016 +0100
1.3 @@ -0,0 +1,67 @@
1.4 +/* Native functions for locale handling.
1.5 +
1.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
1.7 +
1.8 +This program is free software; you can redistribute it and/or modify it under
1.9 +the terms of the GNU General Public License as published by the Free Software
1.10 +Foundation; either version 3 of the License, or (at your option) any later
1.11 +version.
1.12 +
1.13 +This program is distributed in the hope that it will be useful, but WITHOUT
1.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.16 +details.
1.17 +
1.18 +You should have received a copy of the GNU General Public License along with
1.19 +this program. If not, see <http://www.gnu.org/licenses/>.
1.20 +*/
1.21 +
1.22 +#include <locale.h> /* setlocale */
1.23 +#include "native/common.h"
1.24 +#include "types.h"
1.25 +#include "exceptions.h"
1.26 +#include "ops.h"
1.27 +#include "progconsts.h"
1.28 +#include "progops.h"
1.29 +#include "progtypes.h"
1.30 +#include "main.h"
1.31 +
1.32 +/* Locales. */
1.33 +
1.34 +__attr __fn_native_locale_getlocale(__attr __args[])
1.35 +{
1.36 + __attr * const category = &__args[1];
1.37 + /* category interpreted as int */
1.38 + int cat = __load_via_object(category->value, __pos___data__).intvalue;
1.39 + char *result;
1.40 +
1.41 + result = setlocale(cat, NULL);
1.42 +
1.43 + if (result == NULL)
1.44 + return __builtins___none_None;
1.45 + else
1.46 + return __new_str(result);
1.47 +}
1.48 +
1.49 +__attr __fn_native_locale_setlocale(__attr __args[])
1.50 +{
1.51 + __attr * const category = &__args[1];
1.52 + __attr * const value = &__args[2];
1.53 + /* category interpreted as int */
1.54 + int cat = __load_via_object(category->value, __pos___data__).intvalue;
1.55 + /* value interpreted as string */
1.56 + char *s = __load_via_object(value->value, __pos___data__).strvalue, *result;
1.57 +
1.58 + result = setlocale(cat, s);
1.59 +
1.60 + if (result == NULL)
1.61 + return __builtins___none_None;
1.62 + else
1.63 + return __new_str(result);
1.64 +}
1.65 +
1.66 +/* Module initialisation. */
1.67 +
1.68 +void __main_native_locale()
1.69 +{
1.70 +}