]> git.draconx.ca Git - cdecl99.git/blob - src/cdecl-internal.h
libcdecl: Use macros for packing tokens into bytes.
[cdecl99.git] / src / cdecl-internal.h
1 /*
2  * Internal declarations for libcdecl.
3  * Copyright © 2021, 2023 Nick Bowler
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef CDECL_INTERNAL_H_
19 #define CDECL_INTERNAL_H_
20
21 #include <stddef.h>
22 #include <gettext.h>
23
24 #define _(s) dgettext(PACKAGE, s)
25 #define N_(s) s
26
27 /*
28  * Pack a parser token into 7 bits.
29  *
30  * Bison normally numbers user-defined tokens sequentially starting from 258.
31  * If api.token,raw is used, then the numbering starts from 3.  As we have
32  * about 50 tokens, the latter case will fit in 7 bits easily; in the former
33  * case the upper bits are constant so we don't need to store them.
34  */
35 #define PACK_TOKEN(x) ((x) & 0x7f)
36
37 /*
38  * Expand a packed token to its original value.
39  */
40 #define UNPACK_TOKEN(x) ((x) | ((T_IDENT > 256) << 8))
41
42 struct cdecl_error;
43 struct cdecl_declspec;
44
45 #if ENABLE_NLS
46 void cdecl__init_i18n(void);
47 #else
48 static inline void cdecl__init_i18n(void)
49 {
50 }
51 #endif
52
53 void cdecl__err(unsigned code, const char *fmt, const char *arg);
54 void cdecl__errmsg(unsigned msg);
55
56 struct cdecl_declspec *cdecl__normalize_specs(struct cdecl_declspec *specs);
57
58 struct output_state {
59         char *dst;
60         size_t dstlen;
61         size_t accum;
62 };
63
64 size_t cdecl__advance(struct output_state *dst, size_t amount);
65 size_t cdecl__emit(struct output_state *dst, const char *src);
66
67 const char *cdecl__emit_specs(struct output_state *dst,
68                               struct cdecl_declspec *s,
69                               unsigned mask);
70
71 int cdecl__to_keyword(const char *s, int len, int english_mode);
72
73 #endif