From 69315080f1665373a1753c351fee1251af0545a4 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Thu, 28 Feb 2019 14:16:05 -0500 Subject: clean up internal namespace --- src/nonstd/__load_locale.h | 111 ++++++++++++++++++++++++++++++++++++++++ src/nonstd/ctype-internal.ref | 2 + src/nonstd/ctype_t.c | 22 ++++---- src/nonstd/nonstd-inernal.ref | 2 - src/nonstd/syscall-internal.ref | 2 + 5 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 src/nonstd/__load_locale.h create mode 100644 src/nonstd/ctype-internal.ref delete mode 100644 src/nonstd/nonstd-inernal.ref create mode 100644 src/nonstd/syscall-internal.ref (limited to 'src/nonstd') diff --git a/src/nonstd/__load_locale.h b/src/nonstd/__load_locale.h new file mode 100644 index 00000000..16709870 --- /dev/null +++ b/src/nonstd/__load_locale.h @@ -0,0 +1,111 @@ +#include +#include +#include +#include + +#include "nonstd/locale.h" +#include "nonstd/ctype.h" + +#define LC_COLLATE_MASK (1<<0) +#define LC_CTYPE_MASK (1<<1) +#define LC_MONETARY_MASK (1<<2) +#define LC_NUMERIC_MASK (1<<3) +#define LC_TIME_MASK (1<<4) +#define LC_MESSAGES_MASK (1<<5) + +#define stringreplace(_old, _new) do { \ + _old = realloc(_old, strlen(_new) + 1); \ + if (_old == NULL) { \ + return NULL; \ + } \ + strcpy(_old, _new); \ +} while (0) + +char * __load_locale(struct __locale_t *loc, int mask, const char *name) +{ + char localepath[FILENAME_MAX] = "/lib/locale/"; + strcat(localepath, name); + + FILE *localefile = fopen(localepath, "rb"); + if (localefile == NULL && strcmp(name, "C") && strcmp(name, "POSIX")) { + return NULL; + } + + if (mask & LC_COLLATE_MASK) { + stringreplace(loc->collate, name); + + /* read from file */ + loc->collation = NULL; + } + + if (mask & LC_CTYPE_MASK) { + stringreplace(loc->ctype, name); + + if (localefile == NULL) { + int i; + loc->ctattr = realloc(loc->ctattr, CHAR_MAX); + + for (i = 0; i < 32; i++) { + loc->ctattr[i] = CNTRL; + } + for (i = 'a'; i < 'z'; i++) { + loc->ctattr[i] = LOWER; + } + for (i = 'A'; i < 'Z'; i++) { + loc->ctattr[i] = UPPER; + } + for (i = '0'; i < '9'; i++) { + loc->ctattr[i] = DIGIT | XDIGIT; + } + /* others */ + + loc->ctoupper = realloc(loc->ctoupper, CHAR_MAX); + for (i = 0; i < CHAR_MAX; i++) { + loc->ctoupper[i] = ('a' <= i && i <= 'z') ? i + 32 : i; + } + + loc->ctolower = realloc(loc->ctolower, CHAR_MAX); + for (i = 0; i < CHAR_MAX; i++) { + loc->ctolower[i] = ('A' <= i && i <= 'Z') ? i - 32 : i; + } + } else { + /* read from file */ + loc->ctattr = NULL; + loc->ctoupper = NULL; + loc->ctolower = NULL; + } + } + + if (mask & LC_MONETARY_MASK) { + stringreplace(loc->monetary, name); + + /* + loc->mn.monetary fields; + */ + } + + if (mask & LC_NUMERIC_MASK) { + stringreplace(loc->numeric, name); + + /* + loc->mn.numeric fields + */ + } + + if (mask & LC_TIME_MASK) { + stringreplace(loc->time, name); + + /* read from file */ + /* loc->lc_time */ + } + + if (mask & LC_MESSAGES_MASK) { + stringreplace(loc->messages, name); + + /* read */ + loc->lc_messages.yesexpr = NULL; + loc->lc_messages.noexpr = NULL; + } + + return name; +} diff --git a/src/nonstd/ctype-internal.ref b/src/nonstd/ctype-internal.ref new file mode 100644 index 00000000..3412e61c --- /dev/null +++ b/src/nonstd/ctype-internal.ref @@ -0,0 +1,2 @@ +#include +REFERENCE() diff --git a/src/nonstd/ctype_t.c b/src/nonstd/ctype_t.c index 468214b1..dad5568f 100644 --- a/src/nonstd/ctype_t.c +++ b/src/nonstd/ctype_t.c @@ -1,15 +1,15 @@ #include typedef enum { - ALPHA = (1 << 0), - CNTRL = (1 << 1), - DIGIT = (1 << 2), - GRAPH = (1 << 3), - LOWER = (1 << 4), - PRINT = (1 << 5), - PUNCT = (1 << 6), - SPACE = (1 << 7), - UPPER = (1 << 8), - XDIGIT = (1 << 9), - BLANK = (1 << 10), + CT_ALPHA = (1 << 0), + CT_CNTRL = (1 << 1), + CT_DIGIT = (1 << 2), + CT_GRAPH = (1 << 3), + CT_LOWER = (1 << 4), + CT_PRINT = (1 << 5), + CT_PUNCT = (1 << 6), + CT_SPACE = (1 << 7), + CT_UPPER = (1 << 8), + CT_XDIGIT = (1 << 9), + CT_BLANK = (1 << 10), } ctype_t; diff --git a/src/nonstd/nonstd-inernal.ref b/src/nonstd/nonstd-inernal.ref deleted file mode 100644 index 839537f1..00000000 --- a/src/nonstd/nonstd-inernal.ref +++ /dev/null @@ -1,2 +0,0 @@ -#include -REFERENCE() diff --git a/src/nonstd/syscall-internal.ref b/src/nonstd/syscall-internal.ref new file mode 100644 index 00000000..839537f1 --- /dev/null +++ b/src/nonstd/syscall-internal.ref @@ -0,0 +1,2 @@ +#include +REFERENCE() -- cgit v1.2.1