$(libmain_a_OBJECTS): src/options.h
check_PROGRAMS = test/crossparse test/normalize
-check_LTLIBRARIES = libtest.la
-libtest_la_LIBADD = $(GSL_LIBS)
-libtest_la_SOURCES = test/testlib.c
-$(libtest_la_OBJECTS): $(gnulib_headers)
+check_LIBRARIES = libtest.a
+libtest_a_SOURCES = test/testlib.c common/src/help.c
+$(libtest_a_OBJECTS): $(gnulib_headers)
if HAVE_GSL
-libtest_la_SOURCES += test/declgen.c
check_PROGRAMS += test/randomdecl
+test_randomdecl_SOURCES = test/randomdecl.c test/declgen.c
+test_randomdecl_LDADD = libtest.a libcdecl.la libgnu.la $(GSL_LIBS)
+$(test_randomdecl_OBJECTS): $(gnulib_headers)
endif
-test_crossparse_LDADD = libtest.la libcdecl.la libgnu.la
+test_crossparse_LDADD = libtest.a libcdecl.la libgnu.la
$(test_crossparse_OBJECTS): $(gnulib_headers)
-test_randomdecl_LDADD = libtest.la libcdecl.la libgnu.la
-$(test_randomdecl_OBJECTS): $(gnulib_headers)
-test_normalize_LDADD = libtest.la src/output.lo src/normalize.lo \
+test_normalize_LDADD = libtest.a src/output.lo src/normalize.lo \
libcdecl.la libgnu.la
$(test_normalize_OBJECTS): $(gnulib_headers)
src/scan.lo: src/parse.h
src/parse-decl.lo: src/scan.h src/parse.h src/typemap.h
src/output.lo: src/specstr.h
-test/declgen.lo: test/typegen.h
+test/declgen.$(OBJEXT): test/typegen.h
# Supporting rules for gettext.
include $(top_srcdir)/common/snippet/gettext.mk
print_usage(stdout);
puts("Test that libcdecl can parse its own output.\n");
-
- puts("Options:");
- for (opt = lopts; opt->val; opt++) {
- int w = print_option_start(opt, NULL);
-
- if (w)
- putchar('\n');
- }
+ test_print_options(lopts);
}
enum {
print_usage(stdout);
puts("Test normalization of declaration specifiers.\n");
-
- puts("Options:");
- for (opt = lopts; opt->val; opt++) {
- int w = print_option_start(opt, NULL);
-
- if (w)
- putchar('\n');
- }
+ test_print_options(lopts);
}
static unsigned to_spectype(const char *tok)
print_usage(stdout);
puts("Generate random C declarations for testing.\n");
-
- puts("Options:");
- for (opt = lopts; opt->val; opt++) {
- int w = print_option_start(opt, NULL);
-
- if (w)
- putchar('\n');
- }
+ test_print_options(lopts);
}
static struct cdecl *random_decl(struct gen_rng *rng)
#include <stdbool.h>
#include <limits.h>
#include <assert.h>
-#include <getopt.h>
#ifndef _
# define _(x) (x)
#endif
-static inline int
-print_option_start(const struct option *opt, const char *argname)
-{
- int w;
-
- if (!argname)
- argname = _("ARG");
-
- if (opt->val >= CHAR_MIN && opt->val <= CHAR_MAX) {
- switch (opt->has_arg) {
- case 0:
- w = printf(_(" -%c, --%s"), opt->val, opt->name);
- break;
- case 1:
- w = printf(_(" -%c, --%s=%s"),
- opt->val, opt->name, argname);
- break;
- case 2:
- w = printf(_(" -%c, --%s[=%s]"),
- opt->val, opt->name, argname);
- break;
- default:
- assert(0);
- }
- } else {
- switch (opt->has_arg) {
- case 0:
- w = printf(_(" --%s"), opt->name);
- break;
- case 1:
- w = printf(_(" --%s=%s"), opt->name, argname);
- break;
- case 2:
- w = printf(_(" --%s[=%s]"), opt->name, argname);
- break;
- default:
- assert(0);
- }
- }
-
- if (w > 18) {
- putchar('\n');
- w = 0;
- }
-
- return w;
-}
-
struct cdecl_declspec;
+struct option;
struct cdecl;
void *malloc_nofail(size_t size);
bool strict_strtoul(unsigned long *val, const char *str, int base);
void test_print_version(const char *program);
+void test_print_options(const struct option *lopts);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
+#include <getopt.h>
#include <cdecl.h>
+
+#include "help.h"
#include "test.h"
static size_t printbuf_size;
puts("This is free software: you are free to change and redistribute it.");
puts("There is NO WARRANTY, to the extent permitted by law.");
}
+
+void test_print_options(const struct option *lopts)
+{
+ const struct option *opt;
+
+ puts("Options:");
+ for (opt = lopts; opt->val; opt++) {
+ if (help_print_optstring(opt, "ARG", 20))
+ putchar('\n');
+ }
+}