diff options
Diffstat (limited to 'src/nonstd')
| -rw-r--r-- | src/nonstd/ASSERT_NONNULL.c | 14 | ||||
| -rw-r--r-- | src/nonstd/ASSERT_NONZERO.c | 14 | ||||
| -rw-r--r-- | src/nonstd/ASSERT_NOOVERLAP.c | 9 | ||||
| -rw-r--r-- | src/nonstd/ASSERT_REPRESENTABLE.c | 21 | ||||
| -rw-r--r-- | src/nonstd/LIBC_INTERNAL.c | 17 | ||||
| -rw-r--r-- | src/nonstd/__libc.c | 10 | ||||
| -rw-r--r-- | src/nonstd/__libc_per_thread.c | 4 | ||||
| -rw-r--r-- | src/nonstd/__load_locale.c | 4 | ||||
| -rw-r--r-- | src/nonstd/_locale.h | 235 | ||||
| -rw-r--r-- | src/nonstd/locale-internal.ref | 2 | ||||
| -rw-r--r-- | src/nonstd/locale-limits.ref | 2 | ||||
| -rw-r--r-- | src/nonstd/locale-locale.ref | 2 | ||||
| -rw-r--r-- | src/nonstd/struct_locale_t.c | 57 |
13 files changed, 4 insertions, 387 deletions
diff --git a/src/nonstd/ASSERT_NONNULL.c b/src/nonstd/ASSERT_NONNULL.c deleted file mode 100644 index 26a6138e..00000000 --- a/src/nonstd/ASSERT_NONNULL.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <nonstd/assert.h> - -#ifndef NDEBUG -#define ASSERT_NONNULL(__ptr) do { \ - if (!__ptr) { \ - struct __constraint_info _ci = {0}; \ - _ci.func = __func__; \ - __libc.stdlib.constraint_handler("Undefined behavior: " \ - "Parameter " #__ptr " can not be NULL", &_ci, EFAULT); \ - } \ - } while (0) -#else -#define ASSERT_NONNULL(x) -#endif diff --git a/src/nonstd/ASSERT_NONZERO.c b/src/nonstd/ASSERT_NONZERO.c deleted file mode 100644 index e48e775a..00000000 --- a/src/nonstd/ASSERT_NONZERO.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <nonstd/assert.h> - -#ifndef NDEBUG -#define ASSERT_NONZERO(__n) do { \ - if (!__n) { \ - struct __constraint_info _ci = {0}; \ - _ci.func = __func__; \ - __libc.stdlib.constraint_handler("Undefined behavior: " \ - "Parameter " #__n " can not be 0", &_ci, ERANGE); \ - } \ - } while (0) -#else -#define ASSERT_NONZERO(n) -#endif diff --git a/src/nonstd/ASSERT_NOOVERLAP.c b/src/nonstd/ASSERT_NOOVERLAP.c deleted file mode 100644 index 7173752d..00000000 --- a/src/nonstd/ASSERT_NOOVERLAP.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <nonstd/assert.h> - -#ifndef NDEBUG -#define ASSERT_NOOVERLAP(__x, __y, __s) do { \ - /* TODO */ \ - } while (0) -#else -#define ASSERT_NOOVERLAP(__x, __y, __s) -#endif diff --git a/src/nonstd/ASSERT_REPRESENTABLE.c b/src/nonstd/ASSERT_REPRESENTABLE.c deleted file mode 100644 index 0067d9b4..00000000 --- a/src/nonstd/ASSERT_REPRESENTABLE.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <nonstd/assert.h> - -#ifndef NDEBUG -#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel) do { \ - if (_sentinel && (_n != _sentinel && (_n < _min || _n > _max))) { \ - struct __constraint_info _ci = {0}; \ - _ci.func = __func__; \ - __libc.stdlib.constraint_handler("Undefined behavior: " \ - "Paramater " #_n " must be representable as a " #_type \ - "or be equal to " #_sentinel, &_ci, ERANGE); \ - } else if (_n < _min || _n > _max) { \ - struct __constraint_info _ci = {0}; \ - _ci.func = __func__; \ - __libc.stdlib.constraint_handler("Undefined behavior: " \ - "Parameter " #_n " must be representable as a " #_type, \ - &_ci, ERANGE); \ - } \ - } while (0) -#else -#define ASSERT_REPRESENTABLE(_n, _min, _max, _type, _sentinel) -#endif diff --git a/src/nonstd/LIBC_INTERNAL.c b/src/nonstd/LIBC_INTERNAL.c deleted file mode 100644 index a00a0c98..00000000 --- a/src/nonstd/LIBC_INTERNAL.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <nonstd/internal.h> - -typedef enum { - /* errno.h */ - ERRNO, - - /* locale.h */ - THREAD_LOCALE, - GLOBAL_LOCALE, - LCONV, - LOAD_LOCALE, - - /* [w]ctype.h */ - CTYPE, - TOLOWER, - TOUPPER, -} LIBC_INTERNAL; diff --git a/src/nonstd/__libc.c b/src/nonstd/__libc.c index 752dcab0..9000dd46 100644 --- a/src/nonstd/__libc.c +++ b/src/nonstd/__libc.c @@ -1,10 +1,8 @@ #include "sys/types.h" -#include <nonstd/internal.h> -#include "nonstd/locale.h" +#include "../_nonstd.h" +#include "../locale/_locale.h" #include "../stdio/_stdio.h" -#include "_locale.h" - void *__libc(LIBC_INTERNAL variable) { extern void *__libc_per_thread(LIBC_INTERNAL __variable); @@ -59,10 +57,6 @@ void *__libc(LIBC_INTERNAL variable) r = &(((struct __locale_t*)r)->mn); break; - case LOAD_LOCALE: - r = (void*)(__load_locale); - break; - default: break; } diff --git a/src/nonstd/__libc_per_thread.c b/src/nonstd/__libc_per_thread.c index 15156c6e..38c7c610 100644 --- a/src/nonstd/__libc_per_thread.c +++ b/src/nonstd/__libc_per_thread.c @@ -1,6 +1,6 @@ -#include "nonstd/internal.h" +#include "../_nonstd.h" #include "locale.h" -#include "nonstd/locale.h" +#include "../locale/_locale.h" #if defined __STDC_VERSION__ && 201112L <= __STDC_VERSION__ && !defined __STDC_NO_THREADS__ #define THREAD_LOCAL static _Thread_local diff --git a/src/nonstd/__load_locale.c b/src/nonstd/__load_locale.c deleted file mode 100644 index 2233e6b8..00000000 --- a/src/nonstd/__load_locale.c +++ /dev/null @@ -1,4 +0,0 @@ -#include <nonstd/locale.h> - -#define __load_locale(_loc, _mask, _name) \ - ((char * (*)(struct __locale_t *, int, const char *))__libc(LOAD_LOCALE))(_loc, _mask, _name) diff --git a/src/nonstd/_locale.h b/src/nonstd/_locale.h deleted file mode 100644 index be692e87..00000000 --- a/src/nonstd/_locale.h +++ /dev/null @@ -1,235 +0,0 @@ -#include <locale.h> -#include <limits.h> -#include <stdio.h> -#include <string.h> - -#include "nonstd/locale.h" -#include "../ctype/_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 LC_ALL_MASK (0xff) - -#define setall(_map, _input, _mask) do { \ - size_t _i; \ - for (_i = 0; _i < sizeof(_input) - 1; _i++) { \ - _map[(int)_input[_i]] |= _mask; \ - } \ -} while (0) - -static char * (__load_locale)(struct __locale_t *loc, int mask, const char *name) -{ - if (name == NULL) { - 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) { - strcpy(loc->collate, name); - - if (localefile == NULL) { - /* TODO: POSIX/C locale collation */ - } else { - /* read from file */ - loc->lc_collate = NULL; - } - } - - if (mask & LC_CTYPE_MASK) { - strcpy(loc->ctype, name); - - if (localefile == NULL) { - char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char lower[] = "abcdefghijklmnopqrstuvwxyz"; - char digit[] = "0123456789"; - char xdigit[] = "0123456789ABCDEFabcdef"; - char space[] = " \f\n\r\t\v"; - char punct[] = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; - char blank[] = " \t"; - size_t i; - - memset(loc->lc_ctype.ctattr, 0, sizeof(loc->lc_ctype.ctattr)); - - for (i = 0; i < 32; i++) { - loc->lc_ctype.ctattr[i] = CT_CNTRL; - } - loc->lc_ctype.ctattr[127] = CT_CNTRL; - - setall(loc->lc_ctype.ctattr, upper, CT_UPPER); - setall(loc->lc_ctype.ctattr, upper, CT_ALPHA); - setall(loc->lc_ctype.ctattr, lower, CT_LOWER); - setall(loc->lc_ctype.ctattr, lower, CT_ALPHA); - setall(loc->lc_ctype.ctattr, digit, CT_DIGIT); - setall(loc->lc_ctype.ctattr, xdigit, CT_XDIGIT); - setall(loc->lc_ctype.ctattr, space, CT_SPACE); - setall(loc->lc_ctype.ctattr, punct, CT_PUNCT); - setall(loc->lc_ctype.ctattr, blank, CT_BLANK); - - for (i = 0; i < CHAR_MAX; i++) { - if (loc->lc_ctype.ctattr[i] & - (CT_UPPER | CT_ALPHA | CT_LOWER | - CT_DIGIT | CT_XDIGIT | CT_PUNCT)) { - loc->lc_ctype.ctattr[i] |= CT_GRAPH; - loc->lc_ctype.ctattr[i] |= CT_PRINT; - } - } - - loc->lc_ctype.ctattr[' '] |= CT_PRINT; - - for (i = 0; i < UCHAR_MAX; i++) { - loc->lc_ctype.ctoupper[i] = i; - loc->lc_ctype.ctolower[i] = i; - } - - for (i = 0; i < sizeof(upper); i++) { - loc->lc_ctype.ctolower[(int)upper[i]] = lower[i]; - loc->lc_ctype.ctoupper[(int)lower[i]] = upper[i]; - } - } else { - /* read from file */ - /* - loc->lc_ctype.ctattr - loc->lc_ctype.ctoupper - loc->lc_ctype.ctolower - */ - } - } - - if (mask & LC_MONETARY_MASK) { - strcpy(loc->monetary, name); - - if (localefile == NULL) { - loc->mn.mon_decimal_point = ""; - loc->mn.mon_thousands_sep = ""; - loc->mn.mon_grouping = ""; - loc->mn.positive_sign = ""; - loc->mn.negative_sign = ""; - loc->mn.currency_symbol = ""; - loc->mn.frac_digits = CHAR_MAX; - loc->mn.p_cs_precedes = CHAR_MAX; - loc->mn.n_cs_precedes = CHAR_MAX; - loc->mn.p_sep_by_space = CHAR_MAX; - loc->mn.n_sep_by_space = CHAR_MAX; - loc->mn.p_sign_posn = CHAR_MAX; - loc->mn.n_sign_posn = CHAR_MAX; - loc->mn.int_curr_symbol = ""; - loc->mn.int_frac_digits = CHAR_MAX; - - #if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ - loc->mn.int_p_cs_precedes = CHAR_MAX; - loc->mn.int_n_cs_precedes = CHAR_MAX; - loc->mn.int_p_sep_by_space = CHAR_MAX; - loc->mn.int_n_sep_by_space = CHAR_MAX; - loc->mn.int_p_sign_posn = CHAR_MAX; - loc->mn.int_n_sign_posn = CHAR_MAX; - #else - loc->mn.__int_p_cs_precedes = CHAR_MAX; - loc->mn.__int_n_cs_precedes = CHAR_MAX; - loc->mn.__int_p_sep_by_space = CHAR_MAX; - loc->mn.__int_n_sep_by_space = CHAR_MAX; - loc->mn.__int_p_sign_posn = CHAR_MAX; - loc->mn.__int_n_sign_posn = CHAR_MAX; - #endif - } else { - /* - loc->mn.monetary fields; - */ - } - } - - if (mask & LC_NUMERIC_MASK) { - strcpy(loc->numeric, name); - - if (localefile == NULL) { - loc->mn.decimal_point = "."; - loc->mn.thousands_sep = ""; - loc->mn.grouping = ""; - } else { - /* - loc->mn.numeric fields - */ - } - } - - if (mask & LC_TIME_MASK) { - strcpy(loc->time, name); - - if (localefile == NULL) { - memset(&loc->lc_time, 0, sizeof(loc->lc_time)); - - loc->lc_time.d_t_fmt = "%a %b %e %H:%M:%S %Y"; - loc->lc_time.d_fmt = "%m/%d/%y"; - loc->lc_time.t_fmt = "%H:%M:%S"; - loc->lc_time.am_pm[0] = "AM"; - loc->lc_time.am_pm[1] = "PM"; - loc->lc_time.t_fmt_ampm = "%I:%M:%S %p"; - loc->lc_time.day[0] = "Sunday"; - loc->lc_time.day[1] = "Monday"; - loc->lc_time.day[2] = "Tuesday"; - loc->lc_time.day[3] = "Wednesday"; - loc->lc_time.day[4] = "Thursday"; - loc->lc_time.day[5] = "Friday"; - loc->lc_time.day[6] = "Saturday"; - loc->lc_time.abday[0] = "Sun"; - loc->lc_time.abday[1] = "Mon"; - loc->lc_time.abday[2] = "Tue"; - loc->lc_time.abday[3] = "Wed"; - loc->lc_time.abday[4] = "Thu"; - loc->lc_time.abday[5] = "Fri"; - loc->lc_time.abday[6] = "Sat"; - loc->lc_time.mon[0] = "January"; - loc->lc_time.mon[1] = "February"; - loc->lc_time.mon[2] = "March"; - loc->lc_time.mon[3] = "April"; - loc->lc_time.mon[4] = "May"; - loc->lc_time.mon[5] = "June"; - loc->lc_time.mon[6] = "July"; - loc->lc_time.mon[7] = "August"; - loc->lc_time.mon[8] = "September"; - loc->lc_time.mon[9] = "October"; - loc->lc_time.mon[10] = "November"; - loc->lc_time.mon[11] = "December"; - loc->lc_time.abmon[0] = "Jan"; - loc->lc_time.abmon[1] = "Feb"; - loc->lc_time.abmon[2] = "Mar"; - loc->lc_time.abmon[3] = "Apr"; - loc->lc_time.abmon[4] = "May"; - loc->lc_time.abmon[5] = "Jun"; - loc->lc_time.abmon[6] = "Jul"; - loc->lc_time.abmon[7] = "Aug"; - loc->lc_time.abmon[8] = "Sep"; - loc->lc_time.abmon[9] = "Oct"; - loc->lc_time.abmon[10] = "Nov"; - loc->lc_time.abmon[11] = "Dec"; - } else { - /* read from file */ - /* loc->lc_time */ - } - } - - if (mask & LC_MESSAGES_MASK) { - strcpy(loc->messages, name); - - if (localefile == NULL) { - loc->lc_messages.yesexpr = "^[yY]"; - loc->lc_messages.noexpr = "^[nN]"; - } else { - /* read */ - loc->lc_messages.yesexpr = NULL; - loc->lc_messages.noexpr = NULL; - } - } - - return (char*)name; -} diff --git a/src/nonstd/locale-internal.ref b/src/nonstd/locale-internal.ref deleted file mode 100644 index d795ee8f..00000000 --- a/src/nonstd/locale-internal.ref +++ /dev/null @@ -1,2 +0,0 @@ -#include <nonstd/locale.h> -REFERENCE(<nonstd/internal.h>) diff --git a/src/nonstd/locale-limits.ref b/src/nonstd/locale-limits.ref deleted file mode 100644 index 705296b4..00000000 --- a/src/nonstd/locale-limits.ref +++ /dev/null @@ -1,2 +0,0 @@ -#include <nonstd/locale.h> -REFERENCE(<limits.h>) diff --git a/src/nonstd/locale-locale.ref b/src/nonstd/locale-locale.ref deleted file mode 100644 index 98478b9f..00000000 --- a/src/nonstd/locale-locale.ref +++ /dev/null @@ -1,2 +0,0 @@ -#include <nonstd/locale.h> -REFERENCE(<locale.h>) diff --git a/src/nonstd/struct_locale_t.c b/src/nonstd/struct_locale_t.c deleted file mode 100644 index 3479e22f..00000000 --- a/src/nonstd/struct_locale_t.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <nonstd/locale.h> - -struct __locale_t { - char all[UCHAR_MAX]; - - char ctype[UCHAR_MAX]; - struct { - unsigned int ctattr[UCHAR_MAX + 1]; - unsigned char ctoupper[UCHAR_MAX + 1]; - unsigned char ctolower[UCHAR_MAX + 1]; - } lc_ctype; - - char collate[UCHAR_MAX]; - struct collation { - char * sequence; - int weight; - } *lc_collate; - - char messages[UCHAR_MAX]; - struct { - char *yesexpr; - char *noexpr; - } lc_messages; - - char monetary[UCHAR_MAX]; - char numeric[UCHAR_MAX]; - struct lconv mn; - - char time[UCHAR_MAX]; - struct { - char *abday[7]; - char *day[7]; - char *abmon[12]; - char *mon[12]; - char *d_t_fmt; - char *d_fmt; - char *t_fmt; - char *am_pm[2]; - char *t_fmt_ampm; - struct { - char direction; - int offset; - int start_year; - int start_month; - int start_day; - int end_year; - int end_month; - int end_day; - char *era_name; - char *era_format; - } era; - char *era_d_fmt; - char *era_t_fmt; - char *era_d_t_fmt; - char *alt_digits; - } lc_time; -}; |
