diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-02-28 14:16:05 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-02-28 14:16:05 -0500 |
commit | 69315080f1665373a1753c351fee1251af0545a4 (patch) | |
tree | 61c6592146afeade2ad57d9e930a341510b571ae | |
parent | 80548c779ba2302b2a4256f15d6e5f66b5dcfb18 (diff) |
clean up internal namespace
-rw-r--r-- | src/ctype/isblank.c | 3 | ||||
-rw-r--r-- | src/ctype/iscntrl.c | 3 | ||||
-rw-r--r-- | src/ctype/isgraph.c | 3 | ||||
-rw-r--r-- | src/ctype/islower.c | 3 | ||||
-rw-r--r-- | src/ctype/isprint.c | 3 | ||||
-rw-r--r-- | src/ctype/ispunct.c | 3 | ||||
-rw-r--r-- | src/ctype/isspace.c | 3 | ||||
-rw-r--r-- | src/ctype/isupper.c | 3 | ||||
-rw-r--r-- | src/ctype/isxdigit.c | 3 | ||||
-rw-r--r-- | src/ctype/tolower.c | 1 | ||||
-rw-r--r-- | src/ctype/toupper.c | 2 | ||||
-rw-r--r-- | src/nonstd/__load_locale.h | 111 | ||||
-rw-r--r-- | src/nonstd/ctype-internal.ref | 2 | ||||
-rw-r--r-- | src/nonstd/ctype_t.c | 22 | ||||
-rw-r--r-- | src/nonstd/syscall-internal.ref (renamed from src/nonstd/nonstd-inernal.ref) | 0 | ||||
-rw-r--r-- | src/wctype/wctrans.c | 4 | ||||
-rw-r--r-- | src/wctype/wctype.c | 22 |
17 files changed, 147 insertions, 44 deletions
diff --git a/src/ctype/isblank.c b/src/ctype/isblank.c index 1a597f82..2b48b67f 100644 --- a/src/ctype/isblank.c +++ b/src/ctype/isblank.c @@ -2,7 +2,6 @@ #include "limits.h" #include "locale.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" #include "nonstd/assert.h" /** test whether a character is blank **/ @@ -12,7 +11,7 @@ int isblank(int c) unsigned int *map = __libc(CTYPE); - return map[c] & BLANK; + return map[c] & CT_BLANK; } /*** diff --git a/src/ctype/iscntrl.c b/src/ctype/iscntrl.c index 31804123..eead7f5f 100644 --- a/src/ctype/iscntrl.c +++ b/src/ctype/iscntrl.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is a control character */ int iscntrl(int c) @@ -15,7 +14,7 @@ int iscntrl(int c) RETURN(0, ARGUMENT(c) is not a control character); */ - return map[c] == 0 || (map[c] == SPACE && c != ' '); + return map[c] == 0 || (map[c] == CT_SPACE && c != ' '); } /*** diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c index 8ad3be0b..206a09b7 100644 --- a/src/ctype/isgraph.c +++ b/src/ctype/isgraph.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is graphic **/ int isgraph(int c) @@ -15,7 +14,7 @@ int isgraph(int c) RETURN(0, ARGUMENT(c) is not a graphic character); */ - return map[c] & ~SPACE; + return map[c] & ~CT_SPACE; } /*** diff --git a/src/ctype/islower.c b/src/ctype/islower.c index 082697dd..6b4764d8 100644 --- a/src/ctype/islower.c +++ b/src/ctype/islower.c @@ -1,7 +1,6 @@ #include <ctype.h> #include "limits.h" #include "nonstd/assert.h" -#include "nonstd/internal.h" #include "nonstd/ctype.h" /** test whether a character is a lowercase letter **/ @@ -14,7 +13,7 @@ int islower(int c) RETURN(NONZERO, ARGUMENT(c) is a lowercase letter); RETURN(0, ARGUMENT(c) is not a lowercase letter); */ - return map[c] & LOWER; + return map[c] & CT_LOWER; } /*** diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c index 58120351..19847118 100644 --- a/src/ctype/isprint.c +++ b/src/ctype/isprint.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is printable **/ int isprint(int c) @@ -15,7 +14,7 @@ int isprint(int c) RETURN(0, ARGUMENT(c) is not a printable character); */ - return map[c] & ~SPACE || c == ' '; + return map[c] & ~CT_SPACE || c == ' '; } /*** diff --git a/src/ctype/ispunct.c b/src/ctype/ispunct.c index bad66523..8a0cd118 100644 --- a/src/ctype/ispunct.c +++ b/src/ctype/ispunct.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is punctuation **/ int ispunct(int c) @@ -15,7 +14,7 @@ int ispunct(int c) RETURN(0, ARGUMENT(c) is not a punctuation character); */ - return map[c] & PUNCT; + return map[c] & CT_PUNCT; } /*** diff --git a/src/ctype/isspace.c b/src/ctype/isspace.c index a83cb584..79aa9673 100644 --- a/src/ctype/isspace.c +++ b/src/ctype/isspace.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is white-space **/ int isspace(int c) @@ -15,7 +14,7 @@ int isspace(int c) RETURN(0, ARGUMENT(c) is not a white-space character); */ - return map[c] & SPACE; + return map[c] & CT_SPACE; } /*** diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c index 84247c28..0d3e7240 100644 --- a/src/ctype/isupper.c +++ b/src/ctype/isupper.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is an uppercase letter **/ int isupper(int c) @@ -15,7 +14,7 @@ int isupper(int c) RETURN(0, ARGUMENT(c) is not an uppercase letter); */ - return map[c] & UPPER; + return map[c] & CT_UPPER; } /*** diff --git a/src/ctype/isxdigit.c b/src/ctype/isxdigit.c index 37857d92..30ddd618 100644 --- a/src/ctype/isxdigit.c +++ b/src/ctype/isxdigit.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** test whether a character is a hexadecimal digit **/ int isxdigit(int c) @@ -14,7 +13,7 @@ int isxdigit(int c) RETURN(NONZERO, ARGUMENT(c) is a hexadecimal digit); RETURN(0, ARGUMENT(c) is not a hexadecimal digit); */ - return map[c] & XDIGIT; + return map[c] & CT_XDIGIT; } /*** diff --git a/src/ctype/tolower.c b/src/ctype/tolower.c index b684eb7a..793de6bb 100644 --- a/src/ctype/tolower.c +++ b/src/ctype/tolower.c @@ -2,7 +2,6 @@ #include "limits.h" #include "nonstd/assert.h" #include "nonstd/ctype.h" -#include "nonstd/internal.h" /** convert an uppercase letter to lowercase **/ int tolower(int c) diff --git a/src/ctype/toupper.c b/src/ctype/toupper.c index f4611bc7..35b7c9e2 100644 --- a/src/ctype/toupper.c +++ b/src/ctype/toupper.c @@ -1,7 +1,7 @@ #include <ctype.h> #include "limits.h" #include "nonstd/assert.h" -#include "nonstd/internal.h" +#include "nonstd/ctype.h" /** convert a lowercase letter to uppercase **/ int toupper(int c) 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 <locale.h> +#include <limits.h> +#include <stdio.h> +#include <string.h> + +#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 <nonstd/ctype.h> +REFERENCE(<nonstd/internal.h>) 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 <nonstd/ctype.h> 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/syscall-internal.ref index 839537f1..839537f1 100644 --- a/src/nonstd/nonstd-inernal.ref +++ b/src/nonstd/syscall-internal.ref diff --git a/src/wctype/wctrans.c b/src/wctype/wctrans.c index 54a6e211..eb51e112 100644 --- a/src/wctype/wctrans.c +++ b/src/wctype/wctrans.c @@ -9,9 +9,9 @@ wctrans_t wctrans(const char * property) ASSERT_NONNULL(property); if (!strcmp(property, "tolower")) { - return LOWER; + return CT_LOWER; } else if (!strcmp(property, "toupper")) { - return UPPER; + return CT_UPPER; } return 0; diff --git a/src/wctype/wctype.c b/src/wctype/wctype.c index 1b27af1d..cad10dae 100644 --- a/src/wctype/wctype.c +++ b/src/wctype/wctype.c @@ -9,27 +9,27 @@ wctype_t wctype(const char * property) ASSERT_NONNULL(property); if (!strcmp(property, "alnum")) { - return ALPHA | DIGIT; + return CT_ALPHA | CT_DIGIT; } else if (!strcmp(property, "alpha")) { - return ALPHA; + return CT_ALPHA; } else if (!strcmp(property, "cntrl")) { - return CNTRL; + return CT_CNTRL; } else if (!strcmp(property, "digit")) { - return DIGIT; + return CT_DIGIT; } else if (!strcmp(property, "graph")) { - return GRAPH; + return CT_GRAPH; } else if (!strcmp(property, "lower")) { - return LOWER; + return CT_LOWER; } else if (!strcmp(property, "print")) { - return PRINT; + return CT_PRINT; } else if (!strcmp(property, "punct")) { - return PUNCT; + return CT_PUNCT; } else if (!strcmp(property, "space")) { - return SPACE; + return CT_SPACE; } else if (!strcmp(property, "upper")) { - return UPPER; + return CT_UPPER; } else if (!strcmp(property, "xdigit")) { - return XDIGIT; + return CT_XDIGIT; } return 0; |