From: Nick Bowler Date: Tue, 2 Mar 2021 05:13:56 +0000 (-0500) Subject: Consolidate header files. X-Git-Tag: v1~2 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/0c61f9637a469ac7a28b5a329551b03e6ad14d62 Consolidate header files. There is no need for this quantity of tiny header files. We can simply use a single internal header file for libcdecl, and a single internal header file for cdecl99, including all necessary declarations. --- diff --git a/Makefile.am b/Makefile.am index ce76be1..ffbc85f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,18 +35,17 @@ EXTRA_DIST = bootstrap $(DX_BASEDIR)/scripts/fix-gnulib.pl m4/gnulib-cache.m4 \ dist_man_MANS = doc/man/cdecl99.1 doc/man/libcdecl.3 include_HEADERS = src/cdecl.h -noinst_HEADERS = conf_pre.h conf_post.h src/typemap.h src/output.h src/scan.h \ - src/parse.h src/i18n.h src/normalize.h src/error.h src/history.h \ - test/declgen.h test/test.h +noinst_HEADERS = conf_pre.h conf_post.h src/scan.h src/parse.h \ + test/declgen.h test/test.h noinst_DATA = $(MOFILES) lib_LTLIBRARIES = libcdecl.la -libcdecl_la_LDFLAGS = -no-undefined \ - -export-symbols-regex '^cdecl_[[:lower:]]' +libcdecl_la_LDFLAGS = -export-symbols-regex '^cdecl_[[:lower:]]' \ + -no-undefined libcdecl_la_SOURCES = src/scan.c src/parse.c src/parse-decl.c src/typemap.c \ - src/output.c src/explain.c src/declare.c src/i18n.c src/error.c \ - src/normalize.c + src/output.c src/explain.c src/declare.c src/i18n.c \ + src/error.c src/normalize.c src/cdecl-internal.h libcdecl_la_LIBADD = libgnu.la $(LTLIBINTL) $(LTLIBTHREAD) $(libcdecl_la_OBJECTS): $(gnulib_headers) diff --git a/src/cdecl-internal.h b/src/cdecl-internal.h new file mode 100644 index 0000000..2140006 --- /dev/null +++ b/src/cdecl-internal.h @@ -0,0 +1,45 @@ +/* + * Internal declarations for libcdecl. + * Copyright © 2021 Nick Bowler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef CDECL_INTERNAL_H_ +#define CDECL_INTERNAL_H_ + +#include +#include + +#define _(s) dgettext(PACKAGE, s) +#define N_(s) s + +struct cdecl_error; +struct cdecl_declspec; + +void cdecl__init_i18n(void); + +const char *cdecl__strerror(unsigned code); +void cdecl__set_error(const struct cdecl_error *err); + +unsigned long cdecl__build_typemap(struct cdecl_declspec *s); +struct cdecl_declspec *cdecl__normalize_specs(struct cdecl_declspec *specs); + +size_t cdecl__advance_(char **buf, size_t *n, size_t amount); +size_t cdecl__advance(char **buf, size_t *n, size_t amount); +size_t cdecl__explain_specs(char *buf, size_t n, struct cdecl_declspec *s, + unsigned mask); +size_t cdecl__explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s); +size_t cdecl__explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s); + +#endif diff --git a/src/cdecl99.c b/src/cdecl99.c index 18c6a5d..00053b2 100644 --- a/src/cdecl99.c +++ b/src/cdecl99.c @@ -25,8 +25,6 @@ #include #include #include -#include "history.h" -#include "cdecl.h" #include #include @@ -36,6 +34,7 @@ #include #include "cdecl99.h" +#include "cdecl.h" static const char *progname = "cdecl99"; @@ -187,7 +186,7 @@ static int repl(void) for (; (line = readline("> ")); free(line)) { if (!is_blank_line(line)) - cdecl_add_history(line); + add_history(line); if (run_command(line, true) > 0) break; diff --git a/src/cdecl99.h b/src/cdecl99.h index 6eb1b6c..e1030d4 100644 --- a/src/cdecl99.h +++ b/src/cdecl99.h @@ -28,4 +28,12 @@ int run_command_simplify(const char *arg); int run_command_explain(const char *arg); int run_command_declare(const char *cmdarg); +#if HAVE_RL_ADD_HISTORY && HAVE_READLINE_HISTORY_H +# include +#else +static inline void add_history(const char *str) +{ +} +#endif + #endif diff --git a/src/declare.c b/src/declare.c index d5af714..4fc9fee 100644 --- a/src/declare.c +++ b/src/declare.c @@ -1,6 +1,6 @@ /* * Render C declarations. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,13 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include #include #include #include #include "cdecl.h" -#include "output.h" +#include "cdecl-internal.h" static size_t declare_specs(char *buf, size_t n, struct cdecl_declspec *s) { diff --git a/src/error.c b/src/error.c index 8d26d5b..9b89bac 100644 --- a/src/error.c +++ b/src/error.c @@ -1,12 +1,30 @@ +/* + * Error handling for libcdecl. + * Copyright © 2011-2012, 2021 Nick Bowler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include #include #include #include #include #include + #include "cdecl.h" -#include "error.h" -#include "i18n.h" +#include "cdecl-internal.h" gl_once_define(static, tls_initialized); static gl_tls_key_t tls_key; diff --git a/src/error.h b/src/error.h deleted file mode 100644 index f7cace9..0000000 --- a/src/error.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CDECL_ERROR_H_ -#define CDECL_ERROR_H_ - -struct cdecl_error; -const char *cdecl__strerror(unsigned code); -void cdecl__set_error(const struct cdecl_error *err); - -#endif diff --git a/src/explain.c b/src/explain.c index 1b46d20..0f6b787 100644 --- a/src/explain.c +++ b/src/explain.c @@ -1,6 +1,6 @@ /* * Render C declarations as English. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,6 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include #include #include @@ -23,7 +24,7 @@ #include #include "cdecl.h" -#include "output.h" +#include "cdecl-internal.h" /* * Renders the start of the thing being declared. If top is true, print diff --git a/src/history.h b/src/history.h deleted file mode 100644 index 2d519ee..0000000 --- a/src/history.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Simple wrappers around libhistory to stub out unavailable functions. - * Copyright © 2012 Nick Bowler - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#if HAVE_READLINE_HISTORY_H -# include -#endif - -#if HAVE_RL_ADD_HISTORY -static inline void cdecl_add_history(const char *str) -{ - add_history(str); -} -#else -static inline void cdecl_add_history(const char *str) -{ -} -#endif diff --git a/src/i18n.c b/src/i18n.c index c691443..476386e 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -1,6 +1,6 @@ /* * Library initialization. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,12 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include #include #include #include -#include -#include "i18n.h" + +#include "cdecl-internal.h" static void initialize(void) { diff --git a/src/i18n.h b/src/i18n.h deleted file mode 100644 index e1b5503..0000000 --- a/src/i18n.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef CDECL_I18N_H_ -#define CDECL_I18N_H_ - -#include - -#define _(s) dgettext(PACKAGE, s) -#define N_(s) s - -void cdecl__init_i18n(void); - -#endif diff --git a/src/normalize.c b/src/normalize.c index 704d575..e6502d2 100644 --- a/src/normalize.c +++ b/src/normalize.c @@ -1,6 +1,6 @@ /* * Normalize C declaration specifier lists. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,12 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include #include #include #include "cdecl.h" -#include "normalize.h" +#include "cdecl-internal.h" /* * Totally order the declaration specifier types by defining an injection into diff --git a/src/normalize.h b/src/normalize.h deleted file mode 100644 index 3785df5..0000000 --- a/src/normalize.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef CDECL_NORMALIZE_H_ -#define CDECL_NORMALIZE_H_ - -struct cdecl_declspec; -struct cdecl_declspec *cdecl__normalize_specs(struct cdecl_declspec *specs); - -#endif diff --git a/src/output.c b/src/output.c index 8fffd24..22fc2e9 100644 --- a/src/output.c +++ b/src/output.c @@ -1,6 +1,6 @@ /* * Helper functions for outputting text. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,9 +19,8 @@ #include #include -#include "typemap.h" -#include "output.h" #include "cdecl.h" +#include "cdecl-internal.h" size_t cdecl__advance_(char **buf, size_t *n, size_t amount) { diff --git a/src/output.h b/src/output.h deleted file mode 100644 index 28a13de..0000000 --- a/src/output.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef CDECL_OUTPUT_H_ -#define CDECL_OUTPUT_H_ - -#include -#include "cdecl.h" - -size_t cdecl__advance_(char **buf, size_t *n, size_t amount); -size_t cdecl__advance(char **buf, size_t *n, size_t amount); -size_t cdecl__explain_specs(char *buf, size_t n, struct cdecl_declspec *s, - unsigned mask); -size_t cdecl__explain_pre_specs(char *buf, size_t n, struct cdecl_declspec *s); -size_t cdecl__explain_post_specs(char *buf, size_t n, struct cdecl_declspec *s); - -#endif diff --git a/src/parse-decl.c b/src/parse-decl.c index 694f4ab..2757703 100644 --- a/src/parse-decl.c +++ b/src/parse-decl.c @@ -1,6 +1,6 @@ /* * Parse and validate C declarations. - * Copyright © 2011-2012, 2020 Nick Bowler + * Copyright © 2011-2012, 2020-2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,11 +22,9 @@ #include #include "cdecl.h" -#include "typemap.h" +#include "cdecl-internal.h" #include "parse.h" #include "scan.h" -#include "i18n.h" -#include "normalize.h" /* * Verify the declaration specifiers of a declaration. If top is true, treat diff --git a/src/parse.y b/src/parse.y index 9c644da..a14f909 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1,7 +1,7 @@ %code top { /* * Parser for C declarations. - * Copyright © 2011 Nick Bowler + * Copyright © 2011-2012, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,8 +32,8 @@ #include #include "scan.h" -#include "error.h" #include "cdecl.h" +#include "cdecl-internal.h" #define FAIL(msg) do { \ yyerror(&yylloc, NULL, NULL, msg); \ diff --git a/src/typemap.c b/src/typemap.c index a280be2..918a037 100644 --- a/src/typemap.c +++ b/src/typemap.c @@ -1,6 +1,6 @@ /* * Helpers for dealing with type specifiers. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,12 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include #include #include #include + #include "cdecl.h" -#include "typemap.h" +#include "cdecl-internal.h" /* * We can represent type specifiers as a bitmap, which gives us a finite diff --git a/src/typemap.h b/src/typemap.h deleted file mode 100644 index d43afa7..0000000 --- a/src/typemap.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CDECL_TYPEMAP_H_ -#define CDECL_TYPEMAP_H_ - -#include "cdecl.h" - -unsigned long cdecl__build_typemap(struct cdecl_declspec *s); - -#endif