2 * Helper functions for outputting text.
3 * Copyright © 2011, 2021, 2023 Nick Bowler
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "cdecl-internal.h"
27 #define MIN(a, b) ((a) < (b) ? (a) : (b))
29 size_t cdecl__advance(struct output_state *dst, size_t amount)
31 size_t x = MIN(amount, dst->dstlen);
40 size_t cdecl__emit(struct output_state *dst, const char *src)
42 size_t rc = snprintf(dst->dst, dst->dstlen, "%s", src);
43 return cdecl__advance(dst, rc);
46 static size_t explain_spec(struct output_state *dst, struct cdecl_declspec *s)
50 ret = cdecl__emit(dst, spec_string(s->type));
52 ret += cdecl__emit(dst, " " + !ret);
53 ret += cdecl__emit(dst, s->ident);
60 * Render a list of declaration specifiers. Only the declaration specifiers
61 * listed in mask, which is the bitwise OR of the desired specifier kinds, are
64 size_t cdecl__emit_specs(struct output_state *dst,
65 struct cdecl_declspec *s,
70 for (; s; s = s->next) {
71 if (!(s->type & mask))
74 ret += cdecl__emit(dst, " " + !ret);
75 ret += explain_spec(dst, s);