1e12a957fSPedro F. Giffuni /*- 24644f9beSYuri Pankov * Copyright 2018 Nexenta Systems, Inc. 3057ca2d4SBaptiste Daroussin * Copyright 2015 John Marino <draco@marino.st> 4057ca2d4SBaptiste Daroussin * 5057ca2d4SBaptiste Daroussin * This source code is derived from the illumos localedef command, and 6057ca2d4SBaptiste Daroussin * provided under BSD-style license terms by Nexenta Systems, Inc. 7057ca2d4SBaptiste Daroussin * 8057ca2d4SBaptiste Daroussin * Redistribution and use in source and binary forms, with or without 9057ca2d4SBaptiste Daroussin * modification, are permitted provided that the following conditions 10057ca2d4SBaptiste Daroussin * are met: 11057ca2d4SBaptiste Daroussin * 12057ca2d4SBaptiste Daroussin * 1. Redistributions of source code must retain the above copyright 13057ca2d4SBaptiste Daroussin * notice, this list of conditions and the following disclaimer. 14057ca2d4SBaptiste Daroussin * 2. Redistributions in binary form must reproduce the above copyright 15057ca2d4SBaptiste Daroussin * notice, this list of conditions and the following disclaimer in the 16057ca2d4SBaptiste Daroussin * documentation and/or other materials provided with the distribution. 17057ca2d4SBaptiste Daroussin * 18057ca2d4SBaptiste Daroussin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19057ca2d4SBaptiste Daroussin * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20057ca2d4SBaptiste Daroussin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21057ca2d4SBaptiste Daroussin * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22057ca2d4SBaptiste Daroussin * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23057ca2d4SBaptiste Daroussin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24057ca2d4SBaptiste Daroussin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25057ca2d4SBaptiste Daroussin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26057ca2d4SBaptiste Daroussin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27057ca2d4SBaptiste Daroussin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28057ca2d4SBaptiste Daroussin * POSSIBILITY OF SUCH DAMAGE. 29057ca2d4SBaptiste Daroussin */ 30057ca2d4SBaptiste Daroussin 31057ca2d4SBaptiste Daroussin /* 32057ca2d4SBaptiste Daroussin * POSIX localedef. 33057ca2d4SBaptiste Daroussin */ 34057ca2d4SBaptiste Daroussin 35057ca2d4SBaptiste Daroussin /* Common header files. */ 36*5e3934b1SWarner Losh 376d284c01SEnji Cooper #include <sys/types.h> 386d284c01SEnji Cooper #include <stdarg.h> 39057ca2d4SBaptiste Daroussin #include <stdio.h> 40057ca2d4SBaptiste Daroussin #include <stdlib.h> 41057ca2d4SBaptiste Daroussin 42057ca2d4SBaptiste Daroussin extern int com_char; 43057ca2d4SBaptiste Daroussin extern int esc_char; 44057ca2d4SBaptiste Daroussin extern int mb_cur_max; 45057ca2d4SBaptiste Daroussin extern int mb_cur_min; 46057ca2d4SBaptiste Daroussin extern int last_kw; 47057ca2d4SBaptiste Daroussin extern int verbose; 48d836a9dbSJung-uk Kim #if YYDEBUG 49057ca2d4SBaptiste Daroussin extern int yydebug; 50d836a9dbSJung-uk Kim #endif 51057ca2d4SBaptiste Daroussin extern int lineno; 52057ca2d4SBaptiste Daroussin extern int undefok; /* mostly ignore undefined symbols */ 53057ca2d4SBaptiste Daroussin extern int warnok; 54057ca2d4SBaptiste Daroussin extern int warnings; 55057ca2d4SBaptiste Daroussin 56cc7edd25SThomas Munro extern char *version; 57cc7edd25SThomas Munro 58057ca2d4SBaptiste Daroussin int yylex(void); 59057ca2d4SBaptiste Daroussin void yyerror(const char *); 60ead8d64aSEnji Cooper _Noreturn void errf(const char *, ...) __printflike(1, 2); 61ead8d64aSEnji Cooper void warn(const char *, ...) __printflike(1, 2); 62057ca2d4SBaptiste Daroussin 63057ca2d4SBaptiste Daroussin int putl_category(const char *, FILE *); 64057ca2d4SBaptiste Daroussin int wr_category(void *, size_t, FILE *); 65057ca2d4SBaptiste Daroussin FILE *open_category(void); 66057ca2d4SBaptiste Daroussin void close_category(FILE *); 67057ca2d4SBaptiste Daroussin void copy_category(char *); 68057ca2d4SBaptiste Daroussin const char *category_name(void); 69057ca2d4SBaptiste Daroussin 70057ca2d4SBaptiste Daroussin int get_category(void); 71057ca2d4SBaptiste Daroussin int get_symbol(void); 72057ca2d4SBaptiste Daroussin int get_escaped(int); 73057ca2d4SBaptiste Daroussin int get_wide(void); 74057ca2d4SBaptiste Daroussin void reset_scanner(const char *); 75057ca2d4SBaptiste Daroussin void scan_to_eol(void); 76057ca2d4SBaptiste Daroussin void add_wcs(wchar_t); 77057ca2d4SBaptiste Daroussin void add_tok(int); 78057ca2d4SBaptiste Daroussin wchar_t *get_wcs(void); 79057ca2d4SBaptiste Daroussin 804644f9beSYuri Pankov uint32_t htote(uint32_t); 814644f9beSYuri Pankov 82057ca2d4SBaptiste Daroussin /* charmap.c - CHARMAP handling */ 83057ca2d4SBaptiste Daroussin void init_charmap(void); 84a0e395a4SBaptiste Daroussin void add_charmap(const char *, int); 85057ca2d4SBaptiste Daroussin void add_charmap_undefined(char *); 86057ca2d4SBaptiste Daroussin void add_charmap_posix(void); 87057ca2d4SBaptiste Daroussin void add_charmap_range(char *, char *, int); 88a0e395a4SBaptiste Daroussin void add_charmap_char(const char *name, int val); 89057ca2d4SBaptiste Daroussin int lookup_charmap(const char *, wchar_t *); 90057ca2d4SBaptiste Daroussin int check_charmap_undefined(char *); 91057ca2d4SBaptiste Daroussin int check_charmap(wchar_t); 92057ca2d4SBaptiste Daroussin 93057ca2d4SBaptiste Daroussin /* collate.o - LC_COLLATE handling */ 94057ca2d4SBaptiste Daroussin typedef struct collelem collelem_t; 95057ca2d4SBaptiste Daroussin typedef struct collsym collsym_t; 96057ca2d4SBaptiste Daroussin void init_collate(void); 97057ca2d4SBaptiste Daroussin void define_collsym(char *); 98057ca2d4SBaptiste Daroussin void define_collelem(char *, wchar_t *); 99057ca2d4SBaptiste Daroussin void add_order_directive(void); 100057ca2d4SBaptiste Daroussin void add_order_bit(int); 101057ca2d4SBaptiste Daroussin void dump_collate(void); 102057ca2d4SBaptiste Daroussin collsym_t *lookup_collsym(char *); 103057ca2d4SBaptiste Daroussin collelem_t *lookup_collelem(char *); 104057ca2d4SBaptiste Daroussin void start_order_collelem(collelem_t *); 105057ca2d4SBaptiste Daroussin void start_order_undefined(void); 106057ca2d4SBaptiste Daroussin void start_order_symbol(char *); 107057ca2d4SBaptiste Daroussin void start_order_char(wchar_t); 108057ca2d4SBaptiste Daroussin void start_order_ellipsis(void); 109057ca2d4SBaptiste Daroussin void end_order_collsym(collsym_t *); 110057ca2d4SBaptiste Daroussin void end_order(void); 111057ca2d4SBaptiste Daroussin void add_weight(int32_t, int); 112057ca2d4SBaptiste Daroussin void add_weights(int32_t *); 113057ca2d4SBaptiste Daroussin void add_weight_num(int); 114057ca2d4SBaptiste Daroussin void add_order_collelem(collelem_t *); 115057ca2d4SBaptiste Daroussin void add_order_collsym(collsym_t *); 116057ca2d4SBaptiste Daroussin void add_order_char(wchar_t); 117057ca2d4SBaptiste Daroussin void add_order_ignore(void); 118057ca2d4SBaptiste Daroussin void add_order_ellipsis(void); 119057ca2d4SBaptiste Daroussin void add_order_symbol(char *); 120057ca2d4SBaptiste Daroussin void add_order_subst(void); 121057ca2d4SBaptiste Daroussin void add_subst_char(wchar_t); 122057ca2d4SBaptiste Daroussin void add_subst_collsym(collsym_t *); 123057ca2d4SBaptiste Daroussin void add_subst_collelem(collelem_t *); 124057ca2d4SBaptiste Daroussin void add_subst_symbol(char *); 125057ca2d4SBaptiste Daroussin int32_t get_weight(int32_t, int); 126057ca2d4SBaptiste Daroussin wchar_t * wsncpy(wchar_t *, const wchar_t *, size_t); 127057ca2d4SBaptiste Daroussin 128057ca2d4SBaptiste Daroussin 129057ca2d4SBaptiste Daroussin /* ctype.c - LC_CTYPE handling */ 130057ca2d4SBaptiste Daroussin void init_ctype(void); 131057ca2d4SBaptiste Daroussin void add_ctype(int); 1328c859b07SBaptiste Daroussin void add_ctype_range(wchar_t); 133057ca2d4SBaptiste Daroussin void add_width(int, int); 134057ca2d4SBaptiste Daroussin void add_width_range(int, int, int); 135057ca2d4SBaptiste Daroussin void add_caseconv(int, int); 136057ca2d4SBaptiste Daroussin void dump_ctype(void); 137057ca2d4SBaptiste Daroussin 138057ca2d4SBaptiste Daroussin /* messages.c - LC_MESSAGES handling */ 139057ca2d4SBaptiste Daroussin void init_messages(void); 140057ca2d4SBaptiste Daroussin void add_message(wchar_t *); 141057ca2d4SBaptiste Daroussin void dump_messages(void); 142057ca2d4SBaptiste Daroussin 143057ca2d4SBaptiste Daroussin /* monetary.c - LC_MONETARY handling */ 144057ca2d4SBaptiste Daroussin void init_monetary(void); 145057ca2d4SBaptiste Daroussin void add_monetary_str(wchar_t *); 146057ca2d4SBaptiste Daroussin void add_monetary_num(int); 147057ca2d4SBaptiste Daroussin void reset_monetary_group(void); 148057ca2d4SBaptiste Daroussin void add_monetary_group(int); 149057ca2d4SBaptiste Daroussin void dump_monetary(void); 150057ca2d4SBaptiste Daroussin 151057ca2d4SBaptiste Daroussin /* numeric.c - LC_NUMERIC handling */ 152057ca2d4SBaptiste Daroussin void init_numeric(void); 153057ca2d4SBaptiste Daroussin void add_numeric_str(wchar_t *); 154057ca2d4SBaptiste Daroussin void reset_numeric_group(void); 155057ca2d4SBaptiste Daroussin void add_numeric_group(int); 156057ca2d4SBaptiste Daroussin void dump_numeric(void); 157057ca2d4SBaptiste Daroussin 158057ca2d4SBaptiste Daroussin /* time.c - LC_TIME handling */ 159057ca2d4SBaptiste Daroussin void init_time(void); 160057ca2d4SBaptiste Daroussin void add_time_str(wchar_t *); 161057ca2d4SBaptiste Daroussin void reset_time_list(void); 162057ca2d4SBaptiste Daroussin void add_time_list(wchar_t *); 163057ca2d4SBaptiste Daroussin void check_time_list(void); 164057ca2d4SBaptiste Daroussin void dump_time(void); 165057ca2d4SBaptiste Daroussin 166057ca2d4SBaptiste Daroussin /* wide.c - Wide character handling. */ 167057ca2d4SBaptiste Daroussin int to_wide(wchar_t *, const char *); 168057ca2d4SBaptiste Daroussin int to_mbs(char *, wchar_t); 169057ca2d4SBaptiste Daroussin int to_mb(char *, wchar_t); 170057ca2d4SBaptiste Daroussin char *to_mb_string(const wchar_t *); 171057ca2d4SBaptiste Daroussin void set_wide_encoding(const char *); 172057ca2d4SBaptiste Daroussin void werr(const char *, ...); 173057ca2d4SBaptiste Daroussin const char *get_wide_encoding(void); 174057ca2d4SBaptiste Daroussin int max_wide(void); 175057ca2d4SBaptiste Daroussin 176057ca2d4SBaptiste Daroussin //#define _(x) gettext(x) 1773141e51dSKyle Evans #define INTERR fprintf(stderr,"internal fault (%s:%d)\n", __FILE__, __LINE__) 178