Index: head/usr.bin/localedef/Makefile =================================================================== --- head/usr.bin/localedef/Makefile (revision 290561) +++ head/usr.bin/localedef/Makefile (revision 290562) @@ -1,26 +1,26 @@ # $FreeBSD$ PROG= localedef SRCS= charmap.c \ collate.c \ ctype.c \ localedef.c \ messages.c \ monetary.c \ numeric.c \ parser.y \ scanner.c \ time.c \ wide.c -WARNS= 5 +WARNS= 3 ${SRCS:M*.c}: parser.h parser.h: parser.y IGNORE_PRAGMA= yes CFLAGS+= -I. -I${.CURDIR} CFLAGS+= -I${.CURDIR}/../../lib/libc/locale CFLAGS+= -I${.CURDIR}/../../lib/libc/stdtime .include Index: head/usr.bin/localedef/monetary.c =================================================================== --- head/usr.bin/localedef/monetary.c (revision 290561) +++ head/usr.bin/localedef/monetary.c (revision 290562) @@ -1,216 +1,211 @@ /* * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright 2015 John Marino * * This source code is derived from the illumos localedef command, and * provided under BSD-style license terms by Nexenta Systems, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * LC_MONETARY database generation routines for localedef. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "localedef.h" #include "parser.h" #include "lmonetary.h" static struct lc_monetary_T mon; void init_monetary(void) { (void) memset(&mon, 0, sizeof (mon)); } void add_monetary_str(wchar_t *wcs) { char *str; if ((str = to_mb_string(wcs)) == NULL) { INTERR; return; } free(wcs); switch (last_kw) { case T_INT_CURR_SYMBOL: mon.int_curr_symbol = str; break; case T_CURRENCY_SYMBOL: mon.currency_symbol = str; break; case T_MON_DECIMAL_POINT: mon.mon_decimal_point = str; break; case T_MON_THOUSANDS_SEP: mon.mon_thousands_sep = str; break; case T_POSITIVE_SIGN: mon.positive_sign = str; break; case T_NEGATIVE_SIGN: mon.negative_sign = str; break; default: free(str); INTERR; break; } } void add_monetary_num(int n) { char *str = NULL; (void) asprintf(&str, "%d", n); if (str == NULL) { fprintf(stderr, "out of memory"); return; } switch (last_kw) { case T_INT_FRAC_DIGITS: mon.int_frac_digits = str; break; case T_FRAC_DIGITS: mon.frac_digits = str; break; case T_P_CS_PRECEDES: mon.p_cs_precedes = str; break; case T_P_SEP_BY_SPACE: mon.p_sep_by_space = str; break; case T_N_CS_PRECEDES: mon.n_cs_precedes = str; break; case T_N_SEP_BY_SPACE: mon.n_sep_by_space = str; break; case T_P_SIGN_POSN: mon.p_sign_posn = str; break; case T_N_SIGN_POSN: mon.n_sign_posn = str; break; case T_INT_P_CS_PRECEDES: mon.int_p_cs_precedes = str; break; case T_INT_N_CS_PRECEDES: mon.int_n_cs_precedes = str; break; case T_INT_P_SEP_BY_SPACE: mon.int_p_sep_by_space = str; break; case T_INT_N_SEP_BY_SPACE: mon.int_n_sep_by_space = str; break; case T_INT_P_SIGN_POSN: mon.int_p_sign_posn = str; break; case T_INT_N_SIGN_POSN: mon.int_n_sign_posn = str; break; case T_MON_GROUPING: mon.mon_grouping = str; break; default: INTERR; break; } } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-qual" - void reset_monetary_group(void) { free((char *)mon.mon_grouping); mon.mon_grouping = NULL; } void add_monetary_group(int n) { char *s = NULL; if (mon.mon_grouping == NULL) { (void) asprintf(&s, "%d", n); } else { (void) asprintf(&s, "%s;%d", mon.mon_grouping, n); } if (s == NULL) fprintf(stderr, "out of memory"); free((char *)mon.mon_grouping); mon.mon_grouping = s; } - -#pragma GCC diagnostic pop void dump_monetary(void) { FILE *f; if ((f = open_category()) == NULL) { return; } if ((putl_category(mon.int_curr_symbol, f) == EOF) || (putl_category(mon.currency_symbol, f) == EOF) || (putl_category(mon.mon_decimal_point, f) == EOF) || (putl_category(mon.mon_thousands_sep, f) == EOF) || (putl_category(mon.mon_grouping, f) == EOF) || (putl_category(mon.positive_sign, f) == EOF) || (putl_category(mon.negative_sign, f) == EOF) || (putl_category(mon.int_frac_digits, f) == EOF) || (putl_category(mon.frac_digits, f) == EOF) || (putl_category(mon.p_cs_precedes, f) == EOF) || (putl_category(mon.p_sep_by_space, f) == EOF) || (putl_category(mon.n_cs_precedes, f) == EOF) || (putl_category(mon.n_sep_by_space, f) == EOF) || (putl_category(mon.p_sign_posn, f) == EOF) || (putl_category(mon.n_sign_posn, f) == EOF) || (putl_category(mon.int_p_cs_precedes, f) == EOF) || (putl_category(mon.int_n_cs_precedes, f) == EOF) || (putl_category(mon.int_p_sep_by_space, f) == EOF) || (putl_category(mon.int_n_sep_by_space, f) == EOF) || (putl_category(mon.int_p_sign_posn, f) == EOF) || (putl_category(mon.int_n_sign_posn, f) == EOF)) { return; } close_category(f); } Index: head/usr.bin/localedef/numeric.c =================================================================== --- head/usr.bin/localedef/numeric.c (revision 290561) +++ head/usr.bin/localedef/numeric.c (revision 290562) @@ -1,124 +1,119 @@ /* * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright 2015 John Marino * * This source code is derived from the illumos localedef command, and * provided under BSD-style license terms by Nexenta Systems, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * LC_NUMERIC database generation routines for localedef. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "localedef.h" #include "parser.h" #include "lnumeric.h" static struct lc_numeric_T numeric; void init_numeric(void) { (void) memset(&numeric, 0, sizeof (numeric)); } void add_numeric_str(wchar_t *wcs) { char *str; if ((str = to_mb_string(wcs)) == NULL) { INTERR; return; } free(wcs); switch (last_kw) { case T_DECIMAL_POINT: numeric.decimal_point = str; break; case T_THOUSANDS_SEP: numeric.thousands_sep = str; break; default: free(str); INTERR; break; } } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-qual" - void reset_numeric_group(void) { free((char *)numeric.grouping); numeric.grouping = NULL; } void add_numeric_group(int n) { char *s; if (numeric.grouping == NULL) { (void) asprintf(&s, "%d", n); } else { (void) asprintf(&s, "%s;%d", numeric.grouping, n); } if (s == NULL) fprintf(stderr, "out of memory"); free((char *)numeric.grouping); numeric.grouping = s; } - -#pragma GCC diagnostic pop void dump_numeric(void) { FILE *f; if ((f = open_category()) == NULL) { return; } if ((putl_category(numeric.decimal_point, f) == EOF) || (putl_category(numeric.thousands_sep, f) == EOF) || (putl_category(numeric.grouping, f) == EOF)) { return; } close_category(f); } Index: head/usr.bin/localedef/time.c =================================================================== --- head/usr.bin/localedef/time.c (revision 290561) +++ head/usr.bin/localedef/time.c (revision 290562) @@ -1,280 +1,275 @@ /* * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright 2015 John Marino * * This source code is derived from the illumos localedef command, and * provided under BSD-style license terms by Nexenta Systems, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * LC_TIME database generation routines for localedef. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "localedef.h" #include "parser.h" #include "timelocal.h" struct lc_time_T tm; void init_time(void) { (void) memset(&tm, 0, sizeof (tm)); } void add_time_str(wchar_t *wcs) { char *str; if ((str = to_mb_string(wcs)) == NULL) { INTERR; return; } free(wcs); switch (last_kw) { case T_D_T_FMT: tm.c_fmt = str; break; case T_D_FMT: tm.x_fmt = str; break; case T_T_FMT: tm.X_fmt = str; break; case T_T_FMT_AMPM: tm.ampm_fmt = str; break; case T_DATE_FMT: /* * This one is a Solaris extension, Too bad date just * doesn't use %c, which would be simpler. */ tm.date_fmt = str; break; case T_ERA_D_FMT: case T_ERA_T_FMT: case T_ERA_D_T_FMT: /* Silently ignore it. */ break; default: free(str); INTERR; break; } } static void add_list(const char *ptr[], char *str, int limit) { int i; for (i = 0; i < limit; i++) { if (ptr[i] == NULL) { ptr[i] = str; return; } } fprintf(stderr,"too many list elements"); } void add_time_list(wchar_t *wcs) { char *str; if ((str = to_mb_string(wcs)) == NULL) { INTERR; return; } free(wcs); switch (last_kw) { case T_ABMON: add_list(tm.mon, str, 12); break; case T_MON: add_list(tm.month, str, 12); break; case T_ABDAY: add_list(tm.wday, str, 7); break; case T_DAY: add_list(tm.weekday, str, 7); break; case T_AM_PM: if (tm.am == NULL) { tm.am = str; } else if (tm.pm == NULL) { tm.pm = str; } else { fprintf(stderr,"too many list elements"); } break; case T_ALT_DIGITS: case T_ERA: free(str); break; default: free(str); INTERR; break; } } void check_time_list(void) { switch (last_kw) { case T_ABMON: if (tm.mon[11] != NULL) return; break; case T_MON: if (tm.month[11] != NULL) return; break; case T_ABDAY: if (tm.wday[6] != NULL) return; break; case T_DAY: if (tm.weekday[6] != NULL) return; break; case T_AM_PM: if (tm.pm != NULL) return; break; case T_ERA: case T_ALT_DIGITS: return; default: fprintf(stderr,"unknown list"); break; } fprintf(stderr,"too few items in list (%d)", last_kw); } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-qual" - void reset_time_list(void) { int i; switch (last_kw) { case T_ABMON: for (i = 0; i < 12; i++) { free((char *)tm.mon[i]); tm.mon[i] = NULL; } break; case T_MON: for (i = 0; i < 12; i++) { free((char *)tm.month[i]); tm.month[i] = NULL; } break; case T_ABDAY: for (i = 0; i < 7; i++) { free((char *)tm.wday[i]); tm.wday[i] = NULL; } break; case T_DAY: for (i = 0; i < 7; i++) { free((char *)tm.weekday[i]); tm.weekday[i] = NULL; } break; case T_AM_PM: free((char *)tm.am); tm.am = NULL; free((char *)tm.pm); tm.pm = NULL; break; } } - -#pragma GCC diagnostic pop void dump_time(void) { FILE *f; int i; if ((f = open_category()) == NULL) { return; } for (i = 0; i < 12; i++) { if (putl_category(tm.mon[i], f) == EOF) { return; } } for (i = 0; i < 12; i++) { if (putl_category(tm.month[i], f) == EOF) { return; } } for (i = 0; i < 7; i++) { if (putl_category(tm.wday[i], f) == EOF) { return; } } for (i = 0; i < 7; i++) { if (putl_category(tm.weekday[i], f) == EOF) { return; } } /* * NOTE: If date_fmt is not specified, then we'll default to * using the %c for date. This is reasonable for most * locales, although for reasons that I don't understand * Solaris historically has had a seperate format for date. */ if ((putl_category(tm.X_fmt, f) == EOF) || (putl_category(tm.x_fmt, f) == EOF) || (putl_category(tm.c_fmt, f) == EOF) || (putl_category(tm.am, f) == EOF) || (putl_category(tm.pm, f) == EOF) || (putl_category(tm.date_fmt ? tm.date_fmt : tm.c_fmt, f) == EOF) || (putl_category(tm.ampm_fmt, f) == EOF)) { return; } close_category(f); }