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"
28 #define MIN(a, b) ((a) < (b) ? (a) : (b))
30 size_t cdecl__advance(struct output_state *dst, size_t amount)
32 size_t x = MIN(amount, dst->dstlen);
41 size_t cdecl__emit(struct output_state *dst, const char *src)
43 size_t rc = snprintf(dst->dst, dst->dstlen, "%s", src);
44 return cdecl__advance(dst, rc);
47 static void explain_spec(struct output_state *dst, struct cdecl_declspec *s)
51 rc = cdecl__emit(dst, spec_string(s->type));
53 cdecl__emit(dst, " " + !rc);
54 cdecl__emit(dst, s->ident);
59 * Render a list of declaration specifiers. Only the declaration specifiers
60 * listed in mask, which is the bitwise OR of the desired specifier kinds, are
63 const char *cdecl__emit_specs(struct output_state *dst,
64 struct cdecl_declspec *s,
67 const char *sep = " ";
70 for (; s; s = s->next) {
71 if (!(s->type & mask))
74 cdecl__emit(dst, sep + empty);