paul@375 | 1 | /* Native functions for locale handling. |
paul@375 | 2 | |
paul@375 | 3 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@375 | 4 | |
paul@375 | 5 | This program is free software; you can redistribute it and/or modify it under |
paul@375 | 6 | the terms of the GNU General Public License as published by the Free Software |
paul@375 | 7 | Foundation; either version 3 of the License, or (at your option) any later |
paul@375 | 8 | version. |
paul@375 | 9 | |
paul@375 | 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@375 | 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@375 | 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@375 | 13 | details. |
paul@375 | 14 | |
paul@375 | 15 | You should have received a copy of the GNU General Public License along with |
paul@375 | 16 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@375 | 17 | */ |
paul@375 | 18 | |
paul@375 | 19 | #include <locale.h> /* setlocale */ |
paul@375 | 20 | #include "native/common.h" |
paul@375 | 21 | #include "types.h" |
paul@375 | 22 | #include "exceptions.h" |
paul@375 | 23 | #include "ops.h" |
paul@375 | 24 | #include "progconsts.h" |
paul@375 | 25 | #include "progops.h" |
paul@375 | 26 | #include "progtypes.h" |
paul@375 | 27 | #include "main.h" |
paul@375 | 28 | |
paul@375 | 29 | /* Locales. */ |
paul@375 | 30 | |
paul@375 | 31 | __attr __fn_native_locale_getlocale(__attr __args[]) |
paul@375 | 32 | { |
paul@375 | 33 | __attr * const category = &__args[1]; |
paul@375 | 34 | /* category interpreted as int */ |
paul@375 | 35 | int cat = __load_via_object(category->value, __pos___data__).intvalue; |
paul@375 | 36 | char *result; |
paul@375 | 37 | |
paul@375 | 38 | result = setlocale(cat, NULL); |
paul@375 | 39 | |
paul@375 | 40 | if (result == NULL) |
paul@375 | 41 | return __builtins___none_None; |
paul@375 | 42 | else |
paul@375 | 43 | return __new_str(result); |
paul@375 | 44 | } |
paul@375 | 45 | |
paul@375 | 46 | __attr __fn_native_locale_setlocale(__attr __args[]) |
paul@375 | 47 | { |
paul@375 | 48 | __attr * const category = &__args[1]; |
paul@375 | 49 | __attr * const value = &__args[2]; |
paul@375 | 50 | /* category interpreted as int */ |
paul@375 | 51 | int cat = __load_via_object(category->value, __pos___data__).intvalue; |
paul@375 | 52 | /* value interpreted as string */ |
paul@375 | 53 | char *s = __load_via_object(value->value, __pos___data__).strvalue, *result; |
paul@375 | 54 | |
paul@375 | 55 | result = setlocale(cat, s); |
paul@375 | 56 | |
paul@375 | 57 | if (result == NULL) |
paul@375 | 58 | return __builtins___none_None; |
paul@375 | 59 | else |
paul@375 | 60 | return __new_str(result); |
paul@375 | 61 | } |
paul@375 | 62 | |
paul@375 | 63 | /* Module initialisation. */ |
paul@375 | 64 | |
paul@375 | 65 | void __main_native_locale() |
paul@375 | 66 | { |
paul@375 | 67 | } |