summaryrefslogtreecommitdiff
path: root/src/locale
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
commit7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch)
tree092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/locale
parent6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff)
merge sources into single tree
Diffstat (limited to 'src/locale')
-rw-r--r--src/locale/LC_ALL.c12
-rw-r--r--src/locale/LC_COLLATE.c12
-rw-r--r--src/locale/LC_CTYPE.c13
-rw-r--r--src/locale/LC_MONETARY.c12
-rw-r--r--src/locale/LC_NUMERIC.c13
-rw-r--r--src/locale/LC_TIME.c12
-rw-r--r--src/locale/NULL.ref3
-rw-r--r--src/locale/localeconv.c63
-rw-r--r--src/locale/setlocale.c107
-rw-r--r--src/locale/struct_lconv.c65
10 files changed, 312 insertions, 0 deletions
diff --git a/src/locale/LC_ALL.c b/src/locale/LC_ALL.c
new file mode 100644
index 00000000..164a18ae
--- /dev/null
+++ b/src/locale/LC_ALL.c
@@ -0,0 +1,12 @@
+#include <locale.h>
+#define LC_ALL (0)
+
+/** all locale categories **/
+
+/***
+is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate
+on all categories of the current locale.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/locale/LC_COLLATE.c b/src/locale/LC_COLLATE.c
new file mode 100644
index 00000000..2708525c
--- /dev/null
+++ b/src/locale/LC_COLLATE.c
@@ -0,0 +1,12 @@
+#include <locale.h>
+#define LC_COLLATE (1)
+
+/** locale collation category **/
+
+/***
+is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate
+on the portion of the locale that affects sorting and collating strings.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/locale/LC_CTYPE.c b/src/locale/LC_CTYPE.c
new file mode 100644
index 00000000..9095cf60
--- /dev/null
+++ b/src/locale/LC_CTYPE.c
@@ -0,0 +1,13 @@
+#include <locale.h>
+#define LC_CTYPE (2)
+
+/** locale character handling category **/
+
+/***
+is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate
+on the portion of the locale that affects classifying and transforming
+individual characters.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/locale/LC_MONETARY.c b/src/locale/LC_MONETARY.c
new file mode 100644
index 00000000..cdc94832
--- /dev/null
+++ b/src/locale/LC_MONETARY.c
@@ -0,0 +1,12 @@
+#include <locale.h>
+#define LC_MONETARY (3)
+
+/** locale monetary formatting category **/
+
+/***
+is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate
+on the portion of the locale that affects formatting monetary values.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/locale/LC_NUMERIC.c b/src/locale/LC_NUMERIC.c
new file mode 100644
index 00000000..80459086
--- /dev/null
+++ b/src/locale/LC_NUMERIC.c
@@ -0,0 +1,13 @@
+#include <locale.h>
+#define LC_NUMERIC (4)
+
+/** locale number formatting category **/
+
+/***
+is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate
+on the portion of the locale that affects formatting numeric values, except
+for monetary values.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/locale/LC_TIME.c b/src/locale/LC_TIME.c
new file mode 100644
index 00000000..e3e70662
--- /dev/null
+++ b/src/locale/LC_TIME.c
@@ -0,0 +1,12 @@
+#include <locale.h>
+#define LC_TIME (5)
+
+/** locale time formatting category **/
+
+/***
+is used as the ARGUMENT(category) in a call to FUNCTION(setlocale) to operate
+on the portion of the locale that affects formatting date and time values.
+***/
+/*
+STDC(1)
+*/
diff --git a/src/locale/NULL.ref b/src/locale/NULL.ref
new file mode 100644
index 00000000..e1d480f2
--- /dev/null
+++ b/src/locale/NULL.ref
@@ -0,0 +1,3 @@
+#include <locale.h>
+REFERENCE(stddef/NULL.c)
+STDC(1)
diff --git a/src/locale/localeconv.c b/src/locale/localeconv.c
new file mode 100644
index 00000000..f767153c
--- /dev/null
+++ b/src/locale/localeconv.c
@@ -0,0 +1,63 @@
+#include <locale.h>
+#include "string.h"
+#include "limits.h"
+
+/** return locale-specific information **/
+struct lconv * localeconv(void)
+{
+ static struct lconv lc;
+
+ char *monetary = setlocale(LC_MONETARY, NULL);
+ char *numeric = setlocale(LC_NUMERIC, NULL);
+
+ if (!strcmp(monetary, "C") || !strcmp(monetary, "POSIX")) {
+ lc.int_curr_symbol = "";
+ lc.currency_symbol = "";
+ lc.mon_decimal_point = "";
+ lc.grouping = "";
+ lc.mon_thousands_sep = "";
+ lc.mon_grouping = "";
+ lc.positive_sign = "";
+ lc.negative_sign = "";
+ lc.int_frac_digits = CHAR_MAX;
+ lc.frac_digits = CHAR_MAX;
+ lc.p_cs_precedes = CHAR_MAX;
+ lc.p_sep_by_space = CHAR_MAX;
+ lc.n_cs_precedes = CHAR_MAX;
+ lc.n_sep_by_space = CHAR_MAX;
+ lc.p_sign_posn = CHAR_MAX;
+ lc.n_sign_posn = CHAR_MAX;
+
+ #if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199909L)
+ lc.int_p_cs_precedes = CHAR_MAX;
+ lc.int_p_sep_by_space = CHAR_MAX;
+ lc.int_n_cs_precedes = CHAR_MAX;
+ lc.int_n_sep_by_space = CHAR_MAX;
+ lc.int_p_sign_posn = CHAR_MAX;
+ lc.int_n_sign_posn = CHAR_MAX;
+ #endif
+ }
+
+ if (!strcmp(numeric, "C") || !strcmp(numeric, "POSIX")) {
+ lc.decimal_point = "";
+ lc.thousands_sep = "";
+ }
+
+ /*
+ RETURN_SUCCESS(a pointer to a filled-in STRUCTDEF(lconv) for the current locale);
+ */
+ return &lc;
+}
+
+/***
+fills in a STRUCTDEF(lconv) in the current locale for
+use in formatting numbers and monetary values.
+***/
+
+/*
+LC_MONETARY
+LC_NUMERIC
+*/
+/*
+STDC(1)
+*/
diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c
new file mode 100644
index 00000000..0f64b35e
--- /dev/null
+++ b/src/locale/setlocale.c
@@ -0,0 +1,107 @@
+#include <locale.h>
+#include "string.h"
+#include "stdlib.h"
+
+char * setlocale(int category, const char *locale)
+{
+ static struct {
+ char *lc_collate;
+ char *lc_ctype;
+ char *lc_messages;
+ char *lc_monetary;
+ char *lc_numeric;
+ char *lc_time;
+ } current = { 0 };
+
+ char *desired = NULL;
+
+ switch (category) {
+ case LC_COLLATE: desired = current.lc_collate; break;
+ case LC_CTYPE: desired = current.lc_ctype; break;
+ case LC_MONETARY: desired = current.lc_monetary; break;
+ case LC_NUMERIC: desired = current.lc_numeric; break;
+ case LC_TIME: desired = current.lc_time; break;
+ #ifdef LC_MESSAGES
+ case LC_MESSAGES: desired = current.lc_messages; break;
+ #endif
+ default: break;
+ }
+
+ if (locale == NULL) {
+ if (category == LC_ALL) {
+ /* build a string if locale is not heterogenous */
+ }
+ return desired;
+ }
+
+ if (category == LC_ALL) {
+ /* TODO: make sure all these can be honored */
+ #ifdef LC_MESSAGES
+ setlocale(LC_MESSAGES, locale);
+ #endif
+ setlocale(LC_COLLATE, locale);
+ setlocale(LC_CTYPE, locale);
+ setlocale(LC_MONETARY, locale);
+ setlocale(LC_NUMERIC, locale);
+ return setlocale(LC_TIME, locale);
+ }
+
+ if (desired) {
+ free(desired);
+ }
+
+ if (!strcmp(locale, "")) {
+ desired = getenv("");
+ } else {
+ desired = (char*)locale;
+ }
+
+ return desired;
+}
+
+/** get or set program locale **/
+
+/***
+sets or retrieves the current global locale of the
+program. The program locale has global effects of various operations, based
+on ARGUMENT(category):
+
+FLAG(CONSTANT(LC_COLLATE),
+ `Affects regular expression, and string collation.')
+FLAG(CONSTANT(LC_CTYPE),
+ `Affects regular expressions, character classification, and character conversion.')
+FLAG(CONSTANT(LC_MESSAGES),
+ `On POSIX systems, affects how message catalogs are found and the format
+ of affirmative and negative responses. The format of strings written
+ or returned by library functions may also be affected.')
+FLAG(CONSTANT(LC_MONETARY),
+ `Affects functions that convert monetary values.')
+FLAG(CONSTANT(LC_NUMERIC),
+ `Affects functions that convert non-monetary numeric valus.')
+FLAG(CONSTANT(LC_TIME),
+ `Affects functions that convert time.')
+
+Specifying CONSTANT(LC_ALL) for ARGUMENT(category) will change the current global locale
+for all of the above categories.
+
+Specifying CONSTANT(NULL) for ARGUMENT(locale) will not change anything, and will simply
+return the current globale locale for ARGUMENT(category).
+
+Specifying empty() for ARGUMENT(locale) will set ARGUMENT(category) to an
+implementation-defined native environment.
+
+All conformant systems support the locale(C), which is a minimal locale required
+to support std(C).
+
+All POSIX systems support the locale(POSIX), which is a minimal locale required
+to support std(POSIX).
+***/
+
+/*
+RETURN(CONSTANT(NULL), the request could not be honored)
+RETURN(NONNULL, the current locale name for ARGUMENT(category))
+IMPLEMENTATION(The native environment)
+*/
+/*
+STDC(1)
+*/
diff --git a/src/locale/struct_lconv.c b/src/locale/struct_lconv.c
new file mode 100644
index 00000000..6f71fa20
--- /dev/null
+++ b/src/locale/struct_lconv.c
@@ -0,0 +1,65 @@
+#include <locale.h>
+struct lconv {
+ /** The character that separates the whole and decimal portions of non-monetary values **/
+ char *decimal_point; /* "." */
+ /** The character that separates groups of digits in the whole portion of non-monetary values **/
+ char *thousands_sep; /* "" */
+ /** A string indicating how to group digits of monetary values */
+ char *grouping; /* "" */
+ /** The three character ISO 4217 currency symbol of the current locale, followed by a fourth separating character **/
+ char *int_curr_symbol; /* "" */
+ /** The locale currency symbol in the current locale **/
+ char *currency_symbol; /* "" */
+ /** The character used for decimal points in monetary values **/
+ char *mon_decimal_point; /* "" */
+ /** The character separating digit groups in monetary values **/
+ char *mon_thousands_sep; /* "" */
+ /** A string indicating how to group digits in monetary values **/
+ char *mon_grouping; /* "" */
+ /** A string to indicate positive monetary values **/
+ char *positive_sign; /* "" */
+ /** A string to indicate negative monetary values **/
+ char *negative_sign; /* "" */
+ /** The number of digits after the decimal point in international monetary values **/
+ char int_frac_digits; /* CHAR_MAX */
+ /** The number of digits after the decimal point in monetary values **/
+ char frac_digits; /* CHAR_MAX */
+ /** Whether field(currency_symbol) precedes (1) or follows (0) positive monetary values **/
+ char p_cs_precedes; /* CHAR_MAX */
+ /** Whether field(currency_symbol) is (1) or is not (0) separated from positive monetary values by a space **/
+ char p_sep_by_space; /* CHAR_MAX */
+ /** Whether field(currency_symbol) precedes (1) or follows (0) negative monetary values **/
+ char n_cs_precedes; /* CHAR_MAX */
+ /** Whether field(currency_symbol) is (1) or is not(0) separated from negative monetary values by a space **/
+ char n_sep_by_space; /* CHAR_MAX */
+ /** The position of field(positive_sign) for positive monetary values **/
+ char p_sign_posn; /* CHAR_MAX */
+ /** The position of field(positive_sign) for negative monetary values **/
+ char n_sign_posn; /* CHAR_MAX */
+ #if __STDC_VERSION__ >= 199901L
+ /** Whether field(currency_symbol) precedes (1) or follows (0) positive international monetary values **/
+ char int_p_cs_precedes; /* CHAR_MAX */
+ /** Whether field(currency_symbol) is (1) or is not (0) separated from positive international monetary values by a space **/
+ char int_p_sep_by_space; /* CHAR_MAX */
+ /** Whether field(currency_symbol) precedes (1) or follows (0) negative international monetary values **/
+ char int_n_cs_precedes; /* CHAR_MAX */
+ /** Whether field(currency_symbol) is (1) or is not(0) separated from negative international monetary values by a space **/
+ char int_n_sep_by_space; /* CHAR_MAX */
+ /** The position of field(positive_sign) for positive international monetary values **/
+ char int_p_sign_posn; /* CHAR_MAX */
+ /** The position of field(positive_sign) for negative international monetary values **/
+ char int_n_sign_posn; /* CHAR_MAX */
+ #else
+ char __int_p_cs_precedes;
+ char __int_p_sep_by_space;
+ char __int_n_cs_precedes;
+ char __int_n_sep_by_space;
+ char __int_p_sign_posn;
+ char __int_n_sign_posn;
+ #endif
+};
+
+/* values specified in comments are for the "C" locale */
+/*
+STDC(1)
+*/