1/*-
2 * Copyright 2018 Nexenta Systems, Inc.
3 * Copyright 2015 John Marino <draco@marino.st>
4 *
5 * This source code is derived from the illumos localedef command, and
6 * provided under BSD-style license terms by Nexenta Systems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/*
32 * POSIX localedef.
33 */
34
35/* Common header files. */
36
37#include <sys/types.h>
38#include <stdarg.h>
39#include <stdio.h>
40#include <stdlib.h>
41
42extern int com_char;
43extern int esc_char;
44extern int mb_cur_max;
45extern int mb_cur_min;
46extern int last_kw;
47extern int verbose;
48#if YYDEBUG
49extern int yydebug;
50#endif
51extern int lineno;
52extern int undefok;	/* mostly ignore undefined symbols */
53extern int warnok;
54extern int warnings;
55
56extern char *version;
57
58int yylex(void);
59void yyerror(const char *);
60_Noreturn void errf(const char *, ...) __printflike(1, 2);
61void warn(const char *, ...) __printflike(1, 2);
62
63int putl_category(const char *, FILE *);
64int wr_category(void *, size_t, FILE *);
65FILE *open_category(void);
66void close_category(FILE *);
67void copy_category(char *);
68const char *category_name(void);
69
70int get_category(void);
71int get_symbol(void);
72int get_escaped(int);
73int get_wide(void);
74void reset_scanner(const char *);
75void scan_to_eol(void);
76void add_wcs(wchar_t);
77void add_tok(int);
78wchar_t *get_wcs(void);
79
80uint32_t htote(uint32_t);
81
82/* charmap.c - CHARMAP handling */
83void init_charmap(void);
84void add_charmap(const char *, int);
85void add_charmap_undefined(char *);
86void add_charmap_posix(void);
87void add_charmap_range(char *, char *, int);
88void add_charmap_char(const char *name, int val);
89int lookup_charmap(const char *, wchar_t *);
90int check_charmap_undefined(char *);
91int check_charmap(wchar_t);
92
93/* collate.o - LC_COLLATE handling */
94typedef struct collelem collelem_t;
95typedef struct collsym collsym_t;
96void init_collate(void);
97void define_collsym(char *);
98void define_collelem(char *, wchar_t *);
99void add_order_directive(void);
100void add_order_bit(int);
101void dump_collate(void);
102collsym_t *lookup_collsym(char *);
103collelem_t *lookup_collelem(char *);
104void start_order_collelem(collelem_t *);
105void start_order_undefined(void);
106void start_order_symbol(char *);
107void start_order_char(wchar_t);
108void start_order_ellipsis(void);
109void end_order_collsym(collsym_t *);
110void end_order(void);
111void add_weight(int32_t, int);
112void add_weights(int32_t *);
113void add_weight_num(int);
114void add_order_collelem(collelem_t *);
115void add_order_collsym(collsym_t *);
116void add_order_char(wchar_t);
117void add_order_ignore(void);
118void add_order_ellipsis(void);
119void add_order_symbol(char *);
120void add_order_subst(void);
121void add_subst_char(wchar_t);
122void add_subst_collsym(collsym_t *);
123void add_subst_collelem(collelem_t *);
124void add_subst_symbol(char *);
125int32_t get_weight(int32_t, int);
126wchar_t * wsncpy(wchar_t *, const wchar_t *, size_t);
127
128
129/* ctype.c - LC_CTYPE handling */
130void init_ctype(void);
131void add_ctype(int);
132void add_ctype_range(wchar_t);
133void add_width(int, int);
134void add_width_range(int, int, int);
135void add_caseconv(int, int);
136void dump_ctype(void);
137
138/* messages.c - LC_MESSAGES handling */
139void init_messages(void);
140void add_message(wchar_t *);
141void dump_messages(void);
142
143/* monetary.c - LC_MONETARY handling */
144void init_monetary(void);
145void add_monetary_str(wchar_t *);
146void add_monetary_num(int);
147void reset_monetary_group(void);
148void add_monetary_group(int);
149void dump_monetary(void);
150
151/* numeric.c - LC_NUMERIC handling */
152void init_numeric(void);
153void add_numeric_str(wchar_t *);
154void reset_numeric_group(void);
155void add_numeric_group(int);
156void dump_numeric(void);
157
158/* time.c - LC_TIME handling */
159void init_time(void);
160void add_time_str(wchar_t *);
161void reset_time_list(void);
162void add_time_list(wchar_t *);
163void check_time_list(void);
164void dump_time(void);
165
166/* wide.c -  Wide character handling. */
167int to_wide(wchar_t *, const char *);
168int to_mbs(char *, wchar_t);
169int to_mb(char *, wchar_t);
170char *to_mb_string(const wchar_t *);
171void set_wide_encoding(const char *);
172void werr(const char *, ...);
173const char *get_wide_encoding(void);
174int max_wide(void);
175
176//#define	_(x)	gettext(x)
177#define	INTERR	fprintf(stderr,"internal fault (%s:%d)\n", __FILE__, __LINE__)
178