]> git.saurik.com Git - bison.git/blame - src/uniqstr.h
doc: liby's main arms the internationalization
[bison.git] / src / uniqstr.h
CommitLineData
5bab03fc 1/* Keeping a unique copy of strings.
a737b216 2
3209eb1c 3 Copyright (C) 2002-2003, 2008-2015 Free Software Foundation, Inc.
5bab03fc
PE
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
f16b0819 7 This program is free software: you can redistribute it and/or modify
5bab03fc 8 it under the terms of the GNU General Public License as published by
f16b0819
PE
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
5bab03fc 11
f16b0819 12 This program is distributed in the hope that it will be useful,
5bab03fc
PE
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
f16b0819 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5bab03fc
PE
19
20#ifndef UNIQSTR_H_
21# define UNIQSTR_H_
22
67411a88
PE
23# include <stdio.h>
24
5bab03fc
PE
25/*-----------------------------------------.
26| Pointers to unique copies of C strings. |
27`-----------------------------------------*/
28
29typedef char const *uniqstr;
30
a737b216
PE
31/* Return the uniqstr for STR. */
32uniqstr uniqstr_new (char const *str);
5bab03fc 33
0ab402b4
JD
34/* Return a uniqstr built by vsprintf. In order to simply concatenate
35 strings, use UNIQSTR_CONCAT, which is a convenient wrapper around
36 this function. */
37uniqstr uniqstr_vsprintf (char const *format, ...)
67411a88 38 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2);
0ab402b4 39
a737b216 40/* Two uniqstr values have the same value iff they are the same. */
e3810658 41# define UNIQSTR_EQ(Ustr1, Ustr2) (!!((Ustr1) == (Ustr2)))
5bab03fc 42
95d176ff
AD
43/* Compare two uniqstr a la strcmp: negative for <, nul for =, and
44 positive for >. Undefined order, relies on addresses. */
c0ef22ab 45int uniqstr_cmp (uniqstr u1, uniqstr u2);
95d176ff 46
a737b216
PE
47/* Die if STR is not a uniqstr. */
48void uniqstr_assert (char const *str);
5bab03fc 49
0ab402b4
JD
50/*----------------.
51| Concatenation. |
52`----------------*/
53
54/* Concatenate at most 20 strings and return a uniqstr. The goal of
55 this macro is to make the caller's code a little more succinct
56 without a trivial uniqstr_vsprintf format string to maintain
57 (for example, "%s%s%s") while still benefitting from gcc's type
58 checking. Unfortunately, because of the missing format string in the
59 macro invocation, the argument number reported by gcc for a bad
60 argument type is 1 too large. */
a99ec53e
AD
61# define UNIQSTR_CONCAT(...) \
62 uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__, \
63 "%s", "%s", "%s", "%s", "%s", \
64 "%s", "%s", "%s", "%s", "%s", \
65 "%s", "%s", "%s", "%s", "%s", \
66 "%s", "%s", "%s", "%s", "%s"), \
0ab402b4
JD
67 __VA_ARGS__)
68
a99ec53e
AD
69# define UNIQSTR_GEN_FORMAT(F1, F2, F3, F4, F5, \
70 F6, F7, F8, F9, F10, \
71 F11, F12, F13, F14, F15, \
72 F16, F17, F18, F19, F20, \
73 ...) \
74 UNIQSTR_GEN_FORMAT_ (__VA_ARGS__, \
75 "", "", "", "", "", \
76 "", "", "", "", "", \
77 "", "", "", "", "", \
0ab402b4
JD
78 "", "", "", "", "")
79
a99ec53e
AD
80# define UNIQSTR_GEN_FORMAT_(F1, F2, F3, F4, F5, \
81 F6, F7, F8, F9, F10, \
82 F11, F12, F13, F14, F15, \
83 F16, F17, F18, F19, F20, ...) \
84 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \
0ab402b4
JD
85 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20
86
e3810658
AD
87/*--------------------.
88| Table of uniqstrs. |
89`--------------------*/
90
91/* Create the string table. */
92void uniqstrs_new (void);
93
94/* Free all the memory allocated for symbols. */
95void uniqstrs_free (void);
96
97/* Report them all. */
98void uniqstrs_print (void);
99
5bab03fc 100#endif /* ! defined UNIQSTR_H_ */