From 247256a628cecfe9e4485789535a1bc2c1d680a3 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 17 May 2010 10:20:16 +0200 Subject: [PATCH] use isl for argument parsing --- Makefile.am | 40 +- barvinok.cc | 14 +- barvinok/options.h | 74 +- barvinok_count.c | 5 +- barvinok_ehrhart.cc | 58 +- barvinok_ehrhart_options.c | 13 + barvinok_ehrhart_options.h | 18 + barvinok_enumerate.cc | 116 +- barvinok_enumerate_e.cc | 167 +- barvinok_enumerate_e_options.c | 24 + barvinok_enumerate_e_options.h | 24 + barvinok_enumerate_options.c | 16 + barvinok_enumerate_options.h | 21 + barvinok_summate.cc | 72 +- barvinok_summate_options.c | 13 + barvinok_summate_options.h | 19 + barvinok_union.cc | 56 +- barvinok_union_options.c | 11 + barvinok_union_options.h | 17 + bernoulli.c | 10 +- bound.cc | 111 +- bound_options.c | 18 + bound_options.h | 22 + cone_integer_hull.c | 5 +- configure.in | 5 +- edomain.cc | 6 +- evalue_convert.cc | 58 - evalue_convert.h | 4 +- evalue_convert_main.c | 27 +- evalue_convert_options.c | 14 + lexmin.cc | 116 +- lexmin.h | 12 +- lexmin_options.c | 19 + lib/Makefile.am | 615 ------- lib/alloca.c | 489 ----- lib/alloca.in.h | 54 - lib/argp-ba.c | 25 - lib/argp-eexst.c | 31 - lib/argp-fmtstream.c | 435 ----- lib/argp-fmtstream.h | 301 --- lib/argp-fs-xinl.c | 43 - lib/argp-help.c | 1954 -------------------- lib/argp-namefrob.h | 158 -- lib/argp-parse.c | 953 ---------- lib/argp-pin.c | 28 - lib/argp-pv.c | 24 - lib/argp-pvh.c | 31 - lib/argp-xinl.c | 43 - lib/argp.h | 622 ------- lib/asnprintf.c | 35 - lib/basename.c | 129 -- lib/dirname.c | 85 - lib/dirname.h | 70 - lib/error.c | 339 ---- lib/error.h | 66 - lib/exitfail.c | 26 - lib/exitfail.h | 20 - lib/float+.h | 148 -- lib/float.in.h | 59 - lib/getopt.c | 1191 ------------ lib/getopt.in.h | 226 --- lib/getopt1.c | 171 -- lib/getopt_int.h | 131 -- lib/getsubopt.c | 82 - lib/gettext.h | 270 --- lib/malloc.c | 57 - lib/mempcpy.c | 29 - lib/printf-args.c | 187 -- lib/printf-args.h | 154 -- lib/printf-parse.c | 576 ------ lib/printf-parse.h | 179 -- lib/progname.c | 50 - lib/progname.h | 61 - lib/size_max.h | 31 - lib/sleep.c | 47 - lib/stdbool.in.h | 118 -- lib/stdint.in.h | 508 ----- lib/stdio.in.h | 382 ---- lib/stdlib.in.h | 177 -- lib/strcasecmp.c | 63 - lib/strchrnul.c | 32 - lib/strerror.c | 79 - lib/string.in.h | 579 ------ lib/stripslash.c | 45 - lib/strncasecmp.c | 63 - lib/strndup.c | 37 - lib/strnlen.c | 31 - lib/sysexits.in.h | 68 - lib/unistd.in.h | 262 --- lib/vasnprintf.c | 3966 ---------------------------------------- lib/vasnprintf.h | 81 - lib/vsnprintf.c | 76 - lib/wchar.in.h | 82 - lib/xalloc-die.c | 42 - lib/xalloc.h | 271 --- lib/xmalloc.c | 123 -- lib/xsize.h | 108 -- lib/xstrndup.c | 37 - lib/xstrndup.h | 24 - m4/alloca.m4 | 50 - m4/argp.m4 | 65 - m4/dirname.m4 | 18 - m4/dos.m4 | 71 - m4/double-slash-root.m4 | 38 - m4/eoverflow.m4 | 70 - m4/error.m4 | 22 - m4/exitfail.m4 | 13 - m4/extensions.m4 | 82 - m4/float_h.m4 | 19 - m4/getopt.m4 | 83 - m4/getsubopt.m4 | 22 - m4/gnulib-cache.m4 | 33 - m4/gnulib-common.m4 | 22 - m4/gnulib-comp.m4 | 251 --- m4/gnulib-tool.m4 | 33 - m4/include_next.m4 | 107 -- m4/inline.m4 | 40 - m4/intmax_t.m4 | 61 - m4/inttypes_h.m4 | 26 - m4/longlong.m4 | 72 - m4/malloc.m4 | 41 - m4/mempcpy.m4 | 26 - m4/onceonly_2_57.m4 | 86 - m4/size_max.m4 | 68 - m4/sleep.m4 | 19 - m4/stdbool.m4 | 115 -- m4/stdint.m4 | 395 ---- m4/stdint_h.m4 | 26 - m4/stdio_h.m4 | 86 - m4/stdlib_h.m4 | 35 - m4/strcase.m4 | 44 - m4/strchrnul.m4 | 21 - m4/strerror.m4 | 49 - m4/string_h.m4 | 80 - m4/strndup.m4 | 53 - m4/strnlen.m4 | 31 - m4/sysexits.m4 | 43 - m4/ulonglong.m4 | 48 - m4/unistd_h.m4 | 56 - m4/vasnprintf.m4 | 197 -- m4/vsnprintf.m4 | 31 - m4/wchar.m4 | 54 - m4/wchar_t.m4 | 20 - m4/wint_t.m4 | 28 - m4/xalloc.m4 | 24 - m4/xsize.m4 | 13 - m4/xstrndup.m4 | 15 - options.c | 681 +++---- polyhedron_integer_hull.c | 5 +- polyhedron_sample.c | 6 +- polytope_lattice_width.c | 55 +- polytope_minimize.c | 5 +- polytope_scan.c | 60 +- polytope_volume.c | 2 +- scale.c | 34 +- semigroup_holes.cc | 5 +- test.c | 5 +- test_approx.c | 73 +- test_bound.c | 67 +- vector_partition_chambers.c | 5 +- verif_ehrhart.c | 2 +- verify.c | 87 +- verify.h | 12 +- verify_lexsmaller.c | 89 +- volume.c | 20 +- 165 files changed, 947 insertions(+), 21852 deletions(-) create mode 100644 barvinok_ehrhart_options.c create mode 100644 barvinok_ehrhart_options.h create mode 100644 barvinok_enumerate_e_options.c create mode 100644 barvinok_enumerate_e_options.h create mode 100644 barvinok_enumerate_options.c create mode 100644 barvinok_enumerate_options.h create mode 100644 barvinok_summate_options.c create mode 100644 barvinok_summate_options.h create mode 100644 barvinok_union_options.c create mode 100644 barvinok_union_options.h create mode 100644 bound_options.c create mode 100644 bound_options.h create mode 100644 evalue_convert_options.c create mode 100644 lexmin_options.c delete mode 100644 lib/Makefile.am delete mode 100644 lib/alloca.c delete mode 100644 lib/alloca.in.h delete mode 100644 lib/argp-ba.c delete mode 100644 lib/argp-eexst.c delete mode 100644 lib/argp-fmtstream.c delete mode 100644 lib/argp-fmtstream.h delete mode 100644 lib/argp-fs-xinl.c delete mode 100644 lib/argp-help.c delete mode 100644 lib/argp-namefrob.h delete mode 100644 lib/argp-parse.c delete mode 100644 lib/argp-pin.c delete mode 100644 lib/argp-pv.c delete mode 100644 lib/argp-pvh.c delete mode 100644 lib/argp-xinl.c delete mode 100644 lib/argp.h delete mode 100644 lib/asnprintf.c delete mode 100644 lib/basename.c delete mode 100644 lib/dirname.c delete mode 100644 lib/dirname.h delete mode 100644 lib/error.c delete mode 100644 lib/error.h delete mode 100644 lib/exitfail.c delete mode 100644 lib/exitfail.h delete mode 100644 lib/float+.h delete mode 100644 lib/float.in.h delete mode 100644 lib/getopt.c delete mode 100644 lib/getopt.in.h delete mode 100644 lib/getopt1.c delete mode 100644 lib/getopt_int.h delete mode 100644 lib/getsubopt.c delete mode 100644 lib/gettext.h delete mode 100644 lib/malloc.c delete mode 100644 lib/mempcpy.c delete mode 100644 lib/printf-args.c delete mode 100644 lib/printf-args.h delete mode 100644 lib/printf-parse.c delete mode 100644 lib/printf-parse.h delete mode 100644 lib/progname.c delete mode 100644 lib/progname.h delete mode 100644 lib/size_max.h delete mode 100644 lib/sleep.c delete mode 100644 lib/stdbool.in.h delete mode 100644 lib/stdint.in.h delete mode 100644 lib/stdio.in.h delete mode 100644 lib/stdlib.in.h delete mode 100644 lib/strcasecmp.c delete mode 100644 lib/strchrnul.c delete mode 100644 lib/strerror.c delete mode 100644 lib/string.in.h delete mode 100644 lib/stripslash.c delete mode 100644 lib/strncasecmp.c delete mode 100644 lib/strndup.c delete mode 100644 lib/strnlen.c delete mode 100644 lib/sysexits.in.h delete mode 100644 lib/unistd.in.h delete mode 100644 lib/vasnprintf.c delete mode 100644 lib/vasnprintf.h delete mode 100644 lib/vsnprintf.c delete mode 100644 lib/wchar.in.h delete mode 100644 lib/xalloc-die.c delete mode 100644 lib/xalloc.h delete mode 100644 lib/xmalloc.c delete mode 100644 lib/xsize.h delete mode 100644 lib/xstrndup.c delete mode 100644 lib/xstrndup.h delete mode 100644 m4/alloca.m4 delete mode 100644 m4/argp.m4 delete mode 100644 m4/dirname.m4 delete mode 100644 m4/dos.m4 delete mode 100644 m4/double-slash-root.m4 delete mode 100644 m4/eoverflow.m4 delete mode 100644 m4/error.m4 delete mode 100644 m4/exitfail.m4 delete mode 100644 m4/extensions.m4 delete mode 100644 m4/float_h.m4 delete mode 100644 m4/getopt.m4 delete mode 100644 m4/getsubopt.m4 delete mode 100644 m4/gnulib-cache.m4 delete mode 100644 m4/gnulib-common.m4 delete mode 100644 m4/gnulib-comp.m4 delete mode 100644 m4/gnulib-tool.m4 delete mode 100644 m4/include_next.m4 delete mode 100644 m4/inline.m4 delete mode 100644 m4/intmax_t.m4 delete mode 100644 m4/inttypes_h.m4 delete mode 100644 m4/longlong.m4 delete mode 100644 m4/malloc.m4 delete mode 100644 m4/mempcpy.m4 delete mode 100644 m4/onceonly_2_57.m4 delete mode 100644 m4/size_max.m4 delete mode 100644 m4/sleep.m4 delete mode 100644 m4/stdbool.m4 delete mode 100644 m4/stdint.m4 delete mode 100644 m4/stdint_h.m4 delete mode 100644 m4/stdio_h.m4 delete mode 100644 m4/stdlib_h.m4 delete mode 100644 m4/strcase.m4 delete mode 100644 m4/strchrnul.m4 delete mode 100644 m4/strerror.m4 delete mode 100644 m4/string_h.m4 delete mode 100644 m4/strndup.m4 delete mode 100644 m4/strnlen.m4 delete mode 100644 m4/sysexits.m4 delete mode 100644 m4/ulonglong.m4 delete mode 100644 m4/unistd_h.m4 delete mode 100644 m4/vasnprintf.m4 delete mode 100644 m4/vsnprintf.m4 delete mode 100644 m4/wchar.m4 delete mode 100644 m4/wchar_t.m4 delete mode 100644 m4/wint_t.m4 delete mode 100644 m4/xalloc.m4 delete mode 100644 m4/xsize.m4 delete mode 100644 m4/xstrndup.m4 rewrite options.c (88%) diff --git a/Makefile.am b/Makefile.am index 2859f87..64a98ac 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,14 +27,12 @@ if USE_PARKER endif SUBDIRS = $(MAYBE_PIPLIB) $(MAYBE_POLYLIB) $(MAYBE_ISL) $(MAYBE_ISL_POLYLIB) \ $(MAYBE_BERNSTEIN) $(MAYBE_OMEGA) \ - lib $(MAYBE_ZSOLVE) $(MAYBE_PARKER) . doc + $(MAYBE_ZSOLVE) $(MAYBE_PARKER) . doc DIST_SUBDIRS = $(MAYBE_PIPLIB) $(MAYBE_POLYLIB) $(MAYBE_ISL) \ $(MAYBE_ISL_POLYLIB) bernstein $(MAYBE_OMEGA) \ - lib zsolve parker doc + zsolve parker doc FORCE: -lib/libgnu.la: FORCE - cd lib; $(MAKE) $(AM_MAKEFLAGS) libgnu.la bernstein/libbernstein.la: FORCE cd bernstein; $(MAKE) $(AM_MAKEFLAGS) libbernstein.la polylib/libpolylibgmp.la: FORCE @@ -52,10 +50,10 @@ zsolve/libzsolve.la: FORCE parker/libparker.la: FORCE cd parker; $(MAKE) $(AM_MAKEFLAGS) libparker.la -AM_CPPFLAGS = -I$(srcdir)/bernstein/include -I$(srcdir)/lib -Ilib \ +AM_CPPFLAGS = -I$(srcdir)/bernstein/include \ @POLYLIB_CPPFLAGS@ @PIPLIB_CPPFLAGS@ @ginac_CFLAGS@ \ @NTL_CPPFLAGS@ @ISL_CFLAGS@ @ISL_POLYLIB_CFLAGS@ -AM_LDFLAGS = -Llib @POLYLIB_LDFLAGS@ @PIPLIB_LDFLAGS@ @NTL_LDFLAGS@ +AM_LDFLAGS = @POLYLIB_LDFLAGS@ @PIPLIB_LDFLAGS@ @NTL_LDFLAGS@ LIB_ISL = $(ISL_LA) @ISL_LIBS@ LIB_ISL_POLYLIB = $(ISL_POLYLIB_LA) @ISL_POLYLIB_LIBS@ @@ -213,7 +211,7 @@ endif libbarvinok_core_la_LIBADD = @LTLIBOBJS@ $(LIB_ISL_POLYLIB) $(LIB_ISL) \ $(POLYLIB_LA) @POLYLIB_LIBS@ \ $(PIPLIB_LA) @PIPLIB_LIBS@ \ - $(ZSOLVE_LA) lib/libgnu.la + $(ZSOLVE_LA) libbarvinok_core_la_LDFLAGS = @BV_LDFLAGS@ -version-info @versioninfo@ \ $(AM_LDFLAGS) if HAVE_GINAC @@ -247,11 +245,17 @@ testlib_SOURCES = \ testlib.cc barvinok_count_SOURCES = barvinok_count.c barvinok_ehrhart_SOURCES = \ + barvinok_ehrhart_options.c \ + barvinok_ehrhart_options.h \ barvinok_ehrhart.cc \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ $(FDSTREAM) -barvinok_union_SOURCES = barvinok_union.cc +barvinok_union_SOURCES = \ + barvinok_union_options.c \ + barvinok_union_options.h \ + barvinok_union.cc if HAVE_OMEGA BEEO_SOURCES = \ omega_interface/Exit.cc \ @@ -266,7 +270,10 @@ if USE_FDSTREAM FDSTREAM = fdstream.cc fdstream.h endif barvinok_enumerate_SOURCES = \ + barvinok_enumerate_options.c \ + barvinok_enumerate_options.h \ barvinok_enumerate.cc \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ $(FDSTREAM) \ @@ -280,7 +287,10 @@ barvinok_enumerate_SOURCES = \ verify_series.cc EXTRA_barvinok_enumerate_SOURCES = fdstream.cc fdstream.h barvinok_enumerate_e_SOURCES = \ + barvinok_enumerate_e_options.c \ + barvinok_enumerate_e_options.h \ barvinok_enumerate_e.cc \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ $(FDSTREAM) \ @@ -307,11 +317,14 @@ barvinok_enumerate_e_LDADD = \ $(PARKER_LA) $(MONA_LIBS) @OMEGA_LIBS@ $(OMEGA_LA) libbarvinok-core.la \ @ISL_POLYLIB_LIBS@ @ISL_LIBS@ @POLYLIB_LIBS@ @PIPLIB_LIBS@ barvinok_bound_SOURCES = \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ evalue_read.c \ evalue_read.h \ $(FDSTREAM) \ + bound_options.h \ + bound_options.c \ bound.cc \ verify.h \ verify.c @@ -320,7 +333,10 @@ barvinok_bound_LDADD = \ libbarvinok-core.la libbarvinok.la @ISL_POLYLIB_LIBS@ @ISL_LIBS@ \ @POLYLIB_LIBS@ @PIPLIB_LIBS@ barvinok_summate_SOURCES = \ + barvinok_summate_options.c \ + barvinok_summate_options.h \ barvinok_summate.cc \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ evalue_read.c \ @@ -332,6 +348,7 @@ EXTRA_barvinok_summate_SOURCES = fdstream.cc fdstream.h 4coins_SOURCES = 4coins.cc semigroup_holes_SOURCES = semigroup_holes.cc lexmin_SOURCES = \ + lexmin_options.c \ lexmin.h \ lexmin.cc \ combine.c \ @@ -348,6 +365,7 @@ test_approx_SOURCES = \ verify.c test_bound_SOURCES = \ test_bound.c \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ evalue_read.c \ @@ -361,6 +379,7 @@ test_bound_LDADD = \ @POLYLIB_LIBS@ @PIPLIB_LIBS@ evalue_convert_SOURCES = \ evalue_convert_main.c \ + evalue_convert_options.c \ evalue_convert.cc \ evalue_convert.h \ evalue_read.c \ @@ -484,11 +503,14 @@ check-enumerate: barvinok_enumerate$(EXEEXT) ./barvinok_enumerate$(EXEEXT) --verify $$opt < $$i || exit; \ fi \ done +if HAVE_OMEGA + SPEC_OMEGA = '--isl --omega' +endif check-enumerate_e: barvinok_enumerate_e$(EXEEXT) @for dir in $(BEE_TESTDIRS); do \ for i in $(top_srcdir)/tests/$$dir/*; do \ if test -f $$i; then \ - for options in '' '--isl --omega' '--isl'; do \ + for options in '' $(SPEC_OMEGA) '--isl'; do \ for spec in 'random' 'bf' 'df'; do \ opt="--specialization=$$spec $$options"; \ echo $$i $$opt; \ diff --git a/barvinok.cc b/barvinok.cc index 8d24ce5..0cc7d6b 100644 --- a/barvinok.cc +++ b/barvinok.cc @@ -1289,12 +1289,12 @@ out: } emul(&factor, eres); - if (options->approximation_method == BV_APPROX_DROP) { - if (options->polynomial_approximation == BV_APPROX_SIGN_UPPER) + if (options->approx->method == BV_APPROX_DROP) { + if (options->approx->approximation == BV_APPROX_SIGN_UPPER) evalue_frac2polynomial(eres, 1, options->MaxRays); - if (options->polynomial_approximation == BV_APPROX_SIGN_LOWER) + if (options->approx->approximation == BV_APPROX_SIGN_LOWER) evalue_frac2polynomial(eres, -1, options->MaxRays); - if (options->polynomial_approximation == BV_APPROX_SIGN_APPROX) + if (options->approx->approximation == BV_APPROX_SIGN_APPROX) evalue_frac2polynomial(eres, 0, options->MaxRays); } reduce_evalue(eres); @@ -1393,7 +1393,7 @@ evalue* barvinok_enumerate_with_options(Polyhedron *P, Polyhedron* C, next = P->next; P->next = NULL; - if (options->approximation_method == BV_APPROX_BERNOULLI || + if (options->approx->method == BV_APPROX_BERNOULLI || options->summation == BV_SUM_BERNOULLI) { int summation = options->summation; options->summation = BV_SUM_BERNOULLI; @@ -1475,12 +1475,12 @@ static evalue* barvinok_enumerate_ev_f(Polyhedron *P, Polyhedron* C, barvinok_options *options) { unsigned nparam = C->Dimension; - bool do_scale = options->approximation_method == BV_APPROX_SCALE; + bool do_scale = options->approx->method == BV_APPROX_SCALE; if (options->summation == BV_SUM_EULER) return barvinok_summate_unweighted(P, C, options); - if (options->approximation_method == BV_APPROX_VOLUME) + if (options->approx->method == BV_APPROX_VOLUME) return Param_Polyhedron_Volume(P, C, options); if (P->Dimension - nparam == 1 && !do_scale) diff --git a/barvinok/options.h b/barvinok/options.h index 89421a3..d841c4d 100644 --- a/barvinok/options.h +++ b/barvinok/options.h @@ -2,6 +2,7 @@ #define BARVINOK_OPTIONS_H #include +#include #if defined(__cplusplus) extern "C" { @@ -20,7 +21,32 @@ struct barvinok_stats { void barvinok_stats_clear(struct barvinok_stats *stats); void barvinok_stats_print(struct barvinok_stats *stats, FILE *out); +struct barvinok_approximation_options { + #define BV_APPROX_SIGN_NONE 0 + #define BV_APPROX_SIGN_APPROX 1 + #define BV_APPROX_SIGN_LOWER 2 + #define BV_APPROX_SIGN_UPPER 3 + int approximation; + #define BV_APPROX_NONE 0 + #define BV_APPROX_DROP 1 + #define BV_APPROX_SCALE 2 + #define BV_APPROX_VOLUME 3 + #define BV_APPROX_BERNOULLI 4 + int method; + #define BV_APPROX_SCALE_FAST (1 << 0) + #define BV_APPROX_SCALE_NARROW (1 << 1) + #define BV_APPROX_SCALE_NARROW2 (1 << 2) + #define BV_APPROX_SCALE_CHAMBER (1 << 3) + int scale_flags; + #define BV_VOL_LIFT 0 + #define BV_VOL_VERTEX 1 + #define BV_VOL_BARYCENTER 2 + int volume_triangulate; +}; + struct barvinok_options { + struct isl_options *isl; + struct barvinok_approximation_options *approx; struct barvinok_stats *stats; /* PolyLib options */ @@ -45,27 +71,6 @@ struct barvinok_options { int try_Delaunay_triangulation; - #define BV_APPROX_SIGN_NONE 0 - #define BV_APPROX_SIGN_APPROX 1 - #define BV_APPROX_SIGN_LOWER 2 - #define BV_APPROX_SIGN_UPPER 3 - int polynomial_approximation; - #define BV_APPROX_NONE 0 - #define BV_APPROX_DROP 1 - #define BV_APPROX_SCALE 2 - #define BV_APPROX_VOLUME 3 - #define BV_APPROX_BERNOULLI 4 - int approximation_method; - #define BV_APPROX_SCALE_FAST (1 << 0) - #define BV_APPROX_SCALE_NARROW (1 << 1) - #define BV_APPROX_SCALE_NARROW2 (1 << 2) - #define BV_APPROX_SCALE_CHAMBER (1 << 3) - int scale_flags; - #define BV_VOL_LIFT 0 - #define BV_VOL_VERTEX 1 - #define BV_VOL_BARYCENTER 2 - int volume_triangulate; - /* basis reduction options */ #define BV_GBR_PIP 0 #define BV_GBR_GLPK 1 @@ -118,32 +123,7 @@ struct barvinok_options { int gbr_only_first; }; -struct barvinok_options *barvinok_options_new_with_defaults(); -void barvinok_options_free(struct barvinok_options *options); - -#define BV_OPT_SPECIALIZATION 256 -#define BV_OPT_PRIMAL 257 -#define BV_OPT_TABLE 258 -#define BV_OPT_GBR 259 -#define BV_OPT_MAXINDEX 260 -#define BV_OPT_POLAPPROX 261 -#define BV_OPT_APPROX 262 -#define BV_OPT_SCALE 263 -#define BV_OPT_VOL 264 -#define BV_OPT_RECURSE 265 -#define BV_OPT_LP 266 -#define BV_OPT_SUM 267 -#define BV_OPT_CHAMBERS 268 -#define BV_OPT_HULL 269 -#define BV_OPT_PRINT_STATS 270 -#define BV_OPT_BOUND 271 -#define BV_OPT_LAST 271 - -#define BV_GRP_APPROX 1 -#define BV_GRP_LAST 1 - -struct argp; -extern struct argp barvinok_argp; +ISL_ARG_DECL(barvinok_options, struct barvinok_options, barvinok_options_arg) #if defined(__cplusplus) } diff --git a/barvinok_count.c b/barvinok_count.c index fe3e96f..e8e916c 100644 --- a/barvinok_count.c +++ b/barvinok_count.c @@ -3,8 +3,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" int main(int argc, char **argv) { @@ -12,8 +10,7 @@ int main(int argc, char **argv) Polyhedron *A; struct barvinok_options *options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); A = Polyhedron_Read(options->MaxRays); value_init(cb); diff --git a/barvinok_ehrhart.cc b/barvinok_ehrhart.cc index b36194f..5d4b906 100644 --- a/barvinok_ehrhart.cc +++ b/barvinok_ehrhart.cc @@ -3,9 +3,8 @@ #include #include #include -#include "argp.h" -#include "progname.h" #include "evalue_convert.h" +#include "barvinok_ehrhart_options.h" /* The input of this example program is a polytope in PolyLib notation, * i.e., an n by d+2 matrix of the n constraints A x + b >= 0 defining @@ -21,62 +20,23 @@ * should always be 1. */ -struct argp_option argp_options[] = { - { "series", 's', 0, 0, "compute rational generating function" }, - { 0 } -}; - -struct arguments { - int series; - struct barvinok_options *barvinok; - struct convert_options convert; -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct arguments *options = (struct arguments*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->barvinok; - state->child_inputs[1] = &options->convert; - options->series = 0; - break; - case 's': - options->series = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - int main(int argc, char **argv) { Polyhedron *A, *C, *U; const char **param_name; int print_solution = 1; - struct arguments options; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { &convert_argp, 0, "output conversion", BV_GRP_LAST+1 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - barvinok_options *bv_options = barvinok_options_new_with_defaults(); + struct ehrhart_options *options = ehrhart_options_new_with_defaults(); - options.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + argc = ehrhart_options_parse(options, argc, argv, ISL_ARG_ALL); - A = Polyhedron_Read(bv_options->MaxRays); + A = Polyhedron_Read(options->barvinok->MaxRays); param_name = Read_ParamNames(stdin, 1); Polyhedron_Print(stdout, P_VALUE_FMT, A); C = Cone_over_Polyhedron(A); U = Universe_Polyhedron(1); - if (options.series) { + if (options->series) { gen_fun *gf; - gf = barvinok_series_with_options(C, U, bv_options); + gf = barvinok_series_with_options(C, U, options->barvinok); gf->print(std::cout, U->Dimension, param_name); puts(""); delete gf; @@ -87,9 +47,9 @@ int main(int argc, char **argv) * vertices, rather than letting barvinok_enumerate_ev (re)compute * them through Polyhedron2Param_SimplifiedDomain. */ - EP = barvinok_enumerate_with_options(C, U, bv_options); + EP = barvinok_enumerate_with_options(C, U, options->barvinok); assert(EP); - if (evalue_convert(EP, &options.convert, bv_options->verbose, + if (evalue_convert(EP, options->convert, options->barvinok->verbose, C->Dimension, param_name)) print_solution = 0; if (print_solution) @@ -100,6 +60,6 @@ int main(int argc, char **argv) Polyhedron_Free(A); Polyhedron_Free(C); Polyhedron_Free(U); - barvinok_options_free(bv_options); + ehrhart_options_free(options); return 0; } diff --git a/barvinok_ehrhart_options.c b/barvinok_ehrhart_options.c new file mode 100644 index 0000000..bf90e0d --- /dev/null +++ b/barvinok_ehrhart_options.c @@ -0,0 +1,13 @@ +#include +#include "barvinok_ehrhart_options.h" + +struct isl_arg ehrhart_options_arg[] = { +ISL_ARG_CHILD(struct ehrhart_options, convert, NULL, + convert_options_arg, "output conversion") +ISL_ARG_CHILD(struct ehrhart_options, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_BOOL(struct ehrhart_options, series, 's', "series", 0, + "compute rational generating function") +ISL_ARG_END +}; + +ISL_ARG_DEF(ehrhart_options, struct ehrhart_options, ehrhart_options_arg) diff --git a/barvinok_ehrhart_options.h b/barvinok_ehrhart_options.h new file mode 100644 index 0000000..ef28d8c --- /dev/null +++ b/barvinok_ehrhart_options.h @@ -0,0 +1,18 @@ +#include +#include "evalue_convert.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +struct ehrhart_options { + int series; + struct barvinok_options *barvinok; + struct convert_options *convert; +}; + +ISL_ARG_DECL(ehrhart_options, struct ehrhart_options, ehrhart_options_arg) + +#if defined(__cplusplus) +} +#endif diff --git a/barvinok_enumerate.cc b/barvinok_enumerate.cc index 61ac772..87cef03 100644 --- a/barvinok_enumerate.cc +++ b/barvinok_enumerate.cc @@ -5,8 +5,7 @@ #include #include #include -#include "argp.h" -#include "progname.h" +#include "barvinok_enumerate_options.h" #include "verify.h" #include "verif_ehrhart.h" #include "verify_series.h" @@ -27,49 +26,6 @@ using std::endl; * Both polytopes are in PolyLib notation. */ -struct argp_option argp_options[] = { - { "size", 'S' }, - { "series", 's', 0, 0, "compute rational generating function" }, - { "explicit", 'e', 0, 0, "convert rgf to psp" }, - { 0 } -}; - -struct arguments { - int size; - int series; - int function; - struct verify_options verify; - struct convert_options convert; -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct arguments *options = (struct arguments*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->verify.barvinok; - state->child_inputs[1] = &options->verify; - state->child_inputs[2] = &options->convert; - options->size = 0; - options->series = 0; - options->function = 0; - break; - case 'S': - options->size = 1; - break; - case 'e': - options->function = 1; - /* fall through */ - case 's': - options->series = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - struct verify_point_enum { struct verify_point_data vpd; isl_set *set; @@ -84,7 +40,7 @@ static int verify_point(__isl_take isl_point *pnt, void *user) unsigned nparam; isl_int v, n, d; isl_qpolynomial *cnt = NULL; - int pa = vpe->vpd.options->barvinok->polynomial_approximation; + int pa = vpe->vpd.options->barvinok->approx->approximation; int cst; int ok; FILE *out = vpe->vpd.options->print_all ? stdout : stderr; @@ -212,34 +168,34 @@ static int verify_isl(Polyhedron *P, Polyhedron *C, } static int verify(Polyhedron *P, Polyhedron *C, evalue *EP, skewed_gen_fun *gf, - arguments *options) + struct enumerate_options *options) { Polyhedron *CS, *S; Vector *p; int result = 0; if (!options->series || options->function) - return verify_isl(P, C, EP, &options->verify); + return verify_isl(P, C, EP, options->verify); - CS = check_poly_context_scan(P, &C, C->Dimension, &options->verify); + CS = check_poly_context_scan(P, &C, C->Dimension, options->verify); p = Vector_Alloc(P->Dimension+2); value_set_si(p->p[P->Dimension+1], 1); /* S = scanning list of polyhedra */ - S = Polyhedron_Scan(P, C, options->verify.barvinok->MaxRays); + S = Polyhedron_Scan(P, C, options->verify->barvinok->MaxRays); - check_poly_init(C, &options->verify); + check_poly_init(C, options->verify); /******* CHECK NOW *********/ if (S) { if (!options->series || options->function) { if (!check_poly_EP(S, CS, EP, 0, C->Dimension, 0, p->p, - &options->verify)) + options->verify)) result = -1; } else { if (!check_poly_gf(S, CS, gf, 0, C->Dimension, 0, p->p, - &options->verify)) + options->verify)) result = -1; } Domain_Free(S); @@ -248,7 +204,7 @@ static int verify(Polyhedron *P, Polyhedron *C, evalue *EP, skewed_gen_fun *gf, if (result == -1) fprintf(stderr,"Check failed !\n"); - if (!options->verify.print_all) + if (!options->verify->print_all) printf( "\n" ); Vector_Free(p); @@ -431,68 +387,58 @@ int main(int argc, char **argv) const char **param_name; int print_solution = 1; int result = 0; - struct arguments options; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", BV_GRP_LAST+1 }, - { &convert_argp, 0, "output conversion", BV_GRP_LAST+2 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); - - options.verify.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + struct enumerate_options *options = enumerate_options_new_with_defaults(); + + argc = enumerate_options_parse(options, argc, argv, ISL_ARG_ALL); M = Matrix_Read(); assert(M); - A = Constraints2Polyhedron(M, bv_options->MaxRays); + A = Constraints2Polyhedron(M, options->verify->barvinok->MaxRays); Matrix_Free(M); M = Matrix_Read(); assert(M); - C = Constraints2Polyhedron(M, bv_options->MaxRays); + C = Constraints2Polyhedron(M, options->verify->barvinok->MaxRays); Matrix_Free(M); assert(A->Dimension >= C->Dimension); param_name = Read_ParamNames(stdin, C->Dimension); - if (options.verify.verify) { - verify_options_set_range(&options.verify, A->Dimension); - if (!bv_options->verbose) + if (options->verify->verify) { + verify_options_set_range(options->verify, A->Dimension); + if (!options->verify->barvinok->verbose) print_solution = 0; } - if (print_solution && bv_options->verbose) { + if (print_solution && options->verify->barvinok->verbose) { Polyhedron_Print(stdout, P_VALUE_FMT, A); Polyhedron_Print(stdout, P_VALUE_FMT, C); } - if (options.series) { - gf = series(A, C, bv_options); + if (options->series) { + gf = series(A, C, options->verify->barvinok); if (print_solution) { gf->print(cout, C->Dimension, param_name); puts(""); } - if (options.function) { + if (options->function) { EP = *gf; if (print_solution) print_evalue(stdout, EP, param_name); } } else { - EP = barvinok_enumerate_with_options(A, C, bv_options); + EP = barvinok_enumerate_with_options(A, C, options->verify->barvinok); assert(EP); - if (evalue_convert(EP, &options.convert, bv_options->verbose, + if (evalue_convert(EP, options->convert, options->verify->barvinok->verbose, C->Dimension, param_name)) print_solution = 0; - if (options.size) + if (options->size) printf("\nSize: %d\n", evalue_size(EP)); if (print_solution) print_evalue(stdout, EP, param_name); } - if (options.verify.verify) { - options.verify.params = param_name; - result = verify(A, C, EP, gf, &options); + if (options->verify->verify) { + options->verify->params = param_name; + result = verify(A, C, EP, gf, options); } if (gf) @@ -500,12 +446,12 @@ int main(int argc, char **argv) if (EP) evalue_free(EP); - if (options.verify.barvinok->print_stats) - barvinok_stats_print(options.verify.barvinok->stats, stdout); + if (options->verify->barvinok->print_stats) + barvinok_stats_print(options->verify->barvinok->stats, stdout); Free_ParamNames(param_name, C->Dimension); Polyhedron_Free(A); Polyhedron_Free(C); - barvinok_options_free(bv_options); + enumerate_options_free(options); return result; } diff --git a/barvinok_enumerate_e.cc b/barvinok_enumerate_e.cc index 657f0fc..c2f9918 100644 --- a/barvinok_enumerate_e.cc +++ b/barvinok_enumerate_e.cc @@ -4,9 +4,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" -#include "error.h" #include "config.h" #ifdef HAVE_OMEGA #include "omega_interface/convert.h" @@ -17,6 +14,7 @@ #include "verif_ehrhart.h" #include "verify_series.h" #include "evalue_convert.h" +#include "barvinok_enumerate_e_options.h" /* The input of this example program is a polytope in combined * data and parameter space followed by two lines indicating @@ -27,70 +25,6 @@ * The polytope is in PolyLib notation. */ -struct argp_option argp_options[] = { - { "isl", 'i', 0, 0 }, - { "omega", 'o', 0, 0 }, - { "parker", 'P', 0, 0 }, - { "series", 's', 0, 0 }, - { "series", 's', 0, 0, "compute rational generating function" }, - { "explicit", 'e', 0, 0, "convert rgf to psp" }, - { "scarf", 'S', 0, 0 }, - { 0 } -}; - -struct arguments { - struct verify_options verify; - struct convert_options convert; - int isl; - int omega; - int parker; - int scarf; - int series; - int function; -}; - -error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct arguments *arguments = (struct arguments *)(state->input); - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = arguments->verify.barvinok; - state->child_inputs[1] = &arguments->verify; - state->child_inputs[2] = &arguments->convert; - break; - case 'e': - arguments->function = 1; - /* fall through */ - case 's': - arguments->series = 1; - break; - case 'S': - arguments->scarf = 1; - break; - case 'o': -#ifdef HAVE_OMEGA - arguments->omega = 1; -#else - error(0, 0, "--omega option not supported"); -#endif - break; - case 'P': -#ifdef USE_PARKER - arguments->parker = 1; -#else - error(0, 0, "--parker option not supported"); -#endif - break; - case 'i': - arguments->isl = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - #ifdef HAVE_OMEGA Polyhedron *Omega_simplify(Polyhedron *P, @@ -122,7 +56,7 @@ evalue *barvinok_enumerate_parker(Polyhedron *P, static void verify_results(Polyhedron *P, evalue *EP, gen_fun *gf, int exist, int nparam, - arguments *options); + enumerate_e_options *options); static char *next_line(FILE *input, char *line, unsigned len) { @@ -148,29 +82,12 @@ int main(int argc, char **argv) evalue *EP = NULL; gen_fun *gf = NULL; int print_solution = 1; - struct arguments arguments; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", BV_GRP_LAST+1 }, - { &convert_argp, 0, "output conversion", BV_GRP_LAST+2 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct barvinok_options *options = barvinok_options_new_with_defaults(); - - arguments.verify.barvinok = options; - arguments.isl = 0; - arguments.omega = 0; - arguments.parker = 0; - arguments.scarf = 0; - arguments.series = 0; - arguments.function = 0; + struct enumerate_e_options *options = enumerate_e_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &arguments); + argc = enumerate_e_options_parse(options, argc, argv, ISL_ARG_ALL); MA = Matrix_Read(); - A = Constraints2Polyhedron(MA, options->MaxRays); + A = Constraints2Polyhedron(MA, options->verify->barvinok->MaxRays); Matrix_Free(MA); exist = -1; @@ -187,113 +104,119 @@ int main(int argc, char **argv) /******* Read the options: initialize Min and Max ********/ - if (arguments.verify.verify) { - verify_options_set_range(&arguments.verify, A->Dimension); - if (!options->verbose) + if (options->verify->verify) { + verify_options_set_range(options->verify, A->Dimension); + if (!options->verify->barvinok->verbose) print_solution = 0; } - if (print_solution && options->verbose) { + if (print_solution && options->verify->barvinok->verbose) { Polyhedron_Print(stdout, P_VALUE_FMT, A); printf("exist: %d, nparam: %d\n", exist, nparam); } param_name = Read_ParamNames(stdin, nparam); nvar = A->Dimension - exist - nparam; - if (arguments.omega) { - A = Omega_simplify(A, exist, nparam, param_name, options->MaxRays); + if (options->omega) { + A = Omega_simplify(A, exist, nparam, param_name, + options->verify->barvinok->MaxRays); assert(!A->next); exist = A->Dimension - nvar - nparam; } - if (arguments.series) { - if (arguments.scarf) - gf = barvinok_enumerate_scarf_series(A, exist, nparam, options); + if (options->series) { + if (options->scarf) + gf = barvinok_enumerate_scarf_series(A, exist, nparam, + options->verify->barvinok); else - gf = barvinok_enumerate_e_series(A, exist, nparam, options); + gf = barvinok_enumerate_e_series(A, exist, nparam, + options->verify->barvinok); if (print_solution) { gf->print(std::cout, nparam, param_name); puts(""); } - if (arguments.function) { + if (options->function) { EP = *gf; if (print_solution) print_evalue(stdout, EP, param_name); } } else { - if (arguments.parker) - EP = barvinok_enumerate_parker(A, A->Dimension-nparam-exist, - nparam, options->MaxRays); - else if (arguments.scarf) - EP = barvinok_enumerate_scarf(A, exist, nparam, options); - else if (arguments.isl && exist > 0) - EP = barvinok_enumerate_isl(A, exist, nparam, options); + if (options->parker) + EP = barvinok_enumerate_parker(A, A->Dimension-nparam-exist, nparam, + options->verify->barvinok->MaxRays); + else if (options->scarf) + EP = barvinok_enumerate_scarf(A, exist, nparam, + options->verify->barvinok); + else if (options->isl && exist > 0) + EP = barvinok_enumerate_isl(A, exist, nparam, + options->verify->barvinok); else - EP = barvinok_enumerate_e_with_options(A, exist, nparam, options); + EP = barvinok_enumerate_e_with_options(A, exist, nparam, + options->verify->barvinok); reduce_evalue(EP); - if (evalue_convert(EP, &arguments.convert, options->verbose, nparam, - param_name)) + if (evalue_convert(EP, options->convert, + options->verify->barvinok->verbose, nparam, param_name)) print_solution = 0; if (print_solution) print_evalue(stdout, EP, param_name); } - if (arguments.verify.verify) { - arguments.verify.params = param_name; - verify_results(A, EP, gf, exist, nparam, &arguments); + if (options->verify->verify) { + options->verify->params = param_name; + verify_results(A, EP, gf, exist, nparam, options); } if (gf) delete gf; if (EP) evalue_free(EP); - if (options->print_stats) - barvinok_stats_print(options->stats, stdout); + if (options->verify->barvinok->print_stats) + barvinok_stats_print(options->verify->barvinok->stats, stdout); Free_ParamNames(param_name, nparam); Polyhedron_Free(A); - barvinok_options_free(options); + enumerate_e_options_free(options); return 0; } void verify_results(Polyhedron *P, evalue *EP, gen_fun *gf, int exist, int nparam, - arguments *options) + enumerate_e_options *options) { int i; int res = 0; Vector *p; Value tmp; Polyhedron *S, *CS; - unsigned MaxRays = options->verify.barvinok->MaxRays; + unsigned MaxRays = options->verify->barvinok->MaxRays; Polyhedron *C = NULL; value_init(tmp); p = Vector_Alloc(P->Dimension+2); value_set_si(p->p[P->Dimension+1], 1); - CS = check_poly_context_scan(P, &C, nparam, &options->verify); + CS = check_poly_context_scan(P, &C, nparam, options->verify); if (!C) C = Universe_Polyhedron(nparam); /* S = scanning list of polyhedra */ S = Polyhedron_Scan(P, C, MaxRays & POL_NO_DUAL ? 0 : MaxRays); - check_poly_init(C, &options->verify); + check_poly_init(C, options->verify); /******* CHECK NOW *********/ if (S) { if (!options->series || options->function) { if (!check_poly_EP(S, CS, EP, exist, nparam, 0, p->p, - &options->verify)) + options->verify)) res = -1; } else { skewed_gen_fun *sgf = new skewed_gen_fun(new gen_fun(gf)); if (!check_poly_gf(S, CS, sgf, exist, nparam, 0, p->p, - &options->verify)) + options->verify)) res = -1; delete sgf; } } - if (!options->verify.print_all) + if (!options->verify->print_all) printf( "\n" ); Vector_Free(p); diff --git a/barvinok_enumerate_e_options.c b/barvinok_enumerate_e_options.c new file mode 100644 index 0000000..a4ea197 --- /dev/null +++ b/barvinok_enumerate_e_options.c @@ -0,0 +1,24 @@ +#include "barvinok_enumerate_e_options.h" +#include "config.h" + +struct isl_arg enumerate_e_options_arg[] = { +ISL_ARG_CHILD(struct enumerate_e_options, verify, NULL, + verify_options_arg, "verification") +ISL_ARG_CHILD(struct enumerate_e_options, convert, NULL, + convert_options_arg, "output conversion") +ISL_ARG_BOOL(struct enumerate_e_options, isl, 'i', "isl", 0, NULL) +#ifdef HAVE_OMEGA +ISL_ARG_BOOL(struct enumerate_e_options, omega, 'o', "omega", 0, NULL) +#endif +#ifdef USE_PARKER +ISL_ARG_BOOL(struct enumerate_e_options, parker, 'P', "parker", 0, NULL) +#endif +ISL_ARG_BOOL(struct enumerate_e_options, scarf, 'S', "scarf", 0, NULL) +ISL_ARG_BOOL(struct enumerate_e_options, series, 's', "series", 0, + "compute rational generating function") +ISL_ARG_BOOL(struct enumerate_e_options, function, 'e', "explicit", 0, + "convert rgf to psp") +ISL_ARG_END +}; + +ISL_ARG_DEF(enumerate_e_options, struct enumerate_e_options, enumerate_e_options_arg) diff --git a/barvinok_enumerate_e_options.h b/barvinok_enumerate_e_options.h new file mode 100644 index 0000000..5b8e93e --- /dev/null +++ b/barvinok_enumerate_e_options.h @@ -0,0 +1,24 @@ +#include +#include "evalue_convert.h" +#include "verify.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +struct enumerate_e_options { + struct verify_options *verify; + struct convert_options *convert; + int isl; + int omega; + int parker; + int scarf; + int series; + int function; +}; + +ISL_ARG_DECL(enumerate_e_options, struct enumerate_e_options, enumerate_e_options_arg) + +#if defined(__cplusplus) +} +#endif diff --git a/barvinok_enumerate_options.c b/barvinok_enumerate_options.c new file mode 100644 index 0000000..5de15bc --- /dev/null +++ b/barvinok_enumerate_options.c @@ -0,0 +1,16 @@ +#include "barvinok_enumerate_options.h" + +struct isl_arg enumerate_options_arg[] = { +ISL_ARG_CHILD(struct enumerate_options, verify, NULL, + verify_options_arg, "verification") +ISL_ARG_CHILD(struct enumerate_options, convert, NULL, + convert_options_arg, "output conversion") +ISL_ARG_BOOL(struct enumerate_options, size, 'S', "size", 0, NULL) +ISL_ARG_BOOL(struct enumerate_options, series, 's', "series", 0, + "compute rational generating function") +ISL_ARG_BOOL(struct enumerate_options, function, 'e', "explicit", 0, + "convert rgf to psp") +ISL_ARG_END +}; + +ISL_ARG_DEF(enumerate_options, struct enumerate_options, enumerate_options_arg) diff --git a/barvinok_enumerate_options.h b/barvinok_enumerate_options.h new file mode 100644 index 0000000..30cfbb7 --- /dev/null +++ b/barvinok_enumerate_options.h @@ -0,0 +1,21 @@ +#include +#include "evalue_convert.h" +#include "verify.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +struct enumerate_options { + int size; + int series; + int function; + struct verify_options *verify; + struct convert_options *convert; +}; + +ISL_ARG_DECL(enumerate_options, struct enumerate_options, enumerate_options_arg) + +#if defined(__cplusplus) +} +#endif diff --git a/barvinok_summate.cc b/barvinok_summate.cc index 5b009ad..57aa109 100644 --- a/barvinok_summate.cc +++ b/barvinok_summate.cc @@ -3,8 +3,7 @@ #include #include #include -#include "argp.h" -#include "progname.h" +#include "barvinok_summate_options.h" #include "evalue_convert.h" #include "evalue_read.h" #include "verify.h" @@ -15,40 +14,6 @@ using std::endl; #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type)) -#define OPT_VARS (BV_OPT_LAST+1) - -struct argp_option argp_options[] = { - { "variables", OPT_VARS, "list", 0, - "comma separated list of variables over which to sum" }, - { 0 } -}; - -struct options { - struct convert_options convert; - struct verify_options verify; - char* var_list; -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct options *options = (struct options*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = &options->convert; - state->child_inputs[1] = &options->verify; - state->child_inputs[2] = options->verify.barvinok; - options->var_list = NULL; - break; - case OPT_VARS: - options->var_list = strdup(arg); - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - static int check_poly_sum(const struct check_poly_data *data, int nparam, Value *z, const struct verify_options *options); @@ -133,37 +98,28 @@ int main(int argc, char **argv) const char **all_vars = NULL; unsigned nvar; unsigned nparam; - struct options options; - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); - static struct argp_child argp_children[] = { - { &convert_argp, 0, "input conversion", 1 }, - { &verify_argp, 0, "verification", 2 }, - { &barvinok_argp, 0, "barvinok options", 3 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; int result = 0; + struct options *options = options_new_with_defaults(); - options.verify.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + argc = options_parse(options, argc, argv, ISL_ARG_ALL); - EP = evalue_read_from_file(stdin, options.var_list, &all_vars, - &nvar, &nparam, bv_options->MaxRays); + EP = evalue_read_from_file(stdin, options->var_list, &all_vars, + &nvar, &nparam, options->verify->barvinok->MaxRays); assert(EP); - if (options.verify.verify) - verify_options_set_range(&options.verify, nvar+nparam); + if (options->verify->verify) + verify_options_set_range(options->verify, nvar+nparam); - evalue_convert(EP, &options.convert, bv_options->verbose, nparam, all_vars); + evalue_convert(EP, options->convert, options->verify->barvinok->verbose, + nparam, all_vars); if (EVALUE_IS_ZERO(*EP)) print_evalue(stdout, EP, all_vars); else { - evalue *sum = barvinok_summate(EP, nvar, bv_options); + evalue *sum = barvinok_summate(EP, nvar, options->verify->barvinok); assert(sum); - if (options.verify.verify) - result = verify(EP, sum, nvar, nparam, &options.verify); + if (options->verify->verify) + result = verify(EP, sum, nvar, nparam, options->verify); else print_evalue(stdout, sum, all_vars+nvar); evalue_free(sum); @@ -171,9 +127,7 @@ int main(int argc, char **argv) evalue_free(EP); - if (options.var_list) - free(options.var_list); Free_ParamNames(all_vars, nvar+nparam); - barvinok_options_free(bv_options); + options_free(options); return result; } diff --git a/barvinok_summate_options.c b/barvinok_summate_options.c new file mode 100644 index 0000000..412ba2a --- /dev/null +++ b/barvinok_summate_options.c @@ -0,0 +1,13 @@ +#include "barvinok_summate_options.h" + +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct options, verify, NULL, + verify_options_arg, "verification") +ISL_ARG_CHILD(struct options, convert, NULL, + convert_options_arg, "output conversion") +ISL_ARG_STR(struct options, var_list, 0, "variables", "list", NULL, + "comma separated list of variables over which to sum") +ISL_ARG_END +}; + +ISL_ARG_DEF(options, struct options, options_arg) diff --git a/barvinok_summate_options.h b/barvinok_summate_options.h new file mode 100644 index 0000000..c6415c5 --- /dev/null +++ b/barvinok_summate_options.h @@ -0,0 +1,19 @@ +#include +#include "evalue_convert.h" +#include "verify.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +struct options { + struct convert_options *convert; + struct verify_options *verify; + char *var_list; +}; + +ISL_ARG_DECL(options, struct options, options_arg) + +#if defined(__cplusplus) +} +#endif diff --git a/barvinok_union.cc b/barvinok_union.cc index b5e56e7..255908e 100644 --- a/barvinok_union.cc +++ b/barvinok_union.cc @@ -1,7 +1,6 @@ #include #include -#include "argp.h" -#include "progname.h" +#include "barvinok_union_options.h" /* The input of this example program is similar to that of ehrhart_union * in the PolyLib distribution, the difference being that the number of @@ -12,34 +11,6 @@ * All polytopes are in PolyLib notation. */ -struct argp_option argp_options[] = { - { "series", 's', 0, 0, "compute rational generating function" }, - { 0 } -}; - -struct arguments { - int series; - struct barvinok_options *barvinok; -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct arguments *options = (struct arguments*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->barvinok; - options->series = 0; - break; - case 's': - options->series = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - int main(int argc, char **argv) { @@ -49,18 +20,9 @@ int main(int argc, char **argv) const char **param_name; char s[128]; int c, ind = 0; - int series = 0; - struct arguments options; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); + struct union_options *options = union_options_new_with_defaults(); - options.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + argc = union_options_parse(options, argc, argv, ISL_ARG_ALL); fgets(s, 128, stdin); while ((*s=='#') || (sscanf(s, "%d", &npol)<1)) @@ -69,31 +31,31 @@ int main(int argc, char **argv) for (i = 0; i < npol; ++i) { Polyhedron *P; M = Matrix_Read(); - P = Constraints2Polyhedron(M, bv_options->MaxRays); + P = Constraints2Polyhedron(M, options->barvinok->MaxRays); Matrix_Free(M); D = DomainConcat(P, D); } M = Matrix_Read(); - C = Constraints2Polyhedron(M, bv_options->MaxRays); + C = Constraints2Polyhedron(M, options->barvinok->MaxRays); Matrix_Free(M); Polyhedron_Print(stdout, P_VALUE_FMT, D); Polyhedron_Print(stdout, P_VALUE_FMT, C); param_name = Read_ParamNames(stdin, C->Dimension); - if (series) { + if (options->series) { gen_fun *gf; - gf = barvinok_enumerate_union_series(D, C, bv_options->MaxRays); + gf = barvinok_enumerate_union_series(D, C, options->barvinok->MaxRays); gf->print(std::cout, C->Dimension, param_name); puts(""); delete gf; } else { evalue *EP; - EP = barvinok_enumerate_union(D, C, bv_options->MaxRays); + EP = barvinok_enumerate_union(D, C, options->barvinok->MaxRays); print_evalue(stdout, EP, param_name); evalue_free(EP); } Free_ParamNames(param_name, C->Dimension); Domain_Free(D); Polyhedron_Free(C); - barvinok_options_free(bv_options); + union_options_free(options); return 0; } diff --git a/barvinok_union_options.c b/barvinok_union_options.c new file mode 100644 index 0000000..dbd1c27 --- /dev/null +++ b/barvinok_union_options.c @@ -0,0 +1,11 @@ +#include +#include "barvinok_union_options.h" + +struct isl_arg union_options_arg[] = { +ISL_ARG_CHILD(struct union_options, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_BOOL(struct union_options, series, 's', "series", 0, + "compute rational generating function") +ISL_ARG_END +}; + +ISL_ARG_DEF(union_options, struct union_options, union_options_arg) diff --git a/barvinok_union_options.h b/barvinok_union_options.h new file mode 100644 index 0000000..de11e86 --- /dev/null +++ b/barvinok_union_options.h @@ -0,0 +1,17 @@ +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +struct union_options { + int series; + struct barvinok_options *barvinok; +}; + +ISL_ARG_DECL(union_options, struct union_options, union_options_arg) + +#if defined(__cplusplus) +} +#endif diff --git a/bernoulli.c b/bernoulli.c index 77d3128..84f9298 100644 --- a/bernoulli.c +++ b/bernoulli.c @@ -254,7 +254,7 @@ static evalue *compute_poly_u(evalue *poly_u, Value *upper, Vector *row, struct poly_list *faulhaber, struct Bernoulli_data *data) { - int exact = data->options->approximation_method == BV_APPROX_NONE; + int exact = data->options->approx->method == BV_APPROX_NONE; if (poly_u) return poly_u; Vector_Copy(upper+2, row->p, dim+1); @@ -268,7 +268,7 @@ static evalue *compute_poly_l(evalue *poly_l, Value *lower, Vector *row, struct poly_list *faulhaber, struct Bernoulli_data *data) { - int exact = data->options->approximation_method == BV_APPROX_NONE; + int exact = data->options->approx->method == BV_APPROX_NONE; if (poly_l) return poly_l; Vector_Copy(lower+2, row->p, dim+1); @@ -321,7 +321,7 @@ static evalue *linear_term(const evalue *cst, Value *lower, Value *upper, static void Bernoulli_init(unsigned n, void *cb_data) { struct Bernoulli_data *data = (struct Bernoulli_data *)cb_data; - int exact = data->options->approximation_method == BV_APPROX_NONE; + int exact = data->options->approx->method == BV_APPROX_NONE; int cases = exact ? 3 : 5; evalue_section_array_ensure(data->sections, cases * n); @@ -423,7 +423,7 @@ static void Bernoulli_cb(Matrix *M, Value *lower, Value *upper, void *cb_data) Value tmp; unsigned dim = M->NbColumns-2; Vector *row; - int exact = data->options->approximation_method == BV_APPROX_NONE; + int exact = data->options->approx->method == BV_APPROX_NONE; int cases = exact ? 3 : 5; assert(lower); @@ -894,7 +894,7 @@ evalue *bernoulli_summate(Polyhedron *P, evalue *E, unsigned nvar, evalue *E_orig = E; Value period; evalue *sum; - int exact = options->approximation_method == BV_APPROX_NONE; + int exact = options->approx->method == BV_APPROX_NONE; value_init(period); diff --git a/bound.cc b/bound.cc index cf25976..a0b64c7 100644 --- a/bound.cc +++ b/bound.cc @@ -6,8 +6,7 @@ #include #include #include -#include "argp.h" -#include "progname.h" +#include "bound_options.h" #include "evalue_convert.h" #include "evalue_read.h" #include "verify.h" @@ -19,65 +18,6 @@ using namespace barvinok; #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type)) -#define OPT_VARS (BV_OPT_LAST+1) -#define OPT_SPLIT (BV_OPT_LAST+2) -#define OPT_LOWER (BV_OPT_LAST+3) -#define OPT_ITERATE (BV_OPT_LAST+4) - -struct argp_option argp_options[] = { - { "split", OPT_SPLIT, "int" }, - { "variables", OPT_VARS, "list", 0, - "comma separated list of variables over which to compute a bound" }, - { "lower", OPT_LOWER, 0, 0, "compute lower bound instead of upper bound"}, - { "iterate", OPT_ITERATE, "int", 1, - "exact result by iterating over domain (of specified maximal size)"}, - { 0 } -}; - -struct options { - struct convert_options convert; - struct verify_options verify; - char* var_list; - int split; - int lower; - int iterate; -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct options *options = (struct options*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = &options->convert; - state->child_inputs[1] = &options->verify; - state->child_inputs[2] = options->verify.barvinok; - options->var_list = NULL; - options->split = 0; - options->lower = 0; - options->iterate = 0; - break; - case OPT_VARS: - options->var_list = strdup(arg); - break; - case OPT_SPLIT: - options->split = atoi(arg); - break; - case OPT_LOWER: - options->lower = 1; - break; - case OPT_ITERATE: - if (!arg) - options->iterate = -1; - else - options->iterate = atoi(arg); - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - struct verify_point_bound { struct verify_point_data vpd; isl_pw_qpolynomial *pwqp; @@ -342,7 +282,7 @@ static __isl_give isl_pw_qpolynomial_fold *optimize(evalue *EP, unsigned nvar, isl_pw_qpolynomial_fold *pwf = NULL, *pwf_more = NULL; split_on_domain_size(EP, &EP_less, &EP_more, options->iterate, - options->verify.barvinok); + options->verify->barvinok); if (!EVALUE_IS_ZERO(*EP_less)) { options->iterate = -1; pwf = optimize(EP_less, nvar, C, isl_dim_copy(dim), options); @@ -360,7 +300,7 @@ static __isl_give isl_pw_qpolynomial_fold *optimize(evalue *EP, unsigned nvar, return pwf; return isl_pw_qpolynomial_fold_add(pwf, pwf_more); } - int method = options->verify.barvinok->bound; + int method = options->verify->barvinok->bound; isl_dim *dim_EP; isl_pw_qpolynomial *pwqp; enum isl_fold type = options->lower ? isl_fold_min : isl_fold_max; @@ -381,7 +321,7 @@ static int optimize(evalue *EP, const char **all_vars, U = Universe_Polyhedron(nparam); int print_solution = 1; int result = 0; - isl_ctx *ctx = isl_ctx_alloc(); + isl_ctx *ctx = isl_ctx_alloc_with_options(options_arg, options); isl_dim *dim; isl_pw_qpolynomial_fold *pwf; @@ -389,16 +329,16 @@ static int optimize(evalue *EP, const char **all_vars, for (int i = 0; i < nparam; ++i) dim = isl_dim_set_name(dim, isl_dim_param, i, all_vars[nvar + i]); - if (options->verify.verify) { - verify_options_set_range(&options->verify, nvar+nparam); - if (!options->verify.barvinok->verbose) + if (options->verify->verify) { + verify_options_set_range(options->verify, nvar+nparam); + if (!options->verify->barvinok->verbose) print_solution = 0; } if (options->lower) - options->verify.barvinok->bernstein_optimize = BV_BERNSTEIN_MIN; + options->verify->barvinok->bernstein_optimize = BV_BERNSTEIN_MIN; else - options->verify.barvinok->bernstein_optimize = BV_BERNSTEIN_MAX; + options->verify->barvinok->bernstein_optimize = BV_BERNSTEIN_MAX; pwf = optimize(EP, nvar, U, dim, options); assert(pwf); if (print_solution) { @@ -407,8 +347,8 @@ static int optimize(evalue *EP, const char **all_vars, p = isl_printer_end_line(p); isl_printer_free(p); } - if (options->verify.verify) { - result = verify(pwf, EP, nvar, &options->verify); + if (options->verify->verify) { + result = verify(pwf, EP, nvar, options->verify); } isl_pw_qpolynomial_fold_free(pwf); @@ -425,41 +365,28 @@ int main(int argc, char **argv) const char **all_vars = NULL; unsigned nvar; unsigned nparam; - struct options options; - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); - static struct argp_child argp_children[] = { - { &convert_argp, 0, "input conversion", 1 }, - { &verify_argp, 0, "verification", 2 }, - { &barvinok_argp, 0, "barvinok options", 3 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; + struct options *options = options_new_with_defaults(); int result = 0; - options.verify.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + argc = options_parse(options, argc, argv, ISL_ARG_ALL); - EP = evalue_read_from_file(stdin, options.var_list, &all_vars, - &nvar, &nparam, bv_options->MaxRays); + EP = evalue_read_from_file(stdin, options->var_list, &all_vars, + &nvar, &nparam, options->verify->barvinok->MaxRays); assert(EP); - if (options.split) - evalue_split_periods(EP, options.split, bv_options->MaxRays); + if (options->split) + evalue_split_periods(EP, options->split, options->verify->barvinok->MaxRays); - evalue_convert(EP, &options.convert, bv_options->verbose, + evalue_convert(EP, options->convert, options->verify->barvinok->verbose, nvar+nparam, all_vars); if (EVALUE_IS_ZERO(*EP)) print_evalue(stdout, EP, all_vars); else - result = optimize(EP, all_vars, nvar, nparam, &options); + result = optimize(EP, all_vars, nvar, nparam, options); evalue_free(EP); - if (options.var_list) - free(options.var_list); Free_ParamNames(all_vars, nvar+nparam); - barvinok_options_free(bv_options); return result; } diff --git a/bound_options.c b/bound_options.c new file mode 100644 index 0000000..3624c6d --- /dev/null +++ b/bound_options.c @@ -0,0 +1,18 @@ +#include "bound_options.h" + +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct options, verify, NULL, + verify_options_arg, "verification") +ISL_ARG_CHILD(struct options, convert, NULL, + convert_options_arg, "input conversion") +ISL_ARG_STR(struct options, var_list, 0, "variables", "list", NULL, + "comma separated list of variables over which to sum") +ISL_ARG_LONG(struct options, split, 0, "split", 0, NULL) +ISL_ARG_OPT_LONG(struct options, iterate, 0, "iterate", 0, -1, + "exact result by iterating over domain (of specified maximal size)") +ISL_ARG_BOOL(struct options, lower, 0, "lower", 0, + "compute lower bound instead of upper bound") +ISL_ARG_END +}; + +ISL_ARG_DEF(options, struct options, options_arg) diff --git a/bound_options.h b/bound_options.h new file mode 100644 index 0000000..3aaf827 --- /dev/null +++ b/bound_options.h @@ -0,0 +1,22 @@ +#include +#include "evalue_convert.h" +#include "verify.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +struct options { + struct convert_options *convert; + struct verify_options *verify; + char* var_list; + long split; + int lower; + long iterate; +}; + +ISL_ARG_DECL(options, struct options, options_arg) + +#if defined(__cplusplus) +} +#endif diff --git a/cone_integer_hull.c b/cone_integer_hull.c index 69566e3..3c75998 100644 --- a/cone_integer_hull.c +++ b/cone_integer_hull.c @@ -1,7 +1,5 @@ #include #include -#include "argp.h" -#include "progname.h" #include "hull.h" int main(int argc, char **argv) @@ -10,8 +8,7 @@ int main(int argc, char **argv) Polyhedron *C; struct barvinok_options *options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); M = Matrix_Read(); C = Constraints2Polyhedron(M, options->MaxRays); diff --git a/configure.in b/configure.in index 19764f6..08d92d8 100644 --- a/configure.in +++ b/configure.in @@ -23,9 +23,6 @@ esac AC_PROG_LIBTOOL -gl_MODULES(argp progname) -gl_INIT - PKG_PROG_PKG_CONFIG AC_CHECK_HEADERS(getopt.h) @@ -564,7 +561,7 @@ PACKAGE_LIBS="-lbarvinok -lbarvinok-core $EXTRA_PACKAGE_LIBS -lisl-polylib -lpol AX_CREATE_PKGCONFIG_INFO AC_CONFIG_HEADERS(config.h) -AC_CONFIG_FILES(Makefile lib/Makefile zsolve/Makefile doc/Makefile) +AC_CONFIG_FILES(Makefile zsolve/Makefile doc/Makefile) AC_CONFIG_FILES(parker/Makefile) if test $with_polylib = bundled; then AC_CONFIG_SUBDIRS(polylib) diff --git a/edomain.cc b/edomain.cc index f9cb209..c10af44 100644 --- a/edomain.cc +++ b/edomain.cc @@ -492,7 +492,7 @@ bool EDomain::not_empty(lexmin_options *options) bool notzero; Value cb; value_init(cb); - barvinok_count_with_options(P, &cb, options->verify.barvinok); + barvinok_count_with_options(P, &cb, options->verify->barvinok); notzero = value_notzero_p(cb); value_clear(cb); return notzero; @@ -501,7 +501,7 @@ bool EDomain::not_empty(lexmin_options *options) Matrix *T = NULL; while (P && !emptyQ2(P) && P->NbEq > 0) { Polyhedron *Q = P; - Matrix *T2 = remove_equalities(&P, 0, options->verify.barvinok->MaxRays); + Matrix *T2 = remove_equalities(&P, 0, options->verify->barvinok->MaxRays); if (!T) T = T2; else { @@ -517,7 +517,7 @@ bool EDomain::not_empty(lexmin_options *options) } } if (P) - sample = Polyhedron_Sample(P, options->verify.barvinok); + sample = Polyhedron_Sample(P, options->verify->barvinok); if (sample) { if (T) { Vector *P_sample = Vector_Alloc(Porig->Dimension + 1); diff --git a/evalue_convert.cc b/evalue_convert.cc index bbc9662..7b145c1 100644 --- a/evalue_convert.cc +++ b/evalue_convert.cc @@ -17,64 +17,6 @@ using std::endl; using std::string; -static struct argp_option argp_options[] = { - { "convert", 'c', 0, 0, "convert fractionals to periodics" }, - { "combine", 'C', 0, 0 }, - { "floor", 'f', 0, 0, "convert fractionals to floorings" }, - { "list", 'l', 0, 0 }, - { "latex", 'L', 0, 0 }, - { "to-isl", 'I', 0, 0 }, - { "range-reduction", 'R', 0, 0 }, - 0 -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct convert_options *options = (struct convert_options *)state->input; - - switch (key) { - case ARGP_KEY_INIT: - options->floor = 0; - options->convert = 0; - options->combine = 0; - options->range = 0; - options->list = 0; - options->latex = 0; - options->isl = 0; - break; - case ARGP_KEY_FINI: - break; - case 'f': - options->floor = 1; - break; - case 'c': - options->convert = 1; - break; - case 'C': - options->combine = 1; - break; - case 'l': - options->list = 1; - break; - case 'L': - options->latex = 1; - break; - case 'R': - options->range = 1; - break; - case 'I': - options->isl = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -struct argp convert_argp = { - argp_options, parse_opt, 0, 0 -}; - static int type_offset(enode *p) { return p->type == fractional ? 1 : diff --git a/evalue_convert.h b/evalue_convert.h index fdf4b9c..41e0ea7 100644 --- a/evalue_convert.h +++ b/evalue_convert.h @@ -1,8 +1,8 @@ #ifndef EVALUE_CONVERT #define EVALUE_CONVERT +#include #include -#include "argp.h" #if defined(__cplusplus) extern "C" { @@ -21,7 +21,7 @@ struct convert_options { int evalue_convert(evalue *EP, struct convert_options *options, int verbose, unsigned nparam, const char **params); -extern struct argp convert_argp; +ISL_ARG_DECL(convert_options, struct convert_options, convert_options_arg) #if defined(__cplusplus) } diff --git a/evalue_convert_main.c b/evalue_convert_main.c index 43e147a..99ae604 100644 --- a/evalue_convert_main.c +++ b/evalue_convert_main.c @@ -1,32 +1,43 @@ -#include "argp.h" #include #include "evalue_convert.h" #include "evalue_read.h" +struct options { + struct convert_options *convert; + struct barvinok_options *barvinok; +}; + +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct options, convert, NULL, convert_options_arg, NULL) +ISL_ARG_CHILD(struct options, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_END +}; + +ISL_ARG_DEF(options, struct options, options_arg) + int main(int argc, char **argv) { evalue *EP; const char **all_vars = NULL; unsigned nvar; unsigned nparam; - struct barvinok_options *options = barvinok_options_new_with_defaults(); - struct convert_options convert; + struct options *options = options_new_with_defaults(); int printed; - set_program_name(argv[0]); - argp_parse(&convert_argp, argc, argv, 0, 0, &convert); + argc = options_parse(options, argc, argv, ISL_ARG_ALL); EP = evalue_read_from_file(stdin, NULL, &all_vars, - &nvar, &nparam, options->MaxRays); + &nvar, &nparam, options->barvinok->MaxRays); assert(EP); printed = - evalue_convert(EP, &convert, options->verbose, nvar+nparam, all_vars); + evalue_convert(EP, options->convert, options->barvinok->verbose, + nvar+nparam, all_vars); if (!printed) print_evalue(stdout, EP, all_vars); evalue_free(EP); Free_ParamNames(all_vars, nvar+nparam); - barvinok_options_free(options); + options_free(options); } diff --git a/evalue_convert_options.c b/evalue_convert_options.c new file mode 100644 index 0000000..4280d27 --- /dev/null +++ b/evalue_convert_options.c @@ -0,0 +1,14 @@ +#include "evalue_convert.h" + +struct isl_arg convert_options_arg[] = { +ISL_ARG_BOOL(struct convert_options, range, 'R', "range-reduction", 0, NULL) +ISL_ARG_BOOL(struct convert_options, convert, 'c', "convert", 0, + "convert fractionals to periodics") +ISL_ARG_BOOL(struct convert_options, combine, 'C', "combine", 0, NULL) +ISL_ARG_BOOL(struct convert_options, floor, 'f', "floor", 0, + "convert fractionals to floorings") +ISL_ARG_BOOL(struct convert_options, list, 'l', "list", 0, NULL) +ISL_ARG_BOOL(struct convert_options, latex, 'L', "latex", 0, NULL) +ISL_ARG_BOOL(struct convert_options, isl, 'I', "to-isl", 0, NULL) +ISL_ARG_END +}; diff --git a/lexmin.cc b/lexmin.cc index 2d368af..860cea7 100644 --- a/lexmin.cc +++ b/lexmin.cc @@ -13,8 +13,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" #include "conversion.h" #include "decomposer.h" #include "lattice_point.h" @@ -43,45 +41,6 @@ using std::endl; using std::ostream; #define ALLOC(type) (type*)malloc(sizeof(type)) - -#define EMPTINESS_CHECK (BV_OPT_LAST+1) -#define NO_REDUCTION (BV_OPT_LAST+2) - -struct argp_option argp_options[] = { - { "emptiness-check", EMPTINESS_CHECK, "[none|count]", 0 }, - { "no-reduction", NO_REDUCTION, 0, 0 }, - { 0 } -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct lexmin_options *options = (struct lexmin_options *)(state->input); - struct barvinok_options *bv_options = options->verify.barvinok; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->verify.barvinok; - state->child_inputs[1] = &options->verify; - options->emptiness_check = BV_LEXMIN_EMPTINESS_CHECK_SAMPLE; - options->reduce = 1; - break; - case EMPTINESS_CHECK: - if (!strcmp(arg, "none")) - options->emptiness_check = BV_LEXMIN_EMPTINESS_CHECK_NONE; - else if (!strcmp(arg, "count")) { - options->emptiness_check = BV_LEXMIN_EMPTINESS_CHECK_COUNT; - bv_options->count_sample_infinite = 0; - } - break; - case NO_REDUCTION: - options->reduce = 0; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type)) static int type_offset(enode *p) @@ -1215,7 +1174,7 @@ struct indicator { int nparam = ic.PP->Constraints->NbColumns-2 - ic.vertex.length(); if (options->reduce) { Polyhedron *Q = Polyhedron_Project_Initial(D->D, nparam); - Q = DomainConstraintSimplify(Q, options->verify.barvinok->MaxRays); + Q = DomainConstraintSimplify(Q, options->verify->barvinok->MaxRays); if (!P || !PolyhedronIncludes(Q, P)) reduce_in_domain(Q); if (P) @@ -1456,7 +1415,7 @@ order_sign partial_order::compare(const indicator_term *a, const indicator_term unsigned dim = a->den.NumCols(); order_sign sign = order_eq; EDomain *D = ind->D; - unsigned MaxRays = ind->options->verify.barvinok->MaxRays; + unsigned MaxRays = ind->options->verify->barvinok->MaxRays; bool rational = a->sign == 0 || b->sign == 0; order_sign cached_sign = order_eq; @@ -1478,9 +1437,9 @@ order_sign partial_order::compare(const indicator_term *a, const indicator_term } if (rational && POL_ISSET(MaxRays, POL_INTEGER)) { - ind->options->verify.barvinok->MaxRays &= ~POL_INTEGER; - if (ind->options->verify.barvinok->MaxRays) - ind->options->verify.barvinok->MaxRays |= POL_HIGH_BIT; + ind->options->verify->barvinok->MaxRays &= ~POL_INTEGER; + if (ind->options->verify->barvinok->MaxRays) + ind->options->verify->barvinok->MaxRays |= POL_HIGH_BIT; } sign = order_eq; @@ -1504,7 +1463,7 @@ order_sign partial_order::compare(const indicator_term *a, const indicator_term else if (eequal(a->vertex[k], b->vertex[k])) diff_sign = order_eq; else - diff_sign = evalue_sign(diff, D, ind->options->verify.barvinok); + diff_sign = evalue_sign(diff, D, ind->options->verify->barvinok); if (diff_sign == order_undefined) { assert(sign == order_le || sign == order_ge); @@ -1563,7 +1522,7 @@ order_sign partial_order::compare(const indicator_term *a, const indicator_term delete term[1]; } - ind->options->verify.barvinok->MaxRays = MaxRays; + ind->options->verify->barvinok->MaxRays = MaxRays; return sign; } @@ -1830,7 +1789,7 @@ void indicator::expand_rational_vertex(const indicator_term *initial) Param_Vertices *V; FORALL_PVertex_in_ParamPolyhedron(V, PD, ic.PP) // _i is internal counter if (_i == pos) { - ic.decompose_at_vertex(V, pos, options->verify.barvinok); + ic.decompose_at_vertex(V, pos, options->verify->barvinok); break; } END_FORALL_PVertex_in_ParamPolyhedron; @@ -2226,16 +2185,16 @@ static void split_on(const split& sp, EDomain *D, *Dgt = NULL; ge_constraint *ge = D->compute_ge_constraint(sp.constraint); if (sp.sign == split::lge || sp.sign == split::ge) - ED[2] = EDomain::new_from_ge_constraint(ge, 1, options->verify.barvinok); + ED[2] = EDomain::new_from_ge_constraint(ge, 1, options->verify->barvinok); else ED[2] = NULL; if (sp.sign == split::lge || sp.sign == split::le) - ED[0] = EDomain::new_from_ge_constraint(ge, -1, options->verify.barvinok); + ED[0] = EDomain::new_from_ge_constraint(ge, -1, options->verify->barvinok); else ED[0] = NULL; assert(sp.sign == split::lge || sp.sign == split::ge || sp.sign == split::le); - ED[1] = EDomain::new_from_ge_constraint(ge, 0, options->verify.barvinok); + ED[1] = EDomain::new_from_ge_constraint(ge, 0, options->verify->barvinok); delete ge; @@ -2455,7 +2414,7 @@ static vector lexmin(indicator& ind, unsigned nparam, if (!best) { /* apparently there can be negative initial term on empty domains */ if (ind.options->emptiness_check != BV_LEXMIN_EMPTINESS_CHECK_NONE && - ind.options->verify.barvinok->lp_solver == BV_LP_POLYLIB) + ind.options->verify->barvinok->lp_solver == BV_LP_POLYLIB) assert(!neg); break; } @@ -2468,7 +2427,7 @@ static vector lexmin(indicator& ind, unsigned nparam, bool handled = ind.handle_equal_numerators(best); if (ind.options->emptiness_check != BV_LEXMIN_EMPTINESS_CHECK_NONE && - ind.options->verify.barvinok->lp_solver == BV_LP_POLYLIB) + ind.options->verify->barvinok->lp_solver == BV_LP_POLYLIB) assert(handled); /* If !handled then the leading coefficient is bigger than one; * must be an empty domain @@ -2513,7 +2472,7 @@ static vector lexmin(indicator& ind, unsigned nparam, order_sign sign; for (int k = 0; k < dim; ++k) { diff = ediff(best->vertex[k], second->vertex[k]); - sign = evalue_sign(diff, ind.D, ind.options->verify.barvinok); + sign = evalue_sign(diff, ind.D, ind.options->verify->barvinok); /* neg can never be smaller than best, unless it may still cancel. * This can happen if positive terms have been determined to @@ -2616,7 +2575,7 @@ static void lexmin_base(Polyhedron *P, Polyhedron *C, unsigned nparam = C->Dimension; Param_Polyhedron *PP = NULL; - PP = Polyhedron2Param_Polyhedron(P, C, options->verify.barvinok); + PP = Polyhedron2Param_Polyhedron(P, C, options->verify->barvinok); unsigned dim = P->Dimension - nparam; @@ -2628,8 +2587,8 @@ static void lexmin_base(Polyhedron *P, Polyhedron *C, construct_rational_vertices(PP, T, T ? T->NbRows-nparam-1 : dim, nparam, all_vertices); - Polyhedron *TC = true_context(P, C, options->verify.barvinok->MaxRays); - FORALL_REDUCED_DOMAIN(PP, TC, nd, options->verify.barvinok, i, D, rVD) + Polyhedron *TC = true_context(P, C, options->verify->barvinok->MaxRays); + FORALL_REDUCED_DOMAIN(PP, TC, nd, options->verify->barvinok, i, D, rVD) Param_Vertices *V; EDomain *epVD = new EDomain(rVD); @@ -2645,7 +2604,7 @@ static void lexmin_base(Polyhedron *P, Polyhedron *C, vector maxima = lexmin(ind, nparam, loc); if (CP) for (int j = 0; j < maxima.size(); ++j) - maxima[j]->substitute(CP, options->verify.barvinok); + maxima[j]->substitute(CP, options->verify->barvinok); all_max.insert(all_max.end(), maxima.begin(), maxima.end()); Domain_Free(rVD); @@ -2677,7 +2636,7 @@ static vector lexmin(Polyhedron *P, Polyhedron *C, if (P->NbEq > 0) remove_all_equalities(&P, &C, &CP, &T, nparam, - options->verify.barvinok->MaxRays); + options->verify->barvinok->MaxRays); if (!emptyQ2(P)) lexmin_base(P, C, CP, T, all_max, options); done: @@ -2704,34 +2663,23 @@ int main(int argc, char **argv) int bignum; char **iter_names, **param_names; int print_solution = 1; - struct lexmin_options options; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", 1 }, - { 0 } - }; - static struct argp argp = { argp_options, &parse_opt, 0, 0, argp_children }; - struct barvinok_options *bv_options; - - bv_options = barvinok_options_new_with_defaults(); - bv_options->lookup_table = 0; - - options.verify.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + struct lexmin_options *options = lexmin_options_new_with_defaults(); + options->verify->barvinok->lookup_table = 0; + + argc = lexmin_options_parse(options, argc, argv, ISL_ARG_ALL); MA = Matrix_Read(); - C = Constraints2Polyhedron(MA, bv_options->MaxRays); + C = Constraints2Polyhedron(MA, options->verify->barvinok->MaxRays); Matrix_Free(MA); fscanf(stdin, " %d", &bignum); assert(bignum == -1); MA = Matrix_Read(); - A = Constraints2Polyhedron(MA, bv_options->MaxRays); + A = Constraints2Polyhedron(MA, options->verify->barvinok->MaxRays); Matrix_Free(MA); - verify_options_set_range(&options.verify, A->Dimension); + verify_options_set_range(options->verify, A->Dimension); - if (options.verify.verify) + if (options->verify->verify) print_solution = 0; iter_names = util_generate_names(A->Dimension - C->Dimension, "i"); @@ -2740,13 +2688,13 @@ int main(int argc, char **argv) Polyhedron_Print(stdout, P_VALUE_FMT, A); Polyhedron_Print(stdout, P_VALUE_FMT, C); } - vector maxima = lexmin(A, C, &options); + vector maxima = lexmin(A, C, options); if (print_solution) for (int i = 0; i < maxima.size(); ++i) - maxima[i]->print(cout, param_names, options.verify.barvinok); + maxima[i]->print(cout, param_names, options->verify->barvinok); - if (options.verify.verify) - verify_results(A, C, maxima, &options.verify); + if (options->verify->verify) + verify_results(A, C, maxima, options->verify); for (int i = 0; i < maxima.size(); ++i) delete maxima[i]; @@ -2756,7 +2704,7 @@ int main(int argc, char **argv) Polyhedron_Free(A); Polyhedron_Free(C); - barvinok_options_free(bv_options); + lexmin_options_free(options); return 0; } diff --git a/lexmin.h b/lexmin.h index 61855ae..e84aaeb 100644 --- a/lexmin.h +++ b/lexmin.h @@ -3,6 +3,10 @@ #include "verify.h" +#if defined(__cplusplus) +extern "C" { +#endif + struct lexmin_options { /* Check for integer points in domain */ @@ -12,7 +16,13 @@ struct lexmin_options { int emptiness_check; int reduce; - struct verify_options verify; + struct verify_options *verify; }; +ISL_ARG_DECL(lexmin_options, struct lexmin_options, lexmin_options_arg) + +#if defined(__cplusplus) +} +#endif + #endif diff --git a/lexmin_options.c b/lexmin_options.c new file mode 100644 index 0000000..ea61c4c --- /dev/null +++ b/lexmin_options.c @@ -0,0 +1,19 @@ +#include "lexmin.h" + +static struct isl_arg_choice check[] = { + {"none", BV_LEXMIN_EMPTINESS_CHECK_NONE}, + {"count", BV_LEXMIN_EMPTINESS_CHECK_COUNT}, + {"sample", BV_LEXMIN_EMPTINESS_CHECK_SAMPLE}, + {0} +}; + +struct isl_arg lexmin_options_arg[] = { +ISL_ARG_CHILD(struct lexmin_options, verify, NULL, + verify_options_arg, "verification") +ISL_ARG_BOOL(struct lexmin_options, reduce, 0, "reduction", 1, NULL) +ISL_ARG_CHOICE(struct lexmin_options, emptiness_check, + 0, "emptiness-check", check, BV_LEXMIN_EMPTINESS_CHECK_SAMPLE, NULL) +ISL_ARG_END +}; + +ISL_ARG_DEF(lexmin_options, struct lexmin_options, lexmin_options_arg) diff --git a/lib/Makefile.am b/lib/Makefile.am deleted file mode 100644 index 880e49a..0000000 --- a/lib/Makefile.am +++ /dev/null @@ -1,615 +0,0 @@ -## DO NOT EDIT! GENERATED AUTOMATICALLY! -## Process this file with automake to produce Makefile.in. -# Copyright (C) 2004-2007 Free Software Foundation, Inc. -# -# This file is free software, distributed under the terms of the GNU -# General Public License. As a special exception to the GNU General -# Public License, this file may be distributed as part of a program -# that contains a configuration script generated by Autoconf, under -# the same distribution terms as the rest of that program. -# -# Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --aux-dir=. --libtool --macro-prefix=gl argp getsubopt progname - -AUTOMAKE_OPTIONS = 1.5 gnits - -noinst_HEADERS = -noinst_LIBRARIES = -noinst_LTLIBRARIES = -EXTRA_DIST = -BUILT_SOURCES = -SUFFIXES = -MOSTLYCLEANFILES = core *.stackdump -MOSTLYCLEANDIRS = -CLEANFILES = -DISTCLEANFILES = -MAINTAINERCLEANFILES = - -AM_CPPFLAGS = - -noinst_LTLIBRARIES += libgnu.la - -libgnu_la_SOURCES = -libgnu_la_LIBADD = $(gl_LTLIBOBJS) -libgnu_la_DEPENDENCIES = $(gl_LTLIBOBJS) -EXTRA_libgnu_la_SOURCES = -libgnu_la_LDFLAGS = $(AM_LDFLAGS) - -## begin gnulib module absolute-header - -# Use this preprocessor expression to decide whether #include_next works. -# Do not rely on a 'configure'-time test for this, since the expression -# might appear in an installed header, which is used by some other compiler. -HAVE_INCLUDE_NEXT = (__GNUC__ || 60000000 <= __DECC_VER) - -## end gnulib module absolute-header - -## begin gnulib module alloca - - -EXTRA_DIST += alloca.c - -EXTRA_libgnu_la_SOURCES += alloca.c - -libgnu_la_LIBADD += @LTALLOCA@ -libgnu_la_DEPENDENCIES += @LTALLOCA@ -## end gnulib module alloca - -## begin gnulib module alloca-opt - -BUILT_SOURCES += $(ALLOCA_H) - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -alloca.h: alloca.in.h - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - cat $(srcdir)/alloca.in.h; \ - } > $@-t - mv -f $@-t $@ -MOSTLYCLEANFILES += alloca.h alloca.h-t - -EXTRA_DIST += alloca.in.h - -## end gnulib module alloca-opt - -## begin gnulib module argp - -libgnu_la_SOURCES += argp.h argp-ba.c argp-eexst.c \ - argp-fmtstream.c argp-fmtstream.h argp-fs-xinl.c argp-help.c \ - argp-namefrob.h argp-parse.c argp-pin.c argp-pv.c argp-pvh.c \ - argp-xinl.c - -EXTRA_DIST += argp-namefrob.h argp-parse.c argp-pin.c argp-pv.c argp-pvh.c argp-xinl.c - -EXTRA_libgnu_la_SOURCES += argp-parse.c argp-pin.c argp-pv.c argp-pvh.c argp-xinl.c - -## end gnulib module argp - -## begin gnulib module dirname - - -EXTRA_DIST += basename.c dirname.c dirname.h stripslash.c - -EXTRA_libgnu_la_SOURCES += basename.c dirname.c stripslash.c - -## end gnulib module dirname - -## begin gnulib module error - - -EXTRA_DIST += error.c error.h - -EXTRA_libgnu_la_SOURCES += error.c - -## end gnulib module error - -## begin gnulib module exitfail - - -EXTRA_DIST += exitfail.c exitfail.h - -EXTRA_libgnu_la_SOURCES += exitfail.c - -## end gnulib module exitfail - -## begin gnulib module float - -BUILT_SOURCES += $(FLOAT_H) - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -float.h: float.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ - sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \ - < $(srcdir)/float.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += float.h float.h-t - -EXTRA_DIST += float.in.h - -## end gnulib module float - -## begin gnulib module getopt - -BUILT_SOURCES += $(GETOPT_H) - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -getopt.h: getopt.in.h - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - cat $(srcdir)/getopt.in.h; \ - } > $@-t - mv -f $@-t $@ -MOSTLYCLEANFILES += getopt.h getopt.h-t - -EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h - -EXTRA_libgnu_la_SOURCES += getopt.c getopt1.c - -## end gnulib module getopt - -## begin gnulib module getsubopt - - -EXTRA_DIST += getsubopt.c - -EXTRA_libgnu_la_SOURCES += getsubopt.c - -## end gnulib module getsubopt - -## begin gnulib module gettext-h - -libgnu_la_SOURCES += gettext.h - -## end gnulib module gettext-h - -## begin gnulib module malloc - - -EXTRA_DIST += malloc.c - -EXTRA_libgnu_la_SOURCES += malloc.c - -## end gnulib module malloc - -## begin gnulib module malloc-posix - - -EXTRA_DIST += malloc.c - -EXTRA_libgnu_la_SOURCES += malloc.c - -## end gnulib module malloc-posix - -## begin gnulib module mempcpy - - -EXTRA_DIST += mempcpy.c - -EXTRA_libgnu_la_SOURCES += mempcpy.c - -## end gnulib module mempcpy - -## begin gnulib module progname - -libgnu_la_SOURCES += progname.h progname.c - -## end gnulib module progname - -## begin gnulib module size_max - -libgnu_la_SOURCES += size_max.h - -## end gnulib module size_max - -## begin gnulib module sleep - - -EXTRA_DIST += sleep.c - -EXTRA_libgnu_la_SOURCES += sleep.c - -## end gnulib module sleep - -## begin gnulib module stdbool - -BUILT_SOURCES += $(STDBOOL_H) - -# We need the following in order to create when the system -# doesn't have one that works. -stdbool.h: stdbool.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += stdbool.h stdbool.h-t - -EXTRA_DIST += stdbool.in.h - -## end gnulib module stdbool - -## begin gnulib module stdint - -BUILT_SOURCES += $(STDINT_H) - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -stdint.h: stdint.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ - -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \ - -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ - -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ - -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ - -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ - -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \ - -e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \ - -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ - -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ - -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \ - -e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \ - -e 's/@''SIG_ATOMIC_T_SUFFIX''@/$(SIG_ATOMIC_T_SUFFIX)/g' \ - -e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \ - -e 's/@''SIZE_T_SUFFIX''@/$(SIZE_T_SUFFIX)/g' \ - -e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \ - -e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \ - -e 's/@''WCHAR_T_SUFFIX''@/$(WCHAR_T_SUFFIX)/g' \ - -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ - -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ - -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ - < $(srcdir)/stdint.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += stdint.h stdint.h-t - -EXTRA_DIST += stdint.in.h - -## end gnulib module stdint - -## begin gnulib module stdio - -BUILT_SOURCES += stdio.h - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -stdio.h: stdio.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ - sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \ - -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \ - -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \ - -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \ - -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \ - -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \ - -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \ - -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \ - -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \ - -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \ - -e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \ - -e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \ - -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \ - -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \ - -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \ - -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \ - -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \ - -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \ - -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \ - -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ - -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \ - -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ - -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \ - -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \ - -e 's|@''HAVE_DECL_SNPRINTF''@|$(HAVE_DECL_SNPRINTF)|g' \ - -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \ - -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \ - -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \ - -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \ - -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \ - -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \ - -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \ - -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \ - -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \ - -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \ - -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \ - -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \ - -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \ - -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ - -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \ - -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \ - < $(srcdir)/stdio.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += stdio.h stdio.h-t - -EXTRA_DIST += stdio.in.h - -## end gnulib module stdio - -## begin gnulib module stdlib - -BUILT_SOURCES += stdlib.h - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -stdlib.h: stdlib.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ - sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ - -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ - -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \ - -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ - -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ - -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ - -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \ - -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ - -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ - -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ - -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ - -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ - -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ - < $(srcdir)/stdlib.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += stdlib.h stdlib.h-t - -EXTRA_DIST += stdlib.in.h - -## end gnulib module stdlib - -## begin gnulib module strcase - - -EXTRA_DIST += strcasecmp.c strncasecmp.c - -EXTRA_libgnu_la_SOURCES += strcasecmp.c strncasecmp.c - -## end gnulib module strcase - -## begin gnulib module strchrnul - - -EXTRA_DIST += strchrnul.c - -EXTRA_libgnu_la_SOURCES += strchrnul.c - -## end gnulib module strchrnul - -## begin gnulib module strerror - - -EXTRA_DIST += strerror.c - -EXTRA_libgnu_la_SOURCES += strerror.c - -## end gnulib module strerror - -## begin gnulib module string - -BUILT_SOURCES += string.h - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -string.h: string.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ - sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \ - -e 's|@''GNULIB_MBSLEN''@|$(GNULIB_MBSLEN)|g' \ - -e 's|@''GNULIB_MBSNLEN''@|$(GNULIB_MBSNLEN)|g' \ - -e 's|@''GNULIB_MBSCHR''@|$(GNULIB_MBSCHR)|g' \ - -e 's|@''GNULIB_MBSRCHR''@|$(GNULIB_MBSRCHR)|g' \ - -e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \ - -e 's|@''GNULIB_MBSCASECMP''@|$(GNULIB_MBSCASECMP)|g' \ - -e 's|@''GNULIB_MBSNCASECMP''@|$(GNULIB_MBSNCASECMP)|g' \ - -e 's|@''GNULIB_MBSPCASECMP''@|$(GNULIB_MBSPCASECMP)|g' \ - -e 's|@''GNULIB_MBSCASESTR''@|$(GNULIB_MBSCASESTR)|g' \ - -e 's|@''GNULIB_MBSCSPN''@|$(GNULIB_MBSCSPN)|g' \ - -e 's|@''GNULIB_MBSPBRK''@|$(GNULIB_MBSPBRK)|g' \ - -e 's|@''GNULIB_MBSSPN''@|$(GNULIB_MBSSPN)|g' \ - -e 's|@''GNULIB_MBSSEP''@|$(GNULIB_MBSSEP)|g' \ - -e 's|@''GNULIB_MBSTOK_R''@|$(GNULIB_MBSTOK_R)|g' \ - -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \ - -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \ - -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \ - -e 's|@''GNULIB_STPCPY''@|$(GNULIB_STPCPY)|g' \ - -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \ - -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \ - -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \ - -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \ - -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \ - -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \ - -e 's|@''GNULIB_STRSEP''@|$(GNULIB_STRSEP)|g' \ - -e 's|@''GNULIB_STRCASESTR''@|$(GNULIB_STRCASESTR)|g' \ - -e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \ - -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \ - -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ - -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ - -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ - -e 's|@''HAVE_STPCPY''@|$(HAVE_STPCPY)|g' \ - -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ - -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ - -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ - -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ - -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ - -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \ - -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ - -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ - -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ - -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ - -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ - -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ - -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \ - -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ - < $(srcdir)/string.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += string.h string.h-t - -EXTRA_DIST += string.in.h - -## end gnulib module string - -## begin gnulib module strndup - - -EXTRA_DIST += strndup.c - -EXTRA_libgnu_la_SOURCES += strndup.c - -## end gnulib module strndup - -## begin gnulib module strnlen - - -EXTRA_DIST += strnlen.c - -EXTRA_libgnu_la_SOURCES += strnlen.c - -## end gnulib module strnlen - -## begin gnulib module sysexits - -BUILT_SOURCES += $(SYSEXITS_H) - -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -sysexits.h: sysexits.in.h - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's|@''HAVE_SYSEXITS_H''@|$(HAVE_SYSEXITS_H)|g' \ - -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_SYSEXITS_H''@|$(NEXT_SYSEXITS_H)|g' \ - < $(srcdir)/sysexits.in.h; \ - } > $@-t - mv -f $@-t $@ -MOSTLYCLEANFILES += sysexits.h sysexits.h-t - -EXTRA_DIST += sysexits.in.h - -## end gnulib module sysexits - -## begin gnulib module unistd - -BUILT_SOURCES += unistd.h - -# We need the following in order to create an empty placeholder for -# when the system doesn't have one. -unistd.h: unistd.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ - -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ - -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ - -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ - -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ - -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ - -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ - -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ - -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \ - -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \ - -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \ - -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \ - -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ - -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ - -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ - -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ - -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ - -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ - -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ - -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ - -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ - -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ - < $(srcdir)/unistd.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += unistd.h unistd.h-t - -EXTRA_DIST += unistd.in.h - -## end gnulib module unistd - -## begin gnulib module vasnprintf - - -EXTRA_DIST += asnprintf.c float+.h printf-args.c printf-args.h printf-parse.c printf-parse.h vasnprintf.c vasnprintf.h - -EXTRA_libgnu_la_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c - -## end gnulib module vasnprintf - -## begin gnulib module vsnprintf - - -EXTRA_DIST += vsnprintf.c - -EXTRA_libgnu_la_SOURCES += vsnprintf.c - -## end gnulib module vsnprintf - -## begin gnulib module wchar - -BUILT_SOURCES += $(WCHAR_H) - -# We need the following in order to create when the system -# version does not work standalone. -wchar.h: wchar.in.h - rm -f $@-t $@ - { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \ - -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \ - -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \ - -e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \ - -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ - -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ - < $(srcdir)/wchar.in.h; \ - } > $@-t - mv $@-t $@ -MOSTLYCLEANFILES += wchar.h wchar.h-t - -EXTRA_DIST += wchar.in.h - -## end gnulib module wchar - -## begin gnulib module xalloc - - -EXTRA_DIST += xalloc.h xmalloc.c - -EXTRA_libgnu_la_SOURCES += xmalloc.c - -## end gnulib module xalloc - -## begin gnulib module xalloc-die - -libgnu_la_SOURCES += xalloc-die.c - -## end gnulib module xalloc-die - -## begin gnulib module xsize - -libgnu_la_SOURCES += xsize.h - -## end gnulib module xsize - -## begin gnulib module xstrndup - -libgnu_la_SOURCES += xstrndup.h xstrndup.c - -## end gnulib module xstrndup - - -mostlyclean-local: mostlyclean-generic - @for dir in '' $(MOSTLYCLEANDIRS); do \ - if test -n "$$dir" && test -d $$dir; then \ - echo "rmdir $$dir"; rmdir $$dir; \ - fi; \ - done; \ - : diff --git a/lib/alloca.c b/lib/alloca.c deleted file mode 100644 index 3a1f4e2..0000000 --- a/lib/alloca.c +++ /dev/null @@ -1,489 +0,0 @@ -/* alloca.c -- allocate automatically reclaimed memory - (Mostly) portable public-domain implementation -- D A Gwyn - - This implementation of the PWB library alloca function, - which is used to allocate space off the run-time stack so - that it is automatically reclaimed upon procedure exit, - was inspired by discussions with J. Q. Johnson of Cornell. - J.Otto Tennant contributed the Cray support. - - There are some preprocessor constants that can - be defined when compiling for your specific system, for - improved efficiency; however, the defaults should be okay. - - The general concept of this implementation is to keep - track of all alloca-allocated blocks, and reclaim any - that are found to be deeper in the stack than the current - invocation. This heuristic does not reclaim storage as - soon as it becomes invalid, but it will do so eventually. - - As a special case, alloca(0) reclaims storage without - allocating any. It is a good idea to use alloca(0) in - your main control loop, etc. to force garbage collection. */ - -#include - -#include - -#include -#include - -#ifdef emacs -# include "lisp.h" -# include "blockinput.h" -# ifdef EMACS_FREE -# undef free -# define free EMACS_FREE -# endif -#else -# define memory_full() abort () -#endif - -/* If compiling with GCC 2, this file's not needed. */ -#if !defined (__GNUC__) || __GNUC__ < 2 - -/* If someone has defined alloca as a macro, - there must be some other way alloca is supposed to work. */ -# ifndef alloca - -# ifdef emacs -# ifdef static -/* actually, only want this if static is defined as "" - -- this is for usg, in which emacs must undefine static - in order to make unexec workable - */ -# ifndef STACK_DIRECTION -you -lose --- must know STACK_DIRECTION at compile-time -/* Using #error here is not wise since this file should work for - old and obscure compilers. */ -# endif /* STACK_DIRECTION undefined */ -# endif /* static */ -# endif /* emacs */ - -/* If your stack is a linked list of frames, you have to - provide an "address metric" ADDRESS_FUNCTION macro. */ - -# if defined (CRAY) && defined (CRAY_STACKSEG_END) -long i00afunc (); -# define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) -# else -# define ADDRESS_FUNCTION(arg) &(arg) -# endif - -/* Define STACK_DIRECTION if you know the direction of stack - growth for your system; otherwise it will be automatically - deduced at run-time. - - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ - -# ifndef STACK_DIRECTION -# define STACK_DIRECTION 0 /* Direction unknown. */ -# endif - -# if STACK_DIRECTION != 0 - -# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ - -# else /* STACK_DIRECTION == 0; need run-time code. */ - -static int stack_dir; /* 1 or -1 once known. */ -# define STACK_DIR stack_dir - -static void -find_stack_direction (void) -{ - static char *addr = NULL; /* Address of first `dummy', once known. */ - auto char dummy; /* To get stack address. */ - - if (addr == NULL) - { /* Initial entry. */ - addr = ADDRESS_FUNCTION (dummy); - - find_stack_direction (); /* Recurse once. */ - } - else - { - /* Second entry. */ - if (ADDRESS_FUNCTION (dummy) > addr) - stack_dir = 1; /* Stack grew upward. */ - else - stack_dir = -1; /* Stack grew downward. */ - } -} - -# endif /* STACK_DIRECTION == 0 */ - -/* An "alloca header" is used to: - (a) chain together all alloca'ed blocks; - (b) keep track of stack depth. - - It is very important that sizeof(header) agree with malloc - alignment chunk size. The following default should work okay. */ - -# ifndef ALIGN_SIZE -# define ALIGN_SIZE sizeof(double) -# endif - -typedef union hdr -{ - char align[ALIGN_SIZE]; /* To force sizeof(header). */ - struct - { - union hdr *next; /* For chaining headers. */ - char *deep; /* For stack depth measure. */ - } h; -} header; - -static header *last_alloca_header = NULL; /* -> last alloca header. */ - -/* Return a pointer to at least SIZE bytes of storage, - which will be automatically reclaimed upon exit from - the procedure that called alloca. Originally, this space - was supposed to be taken from the current stack frame of the - caller, but that method cannot be made to work for some - implementations of C, for example under Gould's UTX/32. */ - -void * -alloca (size_t size) -{ - auto char probe; /* Probes stack depth: */ - register char *depth = ADDRESS_FUNCTION (probe); - -# if STACK_DIRECTION == 0 - if (STACK_DIR == 0) /* Unknown growth direction. */ - find_stack_direction (); -# endif - - /* Reclaim garbage, defined as all alloca'd storage that - was allocated from deeper in the stack than currently. */ - - { - register header *hp; /* Traverses linked list. */ - -# ifdef emacs - BLOCK_INPUT; -# endif - - for (hp = last_alloca_header; hp != NULL;) - if ((STACK_DIR > 0 && hp->h.deep > depth) - || (STACK_DIR < 0 && hp->h.deep < depth)) - { - register header *np = hp->h.next; - - free (hp); /* Collect garbage. */ - - hp = np; /* -> next header. */ - } - else - break; /* Rest are not deeper. */ - - last_alloca_header = hp; /* -> last valid storage. */ - -# ifdef emacs - UNBLOCK_INPUT; -# endif - } - - if (size == 0) - return NULL; /* No allocation required. */ - - /* Allocate combined header + user data storage. */ - - { - /* Address of header. */ - register header *new; - - size_t combined_size = sizeof (header) + size; - if (combined_size < sizeof (header)) - memory_full (); - - new = malloc (combined_size); - - if (! new) - memory_full (); - - new->h.next = last_alloca_header; - new->h.deep = depth; - - last_alloca_header = new; - - /* User storage begins just after header. */ - - return (void *) (new + 1); - } -} - -# if defined (CRAY) && defined (CRAY_STACKSEG_END) - -# ifdef DEBUG_I00AFUNC -# include -# endif - -# ifndef CRAY_STACK -# define CRAY_STACK -# ifndef CRAY2 -/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ -struct stack_control_header - { - long shgrow:32; /* Number of times stack has grown. */ - long shaseg:32; /* Size of increments to stack. */ - long shhwm:32; /* High water mark of stack. */ - long shsize:32; /* Current size of stack (all segments). */ - }; - -/* The stack segment linkage control information occurs at - the high-address end of a stack segment. (The stack - grows from low addresses to high addresses.) The initial - part of the stack segment linkage control information is - 0200 (octal) words. This provides for register storage - for the routine which overflows the stack. */ - -struct stack_segment_linkage - { - long ss[0200]; /* 0200 overflow words. */ - long sssize:32; /* Number of words in this segment. */ - long ssbase:32; /* Offset to stack base. */ - long:32; - long sspseg:32; /* Offset to linkage control of previous - segment of stack. */ - long:32; - long sstcpt:32; /* Pointer to task common address block. */ - long sscsnm; /* Private control structure number for - microtasking. */ - long ssusr1; /* Reserved for user. */ - long ssusr2; /* Reserved for user. */ - long sstpid; /* Process ID for pid based multi-tasking. */ - long ssgvup; /* Pointer to multitasking thread giveup. */ - long sscray[7]; /* Reserved for Cray Research. */ - long ssa0; - long ssa1; - long ssa2; - long ssa3; - long ssa4; - long ssa5; - long ssa6; - long ssa7; - long sss0; - long sss1; - long sss2; - long sss3; - long sss4; - long sss5; - long sss6; - long sss7; - }; - -# else /* CRAY2 */ -/* The following structure defines the vector of words - returned by the STKSTAT library routine. */ -struct stk_stat - { - long now; /* Current total stack size. */ - long maxc; /* Amount of contiguous space which would - be required to satisfy the maximum - stack demand to date. */ - long high_water; /* Stack high-water mark. */ - long overflows; /* Number of stack overflow ($STKOFEN) calls. */ - long hits; /* Number of internal buffer hits. */ - long extends; /* Number of block extensions. */ - long stko_mallocs; /* Block allocations by $STKOFEN. */ - long underflows; /* Number of stack underflow calls ($STKRETN). */ - long stko_free; /* Number of deallocations by $STKRETN. */ - long stkm_free; /* Number of deallocations by $STKMRET. */ - long segments; /* Current number of stack segments. */ - long maxs; /* Maximum number of stack segments so far. */ - long pad_size; /* Stack pad size. */ - long current_address; /* Current stack segment address. */ - long current_size; /* Current stack segment size. This - number is actually corrupted by STKSTAT to - include the fifteen word trailer area. */ - long initial_address; /* Address of initial segment. */ - long initial_size; /* Size of initial segment. */ - }; - -/* The following structure describes the data structure which trails - any stack segment. I think that the description in 'asdef' is - out of date. I only describe the parts that I am sure about. */ - -struct stk_trailer - { - long this_address; /* Address of this block. */ - long this_size; /* Size of this block (does not include - this trailer). */ - long unknown2; - long unknown3; - long link; /* Address of trailer block of previous - segment. */ - long unknown5; - long unknown6; - long unknown7; - long unknown8; - long unknown9; - long unknown10; - long unknown11; - long unknown12; - long unknown13; - long unknown14; - }; - -# endif /* CRAY2 */ -# endif /* not CRAY_STACK */ - -# ifdef CRAY2 -/* Determine a "stack measure" for an arbitrary ADDRESS. - I doubt that "lint" will like this much. */ - -static long -i00afunc (long *address) -{ - struct stk_stat status; - struct stk_trailer *trailer; - long *block, size; - long result = 0; - - /* We want to iterate through all of the segments. The first - step is to get the stack status structure. We could do this - more quickly and more directly, perhaps, by referencing the - $LM00 common block, but I know that this works. */ - - STKSTAT (&status); - - /* Set up the iteration. */ - - trailer = (struct stk_trailer *) (status.current_address - + status.current_size - - 15); - - /* There must be at least one stack segment. Therefore it is - a fatal error if "trailer" is null. */ - - if (trailer == 0) - abort (); - - /* Discard segments that do not contain our argument address. */ - - while (trailer != 0) - { - block = (long *) trailer->this_address; - size = trailer->this_size; - if (block == 0 || size == 0) - abort (); - trailer = (struct stk_trailer *) trailer->link; - if ((block <= address) && (address < (block + size))) - break; - } - - /* Set the result to the offset in this segment and add the sizes - of all predecessor segments. */ - - result = address - block; - - if (trailer == 0) - { - return result; - } - - do - { - if (trailer->this_size <= 0) - abort (); - result += trailer->this_size; - trailer = (struct stk_trailer *) trailer->link; - } - while (trailer != 0); - - /* We are done. Note that if you present a bogus address (one - not in any segment), you will get a different number back, formed - from subtracting the address of the first block. This is probably - not what you want. */ - - return (result); -} - -# else /* not CRAY2 */ -/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. - Determine the number of the cell within the stack, - given the address of the cell. The purpose of this - routine is to linearize, in some sense, stack addresses - for alloca. */ - -static long -i00afunc (long address) -{ - long stkl = 0; - - long size, pseg, this_segment, stack; - long result = 0; - - struct stack_segment_linkage *ssptr; - - /* Register B67 contains the address of the end of the - current stack segment. If you (as a subprogram) store - your registers on the stack and find that you are past - the contents of B67, you have overflowed the segment. - - B67 also points to the stack segment linkage control - area, which is what we are really interested in. */ - - stkl = CRAY_STACKSEG_END (); - ssptr = (struct stack_segment_linkage *) stkl; - - /* If one subtracts 'size' from the end of the segment, - one has the address of the first word of the segment. - - If this is not the first segment, 'pseg' will be - nonzero. */ - - pseg = ssptr->sspseg; - size = ssptr->sssize; - - this_segment = stkl - size; - - /* It is possible that calling this routine itself caused - a stack overflow. Discard stack segments which do not - contain the target address. */ - - while (!(this_segment <= address && address <= stkl)) - { -# ifdef DEBUG_I00AFUNC - fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); -# endif - if (pseg == 0) - break; - stkl = stkl - pseg; - ssptr = (struct stack_segment_linkage *) stkl; - size = ssptr->sssize; - pseg = ssptr->sspseg; - this_segment = stkl - size; - } - - result = address - this_segment; - - /* If you subtract pseg from the current end of the stack, - you get the address of the previous stack segment's end. - This seems a little convoluted to me, but I'll bet you save - a cycle somewhere. */ - - while (pseg != 0) - { -# ifdef DEBUG_I00AFUNC - fprintf (stderr, "%011o %011o\n", pseg, size); -# endif - stkl = stkl - pseg; - ssptr = (struct stack_segment_linkage *) stkl; - size = ssptr->sssize; - pseg = ssptr->sspseg; - result += size; - } - return (result); -} - -# endif /* not CRAY2 */ -# endif /* CRAY */ - -# endif /* no alloca */ -#endif /* not GCC version 2 */ diff --git a/lib/alloca.in.h b/lib/alloca.in.h deleted file mode 100644 index af274b9..0000000 --- a/lib/alloca.in.h +++ /dev/null @@ -1,54 +0,0 @@ -/* Memory allocation on the stack. - - Copyright (C) 1995, 1999, 2001-2004, 2006-2007 Free Software - Foundation, Inc. - - 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 2, 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, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. */ - -/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H - means there is a real alloca function. */ -#ifndef _GL_ALLOCA_H -#define _GL_ALLOCA_H - -/* alloca (N) returns a pointer to N bytes of memory - allocated on the stack, which will last until the function returns. - Use of alloca should be avoided: - - inside arguments of function calls - undefined behaviour, - - in inline functions - the allocation may actually last until the - calling function returns, - - for huge N (say, N >= 65536) - you never know how large (or small) - the stack is, and when the stack cannot fulfill the memory allocation - request, the program just crashes. - */ - -#ifndef alloca -# ifdef __GNUC__ -# define alloca __builtin_alloca -# elif defined _AIX -# define alloca __alloca -# elif defined _MSC_VER -# include -# define alloca _alloca -# else -# include -# ifdef __cplusplus -extern "C" -# endif -void *alloca (size_t); -# endif -#endif - -#endif /* _GL_ALLOCA_H */ diff --git a/lib/argp-ba.c b/lib/argp-ba.c deleted file mode 100644 index 8bb7309..0000000 --- a/lib/argp-ba.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Default definition for ARGP_PROGRAM_BUG_ADDRESS. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* If set by the user program, it should point to string that is the - bug-reporting address for the program. It will be printed by argp_help if - the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help - messages), embedded in a sentence that says something like `Report bugs to - ADDR.'. */ -const char *argp_program_bug_address; diff --git a/lib/argp-eexst.c b/lib/argp-eexst.c deleted file mode 100644 index bcab1c0..0000000 --- a/lib/argp-eexst.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Default definition for ARGP_ERR_EXIT_STATUS - Copyright (C) 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "argp.h" - -/* The exit status that argp will use when exiting due to a parsing error. - If not defined or set by the user program, this defaults to EX_USAGE from - . */ -error_t argp_err_exit_status = EX_USAGE; diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c deleted file mode 100644 index 0dd9256..0000000 --- a/lib/argp-fmtstream.c +++ /dev/null @@ -1,435 +0,0 @@ -/* Word-wrapping and line-truncating streams - Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* This package emulates glibc `line_wrap_stream' semantics for systems that - don't have that. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include - -#include "argp-fmtstream.h" -#include "argp-namefrob.h" - -#ifndef ARGP_FMTSTREAM_USE_LINEWRAP - -#ifndef isblank -#define isblank(ch) ((ch)==' ' || (ch)=='\t') -#endif - -#if defined _LIBC && defined USE_IN_LIBIO -# include -# include -# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a) -#endif - -#define INIT_BUF_SIZE 200 -#define PRINTF_SIZE_GUESS 150 - -/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines - written on it with LMARGIN spaces and limits them to RMARGIN columns - total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by - replacing the whitespace before them with a newline and WMARGIN spaces. - Otherwise, chars beyond RMARGIN are simply dropped until a newline. - Returns NULL if there was an error. */ -argp_fmtstream_t -__argp_make_fmtstream (FILE *stream, - size_t lmargin, size_t rmargin, ssize_t wmargin) -{ - argp_fmtstream_t fs; - - fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream)); - if (fs != NULL) - { - fs->stream = stream; - - fs->lmargin = lmargin; - fs->rmargin = rmargin; - fs->wmargin = wmargin; - fs->point_col = 0; - fs->point_offs = 0; - - fs->buf = (char *) malloc (INIT_BUF_SIZE); - if (! fs->buf) - { - free (fs); - fs = 0; - } - else - { - fs->p = fs->buf; - fs->end = fs->buf + INIT_BUF_SIZE; - } - } - - return fs; -} -#if 0 -/* Not exported. */ -#ifdef weak_alias -weak_alias (__argp_make_fmtstream, argp_make_fmtstream) -#endif -#endif - -/* Flush FS to its stream, and free it (but don't close the stream). */ -void -__argp_fmtstream_free (argp_fmtstream_t fs) -{ - __argp_fmtstream_update (fs); - if (fs->p > fs->buf) - { -#ifdef USE_IN_LIBIO - __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); -#else - fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); -#endif - } - free (fs->buf); - free (fs); -} -#if 0 -/* Not exported. */ -#ifdef weak_alias -weak_alias (__argp_fmtstream_free, argp_fmtstream_free) -#endif -#endif - -/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the - end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ -void -__argp_fmtstream_update (argp_fmtstream_t fs) -{ - char *buf, *nl; - size_t len; - - /* Scan the buffer for newlines. */ - buf = fs->buf + fs->point_offs; - while (buf < fs->p) - { - size_t r; - - if (fs->point_col == 0 && fs->lmargin != 0) - { - /* We are starting a new line. Print spaces to the left margin. */ - const size_t pad = fs->lmargin; - if (fs->p + pad < fs->end) - { - /* We can fit in them in the buffer by moving the - buffer text up and filling in the beginning. */ - memmove (buf + pad, buf, fs->p - buf); - fs->p += pad; /* Compensate for bigger buffer. */ - memset (buf, ' ', pad); /* Fill in the spaces. */ - buf += pad; /* Don't bother searching them. */ - } - else - { - /* No buffer space for spaces. Must flush. */ - size_t i; - for (i = 0; i < pad; i++) - { -#ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - putwc_unlocked (L' ', fs->stream); - else -#endif - putc_unlocked (' ', fs->stream); - } - } - fs->point_col = pad; - } - - len = fs->p - buf; - nl = memchr (buf, '\n', len); - - if (fs->point_col < 0) - fs->point_col = 0; - - if (!nl) - { - /* The buffer ends in a partial line. */ - - if (fs->point_col + len < fs->rmargin) - { - /* The remaining buffer text is a partial line and fits - within the maximum line width. Advance point for the - characters to be written and stop scanning. */ - fs->point_col += len; - break; - } - else - /* Set the end-of-line pointer for the code below to - the end of the buffer. */ - nl = fs->p; - } - else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) - { - /* The buffer contains a full line that fits within the maximum - line width. Reset point and scan the next line. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - - /* This line is too long. */ - r = fs->rmargin - 1; - - if (fs->wmargin < 0) - { - /* Truncate the line by overwriting the excess with the - newline and anything after it in the buffer. */ - if (nl < fs->p) - { - memmove (buf + (r - fs->point_col), nl, fs->p - nl); - fs->p -= buf + (r - fs->point_col) - nl; - /* Reset point for the next line and start scanning it. */ - fs->point_col = 0; - buf += r + 1; /* Skip full line plus \n. */ - } - else - { - /* The buffer ends with a partial line that is beyond the - maximum line width. Advance point for the characters - written, and discard those past the max from the buffer. */ - fs->point_col += len; - fs->p -= fs->point_col - r; - break; - } - } - else - { - /* Do word wrap. Go to the column just past the maximum line - width and scan back for the beginning of the word there. - Then insert a line break. */ - - char *p, *nextline; - int i; - - p = buf + (r + 1 - fs->point_col); - while (p >= buf && !isblank (*p)) - --p; - nextline = p + 1; /* This will begin the next line. */ - - if (nextline > buf) - { - /* Swallow separating blanks. */ - if (p >= buf) - do - --p; - while (p >= buf && isblank (*p)); - nl = p + 1; /* The newline will replace the first blank. */ - } - else - { - /* A single word that is greater than the maximum line width. - Oh well. Put it on an overlong line by itself. */ - p = buf + (r + 1 - fs->point_col); - /* Find the end of the long word. */ - if (p < nl) - do - ++p; - while (p < nl && !isblank (*p)); - if (p == nl) - { - /* It already ends a line. No fussing required. */ - fs->point_col = 0; - buf = nl + 1; - continue; - } - /* We will move the newline to replace the first blank. */ - nl = p; - /* Swallow separating blanks. */ - do - ++p; - while (isblank (*p)); - /* The next line will start here. */ - nextline = p; - } - - /* Note: There are a bunch of tests below for - NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall - at the end of the buffer, and NEXTLINE is in fact empty (and so - we need not be careful to maintain its contents). */ - - if ((nextline == buf + len + 1 - ? fs->end - nl < fs->wmargin + 1 - : nextline - (nl + 1) < fs->wmargin) - && fs->p > nextline) - { - /* The margin needs more blanks than we removed. */ - if (fs->end - fs->p > fs->wmargin + 1) - /* Make some space for them. */ - { - size_t mv = fs->p - nextline; - memmove (nl + 1 + fs->wmargin, nextline, mv); - nextline = nl + 1 + fs->wmargin; - len = nextline + mv - buf; - *nl++ = '\n'; - } - else - /* Output the first line so we can use the space. */ - { -#ifdef _LIBC - __fxprintf (fs->stream, "%.*s\n", - (int) (nl - fs->buf), fs->buf); -#else - if (nl > fs->buf) - fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream); - putc_unlocked ('\n', fs->stream); -#endif - - len += buf - fs->buf; - nl = buf = fs->buf; - } - } - else - /* We can fit the newline and blanks in before - the next word. */ - *nl++ = '\n'; - - if (nextline - nl >= fs->wmargin - || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin)) - /* Add blanks up to the wrap margin column. */ - for (i = 0; i < fs->wmargin; ++i) - *nl++ = ' '; - else - for (i = 0; i < fs->wmargin; ++i) -#ifdef USE_IN_LIBIO - if (_IO_fwide (fs->stream, 0) > 0) - putwc_unlocked (L' ', fs->stream); - else -#endif - putc_unlocked (' ', fs->stream); - - /* Copy the tail of the original buffer into the current buffer - position. */ - if (nl < nextline) - memmove (nl, nextline, buf + len - nextline); - len -= nextline - buf; - - /* Continue the scan on the remaining lines in the buffer. */ - buf = nl; - - /* Restore bufp to include all the remaining text. */ - fs->p = nl + len; - - /* Reset the counter of what has been output this line. If wmargin - is 0, we want to avoid the lmargin getting added, so we set - point_col to a magic value of -1 in that case. */ - fs->point_col = fs->wmargin ? fs->wmargin : -1; - } - } - - /* Remember that we've scanned as far as the end of the buffer. */ - fs->point_offs = fs->p - fs->buf; -} - -/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by - growing the buffer, or by flushing it. True is returned iff we succeed. */ -int -__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount) -{ - if ((size_t) (fs->end - fs->p) < amount) - { - ssize_t wrote; - - /* Flush FS's buffer. */ - __argp_fmtstream_update (fs); - -#ifdef _LIBC - __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf); - wrote = fs->p - fs->buf; -#else - wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream); -#endif - if (wrote == fs->p - fs->buf) - { - fs->p = fs->buf; - fs->point_offs = 0; - } - else - { - fs->p -= wrote; - fs->point_offs -= wrote; - memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf); - return 0; - } - - if ((size_t) (fs->end - fs->buf) < amount) - /* Gotta grow the buffer. */ - { - size_t old_size = fs->end - fs->buf; - size_t new_size = old_size + amount; - char *new_buf; - - if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size))) - { - __set_errno (ENOMEM); - return 0; - } - - fs->buf = new_buf; - fs->end = new_buf + new_size; - fs->p = fs->buf; - } - } - - return 1; -} - -ssize_t -__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...) -{ - int out; - size_t avail; - size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */ - - do - { - va_list args; - - if (! __argp_fmtstream_ensure (fs, size_guess)) - return -1; - - va_start (args, fmt); - avail = fs->end - fs->p; - out = __vsnprintf (fs->p, avail, fmt, args); - va_end (args); - if ((size_t) out >= avail) - size_guess = out + 1; - } - while ((size_t) out >= avail); - - fs->p += out; - - return out; -} -#if 0 -/* Not exported. */ -#ifdef weak_alias -weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf) -#endif -#endif - -#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */ diff --git a/lib/argp-fmtstream.h b/lib/argp-fmtstream.h deleted file mode 100644 index e045a72..0000000 --- a/lib/argp-fmtstream.h +++ /dev/null @@ -1,301 +0,0 @@ -/* Word-wrapping and line-truncating streams. - Copyright (C) 1997, 2006 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* This package emulates glibc `line_wrap_stream' semantics for systems that - don't have that. If the system does have it, it is just a wrapper for - that. This header file is only used internally while compiling argp, and - shouldn't be installed. */ - -#ifndef _ARGP_FMTSTREAM_H -#define _ARGP_FMTSTREAM_H - -#include -#include -#include - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__ -# define __format__ format -# define __printf__ printf -# endif -#endif - -#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \ - || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)) -/* line_wrap_stream is available, so use that. */ -#define ARGP_FMTSTREAM_USE_LINEWRAP -#endif - -#ifdef ARGP_FMTSTREAM_USE_LINEWRAP -/* Just be a simple wrapper for line_wrap_stream; the semantics are - *slightly* different, as line_wrap_stream doesn't actually make a new - object, it just modifies the given stream (reversibly) to do - line-wrapping. Since we control who uses this code, it doesn't matter. */ - -#include - -typedef FILE *argp_fmtstream_t; - -#define argp_make_fmtstream line_wrap_stream -#define __argp_make_fmtstream line_wrap_stream -#define argp_fmtstream_free line_unwrap_stream -#define __argp_fmtstream_free line_unwrap_stream - -#define __argp_fmtstream_putc(fs,ch) putc(ch,fs) -#define argp_fmtstream_putc(fs,ch) putc(ch,fs) -#define __argp_fmtstream_puts(fs,str) fputs(str,fs) -#define argp_fmtstream_puts(fs,str) fputs(str,fs) -#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) -#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs) -#define __argp_fmtstream_printf fprintf -#define argp_fmtstream_printf fprintf - -#define __argp_fmtstream_lmargin line_wrap_lmargin -#define argp_fmtstream_lmargin line_wrap_lmargin -#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin -#define argp_fmtstream_set_lmargin line_wrap_set_lmargin -#define __argp_fmtstream_rmargin line_wrap_rmargin -#define argp_fmtstream_rmargin line_wrap_rmargin -#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin -#define argp_fmtstream_set_rmargin line_wrap_set_rmargin -#define __argp_fmtstream_wmargin line_wrap_wmargin -#define argp_fmtstream_wmargin line_wrap_wmargin -#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin -#define argp_fmtstream_set_wmargin line_wrap_set_wmargin -#define __argp_fmtstream_point line_wrap_point -#define argp_fmtstream_point line_wrap_point - -#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */ -/* Guess we have to define our own version. */ - -struct argp_fmtstream -{ - FILE *stream; /* The stream we're outputting to. */ - - size_t lmargin, rmargin; /* Left and right margins. */ - ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ - - /* Point in buffer to which we've processed for wrapping, but not output. */ - size_t point_offs; - /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ - ssize_t point_col; - - char *buf; /* Output buffer. */ - char *p; /* Current end of text in BUF. */ - char *end; /* Absolute end of BUF. */ -}; - -typedef struct argp_fmtstream *argp_fmtstream_t; - -/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines - written on it with LMARGIN spaces and limits them to RMARGIN columns - total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by - replacing the whitespace before them with a newline and WMARGIN spaces. - Otherwise, chars beyond RMARGIN are simply dropped until a newline. - Returns NULL if there was an error. */ -extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); -extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); - -/* Flush __FS to its stream, and free it (but don't close the stream). */ -extern void __argp_fmtstream_free (argp_fmtstream_t __fs); -extern void argp_fmtstream_free (argp_fmtstream_t __fs); - -extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, - const char *__fmt, ...) - __attribute__ ((__format__ (printf, 2, 3))); -extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, - const char *__fmt, ...) - __attribute__ ((__format__ (printf, 2, 3))); - -extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); -extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); - -extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); -extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); - -extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - const char *__str, size_t __len); -extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, - const char *__str, size_t __len); - -/* Access macros for various bits of state. */ -#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin) -#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin) -#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin) -#define __argp_fmtstream_lmargin argp_fmtstream_lmargin -#define __argp_fmtstream_rmargin argp_fmtstream_rmargin -#define __argp_fmtstream_wmargin argp_fmtstream_wmargin - -/* Set __FS's left margin to LMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); -extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); -extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); - -/* Set __FS's wrap margin to __WMARGIN and return the old value. */ -extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); -extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); - -/* Return the column number of the current output point in __FS. */ -extern size_t argp_fmtstream_point (argp_fmtstream_t __fs); -extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs); - -/* Internal routines. */ -extern void _argp_fmtstream_update (argp_fmtstream_t __fs); -extern void __argp_fmtstream_update (argp_fmtstream_t __fs); -extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); -extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); - -#ifdef __OPTIMIZE__ -/* Inline versions of above routines. */ - -#if !_LIBC -#define __argp_fmtstream_putc argp_fmtstream_putc -#define __argp_fmtstream_puts argp_fmtstream_puts -#define __argp_fmtstream_write argp_fmtstream_write -#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin -#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin -#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin -#define __argp_fmtstream_point argp_fmtstream_point -#define __argp_fmtstream_update _argp_fmtstream_update -#define __argp_fmtstream_ensure _argp_fmtstream_ensure -#endif - -#ifndef ARGP_FS_EI -#define ARGP_FS_EI extern inline -#endif - -ARGP_FS_EI size_t -__argp_fmtstream_write (argp_fmtstream_t __fs, - const char *__str, size_t __len) -{ - if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) - { - memcpy (__fs->p, __str, __len); - __fs->p += __len; - return __len; - } - else - return 0; -} - -ARGP_FS_EI int -__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str) -{ - size_t __len = strlen (__str); - if (__len) - { - size_t __wrote = __argp_fmtstream_write (__fs, __str, __len); - return __wrote == __len ? 0 : -1; - } - else - return 0; -} - -ARGP_FS_EI int -__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch) -{ - if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1)) - return *__fs->p++ = __ch; - else - return EOF; -} - -/* Set __FS's left margin to __LMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->lmargin; - __fs->lmargin = __lmargin; - return __old; -} - -/* Set __FS's right margin to __RMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->rmargin; - __fs->rmargin = __rmargin; - return __old; -} - -/* Set FS's wrap margin to __WMARGIN and return the old value. */ -ARGP_FS_EI size_t -__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin) -{ - size_t __old; - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - __old = __fs->wmargin; - __fs->wmargin = __wmargin; - return __old; -} - -/* Return the column number of the current output point in __FS. */ -ARGP_FS_EI size_t -__argp_fmtstream_point (argp_fmtstream_t __fs) -{ - if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs) - __argp_fmtstream_update (__fs); - return __fs->point_col >= 0 ? __fs->point_col : 0; -} - -#if !_LIBC -#undef __argp_fmtstream_putc -#undef __argp_fmtstream_puts -#undef __argp_fmtstream_write -#undef __argp_fmtstream_set_lmargin -#undef __argp_fmtstream_set_rmargin -#undef __argp_fmtstream_set_wmargin -#undef __argp_fmtstream_point -#undef __argp_fmtstream_update -#undef __argp_fmtstream_ensure -#endif - -#endif /* __OPTIMIZE__ */ - -#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */ - -#endif /* argp-fmtstream.h */ diff --git a/lib/argp-fs-xinl.c b/lib/argp-fs-xinl.c deleted file mode 100644 index 3b4c917..0000000 --- a/lib/argp-fs-xinl.c +++ /dev/null @@ -1,43 +0,0 @@ -/* Real definitions for extern inline functions in argp-fmtstream.h - Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#define ARGP_FS_EI -#undef __OPTIMIZE__ -#define __OPTIMIZE__ 1 -#include "argp-fmtstream.h" - -#if 0 -/* Not exported. */ -/* Add weak aliases. */ -#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias) - -weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc) -weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts) -weak_alias (__argp_fmtstream_write, argp_fmtstream_write) -weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin) -weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin) -weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin) -weak_alias (__argp_fmtstream_point, argp_fmtstream_point) - -#endif -#endif diff --git a/lib/argp-help.c b/lib/argp-help.c deleted file mode 100644 index 1a4131f..0000000 --- a/lib/argp-help.c +++ /dev/null @@ -1,1954 +0,0 @@ -/* Hierarchial argument parsing help output - Copyright (C) 1995-2005, 2007 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef USE_IN_LIBIO -# include -#endif - -#ifdef _LIBC -# include -# undef dgettext -# define dgettext(domain, msgid) \ - INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES) -#else -# include "gettext.h" -#endif - -#include "argp.h" -#include "argp-fmtstream.h" -#include "argp-namefrob.h" - -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - -/* User-selectable (using an environment variable) formatting parameters. - - These may be specified in an environment variable called `ARGP_HELP_FMT', - with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2 - Where VALn must be a positive integer. The list of variables is in the - UPARAM_NAMES vector, below. */ - -/* Default parameters. */ -#define DUP_ARGS 0 /* True if option argument can be duplicated. */ -#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */ -#define SHORT_OPT_COL 2 /* column in which short options start */ -#define LONG_OPT_COL 6 /* column in which long options start */ -#define DOC_OPT_COL 2 /* column in which doc options start */ -#define OPT_DOC_COL 29 /* column in which option text starts */ -#define HEADER_COL 1 /* column in which group headers are printed */ -#define USAGE_INDENT 12 /* indentation of wrapped usage lines */ -#define RMARGIN 79 /* right margin used for wrapping */ - -/* User-selectable (using an environment variable) formatting parameters. - They must all be of type `int' for the parsing code to work. */ -struct uparams -{ - /* If true, arguments for an option are shown with both short and long - options, even when a given option has both, e.g. `-x ARG, --longx=ARG'. - If false, then if an option has both, the argument is only shown with - the long one, e.g., `-x, --longx=ARG', and a message indicating that - this really means both is printed below the options. */ - int dup_args; - - /* This is true if when DUP_ARGS is false, and some duplicate arguments have - been suppressed, an explanatory message should be printed. */ - int dup_args_note; - - /* Various output columns. */ - int short_opt_col; /* column in which short options start */ - int long_opt_col; /* column in which long options start */ - int doc_opt_col; /* column in which doc options start */ - int opt_doc_col; /* column in which option text starts */ - int header_col; /* column in which group headers are printed */ - int usage_indent; /* indentation of wrapped usage lines */ - int rmargin; /* right margin used for wrapping */ - - int valid; /* True when the values in here are valid. */ -}; - -/* This is a global variable, as user options are only ever read once. */ -static struct uparams uparams = { - DUP_ARGS, DUP_ARGS_NOTE, - SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL, - USAGE_INDENT, RMARGIN, - 0 -}; - -/* A particular uparam, and what the user name is. */ -struct uparam_name -{ - const char *name; /* User name. */ - int is_bool; /* Whether it's `boolean'. */ - size_t uparams_offs; /* Location of the (int) field in UPARAMS. */ -}; - -/* The name-field mappings we know about. */ -static const struct uparam_name uparam_names[] = -{ - { "dup-args", 1, offsetof (struct uparams, dup_args) }, - { "dup-args-note", 1, offsetof (struct uparams, dup_args_note) }, - { "short-opt-col", 0, offsetof (struct uparams, short_opt_col) }, - { "long-opt-col", 0, offsetof (struct uparams, long_opt_col) }, - { "doc-opt-col", 0, offsetof (struct uparams, doc_opt_col) }, - { "opt-doc-col", 0, offsetof (struct uparams, opt_doc_col) }, - { "header-col", 0, offsetof (struct uparams, header_col) }, - { "usage-indent", 0, offsetof (struct uparams, usage_indent) }, - { "rmargin", 0, offsetof (struct uparams, rmargin) }, - { 0 } -}; - -static void -validate_uparams (const struct argp_state *state, struct uparams *upptr) -{ - const struct uparam_name *up; - - for (up = uparam_names; up->name; up++) - { - if (up->is_bool - || up->uparams_offs == offsetof (struct uparams, rmargin)) - continue; - if (*(int *)((char *)upptr + up->uparams_offs) >= upptr->rmargin) - { - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "\ -ARGP_HELP_FMT: %s value is less than or equal to %s"), - "rmargin", up->name); - return; - } - } - uparams = *upptr; - uparams.valid = 1; -} - -/* Read user options from the environment, and fill in UPARAMS appropiately. */ -static void -fill_in_uparams (const struct argp_state *state) -{ - const char *var = getenv ("ARGP_HELP_FMT"); - struct uparams new_params = uparams; - -#define SKIPWS(p) do { while (isspace ((unsigned char) *p)) p++; } while (0); - - if (var) - { - /* Parse var. */ - while (*var) - { - SKIPWS (var); - - if (isalpha ((unsigned char) *var)) - { - size_t var_len; - const struct uparam_name *un; - int unspec = 0, val = 0; - const char *arg = var; - - while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == '_') - arg++; - var_len = arg - var; - - SKIPWS (arg); - - if (*arg == '\0' || *arg == ',') - unspec = 1; - else if (*arg == '=') - { - arg++; - SKIPWS (arg); - } - - if (unspec) - { - if (var[0] == 'n' && var[1] == 'o' && var[2] == '-') - { - val = 0; - var += 3; - var_len -= 3; - } - else - val = 1; - } - else if (isdigit ((unsigned char) *arg)) - { - val = atoi (arg); - while (isdigit ((unsigned char) *arg)) - arg++; - SKIPWS (arg); - } - - for (un = uparam_names; un->name; un++) - if (strlen (un->name) == var_len - && strncmp (var, un->name, var_len) == 0) - { - if (unspec && !un->is_bool) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "\ -%.*s: ARGP_HELP_FMT parameter requires a value"), - (int) var_len, var); - else if (val < 0) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "\ -%.*s: ARGP_HELP_FMT parameter must be positive"), - (int) var_len, var); - else - *(int *)((char *)&new_params + un->uparams_offs) = val; - break; - } - if (! un->name) - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, "\ -%.*s: Unknown ARGP_HELP_FMT parameter"), - (int) var_len, var); - - var = arg; - if (*var == ',') - var++; - } - else if (*var) - { - __argp_failure (state, 0, 0, - dgettext (state->root_argp->argp_domain, - "Garbage in ARGP_HELP_FMT: %s"), var); - break; - } - } - validate_uparams (state, &new_params); - } -} - -/* Returns true if OPT hasn't been marked invisible. Visibility only affects - whether OPT is displayed or used in sorting, not option shadowing. */ -#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN)) - -/* Returns true if OPT is an alias for an earlier option. */ -#define oalias(opt) ((opt)->flags & OPTION_ALIAS) - -/* Returns true if OPT is an documentation-only entry. */ -#define odoc(opt) ((opt)->flags & OPTION_DOC) - -/* Returns true if OPT should not be translated */ -#define onotrans(opt) ((opt)->flags & OPTION_NO_TRANS) - -/* Returns true if OPT is the end-of-list marker for a list of options. */ -#define oend(opt) __option_is_end (opt) - -/* Returns true if OPT has a short option. */ -#define oshort(opt) __option_is_short (opt) - -/* - The help format for a particular option is like: - - -xARG, -yARG, --long1=ARG, --long2=ARG Documentation... - - Where ARG will be omitted if there's no argument, for this option, or - will be surrounded by "[" and "]" appropiately if the argument is - optional. The documentation string is word-wrapped appropiately, and if - the list of options is long enough, it will be started on a separate line. - If there are no short options for a given option, the first long option is - indented slighly in a way that's supposed to make most long options appear - to be in a separate column. - - For example, the following output (from ps): - - -p PID, --pid=PID List the process PID - --pgrp=PGRP List processes in the process group PGRP - -P, -x, --no-parent Include processes without parents - -Q, --all-fields Don't elide unusable fields (normally if there's - some reason ps can't print a field for any - process, it's removed from the output entirely) - -r, --reverse, --gratuitously-long-reverse-option - Reverse the order of any sort - --session[=SID] Add the processes from the session SID (which - defaults to the sid of the current process) - - Here are some more options: - -f ZOT, --foonly=ZOT Glork a foonly - -z, --zaza Snit a zar - - -?, --help Give this help list - --usage Give a short usage message - -V, --version Print program version - - The struct argp_option array for the above could look like: - - { - {"pid", 'p', "PID", 0, "List the process PID"}, - {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"}, - {"no-parent", 'P', 0, 0, "Include processes without parents"}, - {0, 'x', 0, OPTION_ALIAS}, - {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally" - " if there's some reason ps can't" - " print a field for any process, it's" - " removed from the output entirely)" }, - {"reverse", 'r', 0, 0, "Reverse the order of any sort"}, - {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS}, - {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL, - "Add the processes from the session" - " SID (which defaults to the sid of" - " the current process)" }, - - {0,0,0,0, "Here are some more options:"}, - {"foonly", 'f', "ZOT", 0, "Glork a foonly"}, - {"zaza", 'z', 0, 0, "Snit a zar"}, - - {0} - } - - Note that the last three options are automatically supplied by argp_parse, - unless you tell it not to with ARGP_NO_HELP. - -*/ - -/* Returns true if CH occurs between BEG and END. */ -static int -find_char (char ch, char *beg, char *end) -{ - while (beg < end) - if (*beg == ch) - return 1; - else - beg++; - return 0; -} - -struct hol_cluster; /* fwd decl */ - -struct hol_entry -{ - /* First option. */ - const struct argp_option *opt; - /* Number of options (including aliases). */ - unsigned num; - - /* A pointers into the HOL's short_options field, to the first short option - letter for this entry. The order of the characters following this point - corresponds to the order of options pointed to by OPT, and there are at - most NUM. A short option recorded in a option following OPT is only - valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's - probably been shadowed by some other entry). */ - char *short_options; - - /* Entries are sorted by their group first, in the order: - 1, 2, ..., n, 0, -m, ..., -2, -1 - and then alphabetically within each group. The default is 0. */ - int group; - - /* The cluster of options this entry belongs to, or 0 if none. */ - struct hol_cluster *cluster; - - /* The argp from which this option came. */ - const struct argp *argp; - - /* Position in the array */ - unsigned ord; -}; - -/* A cluster of entries to reflect the argp tree structure. */ -struct hol_cluster -{ - /* A descriptive header printed before options in this cluster. */ - const char *header; - - /* Used to order clusters within the same group with the same parent, - according to the order in which they occurred in the parent argp's child - list. */ - int index; - - /* How to sort this cluster with respect to options and other clusters at the - same depth (clusters always follow options in the same group). */ - int group; - - /* The cluster to which this cluster belongs, or 0 if it's at the base - level. */ - struct hol_cluster *parent; - - /* The argp from which this cluster is (eventually) derived. */ - const struct argp *argp; - - /* The distance this cluster is from the root. */ - int depth; - - /* Clusters in a given hol are kept in a linked list, to make freeing them - possible. */ - struct hol_cluster *next; -}; - -/* A list of options for help. */ -struct hol -{ - /* An array of hol_entry's. */ - struct hol_entry *entries; - /* The number of entries in this hol. If this field is zero, the others - are undefined. */ - unsigned num_entries; - - /* A string containing all short options in this HOL. Each entry contains - pointers into this string, so the order can't be messed with blindly. */ - char *short_options; - - /* Clusters of entries in this hol. */ - struct hol_cluster *clusters; -}; - -/* Create a struct hol from the options in ARGP. CLUSTER is the - hol_cluster in which these entries occur, or 0, if at the root. */ -static struct hol * -make_hol (const struct argp *argp, struct hol_cluster *cluster) -{ - char *so; - const struct argp_option *o; - const struct argp_option *opts = argp->options; - struct hol_entry *entry; - unsigned num_short_options = 0; - struct hol *hol = malloc (sizeof (struct hol)); - - assert (hol); - - hol->num_entries = 0; - hol->clusters = 0; - - if (opts) - { - int cur_group = 0; - - /* The first option must not be an alias. */ - assert (! oalias (opts)); - - /* Calculate the space needed. */ - for (o = opts; ! oend (o); o++) - { - if (! oalias (o)) - hol->num_entries++; - if (oshort (o)) - num_short_options++; /* This is an upper bound. */ - } - - hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries); - hol->short_options = malloc (num_short_options + 1); - - assert (hol->entries && hol->short_options); - if (SIZE_MAX <= UINT_MAX) - assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry)); - - /* Fill in the entries. */ - so = hol->short_options; - for (o = opts, entry = hol->entries; ! oend (o); entry++) - { - entry->opt = o; - entry->num = 0; - entry->short_options = so; - entry->group = cur_group = - o->group - ? o->group - : ((!o->name && !o->key) - ? cur_group + 1 - : cur_group); - entry->cluster = cluster; - entry->argp = argp; - - do - { - entry->num++; - if (oshort (o) && ! find_char (o->key, hol->short_options, so)) - /* O has a valid short option which hasn't already been used.*/ - *so++ = o->key; - o++; - } - while (! oend (o) && oalias (o)); - } - *so = '\0'; /* null terminated so we can find the length */ - } - - return hol; -} - -/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the - associated argp child list entry), INDEX, and PARENT, and return a pointer - to it. ARGP is the argp that this cluster results from. */ -static struct hol_cluster * -hol_add_cluster (struct hol *hol, int group, const char *header, int index, - struct hol_cluster *parent, const struct argp *argp) -{ - struct hol_cluster *cl = malloc (sizeof (struct hol_cluster)); - if (cl) - { - cl->group = group; - cl->header = header; - - cl->index = index; - cl->parent = parent; - cl->argp = argp; - cl->depth = parent ? parent->depth + 1 : 0; - - cl->next = hol->clusters; - hol->clusters = cl; - } - return cl; -} - -/* Free HOL and any resources it uses. */ -static void -hol_free (struct hol *hol) -{ - struct hol_cluster *cl = hol->clusters; - - while (cl) - { - struct hol_cluster *next = cl->next; - free (cl); - cl = next; - } - - if (hol->num_entries > 0) - { - free (hol->entries); - free (hol->short_options); - } - - free (hol); -} - -static int -hol_entry_short_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) -{ - unsigned nopts; - int val = 0; - const struct argp_option *opt, *real = entry->opt; - char *so = entry->short_options; - - for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) - if (oshort (opt) && *so == opt->key) - { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - so++; - } - - return val; -} - -static inline int -__attribute__ ((always_inline)) -hol_entry_long_iterate (const struct hol_entry *entry, - int (*func)(const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie), - const char *domain, void *cookie) -{ - unsigned nopts; - int val = 0; - const struct argp_option *opt, *real = entry->opt; - - for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--) - if (opt->name) - { - if (!oalias (opt)) - real = opt; - if (ovisible (opt)) - val = (*func)(opt, real, domain, cookie); - } - - return val; -} - -/* Iterator that returns true for the first short option. */ -static int -until_short (const struct argp_option *opt, const struct argp_option *real, - const char *domain, void *cookie) -{ - return oshort (opt) ? opt->key : 0; -} - -/* Returns the first valid short option in ENTRY, or 0 if there is none. */ -static char -hol_entry_first_short (const struct hol_entry *entry) -{ - return hol_entry_short_iterate (entry, until_short, - entry->argp->argp_domain, 0); -} - -/* Returns the first valid long option in ENTRY, or 0 if there is none. */ -static const char * -hol_entry_first_long (const struct hol_entry *entry) -{ - const struct argp_option *opt; - unsigned num; - for (opt = entry->opt, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - return opt->name; - return 0; -} - -/* Returns the entry in HOL with the long option name NAME, or 0 if there is - none. */ -static struct hol_entry * -hol_find_entry (struct hol *hol, const char *name) -{ - struct hol_entry *entry = hol->entries; - unsigned num_entries = hol->num_entries; - - while (num_entries-- > 0) - { - const struct argp_option *opt = entry->opt; - unsigned num_opts = entry->num; - - while (num_opts-- > 0) - if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0) - return entry; - else - opt++; - - entry++; - } - - return 0; -} - -/* If an entry with the long option NAME occurs in HOL, set it's special - sort position to GROUP. */ -static void -hol_set_group (struct hol *hol, const char *name, int group) -{ - struct hol_entry *entry = hol_find_entry (hol, name); - if (entry) - entry->group = group; -} - -/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1. - EQ is what to return if GROUP1 and GROUP2 are the same. */ -static int -group_cmp (int group1, int group2, int eq) -{ - if (group1 == group2) - return eq; - else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0)) - return group1 - group2; - else - return group2 - group1; -} - -/* Compare clusters CL1 & CL2 by the order that they should appear in - output. */ -static int -hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2) -{ - /* If one cluster is deeper than the other, use its ancestor at the same - level, so that finding the common ancestor is straightforward. - - clN->depth > 0 means that clN->parent != NULL (see hol_add_cluster) */ - while (cl1->depth > cl2->depth) - cl1 = cl1->parent; - while (cl2->depth > cl1->depth) - cl2 = cl2->parent; - - /* Now reduce both clusters to their ancestors at the point where both have - a common parent; these can be directly compared. */ - while (cl1->parent != cl2->parent) - cl1 = cl1->parent, cl2 = cl2->parent; - - return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index); -} - -/* Return the ancestor of CL that's just below the root (i.e., has a parent - of 0). */ -static struct hol_cluster * -hol_cluster_base (struct hol_cluster *cl) -{ - while (cl->parent) - cl = cl->parent; - return cl; -} - -/* Return true if CL1 is a child of CL2. */ -static int -hol_cluster_is_child (const struct hol_cluster *cl1, - const struct hol_cluster *cl2) -{ - while (cl1 && cl1 != cl2) - cl1 = cl1->parent; - return cl1 == cl2; -} - -/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail - that should be used for comparisons, and returns true iff it should be - treated as a non-option. */ -static int -canon_doc_option (const char **name) -{ - int non_opt; - - if (!*name) - non_opt = 1; - else - { - /* Skip initial whitespace. */ - while (isspace ((unsigned char) **name)) - (*name)++; - /* Decide whether this looks like an option (leading `-') or not. */ - non_opt = (**name != '-'); - /* Skip until part of name used for sorting. */ - while (**name && !isalnum ((unsigned char) **name)) - (*name)++; - } - return non_opt; -} - -#define HOL_ENTRY_PTRCMP(a,b) ((a)->ord < (b)->ord ? -1 : 1) - -/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help - listing. */ -static int -hol_entry_cmp (const struct hol_entry *entry1, - const struct hol_entry *entry2) -{ - /* The group numbers by which the entries should be ordered; if either is - in a cluster, then this is just the group within the cluster. */ - int group1 = entry1->group, group2 = entry2->group; - int rc; - - if (entry1->cluster != entry2->cluster) - { - /* The entries are not within the same cluster, so we can't compare them - directly, we have to use the appropiate clustering level too. */ - if (! entry1->cluster) - /* ENTRY1 is at the `base level', not in a cluster, so we have to - compare it's group number with that of the base cluster in which - ENTRY2 resides. Note that if they're in the same group, the - clustered option always comes laster. */ - return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1); - else if (! entry2->cluster) - /* Likewise, but ENTRY2's not in a cluster. */ - return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1); - else - /* Both entries are in clusters, we can just compare the clusters. */ - return (rc = hol_cluster_cmp (entry1->cluster, entry2->cluster)) ? - rc : HOL_ENTRY_PTRCMP(entry1, entry2); - } - else if (group1 == group2) - /* The entries are both in the same cluster and group, so compare them - alphabetically. */ - { - int short1 = hol_entry_first_short (entry1); - int short2 = hol_entry_first_short (entry2); - int doc1 = odoc (entry1->opt); - int doc2 = odoc (entry2->opt); - const char *long1 = hol_entry_first_long (entry1); - const char *long2 = hol_entry_first_long (entry2); - - if (doc1) - doc1 = canon_doc_option (&long1); - if (doc2) - doc2 = canon_doc_option (&long2); - - if (doc1 != doc2) - /* `documentation' options always follow normal options (or - documentation options that *look* like normal options). */ - return doc1 - doc2; - else if (!short1 && !short2 && long1 && long2) - /* Only long options. */ - return (rc = __strcasecmp (long1, long2)) ? - rc : HOL_ENTRY_PTRCMP(entry1, entry2); - else - /* Compare short/short, long/short, short/long, using the first - character of long options. Entries without *any* valid - options (such as options with OPTION_HIDDEN set) will be put - first, but as they're not displayed, it doesn't matter where - they are. */ - { - char first1 = short1 ? short1 : long1 ? *long1 : 0; - char first2 = short2 ? short2 : long2 ? *long2 : 0; -#ifdef _tolower - int lower_cmp = _tolower (first1) - _tolower (first2); -#else - int lower_cmp = tolower (first1) - tolower (first2); -#endif - /* Compare ignoring case, except when the options are both the - same letter, in which case lower-case always comes first. */ - return lower_cmp ? lower_cmp : - (rc = first2 - first1) ? - rc : HOL_ENTRY_PTRCMP(entry1, entry2); - } - } - else - /* Within the same cluster, but not the same group, so just compare - groups. */ - return group_cmp (group1, group2, HOL_ENTRY_PTRCMP(entry1, entry2)); -} - -/* Version of hol_entry_cmp with correct signature for qsort. */ -static int -hol_entry_qcmp (const void *entry1_v, const void *entry2_v) -{ - return hol_entry_cmp (entry1_v, entry2_v); -} - -/* Sort HOL by group and alphabetically by option name (with short options - taking precedence over long). Since the sorting is for display purposes - only, the shadowing of options isn't effected. */ -static void -hol_sort (struct hol *hol) -{ - if (hol->num_entries > 0) - { - unsigned i; - struct hol_entry *e; - for (i = 0, e = hol->entries; i < hol->num_entries; i++, e++) - e->ord = i; - qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry), - hol_entry_qcmp); - } -} - -/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow - any in MORE with the same name. */ -static void -hol_append (struct hol *hol, struct hol *more) -{ - struct hol_cluster **cl_end = &hol->clusters; - - /* Steal MORE's cluster list, and add it to the end of HOL's. */ - while (*cl_end) - cl_end = &(*cl_end)->next; - *cl_end = more->clusters; - more->clusters = 0; - - /* Merge entries. */ - if (more->num_entries > 0) - { - if (hol->num_entries == 0) - { - hol->num_entries = more->num_entries; - hol->entries = more->entries; - hol->short_options = more->short_options; - more->num_entries = 0; /* Mark MORE's fields as invalid. */ - } - else - /* Append the entries in MORE to those in HOL, taking care to only add - non-shadowed SHORT_OPTIONS values. */ - { - unsigned left; - char *so, *more_so; - struct hol_entry *e; - unsigned num_entries = hol->num_entries + more->num_entries; - struct hol_entry *entries = - malloc (num_entries * sizeof (struct hol_entry)); - unsigned hol_so_len = strlen (hol->short_options); - char *short_options = - malloc (hol_so_len + strlen (more->short_options) + 1); - - assert (entries && short_options); - if (SIZE_MAX <= UINT_MAX) - assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry)); - - __mempcpy (__mempcpy (entries, hol->entries, - hol->num_entries * sizeof (struct hol_entry)), - more->entries, - more->num_entries * sizeof (struct hol_entry)); - - __mempcpy (short_options, hol->short_options, hol_so_len); - - /* Fix up the short options pointers from HOL. */ - for (e = entries, left = hol->num_entries; left > 0; e++, left--) - e->short_options += (short_options - hol->short_options); - - /* Now add the short options from MORE, fixing up its entries - too. */ - so = short_options + hol_so_len; - more_so = more->short_options; - for (left = more->num_entries; left > 0; e++, left--) - { - int opts_left; - const struct argp_option *opt; - - e->short_options = so; - - for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--) - { - int ch = *more_so; - if (oshort (opt) && ch == opt->key) - /* The next short option in MORE_SO, CH, is from OPT. */ - { - if (! find_char (ch, short_options, - short_options + hol_so_len)) - /* The short option CH isn't shadowed by HOL's options, - so add it to the sum. */ - *so++ = ch; - more_so++; - } - } - } - - *so = '\0'; - - free (hol->entries); - free (hol->short_options); - - hol->entries = entries; - hol->num_entries = num_entries; - hol->short_options = short_options; - } - } - - hol_free (more); -} - -/* Inserts enough spaces to make sure STREAM is at column COL. */ -static void -indent_to (argp_fmtstream_t stream, unsigned col) -{ - int needed = col - __argp_fmtstream_point (stream); - while (needed-- > 0) - __argp_fmtstream_putc (stream, ' '); -} - -/* Output to STREAM either a space, or a newline if there isn't room for at - least ENSURE characters before the right margin. */ -static void -space (argp_fmtstream_t stream, size_t ensure) -{ - if (__argp_fmtstream_point (stream) + ensure - >= __argp_fmtstream_rmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - else - __argp_fmtstream_putc (stream, ' '); -} - -/* If the option REAL has an argument, we print it in using the printf - format REQ_FMT or OPT_FMT depending on whether it's a required or - optional argument. */ -static void -arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt, - const char *domain, argp_fmtstream_t stream) -{ - if (real->arg) - { - if (real->flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, opt_fmt, - dgettext (domain, real->arg)); - else - __argp_fmtstream_printf (stream, req_fmt, - dgettext (domain, real->arg)); - } -} - -/* Helper functions for hol_entry_help. */ - -/* State used during the execution of hol_help. */ -struct hol_help_state -{ - /* PREV_ENTRY should contain the previous entry printed, or 0. */ - struct hol_entry *prev_entry; - - /* If an entry is in a different group from the previous one, and SEP_GROUPS - is true, then a blank line will be printed before any output. */ - int sep_groups; - - /* True if a duplicate option argument was suppressed (only ever set if - UPARAMS.dup_args is false). */ - int suppressed_dup_arg; -}; - -/* Some state used while printing a help entry (used to communicate with - helper functions). See the doc for hol_entry_help for more info, as most - of the fields are copied from its arguments. */ -struct pentry_state -{ - const struct hol_entry *entry; - argp_fmtstream_t stream; - struct hol_help_state *hhstate; - - /* True if nothing's been printed so far. */ - int first; - - /* If non-zero, the state that was used to print this help. */ - const struct argp_state *state; -}; - -/* If a user doc filter should be applied to DOC, do so. */ -static const char * -filter_doc (const char *doc, int key, const struct argp *argp, - const struct argp_state *state) -{ - if (argp->help_filter) - /* We must apply a user filter to this output. */ - { - void *input = __argp_input (argp, state); - return (*argp->help_filter) (key, doc, input); - } - else - /* No filter. */ - return doc; -} - -/* Prints STR as a header line, with the margin lines set appropiately, and - notes the fact that groups should be separated with a blank line. ARGP is - the argp that should dictate any user doc filtering to take place. Note - that the previous wrap margin isn't restored, but the left margin is reset - to 0. */ -static void -print_header (const char *str, const struct argp *argp, - struct pentry_state *pest) -{ - const char *tstr = dgettext (argp->argp_domain, str); - const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); - - if (fstr) - { - if (*fstr) - { - if (pest->hhstate->prev_entry) - /* Precede with a blank line. */ - __argp_fmtstream_putc (pest->stream, '\n'); - indent_to (pest->stream, uparams.header_col); - __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col); - __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col); - __argp_fmtstream_puts (pest->stream, fstr); - __argp_fmtstream_set_lmargin (pest->stream, 0); - __argp_fmtstream_putc (pest->stream, '\n'); - } - - pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */ - } - - if (fstr != tstr) - free ((char *) fstr); -} - -/* Inserts a comma if this isn't the first item on the line, and then makes - sure we're at least to column COL. If this *is* the first item on a line, - prints any pending whitespace/headers that should precede this line. Also - clears FIRST. */ -static void -comma (unsigned col, struct pentry_state *pest) -{ - if (pest->first) - { - const struct hol_entry *pe = pest->hhstate->prev_entry; - const struct hol_cluster *cl = pest->entry->cluster; - - if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group) - __argp_fmtstream_putc (pest->stream, '\n'); - - if (cl && cl->header && *cl->header - && (!pe - || (pe->cluster != cl - && !hol_cluster_is_child (pe->cluster, cl)))) - /* If we're changing clusters, then this must be the start of the - ENTRY's cluster unless that is an ancestor of the previous one - (in which case we had just popped into a sub-cluster for a bit). - If so, then print the cluster's header line. */ - { - int old_wm = __argp_fmtstream_wmargin (pest->stream); - print_header (cl->header, cl->argp, pest); - __argp_fmtstream_set_wmargin (pest->stream, old_wm); - } - - pest->first = 0; - } - else - __argp_fmtstream_puts (pest->stream, ", "); - - indent_to (pest->stream, col); -} - -/* Print help for ENTRY to STREAM. */ -static void -hol_entry_help (struct hol_entry *entry, const struct argp_state *state, - argp_fmtstream_t stream, struct hol_help_state *hhstate) -{ - unsigned num; - const struct argp_option *real = entry->opt, *opt; - char *so = entry->short_options; - int have_long_opt = 0; /* We have any long options. */ - /* Saved margins. */ - int old_lm = __argp_fmtstream_set_lmargin (stream, 0); - int old_wm = __argp_fmtstream_wmargin (stream); - /* PEST is a state block holding some of our variables that we'd like to - share with helper functions. */ - struct pentry_state pest; - - pest.entry = entry; - pest.stream = stream; - pest.hhstate = hhstate; - pest.first = 1; - pest.state = state; - - if (! odoc (real)) - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - have_long_opt = 1; - break; - } - - /* First emit short options. */ - __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */ - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (oshort (opt) && opt->key == *so) - /* OPT has a valid (non shadowed) short option. */ - { - if (ovisible (opt)) - { - comma (uparams.short_opt_col, &pest); - __argp_fmtstream_putc (stream, '-'); - __argp_fmtstream_putc (stream, *so); - if (!have_long_opt || uparams.dup_args) - arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - so++; - } - - /* Now, long options. */ - if (odoc (real)) - /* A `documentation' option. */ - { - __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col); - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && *opt->name && ovisible (opt)) - { - comma (uparams.doc_opt_col, &pest); - /* Calling dgettext here isn't quite right, since sorting will - have been done on the original; but documentation options - should be pretty rare anyway... */ - __argp_fmtstream_puts (stream, - onotrans (opt) ? - opt->name : - dgettext (state->root_argp->argp_domain, - opt->name)); - } - } - else - /* A real long option. */ - { - int first_long_opt = 1; - - __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col); - for (opt = real, num = entry->num; num > 0; opt++, num--) - if (opt->name && ovisible (opt)) - { - comma (uparams.long_opt_col, &pest); - __argp_fmtstream_printf (stream, "--%s", opt->name); - if (first_long_opt || uparams.dup_args) - arg (real, "=%s", "[=%s]", state->root_argp->argp_domain, - stream); - else if (real->arg) - hhstate->suppressed_dup_arg = 1; - } - } - - /* Next, documentation strings. */ - __argp_fmtstream_set_lmargin (stream, 0); - - if (pest.first) - { - /* Didn't print any switches, what's up? */ - if (!oshort (real) && !real->name) - /* This is a group header, print it nicely. */ - print_header (real->doc, entry->argp, &pest); - else - /* Just a totally shadowed option or null header; print nothing. */ - goto cleanup; /* Just return, after cleaning up. */ - } - else - { - const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain, - real->doc) : 0; - const char *fstr = filter_doc (tstr, real->key, entry->argp, state); - if (fstr && *fstr) - { - unsigned int col = __argp_fmtstream_point (stream); - - __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col); - __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col); - - if (col > (unsigned int) (uparams.opt_doc_col + 3)) - __argp_fmtstream_putc (stream, '\n'); - else if (col >= (unsigned int) uparams.opt_doc_col) - __argp_fmtstream_puts (stream, " "); - else - indent_to (stream, uparams.opt_doc_col); - - __argp_fmtstream_puts (stream, fstr); - } - if (fstr && fstr != tstr) - free ((char *) fstr); - - /* Reset the left margin. */ - __argp_fmtstream_set_lmargin (stream, 0); - __argp_fmtstream_putc (stream, '\n'); - } - - hhstate->prev_entry = entry; - -cleanup: - __argp_fmtstream_set_lmargin (stream, old_lm); - __argp_fmtstream_set_wmargin (stream, old_wm); -} - -/* Output a long help message about the options in HOL to STREAM. */ -static void -hol_help (struct hol *hol, const struct argp_state *state, - argp_fmtstream_t stream) -{ - unsigned num; - struct hol_entry *entry; - struct hol_help_state hhstate = { 0, 0, 0 }; - - for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--) - hol_entry_help (entry, state, stream, &hhstate); - - if (hhstate.suppressed_dup_arg && uparams.dup_args_note) - { - const char *tstr = dgettext (state->root_argp->argp_domain, "\ -Mandatory or optional arguments to long options are also mandatory or \ -optional for any corresponding short options."); - const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE, - state ? state->root_argp : 0, state); - if (fstr && *fstr) - { - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, fstr); - __argp_fmtstream_putc (stream, '\n'); - } - if (fstr && fstr != tstr) - free ((char *) fstr); - } -} - -/* Helper functions for hol_usage. */ - -/* If OPT is a short option without an arg, append its key to the string - pointer pointer to by COOKIE, and advance the pointer. */ -static int -add_argless_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) -{ - char **snao_end = cookie; - if (!(opt->arg || real->arg) - && !((opt->flags | real->flags) & OPTION_NO_USAGE)) - *(*snao_end)++ = opt->key; - return 0; -} - -/* If OPT is a short option with an arg, output a usage entry for it to the - stream pointed at by COOKIE. */ -static int -usage_argful_short_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) -{ - argp_fmtstream_t stream = cookie; - const char *arg = opt->arg; - int flags = opt->flags | real->flags; - - if (! arg) - arg = real->arg; - - if (arg && !(flags & OPTION_NO_USAGE)) - { - arg = dgettext (domain, arg); - - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); - else - { - /* Manually do line wrapping so that it (probably) won't - get wrapped at the embedded space. */ - space (stream, 6 + strlen (arg)); - __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg); - } - } - - return 0; -} - -/* Output a usage entry for the long option opt to the stream pointed at by - COOKIE. */ -static int -usage_long_opt (const struct argp_option *opt, - const struct argp_option *real, - const char *domain, void *cookie) -{ - argp_fmtstream_t stream = cookie; - const char *arg = opt->arg; - int flags = opt->flags | real->flags; - - if (! arg) - arg = real->arg; - - if (! (flags & OPTION_NO_USAGE) && !odoc (opt)) - { - if (arg) - { - arg = dgettext (domain, arg); - if (flags & OPTION_ARG_OPTIONAL) - __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); - else - __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg); - } - else - __argp_fmtstream_printf (stream, " [--%s]", opt->name); - } - - return 0; -} - -/* Print a short usage description for the arguments in HOL to STREAM. */ -static void -hol_usage (struct hol *hol, argp_fmtstream_t stream) -{ - if (hol->num_entries > 0) - { - unsigned nentries; - struct hol_entry *entry; - char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1); - char *snao_end = short_no_arg_opts; - - /* First we put a list of short options without arguments. */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, add_argless_short_opt, - entry->argp->argp_domain, &snao_end); - if (snao_end > short_no_arg_opts) - { - *snao_end++ = 0; - __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts); - } - - /* Now a list of short options *with* arguments. */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_short_iterate (entry, usage_argful_short_opt, - entry->argp->argp_domain, stream); - - /* Finally, a list of long options (whew!). */ - for (entry = hol->entries, nentries = hol->num_entries - ; nentries > 0 - ; entry++, nentries--) - hol_entry_long_iterate (entry, usage_long_opt, - entry->argp->argp_domain, stream); - } -} - -/* Make a HOL containing all levels of options in ARGP. CLUSTER is the - cluster in which ARGP's entries should be clustered, or 0. */ -static struct hol * -argp_hol (const struct argp *argp, struct hol_cluster *cluster) -{ - const struct argp_child *child = argp->children; - struct hol *hol = make_hol (argp, cluster); - if (child) - while (child->argp) - { - struct hol_cluster *child_cluster = - ((child->group || child->header) - /* Put CHILD->argp within its own cluster. */ - ? hol_add_cluster (hol, child->group, child->header, - child - argp->children, cluster, argp) - /* Just merge it into the parent's cluster. */ - : cluster); - hol_append (hol, argp_hol (child->argp, child_cluster)) ; - child++; - } - return hol; -} - -/* Calculate how many different levels with alternative args strings exist in - ARGP. */ -static size_t -argp_args_levels (const struct argp *argp) -{ - size_t levels = 0; - const struct argp_child *child = argp->children; - - if (argp->args_doc && strchr (argp->args_doc, '\n')) - levels++; - - if (child) - while (child->argp) - levels += argp_args_levels ((child++)->argp); - - return levels; -} - -/* Print all the non-option args documented in ARGP to STREAM. Any output is - preceded by a space. LEVELS is a pointer to a byte vector the length - returned by argp_args_levels; it should be initialized to zero, and - updated by this routine for the next call if ADVANCE is true. True is - returned as long as there are more patterns to output. */ -static int -argp_args_usage (const struct argp *argp, const struct argp_state *state, - char **levels, int advance, argp_fmtstream_t stream) -{ - char *our_level = *levels; - int multiple = 0; - const struct argp_child *child = argp->children; - const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0; - const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state); - - if (fdoc) - { - const char *cp = fdoc; - nl = __strchrnul (cp, '\n'); - if (*nl != '\0') - /* This is a `multi-level' args doc; advance to the correct position - as determined by our state in LEVELS, and update LEVELS. */ - { - int i; - multiple = 1; - for (i = 0; i < *our_level; i++) - cp = nl + 1, nl = __strchrnul (cp, '\n'); - (*levels)++; - } - - /* Manually do line wrapping so that it (probably) won't get wrapped at - any embedded spaces. */ - space (stream, 1 + nl - cp); - - __argp_fmtstream_write (stream, cp, nl - cp); - } - if (fdoc && fdoc != tdoc) - free ((char *)fdoc); /* Free user's modified doc string. */ - - if (child) - while (child->argp) - advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream); - - if (advance && multiple) - { - /* Need to increment our level. */ - if (*nl) - /* There's more we can do here. */ - { - (*our_level)++; - advance = 0; /* Our parent shouldn't advance also. */ - } - else if (*our_level > 0) - /* We had multiple levels, but used them up; reset to zero. */ - *our_level = 0; - } - - return !advance; -} - -/* Print the documentation for ARGP to STREAM; if POST is false, then - everything preceeding a `\v' character in the documentation strings (or - the whole string, for those with none) is printed, otherwise, everything - following the `\v' character (nothing for strings without). Each separate - bit of documentation is separated a blank line, and if PRE_BLANK is true, - then the first is as well. If FIRST_ONLY is true, only the first - occurrence is output. Returns true if anything was output. */ -static int -argp_doc (const struct argp *argp, const struct argp_state *state, - int post, int pre_blank, int first_only, - argp_fmtstream_t stream) -{ - const char *text; - const char *inp_text; - size_t inp_text_len = 0; - const char *trans_text; - void *input = 0; - int anything = 0; - const struct argp_child *child = argp->children; - - if (argp->doc) - { - char *vt = strchr (argp->doc, '\v'); - if (vt) - { - if (post) - inp_text = vt + 1; - else - { - inp_text_len = vt - argp->doc; - inp_text = __strndup (argp->doc, inp_text_len); - } - } - else - inp_text = post ? 0 : argp->doc; - trans_text = inp_text ? dgettext (argp->argp_domain, inp_text) : NULL; - } - else - trans_text = inp_text = 0; - - if (argp->help_filter) - /* We have to filter the doc strings. */ - { - input = __argp_input (argp, state); - text = - (*argp->help_filter) (post - ? ARGP_KEY_HELP_POST_DOC - : ARGP_KEY_HELP_PRE_DOC, - trans_text, input); - } - else - text = (const char *) trans_text; - - if (text) - { - if (pre_blank) - __argp_fmtstream_putc (stream, '\n'); - - __argp_fmtstream_puts (stream, text); - - if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - - anything = 1; - } - - if (text && text != trans_text) - free ((char *) text); /* Free TEXT returned from the help filter. */ - - if (inp_text && inp_text_len) - free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */ - - if (post && argp->help_filter) - /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */ - { - text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input); - if (text) - { - if (anything || pre_blank) - __argp_fmtstream_putc (stream, '\n'); - __argp_fmtstream_puts (stream, text); - free ((char *) text); - if (__argp_fmtstream_point (stream) - > __argp_fmtstream_lmargin (stream)) - __argp_fmtstream_putc (stream, '\n'); - anything = 1; - } - } - - if (child) - while (child->argp && !(first_only && anything)) - anything |= - argp_doc ((child++)->argp, state, - post, anything || pre_blank, first_only, - stream); - - return anything; -} - -/* Output a usage message for ARGP to STREAM. If called from - argp_state_help, STATE is the relevent parsing state. FLAGS are from the - set ARGP_HELP_*. NAME is what to use wherever a `program name' is - needed. */ -static void -_help (const struct argp *argp, const struct argp_state *state, FILE *stream, - unsigned flags, char *name) -{ - int anything = 0; /* Whether we've output anything. */ - struct hol *hol = 0; - argp_fmtstream_t fs; - - if (! stream) - return; - -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __flockfile (stream); -#endif - - if (! uparams.valid) - fill_in_uparams (state); - - fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0); - if (! fs) - { -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __funlockfile (stream); -#endif - return; - } - - if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG)) - { - hol = argp_hol (argp, 0); - - /* If present, these options always come last. */ - hol_set_group (hol, "help", -1); - hol_set_group (hol, "version", -1); - - hol_sort (hol); - } - - if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE)) - /* Print a short `Usage:' message. */ - { - int first_pattern = 1, more_patterns; - size_t num_pattern_levels = argp_args_levels (argp); - char *pattern_levels = alloca (num_pattern_levels); - - memset (pattern_levels, 0, num_pattern_levels); - - do - { - int old_lm; - int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); - char *levels = pattern_levels; - - if (first_pattern) - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, "Usage:"), - name); - else - __argp_fmtstream_printf (fs, "%s %s", - dgettext (argp->argp_domain, " or: "), - name); - - /* We set the lmargin as well as the wmargin, because hol_usage - manually wraps options with newline to avoid annoying breaks. */ - old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent); - - if (flags & ARGP_HELP_SHORT_USAGE) - /* Just show where the options go. */ - { - if (hol->num_entries > 0) - __argp_fmtstream_puts (fs, dgettext (argp->argp_domain, - " [OPTION...]")); - } - else - /* Actually print the options. */ - { - hol_usage (hol, fs); - flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */ - } - - more_patterns = argp_args_usage (argp, state, &levels, 1, fs); - - __argp_fmtstream_set_wmargin (fs, old_wm); - __argp_fmtstream_set_lmargin (fs, old_lm); - - __argp_fmtstream_putc (fs, '\n'); - anything = 1; - - first_pattern = 0; - } - while (more_patterns); - } - - if (flags & ARGP_HELP_PRE_DOC) - anything |= argp_doc (argp, state, 0, 0, 1, fs); - - if (flags & ARGP_HELP_SEE) - { - __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\ -Try `%s --help' or `%s --usage' for more information.\n"), - name, name); - anything = 1; - } - - if (flags & ARGP_HELP_LONG) - /* Print a long, detailed help message. */ - { - /* Print info about all the options. */ - if (hol->num_entries > 0) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - hol_help (hol, state, fs); - anything = 1; - } - } - - if (flags & ARGP_HELP_POST_DOC) - /* Print any documentation strings at the end. */ - anything |= argp_doc (argp, state, 1, anything, 0, fs); - - if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address) - { - if (anything) - __argp_fmtstream_putc (fs, '\n'); - __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, - "Report bugs to %s.\n"), - argp_program_bug_address); - anything = 1; - } - -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __funlockfile (stream); -#endif - - if (hol) - hol_free (hol); - - __argp_fmtstream_free (fs); -} - -/* Output a usage message for ARGP to STREAM. FLAGS are from the set - ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */ -void __argp_help (const struct argp *argp, FILE *stream, - unsigned flags, char *name) -{ - struct argp_state state; - memset (&state, 0, sizeof state); - state.root_argp = argp; - _help (argp, &state, stream, flags, name); -} -#ifdef weak_alias -weak_alias (__argp_help, argp_help) -#endif - -#if ! (defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) -char * -__argp_short_program_name (void) -{ -# if HAVE_DECL_PROGRAM_INVOCATION_NAME - return __argp_base_name (program_invocation_name); -# else - /* FIXME: What now? Miles suggests that it is better to use NULL, - but currently the value is passed on directly to fputs_unlocked, - so that requires more changes. */ -# if __GNUC__ -# warning No reasonable value to return -# endif /* __GNUC__ */ - return ""; -# endif -} -#endif - -/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are - from the set ARGP_HELP_*. */ -void -__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags) -{ - if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream) - { - if (state && (state->flags & ARGP_LONG_ONLY)) - flags |= ARGP_HELP_LONG_ONLY; - - _help (state ? state->root_argp : 0, state, stream, flags, - state ? state->name : __argp_short_program_name ()); - - if (!state || ! (state->flags & ARGP_NO_EXIT)) - { - if (flags & ARGP_HELP_EXIT_ERR) - exit (argp_err_exit_status); - if (flags & ARGP_HELP_EXIT_OK) - exit (0); - } - } -} -#ifdef weak_alias -weak_alias (__argp_state_help, argp_state_help) -#endif - -/* If appropriate, print the printf string FMT and following args, preceded - by the program name and `:', to stderr, and followed by a `Try ... --help' - message, then exit (1). */ -void -__argp_error (const struct argp_state *state, const char *fmt, ...) -{ - if (!state || !(state->flags & ARGP_NO_ERRS)) - { - FILE *stream = state ? state->err_stream : stderr; - - if (stream) - { - va_list ap; - -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __flockfile (stream); -#endif - - va_start (ap, fmt); - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - { - char *buf; - - if (__asprintf (&buf, fmt, ap) < 0) - buf = NULL; - - __fwprintf (stream, L"%s: %s\n", - state ? state->name : __argp_short_program_name (), - buf); - - free (buf); - } - else -#endif - { - fputs_unlocked (state - ? state->name : __argp_short_program_name (), - stream); - putc_unlocked (':', stream); - putc_unlocked (' ', stream); - - vfprintf (stream, fmt, ap); - - putc_unlocked ('\n', stream); - } - - __argp_state_help (state, stream, ARGP_HELP_STD_ERR); - - va_end (ap); - -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __funlockfile (stream); -#endif - } - } -} -#ifdef weak_alias -weak_alias (__argp_error, argp_error) -#endif - -/* Similar to the standard gnu error-reporting function error(), but will - respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print - to STATE->err_stream. This is useful for argument parsing code that is - shared between program startup (when exiting is desired) and runtime - option parsing (when typically an error code is returned instead). The - difference between this function and argp_error is that the latter is for - *parsing errors*, and the former is for other problems that occur during - parsing but don't reflect a (syntactic) problem with the input. */ -void -__argp_failure (const struct argp_state *state, int status, int errnum, - const char *fmt, ...) -{ - if (!state || !(state->flags & ARGP_NO_ERRS)) - { - FILE *stream = state ? state->err_stream : stderr; - - if (stream) - { -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __flockfile (stream); -#endif - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - __fwprintf (stream, L"%s", - state ? state->name : __argp_short_program_name ()); - else -#endif - fputs_unlocked (state - ? state->name : __argp_short_program_name (), - stream); - - if (fmt) - { - va_list ap; - - va_start (ap, fmt); -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - { - char *buf; - - if (__asprintf (&buf, fmt, ap) < 0) - buf = NULL; - - __fwprintf (stream, L": %s", buf); - - free (buf); - } - else -#endif - { - putc_unlocked (':', stream); - putc_unlocked (' ', stream); - - vfprintf (stream, fmt, ap); - } - - va_end (ap); - } - - if (errnum) - { - char buf[200]; - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - __fwprintf (stream, L": %s", - __strerror_r (errnum, buf, sizeof (buf))); - else -#endif - { - char const *s = NULL; - putc_unlocked (':', stream); - putc_unlocked (' ', stream); -#if _LIBC || (HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P) - s = __strerror_r (errnum, buf, sizeof buf); -#elif HAVE_DECL_STRERROR_R - if (__strerror_r (errnum, buf, sizeof buf) == 0) - s = buf; -#endif -#if !_LIBC - if (! s && ! (s = strerror (errnum))) - s = dgettext (state->root_argp->argp_domain, - "Unknown system error"); -#endif - fputs (s, stream); - } - } - -#ifdef USE_IN_LIBIO - if (_IO_fwide (stream, 0) > 0) - putwc_unlocked (L'\n', stream); - else -#endif - putc_unlocked ('\n', stream); - -#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) - __funlockfile (stream); -#endif - - if (status && (!state || !(state->flags & ARGP_NO_EXIT))) - exit (status); - } - } -} -#ifdef weak_alias -weak_alias (__argp_failure, argp_failure) -#endif diff --git a/lib/argp-namefrob.h b/lib/argp-namefrob.h deleted file mode 100644 index 6fe99cd..0000000 --- a/lib/argp-namefrob.h +++ /dev/null @@ -1,158 +0,0 @@ -/* Name frobnication for compiling argp outside of glibc - Copyright (C) 1997, 2003, 2007 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#if !_LIBC -/* This code is written for inclusion in gnu-libc, and uses names in the - namespace reserved for libc. If we're not compiling in libc, define those - names to be the normal ones instead. */ - -/* argp-parse functions */ -#undef __argp_parse -#define __argp_parse argp_parse -#undef __option_is_end -#define __option_is_end _option_is_end -#undef __option_is_short -#define __option_is_short _option_is_short -#undef __argp_input -#define __argp_input _argp_input - -/* argp-help functions */ -#undef __argp_help -#define __argp_help argp_help -#undef __argp_error -#define __argp_error argp_error -#undef __argp_failure -#define __argp_failure argp_failure -#undef __argp_state_help -#define __argp_state_help argp_state_help -#undef __argp_usage -#define __argp_usage argp_usage - -/* argp-fmtstream functions */ -#undef __argp_make_fmtstream -#define __argp_make_fmtstream argp_make_fmtstream -#undef __argp_fmtstream_free -#define __argp_fmtstream_free argp_fmtstream_free -#undef __argp_fmtstream_putc -#define __argp_fmtstream_putc argp_fmtstream_putc -#undef __argp_fmtstream_puts -#define __argp_fmtstream_puts argp_fmtstream_puts -#undef __argp_fmtstream_write -#define __argp_fmtstream_write argp_fmtstream_write -#undef __argp_fmtstream_printf -#define __argp_fmtstream_printf argp_fmtstream_printf -#undef __argp_fmtstream_set_lmargin -#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin -#undef __argp_fmtstream_set_rmargin -#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin -#undef __argp_fmtstream_set_wmargin -#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin -#undef __argp_fmtstream_point -#define __argp_fmtstream_point argp_fmtstream_point -#undef __argp_fmtstream_update -#define __argp_fmtstream_update _argp_fmtstream_update -#undef __argp_fmtstream_ensure -#define __argp_fmtstream_ensure _argp_fmtstream_ensure -#undef __argp_fmtstream_lmargin -#define __argp_fmtstream_lmargin argp_fmtstream_lmargin -#undef __argp_fmtstream_rmargin -#define __argp_fmtstream_rmargin argp_fmtstream_rmargin -#undef __argp_fmtstream_wmargin -#define __argp_fmtstream_wmargin argp_fmtstream_wmargin - -/* normal libc functions we call */ -#undef __flockfile -#define __flockfile flockfile -#undef __funlockfile -#define __funlockfile funlockfile -#undef __mempcpy -#define __mempcpy mempcpy -#undef __sleep -#define __sleep sleep -#undef __strcasecmp -#define __strcasecmp strcasecmp -#undef __strchrnul -#define __strchrnul strchrnul -#undef __strerror_r -#define __strerror_r strerror_r -#undef __strndup -#define __strndup strndup -#undef __vsnprintf -#define __vsnprintf vsnprintf - -#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED -# define clearerr_unlocked(x) clearerr (x) -#endif -#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED -# define feof_unlocked(x) feof (x) -# endif -#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED -# define ferror_unlocked(x) ferror (x) -# endif -#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED -# define fflush_unlocked(x) fflush (x) -# endif -#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED -# define fgets_unlocked(x,y,z) fgets (x,y,z) -# endif -#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED -# define fputc_unlocked(x,y) fputc (x,y) -# endif -#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED -# define fputs_unlocked(x,y) fputs (x,y) -# endif -#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED -# define fread_unlocked(w,x,y,z) fread (w,x,y,z) -# endif -#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED -# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) -# endif -#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED -# define getc_unlocked(x) getc (x) -# endif -#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED -# define getchar_unlocked() getchar () -# endif -#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED -# define putc_unlocked(x,y) putc (x,y) -# endif -#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED -# define putchar_unlocked(x) putchar (x) -# endif - -#endif /* !_LIBC */ - -#ifndef __set_errno -#define __set_errno(e) (errno = (e)) -#endif - -#if defined GNULIB_ARGP_DISABLE_DIRNAME -# define __argp_base_name(arg) arg -#elif defined GNULIB_ARGP_EXTERN_BASENAME -extern char *__argp_base_name(const char *arg); -#else -# include "dirname.h" -# define __argp_base_name base_name -#endif - -#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME -# define __argp_short_program_name() (program_invocation_short_name) -#else -extern char *__argp_short_program_name (void); -#endif diff --git a/lib/argp-parse.c b/lib/argp-parse.c deleted file mode 100644 index a7de729..0000000 --- a/lib/argp-parse.c +++ /dev/null @@ -1,953 +0,0 @@ -/* Hierarchial argument parsing, layered over getopt - Copyright (C) 1995-2000, 2002, 2003, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _LIBC -# include -# undef dgettext -# define dgettext(domain, msgid) \ - INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES) -#else -# include "gettext.h" -#endif -#define N_(msgid) msgid - -#include "argp.h" -#include "argp-namefrob.h" - -#define alignof(type) offsetof (struct { char c; type x; }, x) -#define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d)) - -/* Getopt return values. */ -#define KEY_END (-1) /* The end of the options. */ -#define KEY_ARG 1 /* A non-option argument. */ -#define KEY_ERR '?' /* An error parsing the options. */ - -/* The meta-argument used to prevent any further arguments being interpreted - as options. */ -#define QUOTE "--" - -/* The number of bits we steal in a long-option value for our own use. */ -#define GROUP_BITS CHAR_BIT - -/* The number of bits available for the user value. */ -#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS) -#define USER_MASK ((1 << USER_BITS) - 1) - -/* EZ alias for ARGP_ERR_UNKNOWN. */ -#define EBADKEY ARGP_ERR_UNKNOWN - -/* Default options. */ - -/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep - for one second intervals, decrementing _ARGP_HANG until it's zero. Thus - you can force the program to continue by attaching a debugger and setting - it to 0 yourself. */ -static volatile int _argp_hang; - -#define OPT_PROGNAME -2 -#define OPT_USAGE -3 -#define OPT_HANG -4 - -static const struct argp_option argp_default_options[] = -{ - {"help", '?', 0, 0, N_("give this help list"), -1}, - {"usage", OPT_USAGE, 0, 0, N_("give a short usage message"), 0}, - {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0}, - {"HANG", OPT_HANG, N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN, - N_("hang for SECS seconds (default 3600)"), 0}, - {NULL, 0, 0, 0, NULL, 0} -}; - -static error_t -argp_default_parser (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case '?': - __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP); - break; - case OPT_USAGE: - __argp_state_help (state, state->out_stream, - ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); - break; - - case OPT_PROGNAME: /* Set the program name. */ -#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME - program_invocation_name = arg; -#endif - /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka - __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined - to be that, so we have to be a bit careful here.] */ - - /* Update what we use for messages. */ - state->name = __argp_base_name (arg); - -#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME - program_invocation_short_name = state->name; -#endif - - if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS)) - == ARGP_PARSE_ARGV0) - /* Update what getopt uses too. */ - state->argv[0] = arg; - - break; - - case OPT_HANG: - _argp_hang = atoi (arg ? arg : "3600"); - while (_argp_hang-- > 0) - __sleep (1); - break; - - default: - return EBADKEY; - } - return 0; -} - -static const struct argp argp_default_argp = - {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"}; - - -static const struct argp_option argp_version_options[] = -{ - {"version", 'V', 0, 0, N_("print program version"), -1}, - {NULL, 0, 0, 0, NULL, 0} -}; - -static error_t -argp_version_parser (int key, char *arg, struct argp_state *state) -{ - switch (key) - { - case 'V': - if (argp_program_version_hook) - (*argp_program_version_hook) (state->out_stream, state); - else if (argp_program_version) - fprintf (state->out_stream, "%s\n", argp_program_version); - else - __argp_error (state, dgettext (state->root_argp->argp_domain, - "(PROGRAM ERROR) No version known!?")); - if (! (state->flags & ARGP_NO_EXIT)) - exit (0); - break; - default: - return EBADKEY; - } - return 0; -} - -static const struct argp argp_version_argp = - {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"}; - -/* Returns the offset into the getopt long options array LONG_OPTIONS of a - long option with called NAME, or -1 if none is found. Passing NULL as - NAME will return the number of options. */ -static int -find_long_option (struct option *long_options, const char *name) -{ - struct option *l = long_options; - while (l->name != NULL) - if (name != NULL && strcmp (l->name, name) == 0) - return l - long_options; - else - l++; - if (name == NULL) - return l - long_options; - else - return -1; -} - - -/* The state of a `group' during parsing. Each group corresponds to a - particular argp structure from the tree of such descending from the top - level argp passed to argp_parse. */ -struct group -{ - /* This group's parsing function. */ - argp_parser_t parser; - - /* Which argp this group is from. */ - const struct argp *argp; - - /* Points to the point in SHORT_OPTS corresponding to the end of the short - options for this group. We use it to determine from which group a - particular short options is from. */ - char *short_end; - - /* The number of non-option args sucessfully handled by this parser. */ - unsigned args_processed; - - /* This group's parser's parent's group. */ - struct group *parent; - unsigned parent_index; /* And the our position in the parent. */ - - /* These fields are swapped into and out of the state structure when - calling this group's parser. */ - void *input, **child_inputs; - void *hook; -}; - -/* Call GROUP's parser with KEY and ARG, swapping any group-specific info - from STATE before calling, and back into state afterwards. If GROUP has - no parser, EBADKEY is returned. */ -static error_t -group_parse (struct group *group, struct argp_state *state, int key, char *arg) -{ - if (group->parser) - { - error_t err; - state->hook = group->hook; - state->input = group->input; - state->child_inputs = group->child_inputs; - state->arg_num = group->args_processed; - err = (*group->parser)(key, arg, state); - group->hook = state->hook; - return err; - } - else - return EBADKEY; -} - -struct parser -{ - const struct argp *argp; - - /* SHORT_OPTS is the getopt short options string for the union of all the - groups of options. */ - char *short_opts; - /* LONG_OPTS is the array of getop long option structures for the union of - all the groups of options. */ - struct option *long_opts; - /* OPT_DATA is the getopt data used for the re-entrant getopt. */ - struct _getopt_data opt_data; - - /* States of the various parsing groups. */ - struct group *groups; - /* The end of the GROUPS array. */ - struct group *egroup; - /* An vector containing storage for the CHILD_INPUTS field in all groups. */ - void **child_inputs; - - /* True if we think using getopt is still useful; if false, then - remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is - cleared whenever getopt returns KEY_END, but may be set again if the user - moves the next argument pointer backwards. */ - int try_getopt; - - /* State block supplied to parsing routines. */ - struct argp_state state; - - /* Memory used by this parser. */ - void *storage; -}; - -/* The next usable entries in the various parser tables being filled in by - convert_options. */ -struct parser_convert_state -{ - struct parser *parser; - char *short_end; - struct option *long_end; - void **child_inputs_end; -}; - -/* Converts all options in ARGP (which is put in GROUP) and ancestors - into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and - CVT->LONG_END are the points at which new options are added. Returns the - next unused group entry. CVT holds state used during the conversion. */ -static struct group * -convert_options (const struct argp *argp, - struct group *parent, unsigned parent_index, - struct group *group, struct parser_convert_state *cvt) -{ - /* REAL is the most recent non-alias value of OPT. */ - const struct argp_option *real = argp->options; - const struct argp_child *children = argp->children; - - if (real || argp->parser) - { - const struct argp_option *opt; - - if (real) - for (opt = real; !__option_is_end (opt); opt++) - { - if (! (opt->flags & OPTION_ALIAS)) - /* OPT isn't an alias, so we can use values from it. */ - real = opt; - - if (! (real->flags & OPTION_DOC)) - /* A real option (not just documentation). */ - { - if (__option_is_short (opt)) - /* OPT can be used as a short option. */ - { - *cvt->short_end++ = opt->key; - if (real->arg) - { - *cvt->short_end++ = ':'; - if (real->flags & OPTION_ARG_OPTIONAL) - *cvt->short_end++ = ':'; - } - *cvt->short_end = '\0'; /* keep 0 terminated */ - } - - if (opt->name - && find_long_option (cvt->parser->long_opts, opt->name) < 0) - /* OPT can be used as a long option. */ - { - cvt->long_end->name = opt->name; - cvt->long_end->has_arg = - (real->arg - ? (real->flags & OPTION_ARG_OPTIONAL - ? optional_argument - : required_argument) - : no_argument); - cvt->long_end->flag = 0; - /* we add a disambiguating code to all the user's - values (which is removed before we actually call - the function to parse the value); this means that - the user loses use of the high 8 bits in all his - values (the sign of the lower bits is preserved - however)... */ - cvt->long_end->val = - ((opt->key | real->key) & USER_MASK) - + (((group - cvt->parser->groups) + 1) << USER_BITS); - - /* Keep the LONG_OPTS list terminated. */ - (++cvt->long_end)->name = NULL; - } - } - } - - group->parser = argp->parser; - group->argp = argp; - group->short_end = cvt->short_end; - group->args_processed = 0; - group->parent = parent; - group->parent_index = parent_index; - group->input = 0; - group->hook = 0; - group->child_inputs = 0; - - if (children) - /* Assign GROUP's CHILD_INPUTS field some space from - CVT->child_inputs_end.*/ - { - unsigned num_children = 0; - while (children[num_children].argp) - num_children++; - group->child_inputs = cvt->child_inputs_end; - cvt->child_inputs_end += num_children; - } - - parent = group++; - } - else - parent = 0; - - if (children) - { - unsigned index = 0; - while (children->argp) - group = - convert_options (children++->argp, parent, index++, group, cvt); - } - - return group; -} - -/* Find the merged set of getopt options, with keys appropiately prefixed. */ -static void -parser_convert (struct parser *parser, const struct argp *argp, int flags) -{ - struct parser_convert_state cvt; - - cvt.parser = parser; - cvt.short_end = parser->short_opts; - cvt.long_end = parser->long_opts; - cvt.child_inputs_end = parser->child_inputs; - - if (flags & ARGP_IN_ORDER) - *cvt.short_end++ = '-'; - else if (flags & ARGP_NO_ARGS) - *cvt.short_end++ = '+'; - *cvt.short_end = '\0'; - - cvt.long_end->name = NULL; - - parser->argp = argp; - - if (argp) - parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt); - else - parser->egroup = parser->groups; /* No parsers at all! */ -} - -/* Lengths of various parser fields which we will allocated. */ -struct parser_sizes -{ - size_t short_len; /* Getopt short options string. */ - size_t long_len; /* Getopt long options vector. */ - size_t num_groups; /* Group structures we allocate. */ - size_t num_child_inputs; /* Child input slots. */ -}; - -/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of - argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by - the maximum lengths of the resulting merged getopt short options string and - long-options array, respectively. */ -static void -calc_sizes (const struct argp *argp, struct parser_sizes *szs) -{ - const struct argp_child *child = argp->children; - const struct argp_option *opt = argp->options; - - if (opt || argp->parser) - { - szs->num_groups++; - if (opt) - { - int num_opts = 0; - while (!__option_is_end (opt++)) - num_opts++; - szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */ - szs->long_len += num_opts; - } - } - - if (child) - while (child->argp) - { - calc_sizes ((child++)->argp, szs); - szs->num_child_inputs++; - } -} - -/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */ -static error_t -parser_init (struct parser *parser, const struct argp *argp, - int argc, char **argv, int flags, void *input) -{ - error_t err = 0; - struct group *group; - struct parser_sizes szs; - struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER; - char *storage; - size_t glen, gsum; - size_t clen, csum; - size_t llen, lsum; - size_t slen, ssum; - - szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1; - szs.long_len = 0; - szs.num_groups = 0; - szs.num_child_inputs = 0; - - if (argp) - calc_sizes (argp, &szs); - - /* Lengths of the various bits of storage used by PARSER. */ - glen = (szs.num_groups + 1) * sizeof (struct group); - clen = szs.num_child_inputs * sizeof (void *); - llen = (szs.long_len + 1) * sizeof (struct option); - slen = szs.short_len + 1; - - /* Sums of previous lengths, properly aligned. There's no need to - align gsum, since struct group is aligned at least as strictly as - void * (since it contains a void * member). And there's no need - to align lsum, since struct option is aligned at least as - strictly as char. */ - gsum = glen; - csum = alignto (gsum + clen, alignof (struct option)); - lsum = csum + llen; - ssum = lsum + slen; - - parser->storage = malloc (ssum); - if (! parser->storage) - return ENOMEM; - - storage = parser->storage; - parser->groups = parser->storage; - parser->child_inputs = (void **) (storage + gsum); - parser->long_opts = (struct option *) (storage + csum); - parser->short_opts = storage + lsum; - parser->opt_data = opt_data; - - memset (parser->child_inputs, 0, clen); - parser_convert (parser, argp, flags); - - memset (&parser->state, 0, sizeof (struct argp_state)); - parser->state.root_argp = parser->argp; - parser->state.argc = argc; - parser->state.argv = argv; - parser->state.flags = flags; - parser->state.err_stream = stderr; - parser->state.out_stream = stdout; - parser->state.next = 0; /* Tell getopt to initialize. */ - parser->state.pstate = parser; - - parser->try_getopt = 1; - - /* Call each parser for the first time, giving it a chance to propagate - values to child parsers. */ - if (parser->groups < parser->egroup) - parser->groups->input = input; - for (group = parser->groups; - group < parser->egroup && (!err || err == EBADKEY); - group++) - { - if (group->parent) - /* If a child parser, get the initial input value from the parent. */ - group->input = group->parent->child_inputs[group->parent_index]; - - if (!group->parser - && group->argp->children && group->argp->children->argp) - /* For the special case where no parsing function is supplied for an - argp, propagate its input to its first child, if any (this just - makes very simple wrapper argps more convenient). */ - group->child_inputs[0] = group->input; - - err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0); - } - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - if (err) - return err; - - if (parser->state.flags & ARGP_NO_ERRS) - { - parser->opt_data.opterr = 0; - if (parser->state.flags & ARGP_PARSE_ARGV0) - /* getopt always skips ARGV[0], so we have to fake it out. As long - as OPTERR is 0, then it shouldn't actually try to access it. */ - parser->state.argv--, parser->state.argc++; - } - else - parser->opt_data.opterr = 1; /* Print error messages. */ - - if (parser->state.argv == argv && argv[0]) - /* There's an argv[0]; use it for messages. */ - parser->state.name = __argp_base_name (argv[0]); - else - parser->state.name = __argp_short_program_name (); - - return 0; -} - -/* Free any storage consumed by PARSER (but not PARSER itself). */ -static error_t -parser_finalize (struct parser *parser, - error_t err, int arg_ebadkey, int *end_index) -{ - struct group *group; - - if (err == EBADKEY && arg_ebadkey) - /* Suppress errors generated by unparsed arguments. */ - err = 0; - - if (! err) - { - if (parser->state.next == parser->state.argc) - /* We successfully parsed all arguments! Call all the parsers again, - just a few more times... */ - { - for (group = parser->groups; - group < parser->egroup && (!err || err==EBADKEY); - group++) - if (group->args_processed == 0) - err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0); - for (group = parser->egroup - 1; - group >= parser->groups && (!err || err==EBADKEY); - group--) - err = group_parse (group, &parser->state, ARGP_KEY_END, 0); - - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - - /* Tell the user that all arguments are parsed. */ - if (end_index) - *end_index = parser->state.next; - } - else if (end_index) - /* Return any remaining arguments to the user. */ - *end_index = parser->state.next; - else - /* No way to return the remaining arguments, they must be bogus. */ - { - if (!(parser->state.flags & ARGP_NO_ERRS) - && parser->state.err_stream) - fprintf (parser->state.err_stream, - dgettext (parser->argp->argp_domain, - "%s: Too many arguments\n"), - parser->state.name); - err = EBADKEY; - } - } - - /* Okay, we're all done, with either an error or success; call the parsers - to indicate which one. */ - - if (err) - { - /* Maybe print an error message. */ - if (err == EBADKEY) - /* An appropriate message describing what the error was should have - been printed earlier. */ - __argp_state_help (&parser->state, parser->state.err_stream, - ARGP_HELP_STD_ERR); - - /* Since we didn't exit, give each parser an error indication. */ - for (group = parser->groups; group < parser->egroup; group++) - group_parse (group, &parser->state, ARGP_KEY_ERROR, 0); - } - else - /* Notify parsers of success, and propagate back values from parsers. */ - { - /* We pass over the groups in reverse order so that child groups are - given a chance to do there processing before passing back a value to - the parent. */ - for (group = parser->egroup - 1 - ; group >= parser->groups && (!err || err == EBADKEY) - ; group--) - err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0); - if (err == EBADKEY) - err = 0; /* Some parser didn't understand. */ - } - - /* Call parsers once more, to do any final cleanup. Errors are ignored. */ - for (group = parser->egroup - 1; group >= parser->groups; group--) - group_parse (group, &parser->state, ARGP_KEY_FINI, 0); - - if (err == EBADKEY) - err = EINVAL; - - free (parser->storage); - - return err; -} - -/* Call the user parsers to parse the non-option argument VAL, at the current - position, returning any error. The state NEXT pointer is assumed to have - been adjusted (by getopt) to point after this argument; this function will - adjust it correctly to reflect however many args actually end up being - consumed. */ -static error_t -parser_parse_arg (struct parser *parser, char *val) -{ - /* Save the starting value of NEXT, first adjusting it so that the arg - we're parsing is again the front of the arg vector. */ - int index = --parser->state.next; - error_t err = EBADKEY; - struct group *group; - int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */ - - /* Try to parse the argument in each parser. */ - for (group = parser->groups - ; group < parser->egroup && err == EBADKEY - ; group++) - { - parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */ - key = ARGP_KEY_ARG; - err = group_parse (group, &parser->state, key, val); - - if (err == EBADKEY) - /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */ - { - parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */ - key = ARGP_KEY_ARGS; - err = group_parse (group, &parser->state, key, 0); - } - } - - if (! err) - { - if (key == ARGP_KEY_ARGS) - /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't - changed by the user, *all* arguments should be considered - consumed. */ - parser->state.next = parser->state.argc; - - if (parser->state.next > index) - /* Remember that we successfully processed a non-option - argument -- but only if the user hasn't gotten tricky and set - the clock back. */ - (--group)->args_processed += (parser->state.next - index); - else - /* The user wants to reparse some args, give getopt another try. */ - parser->try_getopt = 1; - } - - return err; -} - -/* Call the user parsers to parse the option OPT, with argument VAL, at the - current position, returning any error. */ -static error_t -parser_parse_opt (struct parser *parser, int opt, char *val) -{ - /* The group key encoded in the high bits; 0 for short opts or - group_number + 1 for long opts. */ - int group_key = opt >> USER_BITS; - error_t err = EBADKEY; - - if (group_key == 0) - /* A short option. By comparing OPT's position in SHORT_OPTS to the - various starting positions in each group's SHORT_END field, we can - determine which group OPT came from. */ - { - struct group *group; - char *short_index = strchr (parser->short_opts, opt); - - if (short_index) - for (group = parser->groups; group < parser->egroup; group++) - if (group->short_end > short_index) - { - err = group_parse (group, &parser->state, opt, - parser->opt_data.optarg); - break; - } - } - else - /* A long option. We use shifts instead of masking for extracting - the user value in order to preserve the sign. */ - err = - group_parse (&parser->groups[group_key - 1], &parser->state, - (opt << GROUP_BITS) >> GROUP_BITS, - parser->opt_data.optarg); - - if (err == EBADKEY) - /* At least currently, an option not recognized is an error in the - parser, because we pre-compute which parser is supposed to deal - with each option. */ - { - static const char bad_key_err[] = - N_("(PROGRAM ERROR) Option should have been recognized!?"); - if (group_key == 0) - __argp_error (&parser->state, "-%c: %s", opt, - dgettext (parser->argp->argp_domain, bad_key_err)); - else - { - struct option *long_opt = parser->long_opts; - while (long_opt->val != opt && long_opt->name) - long_opt++; - __argp_error (&parser->state, "--%s: %s", - long_opt->name ? long_opt->name : "???", - dgettext (parser->argp->argp_domain, bad_key_err)); - } - } - - return err; -} - -/* Parse the next argument in PARSER (as indicated by PARSER->state.next). - Any error from the parsers is returned, and *ARGP_EBADKEY indicates - whether a value of EBADKEY is due to an unrecognized argument (which is - generally not fatal). */ -static error_t -parser_parse_next (struct parser *parser, int *arg_ebadkey) -{ - int opt; - error_t err = 0; - - if (parser->state.quoted && parser->state.next < parser->state.quoted) - /* The next argument pointer has been moved to before the quoted - region, so pretend we never saw the quoting `--', and give getopt - another chance. If the user hasn't removed it, getopt will just - process it again. */ - parser->state.quoted = 0; - - if (parser->try_getopt && !parser->state.quoted) - /* Give getopt a chance to parse this. */ - { - /* Put it back in OPTIND for getopt. */ - parser->opt_data.optind = parser->state.next; - /* Distinguish KEY_ERR from a real option. */ - parser->opt_data.optopt = KEY_END; - if (parser->state.flags & ARGP_LONG_ONLY) - opt = _getopt_long_only_r (parser->state.argc, parser->state.argv, - parser->short_opts, parser->long_opts, 0, - &parser->opt_data); - else - opt = _getopt_long_r (parser->state.argc, parser->state.argv, - parser->short_opts, parser->long_opts, 0, - &parser->opt_data); - /* And see what getopt did. */ - parser->state.next = parser->opt_data.optind; - - if (opt == KEY_END) - /* Getopt says there are no more options, so stop using - getopt; we'll continue if necessary on our own. */ - { - parser->try_getopt = 0; - if (parser->state.next > 1 - && strcmp (parser->state.argv[parser->state.next - 1], QUOTE) - == 0) - /* Not only is this the end of the options, but it's a - `quoted' region, which may have args that *look* like - options, so we definitely shouldn't try to use getopt past - here, whatever happens. */ - parser->state.quoted = parser->state.next; - } - else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END) - /* KEY_ERR can have the same value as a valid user short - option, but in the case of a real error, getopt sets OPTOPT - to the offending character, which can never be KEY_END. */ - { - *arg_ebadkey = 0; - return EBADKEY; - } - } - else - opt = KEY_END; - - if (opt == KEY_END) - { - /* We're past what getopt considers the options. */ - if (parser->state.next >= parser->state.argc - || (parser->state.flags & ARGP_NO_ARGS)) - /* Indicate that we're done. */ - { - *arg_ebadkey = 1; - return EBADKEY; - } - else - /* A non-option arg; simulate what getopt might have done. */ - { - opt = KEY_ARG; - parser->opt_data.optarg = parser->state.argv[parser->state.next++]; - } - } - - if (opt == KEY_ARG) - /* A non-option argument; try each parser in turn. */ - err = parser_parse_arg (parser, parser->opt_data.optarg); - else - err = parser_parse_opt (parser, opt, parser->opt_data.optarg); - - if (err == EBADKEY) - *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG); - - return err; -} - -/* Parse the options strings in ARGC & ARGV according to the argp in ARGP. - FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the - index in ARGV of the first unparsed option is returned in it. If an - unknown option is present, EINVAL is returned; if some parser routine - returned a non-zero value, it is returned; otherwise 0 is returned. */ -error_t -__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, - int *end_index, void *input) -{ - error_t err; - struct parser parser; - - /* If true, then err == EBADKEY is a result of a non-option argument failing - to be parsed (which in some cases isn't actually an error). */ - int arg_ebadkey = 0; - -#ifndef _LIBC - if (!(flags & ARGP_PARSE_ARGV0)) - { -#ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME - if (!program_invocation_name) - program_invocation_name = argv[0]; -#endif -#ifdef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME - if (!program_invocation_short_name) - program_invocation_short_name = __argp_base_name (argv[0]); -#endif - } -#endif - - if (! (flags & ARGP_NO_HELP)) - /* Add our own options. */ - { - struct argp_child *child = alloca (4 * sizeof (struct argp_child)); - struct argp *top_argp = alloca (sizeof (struct argp)); - - /* TOP_ARGP has no options, it just serves to group the user & default - argps. */ - memset (top_argp, 0, sizeof (*top_argp)); - top_argp->children = child; - - memset (child, 0, 4 * sizeof (struct argp_child)); - - if (argp) - (child++)->argp = argp; - (child++)->argp = &argp_default_argp; - if (argp_program_version || argp_program_version_hook) - (child++)->argp = &argp_version_argp; - child->argp = 0; - - argp = top_argp; - } - - /* Construct a parser for these arguments. */ - err = parser_init (&parser, argp, argc, argv, flags, input); - - if (! err) - /* Parse! */ - { - while (! err) - err = parser_parse_next (&parser, &arg_ebadkey); - err = parser_finalize (&parser, err, arg_ebadkey, end_index); - } - - return err; -} -#ifdef weak_alias -weak_alias (__argp_parse, argp_parse) -#endif - -/* Return the input field for ARGP in the parser corresponding to STATE; used - by the help routines. */ -void * -__argp_input (const struct argp *argp, const struct argp_state *state) -{ - if (state) - { - struct group *group; - struct parser *parser = state->pstate; - - for (group = parser->groups; group < parser->egroup; group++) - if (group->argp == argp) - return group->input; - } - - return 0; -} -#ifdef weak_alias -weak_alias (__argp_input, _argp_input) -#endif diff --git a/lib/argp-pin.c b/lib/argp-pin.c deleted file mode 100644 index 852c6d6..0000000 --- a/lib/argp-pin.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Full and short program names for argp module - Copyright (C) 2005 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME -char *program_invocation_short_name = 0; -#endif -#ifndef HAVE_PROGRAM_INVOCATION_NAME -char *program_invocation_name = 0; -#endif - diff --git a/lib/argp-pv.c b/lib/argp-pv.c deleted file mode 100644 index a11298b..0000000 --- a/lib/argp-pv.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Default definition for ARGP_PROGRAM_VERSION. - Copyright (C) 1996, 1997, 1999, 2006 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* If set by the user program to a non-zero value, then a default option - --version is added (unless the ARGP_NO_HELP flag is used), which will - print this string followed by a newline and exit (unless the - ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ -const char *argp_program_version; diff --git a/lib/argp-pvh.c b/lib/argp-pvh.c deleted file mode 100644 index 6bf7c49..0000000 --- a/lib/argp-pvh.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Default definition for ARGP_PROGRAM_VERSION_HOOK. - Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "argp.h" - -/* If set by the user program to a non-zero value, then a default option - --version is added (unless the ARGP_NO_HELP flag is used), which calls - this function with a stream to print the version to and a pointer to the - current parsing state, and then exits (unless the ARGP_NO_EXIT flag is - used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ -void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = NULL; diff --git a/lib/argp-xinl.c b/lib/argp-xinl.c deleted file mode 100644 index a6afb1f..0000000 --- a/lib/argp-xinl.c +++ /dev/null @@ -1,43 +0,0 @@ -/* Real definitions for extern inline functions in argp.h - Copyright (C) 1997, 1998, 2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#if defined _LIBC || defined HAVE_FEATURES_H -# include -#endif - -#ifndef __USE_EXTERN_INLINES -# define __USE_EXTERN_INLINES 1 -#endif -#define ARGP_EI -#undef __OPTIMIZE__ -#define __OPTIMIZE__ 1 -#include "argp.h" - -/* Add weak aliases. */ -#if _LIBC - 0 && defined (weak_alias) - -weak_alias (__argp_usage, argp_usage) -weak_alias (__option_is_short, _option_is_short) -weak_alias (__option_is_end, _option_is_end) - -#endif diff --git a/lib/argp.h b/lib/argp.h deleted file mode 100644 index 1c4e06f..0000000 --- a/lib/argp.h +++ /dev/null @@ -1,622 +0,0 @@ -/* Hierarchial argument parsing, layered over getopt. - Copyright (C) 1995-1999,2003-2007 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Miles Bader . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _ARGP_H -#define _ARGP_H - -#include -#include -#include -#include - -#define __need_error_t -#include - -#ifndef __THROW -# define __THROW -#endif -#ifndef __NTH -# define __NTH(fct) fct __THROW -#endif - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__ -# define __format__ format -# define __printf__ printf -# endif -#endif - -/* GCC 2.95 and later have "__restrict"; C99 compilers have - "restrict", and "configure" may have defined "restrict". - Other compilers use __restrict, __restrict__, and _Restrict, and - 'configure' might #define 'restrict' to those words. */ -#ifndef __restrict -# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) -# if 199901L <= __STDC_VERSION__ -# define __restrict restrict -# else -# define __restrict -# endif -# endif -#endif - -#ifndef __error_t_defined -typedef int error_t; -# define __error_t_defined -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* A description of a particular option. A pointer to an array of - these is passed in the OPTIONS field of an argp structure. Each option - entry can correspond to one long option and/or one short option; more - names for the same option can be added by following an entry in an option - array with options having the OPTION_ALIAS flag set. */ -struct argp_option -{ - /* The long option name. For more than one name for the same option, you - can use following options with the OPTION_ALIAS flag set. */ - const char *name; - - /* What key is returned for this option. If > 0 and printable, then it's - also accepted as a short option. */ - int key; - - /* If non-NULL, this is the name of the argument associated with this - option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */ - const char *arg; - - /* OPTION_ flags. */ - int flags; - - /* The doc string for this option. If both NAME and KEY are 0, This string - will be printed outdented from the normal option column, making it - useful as a group header (it will be the first thing printed in its - group); in this usage, it's conventional to end the string with a `:'. - - Write the initial value as N_("TEXT") if you want xgettext to collect - it into a POT file. */ - const char *doc; - - /* The group this option is in. In a long help message, options are sorted - alphabetically within each group, and the groups presented in the order - 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with - if this field 0 will inherit the group number of the previous entry, or - zero if it's the first one, unless its a group header (NAME and KEY both - 0), in which case, the previous entry + 1 is the default. Automagic - options such as --help are put into group -1. */ - int group; -}; - -/* The argument associated with this option is optional. */ -#define OPTION_ARG_OPTIONAL 0x1 - -/* This option isn't displayed in any help messages. */ -#define OPTION_HIDDEN 0x2 - -/* This option is an alias for the closest previous non-alias option. This - means that it will be displayed in the same help entry, and will inherit - fields other than NAME and KEY from the aliased option. */ -#define OPTION_ALIAS 0x4 - -/* This option isn't actually an option (and so should be ignored by the - actual option parser), but rather an arbitrary piece of documentation that - should be displayed in much the same manner as the options. If this flag - is set, then the option NAME field is displayed unmodified (e.g., no `--' - prefix is added) at the left-margin (where a *short* option would normally - be displayed), and the documentation string in the normal place. The NAME - field will be translated using gettext, unless OPTION_NO_TRANS is set (see - below). For purposes of sorting, any leading whitespace and punctuation is - ignored, except that if the first non-whitespace character is not `-', this - entry is displayed after all options (and OPTION_DOC entries with a leading - `-') in the same group. */ -#define OPTION_DOC 0x8 - -/* This option shouldn't be included in `long' usage messages (but is still - included in help messages). This is mainly intended for options that are - completely documented in an argp's ARGS_DOC field, in which case including - the option in the generic usage list would be redundant. For instance, - if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to - distinguish these two cases, -x should probably be marked - OPTION_NO_USAGE. */ -#define OPTION_NO_USAGE 0x10 - -/* Valid only in conjunction with OPTION_DOC. This option disables translation - of option name. */ -#define OPTION_NO_TRANS 0x20 - - -struct argp; /* fwd declare this type */ -struct argp_state; /* " */ -struct argp_child; /* " */ - -/* The type of a pointer to an argp parsing function. */ -typedef error_t (*argp_parser_t) (int key, char *arg, - struct argp_state *state); - -/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such - returns will simply be ignored. For user keys, this error will be turned - into EINVAL (if the call to argp_parse is such that errors are propagated - back to the user instead of exiting); returning EINVAL itself would result - in an immediate stop to parsing in *all* cases. */ -#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ - -/* Special values for the KEY argument to an argument parsing function. - ARGP_ERR_UNKNOWN should be returned if they aren't understood. - - The sequence of keys to a parsing function is either (where each - uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key): - - INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all - or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed - or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized - - The third case is where every parser returned ARGP_KEY_UNKNOWN for an - argument, in which case parsing stops at that argument (returning the - unparsed arguments to the caller of argp_parse if requested, or stopping - with an error message if not). - - If an error occurs (either detected by argp, or because the parsing - function returned an error value), then the parser is called with - ARGP_KEY_ERROR, and no further calls are made. */ - -/* This is not an option at all, but rather a command line argument. If a - parser receiving this key returns success, the fact is recorded, and the - ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the - argument, a parser function decrements the NEXT field of the state it's - passed, the option won't be considered processed; this is to allow you to - actually modify the argument (perhaps into an option), and have it - processed again. */ -#define ARGP_KEY_ARG 0 -/* There are remaining arguments not parsed by any parser, which may be found - starting at (STATE->argv + STATE->next). If success is returned, but - STATE->next left untouched, it's assumed that all arguments were consume, - otherwise, the parser should adjust STATE->next to reflect any arguments - consumed. */ -#define ARGP_KEY_ARGS 0x1000006 -/* There are no more command line arguments at all. */ -#define ARGP_KEY_END 0x1000001 -/* Because it's common to want to do some special processing if there aren't - any non-option args, user parsers are called with this key if they didn't - successfully process any non-option arguments. Called just before - ARGP_KEY_END (where more general validity checks on previously parsed - arguments can take place). */ -#define ARGP_KEY_NO_ARGS 0x1000002 -/* Passed in before any parsing is done. Afterwards, the values of each - element of the CHILD_INPUT field, if any, in the state structure is - copied to each child's state to be the initial value of the INPUT field. */ -#define ARGP_KEY_INIT 0x1000003 -/* Use after all other keys, including SUCCESS & END. */ -#define ARGP_KEY_FINI 0x1000007 -/* Passed in when parsing has successfully been completed (even if there are - still arguments remaining). */ -#define ARGP_KEY_SUCCESS 0x1000004 -/* Passed in if an error occurs. */ -#define ARGP_KEY_ERROR 0x1000005 - -/* An argp structure contains a set of options declarations, a function to - deal with parsing one, documentation string, a possible vector of child - argp's, and perhaps a function to filter help output. When actually - parsing options, getopt is called with the union of all the argp - structures chained together through their CHILD pointers, with conflicts - being resolved in favor of the first occurrence in the chain. */ -struct argp -{ - /* An array of argp_option structures, terminated by an entry with both - NAME and KEY having a value of 0. */ - const struct argp_option *options; - - /* What to do with an option from this structure. KEY is the key - associated with the option, and ARG is any associated argument (NULL if - none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be - returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then - parsing is stopped immediately, and that value is returned from - argp_parse(). For special (non-user-supplied) values of KEY, see the - ARGP_KEY_ definitions below. */ - argp_parser_t parser; - - /* A string describing what other arguments are wanted by this program. It - is only used by argp_usage to print the `Usage:' message. If it - contains newlines, the strings separated by them are considered - alternative usage patterns, and printed on separate lines (lines after - the first are prefix by ` or: ' instead of `Usage:'). */ - const char *args_doc; - - /* If non-NULL, a string containing extra text to be printed before and - after the options in a long help message (separated by a vertical tab - `\v' character). - Write the initial value as N_("BEFORE-TEXT") "\v" N_("AFTER-TEXT") if - you want xgettext to collect the two pieces of text into a POT file. */ - const char *doc; - - /* A vector of argp_children structures, terminated by a member with a 0 - argp field, pointing to child argps should be parsed with this one. Any - conflicts are resolved in favor of this argp, or early argps in the - CHILDREN list. This field is useful if you use libraries that supply - their own argp structure, which you want to use in conjunction with your - own. */ - const struct argp_child *children; - - /* If non-zero, this should be a function to filter the output of help - messages. KEY is either a key from an option, in which case TEXT is - that option's help text, or a special key from the ARGP_KEY_HELP_ - defines, below, describing which other help text TEXT is. The function - should return either TEXT, if it should be used as-is, a replacement - string, which should be malloced, and will be freed by argp, or NULL, - meaning `print nothing'. The value for TEXT is *after* any translation - has been done, so if any of the replacement text also needs translation, - that should be done by the filter function. INPUT is either the input - supplied to argp_parse, or NULL, if argp_help was called directly. */ - char *(*help_filter) (int __key, const char *__text, void *__input); - - /* If non-zero the strings used in the argp library are translated using - the domain described by this string. Otherwise the currently installed - default domain is used. */ - const char *argp_domain; -}; - -/* Possible KEY arguments to a help filter function. */ -#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */ -#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ -#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ -#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; - TEXT is NULL for this key. */ -/* Explanatory note emitted when duplicate option arguments have been - suppressed. */ -#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005 -#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ - -/* When an argp has a non-zero CHILDREN field, it should point to a vector of - argp_child structures, each of which describes a subsidiary argp. */ -struct argp_child -{ - /* The child parser. */ - const struct argp *argp; - - /* Flags for this child. */ - int flags; - - /* If non-zero, an optional header to be printed in help output before the - child options. As a side-effect, a non-zero value forces the child - options to be grouped together; to achieve this effect without actually - printing a header string, use a value of "". */ - const char *header; - - /* Where to group the child options relative to the other (`consolidated') - options in the parent argp; the values are the same as the GROUP field - in argp_option structs, but all child-groupings follow parent options at - a particular group level. If both this field and HEADER are zero, then - they aren't grouped at all, but rather merged with the parent options - (merging the child's grouping levels with the parents). */ - int group; -}; - -/* Parsing state. This is provided to parsing functions called by argp, - which may examine and, as noted, modify fields. */ -struct argp_state -{ - /* The top level ARGP being parsed. */ - const struct argp *root_argp; - - /* The argument vector being parsed. May be modified. */ - int argc; - char **argv; - - /* The index in ARGV of the next arg that to be parsed. May be modified. */ - int next; - - /* The flags supplied to argp_parse. May be modified. */ - unsigned flags; - - /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the - number of the current arg, starting at zero, and incremented after each - such call returns. At all other times, this is the number of such - arguments that have been processed. */ - unsigned arg_num; - - /* If non-zero, the index in ARGV of the first argument following a special - `--' argument (which prevents anything following being interpreted as an - option). Only set once argument parsing has proceeded past this point. */ - int quoted; - - /* An arbitrary pointer passed in from the user. */ - void *input; - /* Values to pass to child parsers. This vector will be the same length as - the number of children for the current parser. */ - void **child_inputs; - - /* For the parser's use. Initialized to 0. */ - void *hook; - - /* The name used when printing messages. This is initialized to ARGV[0], - or PROGRAM_INVOCATION_NAME if that is unavailable. */ - char *name; - - /* Streams used when argp prints something. */ - FILE *err_stream; /* For errors; initialized to stderr. */ - FILE *out_stream; /* For information; initialized to stdout. */ - - void *pstate; /* Private, for use by argp. */ -}; - -/* Flags for argp_parse (note that the defaults are those that are - convenient for program command line parsing): */ - -/* Don't ignore the first element of ARGV. Normally (and always unless - ARGP_NO_ERRS is set) the first element of the argument vector is - skipped for option parsing purposes, as it corresponds to the program name - in a command line. */ -#define ARGP_PARSE_ARGV0 0x01 - -/* Don't print error messages for unknown options to stderr; unless this flag - is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program - name in the error messages. This flag implies ARGP_NO_EXIT (on the - assumption that silent exiting upon errors is bad behaviour). */ -#define ARGP_NO_ERRS 0x02 - -/* Don't parse any non-option args. Normally non-option args are parsed by - calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg - as the value. Since it's impossible to know which parse function wants to - handle it, each one is called in turn, until one returns 0 or an error - other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the - argp_parse returns prematurely (but with a return value of 0). If all - args have been parsed without error, all parsing functions are called one - last time with a key of ARGP_KEY_END. This flag needn't normally be set, - as the normal behavior is to stop parsing as soon as some argument can't - be handled. */ -#define ARGP_NO_ARGS 0x04 - -/* Parse options and arguments in the same order they occur on the command - line -- normally they're rearranged so that all options come first. */ -#define ARGP_IN_ORDER 0x08 - -/* Don't provide the standard long option --help, which causes usage and - option help information to be output to stdout, and exit (0) called. */ -#define ARGP_NO_HELP 0x10 - -/* Don't exit on errors (they may still result in error messages). */ -#define ARGP_NO_EXIT 0x20 - -/* Use the gnu getopt `long-only' rules for parsing arguments. */ -#define ARGP_LONG_ONLY 0x40 - -/* Turns off any message-printing/exiting options. */ -#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP) - -/* Parse the options strings in ARGC & ARGV according to the options in ARGP. - FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the - index in ARGV of the first unparsed option is returned in it. If an - unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser - routine returned a non-zero value, it is returned; otherwise 0 is - returned. This function may also call exit unless the ARGP_NO_HELP flag - is set. INPUT is a pointer to a value to be passed in to the parser. */ -extern error_t argp_parse (const struct argp *__restrict __argp, - int /*argc*/, char **__restrict /*argv*/, - unsigned __flags, int *__restrict __arg_index, - void *__restrict __input); -extern error_t __argp_parse (const struct argp *__restrict __argp, - int /*argc*/, char **__restrict /*argv*/, - unsigned __flags, int *__restrict __arg_index, - void *__restrict __input); - -/* Global variables. */ - -/* GNULIB makes sure both program_invocation_name and - program_invocation_short_name are available */ -#ifdef GNULIB_PROGRAM_INVOCATION_NAME -extern char *program_invocation_name; -# undef HAVE_DECL_PROGRAM_INVOCATION_NAME -# define HAVE_DECL_PROGRAM_INVOCATION_NAME 1 -#endif - -#ifdef GNULIB_PROGRAM_INVOCATION_SHORT_NAME -extern char *program_invocation_short_name; -# undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME -# define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1 -#endif - -/* If defined or set by the user program to a non-zero value, then a default - option --version is added (unless the ARGP_NO_HELP flag is used), which - will print this string followed by a newline and exit (unless the - ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ -extern const char *argp_program_version; - -/* If defined or set by the user program to a non-zero value, then a default - option --version is added (unless the ARGP_NO_HELP flag is used), which - calls this function with a stream to print the version to and a pointer to - the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is - used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ -extern void (*argp_program_version_hook) (FILE *__restrict __stream, - struct argp_state *__restrict - __state); - -/* If defined or set by the user program, it should point to string that is - the bug-reporting address for the program. It will be printed by - argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various - standard help messages), embedded in a sentence that says something like - `Report bugs to ADDR.'. */ -extern const char *argp_program_bug_address; - -/* The exit status that argp will use when exiting due to a parsing error. - If not defined or set by the user program, this defaults to EX_USAGE from - . */ -extern error_t argp_err_exit_status; - -/* Flags for argp_help. */ -#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ -#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ -#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */ -#define ARGP_HELP_LONG 0x08 /* a long help message. */ -#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ -#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ -#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) -#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ -#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to - reflect ARGP_LONG_ONLY mode. */ - -/* These ARGP_HELP flags are only understood by argp_state_help. */ -#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ -#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ - -/* The standard thing to do after a program command line parsing error, if an - error message has already been printed. */ -#define ARGP_HELP_STD_ERR \ - (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) -/* The standard thing to do after a program command line parsing error, if no - more specific error message has been printed. */ -#define ARGP_HELP_STD_USAGE \ - (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) -/* The standard thing to do in response to a --help option. */ -#define ARGP_HELP_STD_HELP \ - (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \ - | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR) - -/* Output a usage message for ARGP to STREAM. FLAGS are from the set - ARGP_HELP_*. */ -extern void argp_help (const struct argp *__restrict __argp, - FILE *__restrict __stream, - unsigned __flags, char *__restrict __name); -extern void __argp_help (const struct argp *__restrict __argp, - FILE *__restrict __stream, unsigned __flags, - char *__name); - -/* The following routines are intended to be called from within an argp - parsing routine (thus taking an argp_state structure as the first - argument). They may or may not print an error message and exit, depending - on the flags in STATE -- in any case, the caller should be prepared for - them *not* to exit, and should return an appropiate error after calling - them. [argp_usage & argp_error should probably be called argp_state_..., - but they're used often enough that they should be short] */ - -/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are - from the set ARGP_HELP_*. */ -extern void argp_state_help (const struct argp_state *__restrict __state, - FILE *__restrict __stream, - unsigned int __flags); -extern void __argp_state_help (const struct argp_state *__restrict __state, - FILE *__restrict __stream, - unsigned int __flags); - -/* Possibly output the standard usage message for ARGP to stderr and exit. */ -extern void argp_usage (const struct argp_state *__state); -extern void __argp_usage (const struct argp_state *__state); - -/* If appropriate, print the printf string FMT and following args, preceded - by the program name and `:', to stderr, and followed by a `Try ... --help' - message, then exit (1). */ -extern void argp_error (const struct argp_state *__restrict __state, - const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); -extern void __argp_error (const struct argp_state *__restrict __state, - const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); - -/* Similar to the standard gnu error-reporting function error(), but will - respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print - to STATE->err_stream. This is useful for argument parsing code that is - shared between program startup (when exiting is desired) and runtime - option parsing (when typically an error code is returned instead). The - difference between this function and argp_error is that the latter is for - *parsing errors*, and the former is for other problems that occur during - parsing but don't reflect a (syntactic) problem with the input. */ -extern void argp_failure (const struct argp_state *__restrict __state, - int __status, int __errnum, - const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 4, 5))); -extern void __argp_failure (const struct argp_state *__restrict __state, - int __status, int __errnum, - const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 4, 5))); - -/* Returns true if the option OPT is a valid short option. */ -extern int _option_is_short (const struct argp_option *__opt) __THROW; -extern int __option_is_short (const struct argp_option *__opt) __THROW; - -/* Returns true if the option OPT is in fact the last (unused) entry in an - options array. */ -extern int _option_is_end (const struct argp_option *__opt) __THROW; -extern int __option_is_end (const struct argp_option *__opt) __THROW; - -/* Return the input field for ARGP in the parser corresponding to STATE; used - by the help routines. */ -extern void *_argp_input (const struct argp *__restrict __argp, - const struct argp_state *__restrict __state) - __THROW; -extern void *__argp_input (const struct argp *__restrict __argp, - const struct argp_state *__restrict __state) - __THROW; - -#ifdef __USE_EXTERN_INLINES - -# if !_LIBC -# define __argp_usage argp_usage -# define __argp_state_help argp_state_help -# define __option_is_short _option_is_short -# define __option_is_end _option_is_end -# endif - -# ifndef ARGP_EI -# define ARGP_EI extern __inline__ -# endif - -ARGP_EI void -__argp_usage (const struct argp_state *__state) -{ - __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE); -} - -ARGP_EI int -__NTH (__option_is_short (const struct argp_option *__opt)) -{ - if (__opt->flags & OPTION_DOC) - return 0; - else - { - int __key = __opt->key; - return __key > 0 && __key <= UCHAR_MAX && isprint (__key); - } -} - -ARGP_EI int -__NTH (__option_is_end (const struct argp_option *__opt)) -{ - return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; -} - -# if !_LIBC -# undef __argp_usage -# undef __argp_state_help -# undef __option_is_short -# undef __option_is_end -# endif -#endif /* Use extern inlines. */ - -#ifdef __cplusplus -} -#endif - -#endif /* argp.h */ diff --git a/lib/asnprintf.c b/lib/asnprintf.c deleted file mode 100644 index 26c3988..0000000 --- a/lib/asnprintf.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include "vasnprintf.h" - -#include - -char * -asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) -{ - va_list args; - char *result; - - va_start (args, format); - result = vasnprintf (resultbuf, lengthp, format, args); - va_end (args); - return result; -} diff --git a/lib/basename.c b/lib/basename.c deleted file mode 100644 index fbe17ff..0000000 --- a/lib/basename.c +++ /dev/null @@ -1,129 +0,0 @@ -/* basename.c -- return the last element in a file name - - Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free - Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include "dirname.h" - -#include -#include "xalloc.h" -#include "xstrndup.h" - -/* Return the address of the last file name component of NAME. If - NAME has no relative file name components because it is a file - system root, return the empty string. */ - -char * -last_component (char const *name) -{ - char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); - char const *p; - bool saw_slash = false; - - while (ISSLASH (*base)) - base++; - - for (p = base; *p; p++) - { - if (ISSLASH (*p)) - saw_slash = true; - else if (saw_slash) - { - base = p; - saw_slash = false; - } - } - - return (char *) base; -} - - -/* In general, we can't use the builtin `basename' function if available, - since it has different meanings in different environments. - In some environments the builtin `basename' modifies its argument. - - Return the last file name component of NAME, allocated with - xmalloc. On systems with drive letters, a leading "./" - distinguishes relative names that would otherwise look like a drive - letter. Unlike POSIX basename(), NAME cannot be NULL, - base_name("") returns "", and the first trailing slash is not - stripped. - - If lstat (NAME) would succeed, then { chdir (dir_name (NAME)); - lstat (base_name (NAME)); } will access the same file. Likewise, - if the sequence { chdir (dir_name (NAME)); - rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME - to "foo" in the same directory NAME was in. */ - -char * -base_name (char const *name) -{ - char const *base = last_component (name); - size_t length; - - /* If there is no last component, then name is a file system root or the - empty string. */ - if (! *base) - return xstrndup (name, base_len (name)); - - /* Collapse a sequence of trailing slashes into one. */ - length = base_len (base); - if (ISSLASH (base[length])) - length++; - - /* On systems with drive letters, `a/b:c' must return `./b:c' rather - than `b:c' to avoid confusion with a drive letter. On systems - with pure POSIX semantics, this is not an issue. */ - if (FILE_SYSTEM_PREFIX_LEN (base)) - { - char *p = xmalloc (length + 3); - p[0] = '.'; - p[1] = '/'; - memcpy (p + 2, base, length); - p[length + 2] = '\0'; - return p; - } - - /* Finally, copy the basename. */ - return xstrndup (base, length); -} - -/* Return the length of the basename NAME. Typically NAME is the - value returned by base_name or last_component. Act like strlen - (NAME), except omit all trailing slashes. */ - -size_t -base_len (char const *name) -{ - size_t len; - size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); - - for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) - continue; - - if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1 - && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2]) - return 2; - - if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len - && len == prefix_len && ISSLASH (name[prefix_len])) - return prefix_len + 1; - - return len; -} diff --git a/lib/dirname.c b/lib/dirname.c deleted file mode 100644 index 16552c6..0000000 --- a/lib/dirname.c +++ /dev/null @@ -1,85 +0,0 @@ -/* dirname.c -- return all but the last element in a file name - - Copyright (C) 1990, 1998, 2000, 2001, 2003, 2004, 2005, 2006 Free Software - Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include "dirname.h" - -#include -#include "xalloc.h" - -/* Return the length of the prefix of FILE that will be used by - dir_name. If FILE is in the working directory, this returns zero - even though `dir_name (FILE)' will return ".". Works properly even - if there are trailing slashes (by effectively ignoring them). */ - -size_t -dir_len (char const *file) -{ - size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file); - size_t length; - - /* Advance prefix_length beyond important leading slashes. */ - prefix_length += (prefix_length != 0 - ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE - && ISSLASH (file[prefix_length])) - : (ISSLASH (file[0]) - ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT - && ISSLASH (file[1]) && ! ISSLASH (file[2]) - ? 2 : 1)) - : 0)); - - /* Strip the basename and any redundant slashes before it. */ - for (length = last_component (file) - file; - prefix_length < length; length--) - if (! ISSLASH (file[length - 1])) - break; - return length; -} - - -/* In general, we can't use the builtin `dirname' function if available, - since it has different meanings in different environments. - In some environments the builtin `dirname' modifies its argument. - - Return the leading directories part of FILE, allocated with xmalloc. - Works properly even if there are trailing slashes (by effectively - ignoring them). Unlike POSIX dirname(), FILE cannot be NULL. - - If lstat (FILE) would succeed, then { chdir (dir_name (FILE)); - lstat (base_name (FILE)); } will access the same file. Likewise, - if the sequence { chdir (dir_name (FILE)); - rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE - to "foo" in the same directory FILE was in. */ - -char * -dir_name (char const *file) -{ - size_t length = dir_len (file); - bool append_dot = (length == 0 - || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE - && length == FILE_SYSTEM_PREFIX_LEN (file) - && file[2] != '\0' && ! ISSLASH (file[2]))); - char *dir = xmalloc (length + append_dot + 1); - memcpy (dir, file, length); - if (append_dot) - dir[length++] = '.'; - dir[length] = '\0'; - return dir; -} diff --git a/lib/dirname.h b/lib/dirname.h deleted file mode 100644 index 91e7ed3..0000000 --- a/lib/dirname.h +++ /dev/null @@ -1,70 +0,0 @@ -/* Take file names apart into directory and base names. - - Copyright (C) 1998, 2001, 2003-2006 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef DIRNAME_H_ -# define DIRNAME_H_ 1 - -# include -# include - -# ifndef DIRECTORY_SEPARATOR -# define DIRECTORY_SEPARATOR '/' -# endif - -# ifndef ISSLASH -# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) -# endif - -# ifndef FILE_SYSTEM_PREFIX_LEN -# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX - /* This internal macro assumes ASCII, but all hosts that support drive - letters use ASCII. */ -# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \ - <= 'z' - 'a') -# define FILE_SYSTEM_PREFIX_LEN(Filename) \ - (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) -# else -# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 -# endif -# endif - -# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE -# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 -# endif - -# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT -# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 -# endif - -# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE -# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) -# else -# define IS_ABSOLUTE_FILE_NAME(F) \ - (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) -# endif -# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) - -char *base_name (char const *file); -char *dir_name (char const *file); -size_t base_len (char const *file); -size_t dir_len (char const *file); -char *last_component (char const *file); - -bool strip_trailing_slashes (char *file); - -#endif /* not DIRNAME_H_ */ diff --git a/lib/error.c b/lib/error.c deleted file mode 100644 index 9cf67ff..0000000 --- a/lib/error.c +++ /dev/null @@ -1,339 +0,0 @@ -/* Error handler for noninteractive utilities - Copyright (C) 1990-1998, 2000-2007 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Written by David MacKenzie . */ - -#if !_LIBC -# include -#endif - -#include "error.h" - -#include -#include -#include -#include - -#if !_LIBC && ENABLE_NLS -# include "gettext.h" -# define _(msgid) gettext (msgid) -#endif - -#ifdef _LIBC -# include -# include -# include -# include -# define mbsrtowcs __mbsrtowcs -#endif - -#if USE_UNLOCKED_IO -# include "unlocked-io.h" -#endif - -#ifndef _ -# define _(String) String -#endif - -/* If NULL, error will flush stdout, then print on stderr the program - name, a colon and a space. Otherwise, error will call this - function without parameters instead. */ -void (*error_print_progname) (void); - -/* This variable is incremented each time `error' is called. */ -unsigned int error_message_count; - -#ifdef _LIBC -/* In the GNU C library, there is a predefined variable for this. */ - -# define program_name program_invocation_name -# include -# include -# include - -/* In GNU libc we want do not want to use the common name `error' directly. - Instead make it a weak alias. */ -extern void __error (int status, int errnum, const char *message, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); -extern void __error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, - ...) - __attribute__ ((__format__ (__printf__, 5, 6)));; -# define error __error -# define error_at_line __error_at_line - -# include -# define fflush(s) INTUSE(_IO_fflush) (s) -# undef putc -# define putc(c, fp) INTUSE(_IO_putc) (c, fp) - -# include - -#else /* not _LIBC */ - -# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P -# ifndef HAVE_DECL_STRERROR_R -"this configure-time declaration test was not run" -# endif -char *strerror_r (); -# endif - -/* The calling program should define program_name and set it to the - name of the executing program. */ -extern char *program_name; - -# if HAVE_STRERROR_R || defined strerror_r -# define __strerror_r strerror_r -# endif /* HAVE_STRERROR_R || defined strerror_r */ -#endif /* not _LIBC */ - -static void -print_errno_message (int errnum) -{ - char const *s; - -#if defined HAVE_STRERROR_R || _LIBC - char errbuf[1024]; -# if STRERROR_R_CHAR_P || _LIBC - s = __strerror_r (errnum, errbuf, sizeof errbuf); -# else - if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) - s = errbuf; - else - s = 0; -# endif -#else - s = strerror (errnum); -#endif - -#if !_LIBC - if (! s) - s = _("Unknown system error"); -#endif - -#if _LIBC - __fxprintf (NULL, ": %s", s); -#else - fprintf (stderr, ": %s", s); -#endif -} - -static void -error_tail (int status, int errnum, const char *message, va_list args) -{ -#if _LIBC - if (_IO_fwide (stderr, 0) > 0) - { -# define ALLOCA_LIMIT 2000 - size_t len = strlen (message) + 1; - wchar_t *wmessage = NULL; - mbstate_t st; - size_t res; - const char *tmp; - bool use_malloc = false; - - while (1) - { - if (__libc_use_alloca (len * sizeof (wchar_t))) - wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); - else - { - if (!use_malloc) - wmessage = NULL; - - wchar_t *p = (wchar_t *) realloc (wmessage, - len * sizeof (wchar_t)); - if (p == NULL) - { - free (wmessage); - fputws_unlocked (L"out of memory\n", stderr); - return; - } - wmessage = p; - use_malloc = true; - } - - memset (&st, '\0', sizeof (st)); - tmp = message; - - res = mbsrtowcs (wmessage, &tmp, len, &st); - if (res != len) - break; - - if (__builtin_expect (len >= SIZE_MAX / 2, 0)) - { - /* This really should not happen if everything is fine. */ - res = (size_t) -1; - break; - } - - len *= 2; - } - - if (res == (size_t) -1) - { - /* The string cannot be converted. */ - if (use_malloc) - { - free (wmessage); - use_malloc = false; - } - wmessage = (wchar_t *) L"???"; - } - - __vfwprintf (stderr, wmessage, args); - - if (use_malloc) - free (wmessage); - } - else -#endif - vfprintf (stderr, message, args); - va_end (args); - - ++error_message_count; - if (errnum) - print_errno_message (errnum); -#if _LIBC - __fxprintf (NULL, "\n"); -#else - putc ('\n', stderr); -#endif - fflush (stderr); - if (status) - exit (status); -} - - -/* Print the program name and error message MESSAGE, which is a printf-style - format string with optional args. - If ERRNUM is nonzero, print its corresponding system error message. - Exit with status STATUS if it is nonzero. */ -void -error (int status, int errnum, const char *message, ...) -{ - va_list args; - -#if defined _LIBC && defined __libc_ptf_call - /* We do not want this call to be cut short by a thread - cancellation. Therefore disable cancellation for now. */ - int state = PTHREAD_CANCEL_ENABLE; - __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), - 0); -#endif - - fflush (stdout); -#ifdef _LIBC - _IO_flockfile (stderr); -#endif - if (error_print_progname) - (*error_print_progname) (); - else - { -#if _LIBC - __fxprintf (NULL, "%s: ", program_name); -#else - fprintf (stderr, "%s: ", program_name); -#endif - } - - va_start (args, message); - error_tail (status, errnum, message, args); - -#ifdef _LIBC - _IO_funlockfile (stderr); -# ifdef __libc_ptf_call - __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); -# endif -#endif -} - -/* Sometimes we want to have at most one error per line. This - variable controls whether this mode is selected or not. */ -int error_one_per_line; - -void -error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, ...) -{ - va_list args; - - if (error_one_per_line) - { - static const char *old_file_name; - static unsigned int old_line_number; - - if (old_line_number == line_number - && (file_name == old_file_name - || strcmp (old_file_name, file_name) == 0)) - /* Simply return and print nothing. */ - return; - - old_file_name = file_name; - old_line_number = line_number; - } - -#if defined _LIBC && defined __libc_ptf_call - /* We do not want this call to be cut short by a thread - cancellation. Therefore disable cancellation for now. */ - int state = PTHREAD_CANCEL_ENABLE; - __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), - 0); -#endif - - fflush (stdout); -#ifdef _LIBC - _IO_flockfile (stderr); -#endif - if (error_print_progname) - (*error_print_progname) (); - else - { -#if _LIBC - __fxprintf (NULL, "%s:", program_name); -#else - fprintf (stderr, "%s:", program_name); -#endif - } - -#if _LIBC - __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", - file_name, line_number); -#else - fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", - file_name, line_number); -#endif - - va_start (args, message); - error_tail (status, errnum, message, args); - -#ifdef _LIBC - _IO_funlockfile (stderr); -# ifdef __libc_ptf_call - __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); -# endif -#endif -} - -#ifdef _LIBC -/* Make the weak alias. */ -# undef error -# undef error_at_line -weak_alias (__error, error) -weak_alias (__error_at_line, error_at_line) -#endif diff --git a/lib/error.h b/lib/error.h deleted file mode 100644 index 5a5f247..0000000 --- a/lib/error.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Declaration for error-reporting function - Copyright (C) 1995, 1996, 1997, 2003, 2006 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _ERROR_H -#define _ERROR_H 1 - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Print a message with `fprintf (stderr, FORMAT, ...)'; - if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). - If STATUS is nonzero, terminate the program with `exit (STATUS)'. */ - -extern void error (int __status, int __errnum, const char *__format, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); - -extern void error_at_line (int __status, int __errnum, const char *__fname, - unsigned int __lineno, const char *__format, ...) - __attribute__ ((__format__ (__printf__, 5, 6))); - -/* If NULL, error will flush stdout, then print on stderr the program - name, a colon and a space. Otherwise, error will call this - function without parameters instead. */ -extern void (*error_print_progname) (void); - -/* This variable is incremented each time `error' is called. */ -extern unsigned int error_message_count; - -/* Sometimes we want to have at most one error per line. This - variable controls whether this mode is selected or not. */ -extern int error_one_per_line; - -#ifdef __cplusplus -} -#endif - -#endif /* error.h */ diff --git a/lib/exitfail.c b/lib/exitfail.c deleted file mode 100644 index 373d325..0000000 --- a/lib/exitfail.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Failure exit status - - Copyright (C) 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc. - - 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 2, 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; see the file COPYING. - If not, write to the Free Software Foundation, - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include "exitfail.h" - -#include - -int volatile exit_failure = EXIT_FAILURE; diff --git a/lib/exitfail.h b/lib/exitfail.h deleted file mode 100644 index e46cf9c..0000000 --- a/lib/exitfail.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Failure exit status - - Copyright (C) 2002 Free Software Foundation, Inc. - - 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 2, 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; see the file COPYING. - If not, write to the Free Software Foundation, - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -extern int volatile exit_failure; diff --git a/lib/float+.h b/lib/float+.h deleted file mode 100644 index 4de25a9..0000000 --- a/lib/float+.h +++ /dev/null @@ -1,148 +0,0 @@ -/* Supplemental information about the floating-point formats. - Copyright (C) 2007 Free Software Foundation, Inc. - Written by Bruno Haible , 2007. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _FLOATPLUS_H -#define _FLOATPLUS_H - -#include -#include - -/* Number of bits in the mantissa of a floating-point number, including the - "hidden bit". */ -#if FLT_RADIX == 2 -# define FLT_MANT_BIT FLT_MANT_DIG -# define DBL_MANT_BIT DBL_MANT_DIG -# define LDBL_MANT_BIT LDBL_MANT_DIG -#elif FLT_RADIX == 4 -# define FLT_MANT_BIT (FLT_MANT_DIG * 2) -# define DBL_MANT_BIT (DBL_MANT_DIG * 2) -# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2) -#elif FLT_RADIX == 16 -# define FLT_MANT_BIT (FLT_MANT_DIG * 4) -# define DBL_MANT_BIT (DBL_MANT_DIG * 4) -# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4) -#endif - -/* Bit mask that can be used to mask the exponent, as an unsigned number. */ -#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7) -#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7) -#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7) - -/* Number of bits used for the exponent of a floating-point number, including - the exponent's sign. */ -#define FLT_EXP_BIT \ - (FLT_EXP_MASK < 0x100 ? 8 : \ - FLT_EXP_MASK < 0x200 ? 9 : \ - FLT_EXP_MASK < 0x400 ? 10 : \ - FLT_EXP_MASK < 0x800 ? 11 : \ - FLT_EXP_MASK < 0x1000 ? 12 : \ - FLT_EXP_MASK < 0x2000 ? 13 : \ - FLT_EXP_MASK < 0x4000 ? 14 : \ - FLT_EXP_MASK < 0x8000 ? 15 : \ - FLT_EXP_MASK < 0x10000 ? 16 : \ - FLT_EXP_MASK < 0x20000 ? 17 : \ - FLT_EXP_MASK < 0x40000 ? 18 : \ - FLT_EXP_MASK < 0x80000 ? 19 : \ - FLT_EXP_MASK < 0x100000 ? 20 : \ - FLT_EXP_MASK < 0x200000 ? 21 : \ - FLT_EXP_MASK < 0x400000 ? 22 : \ - FLT_EXP_MASK < 0x800000 ? 23 : \ - FLT_EXP_MASK < 0x1000000 ? 24 : \ - FLT_EXP_MASK < 0x2000000 ? 25 : \ - FLT_EXP_MASK < 0x4000000 ? 26 : \ - FLT_EXP_MASK < 0x8000000 ? 27 : \ - FLT_EXP_MASK < 0x10000000 ? 28 : \ - FLT_EXP_MASK < 0x20000000 ? 29 : \ - FLT_EXP_MASK < 0x40000000 ? 30 : \ - FLT_EXP_MASK <= 0x7fffffff ? 31 : \ - 32) -#define DBL_EXP_BIT \ - (DBL_EXP_MASK < 0x100 ? 8 : \ - DBL_EXP_MASK < 0x200 ? 9 : \ - DBL_EXP_MASK < 0x400 ? 10 : \ - DBL_EXP_MASK < 0x800 ? 11 : \ - DBL_EXP_MASK < 0x1000 ? 12 : \ - DBL_EXP_MASK < 0x2000 ? 13 : \ - DBL_EXP_MASK < 0x4000 ? 14 : \ - DBL_EXP_MASK < 0x8000 ? 15 : \ - DBL_EXP_MASK < 0x10000 ? 16 : \ - DBL_EXP_MASK < 0x20000 ? 17 : \ - DBL_EXP_MASK < 0x40000 ? 18 : \ - DBL_EXP_MASK < 0x80000 ? 19 : \ - DBL_EXP_MASK < 0x100000 ? 20 : \ - DBL_EXP_MASK < 0x200000 ? 21 : \ - DBL_EXP_MASK < 0x400000 ? 22 : \ - DBL_EXP_MASK < 0x800000 ? 23 : \ - DBL_EXP_MASK < 0x1000000 ? 24 : \ - DBL_EXP_MASK < 0x2000000 ? 25 : \ - DBL_EXP_MASK < 0x4000000 ? 26 : \ - DBL_EXP_MASK < 0x8000000 ? 27 : \ - DBL_EXP_MASK < 0x10000000 ? 28 : \ - DBL_EXP_MASK < 0x20000000 ? 29 : \ - DBL_EXP_MASK < 0x40000000 ? 30 : \ - DBL_EXP_MASK <= 0x7fffffff ? 31 : \ - 32) -#define LDBL_EXP_BIT \ - (LDBL_EXP_MASK < 0x100 ? 8 : \ - LDBL_EXP_MASK < 0x200 ? 9 : \ - LDBL_EXP_MASK < 0x400 ? 10 : \ - LDBL_EXP_MASK < 0x800 ? 11 : \ - LDBL_EXP_MASK < 0x1000 ? 12 : \ - LDBL_EXP_MASK < 0x2000 ? 13 : \ - LDBL_EXP_MASK < 0x4000 ? 14 : \ - LDBL_EXP_MASK < 0x8000 ? 15 : \ - LDBL_EXP_MASK < 0x10000 ? 16 : \ - LDBL_EXP_MASK < 0x20000 ? 17 : \ - LDBL_EXP_MASK < 0x40000 ? 18 : \ - LDBL_EXP_MASK < 0x80000 ? 19 : \ - LDBL_EXP_MASK < 0x100000 ? 20 : \ - LDBL_EXP_MASK < 0x200000 ? 21 : \ - LDBL_EXP_MASK < 0x400000 ? 22 : \ - LDBL_EXP_MASK < 0x800000 ? 23 : \ - LDBL_EXP_MASK < 0x1000000 ? 24 : \ - LDBL_EXP_MASK < 0x2000000 ? 25 : \ - LDBL_EXP_MASK < 0x4000000 ? 26 : \ - LDBL_EXP_MASK < 0x8000000 ? 27 : \ - LDBL_EXP_MASK < 0x10000000 ? 28 : \ - LDBL_EXP_MASK < 0x20000000 ? 29 : \ - LDBL_EXP_MASK < 0x40000000 ? 30 : \ - LDBL_EXP_MASK <= 0x7fffffff ? 31 : \ - 32) - -/* Number of bits used for a floating-point number: the mantissa (not - counting the "hidden bit", since it may or may not be explicit), the - exponent, and the sign. */ -#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1) -#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1) -#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1) - -/* Number of bytes used for a floating-point number. - This can be smaller than the 'sizeof'. For example, on i386 systems, - 'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence - LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but - sizeof (long double) = 12 or = 16. */ -#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT) -#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT) -#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT) - -/* Verify that SIZEOF_FLT <= sizeof (float) etc. */ -typedef int verify_sizeof_flt[2 * (SIZEOF_FLT <= sizeof (float)) - 1]; -typedef int verify_sizeof_dbl[2 * (SIZEOF_DBL <= sizeof (double)) - 1]; -typedef int verify_sizeof_ldbl[2 * (SIZEOF_LDBL <= sizeof (long double)) - 1]; - -#endif /* _FLOATPLUS_H */ diff --git a/lib/float.in.h b/lib/float.in.h deleted file mode 100644 index d61d630..0000000 --- a/lib/float.in.h +++ /dev/null @@ -1,59 +0,0 @@ -/* A correct . - - Copyright (C) 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GL_FLOAT_H - -/* The include_next requires a split double-inclusion guard. */ -#@INCLUDE_NEXT@ @NEXT_FLOAT_H@ - -#ifndef _GL_FLOAT_H -#define _GL_FLOAT_H - -/* 'long double' properties. */ -#if defined __i386__ && defined __BEOS__ -/* Number of mantissa units, in base FLT_RADIX. */ -# undef LDBL_MANT_DIG -# define LDBL_MANT_DIG 64 -/* Number of decimal digits that is sufficient for representing a number. */ -# undef LDBL_DIG -# define LDBL_DIG 18 -/* x-1 where x is the smallest representable number > 1. */ -# undef LDBL_EPSILON -# define LDBL_EPSILON 1.0842021724855044340E-19L -/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */ -# undef LDBL_MIN_EXP -# define LDBL_MIN_EXP (-16381) -/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */ -# undef LDBL_MAX_EXP -# define LDBL_MAX_EXP 16384 -/* Minimum positive normalized number. */ -# undef LDBL_MIN -# define LDBL_MIN 3.3621031431120935063E-4932L -/* Maximum representable finite number. */ -# undef LDBL_MAX -# define LDBL_MAX 1.1897314953572317650E+4932L -/* Minimum e such that 10^e is in the range of normalized numbers. */ -# undef LDBL_MIN_10_EXP -# define LDBL_MIN_10_EXP (-4931) -/* Maximum e such that 10^e is in the range of representable finite numbers. */ -# undef LDBL_MAX_10_EXP -# define LDBL_MAX_10_EXP 4932 -#endif - -#endif /* _GL_FLOAT_H */ -#endif /* _GL_FLOAT_H */ diff --git a/lib/getopt.c b/lib/getopt.c deleted file mode 100644 index 3580ad8..0000000 --- a/lib/getopt.c +++ /dev/null @@ -1,1191 +0,0 @@ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to drepper@gnu.org - before changing it! - Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004,2006 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _LIBC -# include -#endif - -#include "getopt.h" - -#include -#include -#include -#include - -#ifdef __VMS -# include -#endif - -#ifdef _LIBC -# include -#else -# include "gettext.h" -# define _(msgid) gettext (msgid) -#endif - -#if defined _LIBC && defined USE_IN_LIBIO -# include -#endif - -#ifndef attribute_hidden -# define attribute_hidden -#endif - -/* Unlike standard Unix `getopt', functions like `getopt_long' - let the user intersperse the options with the other arguments. - - As `getopt_long' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Using `getopt' or setting the environment variable POSIXLY_CORRECT - disables permutation. - Then the application's behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "getopt_int.h" - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -/* 1003.2 says this must be 1 before any call. */ -int optind = 1; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int opterr = 1; - -/* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - -int optopt = '?'; - -/* Keep a global copy of all internal members of getopt_data. */ - -static struct _getopt_data getopt_data; - - -#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV -extern char *getenv (); -#endif - -#ifdef _LIBC -/* Stored original parameters. - XXX This is no good solution. We should rather copy the args so - that we can compare them later. But we must not use malloc(3). */ -extern int __libc_argc; -extern char **__libc_argv; - -/* Bash 2.0 gives us an environment variable containing flags - indicating ARGV elements that should not be considered arguments. */ - -# ifdef USE_NONOPTION_FLAGS -/* Defined in getopt_init.c */ -extern char *__getopt_nonoption_flags; -# endif - -# ifdef USE_NONOPTION_FLAGS -# define SWAP_FLAGS(ch1, ch2) \ - if (d->__nonoption_flags_len > 0) \ - { \ - char __tmp = __getopt_nonoption_flags[ch1]; \ - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ - __getopt_nonoption_flags[ch2] = __tmp; \ - } -# else -# define SWAP_FLAGS(ch1, ch2) -# endif -#else /* !_LIBC */ -# define SWAP_FLAGS(ch1, ch2) -#endif /* _LIBC */ - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -static void -exchange (char **argv, struct _getopt_data *d) -{ - int bottom = d->__first_nonopt; - int middle = d->__last_nonopt; - int top = d->optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - -#if defined _LIBC && defined USE_NONOPTION_FLAGS - /* First make sure the handling of the `__getopt_nonoption_flags' - string can work normally. Our top argument must be in the range - of the string. */ - if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len) - { - /* We must extend the array. The user plays games with us and - presents new arguments. */ - char *new_str = malloc (top + 1); - if (new_str == NULL) - d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0; - else - { - memset (__mempcpy (new_str, __getopt_nonoption_flags, - d->__nonoption_flags_max_len), - '\0', top + 1 - d->__nonoption_flags_max_len); - d->__nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } - } -#endif - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - d->__first_nonopt += (d->optind - d->__last_nonopt); - d->__last_nonopt = d->optind; -} - -/* Initialize the internal data when the first call is made. */ - -static const char * -_getopt_initialize (int argc, char **argv, const char *optstring, - int posixly_correct, struct _getopt_data *d) -{ - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - d->__first_nonopt = d->__last_nonopt = d->optind; - - d->__nextchar = NULL; - - d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT"); - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - d->__ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - d->__ordering = REQUIRE_ORDER; - ++optstring; - } - else if (d->__posixly_correct) - d->__ordering = REQUIRE_ORDER; - else - d->__ordering = PERMUTE; - -#if defined _LIBC && defined USE_NONOPTION_FLAGS - if (!d->__posixly_correct - && argc == __libc_argc && argv == __libc_argv) - { - if (d->__nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL - || __getopt_nonoption_flags[0] == '\0') - d->__nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = d->__nonoption_flags_max_len = strlen (orig_str); - if (d->__nonoption_flags_max_len < argc) - d->__nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - (char *) malloc (d->__nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - d->__nonoption_flags_max_len = -1; - else - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), - '\0', d->__nonoption_flags_max_len - len); - } - } - d->__nonoption_flags_len = d->__nonoption_flags_max_len; - } - else - d->__nonoption_flags_len = 0; -#endif - - return optstring; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns -1. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. - - If POSIXLY_CORRECT is nonzero, behave as if the POSIXLY_CORRECT - environment variable were set. */ - -int -_getopt_internal_r (int argc, char **argv, const char *optstring, - const struct option *longopts, int *longind, - int long_only, int posixly_correct, struct _getopt_data *d) -{ - int print_errors = d->opterr; - if (optstring[0] == ':') - print_errors = 0; - - if (argc < 1) - return -1; - - d->optarg = NULL; - - if (d->optind == 0 || !d->__initialized) - { - if (d->optind == 0) - d->optind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = _getopt_initialize (argc, argv, optstring, - posixly_correct, d); - d->__initialized = 1; - } - - /* Test whether ARGV[optind] points to a non-option argument. - Either it does not have option syntax, or there is an environment flag - from the shell indicating it is not an option. The later information - is only used when the used in the GNU libc. */ -#if defined _LIBC && defined USE_NONOPTION_FLAGS -# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \ - || (d->optind < d->__nonoption_flags_len \ - && __getopt_nonoption_flags[d->optind] == '1')) -#else -# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0') -#endif - - if (d->__nextchar == NULL || *d->__nextchar == '\0') - { - /* Advance to the next ARGV-element. */ - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ - if (d->__last_nonopt > d->optind) - d->__last_nonopt = d->optind; - if (d->__first_nonopt > d->optind) - d->__first_nonopt = d->optind; - - if (d->__ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (d->__first_nonopt != d->__last_nonopt - && d->__last_nonopt != d->optind) - exchange ((char **) argv, d); - else if (d->__last_nonopt != d->optind) - d->__first_nonopt = d->optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (d->optind < argc && NONOPTION_P) - d->optind++; - d->__last_nonopt = d->optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (d->optind != argc && !strcmp (argv[d->optind], "--")) - { - d->optind++; - - if (d->__first_nonopt != d->__last_nonopt - && d->__last_nonopt != d->optind) - exchange ((char **) argv, d); - else if (d->__first_nonopt == d->__last_nonopt) - d->__first_nonopt = d->optind; - d->__last_nonopt = argc; - - d->optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (d->optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (d->__first_nonopt != d->__last_nonopt) - d->optind = d->__first_nonopt; - return -1; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if (NONOPTION_P) - { - if (d->__ordering == REQUIRE_ORDER) - return -1; - d->optarg = argv[d->optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - d->__nextchar = (argv[d->optind] + 1 - + (longopts != NULL && argv[d->optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[d->optind][1] == '-' - || (long_only && (argv[d->optind][2] - || !strchr (optstring, argv[d->optind][1]))))) - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) - { - if ((unsigned int) (nameend - d->__nextchar) - == (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else if (long_only - || pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[d->optind]) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[d->optind]); -#endif - } - d->__nextchar += strlen (d->__nextchar); - d->optind++; - d->optopt = 0; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - d->optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - d->optarg = nameend + 1; - else - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - int n; -#endif - - if (argv[d->optind - 1][1] == '-') - { - /* --option */ -#if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("\ -%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); -#else - fprintf (stderr, _("\ -%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); -#endif - } - else - { - /* +option or -option */ -#if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("\ -%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[d->optind - 1][0], - pfound->name); -#else - fprintf (stderr, _("\ -%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[d->optind - 1][0], - pfound->name); -#endif - } - -#if defined _LIBC && defined USE_IN_LIBIO - if (n >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#endif - } - - d->__nextchar += strlen (d->__nextchar); - - d->optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (d->optind < argc) - d->optarg = argv[d->optind++]; - else - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, _("\ -%s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]); -#endif - } - d->__nextchar += strlen (d->__nextchar); - d->optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->__nextchar += strlen (d->__nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[d->optind][1] == '-' - || strchr (optstring, *d->__nextchar) == NULL) - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - int n; -#endif - - if (argv[d->optind][1] == '-') - { - /* --option */ -#if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), - argv[0], d->__nextchar); -#else - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], d->__nextchar); -#endif - } - else - { - /* +option or -option */ -#if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[d->optind][0], d->__nextchar); -#else - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[d->optind][0], d->__nextchar); -#endif - } - -#if defined _LIBC && defined USE_IN_LIBIO - if (n >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#endif - } - d->__nextchar = (char *) ""; - d->optind++; - d->optopt = 0; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *d->__nextchar++; - char *temp = strchr (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*d->__nextchar == '\0') - ++d->optind; - - if (temp == NULL || c == ':') - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - int n; -#endif - - if (d->__posixly_correct) - { - /* 1003.2 specifies the format of this message. */ -#if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("%s: illegal option -- %c\n"), - argv[0], c); -#else - fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); -#endif - } - else - { -#if defined _LIBC && defined USE_IN_LIBIO - n = __asprintf (&buf, _("%s: invalid option -- %c\n"), - argv[0], c); -#else - fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); -#endif - } - -#if defined _LIBC && defined USE_IN_LIBIO - if (n >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#endif - } - d->optopt = c; - return '?'; - } - /* Convenience. Treat POSIX -W foo same as long option --foo */ - if (temp[0] == 'W' && temp[1] == ';') - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*d->__nextchar != '\0') - { - d->optarg = d->__nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - d->optind++; - } - else if (d->optind == argc) - { - if (print_errors) - { - /* 1003.2 specifies the format of this message. */ -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, - _("%s: option requires an argument -- %c\n"), - argv[0], c) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); -#endif - } - d->optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `d->optind' once; - increment it again when taking next ARGV-elt as argument. */ - d->optarg = argv[d->optind++]; - - /* optarg is now the argument, see if it's in the - table of longopts. */ - - for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '='; - nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar)) - { - if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[d->optind]) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[d->optind]); -#endif - } - d->__nextchar += strlen (d->__nextchar); - d->optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - d->optarg = nameend + 1; - else - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, _("\ -%s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, _("\ -%s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); -#endif - } - - d->__nextchar += strlen (d->__nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (d->optind < argc) - d->optarg = argv[d->optind++]; - else - { - if (print_errors) - { -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, _("\ -%s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 - |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[d->optind - 1]); -#endif - } - d->__nextchar += strlen (d->__nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - d->__nextchar += strlen (d->__nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - d->__nextchar = NULL; - return 'W'; /* Let the application handle it. */ - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*d->__nextchar != '\0') - { - d->optarg = d->__nextchar; - d->optind++; - } - else - d->optarg = NULL; - d->__nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*d->__nextchar != '\0') - { - d->optarg = d->__nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - d->optind++; - } - else if (d->optind == argc) - { - if (print_errors) - { - /* 1003.2 specifies the format of this message. */ -#if defined _LIBC && defined USE_IN_LIBIO - char *buf; - - if (__asprintf (&buf, _("\ -%s: option requires an argument -- %c\n"), - argv[0], c) >= 0) - { - _IO_flockfile (stderr); - - int old_flags2 = ((_IO_FILE *) stderr)->_flags2; - ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL; - - __fxprintf (NULL, "%s", buf); - - ((_IO_FILE *) stderr)->_flags2 = old_flags2; - _IO_funlockfile (stderr); - - free (buf); - } -#else - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); -#endif - } - d->optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - d->optarg = argv[d->optind++]; - d->__nextchar = NULL; - } - } - return c; - } -} - -int -_getopt_internal (int argc, char **argv, const char *optstring, - const struct option *longopts, int *longind, - int long_only, int posixly_correct) -{ - int result; - - getopt_data.optind = optind; - getopt_data.opterr = opterr; - - result = _getopt_internal_r (argc, argv, optstring, longopts, longind, - long_only, posixly_correct, &getopt_data); - - optind = getopt_data.optind; - optarg = getopt_data.optarg; - optopt = getopt_data.optopt; - - return result; -} - -/* glibc gets a LSB-compliant getopt. - Standalone applications get a POSIX-compliant getopt. */ -#if _LIBC -enum { POSIXLY_CORRECT = 0 }; -#else -enum { POSIXLY_CORRECT = 1 }; -#endif - -int -getopt (int argc, char *const *argv, const char *optstring) -{ - return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0, - POSIXLY_CORRECT); -} - - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - -int -main (int argc, char **argv) -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == -1) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/lib/getopt.in.h b/lib/getopt.in.h deleted file mode 100644 index 615ef9a..0000000 --- a/lib/getopt.in.h +++ /dev/null @@ -1,226 +0,0 @@ -/* Declarations for getopt. - Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GETOPT_H - -#ifndef __need_getopt -# define _GETOPT_H 1 -#endif - -/* Standalone applications should #define __GETOPT_PREFIX to an - identifier that prefixes the external functions and variables - defined in this header. When this happens, include the - headers that might declare getopt so that they will not cause - confusion if included after this file. Then systematically rename - identifiers so that they do not collide with the system functions - and variables. Renaming avoids problems with some compilers and - linkers. */ -#if defined __GETOPT_PREFIX && !defined __need_getopt -# include -# include -# include -# undef __need_getopt -# undef getopt -# undef getopt_long -# undef getopt_long_only -# undef optarg -# undef opterr -# undef optind -# undef optopt -# define __GETOPT_CONCAT(x, y) x ## y -# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) -# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) -# define getopt __GETOPT_ID (getopt) -# define getopt_long __GETOPT_ID (getopt_long) -# define getopt_long_only __GETOPT_ID (getopt_long_only) -# define optarg __GETOPT_ID (optarg) -# define opterr __GETOPT_ID (opterr) -# define optind __GETOPT_ID (optind) -# define optopt __GETOPT_ID (optopt) -#endif - -/* Standalone applications get correct prototypes for getopt_long and - getopt_long_only; they declare "char **argv". libc uses prototypes - with "char *const *argv" that are incorrect because getopt_long and - getopt_long_only can permute argv; this is required for backward - compatibility (e.g., for LSB 2.0.1). - - This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt', - but it caused redefinition warnings if both unistd.h and getopt.h were - included, since unistd.h includes getopt.h having previously defined - __need_getopt. - - The only place where __getopt_argv_const is used is in definitions - of getopt_long and getopt_long_only below, but these are visible - only if __need_getopt is not defined, so it is quite safe to rewrite - the conditional as follows: -*/ -#if !defined __need_getopt -# if defined __GETOPT_PREFIX -# define __getopt_argv_const /* empty */ -# else -# define __getopt_argv_const const -# endif -#endif - -/* If __GNU_LIBRARY__ is not already defined, either we are being used - standalone, or this is the first header included in the source file. - If we are being used with glibc, we need to include , but - that does not exist if we are standalone. So: if __GNU_LIBRARY__ is - not defined, include , which will pull in for us - if it's from glibc. (Why ctype.h? It's guaranteed to exist and it - doesn't flood the namespace with stuff the way some other headers do.) */ -#if !defined __GNU_LIBRARY__ -# include -#endif - -#ifndef __THROW -# ifndef __GNUC_PREREQ -# define __GNUC_PREREQ(maj, min) (0) -# endif -# if defined __cplusplus && __GNUC_PREREQ (2,8) -# define __THROW throw () -# else -# define __THROW -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -extern int opterr; - -/* Set to an option character which was unrecognized. */ - -extern int optopt; - -#ifndef __need_getopt -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct option'. */ - -# define no_argument 0 -# define required_argument 1 -# define optional_argument 2 -#endif /* need getopt */ - - -/* Get definitions and prototypes for functions to process the - arguments in ARGV (ARGC of them, minus the program name) for - options given in OPTS. - - Return the option character from OPTS just read. Return -1 when - there are no more options. For unrecognized options, or options - missing arguments, `optopt' is set to the option letter, and '?' is - returned. - - The OPTS string is a list of characters which are recognized option - letters, optionally followed by colons, specifying that that letter - takes an argument, to be placed in `optarg'. - - If a letter in OPTS is followed by two colons, its argument is - optional. This behavior is specific to the GNU `getopt'. - - The argument `--' causes premature termination of argument - scanning, explicitly telling `getopt' that there are no more - options. - - If OPTS begins with `-', then non-option arguments are treated as - arguments to the option '\1'. This behavior is specific to the GNU - `getopt'. If OPTS begins with `+', or POSIXLY_CORRECT is set in - the environment, then do not permute arguments. */ - -extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) - __THROW; - -#ifndef __need_getopt -extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind) - __THROW; -extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind) - __THROW; - -#endif - -#ifdef __cplusplus -} -#endif - -/* Make sure we later can get all the definitions and declarations. */ -#undef __need_getopt - -#endif /* getopt.h */ diff --git a/lib/getopt1.c b/lib/getopt1.c deleted file mode 100644 index cc0746e..0000000 --- a/lib/getopt1.c +++ /dev/null @@ -1,171 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef _LIBC -# include -#else -# include -# include "getopt.h" -#endif -#include "getopt_int.h" - -#include - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include -#endif - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, (char **) argv, options, long_options, - opt_index, 0, 0); -} - -int -_getopt_long_r (int argc, char **argv, const char *options, - const struct option *long_options, int *opt_index, - struct _getopt_data *d) -{ - return _getopt_internal_r (argc, argv, options, long_options, opt_index, - 0, 0, d); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (int argc, char *__getopt_argv_const *argv, - const char *options, - const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, (char **) argv, options, long_options, - opt_index, 1, 0); -} - -int -_getopt_long_only_r (int argc, char **argv, const char *options, - const struct option *long_options, int *opt_index, - struct _getopt_data *d) -{ - return _getopt_internal_r (argc, argv, options, long_options, opt_index, - 1, 0, d); -} - - -#ifdef TEST - -#include - -int -main (int argc, char **argv) -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/lib/getopt_int.h b/lib/getopt_int.h deleted file mode 100644 index 401579f..0000000 --- a/lib/getopt_int.h +++ /dev/null @@ -1,131 +0,0 @@ -/* Internal declarations for getopt. - Copyright (C) 1989-1994,1996-1999,2001,2003,2004 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GETOPT_INT_H -#define _GETOPT_INT_H 1 - -extern int _getopt_internal (int ___argc, char **___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - int __long_only, int __posixly_correct); - - -/* Reentrant versions which can handle parsing multiple argument - vectors at the same time. */ - -/* Data type for reentrant functions. */ -struct _getopt_data -{ - /* These have exactly the same meaning as the corresponding global - variables, except that they are used for the reentrant - versions of getopt. */ - int optind; - int opterr; - int optopt; - char *optarg; - - /* Internal members. */ - - /* True if the internal members have been initialized. */ - int __initialized; - - /* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - char *__nextchar; - - /* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters, or by calling getopt. - - PERMUTE is the default. We permute the contents of ARGV as we - scan, so that eventually all the non-options are at the end. - This allows options to be given in any order, even with programs - that were not written to expect this. - - RETURN_IN_ORDER is an option available to programs that were - written to expect options and other ARGV-elements in any order - and that care about the ordering of the two. We describe each - non-option ARGV-element as if it were the argument of an option - with character code 1. Using `-' as the first character of the - list of option characters selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return -1 with `optind' != ARGC. */ - - enum - { - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER - } __ordering; - - /* If the POSIXLY_CORRECT environment variable is set - or getopt was called. */ - int __posixly_correct; - - - /* Handle permutation of arguments. */ - - /* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first - of them; `last_nonopt' is the index after the last of them. */ - - int __first_nonopt; - int __last_nonopt; - -#if defined _LIBC && defined USE_NONOPTION_FLAGS - int __nonoption_flags_max_len; - int __nonoption_flags_len; -# endif -}; - -/* The initializer is necessary to set OPTIND and OPTERR to their - default values and to clear the initialization flag. */ -#define _GETOPT_DATA_INITIALIZER { 1, 1 } - -extern int _getopt_internal_r (int ___argc, char **___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - int __long_only, int __posixly_correct, - struct _getopt_data *__data); - -extern int _getopt_long_r (int ___argc, char **___argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - struct _getopt_data *__data); - -extern int _getopt_long_only_r (int ___argc, char **___argv, - const char *__shortopts, - const struct option *__longopts, - int *__longind, - struct _getopt_data *__data); - -#endif /* getopt_int.h */ diff --git a/lib/getsubopt.c b/lib/getsubopt.c deleted file mode 100644 index cc0859d..0000000 --- a/lib/getsubopt.c +++ /dev/null @@ -1,82 +0,0 @@ -/* Parse comma separated list into words. - Copyright (C) 1996, 1997, 1999, 2004, 2007 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#if !_LIBC -# include -#endif - -#include -#include - -#if !_LIBC -/* This code is written for inclusion in gnu-libc, and uses names in - the namespace reserved for libc. If we're compiling in gnulib, - define those names to be the normal ones instead. */ -# undef __strchrnul -# define __strchrnul strchrnul -#endif - -/* Parse comma separated suboption from *OPTIONP and match against - strings in TOKENS. If found return index and set *VALUEP to - optional value introduced by an equal sign. If the suboption is - not part of TOKENS return in *VALUEP beginning of unknown - suboption. On exit *OPTIONP is set to the beginning of the next - token or at the terminating NUL character. */ -int -getsubopt (char **optionp, char *const *tokens, char **valuep) -{ - char *endp, *vstart; - int cnt; - - if (**optionp == '\0') - return -1; - - /* Find end of next token. */ - endp = __strchrnul (*optionp, ','); - - /* Find start of value. */ - vstart = memchr (*optionp, '=', endp - *optionp); - if (vstart == NULL) - vstart = endp; - - /* Try to match the characters between *OPTIONP and VSTART against - one of the TOKENS. */ - for (cnt = 0; tokens[cnt] != NULL; ++cnt) - if (strncmp (*optionp, tokens[cnt], vstart - *optionp) == 0 - && tokens[cnt][vstart - *optionp] == '\0') - { - /* We found the current option in TOKENS. */ - *valuep = vstart != endp ? vstart + 1 : NULL; - - if (*endp != '\0') - *endp++ = '\0'; - *optionp = endp; - - return cnt; - } - - /* The current suboption does not match any option. */ - *valuep = *optionp; - - if (*endp != '\0') - *endp++ = '\0'; - *optionp = endp; - - return -1; -} diff --git a/lib/gettext.h b/lib/gettext.h deleted file mode 100644 index 9d76ec9..0000000 --- a/lib/gettext.h +++ /dev/null @@ -1,270 +0,0 @@ -/* Convenience header for conditional use of GNU . - Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _LIBGETTEXT_H -#define _LIBGETTEXT_H 1 - -/* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS - -/* Get declarations of GNU message catalog functions. */ -# include - -/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by - the gettext() and ngettext() macros. This is an alternative to calling - textdomain(), and is useful for libraries. */ -# ifdef DEFAULT_TEXT_DOMAIN -# undef gettext -# define gettext(Msgid) \ - dgettext (DEFAULT_TEXT_DOMAIN, Msgid) -# undef ngettext -# define ngettext(Msgid1, Msgid2, N) \ - dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N) -# endif - -#else - -/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which - chokes if dcgettext is defined as a macro. So include it now, to make - later inclusions of a NOP. We don't include - as well because people using "gettext.h" will not include , - and also including would fail on SunOS 4, whereas - is OK. */ -#if defined(__sun) -# include -#endif - -/* Many header files from the libstdc++ coming with g++ 3.3 or newer include - , which chokes if dcgettext is defined as a macro. So include - it now, to make later inclusions of a NOP. */ -#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) -# include -# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H -# include -# endif -#endif - -/* Disabled NLS. - The casts to 'const char *' serve the purpose of producing warnings - for invalid uses of the value returned from these functions. - On pre-ANSI systems without 'const', the config.h file is supposed to - contain "#define const". */ -# define gettext(Msgid) ((const char *) (Msgid)) -# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) -# define dcgettext(Domainname, Msgid, Category) \ - ((void) (Category), dgettext (Domainname, Msgid)) -# define ngettext(Msgid1, Msgid2, N) \ - ((N) == 1 \ - ? ((void) (Msgid2), (const char *) (Msgid1)) \ - : ((void) (Msgid1), (const char *) (Msgid2))) -# define dngettext(Domainname, Msgid1, Msgid2, N) \ - ((void) (Domainname), ngettext (Msgid1, Msgid2, N)) -# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ - ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N)) -# define textdomain(Domainname) ((const char *) (Domainname)) -# define bindtextdomain(Domainname, Dirname) \ - ((void) (Domainname), (const char *) (Dirname)) -# define bind_textdomain_codeset(Domainname, Codeset) \ - ((void) (Domainname), (const char *) (Codeset)) - -#endif - -/* A pseudo function call that serves as a marker for the automated - extraction of messages, but does not call gettext(). The run-time - translation is done at a different place in the code. - The argument, String, should be a literal string. Concatenated strings - and other string expressions won't work. - The macro's expansion is not parenthesized, so that it is suitable as - initializer for static 'char[]' or 'const char[]' variables. */ -#define gettext_noop(String) String - -/* The separator between msgctxt and msgid in a .mo file. */ -#define GETTEXT_CONTEXT_GLUE "\004" - -/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a - MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be - short and rarely need to change. - The letter 'p' stands for 'particular' or 'special'. */ -#ifdef DEFAULT_TEXT_DOMAIN -# define pgettext(Msgctxt, Msgid) \ - pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) -#else -# define pgettext(Msgctxt, Msgid) \ - pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) -#endif -#define dpgettext(Domainname, Msgctxt, Msgid) \ - pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES) -#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \ - pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category) -#ifdef DEFAULT_TEXT_DOMAIN -# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ - npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) -#else -# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \ - npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) -#endif -#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ - npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES) -#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \ - npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -pgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - int category) -{ - const char *translation = dcgettext (domain, msg_ctxt_id, category); - if (translation == msg_ctxt_id) - return msgid; - else - return translation; -} - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -npgettext_aux (const char *domain, - const char *msg_ctxt_id, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) -{ - const char *translation = - dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); - if (translation == msg_ctxt_id || translation == msgid_plural) - return (n == 1 ? msgid : msgid_plural); - else - return translation; -} - -/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID - can be arbitrary expressions. But for string literals these macros are - less efficient than those above. */ - -#include - -#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \ - (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \ - /* || __STDC_VERSION__ >= 199901L */ ) - -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS -#include -#endif - -#define pgettext_expr(Msgctxt, Msgid) \ - dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES) -#define dpgettext_expr(Domainname, Msgctxt, Msgid) \ - dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcgettext (domain, msg_ctxt_id, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (translation != msg_ctxt_id) - return translation; - } - return msgid; -} - -#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) -#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \ - dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES) - -#ifdef __GNUC__ -__inline -#else -#ifdef __cplusplus -inline -#endif -#endif -static const char * -dcnpgettext_expr (const char *domain, - const char *msgctxt, const char *msgid, - const char *msgid_plural, unsigned long int n, - int category) -{ - size_t msgctxt_len = strlen (msgctxt) + 1; - size_t msgid_len = strlen (msgid) + 1; - const char *translation; -#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; -#else - char buf[1024]; - char *msg_ctxt_id = - (msgctxt_len + msgid_len <= sizeof (buf) - ? buf - : (char *) malloc (msgctxt_len + msgid_len)); - if (msg_ctxt_id != NULL) -#endif - { - memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); - msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); -#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - if (msg_ctxt_id != buf) - free (msg_ctxt_id); -#endif - if (!(translation == msg_ctxt_id || translation == msgid_plural)) - return translation; - } - return (n == 1 ? msgid : msgid_plural); -} - -#endif /* _LIBGETTEXT_H */ diff --git a/lib/malloc.c b/lib/malloc.c deleted file mode 100644 index eba131d..0000000 --- a/lib/malloc.c +++ /dev/null @@ -1,57 +0,0 @@ -/* malloc() function that is glibc compatible. - - Copyright (C) 1997, 1998, 2006, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* written by Jim Meyering and Bruno Haible */ - -#include -/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */ -#ifdef malloc -# define NEED_MALLOC_GNU -# undef malloc -#endif - -/* Specification. */ -#include - -#include - -/* Call the system's malloc below. */ -#undef malloc - -/* Allocate an N-byte block of memory from the heap. - If N is zero, allocate a 1-byte block. */ - -void * -rpl_malloc (size_t n) -{ - void *result; - -#ifdef NEED_MALLOC_GNU - if (n == 0) - n = 1; -#endif - - result = malloc (n); - -#if !HAVE_MALLOC_POSIX - if (result == NULL) - errno = ENOMEM; -#endif - - return result; -} diff --git a/lib/mempcpy.c b/lib/mempcpy.c deleted file mode 100644 index 1c702c7..0000000 --- a/lib/mempcpy.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copy memory area and return pointer after last written byte. - Copyright (C) 2003, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include - -/* Copy N bytes of SRC to DEST, return pointer to bytes after the - last written byte. */ -void * -mempcpy (void *dest, const void *src, size_t n) -{ - return (char *) memcpy (dest, src, n) + n; -} diff --git a/lib/printf-args.c b/lib/printf-args.c deleted file mode 100644 index 4978914..0000000 --- a/lib/printf-args.c +++ /dev/null @@ -1,187 +0,0 @@ -/* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2005-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* This file can be parametrized with the following macros: - ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. - PRINTF_FETCHARGS Name of the function to be defined. - STATIC Set to 'static' to declare the function static. */ - -#ifndef PRINTF_FETCHARGS -# include -#endif - -/* Specification. */ -#ifndef PRINTF_FETCHARGS -# include "printf-args.h" -#endif - -#ifdef STATIC -STATIC -#endif -int -PRINTF_FETCHARGS (va_list args, arguments *a) -{ - size_t i; - argument *ap; - - for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) - switch (ap->type) - { - case TYPE_SCHAR: - ap->a.a_schar = va_arg (args, /*signed char*/ int); - break; - case TYPE_UCHAR: - ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); - break; - case TYPE_SHORT: - ap->a.a_short = va_arg (args, /*short*/ int); - break; - case TYPE_USHORT: - ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); - break; - case TYPE_INT: - ap->a.a_int = va_arg (args, int); - break; - case TYPE_UINT: - ap->a.a_uint = va_arg (args, unsigned int); - break; - case TYPE_LONGINT: - ap->a.a_longint = va_arg (args, long int); - break; - case TYPE_ULONGINT: - ap->a.a_ulongint = va_arg (args, unsigned long int); - break; -#if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - ap->a.a_longlongint = va_arg (args, long long int); - break; - case TYPE_ULONGLONGINT: - ap->a.a_ulonglongint = va_arg (args, unsigned long long int); - break; -#endif - case TYPE_DOUBLE: - ap->a.a_double = va_arg (args, double); - break; - case TYPE_LONGDOUBLE: - ap->a.a_longdouble = va_arg (args, long double); - break; - case TYPE_CHAR: - ap->a.a_char = va_arg (args, int); - break; -#if HAVE_WINT_T - case TYPE_WIDE_CHAR: - /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by - default argument promotions", this is not the case in mingw32, - where wint_t is 'unsigned short'. */ - ap->a.a_wide_char = - (sizeof (wint_t) < sizeof (int) - ? va_arg (args, int) - : va_arg (args, wint_t)); - break; -#endif - case TYPE_STRING: - ap->a.a_string = va_arg (args, const char *); - /* A null pointer is an invalid argument for "%s", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_string == NULL) - ap->a.a_string = "(NULL)"; - break; -#if HAVE_WCHAR_T - case TYPE_WIDE_STRING: - ap->a.a_wide_string = va_arg (args, const wchar_t *); - /* A null pointer is an invalid argument for "%ls", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_wide_string == NULL) - { - static const wchar_t wide_null_string[] = - { - (wchar_t)'(', - (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', - (wchar_t)')', - (wchar_t)0 - }; - ap->a.a_wide_string = wide_null_string; - } - break; -#endif - case TYPE_POINTER: - ap->a.a_pointer = va_arg (args, void *); - break; - case TYPE_COUNT_SCHAR_POINTER: - ap->a.a_count_schar_pointer = va_arg (args, signed char *); - break; - case TYPE_COUNT_SHORT_POINTER: - ap->a.a_count_short_pointer = va_arg (args, short *); - break; - case TYPE_COUNT_INT_POINTER: - ap->a.a_count_int_pointer = va_arg (args, int *); - break; - case TYPE_COUNT_LONGINT_POINTER: - ap->a.a_count_longint_pointer = va_arg (args, long int *); - break; -#if HAVE_LONG_LONG_INT - case TYPE_COUNT_LONGLONGINT_POINTER: - ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); - break; -#endif -#if ENABLE_UNISTDIO - /* The unistdio extensions. */ - case TYPE_U8_STRING: - ap->a.a_u8_string = va_arg (args, const uint8_t *); - /* A null pointer is an invalid argument for "%U", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u8_string == NULL) - { - static const uint8_t u8_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u8_string = u8_null_string; - } - break; - case TYPE_U16_STRING: - ap->a.a_u16_string = va_arg (args, const uint16_t *); - /* A null pointer is an invalid argument for "%lU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u16_string == NULL) - { - static const uint16_t u16_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u16_string = u16_null_string; - } - break; - case TYPE_U32_STRING: - ap->a.a_u32_string = va_arg (args, const uint32_t *); - /* A null pointer is an invalid argument for "%llU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u32_string == NULL) - { - static const uint32_t u32_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u32_string = u32_null_string; - } - break; -#endif - default: - /* Unknown type. */ - return -1; - } - return 0; -} diff --git a/lib/printf-args.h b/lib/printf-args.h deleted file mode 100644 index 6f75e2a..0000000 --- a/lib/printf-args.h +++ /dev/null @@ -1,154 +0,0 @@ -/* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _PRINTF_ARGS_H -#define _PRINTF_ARGS_H - -/* This file can be parametrized with the following macros: - ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. - PRINTF_FETCHARGS Name of the function to be declared. - STATIC Set to 'static' to declare the function static. */ - -/* Default parameters. */ -#ifndef PRINTF_FETCHARGS -# define PRINTF_FETCHARGS printf_fetchargs -#endif - -/* Get size_t. */ -#include - -/* Get wchar_t. */ -#if HAVE_WCHAR_T -# include -#endif - -/* Get wint_t. */ -#if HAVE_WINT_T -# include -#endif - -/* Get va_list. */ -#include - - -/* Argument types */ -typedef enum -{ - TYPE_NONE, - TYPE_SCHAR, - TYPE_UCHAR, - TYPE_SHORT, - TYPE_USHORT, - TYPE_INT, - TYPE_UINT, - TYPE_LONGINT, - TYPE_ULONGINT, -#if HAVE_LONG_LONG_INT - TYPE_LONGLONGINT, - TYPE_ULONGLONGINT, -#endif - TYPE_DOUBLE, - TYPE_LONGDOUBLE, - TYPE_CHAR, -#if HAVE_WINT_T - TYPE_WIDE_CHAR, -#endif - TYPE_STRING, -#if HAVE_WCHAR_T - TYPE_WIDE_STRING, -#endif - TYPE_POINTER, - TYPE_COUNT_SCHAR_POINTER, - TYPE_COUNT_SHORT_POINTER, - TYPE_COUNT_INT_POINTER, - TYPE_COUNT_LONGINT_POINTER -#if HAVE_LONG_LONG_INT -, TYPE_COUNT_LONGLONGINT_POINTER -#endif -#if ENABLE_UNISTDIO - /* The unistdio extensions. */ -, TYPE_U8_STRING -, TYPE_U16_STRING -, TYPE_U32_STRING -#endif -} arg_type; - -/* Polymorphic argument */ -typedef struct -{ - arg_type type; - union - { - signed char a_schar; - unsigned char a_uchar; - short a_short; - unsigned short a_ushort; - int a_int; - unsigned int a_uint; - long int a_longint; - unsigned long int a_ulongint; -#if HAVE_LONG_LONG_INT - long long int a_longlongint; - unsigned long long int a_ulonglongint; -#endif - float a_float; - double a_double; - long double a_longdouble; - int a_char; -#if HAVE_WINT_T - wint_t a_wide_char; -#endif - const char* a_string; -#if HAVE_WCHAR_T - const wchar_t* a_wide_string; -#endif - void* a_pointer; - signed char * a_count_schar_pointer; - short * a_count_short_pointer; - int * a_count_int_pointer; - long int * a_count_longint_pointer; -#if HAVE_LONG_LONG_INT - long long int * a_count_longlongint_pointer; -#endif -#if ENABLE_UNISTDIO - /* The unistdio extensions. */ - const uint8_t * a_u8_string; - const uint16_t * a_u16_string; - const uint32_t * a_u32_string; -#endif - } - a; -} -argument; - -typedef struct -{ - size_t count; - argument *arg; -} -arguments; - - -/* Fetch the arguments, putting them into a. */ -#ifdef STATIC -STATIC -#else -extern -#endif -int PRINTF_FETCHARGS (va_list args, arguments *a); - -#endif /* _PRINTF_ARGS_H */ diff --git a/lib/printf-parse.c b/lib/printf-parse.c deleted file mode 100644 index 2e67980..0000000 --- a/lib/printf-parse.c +++ /dev/null @@ -1,576 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999-2000, 2002-2003, 2006-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* This file can be parametrized with the following macros: - CHAR_T The element type of the format string. - CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters - in the format string are ASCII. - DIRECTIVE Structure denoting a format directive. - Depends on CHAR_T. - DIRECTIVES Structure denoting the set of format directives of a - format string. Depends on CHAR_T. - PRINTF_PARSE Function that parses a format string. - Depends on CHAR_T. - STATIC Set to 'static' to declare the function static. - ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */ - -#ifndef PRINTF_PARSE -# include -#endif - -/* Specification. */ -#ifndef PRINTF_PARSE -# include "printf-parse.h" -#endif - -/* Default parameters. */ -#ifndef PRINTF_PARSE -# define PRINTF_PARSE printf_parse -# define CHAR_T char -# define DIRECTIVE char_directive -# define DIRECTIVES char_directives -#endif - -/* Get size_t, NULL. */ -#include - -/* Get intmax_t. */ -#ifdef IN_LIBINTL -# if HAVE_STDINT_H_WITH_UINTMAX -# include -# endif -# if HAVE_INTTYPES_H_WITH_UINTMAX -# include -# endif -#else -# include -#endif - -/* malloc(), realloc(), free(). */ -#include - -/* Checked size_t computations. */ -#include "xsize.h" - -#if CHAR_T_ONLY_ASCII -/* c_isascii(). */ -# include "c-ctype.h" -#endif - -#ifdef STATIC -STATIC -#endif -int -PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) -{ - const CHAR_T *cp = format; /* pointer into format */ - size_t arg_posn = 0; /* number of regular arguments consumed */ - size_t d_allocated; /* allocated elements of d->dir */ - size_t a_allocated; /* allocated elements of a->arg */ - size_t max_width_length = 0; - size_t max_precision_length = 0; - - d->count = 0; - d_allocated = 1; - d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); - if (d->dir == NULL) - /* Out of memory. */ - return -1; - - a->count = 0; - a_allocated = 0; - a->arg = NULL; - -#define REGISTER_ARG(_index_,_type_) \ - { \ - size_t n = (_index_); \ - if (n >= a_allocated) \ - { \ - size_t memory_size; \ - argument *memory; \ - \ - a_allocated = xtimes (a_allocated, 2); \ - if (a_allocated <= n) \ - a_allocated = xsum (n, 1); \ - memory_size = xtimes (a_allocated, sizeof (argument)); \ - if (size_overflow_p (memory_size)) \ - /* Overflow, would lead to out of memory. */ \ - goto error; \ - memory = (argument *) (a->arg \ - ? realloc (a->arg, memory_size) \ - : malloc (memory_size)); \ - if (memory == NULL) \ - /* Out of memory. */ \ - goto error; \ - a->arg = memory; \ - } \ - while (a->count <= n) \ - a->arg[a->count++].type = TYPE_NONE; \ - if (a->arg[n].type == TYPE_NONE) \ - a->arg[n].type = (_type_); \ - else if (a->arg[n].type != (_type_)) \ - /* Ambiguous type for positional argument. */ \ - goto error; \ - } - - while (*cp != '\0') - { - CHAR_T c = *cp++; - if (c == '%') - { - size_t arg_index = ARG_NONE; - DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ - - /* Initialize the next directive. */ - dp->dir_start = cp - 1; - dp->flags = 0; - dp->width_start = NULL; - dp->width_end = NULL; - dp->width_arg_index = ARG_NONE; - dp->precision_start = NULL; - dp->precision_end = NULL; - dp->precision_arg_index = ARG_NONE; - dp->arg_index = ARG_NONE; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - arg_index = n - 1; - cp = np + 1; - } - } - - /* Read the flags. */ - for (;;) - { - if (*cp == '\'') - { - dp->flags |= FLAG_GROUP; - cp++; - } - else if (*cp == '-') - { - dp->flags |= FLAG_LEFT; - cp++; - } - else if (*cp == '+') - { - dp->flags |= FLAG_SHOWSIGN; - cp++; - } - else if (*cp == ' ') - { - dp->flags |= FLAG_SPACE; - cp++; - } - else if (*cp == '#') - { - dp->flags |= FLAG_ALT; - cp++; - } - else if (*cp == '0') - { - dp->flags |= FLAG_ZERO; - cp++; - } - else - break; - } - - /* Parse the field width. */ - if (*cp == '*') - { - dp->width_start = cp; - cp++; - dp->width_end = cp; - if (max_width_length < 1) - max_width_length = 1; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - dp->width_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->width_arg_index == ARG_NONE) - { - dp->width_arg_index = arg_posn++; - if (dp->width_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->width_arg_index, TYPE_INT); - } - else if (*cp >= '0' && *cp <= '9') - { - size_t width_length; - - dp->width_start = cp; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->width_end = cp; - width_length = dp->width_end - dp->width_start; - if (max_width_length < width_length) - max_width_length = width_length; - } - - /* Parse the precision. */ - if (*cp == '.') - { - cp++; - if (*cp == '*') - { - dp->precision_start = cp - 1; - cp++; - dp->precision_end = cp; - if (max_precision_length < 2) - max_precision_length = 2; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory - later. */ - goto error; - dp->precision_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->precision_arg_index == ARG_NONE) - { - dp->precision_arg_index = arg_posn++; - if (dp->precision_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->precision_arg_index, TYPE_INT); - } - else - { - size_t precision_length; - - dp->precision_start = cp - 1; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->precision_end = cp; - precision_length = dp->precision_end - dp->precision_start; - if (max_precision_length < precision_length) - max_precision_length = precision_length; - } - } - - { - arg_type type; - - /* Parse argument type/size specifiers. */ - { - int flags = 0; - - for (;;) - { - if (*cp == 'h') - { - flags |= (1 << (flags & 1)); - cp++; - } - else if (*cp == 'L') - { - flags |= 4; - cp++; - } - else if (*cp == 'l') - { - flags += 8; - cp++; - } - else if (*cp == 'j') - { - if (sizeof (intmax_t) > sizeof (long)) - { - /* intmax_t = long long */ - flags += 16; - } - else if (sizeof (intmax_t) > sizeof (int)) - { - /* intmax_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 'z' || *cp == 'Z') - { - /* 'z' is standardized in ISO C 99, but glibc uses 'Z' - because the warning facility in gcc-2.95.2 understands - only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ - if (sizeof (size_t) > sizeof (long)) - { - /* size_t = long long */ - flags += 16; - } - else if (sizeof (size_t) > sizeof (int)) - { - /* size_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 't') - { - if (sizeof (ptrdiff_t) > sizeof (long)) - { - /* ptrdiff_t = long long */ - flags += 16; - } - else if (sizeof (ptrdiff_t) > sizeof (int)) - { - /* ptrdiff_t = long */ - flags += 8; - } - cp++; - } - else - break; - } - - /* Read the conversion character. */ - c = *cp++; - switch (c) - { - case 'd': case 'i': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGLONGINT; - else -#endif - /* If 'long long' exists and is the same as 'long', we parse - "lld" into TYPE_LONGINT. */ - if (flags >= 8) - type = TYPE_LONGINT; - else if (flags & 2) - type = TYPE_SCHAR; - else if (flags & 1) - type = TYPE_SHORT; - else - type = TYPE_INT; - break; - case 'o': case 'u': case 'x': case 'X': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_ULONGLONGINT; - else -#endif - /* If 'unsigned long long' exists and is the same as - 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ - if (flags >= 8) - type = TYPE_ULONGINT; - else if (flags & 2) - type = TYPE_UCHAR; - else if (flags & 1) - type = TYPE_USHORT; - else - type = TYPE_UINT; - break; - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGDOUBLE; - else - type = TYPE_DOUBLE; - break; - case 'c': - if (flags >= 8) -#if HAVE_WINT_T - type = TYPE_WIDE_CHAR; -#else - goto error; -#endif - else - type = TYPE_CHAR; - break; -#if HAVE_WINT_T - case 'C': - type = TYPE_WIDE_CHAR; - c = 'c'; - break; -#endif - case 's': - if (flags >= 8) -#if HAVE_WCHAR_T - type = TYPE_WIDE_STRING; -#else - goto error; -#endif - else - type = TYPE_STRING; - break; -#if HAVE_WCHAR_T - case 'S': - type = TYPE_WIDE_STRING; - c = 's'; - break; -#endif - case 'p': - type = TYPE_POINTER; - break; - case 'n': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_COUNT_LONGLONGINT_POINTER; - else -#endif - /* If 'long long' exists and is the same as 'long', we parse - "lln" into TYPE_COUNT_LONGINT_POINTER. */ - if (flags >= 8) - type = TYPE_COUNT_LONGINT_POINTER; - else if (flags & 2) - type = TYPE_COUNT_SCHAR_POINTER; - else if (flags & 1) - type = TYPE_COUNT_SHORT_POINTER; - else - type = TYPE_COUNT_INT_POINTER; - break; -#if ENABLE_UNISTDIO - /* The unistdio extensions. */ - case 'U': - if (flags >= 16) - type = TYPE_U32_STRING; - else if (flags >= 8) - type = TYPE_U16_STRING; - else - type = TYPE_U8_STRING; - break; -#endif - case '%': - type = TYPE_NONE; - break; - default: - /* Unknown conversion character. */ - goto error; - } - } - - if (type != TYPE_NONE) - { - dp->arg_index = arg_index; - if (dp->arg_index == ARG_NONE) - { - dp->arg_index = arg_posn++; - if (dp->arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->arg_index, type); - } - dp->conversion = c; - dp->dir_end = cp; - } - - d->count++; - if (d->count >= d_allocated) - { - size_t memory_size; - DIRECTIVE *memory; - - d_allocated = xtimes (d_allocated, 2); - memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); - if (size_overflow_p (memory_size)) - /* Overflow, would lead to out of memory. */ - goto error; - memory = (DIRECTIVE *) realloc (d->dir, memory_size); - if (memory == NULL) - /* Out of memory. */ - goto error; - d->dir = memory; - } - } -#if CHAR_T_ONLY_ASCII - else if (!c_isascii (c)) - { - /* Non-ASCII character. Not supported. */ - goto error; - } -#endif - } - d->dir[d->count].dir_start = cp; - - d->max_width_length = max_width_length; - d->max_precision_length = max_precision_length; - return 0; - -error: - if (a->arg) - free (a->arg); - if (d->dir) - free (d->dir); - return -1; -} - -#undef PRINTF_PARSE -#undef DIRECTIVES -#undef DIRECTIVE -#undef CHAR_T_ONLY_ASCII -#undef CHAR_T diff --git a/lib/printf-parse.h b/lib/printf-parse.h deleted file mode 100644 index de7fc49..0000000 --- a/lib/printf-parse.h +++ /dev/null @@ -1,179 +0,0 @@ -/* Parse printf format string. - Copyright (C) 1999, 2002-2003, 2005, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _PRINTF_PARSE_H -#define _PRINTF_PARSE_H - -/* This file can be parametrized with the following macros: - ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. - STATIC Set to 'static' to declare the function static. */ - -#include "printf-args.h" - - -/* Flags */ -#define FLAG_GROUP 1 /* ' flag */ -#define FLAG_LEFT 2 /* - flag */ -#define FLAG_SHOWSIGN 4 /* + flag */ -#define FLAG_SPACE 8 /* space flag */ -#define FLAG_ALT 16 /* # flag */ -#define FLAG_ZERO 32 - -/* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) - -/* xxx_directive: A parsed directive. - xxx_directives: A parsed format string. */ - -/* A parsed directive. */ -typedef struct -{ - const char* dir_start; - const char* dir_end; - int flags; - const char* width_start; - const char* width_end; - size_t width_arg_index; - const char* precision_start; - const char* precision_end; - size_t precision_arg_index; - char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ - size_t arg_index; -} -char_directive; - -/* A parsed format string. */ -typedef struct -{ - size_t count; - char_directive *dir; - size_t max_width_length; - size_t max_precision_length; -} -char_directives; - -#if ENABLE_UNISTDIO - -/* A parsed directive. */ -typedef struct -{ - const uint8_t* dir_start; - const uint8_t* dir_end; - int flags; - const uint8_t* width_start; - const uint8_t* width_end; - size_t width_arg_index; - const uint8_t* precision_start; - const uint8_t* precision_end; - size_t precision_arg_index; - uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ - size_t arg_index; -} -u8_directive; - -/* A parsed format string. */ -typedef struct -{ - size_t count; - u8_directive *dir; - size_t max_width_length; - size_t max_precision_length; -} -u8_directives; - -/* A parsed directive. */ -typedef struct -{ - const uint16_t* dir_start; - const uint16_t* dir_end; - int flags; - const uint16_t* width_start; - const uint16_t* width_end; - size_t width_arg_index; - const uint16_t* precision_start; - const uint16_t* precision_end; - size_t precision_arg_index; - uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ - size_t arg_index; -} -u16_directive; - -/* A parsed format string. */ -typedef struct -{ - size_t count; - u16_directive *dir; - size_t max_width_length; - size_t max_precision_length; -} -u16_directives; - -/* A parsed directive. */ -typedef struct -{ - const uint32_t* dir_start; - const uint32_t* dir_end; - int flags; - const uint32_t* width_start; - const uint32_t* width_end; - size_t width_arg_index; - const uint32_t* precision_start; - const uint32_t* precision_end; - size_t precision_arg_index; - uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */ - size_t arg_index; -} -u32_directive; - -/* A parsed format string. */ -typedef struct -{ - size_t count; - u32_directive *dir; - size_t max_width_length; - size_t max_precision_length; -} -u32_directives; - -#endif - - -/* Parses the format string. Fills in the number N of directives, and fills - in directives[0], ..., directives[N-1], and sets directives[N].dir_start - to the end of the format string. Also fills in the arg_type fields of the - arguments and the needed count of arguments. */ -#if ENABLE_UNISTDIO -extern int - ulc_printf_parse (const char *format, char_directives *d, arguments *a); -extern int - u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a); -extern int - u16_printf_parse (const uint16_t *format, u16_directives *d, - arguments *a); -extern int - u32_printf_parse (const uint32_t *format, u32_directives *d, - arguments *a); -#else -# ifdef STATIC -STATIC -# else -extern -# endif -int printf_parse (const char *format, char_directives *d, arguments *a); -#endif - -#endif /* _PRINTF_PARSE_H */ diff --git a/lib/progname.c b/lib/progname.c deleted file mode 100644 index df52f60..0000000 --- a/lib/progname.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Program name management. - Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - - -#include - -/* Specification. */ -#undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */ -#include "progname.h" - -#include - - -/* String containing name the program is called with. - To be initialized by main(). */ -const char *program_name = NULL; - -/* Set program_name, based on argv[0]. */ -void -set_program_name (const char *argv0) -{ - /* libtool creates a temporary executable whose name is sometimes prefixed - with "lt-" (depends on the platform). It also makes argv[0] absolute. - Remove this "/.libs/" or "/.libs/lt-" prefix here. */ - const char *slash; - const char *base; - - slash = strrchr (argv0, '/'); - base = (slash != NULL ? slash + 1 : argv0); - if (base - argv0 >= 7 && memcmp (base - 7, "/.libs/", 7) == 0) - argv0 = base; - if (strncmp (base, "lt-", 3) == 0) - argv0 = base + 3; - program_name = argv0; -} diff --git a/lib/progname.h b/lib/progname.h deleted file mode 100644 index 206c2cc..0000000 --- a/lib/progname.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Program name management. - Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _PROGNAME_H -#define _PROGNAME_H - -/* Programs using this file should do the following in main(): - set_program_name (argv[0]); - */ - - -#ifdef __cplusplus -extern "C" { -#endif - - -/* String containing name the program is called with. */ -extern const char *program_name; - -/* Set program_name, based on argv[0]. */ -extern void set_program_name (const char *argv0); - -#if ENABLE_RELOCATABLE - -/* Set program_name, based on argv[0], and original installation prefix and - directory, for relocatability. */ -extern void set_program_name_and_installdir (const char *argv0, - const char *orig_installprefix, - const char *orig_installdir); -#undef set_program_name -#define set_program_name(ARG0) \ - set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR) - -/* Return the full pathname of the current executable, based on the earlier - call to set_program_name_and_installdir. Return NULL if unknown. */ -extern char *get_full_program_name (void); - -#endif - - -#ifdef __cplusplus -} -#endif - - -#endif /* _PROGNAME_H */ diff --git a/lib/size_max.h b/lib/size_max.h deleted file mode 100644 index ed0bc13..0000000 --- a/lib/size_max.h +++ /dev/null @@ -1,31 +0,0 @@ -/* size_max.h -- declare SIZE_MAX through system headers - Copyright (C) 2005-2006 Free Software Foundation, Inc. - Written by Simon Josefsson. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef GNULIB_SIZE_MAX_H -#define GNULIB_SIZE_MAX_H - -/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */ -# include -/* Get SIZE_MAX declaration on systems like glibc 2. */ -# if HAVE_STDINT_H -# include -# endif -/* On systems where these include files don't define it, SIZE_MAX is defined - in config.h. */ - -#endif /* GNULIB_SIZE_MAX_H */ diff --git a/lib/sleep.c b/lib/sleep.c deleted file mode 100644 index 037559b..0000000 --- a/lib/sleep.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Pausing execution of the current thread. - Copyright (C) 2007 Free Software Foundation, Inc. - Written by Bruno Haible , 2007. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - -# define WIN32_LEAN_AND_MEAN /* avoid including junk */ -# include - -unsigned int -sleep (unsigned int seconds) -{ - unsigned int remaining; - - /* Sleep for 1 second many times, because - 1. Sleep is not interruptiple by Ctrl-C, - 2. we want to avoid arithmetic overflow while multiplying with 1000. */ - for (remaining = seconds; remaining > 0; remaining--) - Sleep (1000); - - return remaining; -} - -#else - - #error "Please port gnulib sleep.c to your platform, possibly using usleep() or select(), then report this to bug-gnulib." - -#endif diff --git a/lib/stdbool.in.h b/lib/stdbool.in.h deleted file mode 100644 index 150a010..0000000 --- a/lib/stdbool.in.h +++ /dev/null @@ -1,118 +0,0 @@ -/* Copyright (C) 2001, 2002, 2003, 2006, 2007 Free Software Foundation, Inc. - Written by Bruno Haible , 2001. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GL_STDBOOL_H -#define _GL_STDBOOL_H - -/* ISO C 99 for platforms that lack it. */ - -/* Usage suggestions: - - Programs that use should be aware of some limitations - and standards compliance issues. - - Standards compliance: - - - must be #included before 'bool', 'false', 'true' - can be used. - - - You cannot assume that sizeof (bool) == 1. - - - Programs should not undefine the macros bool, true, and false, - as C99 lists that as an "obsolescent feature". - - Limitations of this substitute, when used in a C89 environment: - - - must be #included before the '_Bool' type can be used. - - - You cannot assume that _Bool is a typedef; it might be a macro. - - - Bit-fields of type 'bool' are not supported. Portable code - should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'. - - - In C99, casts and automatic conversions to '_Bool' or 'bool' are - performed in such a way that every nonzero value gets converted - to 'true', and zero gets converted to 'false'. This doesn't work - with this substitute. With this substitute, only the values 0 and 1 - give the expected result when converted to _Bool' or 'bool'. - - Also, it is suggested that programs use 'bool' rather than '_Bool'; - this isn't required, but 'bool' is more common. */ - - -/* 7.16. Boolean type and values */ - -/* BeOS already #defines false 0, true 1. We use the same - definitions below, but temporarily we have to #undef them. */ -#ifdef __BEOS__ -# include /* defines bool but not _Bool */ -# undef false -# undef true -#endif - -/* For the sake of symbolic names in gdb, we define true and false as - enum constants, not only as macros. - It is tempting to write - typedef enum { false = 0, true = 1 } _Bool; - so that gdb prints values of type 'bool' symbolically. But if we do - this, values of type '_Bool' may promote to 'int' or 'unsigned int' - (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int' - (see ISO C 99 6.3.1.1.(2)). So we add a negative value to the - enum; this ensures that '_Bool' promotes to 'int'. */ -#if defined __cplusplus || defined __BEOS__ - /* A compiler known to have 'bool'. */ - /* If the compiler already has both 'bool' and '_Bool', we can assume they - are the same types. */ -# if !@HAVE__BOOL@ -typedef bool _Bool; -# endif -#else -# if !defined __GNUC__ - /* If @HAVE__BOOL@: - Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when - the built-in _Bool type is used. See - http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html - http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html - http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html - Similar bugs are likely with other compilers as well; this file - wouldn't be used if was working. - So we override the _Bool type. - If !@HAVE__BOOL@: - Need to define _Bool ourselves. As 'signed char' or as an enum type? - Use of a typedef, with SunPRO C, leads to a stupid - "warning: _Bool is a keyword in ISO C99". - Use of an enum type, with IRIX cc, leads to a stupid - "warning(1185): enumerated type mixed with another type". - The only benefit of the enum type, debuggability, is not important - with these compilers. So use 'signed char' and no typedef. */ -# define _Bool signed char -enum { false = 0, true = 1 }; -# else - /* With this compiler, trust the _Bool type if the compiler has it. */ -# if !@HAVE__BOOL@ -typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool; -# endif -# endif -#endif -#define bool _Bool - -/* The other macros must be usable in preprocessor directives. */ -#define false 0 -#define true 1 -#define __bool_true_false_are_defined 1 - -#endif /* _GL_STDBOOL_H */ diff --git a/lib/stdint.in.h b/lib/stdint.in.h deleted file mode 100644 index 121118c..0000000 --- a/lib/stdint.in.h +++ /dev/null @@ -1,508 +0,0 @@ -/* Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc. - Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. - This file is part of gnulib. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* - * ISO C 99 for platforms that lack it. - * - */ - -#ifndef _GL_STDINT_H - -/* Get those types that are already defined in other system include - files, so that we can "#define int8_t signed char" below without - worrying about a later system include file containing a "typedef - signed char int8_t;" that will get messed up by our macro. Our - macros should all be consistent with the system versions, except - for the "fast" types and macros, which we recommend against using - in public interfaces due to compiler differences. */ - -#if @HAVE_STDINT_H@ -# if defined __sgi && ! defined __c99 - /* Bypass IRIX's if in C89 mode, since it merely annoys users - with "This header file is to be used only for c99 mode compilations" - diagnostics. */ -# define __STDINT_H__ -# endif - /* Other systems may have an incomplete or buggy . - Include it before , since any "#include " - in would reinclude us, skipping our contents because - _GL_STDINT_H is defined. - The include_next requires a split double-inclusion guard. */ -# @INCLUDE_NEXT@ @NEXT_STDINT_H@ -#endif - -#if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H -#define _GL_STDINT_H - -/* defines some of the stdint.h types as well, on glibc, - IRIX 6.5, and OpenBSD 3.8 (via ). - AIX 5.2 isn't needed and causes troubles. - MacOS X 10.4.6 includes (which is us), but - relies on the system definitions, so include - after @NEXT_STDINT_H@. */ -#if @HAVE_SYS_TYPES_H@ && ! defined _AIX -# include -#endif - -/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */ -#include - -#if @HAVE_INTTYPES_H@ - /* In OpenBSD 3.8, includes , which defines - int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. - also defines intptr_t and uintptr_t. */ -# define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H -# include -# undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H -#elif @HAVE_SYS_INTTYPES_H@ - /* Solaris 7 has the types except the *_fast*_t types, and - the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ -# include -#endif - -#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ - /* Linux libc4 >= 4.6.7 and libc5 have a that defines - int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is - included by . */ -# include -#endif - -#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS - -/* Get WCHAR_MIN, WCHAR_MAX. */ -# if ! (defined WCHAR_MIN && defined WCHAR_MAX) -# include -# endif - -#endif - -/* Minimum and maximum values for a integer type under the usual assumption. - Return an unspecified value if BITS == 0, adding a check to pacify - picky compilers. */ - -#define _STDINT_MIN(signed, bits, zero) \ - ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) - -#define _STDINT_MAX(signed, bits, zero) \ - ((signed) \ - ? ~ _STDINT_MIN (signed, bits, zero) \ - : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1) - -/* 7.18.1.1. Exact-width integer types */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits. */ - -#undef int8_t -#undef uint8_t -#define int8_t signed char -#define uint8_t unsigned char - -#undef int16_t -#undef uint16_t -#define int16_t short int -#define uint16_t unsigned short int - -#undef int32_t -#undef uint32_t -#define int32_t int -#define uint32_t unsigned int - -/* Do not undefine int64_t if gnulib is not being used with 64-bit - types, since otherwise it breaks platforms like Tandem/NSK. */ -#if LONG_MAX >> 31 >> 31 == 1 -# undef int64_t -# define int64_t long int -# define GL_INT64_T -#elif defined _MSC_VER -# undef int64_t -# define int64_t __int64 -# define GL_INT64_T -#elif @HAVE_LONG_LONG_INT@ -# undef int64_t -# define int64_t long long int -# define GL_INT64_T -#endif - -#if ULONG_MAX >> 31 >> 31 >> 1 == 1 -# undef uint64_t -# define uint64_t unsigned long int -# define GL_UINT64_T -#elif defined _MSC_VER -# undef uint64_t -# define uint64_t unsigned __int64 -# define GL_UINT64_T -#elif @HAVE_UNSIGNED_LONG_LONG_INT@ -# undef uint64_t -# define uint64_t unsigned long long int -# define GL_UINT64_T -#endif - -/* Avoid collision with Solaris 2.5.1 etc. */ -#define _UINT8_T -#define _UINT32_T -#define _UINT64_T - - -/* 7.18.1.2. Minimum-width integer types */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types - are the same as the corresponding N_t types. */ - -#undef int_least8_t -#undef uint_least8_t -#undef int_least16_t -#undef uint_least16_t -#undef int_least32_t -#undef uint_least32_t -#undef int_least64_t -#undef uint_least64_t -#define int_least8_t int8_t -#define uint_least8_t uint8_t -#define int_least16_t int16_t -#define uint_least16_t uint16_t -#define int_least32_t int32_t -#define uint_least32_t uint32_t -#ifdef GL_INT64_T -# define int_least64_t int64_t -#endif -#ifdef GL_UINT64_T -# define uint_least64_t uint64_t -#endif - -/* 7.18.1.3. Fastest minimum-width integer types */ - -/* Note: Other substitutes may define these types differently. - It is not recommended to use these types in public header files. */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types - are taken from the same list of types. Assume that 'long int' - is fast enough for all narrower integers. */ - -#undef int_fast8_t -#undef uint_fast8_t -#undef int_fast16_t -#undef uint_fast16_t -#undef int_fast32_t -#undef uint_fast32_t -#undef int_fast64_t -#undef uint_fast64_t -#define int_fast8_t long int -#define uint_fast8_t unsigned int_fast8_t -#define int_fast16_t long int -#define uint_fast16_t unsigned int_fast16_t -#define int_fast32_t long int -#define uint_fast32_t unsigned int_fast32_t -#ifdef GL_INT64_T -# define int_fast64_t int64_t -#endif -#ifdef GL_UINT64_T -# define uint_fast64_t uint64_t -#endif - -/* 7.18.1.4. Integer types capable of holding object pointers */ - -#undef intptr_t -#undef uintptr_t -#define intptr_t long int -#define uintptr_t unsigned long int - -/* 7.18.1.5. Greatest-width integer types */ - -/* Note: These types are compiler dependent. It may be unwise to use them in - public header files. */ - -#undef intmax_t -#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 -# define intmax_t long long int -#elif defined GL_INT64_T -# define intmax_t int64_t -#else -# define intmax_t long int -#endif - -#undef uintmax_t -#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 -# define uintmax_t unsigned long long int -#elif defined GL_UINT64_T -# define uintmax_t uint64_t -#else -# define uintmax_t unsigned long int -#endif - -/* 7.18.2. Limits of specified-width integer types */ - -#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS - -/* 7.18.2.1. Limits of exact-width integer types */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits. */ - -#undef INT8_MIN -#undef INT8_MAX -#undef UINT8_MAX -#define INT8_MIN (~ INT8_MAX) -#define INT8_MAX 127 -#define UINT8_MAX 255 - -#undef INT16_MIN -#undef INT16_MAX -#undef UINT16_MAX -#define INT16_MIN (~ INT16_MAX) -#define INT16_MAX 32767 -#define UINT16_MAX 65535 - -#undef INT32_MIN -#undef INT32_MAX -#undef UINT32_MAX -#define INT32_MIN (~ INT32_MAX) -#define INT32_MAX 2147483647 -#define UINT32_MAX 4294967295U - -#undef INT64_MIN -#undef INT64_MAX -#ifdef GL_INT64_T -/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0 - evaluates the latter incorrectly in preprocessor expressions. */ -# define INT64_MIN (- INTMAX_C (1) << 63) -# define INT64_MAX INTMAX_C (9223372036854775807) -#endif - -#undef UINT64_MAX -#ifdef GL_UINT64_T -# define UINT64_MAX UINTMAX_C (18446744073709551615) -#endif - -/* 7.18.2.2. Limits of minimum-width integer types */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types - are the same as the corresponding N_t types. */ - -#undef INT_LEAST8_MIN -#undef INT_LEAST8_MAX -#undef UINT_LEAST8_MAX -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define UINT_LEAST8_MAX UINT8_MAX - -#undef INT_LEAST16_MIN -#undef INT_LEAST16_MAX -#undef UINT_LEAST16_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define UINT_LEAST16_MAX UINT16_MAX - -#undef INT_LEAST32_MIN -#undef INT_LEAST32_MAX -#undef UINT_LEAST32_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define UINT_LEAST32_MAX UINT32_MAX - -#undef INT_LEAST64_MIN -#undef INT_LEAST64_MAX -#ifdef GL_INT64_T -# define INT_LEAST64_MIN INT64_MIN -# define INT_LEAST64_MAX INT64_MAX -#endif - -#undef UINT_LEAST64_MAX -#ifdef GL_UINT64_T -# define UINT_LEAST64_MAX UINT64_MAX -#endif - -/* 7.18.2.3. Limits of fastest minimum-width integer types */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types - are taken from the same list of types. */ - -#undef INT_FAST8_MIN -#undef INT_FAST8_MAX -#undef UINT_FAST8_MAX -#define INT_FAST8_MIN LONG_MIN -#define INT_FAST8_MAX LONG_MAX -#define UINT_FAST8_MAX ULONG_MAX - -#undef INT_FAST16_MIN -#undef INT_FAST16_MAX -#undef UINT_FAST16_MAX -#define INT_FAST16_MIN LONG_MIN -#define INT_FAST16_MAX LONG_MAX -#define UINT_FAST16_MAX ULONG_MAX - -#undef INT_FAST32_MIN -#undef INT_FAST32_MAX -#undef UINT_FAST32_MAX -#define INT_FAST32_MIN LONG_MIN -#define INT_FAST32_MAX LONG_MAX -#define UINT_FAST32_MAX ULONG_MAX - -#undef INT_FAST64_MIN -#undef INT_FAST64_MAX -#ifdef GL_INT64_T -# define INT_FAST64_MIN INT64_MIN -# define INT_FAST64_MAX INT64_MAX -#endif - -#undef UINT_FAST64_MAX -#ifdef GL_UINT64_T -# define UINT_FAST64_MAX UINT64_MAX -#endif - -/* 7.18.2.4. Limits of integer types capable of holding object pointers */ - -#undef INTPTR_MIN -#undef INTPTR_MAX -#undef UINTPTR_MAX -#define INTPTR_MIN LONG_MIN -#define INTPTR_MAX LONG_MAX -#define UINTPTR_MAX ULONG_MAX - -/* 7.18.2.5. Limits of greatest-width integer types */ - -#undef INTMAX_MIN -#undef INTMAX_MAX -#ifdef INT64_MAX -# define INTMAX_MIN INT64_MIN -# define INTMAX_MAX INT64_MAX -#else -# define INTMAX_MIN INT32_MIN -# define INTMAX_MAX INT32_MAX -#endif - -#undef UINTMAX_MAX -#ifdef UINT64_MAX -# define UINTMAX_MAX UINT64_MAX -#else -# define UINTMAX_MAX UINT32_MAX -#endif - -/* 7.18.3. Limits of other integer types */ - -/* ptrdiff_t limits */ -#undef PTRDIFF_MIN -#undef PTRDIFF_MAX -#define PTRDIFF_MIN \ - _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) -#define PTRDIFF_MAX \ - _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) - -/* sig_atomic_t limits */ -#undef SIG_ATOMIC_MIN -#undef SIG_ATOMIC_MAX -#define SIG_ATOMIC_MIN \ - _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ - 0@SIG_ATOMIC_T_SUFFIX@) -#define SIG_ATOMIC_MAX \ - _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ - 0@SIG_ATOMIC_T_SUFFIX@) - - -/* size_t limit */ -#undef SIZE_MAX -#define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@) - -/* wchar_t limits */ -#undef WCHAR_MIN -#undef WCHAR_MAX -#define WCHAR_MIN \ - _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) -#define WCHAR_MAX \ - _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) - -/* wint_t limits */ -#undef WINT_MIN -#undef WINT_MAX -#define WINT_MIN \ - _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) -#define WINT_MAX \ - _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) - -#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */ - -/* 7.18.4. Macros for integer constants */ - -#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS - -/* 7.18.4.1. Macros for minimum-width integer constants */ -/* According to ISO C 99 Technical Corrigendum 1 */ - -/* Here we assume a standard architecture where the hardware integer - types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ - -#undef INT8_C -#undef UINT8_C -#define INT8_C(x) x -#define UINT8_C(x) x - -#undef INT16_C -#undef UINT16_C -#define INT16_C(x) x -#define UINT16_C(x) x - -#undef INT32_C -#undef UINT32_C -#define INT32_C(x) x -#define UINT32_C(x) x ## U - -#undef INT64_C -#undef UINT64_C -#if LONG_MAX >> 31 >> 31 == 1 -# define INT64_C(x) x##L -#elif defined _MSC_VER -# define INT64_C(x) x##i64 -#elif @HAVE_LONG_LONG_INT@ -# define INT64_C(x) x##LL -#endif -#if ULONG_MAX >> 31 >> 31 >> 1 == 1 -# define UINT64_C(x) x##UL -#elif defined _MSC_VER -# define UINT64_C(x) x##ui64 -#elif @HAVE_UNSIGNED_LONG_LONG_INT@ -# define UINT64_C(x) x##ULL -#endif - -/* 7.18.4.2. Macros for greatest-width integer constants */ - -#undef INTMAX_C -#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 -# define INTMAX_C(x) x##LL -#elif defined GL_INT64_T -# define INTMAX_C(x) INT64_C(x) -#else -# define INTMAX_C(x) x##L -#endif - -#undef UINTMAX_C -#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 -# define UINTMAX_C(x) x##ULL -#elif defined GL_UINT64_T -# define UINTMAX_C(x) UINT64_C(x) -#else -# define UINTMAX_C(x) x##UL -#endif - -#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ - -#endif /* _GL_STDINT_H */ -#endif /* !defined _GL_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */ diff --git a/lib/stdio.in.h b/lib/stdio.in.h deleted file mode 100644 index 772709c..0000000 --- a/lib/stdio.in.h +++ /dev/null @@ -1,382 +0,0 @@ -/* A GNU-like . - - Copyright (C) 2004, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#if defined __need_FILE || defined __need___FILE -/* Special invocation convention inside glibc header files. */ - -#@INCLUDE_NEXT@ @NEXT_STDIO_H@ - -#else -/* Normal invocation convention. */ - -#ifndef _GL_STDIO_H - -/* The include_next requires a split double-inclusion guard. */ -#@INCLUDE_NEXT@ @NEXT_STDIO_H@ - -#ifndef _GL_STDIO_H -#define _GL_STDIO_H - -#include -#include - -#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \ - || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \ - || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \ - || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@)) -/* Get off_t and ssize_t. */ -# include -#endif - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - - -/* The definition of GL_LINK_WARNING is copied here. */ - - -#ifdef __cplusplus -extern "C" { -#endif - - -#if @GNULIB_FPRINTF_POSIX@ -# if @REPLACE_FPRINTF@ -# define fprintf rpl_fprintf -extern int fprintf (FILE *fp, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef fprintf -# define fprintf \ - (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \ - "use gnulib module fprintf-posix for portable " \ - "POSIX compliance"), \ - fprintf) -#endif - -#if @GNULIB_VFPRINTF_POSIX@ -# if @REPLACE_VFPRINTF@ -# define vfprintf rpl_vfprintf -extern int vfprintf (FILE *fp, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef vfprintf -# define vfprintf(s,f,a) \ - (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \ - "use gnulib module vfprintf-posix for portable " \ - "POSIX compliance"), \ - vfprintf (s, f, a)) -#endif - -#if @GNULIB_PRINTF_POSIX@ -# if @REPLACE_PRINTF@ -/* Don't break __attribute__((format(printf,M,N))). */ -# define printf __printf__ -extern int printf (const char *format, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef printf -# define printf \ - (GL_LINK_WARNING ("printf is not always POSIX compliant - " \ - "use gnulib module printf-posix for portable " \ - "POSIX compliance"), \ - printf) -/* Don't break __attribute__((format(printf,M,N))). */ -# define format(kind,m,n) format (__##kind##__, m, n) -# define __format__(kind,m,n) __format__ (__##kind##__, m, n) -# define ____printf____ __printf__ -# define ____scanf____ __scanf__ -# define ____strftime____ __strftime__ -# define ____strfmon____ __strfmon__ -#endif - -#if @GNULIB_VPRINTF_POSIX@ -# if @REPLACE_VPRINTF@ -# define vprintf rpl_vprintf -extern int vprintf (const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 1, 0))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef vprintf -# define vprintf(f,a) \ - (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \ - "use gnulib module vprintf-posix for portable " \ - "POSIX compliance"), \ - vprintf (f, a)) -#endif - -#if @GNULIB_SNPRINTF@ -# if @REPLACE_SNPRINTF@ -# define snprintf rpl_snprintf -# endif -# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@ -extern int snprintf (char *str, size_t size, const char *format, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef snprintf -# define snprintf \ - (GL_LINK_WARNING ("snprintf is unportable - " \ - "use gnulib module snprintf for portability"), \ - snprintf) -#endif - -#if @GNULIB_VSNPRINTF@ -# if @REPLACE_VSNPRINTF@ -# define vsnprintf rpl_vsnprintf -# endif -# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@ -extern int vsnprintf (char *str, size_t size, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 3, 0))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef vsnprintf -# define vsnprintf(b,s,f,a) \ - (GL_LINK_WARNING ("vsnprintf is unportable - " \ - "use gnulib module vsnprintf for portability"), \ - vsnprintf (b, s, f, a)) -#endif - -#if @GNULIB_SPRINTF_POSIX@ -# if @REPLACE_SPRINTF@ -# define sprintf rpl_sprintf -extern int sprintf (char *str, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef sprintf -# define sprintf \ - (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \ - "use gnulib module sprintf-posix for portable " \ - "POSIX compliance"), \ - sprintf) -#endif - -#if @GNULIB_VSPRINTF_POSIX@ -# if @REPLACE_VSPRINTF@ -# define vsprintf rpl_vsprintf -extern int vsprintf (char *str, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); -# endif -#elif defined GNULIB_POSIXCHECK -# undef vsprintf -# define vsprintf(b,f,a) \ - (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \ - "use gnulib module vsprintf-posix for portable " \ - "POSIX compliance"), \ - vsprintf (b, f, a)) -#endif - -#if @GNULIB_VASPRINTF@ -# if @REPLACE_VASPRINTF@ -# define asprintf rpl_asprintf -# define vasprintf rpl_vasprintf -# endif -# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@ - /* Write formatted output to a string dynamically allocated with malloc(). - If the memory allocation succeeds, store the address of the string in - *RESULT and return the number of resulting bytes, excluding the trailing - NUL. Upon memory allocation error, or some other error, return -1. */ - extern int asprintf (char **result, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); - extern int vasprintf (char **result, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); -# endif -#endif - -#if @GNULIB_FOPEN@ -# if @REPLACE_FOPEN@ -# define fopen rpl_fopen -extern FILE * fopen (const char *filename, const char *mode); -# endif -#elif defined GNULIB_POSIXCHECK -# undef fopen -# define fopen(f,m) \ - (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \ - "use gnulib module fopen for portability"), \ - fopen (f, m)) -#endif - -#if @GNULIB_FREOPEN@ -# if @REPLACE_FREOPEN@ -# define freopen rpl_freopen -extern FILE * freopen (const char *filename, const char *mode, FILE *stream); -# endif -#elif defined GNULIB_POSIXCHECK -# undef freopen -# define freopen(f,m,s) \ - (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \ - "use gnulib module freopen for portability"), \ - freopen (f, m, s)) -#endif - -#if @GNULIB_FSEEKO@ -# if @REPLACE_FSEEKO@ -/* Provide fseek, fseeko functions that are aware of a preceding - fflush(), and which detect pipes. */ -# define fseeko rpl_fseeko -extern int fseeko (FILE *fp, off_t offset, int whence); -# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence) -# endif -#elif defined GNULIB_POSIXCHECK -# undef fseeko -# define fseeko(f,o,w) \ - (GL_LINK_WARNING ("fseeko is unportable - " \ - "use gnulib module fseeko for portability"), \ - fseeko (f, o, w)) -#endif - -#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@ -extern int rpl_fseek (FILE *fp, long offset, int whence); -# undef fseek -# if defined GNULIB_POSIXCHECK -# define fseek(f,o,w) \ - (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \ - "on 32-bit platforms - " \ - "use fseeko function for handling of large files"), \ - rpl_fseek (f, o, w)) -# else -# define fseek rpl_fseek -# endif -#elif defined GNULIB_POSIXCHECK -# ifndef fseek -# define fseek(f,o,w) \ - (GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \ - "on 32-bit platforms - " \ - "use fseeko function for handling of large files"), \ - fseek (f, o, w)) -# endif -#endif - -#if @GNULIB_FTELLO@ -# if @REPLACE_FTELLO@ -# define ftello rpl_ftello -extern off_t ftello (FILE *fp); -# define ftell(fp) ftello (fp) -# endif -#elif defined GNULIB_POSIXCHECK -# undef ftello -# define ftello(f) \ - (GL_LINK_WARNING ("ftello is unportable - " \ - "use gnulib module ftello for portability"), \ - ftello (f)) -#endif - -#if @GNULIB_FTELL@ && @REPLACE_FTELL@ -extern long rpl_ftell (FILE *fp); -# undef ftell -# if GNULIB_POSIXCHECK -# define ftell(f) \ - (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \ - "on 32-bit platforms - " \ - "use ftello function for handling of large files"), \ - rpl_ftell (f)) -# else -# define ftell rpl_ftell -# endif -#elif defined GNULIB_POSIXCHECK -# ifndef ftell -# define ftell(f) \ - (GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \ - "on 32-bit platforms - " \ - "use ftello function for handling of large files"), \ - ftell (f)) -# endif -#endif - -#if @GNULIB_FFLUSH@ -# if @REPLACE_FFLUSH@ -# define fflush rpl_fflush - /* Flush all pending data on STREAM according to POSIX rules. Both - output and seekable input streams are supported. - Note! LOSS OF DATA can occur if fflush is applied on an input stream - that is _not_seekable_ or on an update stream that is _not_seekable_ - and in which the most recent operation was input. Seekability can - be tested with lseek(fileno(fp),0,SEEK_CUR). */ - extern int fflush (FILE *gl_stream); -# endif -#elif defined GNULIB_POSIXCHECK -# undef fflush -# define fflush(f) \ - (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \ - "use gnulib module fflush for portable " \ - "POSIX compliance"), \ - fflush (f)) -#endif - -#if @GNULIB_GETDELIM@ -# if !@HAVE_DECL_GETDELIM@ -/* Read input, up to (and including) the next occurrence of DELIMITER, from - STREAM, store it in *LINEPTR (and NUL-terminate it). - *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE - bytes of space. It is realloc'd as necessary. - Return the number of bytes read and stored at *LINEPTR (not including the - NUL terminator), or -1 on error or EOF. */ -extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter, - FILE *stream); -# endif -#elif defined GNULIB_POSIXCHECK -# undef getdelim -# define getdelim(l, s, d, f) \ - (GL_LINK_WARNING ("getdelim is unportable - " \ - "use gnulib module getdelim for portability"), \ - getdelim (l, s, d, f)) -#endif - -#if @GNULIB_GETLINE@ -# if @REPLACE_GETLINE@ -# undef getline -# define getline rpl_getline -# endif -# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@ -/* Read a line, up to (and including) the next newline, from STREAM, store it - in *LINEPTR (and NUL-terminate it). - *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE - bytes of space. It is realloc'd as necessary. - Return the number of bytes read and stored at *LINEPTR (not including the - NUL terminator), or -1 on error or EOF. */ -extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream); -# endif -#elif defined GNULIB_POSIXCHECK -# undef getline -# define getline(l, s, f) \ - (GL_LINK_WARNING ("getline is unportable - " \ - "use gnulib module getline for portability"), \ - getline (l, s, f)) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _GL_STDIO_H */ -#endif /* _GL_STDIO_H */ -#endif diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h deleted file mode 100644 index a4946e6..0000000 --- a/lib/stdlib.in.h +++ /dev/null @@ -1,177 +0,0 @@ -/* A GNU-like . - - Copyright (C) 1995, 2001-2002, 2006-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#if defined __need_malloc_and_calloc -/* Special invocation convention inside glibc header files. */ - -#@INCLUDE_NEXT@ @NEXT_STDLIB_H@ - -#else -/* Normal invocation convention. */ - -#ifndef _GL_STDLIB_H - -/* The include_next requires a split double-inclusion guard. */ -#@INCLUDE_NEXT@ @NEXT_STDLIB_H@ - -#ifndef _GL_STDLIB_H -#define _GL_STDLIB_H - - -/* The definition of GL_LINK_WARNING is copied here. */ - - -/* Some systems do not define EXIT_*, despite otherwise supporting C89. */ -#ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -#endif -/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere - with proper operation of xargs. */ -#ifndef EXIT_FAILURE -# define EXIT_FAILURE 1 -#elif EXIT_FAILURE != 1 -# undef EXIT_FAILURE -# define EXIT_FAILURE 1 -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - - -#if @GNULIB_MALLOC_POSIX@ -# if !@HAVE_MALLOC_POSIX@ -# undef malloc -# define malloc rpl_malloc -extern void * malloc (size_t size); -# endif -#elif defined GNULIB_POSIXCHECK -# undef malloc -# define malloc(s) \ - (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \ - "use gnulib module malloc-posix for portability"), \ - malloc (s)) -#endif - - -#if @GNULIB_REALLOC_POSIX@ -# if !@HAVE_REALLOC_POSIX@ -# undef realloc -# define realloc rpl_realloc -extern void * realloc (void *ptr, size_t size); -# endif -#elif defined GNULIB_POSIXCHECK -# undef realloc -# define realloc(p,s) \ - (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \ - "use gnulib module realloc-posix for portability"), \ - realloc (p, s)) -#endif - - -#if @GNULIB_CALLOC_POSIX@ -# if !@HAVE_CALLOC_POSIX@ -# undef calloc -# define calloc rpl_calloc -extern void * calloc (size_t nmemb, size_t size); -# endif -#elif defined GNULIB_POSIXCHECK -# undef calloc -# define calloc(n,s) \ - (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \ - "use gnulib module calloc-posix for portability"), \ - calloc (n, s)) -#endif - - -#if @GNULIB_GETSUBOPT@ -/* Assuming *OPTIONP is a comma separated list of elements of the form - "token" or "token=value", getsubopt parses the first of these elements. - If the first element refers to a "token" that is member of the given - NULL-terminated array of tokens: - - It replaces the comma with a NUL byte, updates *OPTIONP to point past - the first option and the comma, sets *VALUEP to the value of the - element (or NULL if it doesn't contain an "=" sign), - - It returns the index of the "token" in the given array of tokens. - Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined. - For more details see the POSIX:2001 specification. - http://www.opengroup.org/susv3xsh/getsubopt.html */ -# if !@HAVE_GETSUBOPT@ -extern int getsubopt (char **optionp, char *const *tokens, char **valuep); -# endif -#elif defined GNULIB_POSIXCHECK -# undef getsubopt -# define getsubopt(o,t,v) \ - (GL_LINK_WARNING ("getsubopt is unportable - " \ - "use gnulib module getsubopt for portability"), \ - getsubopt (o, t, v)) -#endif - - -#if @GNULIB_MKDTEMP@ -# if !@HAVE_MKDTEMP@ -/* Create a unique temporary directory from TEMPLATE. - The last six characters of TEMPLATE must be "XXXXXX"; - they are replaced with a string that makes the directory name unique. - Returns TEMPLATE, or a null pointer if it cannot get a unique name. - The directory is created mode 700. */ -extern char * mkdtemp (char * /*template*/); -# endif -#elif defined GNULIB_POSIXCHECK -# undef mkdtemp -# define mkdtemp(t) \ - (GL_LINK_WARNING ("mkdtemp is unportable - " \ - "use gnulib module mkdtemp for portability"), \ - mkdtemp (t)) -#endif - - -#if @GNULIB_MKSTEMP@ -# if @REPLACE_MKSTEMP@ -/* Create a unique temporary file from TEMPLATE. - The last six characters of TEMPLATE must be "XXXXXX"; - they are replaced with a string that makes the file name unique. - The file is then created, ensuring it didn't exist before. - The file is created read-write (mask at least 0600 & ~umask), but it may be - world-readable and world-writable (mask 0666 & ~umask), depending on the - implementation. - Returns the open file descriptor if successful, otherwise -1 and errno - set. */ -# define mkstemp rpl_mkstemp -extern int mkstemp (char * /*template*/); -# else -/* On MacOS X 10.3, only declares mkstemp. */ -# include -# endif -#elif defined GNULIB_POSIXCHECK -# undef mkstemp -# define mkstemp(t) \ - (GL_LINK_WARNING ("mkstemp is unportable - " \ - "use gnulib module mkstemp for portability"), \ - mkstemp (t)) -#endif - - -#ifdef __cplusplus -} -#endif - -#endif /* _GL_STDLIB_H */ -#endif /* _GL_STDLIB_H */ -#endif diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c deleted file mode 100644 index c605fb0..0000000 --- a/lib/strcasecmp.c +++ /dev/null @@ -1,63 +0,0 @@ -/* Case-insensitive string comparison function. - Copyright (C) 1998-1999, 2005-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include - -#include -#include - -#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) - -/* Compare strings S1 and S2, ignoring case, returning less than, equal to or - greater than zero if S1 is lexicographically less than, equal to or greater - than S2. - Note: This function does not work with multibyte strings! */ - -int -strcasecmp (const char *s1, const char *s2) -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - c1 = TOLOWER (*p1); - c2 = TOLOWER (*p2); - - if (c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); -} diff --git a/lib/strchrnul.c b/lib/strchrnul.c deleted file mode 100644 index 07014be..0000000 --- a/lib/strchrnul.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Searching in a string. - Copyright (C) 2003, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include - -/* Find the first occurrence of C in S or the final NUL byte. */ -char * -strchrnul (const char *s, int c_in) -{ - char c = c_in; - while (*s && (*s != c)) - s++; - - return (char *) s; -} diff --git a/lib/strerror.c b/lib/strerror.c deleted file mode 100644 index ef6234e..0000000 --- a/lib/strerror.c +++ /dev/null @@ -1,79 +0,0 @@ -/* strerror.c --- ANSI C compatible system error routine - - Copyright (C) 1986, 1988, 1989, 1991, 2002, 2003, 2006, 2007 Free - Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#if REPLACE_STRERROR - -# include -# include - -# undef strerror - -char *rpl_strerror (int n) -{ - static char const fmt[] = "Unknown error (%d)"; - static char mesg[sizeof fmt + sizeof n * CHAR_BIT / 3]; - - char *result = strerror (n); - - if (! result) - { - sprintf (mesg, fmt, n); - return mesg; - } - return result; -} - -#elif !HAVE_STRERROR - -#include - -/* Don't include , since it may or may not declare - sys_errlist and its declarations may collide with ours. Just - declare the stuff that we need directly. Standard hosted C89 - implementations define strerror and they don't need this strerror - function, so take some liberties with the standard to cater to - ancient or limited freestanding implementations. */ -int sprintf (char *, char const *, ...); -extern int sys_nerr; -extern char *sys_errlist[]; - -char * -strerror (int n) -{ - static char const fmt[] = "Unknown error (%d)"; - static char mesg[sizeof fmt + sizeof n * CHAR_BIT / 3]; - - if (n < 0 || n >= sys_nerr) - { - sprintf (mesg, fmt, n); - return mesg; - } - else - return sys_errlist[n]; -} - -#else - -/* This declaration is solely to ensure that after preprocessing - this file is never empty. */ -typedef int dummy; - -#endif diff --git a/lib/string.in.h b/lib/string.in.h deleted file mode 100644 index 2abfd39..0000000 --- a/lib/string.in.h +++ /dev/null @@ -1,579 +0,0 @@ -/* A GNU-like . - - Copyright (C) 1995-1996, 2001-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GL_STRING_H - -/* The include_next requires a split double-inclusion guard. */ -#@INCLUDE_NEXT@ @NEXT_STRING_H@ - -#ifndef _GL_STRING_H -#define _GL_STRING_H - - -/* The definition of GL_LINK_WARNING is copied here. */ - - -/* GCC 2.95 and later have "__restrict"; C99 compilers have - "restrict", and "configure" may have defined "restrict". - Other compilers use __restrict, __restrict__, and _Restrict, and - 'configure' might #define 'restrict' to those words. */ -#ifndef __restrict -# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) -# if 199901L <= __STDC_VERSION__ -# define __restrict restrict -# else -# define __restrict -# endif -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Return the first occurrence of NEEDLE in HAYSTACK. */ -#if @GNULIB_MEMMEM@ -# if ! @HAVE_DECL_MEMMEM@ -extern void *memmem (void const *__haystack, size_t __haystack_len, - void const *__needle, size_t __needle_len); -# endif -#elif defined GNULIB_POSIXCHECK -# undef memmem -# define memmem(a,al,b,bl) \ - (GL_LINK_WARNING ("memmem is unportable - " \ - "use gnulib module memmem for portability"), \ - memmem (a, al, b, bl)) -#endif - -/* Copy N bytes of SRC to DEST, return pointer to bytes after the - last written byte. */ -#if @GNULIB_MEMPCPY@ -# if ! @HAVE_MEMPCPY@ -extern void *mempcpy (void *__restrict __dest, void const *__restrict __src, - size_t __n); -# endif -#elif defined GNULIB_POSIXCHECK -# undef mempcpy -# define mempcpy(a,b,n) \ - (GL_LINK_WARNING ("mempcpy is unportable - " \ - "use gnulib module mempcpy for portability"), \ - mempcpy (a, b, n)) -#endif - -/* Search backwards through a block for a byte (specified as an int). */ -#if @GNULIB_MEMRCHR@ -# if ! @HAVE_DECL_MEMRCHR@ -extern void *memrchr (void const *, int, size_t); -# endif -#elif defined GNULIB_POSIXCHECK -# undef memrchr -# define memrchr(a,b,c) \ - (GL_LINK_WARNING ("memrchr is unportable - " \ - "use gnulib module memrchr for portability"), \ - memrchr (a, b, c)) -#endif - -/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ -#if @GNULIB_STPCPY@ -# if ! @HAVE_STPCPY@ -extern char *stpcpy (char *__restrict __dst, char const *__restrict __src); -# endif -#elif defined GNULIB_POSIXCHECK -# undef stpcpy -# define stpcpy(a,b) \ - (GL_LINK_WARNING ("stpcpy is unportable - " \ - "use gnulib module stpcpy for portability"), \ - stpcpy (a, b)) -#endif - -/* Copy no more than N bytes of SRC to DST, returning a pointer past the - last non-NUL byte written into DST. */ -#if @GNULIB_STPNCPY@ -# if ! @HAVE_STPNCPY@ -# define stpncpy gnu_stpncpy -extern char *stpncpy (char *__restrict __dst, char const *__restrict __src, - size_t __n); -# endif -#elif defined GNULIB_POSIXCHECK -# undef stpncpy -# define stpncpy(a,b,n) \ - (GL_LINK_WARNING ("stpncpy is unportable - " \ - "use gnulib module stpncpy for portability"), \ - stpncpy (a, b, n)) -#endif - -/* Compare strings S1 and S2, ignoring case, returning less than, equal to or - greater than zero if S1 is lexicographically less than, equal to or greater - than S2. - Note: This function does not work in multibyte locales. */ -#if ! @HAVE_STRCASECMP@ -extern int strcasecmp (char const *s1, char const *s2); -#endif -#if defined GNULIB_POSIXCHECK -/* strcasecmp() does not work with multibyte strings: - POSIX says that it operates on "strings", and "string" in POSIX is defined - as a sequence of bytes, not of characters. */ -# undef strcasecmp -# define strcasecmp(a,b) \ - (GL_LINK_WARNING ("strcasecmp cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbscasecmp if you care about " \ - "internationalization, or use c_strcasecmp (from " \ - "gnulib module c-strcase) if you want a locale " \ - "independent function"), \ - strcasecmp (a, b)) -#endif - -/* Compare no more than N bytes of strings S1 and S2, ignoring case, - returning less than, equal to or greater than zero if S1 is - lexicographically less than, equal to or greater than S2. - Note: This function cannot work correctly in multibyte locales. */ -#if ! @HAVE_DECL_STRNCASECMP@ -extern int strncasecmp (char const *s1, char const *s2, size_t n); -#endif -#if defined GNULIB_POSIXCHECK -/* strncasecmp() does not work with multibyte strings: - POSIX says that it operates on "strings", and "string" in POSIX is defined - as a sequence of bytes, not of characters. */ -# undef strncasecmp -# define strncasecmp(a,b,n) \ - (GL_LINK_WARNING ("strncasecmp cannot work correctly on character " \ - "strings in multibyte locales - " \ - "use mbsncasecmp or mbspcasecmp if you care about " \ - "internationalization, or use c_strncasecmp (from " \ - "gnulib module c-strcase) if you want a locale " \ - "independent function"), \ - strncasecmp (a, b, n)) -#endif - -#if defined GNULIB_POSIXCHECK -/* strchr() does not work with multibyte strings if the locale encoding is - GB18030 and the character to be searched is a digit. */ -# undef strchr -# define strchr(s,c) \ - (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \ - "in some multibyte locales - " \ - "use mbschr if you care about internationalization"), \ - strchr (s, c)) -#endif - -/* Find the first occurrence of C in S or the final NUL byte. */ -#if @GNULIB_STRCHRNUL@ -# if ! @HAVE_STRCHRNUL@ -extern char *strchrnul (char const *__s, int __c_in); -# endif -#elif defined GNULIB_POSIXCHECK -# undef strchrnul -# define strchrnul(a,b) \ - (GL_LINK_WARNING ("strchrnul is unportable - " \ - "use gnulib module strchrnul for portability"), \ - strchrnul (a, b)) -#endif - -/* Duplicate S, returning an identical malloc'd string. */ -#if @GNULIB_STRDUP@ -# if ! @HAVE_DECL_STRDUP@ && ! defined strdup -extern char *strdup (char const *__s); -# endif -#elif defined GNULIB_POSIXCHECK -# undef strdup -# define strdup(a) \ - (GL_LINK_WARNING ("strdup is unportable - " \ - "use gnulib module strdup for portability"), \ - strdup (a)) -#endif - -/* Return a newly allocated copy of at most N bytes of STRING. */ -#if @GNULIB_STRNDUP@ -# if ! @HAVE_STRNDUP@ -# undef strndup -# define strndup rpl_strndup -# endif -# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ -extern char *strndup (char const *__string, size_t __n); -# endif -#elif defined GNULIB_POSIXCHECK -# undef strndup -# define strndup(a,n) \ - (GL_LINK_WARNING ("strndup is unportable - " \ - "use gnulib module strndup for portability"), \ - strndup (a, n)) -#endif - -/* Find the length (number of bytes) of STRING, but scan at most - MAXLEN bytes. If no '\0' terminator is found in that many bytes, - return MAXLEN. */ -#if @GNULIB_STRNLEN@ -# if ! @HAVE_DECL_STRNLEN@ -extern size_t strnlen (char const *__string, size_t __maxlen); -# endif -#elif defined GNULIB_POSIXCHECK -# undef strnlen -# define strnlen(a,n) \ - (GL_LINK_WARNING ("strnlen is unportable - " \ - "use gnulib module strnlen for portability"), \ - strnlen (a, n)) -#endif - -#if defined GNULIB_POSIXCHECK -/* strcspn() assumes the second argument is a list of single-byte characters. - Even in this simple case, it does not work with multibyte strings if the - locale encoding is GB18030 and one of the characters to be searched is a - digit. */ -# undef strcspn -# define strcspn(s,a) \ - (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbscspn if you care about internationalization"), \ - strcspn (s, a)) -#endif - -/* Find the first occurrence in S of any character in ACCEPT. */ -#if @GNULIB_STRPBRK@ -# if ! @HAVE_STRPBRK@ -extern char *strpbrk (char const *__s, char const *__accept); -# endif -# if defined GNULIB_POSIXCHECK -/* strpbrk() assumes the second argument is a list of single-byte characters. - Even in this simple case, it does not work with multibyte strings if the - locale encoding is GB18030 and one of the characters to be searched is a - digit. */ -# undef strpbrk -# define strpbrk(s,a) \ - (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbspbrk if you care about internationalization"), \ - strpbrk (s, a)) -# endif -#elif defined GNULIB_POSIXCHECK -# undef strpbrk -# define strpbrk(s,a) \ - (GL_LINK_WARNING ("strpbrk is unportable - " \ - "use gnulib module strpbrk for portability"), \ - strpbrk (s, a)) -#endif - -#if defined GNULIB_POSIXCHECK -/* strspn() assumes the second argument is a list of single-byte characters. - Even in this simple case, it cannot work with multibyte strings. */ -# undef strspn -# define strspn(s,a) \ - (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbsspn if you care about internationalization"), \ - strspn (s, a)) -#endif - -#if defined GNULIB_POSIXCHECK -/* strrchr() does not work with multibyte strings if the locale encoding is - GB18030 and the character to be searched is a digit. */ -# undef strrchr -# define strrchr(s,c) \ - (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \ - "in some multibyte locales - " \ - "use mbsrchr if you care about internationalization"), \ - strrchr (s, c)) -#endif - -/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. - If one is found, overwrite it with a NUL, and advance *STRINGP - to point to the next char after it. Otherwise, set *STRINGP to NULL. - If *STRINGP was already NULL, nothing happens. - Return the old value of *STRINGP. - - This is a variant of strtok() that is multithread-safe and supports - empty fields. - - Caveat: It modifies the original string. - Caveat: These functions cannot be used on constant strings. - Caveat: The identity of the delimiting character is lost. - Caveat: It doesn't work with multibyte strings unless all of the delimiter - characters are ASCII characters < 0x30. - - See also strtok_r(). */ -#if @GNULIB_STRSEP@ -# if ! @HAVE_STRSEP@ -extern char *strsep (char **__restrict __stringp, char const *__restrict __delim); -# endif -# if defined GNULIB_POSIXCHECK -# undef strsep -# define strsep(s,d) \ - (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbssep if you care about internationalization"), \ - strsep (s, d)) -# endif -#elif defined GNULIB_POSIXCHECK -# undef strsep -# define strsep(s,d) \ - (GL_LINK_WARNING ("strsep is unportable - " \ - "use gnulib module strsep for portability"), \ - strsep (s, d)) -#endif - -#if defined GNULIB_POSIXCHECK -/* strstr() does not work with multibyte strings if the locale encoding is - different from UTF-8: - POSIX says that it operates on "strings", and "string" in POSIX is defined - as a sequence of bytes, not of characters. */ -# undef strstr -# define strstr(a,b) \ - (GL_LINK_WARNING ("strstr cannot work correctly on character strings " \ - "in most multibyte locales - " \ - "use mbsstr if you care about internationalization"), \ - strstr (a, b)) -#endif - -/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive - comparison. */ -#if ! @HAVE_STRCASESTR@ -extern char *strcasestr (const char *haystack, const char *needle); -#endif -#if defined GNULIB_POSIXCHECK -/* strcasestr() does not work with multibyte strings: - It is a glibc extension, and glibc implements it only for unibyte - locales. */ -# undef strcasestr -# define strcasestr(a,b) \ - (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \ - "in multibyte locales - " \ - "use mbscasestr if you care about " \ - "internationalization, or use c-strcasestr if you want " \ - "a locale independent function"), \ - strcasestr (a, b)) -#endif - -/* Parse S into tokens separated by characters in DELIM. - If S is NULL, the saved pointer in SAVE_PTR is used as - the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = strtok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" - - This is a variant of strtok() that is multithread-safe. - - For the POSIX documentation for this function, see: - http://www.opengroup.org/susv3xsh/strtok.html - - Caveat: It modifies the original string. - Caveat: These functions cannot be used on constant strings. - Caveat: The identity of the delimiting character is lost. - Caveat: It doesn't work with multibyte strings unless all of the delimiter - characters are ASCII characters < 0x30. - - See also strsep(). */ -#if @GNULIB_STRTOK_R@ -# if ! @HAVE_DECL_STRTOK_R@ -extern char *strtok_r (char *__restrict s, char const *__restrict delim, - char **__restrict save_ptr); -# endif -# if defined GNULIB_POSIXCHECK -# undef strtok_r -# define strtok_r(s,d,p) \ - (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbstok_r if you care about internationalization"), \ - strtok_r (s, d, p)) -# endif -#elif defined GNULIB_POSIXCHECK -# undef strtok_r -# define strtok_r(s,d,p) \ - (GL_LINK_WARNING ("strtok_r is unportable - " \ - "use gnulib module strtok_r for portability"), \ - strtok_r (s, d, p)) -#endif - - -/* The following functions are not specified by POSIX. They are gnulib - extensions. */ - -#if @GNULIB_MBSLEN@ -/* Return the number of multibyte characters in the character string STRING. - This considers multibyte characters, unlike strlen, which counts bytes. */ -extern size_t mbslen (const char *string); -#endif - -#if @GNULIB_MBSNLEN@ -/* Return the number of multibyte characters in the character string starting - at STRING and ending at STRING + LEN. */ -extern size_t mbsnlen (const char *string, size_t len); -#endif - -#if @GNULIB_MBSCHR@ -/* Locate the first single-byte character C in the character string STRING, - and return a pointer to it. Return NULL if C is not found in STRING. - Unlike strchr(), this function works correctly in multibyte locales with - encodings such as GB18030. */ -# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ -extern char * mbschr (const char *string, int c); -#endif - -#if @GNULIB_MBSRCHR@ -/* Locate the last single-byte character C in the character string STRING, - and return a pointer to it. Return NULL if C is not found in STRING. - Unlike strrchr(), this function works correctly in multibyte locales with - encodings such as GB18030. */ -# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ -extern char * mbsrchr (const char *string, int c); -#endif - -#if @GNULIB_MBSSTR@ -/* Find the first occurrence of the character string NEEDLE in the character - string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. - Unlike strstr(), this function works correctly in multibyte locales with - encodings different from UTF-8. */ -extern char * mbsstr (const char *haystack, const char *needle); -#endif - -#if @GNULIB_MBSCASECMP@ -/* Compare the character strings S1 and S2, ignoring case, returning less than, - equal to or greater than zero if S1 is lexicographically less than, equal to - or greater than S2. - Note: This function may, in multibyte locales, return 0 for strings of - different lengths! - Unlike strcasecmp(), this function works correctly in multibyte locales. */ -extern int mbscasecmp (const char *s1, const char *s2); -#endif - -#if @GNULIB_MBSNCASECMP@ -/* Compare the initial segment of the character string S1 consisting of at most - N characters with the initial segment of the character string S2 consisting - of at most N characters, ignoring case, returning less than, equal to or - greater than zero if the initial segment of S1 is lexicographically less - than, equal to or greater than the initial segment of S2. - Note: This function may, in multibyte locales, return 0 for initial segments - of different lengths! - Unlike strncasecmp(), this function works correctly in multibyte locales. - But beware that N is not a byte count but a character count! */ -extern int mbsncasecmp (const char *s1, const char *s2, size_t n); -#endif - -#if @GNULIB_MBSPCASECMP@ -/* Compare the initial segment of the character string STRING consisting of - at most mbslen (PREFIX) characters with the character string PREFIX, - ignoring case, returning less than, equal to or greater than zero if this - initial segment is lexicographically less than, equal to or greater than - PREFIX. - Note: This function may, in multibyte locales, return 0 if STRING is of - smaller length than PREFIX! - Unlike strncasecmp(), this function works correctly in multibyte - locales. */ -extern char * mbspcasecmp (const char *string, const char *prefix); -#endif - -#if @GNULIB_MBSCASESTR@ -/* Find the first occurrence of the character string NEEDLE in the character - string HAYSTACK, using case-insensitive comparison. - Note: This function may, in multibyte locales, return success even if - strlen (haystack) < strlen (needle) ! - Unlike strcasestr(), this function works correctly in multibyte locales. */ -extern char * mbscasestr (const char *haystack, const char *needle); -#endif - -#if @GNULIB_MBSCSPN@ -/* Find the first occurrence in the character string STRING of any character - in the character string ACCEPT. Return the number of bytes from the - beginning of the string to this occurrence, or to the end of the string - if none exists. - Unlike strcspn(), this function works correctly in multibyte locales. */ -extern size_t mbscspn (const char *string, const char *accept); -#endif - -#if @GNULIB_MBSPBRK@ -/* Find the first occurrence in the character string STRING of any character - in the character string ACCEPT. Return the pointer to it, or NULL if none - exists. - Unlike strpbrk(), this function works correctly in multibyte locales. */ -# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ -extern char * mbspbrk (const char *string, const char *accept); -#endif - -#if @GNULIB_MBSSPN@ -/* Find the first occurrence in the character string STRING of any character - not in the character string REJECT. Return the number of bytes from the - beginning of the string to this occurrence, or to the end of the string - if none exists. - Unlike strspn(), this function works correctly in multibyte locales. */ -extern size_t mbsspn (const char *string, const char *reject); -#endif - -#if @GNULIB_MBSSEP@ -/* Search the next delimiter (multibyte character listed in the character - string DELIM) starting at the character string *STRINGP. - If one is found, overwrite it with a NUL, and advance *STRINGP to point - to the next multibyte character after it. Otherwise, set *STRINGP to NULL. - If *STRINGP was already NULL, nothing happens. - Return the old value of *STRINGP. - - This is a variant of mbstok_r() that supports empty fields. - - Caveat: It modifies the original string. - Caveat: These functions cannot be used on constant strings. - Caveat: The identity of the delimiting character is lost. - - See also mbstok_r(). */ -extern char * mbssep (char **stringp, const char *delim); -#endif - -#if @GNULIB_MBSTOK_R@ -/* Parse the character string STRING into tokens separated by characters in - the character string DELIM. - If STRING is NULL, the saved pointer in SAVE_PTR is used as - the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = mbstok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" - - Caveat: It modifies the original string. - Caveat: These functions cannot be used on constant strings. - Caveat: The identity of the delimiting character is lost. - - See also mbssep(). */ -extern char * mbstok_r (char *string, const char *delim, char **save_ptr); -#endif - -/* Map any int, typically from errno, into an error message. */ -#if @GNULIB_STRERROR@ -# if @REPLACE_STRERROR@ -# undef strerror -# define strerror rpl_strerror -# endif -# if !@HAVE_DECL_STRERROR@ || @REPLACE_STRERROR@ -extern char *strerror (int); -# endif -#elif defined GNULIB_POSIXCHECK -# undef strerror -# define strerror(e) \ - (GL_LINK_WARNING ("strerror is unportable - " \ - "use gnulib module strerror to guarantee non-NULL result"), \ - strerror (e)) -#endif - - -#ifdef __cplusplus -} -#endif - -#endif /* _GL_STRING_H */ -#endif /* _GL_STRING_H */ diff --git a/lib/stripslash.c b/lib/stripslash.c deleted file mode 100644 index 342d497..0000000 --- a/lib/stripslash.c +++ /dev/null @@ -1,45 +0,0 @@ -/* stripslash.c -- remove redundant trailing slashes from a file name - - Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include "dirname.h" - -/* Remove trailing slashes from FILE. Return true if a trailing slash - was removed. This is useful when using file name completion from a - shell that adds a "/" after directory names (such as tcsh and - bash), because on symlinks to directories, several system calls - have different semantics according to whether a trailing slash is - present. */ - -bool -strip_trailing_slashes (char *file) -{ - char *base = last_component (file); - char *base_lim; - bool had_slash; - - /* last_component returns "" for file system roots, but we need to turn - `///' into `/'. */ - if (! *base) - base = file; - base_lim = base + base_len (base); - had_slash = (*base_lim != '\0'); - *base_lim = '\0'; - return had_slash; -} diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c deleted file mode 100644 index 473a610..0000000 --- a/lib/strncasecmp.c +++ /dev/null @@ -1,63 +0,0 @@ -/* strncasecmp.c -- case insensitive string comparator - Copyright (C) 1998-1999, 2005-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include - -#include -#include - -#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) - -/* Compare no more than N bytes of strings S1 and S2, ignoring case, - returning less than, equal to or greater than zero if S1 is - lexicographically less than, equal to or greater than S2. - Note: This function cannot work correctly in multibyte locales. */ - -int -strncasecmp (const char *s1, const char *s2, size_t n) -{ - register const unsigned char *p1 = (const unsigned char *) s1; - register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2 || n == 0) - return 0; - - do - { - c1 = TOLOWER (*p1); - c2 = TOLOWER (*p2); - - if (--n == 0 || c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); -} diff --git a/lib/strndup.c b/lib/strndup.c deleted file mode 100644 index 3a1b0ea..0000000 --- a/lib/strndup.c +++ /dev/null @@ -1,37 +0,0 @@ -/* A replacement function, for systems that lack strndup. - - Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007 - Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include - -#include - -char * -strndup (char const *s, size_t n) -{ - size_t len = strnlen (s, n); - char *new = malloc (len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return memcpy (new, s, len); -} diff --git a/lib/strnlen.c b/lib/strnlen.c deleted file mode 100644 index d346d32..0000000 --- a/lib/strnlen.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Find the length of STRING, but scan at most MAXLEN characters. - Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. - Written by Simon Josefsson. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include - -/* Find the length of STRING, but scan at most MAXLEN characters. - If no '\0' terminator is found in that many characters, return MAXLEN. */ - -size_t -strnlen (const char *string, size_t maxlen) -{ - const char *end = memchr (string, '\0', maxlen); - return end ? (size_t) (end - string) : maxlen; -} diff --git a/lib/sysexits.in.h b/lib/sysexits.in.h deleted file mode 100644 index b65e0cc..0000000 --- a/lib/sysexits.in.h +++ /dev/null @@ -1,68 +0,0 @@ -/* exit() exit codes for some BSD system programs. - Copyright (C) 2003, 2006-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Written by Simon Josefsson based on sysexits(3) man page */ - -#ifndef _GL_SYSEXITS_H - -#if @HAVE_SYSEXITS_H@ - -/* IRIX 6.5 has an that defines a macro EX_OK with a nonzero - value. Override it. See - */ -# ifdef __sgi -# include -# undef EX_OK -# endif - -/* The include_next requires a split double-inclusion guard. */ -# @INCLUDE_NEXT@ @NEXT_SYSEXITS_H@ - -/* HP-UX 11 ends at EX_NOPERM. */ -# ifndef EX_CONFIG -# define EX_CONFIG 78 -# endif - -#endif - -#ifndef _GL_SYSEXITS_H -#define _GL_SYSEXITS_H - -#if !@HAVE_SYSEXITS_H@ - -# define EX_OK 0 /* same value as EXIT_SUCCESS */ - -# define EX_USAGE 64 -# define EX_DATAERR 65 -# define EX_NOINPUT 66 -# define EX_NOUSER 67 -# define EX_NOHOST 68 -# define EX_UNAVAILABLE 69 -# define EX_SOFTWARE 70 -# define EX_OSERR 71 -# define EX_OSFILE 72 -# define EX_CANTCREAT 73 -# define EX_IOERR 74 -# define EX_TEMPFAIL 75 -# define EX_PROTOCOL 76 -# define EX_NOPERM 77 -# define EX_CONFIG 78 - -#endif - -#endif /* _GL_SYSEXITS_H */ -#endif /* _GL_SYSEXITS_H */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h deleted file mode 100644 index 07c4877..0000000 --- a/lib/unistd.in.h +++ /dev/null @@ -1,262 +0,0 @@ -/* Substitute for and wrapper around . - Copyright (C) 2004-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _GL_UNISTD_H - -/* The include_next requires a split double-inclusion guard. */ -#if @HAVE_UNISTD_H@ -# @INCLUDE_NEXT@ @NEXT_UNISTD_H@ -#endif - -#ifndef _GL_UNISTD_H -#define _GL_UNISTD_H - -/* mingw doesn't define the SEEK_* macros in . */ -#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) -# include -#endif - -/* mingw fails to declare _exit in . */ -#include - -/* The definition of GL_LINK_WARNING is copied here. */ - - -/* Declare overridden functions. */ - -#ifdef __cplusplus -extern "C" { -#endif - - -#if @GNULIB_CHOWN@ -# if @REPLACE_CHOWN@ -# ifndef REPLACE_CHOWN -# define REPLACE_CHOWN 1 -# endif -# if REPLACE_CHOWN -/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE - to GID (if GID is not -1). Follow symbolic links. - Return 0 if successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -# define chown rpl_chown -extern int chown (const char *file, uid_t uid, gid_t gid); -# endif -# endif -#elif defined GNULIB_POSIXCHECK -# undef chown -# define chown(f,u,g) \ - (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \ - "doesn't treat a uid or gid of -1 on some systems - " \ - "use gnulib module chown for portability"), \ - chown (f, u, g)) -#endif - - -#if @GNULIB_DUP2@ -# if !@HAVE_DUP2@ -/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if - NEWFD = OLDFD, otherwise close NEWFD first if it is open. - Return 0 if successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -extern int dup2 (int oldfd, int newfd); -# endif -#elif defined GNULIB_POSIXCHECK -# undef dup2 -# define dup2(o,n) \ - (GL_LINK_WARNING ("dup2 is unportable - " \ - "use gnulib module dup2 for portability"), \ - dup2 (o, n)) -#endif - - -#if @GNULIB_FCHDIR@ -# if @REPLACE_FCHDIR@ - -/* Change the process' current working directory to the directory on which - the given file descriptor is open. - Return 0 if successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -extern int fchdir (int /*fd*/); - -# define close rpl_close -extern int close (int); -# define dup rpl_dup -extern int dup (int); -# define dup2 rpl_dup2 -extern int dup2 (int, int); - -# endif -#elif defined GNULIB_POSIXCHECK -# undef fchdir -# define fchdir(f) \ - (GL_LINK_WARNING ("fchdir is unportable - " \ - "use gnulib module fchdir for portability"), \ - fchdir (f)) -#endif - - -#if @GNULIB_FTRUNCATE@ -# if !@HAVE_FTRUNCATE@ -/* Change the size of the file to which FD is opened to become equal to LENGTH. - Return 0 if successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -extern int ftruncate (int fd, off_t length); -# endif -#elif defined GNULIB_POSIXCHECK -# undef ftruncate -# define ftruncate(f,l) \ - (GL_LINK_WARNING ("ftruncate is unportable - " \ - "use gnulib module ftruncate for portability"), \ - ftruncate (f, l)) -#endif - - -#if @GNULIB_GETCWD@ -/* Include the headers that might declare getcwd so that they will not - cause confusion if included after this file. */ -# include -# if @REPLACE_GETCWD@ -/* Get the name of the current working directory, and put it in SIZE bytes - of BUF. - Return BUF if successful, or NULL if the directory couldn't be determined - or SIZE was too small. - See the POSIX:2001 specification - . - Additionally, the gnulib module 'getcwd' guarantees the following GNU - extension: If BUF is NULL, an array is allocated with 'malloc'; the array - is SIZE bytes long, unless SIZE == 0, in which case it is as big as - necessary. */ -# define getcwd rpl_getcwd -extern char * getcwd (char *buf, size_t size); -# endif -#elif defined GNULIB_POSIXCHECK -# undef getcwd -# define getcwd(b,s) \ - (GL_LINK_WARNING ("getcwd is unportable - " \ - "use gnulib module getcwd for portability"), \ - getcwd (b, s)) -#endif - - -#if @GNULIB_GETLOGIN_R@ -/* Copies the user's login name to NAME. - The array pointed to by NAME has room for SIZE bytes. - - Returns 0 if successful. Upon error, an error number is returned, or -1 in - the case that the login name cannot be found but no specific error is - provided (this case is hopefully rare but is left open by the POSIX spec). - - See . - */ -# if !@HAVE_DECL_GETLOGIN_R@ -# include -extern int getlogin_r (char *name, size_t size); -# endif -#elif defined GNULIB_POSIXCHECK -# undef getlogin_r -# define getlogin_r(n,s) \ - (GL_LINK_WARNING ("getlogin_r is unportable - " \ - "use gnulib module getlogin_r for portability"), \ - getlogin_r (n, s)) -#endif - - -#if @GNULIB_LCHOWN@ -# if @REPLACE_LCHOWN@ -/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE - to GID (if GID is not -1). Do not follow symbolic links. - Return 0 if successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -# define lchown rpl_lchown -extern int lchown (char const *file, uid_t owner, gid_t group); -# endif -#elif defined GNULIB_POSIXCHECK -# undef lchown -# define lchown(f,u,g) \ - (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \ - "systems - use gnulib module lchown for portability"), \ - lchown (f, u, g)) -#endif - - -#if @GNULIB_LSEEK@ -# if @REPLACE_LSEEK@ -/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. - Return the new offset if successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -# define lseek rpl_lseek - extern off_t lseek (int fd, off_t offset, int whence); -# endif -#elif defined GNULIB_POSIXCHECK -# undef lseek -# define lseek(f,o,w) \ - (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \ - "systems - use gnulib module lseek for portability"), \ - lseek (f, o, w)) -#endif - - -#if @GNULIB_READLINK@ -/* Read the contents of the symbolic link FILE and place the first BUFSIZE - bytes of it into BUF. Return the number of bytes placed into BUF if - successful, otherwise -1 and errno set. - See the POSIX:2001 specification - . */ -# if !@HAVE_READLINK@ -# include -extern int readlink (const char *file, char *buf, size_t bufsize); -# endif -#elif defined GNULIB_POSIXCHECK -# undef readlink -# define readlink(f,b,s) \ - (GL_LINK_WARNING ("readlink is unportable - " \ - "use gnulib module readlink for portability"), \ - readlink (f, b, s)) -#endif - - -#if @GNULIB_SLEEP@ -/* Pause the execution of the current thread for N seconds. - Returns the number of seconds left to sleep. - See the POSIX:2001 specification - . */ -# if !@HAVE_SLEEP@ -extern unsigned int sleep (unsigned int n); -# endif -#elif defined GNULIB_POSIXCHECK -# undef sleep -# define sleep(n) \ - (GL_LINK_WARNING ("sleep is unportable - " \ - "use gnulib module sleep for portability"), \ - sleep (n)) -#endif - - -#ifdef __cplusplus -} -#endif - - -#endif /* _GL_UNISTD_H */ -#endif /* _GL_UNISTD_H */ diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c deleted file mode 100644 index f563823..0000000 --- a/lib/vasnprintf.c +++ /dev/null @@ -1,3966 +0,0 @@ -/* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* This file can be parametrized with the following macros: - VASNPRINTF The name of the function being defined. - FCHAR_T The element type of the format string. - DCHAR_T The element type of the destination (result) string. - FCHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters - in the format string are ASCII. MUST be set if - FCHAR_T and DCHAR_T are not the same type. - DIRECTIVE Structure denoting a format directive. - Depends on FCHAR_T. - DIRECTIVES Structure denoting the set of format directives of a - format string. Depends on FCHAR_T. - PRINTF_PARSE Function that parses a format string. - Depends on FCHAR_T. - DCHAR_CPY memcpy like function for DCHAR_T[] arrays. - DCHAR_SET memset like function for DCHAR_T[] arrays. - DCHAR_MBSNLEN mbsnlen like function for DCHAR_T[] arrays. - SNPRINTF The system's snprintf (or similar) function. - This may be either snprintf or swprintf. - TCHAR_T The element type of the argument and result string - of the said SNPRINTF function. This may be either - char or wchar_t. The code exploits that - sizeof (TCHAR_T) | sizeof (DCHAR_T) and - alignof (TCHAR_T) <= alignof (DCHAR_T). - DCHAR_IS_TCHAR Set to 1 if DCHAR_T and TCHAR_T are the same type. - DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[]. - DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t. - DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t. - DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */ - -/* Tell glibc's to provide a prototype for snprintf(). - This must come before because may include - , and once has been included, it's too late. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifndef VASNPRINTF -# include -#endif -#ifndef IN_LIBINTL -# include -#endif - -/* Specification. */ -#ifndef VASNPRINTF -# if WIDE_CHAR_VERSION -# include "vasnwprintf.h" -# else -# include "vasnprintf.h" -# endif -#endif - -#include /* localeconv() */ -#include /* snprintf(), sprintf() */ -#include /* abort(), malloc(), realloc(), free() */ -#include /* memcpy(), strlen() */ -#include /* errno */ -#include /* CHAR_BIT */ -#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ -#if HAVE_NL_LANGINFO -# include -#endif -#ifndef VASNPRINTF -# if WIDE_CHAR_VERSION -# include "wprintf-parse.h" -# else -# include "printf-parse.h" -# endif -#endif - -/* Checked size_t computations. */ -#include "xsize.h" - -#if NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL -# include -# include "float+.h" -# include "fpucw.h" -#endif - -#if NEED_PRINTF_INFINITE_DOUBLE && !defined IN_LIBINTL -# include -# include "isnan.h" -#endif - -#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !defined IN_LIBINTL -# include -# include "isnanl-nolibm.h" -# include "fpucw.h" -#endif - -#if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL -# include -# include "isnan.h" -# include "printf-frexp.h" -# include "isnanl-nolibm.h" -# include "printf-frexpl.h" -# include "fpucw.h" -#endif - -/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ -#ifndef EOVERFLOW -# define EOVERFLOW E2BIG -#endif - -#if HAVE_WCHAR_T -# if HAVE_WCSLEN -# define local_wcslen wcslen -# else - /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid - a dependency towards this library, here is a local substitute. - Define this substitute only once, even if this file is included - twice in the same compilation unit. */ -# ifndef local_wcslen_defined -# define local_wcslen_defined 1 -static size_t -local_wcslen (const wchar_t *s) -{ - const wchar_t *ptr; - - for (ptr = s; *ptr != (wchar_t) 0; ptr++) - ; - return ptr - s; -} -# endif -# endif -#endif - -/* Default parameters. */ -#ifndef VASNPRINTF -# if WIDE_CHAR_VERSION -# define VASNPRINTF vasnwprintf -# define FCHAR_T wchar_t -# define DCHAR_T wchar_t -# define TCHAR_T wchar_t -# define DCHAR_IS_TCHAR 1 -# define DIRECTIVE wchar_t_directive -# define DIRECTIVES wchar_t_directives -# define PRINTF_PARSE wprintf_parse -# define DCHAR_CPY wmemcpy -# else -# define VASNPRINTF vasnprintf -# define FCHAR_T char -# define DCHAR_T char -# define TCHAR_T char -# define DCHAR_IS_TCHAR 1 -# define DIRECTIVE char_directive -# define DIRECTIVES char_directives -# define PRINTF_PARSE printf_parse -# define DCHAR_CPY memcpy -# endif -#endif -#if WIDE_CHAR_VERSION - /* TCHAR_T is wchar_t. */ -# define USE_SNPRINTF 1 -# if HAVE_DECL__SNWPRINTF - /* On Windows, the function swprintf() has a different signature than - on Unix; we use the _snwprintf() function instead. */ -# define SNPRINTF _snwprintf -# else - /* Unix. */ -# define SNPRINTF swprintf -# endif -#else - /* TCHAR_T is char. */ -# /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'. - But don't use it on BeOS, since BeOS snprintf produces no output if the - size argument is >= 0x3000000. */ -# if (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) && !defined __BEOS__ -# define USE_SNPRINTF 1 -# else -# define USE_SNPRINTF 0 -# endif -# if HAVE_DECL__SNPRINTF - /* Windows. */ -# define SNPRINTF _snprintf -# else - /* Unix. */ -# define SNPRINTF snprintf - /* Here we need to call the native snprintf, not rpl_snprintf. */ -# undef snprintf -# endif -#endif -/* Here we need to call the native sprintf, not rpl_sprintf. */ -#undef sprintf - -#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL -/* Determine the decimal-point character according to the current locale. */ -# ifndef decimal_point_char_defined -# define decimal_point_char_defined 1 -static char -decimal_point_char () -{ - const char *point; - /* Determine it in a multithread-safe way. We know nl_langinfo is - multithread-safe on glibc systems, but is not required to be multithread- - safe by POSIX. sprintf(), however, is multithread-safe. localeconv() - is rarely multithread-safe. */ -# if HAVE_NL_LANGINFO && __GLIBC__ - point = nl_langinfo (RADIXCHAR); -# elif 1 - char pointbuf[5]; - sprintf (pointbuf, "%#.0f", 1.0); - point = &pointbuf[1]; -# else - point = localeconv () -> decimal_point; -# endif - /* The decimal point is always a single byte: either '.' or ','. */ - return (point[0] != '\0' ? point[0] : '.'); -} -# endif -#endif - -#if NEED_PRINTF_INFINITE_DOUBLE && !defined IN_LIBINTL - -/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */ -static int -is_infinite_or_zero (double x) -{ - return isnan (x) || x + x == x; -} - -#endif - -#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !defined IN_LIBINTL - -/* Equivalent to !isfinite(x), but does not require libm. */ -static int -is_infinitel (long double x) -{ - return isnanl (x) || (x + x == x && x != 0.0L); -} - -#endif - -#if NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL - -/* Converting 'long double' to decimal without rare rounding bugs requires - real bignums. We use the naming conventions of GNU gmp, but vastly simpler - (and slower) algorithms. */ - -typedef unsigned int mp_limb_t; -# define GMP_LIMB_BITS 32 -typedef int mp_limb_verify[2 * (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS) - 1]; - -typedef unsigned long long mp_twolimb_t; -# define GMP_TWOLIMB_BITS 64 -typedef int mp_twolimb_verify[2 * (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS) - 1]; - -/* Representation of a bignum >= 0. */ -typedef struct -{ - size_t nlimbs; - mp_limb_t *limbs; /* Bits in little-endian order, allocated with malloc(). */ -} mpn_t; - -/* Compute the product of two bignums >= 0. - Return the allocated memory in case of success, NULL in case of memory - allocation failure. */ -static void * -multiply (mpn_t src1, mpn_t src2, mpn_t *dest) -{ - const mp_limb_t *p1; - const mp_limb_t *p2; - size_t len1; - size_t len2; - - if (src1.nlimbs <= src2.nlimbs) - { - len1 = src1.nlimbs; - p1 = src1.limbs; - len2 = src2.nlimbs; - p2 = src2.limbs; - } - else - { - len1 = src2.nlimbs; - p1 = src2.limbs; - len2 = src1.nlimbs; - p2 = src1.limbs; - } - /* Now 0 <= len1 <= len2. */ - if (len1 == 0) - { - /* src1 or src2 is zero. */ - dest->nlimbs = 0; - dest->limbs = (mp_limb_t *) malloc (1); - } - else - { - /* Here 1 <= len1 <= len2. */ - size_t dlen; - mp_limb_t *dp; - size_t k, i, j; - - dlen = len1 + len2; - dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); - if (dp == NULL) - return NULL; - for (k = len2; k > 0; ) - dp[--k] = 0; - for (i = 0; i < len1; i++) - { - mp_limb_t digit1 = p1[i]; - mp_twolimb_t carry = 0; - for (j = 0; j < len2; j++) - { - mp_limb_t digit2 = p2[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - carry += dp[i + j]; - dp[i + j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - dp[i + len2] = (mp_limb_t) carry; - } - /* Normalise. */ - while (dlen > 0 && dp[dlen - 1] == 0) - dlen--; - dest->nlimbs = dlen; - dest->limbs = dp; - } - return dest->limbs; -} - -/* Compute the quotient of a bignum a >= 0 and a bignum b > 0. - a is written as a = q * b + r with 0 <= r < b. q is the quotient, r - the remainder. - Finally, round-to-even is performed: If r > b/2 or if r = b/2 and q is odd, - q is incremented. - Return the allocated memory in case of success, NULL in case of memory - allocation failure. */ -static void * -divide (mpn_t a, mpn_t b, mpn_t *q) -{ - /* Algorithm: - First normalise a and b: a=[a[m-1],...,a[0]], b=[b[n-1],...,b[0]] - with m>=0 and n>0 (in base beta = 2^GMP_LIMB_BITS). - If m=n=1, perform a single-precision division: - r:=0, j:=m, - while j>0 do - {Here (q[m-1]*beta^(m-1)+...+q[j]*beta^j) * b[0] + r*beta^j = - = a[m-1]*beta^(m-1)+...+a[j]*beta^j und 0<=r=n>1, perform a multiple-precision division: - We have a/b < beta^(m-n+1). - s:=intDsize-1-(hightest bit in b[n-1]), 0<=s=beta/2. - For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).} - Compute q* : - q* := floor((r[j+n]*beta+r[j+n-1])/b[n-1]). - In case of overflow (q* >= beta) set q* := beta-1. - Compute c2 := ((r[j+n]*beta+r[j+n-1]) - q* * b[n-1])*beta + r[j+n-2] - and c3 := b[n-2] * q*. - {We have 0 <= c2 < 2*beta^2, even 0 <= c2 < beta^2 if no overflow - occurred. Furthermore 0 <= c3 < beta^2. - If there was overflow and - r[j+n]*beta+r[j+n-1] - q* * b[n-1] >= beta, i.e. c2 >= beta^2, - the next test can be skipped.} - While c3 > c2, {Here 0 <= c2 < c3 < beta^2} - Put q* := q* - 1, c2 := c2 + b[n-1]*beta, c3 := c3 - b[n-2]. - If q* > 0: - Put r := r - b * q* * beta^j. In detail: - [r[n+j],...,r[j]] := [r[n+j],...,r[j]] - q* * [b[n-1],...,b[0]]. - hence: u:=0, for i:=0 to n-1 do - u := u + q* * b[i], - r[j+i]:=r[j+i]-(u mod beta) (+ beta, if carry), - u:=u div beta (+ 1, if carry in subtraction) - r[n+j]:=r[n+j]-u. - {Since always u = (q* * [b[i-1],...,b[0]] div beta^i) + 1 - < q* + 1 <= beta, - the carry u does not overflow.} - If a negative carry occurs, put q* := q* - 1 - and [r[n+j],...,r[j]] := [r[n+j],...,r[j]] + [0,b[n-1],...,b[0]]. - Set q[j] := q*. - Normalise [q[m-n],..,q[0]]; this yields the quotient q. - Shift [r[n-1],...,r[0]] right by s bits and normalise; this yields the - rest r. - The room for q[j] can be allocated at the memory location of r[n+j]. - Finally, round-to-even: - Shift r left by 1 bit. - If r > b or if r = b and q[0] is odd, q := q+1. - */ - const mp_limb_t *a_ptr = a.limbs; - size_t a_len = a.nlimbs; - const mp_limb_t *b_ptr = b.limbs; - size_t b_len = b.nlimbs; - mp_limb_t *roomptr; - mp_limb_t *tmp_roomptr = NULL; - mp_limb_t *q_ptr; - size_t q_len; - mp_limb_t *r_ptr; - size_t r_len; - - /* Allocate room for a_len+2 digits. - (Need a_len+1 digits for the real division and 1 more digit for the - final rounding of q.) */ - roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t)); - if (roomptr == NULL) - return NULL; - - /* Normalise a. */ - while (a_len > 0 && a_ptr[a_len - 1] == 0) - a_len--; - - /* Normalise b. */ - for (;;) - { - if (b_len == 0) - /* Division by zero. */ - abort (); - if (b_ptr[b_len - 1] == 0) - b_len--; - else - break; - } - - /* Here m = a_len >= 0 and n = b_len > 0. */ - - if (a_len < b_len) - { - /* m beta^(m-2) <= a/b < beta^m */ - r_ptr = roomptr; - q_ptr = roomptr + 1; - { - mp_limb_t den = b_ptr[0]; - mp_limb_t remainder = 0; - const mp_limb_t *sourceptr = a_ptr + a_len; - mp_limb_t *destptr = q_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; - *--destptr = num / den; - remainder = num % den; - } - /* Normalise and store r. */ - if (remainder > 0) - { - r_ptr[0] = remainder; - r_len = 1; - } - else - r_len = 0; - /* Normalise q. */ - q_len = a_len; - if (q_ptr[q_len - 1] == 0) - q_len--; - } - } - else - { - /* n>1: multiple precision division. - beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> - beta^(m-n-1) <= a/b < beta^(m-n+1). */ - /* Determine s. */ - size_t s; - { - mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ - s = 31; - if (msd >= 0x10000) - { - msd = msd >> 16; - s -= 16; - } - if (msd >= 0x100) - { - msd = msd >> 8; - s -= 8; - } - if (msd >= 0x10) - { - msd = msd >> 4; - s -= 4; - } - if (msd >= 0x4) - { - msd = msd >> 2; - s -= 2; - } - if (msd >= 0x2) - { - msd = msd >> 1; - s -= 1; - } - } - /* 0 <= s < GMP_LIMB_BITS. - Copy b, shifting it left by s bits. */ - if (s > 0) - { - tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); - if (tmp_roomptr == NULL) - { - free (roomptr); - return NULL; - } - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = tmp_roomptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - /* accu must be zero, since that was how s was determined. */ - if (accu != 0) - abort (); - } - b_ptr = tmp_roomptr; - } - /* Copy a, shifting it left by s bits, yields r. - Memory layout: - At the beginning: r = roomptr[0..a_len], - at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ - r_ptr = roomptr; - if (s == 0) - { - memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); - r_ptr[a_len] = 0; - } - else - { - const mp_limb_t *sourceptr = a_ptr; - mp_limb_t *destptr = r_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = a_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - *destptr++ = (mp_limb_t) accu; - } - q_ptr = roomptr + b_len; - q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ - { - size_t j = a_len - b_len; /* m-n */ - mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ - mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ - mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ - ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; - /* Division loop, traversed m-n+1 times. - j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ - for (;;) - { - mp_limb_t q_star; - mp_limb_t c1; - if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ - { - /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ - mp_twolimb_t num = - ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) - | r_ptr[j + b_len - 1]; - q_star = num / b_msd; - c1 = num % b_msd; - } - else - { - /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ - q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ - /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta - <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta - <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) - {<= beta !}. - If yes, jump directly to the subtraction loop. - (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta - <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ - if (r_ptr[j + b_len] > b_msd - || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) - /* r[j+n] >= b[n-1]+1 or - r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a - carry. */ - goto subtract; - } - /* q_star = q*, - c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by - b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 - this can happen only twice. */ - if (c3 > c2) - { - q_star = q_star - 1; /* q* := q* - 1 */ - if (c3 - c2 > b_msdd) - q_star = q_star - 1; /* q* := q* - 1 */ - } - } - if (q_star > 0) - subtract: - { - /* Subtract r := r - b * q* * beta^j. */ - mp_limb_t cr; - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_twolimb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - /* Here 0 <= carry <= q*. */ - carry = - carry - + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ - + (mp_limb_t) ~(*destptr); - /* Here 0 <= carry <= beta*q* + beta-1. */ - *destptr++ = ~(mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; /* <= q* */ - } - cr = (mp_limb_t) carry; - } - /* Subtract cr from r_ptr[j + b_len], then forget about - r_ptr[j + b_len]. */ - if (cr > r_ptr[j + b_len]) - { - /* Subtraction gave a carry. */ - q_star = q_star - 1; /* q* := q* - 1 */ - /* Add b back. */ - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_limb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - mp_limb_t source1 = *sourceptr++; - mp_limb_t source2 = *destptr; - *destptr++ = source1 + source2 + carry; - carry = - (carry - ? source1 >= (mp_limb_t) ~source2 - : source1 > (mp_limb_t) ~source2); - } - } - /* Forget about the carry and about r[j+n]. */ - } - } - /* q* is determined. Store it as q[j]. */ - q_ptr[j] = q_star; - if (j == 0) - break; - j--; - } - } - r_len = b_len; - /* Normalise q. */ - if (q_ptr[q_len - 1] == 0) - q_len--; -# if 0 /* Not needed here, since we need r only to compare it with b/2, and - b is shifted left by s bits. */ - /* Shift r right by s bits. */ - if (s > 0) - { - mp_limb_t ptr = r_ptr + r_len; - mp_twolimb_t accu = 0; - size_t count; - for (count = r_len; count > 0; count--) - { - accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; - accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); - *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); - } - } -# endif - /* Normalise r. */ - while (r_len > 0 && r_ptr[r_len - 1] == 0) - r_len--; - } - /* Compare r << 1 with b. */ - if (r_len > b_len) - goto increment_q; - { - size_t i; - for (i = b_len;;) - { - mp_limb_t r_i = - (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) - | (i < r_len ? r_ptr[i] << 1 : 0); - mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); - if (r_i > b_i) - goto increment_q; - if (r_i < b_i) - goto keep_q; - if (i == 0) - break; - i--; - } - } - if (q_len > 0 && ((q_ptr[0] & 1) != 0)) - /* q is odd. */ - increment_q: - { - size_t i; - for (i = 0; i < q_len; i++) - if (++(q_ptr[i]) != 0) - goto keep_q; - q_ptr[q_len++] = 1; - } - keep_q: - if (tmp_roomptr != NULL) - free (tmp_roomptr); - q->limbs = q_ptr; - q->nlimbs = q_len; - return roomptr; -} - -/* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal - representation. - Destroys the contents of a. - Return the allocated memory - containing the decimal digits in low-to-high - order, terminated with a NUL character - in case of success, NULL in case - of memory allocation failure. */ -static char * -convert_to_decimal (mpn_t a, size_t extra_zeroes) -{ - mp_limb_t *a_ptr = a.limbs; - size_t a_len = a.nlimbs; - /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ - size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1); - char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes)); - if (c_ptr != NULL) - { - char *d_ptr = c_ptr; - for (; extra_zeroes > 0; extra_zeroes--) - *d_ptr++ = '0'; - while (a_len > 0) - { - /* Divide a by 10^9, in-place. */ - mp_limb_t remainder = 0; - mp_limb_t *ptr = a_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; - *ptr = num / 1000000000; - remainder = num % 1000000000; - } - /* Store the remainder as 9 decimal digits. */ - for (count = 9; count > 0; count--) - { - *d_ptr++ = '0' + (remainder % 10); - remainder = remainder / 10; - } - /* Normalize a. */ - if (a_ptr[a_len - 1] == 0) - a_len--; - } - /* Remove leading zeroes. */ - while (d_ptr > c_ptr && d_ptr[-1] == '0') - d_ptr--; - /* But keep at least one zero. */ - if (d_ptr == c_ptr) - *d_ptr++ = '0'; - /* Terminate the string. */ - *d_ptr = '\0'; - } - return c_ptr; -} - -/* Assuming x is finite and >= 0: - write x as x = 2^e * m, where m is a bignum. - Return the allocated memory in case of success, NULL in case of memory - allocation failure. */ -static void * -decode_long_double (long double x, int *ep, mpn_t *mp) -{ - mpn_t m; - int exp; - long double y; - size_t i; - - /* Allocate memory for result. */ - m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS; - m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t)); - if (m.limbs == NULL) - return NULL; - /* Split into exponential part and mantissa. */ - y = frexpl (x, &exp); - if (!(y >= 0.0L && y < 1.0L)) - abort (); - /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * LDBL_MANT_BIT), and the - latter is an integer. */ - /* Convert the mantissa (y * LDBL_MANT_BIT) to a sequence of limbs. - I'm not sure whether it's safe to cast a 'long double' value between - 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only - 'long double' values between 0 and 2^16 (to 'unsigned int' or 'int', - doesn't matter). */ -# if (LDBL_MANT_BIT % GMP_LIMB_BITS) != 0 -# if (LDBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2 - { - mp_limb_t hi, lo; - y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % (GMP_LIMB_BITS / 2)); - hi = (int) y; - y -= hi; - if (!(y >= 0.0L && y < 1.0L)) - abort (); - y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); - lo = (int) y; - y -= lo; - if (!(y >= 0.0L && y < 1.0L)) - abort (); - m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; - } -# else - { - mp_limb_t d; - y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % GMP_LIMB_BITS); - d = (int) y; - y -= d; - if (!(y >= 0.0L && y < 1.0L)) - abort (); - m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; - } -# endif -# endif - for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; ) - { - mp_limb_t hi, lo; - y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); - hi = (int) y; - y -= hi; - if (!(y >= 0.0L && y < 1.0L)) - abort (); - y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); - lo = (int) y; - y -= lo; - if (!(y >= 0.0L && y < 1.0L)) - abort (); - m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; - } - if (!(y == 0.0L)) - abort (); - /* Normalise. */ - while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0) - m.nlimbs--; - *mp = m; - *ep = exp - LDBL_MANT_BIT; - return m.limbs; -} - -/* Assuming x is finite and >= 0, and n is an integer: - Returns the decimal representation of round (x * 10^n). - Return the allocated memory - containing the decimal digits in low-to-high - order, terminated with a NUL character - in case of success, NULL in case - of memory allocation failure. */ -static char * -scale10_round_decimal_long_double (long double x, int n) -{ - int e; - mpn_t m; - void *memory = decode_long_double (x, &e, &m); - int s; - size_t extra_zeroes; - unsigned int abs_n; - unsigned int abs_s; - mp_limb_t *pow5_ptr; - size_t pow5_len; - unsigned int s_limbs; - unsigned int s_bits; - mpn_t pow5; - mpn_t z; - void *z_memory; - char *digits; - - if (memory == NULL) - return NULL; - /* x = 2^e * m, hence - y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m) - = round (2^s * 5^n * m). */ - s = e + n; - extra_zeroes = 0; - /* Factor out a common power of 10 if possible. */ - if (s > 0 && n > 0) - { - extra_zeroes = (s < n ? s : n); - s -= extra_zeroes; - n -= extra_zeroes; - } - /* Here y = round (2^s * 5^n * m) * 10^extra_zeroes. - Before converting to decimal, we need to compute - z = round (2^s * 5^n * m). */ - /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same - sign. 2.322 is slightly larger than log(5)/log(2). */ - abs_n = (n >= 0 ? n : -n); - abs_s = (s >= 0 ? s : -s); - pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 - + abs_s / GMP_LIMB_BITS + 1) - * sizeof (mp_limb_t)); - if (pow5_ptr == NULL) - { - free (memory); - return NULL; - } - /* Initialize with 1. */ - pow5_ptr[0] = 1; - pow5_len = 1; - /* Multiply with 5^|n|. */ - if (abs_n > 0) - { - static mp_limb_t const small_pow5[13 + 1] = - { - 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, - 48828125, 244140625, 1220703125 - }; - unsigned int n13; - for (n13 = 0; n13 <= abs_n; n13 += 13) - { - mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; - size_t j; - mp_twolimb_t carry = 0; - for (j = 0; j < pow5_len; j++) - { - mp_limb_t digit2 = pow5_ptr[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - pow5_ptr[j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - if (carry > 0) - pow5_ptr[pow5_len++] = (mp_limb_t) carry; - } - } - s_limbs = abs_s / GMP_LIMB_BITS; - s_bits = abs_s % GMP_LIMB_BITS; - if (n >= 0 ? s >= 0 : s <= 0) - { - /* Multiply with 2^|s|. */ - if (s_bits > 0) - { - mp_limb_t *ptr = pow5_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = pow5_len; count > 0; count--) - { - accu += (mp_twolimb_t) *ptr << s_bits; - *ptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - { - *ptr = (mp_limb_t) accu; - pow5_len++; - } - } - if (s_limbs > 0) - { - size_t count; - for (count = pow5_len; count > 0;) - { - count--; - pow5_ptr[s_limbs + count] = pow5_ptr[count]; - } - for (count = s_limbs; count > 0;) - { - count--; - pow5_ptr[count] = 0; - } - pow5_len += s_limbs; - } - pow5.limbs = pow5_ptr; - pow5.nlimbs = pow5_len; - if (n >= 0) - { - /* Multiply m with pow5. No division needed. */ - z_memory = multiply (m, pow5, &z); - } - else - { - /* Divide m by pow5 and round. */ - z_memory = divide (m, pow5, &z); - } - } - else - { - pow5.limbs = pow5_ptr; - pow5.nlimbs = pow5_len; - if (n >= 0) - { - /* n >= 0, s < 0. - Multiply m with pow5, then divide by 2^|s|. */ - mpn_t numerator; - mpn_t denominator; - void *tmp_memory; - tmp_memory = multiply (m, pow5, &numerator); - if (tmp_memory == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - /* Construct 2^|s|. */ - { - mp_limb_t *ptr = pow5_ptr + pow5_len; - size_t i; - for (i = 0; i < s_limbs; i++) - ptr[i] = 0; - ptr[s_limbs] = (mp_limb_t) 1 << s_bits; - denominator.limbs = ptr; - denominator.nlimbs = s_limbs + 1; - } - z_memory = divide (numerator, denominator, &z); - free (tmp_memory); - } - else - { - /* n < 0, s > 0. - Multiply m with 2^s, then divide by pow5. */ - mpn_t numerator; - mp_limb_t *num_ptr; - num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) - * sizeof (mp_limb_t)); - if (num_ptr == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - { - mp_limb_t *destptr = num_ptr; - { - size_t i; - for (i = 0; i < s_limbs; i++) - *destptr++ = 0; - } - if (s_bits > 0) - { - const mp_limb_t *sourceptr = m.limbs; - mp_twolimb_t accu = 0; - size_t count; - for (count = m.nlimbs; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - *destptr++ = (mp_limb_t) accu; - } - else - { - const mp_limb_t *sourceptr = m.limbs; - size_t count; - for (count = m.nlimbs; count > 0; count--) - *destptr++ = *sourceptr++; - } - numerator.limbs = num_ptr; - numerator.nlimbs = destptr - num_ptr; - } - z_memory = divide (numerator, pow5, &z); - free (num_ptr); - } - } - free (pow5_ptr); - free (memory); - - /* Here y = round (x * 10^n) = z * 10^extra_zeroes. */ - - if (z_memory == NULL) - return NULL; - digits = convert_to_decimal (z, extra_zeroes); - free (z_memory); - return digits; -} - -/* Assuming x is finite and > 0: - Return an approximation for n with 10^n <= x < 10^(n+1). - The approximation is usually the right n, but may be off by 1 sometimes. */ -static int -floorlog10l (long double x) -{ - int exp; - long double y; - double z; - double l; - - /* Split into exponential part and mantissa. */ - y = frexpl (x, &exp); - if (!(y >= 0.0L && y < 1.0L)) - abort (); - if (y == 0.0L) - return INT_MIN; - if (y < 0.5L) - { - while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } - if (y < (1.0L / (1 << 16))) - { - y *= 1.0L * (1 << 16); - exp -= 16; - } - if (y < (1.0L / (1 << 8))) - { - y *= 1.0L * (1 << 8); - exp -= 8; - } - if (y < (1.0L / (1 << 4))) - { - y *= 1.0L * (1 << 4); - exp -= 4; - } - if (y < (1.0L / (1 << 2))) - { - y *= 1.0L * (1 << 2); - exp -= 2; - } - if (y < (1.0L / (1 << 1))) - { - y *= 1.0L * (1 << 1); - exp -= 1; - } - } - if (!(y >= 0.5L && y < 1.0L)) - abort (); - /* Compute an approximation for l = log2(x) = exp + log2(y). */ - l = exp; - z = y; - if (z < 0.70710678118654752444) - { - z *= 1.4142135623730950488; - l -= 0.5; - } - if (z < 0.8408964152537145431) - { - z *= 1.1892071150027210667; - l -= 0.25; - } - if (z < 0.91700404320467123175) - { - z *= 1.0905077326652576592; - l -= 0.125; - } - if (z < 0.9576032806985736469) - { - z *= 1.0442737824274138403; - l -= 0.0625; - } - /* Now 0.95 <= z <= 1.01. */ - z = 1 - z; - /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ... - Four terms are enough to get an approximation with error < 10^-7. */ - l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25))); - /* Finally multiply with log(2)/log(10), yields an approximation for - log10(x). */ - l *= 0.30102999566398119523; - /* Round down to the next integer. */ - return (int) l + (l < 0 ? -1 : 0); -} - -#endif - -DCHAR_T * -VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, - const FCHAR_T *format, va_list args) -{ - DIRECTIVES d; - arguments a; - - if (PRINTF_PARSE (format, &d, &a) < 0) - { - errno = EINVAL; - return NULL; - } - -#define CLEANUP() \ - free (d.dir); \ - if (a.arg) \ - free (a.arg); - - if (PRINTF_FETCHARGS (args, &a) < 0) - { - CLEANUP (); - errno = EINVAL; - return NULL; - } - - { - size_t buf_neededlength; - TCHAR_T *buf; - TCHAR_T *buf_malloced; - const FCHAR_T *cp; - size_t i; - DIRECTIVE *dp; - /* Output string accumulator. */ - DCHAR_T *result; - size_t allocated; - size_t length; - - /* Allocate a small buffer that will hold a directive passed to - sprintf or snprintf. */ - buf_neededlength = - xsum4 (7, d.max_width_length, d.max_precision_length, 6); -#if HAVE_ALLOCA - if (buf_neededlength < 4000 / sizeof (TCHAR_T)) - { - buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); - buf_malloced = NULL; - } - else -#endif - { - size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); - if (size_overflow_p (buf_memsize)) - goto out_of_memory_1; - buf = (TCHAR_T *) malloc (buf_memsize); - if (buf == NULL) - goto out_of_memory_1; - buf_malloced = buf; - } - - if (resultbuf != NULL) - { - result = resultbuf; - allocated = *lengthp; - } - else - { - result = NULL; - allocated = 0; - } - length = 0; - /* Invariants: - result is either == resultbuf or == NULL or malloc-allocated. - If length > 0, then result != NULL. */ - - /* Ensures that allocated >= needed. Aborts through a jump to - out_of_memory if needed is SIZE_MAX or otherwise too big. */ -#define ENSURE_ALLOCATION(needed) \ - if ((needed) > allocated) \ - { \ - size_t memory_size; \ - DCHAR_T *memory; \ - \ - allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ - if ((needed) > allocated) \ - allocated = (needed); \ - memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ - if (size_overflow_p (memory_size)) \ - goto out_of_memory; \ - if (result == resultbuf || result == NULL) \ - memory = (DCHAR_T *) malloc (memory_size); \ - else \ - memory = (DCHAR_T *) realloc (result, memory_size); \ - if (memory == NULL) \ - goto out_of_memory; \ - if (result == resultbuf && length > 0) \ - DCHAR_CPY (memory, result, length); \ - result = memory; \ - } - - for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) - { - if (cp != dp->dir_start) - { - size_t n = dp->dir_start - cp; - size_t augmented_length = xsum (length, n); - - ENSURE_ALLOCATION (augmented_length); - /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we - need that the format string contains only ASCII characters - if FCHAR_T and DCHAR_T are not the same type. */ - if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) - { - DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); - length = augmented_length; - } - else - { - do - result[length++] = (unsigned char) *cp++; - while (--n > 0); - } - } - if (i == d.count) - break; - - /* Execute a single directive. */ - if (dp->conversion == '%') - { - size_t augmented_length; - - if (!(dp->arg_index == ARG_NONE)) - abort (); - augmented_length = xsum (length, 1); - ENSURE_ALLOCATION (augmented_length); - result[length] = '%'; - length = augmented_length; - } - else - { - if (!(dp->arg_index != ARG_NONE)) - abort (); - - if (dp->conversion == 'n') - { - switch (a.arg[dp->arg_index].type) - { - case TYPE_COUNT_SCHAR_POINTER: - *a.arg[dp->arg_index].a.a_count_schar_pointer = length; - break; - case TYPE_COUNT_SHORT_POINTER: - *a.arg[dp->arg_index].a.a_count_short_pointer = length; - break; - case TYPE_COUNT_INT_POINTER: - *a.arg[dp->arg_index].a.a_count_int_pointer = length; - break; - case TYPE_COUNT_LONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longint_pointer = length; - break; -#if HAVE_LONG_LONG_INT - case TYPE_COUNT_LONGLONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; - break; -#endif - default: - abort (); - } - } -#if ENABLE_UNISTDIO - /* The unistdio extensions. */ - else if (dp->conversion == 'U') - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - switch (type) - { - case TYPE_U8_STRING: - { - const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; - const uint8_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u8_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - -# if DCHAR_IS_UINT8_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } -# else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; -# if DCHAR_IS_TCHAR - /* Convert from UTF-8 to locale encoding. */ - if (u8_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - &converted, &converted_len) - < 0) -# else - /* Convert from UTF-8 to UTF-16/UTF-32. */ - converted = - U8_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); - if (converted == NULL) -# endif - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } -# endif - - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U16_STRING: - { - const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; - const uint16_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u16_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - -# if DCHAR_IS_UINT16_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } -# else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; -# if DCHAR_IS_TCHAR - /* Convert from UTF-16 to locale encoding. */ - if (u16_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - &converted, &converted_len) - < 0) -# else - /* Convert from UTF-16 to UTF-8/UTF-32. */ - converted = - U16_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); - if (converted == NULL) -# endif - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } -# endif - - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U32_STRING: - { - const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; - const uint32_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u32_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - -# if DCHAR_IS_UINT32_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } -# else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; -# if DCHAR_IS_TCHAR - /* Convert from UTF-32 to locale encoding. */ - if (u32_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - &converted, &converted_len) - < 0) -# else - /* Convert from UTF-32 to UTF-8/UTF-16. */ - converted = - U32_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); - if (converted == NULL) -# endif - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } -# endif - - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - default: - abort (); - } - } -#endif -#if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL - else if (dp->conversion == 'a' || dp->conversion == 'A') - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* Allocate a temporary buffer of sufficient size. */ - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) ((LDBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) ((DBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - - if (tmp_length < width) - tmp_length = width; - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } - - pad_ptr = NULL; - p = tmp; - if (type == TYPE_LONGDOUBLE) - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - long double mantissa; - - if (arg > 0.0L) - mantissa = printf_frexpl (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0L; - } - - if (has_precision - && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - long double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5L : tail > 0.5L) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0L; - } - if (tail != 0.0L) - for (q = precision; q > 0; q--) - tail *= 0.0625L; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0L || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0L) - { - mantissa *= 16.0L; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; -# if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; -# else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } -# endif - } - - END_LONG_DOUBLE_ROUNDING (); - } - } - else - { - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnan (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - double mantissa; - - if (arg > 0.0) - mantissa = printf_frexp (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0; - } - - if (has_precision - && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5 : tail > 0.5) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0; - } - if (tail != 0.0) - for (q = precision; q > 0; q--) - tail *= 0.0625; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0 || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0) - { - mantissa *= 16.0; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; -# if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; -# else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } -# endif - } - } - } - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } -#endif -#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'f' || dp->conversion == 'F' - || dp->conversion == 'e' || dp->conversion == 'E' - || dp->conversion == 'g' || dp->conversion == 'G' - || dp->conversion == 'a' || dp->conversion == 'A') - && (0 -# if NEED_PRINTF_INFINITE_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_DOUBLE - /* The systems (mingw) which produce wrong output - for Inf, -Inf, and NaN also do so for -0.0. - Therefore we treat this case here as well. */ - && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) -# endif -# if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE -# elif NEED_PRINTF_INFINITE_LONG_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE - /* Some systems produce wrong output for Inf, - -Inf, and NaN. */ - && is_infinitel (a.arg[dp->arg_index].a.a_longdouble)) -# endif - )) - { -# if NEED_PRINTF_INFINITE_DOUBLE && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) - arg_type type = a.arg[dp->arg_index].type; -# endif - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* POSIX specifies the default precision to be 6 for %f, %F, - %e, %E, but not for %g, %G. Implementations appear to use - the same default precision also for %g, %G. */ - if (!has_precision) - precision = 6; - - /* Allocate a temporary buffer of sufficient size. */ -# if NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); -# elif NEED_PRINTF_LONG_DOUBLE - tmp_length = LDBL_DIG + 1; -# else - tmp_length = 0; -# endif - if (tmp_length < precision) - tmp_length = precision; -# if NEED_PRINTF_LONG_DOUBLE -# if NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) -# endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - if (!(isnanl (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10l (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } -# endif - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - - if (tmp_length < width) - tmp_length = width; - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } - - pad_ptr = NULL; - p = tmp; - -# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE -# if NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) -# endif - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { -# if NEED_PRINTF_LONG_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_long_double (arg, precision); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0L) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0L. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)precision - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - - /* Here ndigits = precision+1. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ -# if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; -# else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } -# endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0L) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0L. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ -# if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; -# else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } -# endif - } - - free (digits); - } - } - else - abort (); -# else - /* arg is finite. */ - abort (); -# endif - } - - END_LONG_DOUBLE_ROUNDING (); - } - } -# if NEED_PRINTF_INFINITE_DOUBLE - else -# endif -# endif -# if NEED_PRINTF_INFINITE_DOUBLE - { - /* Simpler than above: handle only NaN, Infinity, zero. */ - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnan (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - if (!(arg == 0.0)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - /* Produce the same number of exponent digits as - the native printf implementation. */ -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *p++ = '0'; -# endif - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else - abort (); - } - } - } -# endif - - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } -#endif - else - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; -#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO - int has_width; - size_t width; -#endif -#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO - int pad_ourselves; -#else -# define pad_ourselves 0 -#endif - TCHAR_T *fbp; - unsigned int prefix_count; - int prefixes[2]; -#if !USE_SNPRINTF - size_t tmp_length; - TCHAR_T tmpbuf[700]; - TCHAR_T *tmp; -#endif - -#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } -#endif - -#if !USE_SNPRINTF - /* Allocate a temporary buffer of sufficient size for calling - sprintf. */ - { - size_t precision; - - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - precision = (arg < 0 ? 0 : arg); - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - } - } - - switch (dp->conversion) - { - - case 'd': case 'i': case 'u': -# if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Multiply by 2, as an estimate for FLAG_GROUP. */ - tmp_length = xsum (tmp_length, tmp_length); - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'o': -# if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'x': case 'X': -# if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 2, to account for a leading sign or alternate form. */ - tmp_length = xsum (tmp_length, 2); - break; - - case 'f': case 'F': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - else - tmp_length = - (unsigned int) (DBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'e': case 'E': case 'g': case 'G': - tmp_length = - 12; /* sign, decimal point, exponent etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'a': case 'A': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (DBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - break; - - case 'c': -# if HAVE_WINT_T && !WIDE_CHAR_VERSION - if (type == TYPE_WIDE_CHAR) - tmp_length = MB_CUR_MAX; - else -# endif - tmp_length = 1; - break; - - case 's': -# if HAVE_WCHAR_T - if (type == TYPE_WIDE_STRING) - { - tmp_length = - local_wcslen (a.arg[dp->arg_index].a.a_wide_string); - -# if !WIDE_CHAR_VERSION - tmp_length = xtimes (tmp_length, MB_CUR_MAX); -# endif - } - else -# endif - tmp_length = strlen (a.arg[dp->arg_index].a.a_string); - break; - - case 'p': - tmp_length = - (unsigned int) (sizeof (void *) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading 0x */ - break; - - default: - abort (); - } - -# if ENABLE_UNISTDIO - /* Padding considers the number of characters, therefore the - number of elements after padding may be - > max (tmp_length, width) - but is certainly - <= tmp_length + width. */ - tmp_length = xsum (tmp_length, width); -# else - /* Padding considers the number of elements, says POSIX. */ - if (tmp_length < width) - tmp_length = width; -# endif - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - } - - if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (TCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } -#endif - - /* Decide whether to perform the padding ourselves. */ -#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO - switch (dp->conversion) - { -# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need - to perform the padding after this conversion. Functions - with unistdio extensions perform the padding based on - character count rather than element count. */ - case 'c': case 's': -# endif -# if NEED_PRINTF_FLAG_ZERO - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': -# endif - pad_ourselves = 1; - break; - default: - pad_ourselves = 0; - break; - } -#endif - - /* Construct the format string for calling snprintf or - sprintf. */ - fbp = buf; - *fbp++ = '%'; -#if NEED_PRINTF_FLAG_GROUPING - /* The underlying implementation doesn't support the ' flag. - Produce no grouping characters in this case; this is - acceptable because the grouping is locale dependent. */ -#else - if (flags & FLAG_GROUP) - *fbp++ = '\''; -#endif - if (flags & FLAG_LEFT) - *fbp++ = '-'; - if (flags & FLAG_SHOWSIGN) - *fbp++ = '+'; - if (flags & FLAG_SPACE) - *fbp++ = ' '; - if (flags & FLAG_ALT) - *fbp++ = '#'; - if (!pad_ourselves) - { - if (flags & FLAG_ZERO) - *fbp++ = '0'; - if (dp->width_start != dp->width_end) - { - size_t n = dp->width_end - dp->width_start; - /* The width specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->width_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - if (dp->precision_start != dp->precision_end) - { - size_t n = dp->precision_end - dp->precision_start; - /* The precision specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->precision_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - - switch (type) - { -#if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - case TYPE_ULONGLONGINT: -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *fbp++ = 'I'; - *fbp++ = '6'; - *fbp++ = '4'; - break; -# else - *fbp++ = 'l'; - /*FALLTHROUGH*/ -# endif -#endif - case TYPE_LONGINT: - case TYPE_ULONGINT: -#if HAVE_WINT_T - case TYPE_WIDE_CHAR: -#endif -#if HAVE_WCHAR_T - case TYPE_WIDE_STRING: -#endif - *fbp++ = 'l'; - break; - case TYPE_LONGDOUBLE: - *fbp++ = 'L'; - break; - default: - break; - } -#if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - *fbp = 'f'; - else -#endif - *fbp = dp->conversion; -#if USE_SNPRINTF - fbp[1] = '%'; - fbp[2] = 'n'; - fbp[3] = '\0'; -#else - fbp[1] = '\0'; -#endif - - /* Construct the arguments for calling snprintf or sprintf. */ - prefix_count = 0; - if (!pad_ourselves && dp->width_arg_index != ARG_NONE) - { - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; - } - if (dp->precision_arg_index != ARG_NONE) - { - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; - } - -#if USE_SNPRINTF - /* The SNPRINTF result is appended after result[0..length]. - The latter is an array of DCHAR_T; SNPRINTF appends an - array of TCHAR_T to it. This is possible because - sizeof (TCHAR_T) divides sizeof (DCHAR_T) and - alignof (TCHAR_T) <= alignof (DCHAR_T). */ -# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) - /* Prepare checking whether snprintf returns the count - via %n. */ - ENSURE_ALLOCATION (xsum (length, 1)); - *(TCHAR_T *) (result + length) = '\0'; -#endif - - for (;;) - { - int count = -1; - -#if USE_SNPRINTF - int retcount = 0; - size_t maxlen = allocated - length; - /* SNPRINTF can fail if its second argument is - > INT_MAX. */ - if (maxlen > INT_MAX / TCHARS_PER_DCHAR) - goto overflow; - maxlen = maxlen * TCHARS_PER_DCHAR; -# define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - arg, &count); \ - break; \ - case 1: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], arg, &count); \ - break; \ - case 2: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], prefixes[1], arg, \ - &count); \ - break; \ - default: \ - abort (); \ - } -#else -# define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - count = sprintf (tmp, buf, arg); \ - break; \ - case 1: \ - count = sprintf (tmp, buf, prefixes[0], arg); \ - break; \ - case 2: \ - count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ - arg); \ - break; \ - default: \ - abort (); \ - } -#endif - - switch (type) - { - case TYPE_SCHAR: - { - int arg = a.arg[dp->arg_index].a.a_schar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UCHAR: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uchar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_SHORT: - { - int arg = a.arg[dp->arg_index].a.a_short; - SNPRINTF_BUF (arg); - } - break; - case TYPE_USHORT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_ushort; - SNPRINTF_BUF (arg); - } - break; - case TYPE_INT: - { - int arg = a.arg[dp->arg_index].a.a_int; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UINT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGINT: - { - long int arg = a.arg[dp->arg_index].a.a_longint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGINT: - { - unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; - SNPRINTF_BUF (arg); - } - break; -#if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - { - long long int arg = a.arg[dp->arg_index].a.a_longlongint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGLONGINT: - { - unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_DOUBLE: - { - double arg = a.arg[dp->arg_index].a.a_double; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGDOUBLE: - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - SNPRINTF_BUF (arg); - } - break; - case TYPE_CHAR: - { - int arg = a.arg[dp->arg_index].a.a_char; - SNPRINTF_BUF (arg); - } - break; -#if HAVE_WINT_T - case TYPE_WIDE_CHAR: - { - wint_t arg = a.arg[dp->arg_index].a.a_wide_char; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_STRING: - { - const char *arg = a.arg[dp->arg_index].a.a_string; - SNPRINTF_BUF (arg); - } - break; -#if HAVE_WCHAR_T - case TYPE_WIDE_STRING: - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_POINTER: - { - void *arg = a.arg[dp->arg_index].a.a_pointer; - SNPRINTF_BUF (arg); - } - break; - default: - abort (); - } - -#if USE_SNPRINTF - /* Portability: Not all implementations of snprintf() - are ISO C 99 compliant. Determine the number of - bytes that snprintf() has produced or would have - produced. */ - if (count >= 0) - { - /* Verify that snprintf() has NUL-terminated its - result. */ - if (count < maxlen - && ((TCHAR_T *) (result + length)) [count] != '\0') - abort (); - /* Portability hack. */ - if (retcount > count) - count = retcount; - } - else - { - /* snprintf() doesn't understand the '%n' - directive. */ - if (fbp[1] != '\0') - { - /* Don't use the '%n' directive; instead, look - at the snprintf() return value. */ - fbp[1] = '\0'; - continue; - } - else - { - /* Look at the snprintf() return value. */ - if (retcount < 0) - { - /* HP-UX 10.20 snprintf() is doubly deficient: - It doesn't understand the '%n' directive, - *and* it returns -1 (rather than the length - that would have been required) when the - buffer is too small. */ - size_t bigger_need = - xsum (xtimes (allocated, 2), 12); - ENSURE_ALLOCATION (bigger_need); - continue; - } - else - count = retcount; - } - } -#endif - - /* Attempt to handle failure. */ - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EINVAL; - return NULL; - } - -#if USE_SNPRINTF - /* Handle overflow of the allocated buffer. */ - if (count >= maxlen) - { - /* Need at least count * sizeof (TCHAR_T) bytes. But - allocate proportionally, to avoid looping eternally - if snprintf() reports a too small count. */ - size_t n = - xmax (xsum (length, - (count + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR), - xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - continue; - } -#endif - -#if !DCHAR_IS_TCHAR -# if !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); -# endif - - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - if (dp->conversion == 'c' || dp->conversion == 's') - { - /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING - TYPE_WIDE_STRING. - The result string is not certainly ASCII. */ - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify - [2 * (sizeof (TCHAR_T) == 1) - 1]; -# if USE_SNPRINTF - tmpsrc = (TCHAR_T *) (result + length); -# else - tmpsrc = tmp; -# endif - tmpdst = NULL; - tmpdst_len = 0; - if (DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, count, - NULL, - &tmpdst, &tmpdst_len) - < 0) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - count = tmpdst_len; - } - else - { - /* The result string is ASCII. - Simple 1:1 conversion. */ -# if USE_SNPRINTF - /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a - no-op conversion, in-place on the array starting - at (result + length). */ - if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) -# endif - { - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t n; - -# if USE_SNPRINTF - if (result == resultbuf) - { - tmpsrc = (TCHAR_T *) (result + length); - /* ENSURE_ALLOCATION will not move tmpsrc - (because it's part of resultbuf). */ - ENSURE_ALLOCATION (xsum (length, count)); - } - else - { - /* ENSURE_ALLOCATION will move the array - (because it uses realloc(). */ - ENSURE_ALLOCATION (xsum (length, count)); - tmpsrc = (TCHAR_T *) (result + length); - } -# else - tmpsrc = tmp; - ENSURE_ALLOCATION (xsum (length, count)); -# endif - tmpdst = result + length; - /* Copy backwards, because of overlapping. */ - tmpsrc += count; - tmpdst += count; - for (n = count; n > 0; n--) - *--tmpdst = (unsigned char) *--tmpsrc; - } - } -#endif - -#if DCHAR_IS_TCHAR && !USE_SNPRINTF - /* Make room for the result. */ - if (count > allocated - length) - { - /* Need at least count elements. But allocate - proportionally. */ - size_t n = - xmax (xsum (length, count), xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - } -#endif - - /* Here count <= allocated - length. */ - - /* Perform padding. */ -#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO - if (pad_ourselves && has_width) - { - size_t w; -# if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, count); -# else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = count; -# endif - if (w < width) - { - size_t pad = width - w; -# if USE_SNPRINTF - /* Make room for the result. */ - if (xsum (count, pad) > allocated - length) - { - /* Need at least count + pad elements. But - allocate proportionally. */ - size_t n = - xmax (xsum3 (length, count, pad), - xtimes (allocated, 2)); - - length += count; - ENSURE_ALLOCATION (n); - length -= count; - } - /* Here count + pad <= allocated - length. */ -# endif - { -# if !DCHAR_IS_TCHAR || USE_SNPRINTF - DCHAR_T * const rp = result + length; -# else - DCHAR_T * const rp = tmp; -# endif - DCHAR_T *p = rp + count; - DCHAR_T *end = p + pad; -# if NEED_PRINTF_FLAG_ZERO - DCHAR_T *pad_ptr; -# if !DCHAR_IS_TCHAR - if (dp->conversion == 'c' - || dp->conversion == 's') - /* No zero-padding for string directives. */ - pad_ptr = NULL; - else -# endif - { - pad_ptr = (*rp == '-' ? rp + 1 : rp); - /* No zero-padding of "inf" and "nan". */ - if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') - || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) - pad_ptr = NULL; - } -# endif - /* The generated string now extends from rp to p, - with the zero padding insertion point being at - pad_ptr. */ - - count = count + pad; /* = end - rp */ - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } -# if NEED_PRINTF_FLAG_ZERO - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } -# endif - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > rp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - } - } - } -#endif - -#if DCHAR_IS_TCHAR && !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); -#endif - - /* Here still count <= allocated - length. */ - -#if !DCHAR_IS_TCHAR || USE_SNPRINTF - /* The snprintf() result did fit. */ -#else - /* Append the sprintf() result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); -#endif -#if !USE_SNPRINTF - if (tmp != tmpbuf) - free (tmp); -#endif - -#if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - { - /* Convert the %f result to upper case for %F. */ - DCHAR_T *rp = result + length; - size_t rc; - for (rc = count; rc > 0; rc--, rp++) - if (*rp >= 'a' && *rp <= 'z') - *rp = *rp - 'a' + 'A'; - } -#endif - - length += count; - break; - } - } - } - } - - /* Add the final NUL. */ - ENSURE_ALLOCATION (xsum (length, 1)); - result[length] = '\0'; - - if (result != resultbuf && length + 1 < allocated) - { - /* Shrink the allocated memory if possible. */ - DCHAR_T *memory; - - memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); - if (memory != NULL) - result = memory; - } - - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - *lengthp = length; - /* Note that we can produce a big string of a length > INT_MAX. POSIX - says that snprintf() fails with errno = EOVERFLOW in this case, but - that's only because snprintf() returns an 'int'. This function does - not have this limitation. */ - return result; - - overflow: - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EOVERFLOW; - return NULL; - - out_of_memory: - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - out_of_memory_1: - CLEANUP (); - errno = ENOMEM; - return NULL; - } -} - -#undef TCHARS_PER_DCHAR -#undef SNPRINTF -#undef USE_SNPRINTF -#undef PRINTF_PARSE -#undef DIRECTIVES -#undef DIRECTIVE -#undef TCHAR_T -#undef DCHAR_T -#undef FCHAR_T -#undef VASNPRINTF diff --git a/lib/vasnprintf.h b/lib/vasnprintf.h deleted file mode 100644 index 7a0c01f..0000000 --- a/lib/vasnprintf.h +++ /dev/null @@ -1,81 +0,0 @@ -/* vsprintf with automatic memory allocation. - Copyright (C) 2002-2004, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _VASNPRINTF_H -#define _VASNPRINTF_H - -/* Get va_list. */ -#include - -/* Get size_t. */ -#include - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Write formatted output to a string dynamically allocated with malloc(). - You can pass a preallocated buffer for the result in RESULTBUF and its - size in *LENGTHP; otherwise you pass RESULTBUF = NULL. - If successful, return the address of the string (this may be = RESULTBUF - if no dynamic memory allocation was necessary) and set *LENGTHP to the - number of resulting bytes, excluding the trailing NUL. Upon error, set - errno and return NULL. - - When dynamic memory allocation occurs, the preallocated buffer is left - alone (with possibly modified contents). This makes it possible to use - a statically allocated or stack-allocated buffer, like this: - - char buf[100]; - size_t len = sizeof (buf); - char *output = vasnprintf (buf, &len, format, args); - if (output == NULL) - ... error handling ...; - else - { - ... use the output string ...; - if (output != buf) - free (output); - } - */ -#if REPLACE_VASNPRINTF -# define asnprintf rpl_asnprintf -# define vasnprintf rpl_vasnprintf -#endif -extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); -extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 3, 0))); - -#ifdef __cplusplus -} -#endif - -#endif /* _VASNPRINTF_H */ diff --git a/lib/vsnprintf.c b/lib/vsnprintf.c deleted file mode 100644 index 4f841fc..0000000 --- a/lib/vsnprintf.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 2004, 2006-2007 Free Software Foundation, Inc. - Written by Simon Josefsson and Yoann Vandoorselaere . - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -/* Specification. */ -#include - -#include -#include -#include -#include -#include - -#include "vasnprintf.h" - -/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ -#ifndef EOVERFLOW -# define EOVERFLOW E2BIG -#endif - -/* Print formatted output to string STR. Similar to vsprintf, but - additional length SIZE limit how much is written into STR. Returns - string length of formatted string (which may be larger than SIZE). - STR may be NULL, in which case nothing will be written. On error, - return a negative value. */ -int -vsnprintf (char *str, size_t size, const char *format, va_list args) -{ - char *output; - size_t len; - size_t lenbuf = size; - - output = vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - - if (!output) - return -1; - - if (output != str) - { - if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } - - free (output); - } - - if (len > INT_MAX) - { - errno = EOVERFLOW; - return -1; - } - - return len; -} diff --git a/lib/wchar.in.h b/lib/wchar.in.h deleted file mode 100644 index 924a338..0000000 --- a/lib/wchar.in.h +++ /dev/null @@ -1,82 +0,0 @@ -/* A substitute for ISO C99 , for platforms that have issues. - - Copyright (C) 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Written by Eric Blake. */ - -/* - * ISO C 99 for platforms that have issues. - * - * - * For now, this just ensures proper prerequisite inclusion order and - * the declaration of wcwidth(). - */ - -#ifndef _GL_WCHAR_H - -/* Tru64 with Desktop Toolkit C has a bug: must be included before - . - BSD/OS 4.0.1 has a bug: , and must be - included before . */ -#include -#include -#include - -/* Include the original if it exists. - Some builds of uClibc lack it. */ -/* The include_next requires a split double-inclusion guard. */ -#if @HAVE_WCHAR_H@ -# @INCLUDE_NEXT@ @NEXT_WCHAR_H@ -#endif - -#ifndef _GL_WCHAR_H -#define _GL_WCHAR_H - -/* The definition of GL_LINK_WARNING is copied here. */ - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Return the number of screen columns needed for WC. */ -#if @GNULIB_WCWIDTH@ -# if @REPLACE_WCWIDTH@ -# undef wcwidth -# define wcwidth rpl_wcwidth -extern int wcwidth (wchar_t); -# else -# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@ -/* wcwidth exists but is not declared. */ -extern int wcwidth (int /* actually wchar_t */); -# endif -# endif -#elif defined GNULIB_POSIXCHECK -# undef wcwidth -# define wcwidth(w) \ - (GL_LINK_WARNING ("wcwidth is unportable - " \ - "use gnulib module wcwidth for portability"), \ - wcwidth (w)) -#endif - - -#ifdef __cplusplus -} -#endif - -#endif /* _GL_WCHAR_H */ -#endif /* _GL_WCHAR_H */ diff --git a/lib/xalloc-die.c b/lib/xalloc-die.c deleted file mode 100644 index 090f060..0000000 --- a/lib/xalloc-die.c +++ /dev/null @@ -1,42 +0,0 @@ -/* Report a memory allocation failure and exit. - - Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2006 Free - Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#include "xalloc.h" - -#include - -#include "error.h" -#include "exitfail.h" - -#include "gettext.h" -#define _(msgid) gettext (msgid) - -void -xalloc_die (void) -{ - error (exit_failure, 0, "%s", _("memory exhausted")); - - /* The `noreturn' cannot be given to error, since it may return if - its first argument is 0. To help compilers understand the - xalloc_die does not return, call abort. Also, the abort is a - safety feature if exit_failure is 0 (which shouldn't happen). */ - abort (); -} diff --git a/lib/xalloc.h b/lib/xalloc.h deleted file mode 100644 index 0c6d8dc..0000000 --- a/lib/xalloc.h +++ /dev/null @@ -1,271 +0,0 @@ -/* xalloc.h -- malloc with out-of-memory checking - - Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef XALLOC_H_ -# define XALLOC_H_ - -# include - - -# ifdef __cplusplus -extern "C" { -# endif - - -# ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ -# define __attribute__(x) -# endif -# endif - -# ifndef ATTRIBUTE_NORETURN -# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) -# endif - -/* This function is always triggered when memory is exhausted. - It must be defined by the application, either explicitly - or by using gnulib's xalloc-die module. This is the - function to call when one wants the program to die because of a - memory allocation failure. */ -extern void xalloc_die (void) ATTRIBUTE_NORETURN; - -void *xmalloc (size_t s); -void *xzalloc (size_t s); -void *xcalloc (size_t n, size_t s); -void *xrealloc (void *p, size_t s); -void *x2realloc (void *p, size_t *pn); -void *xmemdup (void const *p, size_t s); -char *xstrdup (char const *str); - -/* Return 1 if an array of N objects, each of size S, cannot exist due - to size arithmetic overflow. S must be positive and N must be - nonnegative. This is a macro, not an inline function, so that it - works correctly even when SIZE_MAX < N. - - By gnulib convention, SIZE_MAX represents overflow in size - calculations, so the conservative dividend to use here is - SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. - However, malloc (SIZE_MAX) fails on all known hosts where - sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for - exactly-SIZE_MAX allocations on such hosts; this avoids a test and - branch when S is known to be 1. */ -# define xalloc_oversized(n, s) \ - ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) - - -/* In the following macros, T must be an elementary or structure/union or - typedef'ed type, or a pointer to such a type. To apply one of the - following macros to a function pointer or array type, you need to typedef - it first and use the typedef name. */ - -/* Allocate an object of type T dynamically, with error checking. */ -/* extern t *XMALLOC (typename t); */ -# define XMALLOC(t) ((t *) xmalloc (sizeof (t))) - -/* Allocate memory for N elements of type T, with error checking. */ -/* extern t *XNMALLOC (size_t n, typename t); */ -# define XNMALLOC(n, t) \ - ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) - -/* Allocate an object of type T dynamically, with error checking, - and zero it. */ -/* extern t *XZALLOC (typename t); */ -# define XZALLOC(t) ((t *) xzalloc (sizeof (t))) - -/* Allocate memory for N elements of type T, with error checking, - and zero it. */ -/* extern t *XCALLOC (size_t n, typename t); */ -# define XCALLOC(n, t) \ - ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) - - -# if HAVE_INLINE -# define static_inline static inline -# else - void *xnmalloc (size_t n, size_t s); - void *xnrealloc (void *p, size_t n, size_t s); - void *x2nrealloc (void *p, size_t *pn, size_t s); - char *xcharalloc (size_t n); -# endif - -# ifdef static_inline - -/* Allocate an array of N objects, each with S bytes of memory, - dynamically, with error checking. S must be nonzero. */ - -static_inline void * -xnmalloc (size_t n, size_t s) -{ - if (xalloc_oversized (n, s)) - xalloc_die (); - return xmalloc (n * s); -} - -/* Change the size of an allocated block of memory P to an array of N - objects each of S bytes, with error checking. S must be nonzero. */ - -static_inline void * -xnrealloc (void *p, size_t n, size_t s) -{ - if (xalloc_oversized (n, s)) - xalloc_die (); - return xrealloc (p, n * s); -} - -/* If P is null, allocate a block of at least *PN such objects; - otherwise, reallocate P so that it contains more than *PN objects - each of S bytes. *PN must be nonzero unless P is null, and S must - be nonzero. Set *PN to the new number of objects, and return the - pointer to the new block. *PN is never set to zero, and the - returned pointer is never null. - - Repeated reallocations are guaranteed to make progress, either by - allocating an initial block with a nonzero size, or by allocating a - larger block. - - In the following implementation, nonzero sizes are increased by a - factor of approximately 1.5 so that repeated reallocations have - O(N) overall cost rather than O(N**2) cost, but the - specification for this function does not guarantee that rate. - - Here is an example of use: - - int *p = NULL; - size_t used = 0; - size_t allocated = 0; - - void - append_int (int value) - { - if (used == allocated) - p = x2nrealloc (p, &allocated, sizeof *p); - p[used++] = value; - } - - This causes x2nrealloc to allocate a block of some nonzero size the - first time it is called. - - To have finer-grained control over the initial size, set *PN to a - nonzero value before calling this function with P == NULL. For - example: - - int *p = NULL; - size_t used = 0; - size_t allocated = 0; - size_t allocated1 = 1000; - - void - append_int (int value) - { - if (used == allocated) - { - p = x2nrealloc (p, &allocated1, sizeof *p); - allocated = allocated1; - } - p[used++] = value; - } - - */ - -static_inline void * -x2nrealloc (void *p, size_t *pn, size_t s) -{ - size_t n = *pn; - - if (! p) - { - if (! n) - { - /* The approximate size to use for initial small allocation - requests, when the invoking code specifies an old size of - zero. 64 bytes is the largest "small" request for the - GNU C library malloc. */ - enum { DEFAULT_MXFAST = 64 }; - - n = DEFAULT_MXFAST / s; - n += !n; - } - } - else - { - /* Set N = ceil (1.5 * N) so that progress is made if N == 1. - Check for overflow, so that N * S stays in size_t range. - The check is slightly conservative, but an exact check isn't - worth the trouble. */ - if ((size_t) -1 / 3 * 2 / s <= n) - xalloc_die (); - n += (n + 1) / 2; - } - - *pn = n; - return xrealloc (p, n * s); -} - -/* Return a pointer to a new buffer of N bytes. This is like xmalloc, - except it returns char *. */ - -static_inline char * -xcharalloc (size_t n) -{ - return XNMALLOC (n, char); -} - -# endif - -# ifdef __cplusplus -} - -/* C++ does not allow conversions from void * to other pointer types - without a cast. Use templates to work around the problem when - possible. */ - -template inline T * -xrealloc (T *p, size_t s) -{ - return (T *) xrealloc ((void *) p, s); -} - -template inline T * -xnrealloc (T *p, size_t n, size_t s) -{ - return (T *) xnrealloc ((void *) p, n, s); -} - -template inline T * -x2realloc (T *p, size_t *pn) -{ - return (T *) x2realloc ((void *) p, pn); -} - -template inline T * -x2nrealloc (T *p, size_t *pn, size_t s) -{ - return (T *) x2nrealloc ((void *) p, pn, s); -} - -template inline T * -xmemdup (T const *p, size_t s) -{ - return (T *) xmemdup ((void const *) p, s); -} - -# endif - - -#endif /* !XALLOC_H_ */ diff --git a/lib/xmalloc.c b/lib/xmalloc.c deleted file mode 100644 index 318e0dd..0000000 --- a/lib/xmalloc.c +++ /dev/null @@ -1,123 +0,0 @@ -/* xmalloc.c -- malloc with out of memory checking - - Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, - Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -#if ! HAVE_INLINE -# define static_inline -#endif -#include "xalloc.h" -#undef static_inline - -#include -#include - -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - -/* 1 if calloc is known to be compatible with GNU calloc. This - matters if we are not also using the calloc module, which defines - HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ -#if defined HAVE_CALLOC || defined __GLIBC__ -enum { HAVE_GNU_CALLOC = 1 }; -#else -enum { HAVE_GNU_CALLOC = 0 }; -#endif - -/* Allocate N bytes of memory dynamically, with error checking. */ - -void * -xmalloc (size_t n) -{ - void *p = malloc (n); - if (!p && n != 0) - xalloc_die (); - return p; -} - -/* Change the size of an allocated block of memory P to N bytes, - with error checking. */ - -void * -xrealloc (void *p, size_t n) -{ - p = realloc (p, n); - if (!p && n != 0) - xalloc_die (); - return p; -} - -/* If P is null, allocate a block of at least *PN bytes; otherwise, - reallocate P so that it contains more than *PN bytes. *PN must be - nonzero unless P is null. Set *PN to the new block's size, and - return the pointer to the new block. *PN is never set to zero, and - the returned pointer is never null. */ - -void * -x2realloc (void *p, size_t *pn) -{ - return x2nrealloc (p, pn, 1); -} - -/* Allocate S bytes of zeroed memory dynamically, with error checking. - There's no need for xnzalloc (N, S), since it would be equivalent - to xcalloc (N, S). */ - -void * -xzalloc (size_t s) -{ - return memset (xmalloc (s), 0, s); -} - -/* Allocate zeroed memory for N elements of S bytes, with error - checking. S must be nonzero. */ - -void * -xcalloc (size_t n, size_t s) -{ - void *p; - /* Test for overflow, since some calloc implementations don't have - proper overflow checks. But omit overflow and size-zero tests if - HAVE_GNU_CALLOC, since GNU calloc catches overflow and never - returns NULL if successful. */ - if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) - || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) - xalloc_die (); - return p; -} - -/* Clone an object P of size S, with error checking. There's no need - for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any - need for an arithmetic overflow check. */ - -void * -xmemdup (void const *p, size_t s) -{ - return memcpy (xmalloc (s), p, s); -} - -/* Clone STRING. */ - -char * -xstrdup (char const *string) -{ - return xmemdup (string, strlen (string) + 1); -} diff --git a/lib/xsize.h b/lib/xsize.h deleted file mode 100644 index 341fb16..0000000 --- a/lib/xsize.h +++ /dev/null @@ -1,108 +0,0 @@ -/* xsize.h -- Checked size_t computations. - - Copyright (C) 2003 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _XSIZE_H -#define _XSIZE_H - -/* Get size_t. */ -#include - -/* Get SIZE_MAX. */ -#include -#if HAVE_STDINT_H -# include -#endif - -/* The size of memory objects is often computed through expressions of - type size_t. Example: - void* p = malloc (header_size + n * element_size). - These computations can lead to overflow. When this happens, malloc() - returns a piece of memory that is way too small, and the program then - crashes while attempting to fill the memory. - To avoid this, the functions and macros in this file check for overflow. - The convention is that SIZE_MAX represents overflow. - malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc - implementation that uses mmap --, it's recommended to use size_overflow_p() - or size_in_bounds_p() before invoking malloc(). - The example thus becomes: - size_t size = xsum (header_size, xtimes (n, element_size)); - void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); -*/ - -/* Convert an arbitrary value >= 0 to type size_t. */ -#define xcast_size_t(N) \ - ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) - -/* Sum of two sizes, with overflow check. */ -static inline size_t -#if __GNUC__ >= 3 -__attribute__ ((__pure__)) -#endif -xsum (size_t size1, size_t size2) -{ - size_t sum = size1 + size2; - return (sum >= size1 ? sum : SIZE_MAX); -} - -/* Sum of three sizes, with overflow check. */ -static inline size_t -#if __GNUC__ >= 3 -__attribute__ ((__pure__)) -#endif -xsum3 (size_t size1, size_t size2, size_t size3) -{ - return xsum (xsum (size1, size2), size3); -} - -/* Sum of four sizes, with overflow check. */ -static inline size_t -#if __GNUC__ >= 3 -__attribute__ ((__pure__)) -#endif -xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) -{ - return xsum (xsum (xsum (size1, size2), size3), size4); -} - -/* Maximum of two sizes, with overflow check. */ -static inline size_t -#if __GNUC__ >= 3 -__attribute__ ((__pure__)) -#endif -xmax (size_t size1, size_t size2) -{ - /* No explicit check is needed here, because for any n: - max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ - return (size1 >= size2 ? size1 : size2); -} - -/* Multiplication of a count with an element size, with overflow check. - The count must be >= 0 and the element size must be > 0. - This is a macro, not an inline function, so that it works correctly even - when N is of a wider tupe and N > SIZE_MAX. */ -#define xtimes(N, ELSIZE) \ - ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) - -/* Check for overflow. */ -#define size_overflow_p(SIZE) \ - ((SIZE) == SIZE_MAX) -/* Check against overflow. */ -#define size_in_bounds_p(SIZE) \ - ((SIZE) != SIZE_MAX) - -#endif /* _XSIZE_H */ diff --git a/lib/xstrndup.c b/lib/xstrndup.c deleted file mode 100644 index 7ccefd7..0000000 --- a/lib/xstrndup.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Duplicate a bounded initial segment of a string, with out-of-memory - checking. - Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Specification. */ -#include "xstrndup.h" - -#include -#include "xalloc.h" - -/* Return a newly allocated copy of at most N bytes of STRING. - In other words, return a copy of the initial segment of length N of - STRING. */ -char * -xstrndup (const char *string, size_t n) -{ - char *s = strndup (string, n); - if (! s) - xalloc_die (); - return s; -} diff --git a/lib/xstrndup.h b/lib/xstrndup.h deleted file mode 100644 index 88354cf..0000000 --- a/lib/xstrndup.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Duplicate a bounded initial segment of a string, with out-of-memory - checking. - Copyright (C) 2003 Free Software Foundation, Inc. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include - -/* Return a newly allocated copy of at most N bytes of STRING. - In other words, return a copy of the initial segment of length N of - STRING. */ -extern char *xstrndup (const char *string, size_t n); diff --git a/m4/alloca.m4 b/m4/alloca.m4 deleted file mode 100644 index eb62e0e..0000000 --- a/m4/alloca.m4 +++ /dev/null @@ -1,50 +0,0 @@ -# alloca.m4 serial 7 -dnl Copyright (C) 2002-2004, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_ALLOCA], -[ - dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57. - AC_REQUIRE([AC_PROG_CPP]) - AC_REQUIRE([AC_PROG_EGREP]) - - AC_REQUIRE([AC_FUNC_ALLOCA]) - if test $ac_cv_func_alloca_works = no; then - gl_PREREQ_ALLOCA - fi - - # Define an additional variable used in the Makefile substitution. - if test $ac_cv_working_alloca_h = yes; then - AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ - AC_EGREP_CPP([Need own alloca], [ -#if defined __GNUC__ || defined _AIX || defined _MSC_VER - Need own alloca -#endif - ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) - ]) - if test $gl_cv_rpl_alloca = yes; then - dnl OK, alloca can be implemented through a compiler built-in. - AC_DEFINE([HAVE_ALLOCA], 1, - [Define to 1 if you have 'alloca' after including , - a header that may be supplied by this distribution.]) - ALLOCA_H=alloca.h - else - dnl alloca exists as a library function, i.e. it is slow and probably - dnl a memory leak. Don't define HAVE_ALLOCA in this case. - ALLOCA_H= - fi - else - ALLOCA_H=alloca.h - fi - AC_SUBST([ALLOCA_H]) - - AC_DEFINE(HAVE_ALLOCA_H, 1, - [Define HAVE_ALLOCA_H for backward compatibility with older code - that includes only if HAVE_ALLOCA_H is defined.]) -]) - -# Prerequisites of lib/alloca.c. -# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. -AC_DEFUN([gl_PREREQ_ALLOCA], [:]) diff --git a/m4/argp.m4 b/m4/argp.m4 deleted file mode 100644 index 77f1510..0000000 --- a/m4/argp.m4 +++ /dev/null @@ -1,65 +0,0 @@ -# argp.m4 serial 8 -dnl Copyright (C) 2003-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_ARGP], -[ - AC_REQUIRE([AC_C_INLINE]) - AC_REQUIRE([AC_C_RESTRICT]) - AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - dnl argp-parse.c depends on GNU getopt internals, therefore use GNU getopt - dnl always. - gl_GETOPT_SUBSTITUTE - dnl Note: gl_GETOPT_SUBSTITUTE does AC_LIBOBJ(getopt), AC_LIBOBJ(getopt1). - - AC_CHECK_DECL([program_invocation_name], - [AC_DEFINE(HAVE_DECL_PROGRAM_INVOCATION_NAME, 1, - [Define if program_invocation_name is declared])], - [AC_DEFINE(GNULIB_PROGRAM_INVOCATION_NAME, 1, - [Define to 1 to add extern declaration of program_invocation_name to argp.h])], - [#include ]) - AC_CHECK_DECL([program_invocation_short_name], - [AC_DEFINE(HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME, 1, - [Define if program_invocation_short_name is declared])], - [AC_DEFINE(GNULIB_PROGRAM_INVOCATION_SHORT_NAME, 1, - [Define to 1 to add extern declaration of program_invocation_short_name to argp.h])], - [#include ]) - - # Check if program_invocation_name and program_invocation_short_name - # are defined elsewhere. It is improbable that only one of them will - # be defined and other not, I prefer to stay on the safe side and to - # test each one separately. - AC_MSG_CHECKING(whether program_invocation_name is defined) - AC_TRY_COMPILE([#include ], - [ program_invocation_name = "test"; ], - [ AC_DEFINE(HAVE_PROGRAM_INVOCATION_NAME,1, - [Define if program_invocation_name is defined]) - AC_MSG_RESULT(yes)], - [ AC_MSG_RESULT(no)] ) - - AC_MSG_CHECKING(whether program_invocation_short_name is defined) - AC_TRY_COMPILE([#include ], - [ program_invocation_short_name = "test"; ], - [ AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME,1, - [Define if program_invocation_short_name is defined]) - AC_MSG_RESULT(yes)], - [ AC_MSG_RESULT(no)] ) - - AC_CHECK_DECLS_ONCE([clearerr_unlocked]) - AC_CHECK_DECLS_ONCE([feof_unlocked]) - AC_CHECK_DECLS_ONCE([ferror_unlocked]) - AC_CHECK_DECLS_ONCE([fflush_unlocked]) - AC_CHECK_DECLS_ONCE([fgets_unlocked]) - AC_CHECK_DECLS_ONCE([fputc_unlocked]) - AC_CHECK_DECLS_ONCE([fputs_unlocked]) - AC_CHECK_DECLS_ONCE([fread_unlocked]) - AC_CHECK_DECLS_ONCE([fwrite_unlocked]) - AC_CHECK_DECLS_ONCE([getc_unlocked]) - AC_CHECK_DECLS_ONCE([getchar_unlocked]) - AC_CHECK_DECLS_ONCE([putc_unlocked]) - AC_CHECK_DECLS_ONCE([putchar_unlocked]) - AC_CHECK_FUNCS_ONCE([flockfile funlockfile]) - AC_CHECK_HEADERS_ONCE([features.h linewrap.h]) -]) diff --git a/m4/dirname.m4 b/m4/dirname.m4 deleted file mode 100644 index e35da96..0000000 --- a/m4/dirname.m4 +++ /dev/null @@ -1,18 +0,0 @@ -#serial 7 -*- autoconf -*- -dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_DIRNAME], -[ - AC_LIBOBJ([basename]) - AC_LIBOBJ([dirname]) - AC_LIBOBJ([stripslash]) - - dnl Prerequisites of lib/dirname.h. - AC_REQUIRE([gl_AC_DOS]) - AC_REQUIRE([gl_DOUBLE_SLASH_ROOT]) - - dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c. -]) diff --git a/m4/dos.m4 b/m4/dos.m4 deleted file mode 100644 index dd59571..0000000 --- a/m4/dos.m4 +++ /dev/null @@ -1,71 +0,0 @@ -#serial 10 -*- autoconf -*- - -# Define some macros required for proper operation of code in lib/*.c -# on MSDOS/Windows systems. - -# Copyright (C) 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# From Jim Meyering. - -AC_DEFUN([gl_AC_DOS], - [ - AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], - [ - AC_TRY_COMPILE([], - [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ -neither MSDOS nor Windows -#endif], - [ac_cv_win_or_dos=yes], - [ac_cv_win_or_dos=no]) - ]) - - if test x"$ac_cv_win_or_dos" = xyes; then - ac_fs_accepts_drive_letter_prefix=1 - ac_fs_backslash_is_file_name_separator=1 - AC_CACHE_CHECK([whether drive letter can start relative path], - [ac_cv_drive_letter_can_be_relative], - [ - AC_TRY_COMPILE([], - [#if defined __CYGWIN__ -drive letters are always absolute -#endif], - [ac_cv_drive_letter_can_be_relative=yes], - [ac_cv_drive_letter_can_be_relative=no]) - ]) - if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then - ac_fs_drive_letter_can_be_relative=1 - else - ac_fs_drive_letter_can_be_relative=0 - fi - else - ac_fs_accepts_drive_letter_prefix=0 - ac_fs_backslash_is_file_name_separator=0 - ac_fs_drive_letter_can_be_relative=0 - fi - - AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX], - $ac_fs_accepts_drive_letter_prefix, - [Define on systems for which file names may have a so-called - `drive letter' prefix, define this to compute the length of that - prefix, including the colon.]) - - AH_VERBATIM(ISSLASH, - [#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR -# define ISSLASH(C) ((C) == '/' || (C) == '\\') -#else -# define ISSLASH(C) ((C) == '/') -#endif]) - - AC_DEFINE_UNQUOTED([FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR], - $ac_fs_backslash_is_file_name_separator, - [Define if the backslash character may also serve as a file name - component separator.]) - - AC_DEFINE_UNQUOTED([FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE], - $ac_fs_drive_letter_can_be_relative, - [Define if a drive letter prefix denotes a relative path if it is - not followed by a file name component separator.]) - ]) diff --git a/m4/double-slash-root.m4 b/m4/double-slash-root.m4 deleted file mode 100644 index 69d60d0..0000000 --- a/m4/double-slash-root.m4 +++ /dev/null @@ -1,38 +0,0 @@ -# double-slash-root.m4 serial 2 -*- Autoconf -*- -dnl Copyright (C) 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_DOUBLE_SLASH_ROOT], -[ - AC_REQUIRE([AC_CANONICAL_HOST]) - AC_CACHE_CHECK([whether // is distinct from /], [gl_cv_double_slash_root], - [ if test x"$cross_compiling" = xyes ; then - # When cross-compiling, there is no way to tell whether // is special - # short of a list of hosts. However, the only known hosts to date - # that have a distinct // are Apollo DomainOS (too old to port to), - # Cygwin, and z/OS. If anyone knows of another system for which // has - # special semantics and is distinct from /, please report it to - # . - case $host in - *-cygwin | i370-ibm-openedition) - gl_cv_double_slash_root=yes ;; - *) - # Be optimistic and assume that / and // are the same when we - # don't know. - gl_cv_double_slash_root='unknown, assuming no' ;; - esac - else - set x `ls -di / //` - if test $[2] = $[4] && wc //dev/null >/dev/null 2>&1; then - gl_cv_double_slash_root=no - else - gl_cv_double_slash_root=yes - fi - fi]) - if test "$gl_cv_double_slash_root" = yes; then - AC_DEFINE([DOUBLE_SLASH_IS_DISTINCT_ROOT], 1, - [Define to 1 if // is a file system root distinct from /.]) - fi -]) diff --git a/m4/eoverflow.m4 b/m4/eoverflow.m4 deleted file mode 100644 index 3bffd10..0000000 --- a/m4/eoverflow.m4 +++ /dev/null @@ -1,70 +0,0 @@ -# eoverflow.m4 serial 2 -dnl Copyright (C) 2004, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. - -# The EOVERFLOW errno value ought to be defined in , according to -# POSIX. But some systems (like AIX 3) don't define it, and some systems -# (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined. - -# Define EOVERFLOW as a C macro and as a substituted macro in such a way that -# 1. on all systems, after inclusion of , EOVERFLOW is usable, -# 2. on systems where EOVERFLOW is defined elsewhere, we use the same numeric -# value. - -AC_DEFUN([gl_EOVERFLOW], -[ - AC_REQUIRE([AC_PROG_CC])dnl - - AC_CACHE_CHECK([for EOVERFLOW], ac_cv_decl_EOVERFLOW, [ - AC_EGREP_CPP(yes,[ -#include -#ifdef EOVERFLOW -yes -#endif - ], have_eoverflow=1) - if test -n "$have_eoverflow"; then - dnl EOVERFLOW exists in . Don't need to define EOVERFLOW ourselves. - ac_cv_decl_EOVERFLOW=yes - else - AC_EGREP_CPP(yes,[ -#define _XOPEN_SOURCE_EXTENDED 1 -#include -#ifdef EOVERFLOW -yes -#endif - ], have_eoverflow=1) - if test -n "$have_eoverflow"; then - dnl EOVERFLOW exists but is hidden. - dnl Define it to the same value. - AC_COMPUTE_INT([ac_cv_decl_EOVERFLOW], [EOVERFLOW], [ -#define _XOPEN_SOURCE_EXTENDED 1 -#include -/* The following two lines are a workaround against an autoconf-2.52 bug. */ -#include -#include -]) - else - dnl EOVERFLOW isn't defined by the system. Define EOVERFLOW ourselves, but - dnl don't define it as EINVAL, because snprintf() callers want to - dnl distinguish EINVAL and EOVERFLOW. - ac_cv_decl_EOVERFLOW=E2BIG - fi - fi - ]) - if test "$ac_cv_decl_EOVERFLOW" != yes; then - AC_DEFINE_UNQUOTED([EOVERFLOW], [$ac_cv_decl_EOVERFLOW], - [Define as good substitute value for EOVERFLOW.]) - EOVERFLOW="$ac_cv_decl_EOVERFLOW" - AC_SUBST(EOVERFLOW) - fi -]) - -dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. -dnl Remove this when we can assume autoconf >= 2.61. -m4_ifdef([AC_COMPUTE_INT], [], [ - AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) -]) diff --git a/m4/error.m4 b/m4/error.m4 deleted file mode 100644 index 7c7746e..0000000 --- a/m4/error.m4 +++ /dev/null @@ -1,22 +0,0 @@ -#serial 11 - -# Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004 Free Software -# Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_ERROR], -[ - AC_FUNC_ERROR_AT_LINE - dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]). - gl_PREREQ_ERROR -]) - -# Prerequisites of lib/error.c. -AC_DEFUN([gl_PREREQ_ERROR], -[ - AC_REQUIRE([AC_FUNC_STRERROR_R]) - : -]) diff --git a/m4/exitfail.m4 b/m4/exitfail.m4 deleted file mode 100644 index b7a691e..0000000 --- a/m4/exitfail.m4 +++ /dev/null @@ -1,13 +0,0 @@ -# exitfail.m4 serial 6 -dnl Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_EXITFAIL], -[ - AC_LIBOBJ([exitfail]) - - dnl No prerequisites of lib/exitfail.c. - : -]) diff --git a/m4/extensions.m4 b/m4/extensions.m4 deleted file mode 100644 index bcbb3ce..0000000 --- a/m4/extensions.m4 +++ /dev/null @@ -1,82 +0,0 @@ -# serial 5 -*- Autoconf -*- -# Enable extensions on systems that normally disable them. - -# Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS -# Autoconf. Perhaps we can remove this once we can assume Autoconf -# 2.62 or later everywhere, but since CVS Autoconf mutates rapidly -# enough in this area it's likely we'll need to redefine -# AC_USE_SYSTEM_EXTENSIONS for quite some time. - -# AC_USE_SYSTEM_EXTENSIONS -# ------------------------ -# Enable extensions on systems that normally disable them, -# typically due to standards-conformance issues. -# Remember that #undef in AH_VERBATIM gets replaced with #define by -# AC_DEFINE. The goal here is to define all known feature-enabling -# macros, then, if reports of conflicts are made, disable macros that -# cause problems on some platforms (such as __EXTENSIONS__). -AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], -[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl -AC_BEFORE([$0], [AC_RUN_IFELSE])dnl - - AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) - if test "$MINIX" = yes; then - AC_DEFINE([_POSIX_SOURCE], [1], - [Define to 1 if you need to in order for `stat' and other - things to work.]) - AC_DEFINE([_POSIX_1_SOURCE], [2], - [Define to 2 if the system does not provide POSIX.1 features - except with this defined.]) - AC_DEFINE([_MINIX], [1], - [Define to 1 if on MINIX.]) - fi - - AH_VERBATIM([__EXTENSIONS__], -[/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# undef _ALL_SOURCE -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# undef _POSIX_PTHREAD_SEMANTICS -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# undef _TANDEM_SOURCE -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif -]) - AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], - [ac_cv_safe_to_define___extensions__], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([ -# define __EXTENSIONS__ 1 - AC_INCLUDES_DEFAULT])], - [ac_cv_safe_to_define___extensions__=yes], - [ac_cv_safe_to_define___extensions__=no])]) - test $ac_cv_safe_to_define___extensions__ = yes && - AC_DEFINE([__EXTENSIONS__]) - AC_DEFINE([_ALL_SOURCE]) - AC_DEFINE([_GNU_SOURCE]) - AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) - AC_DEFINE([_TANDEM_SOURCE]) -])# AC_USE_SYSTEM_EXTENSIONS - -# gl_USE_SYSTEM_EXTENSIONS -# ------------------------ -# Enable extensions on systems that normally disable them, -# typically due to standards-conformance issues. -AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], - [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])]) diff --git a/m4/float_h.m4 b/m4/float_h.m4 deleted file mode 100644 index 1b1ad10..0000000 --- a/m4/float_h.m4 +++ /dev/null @@ -1,19 +0,0 @@ -# float_h.m4 serial 2 -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FLOAT_H], -[ - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_HOST]) - FLOAT_H= - case "$host_os" in - beos*) - FLOAT_H=float.h - gl_CHECK_NEXT_HEADERS([float.h]) - ;; - esac - AC_SUBST([FLOAT_H]) -]) diff --git a/m4/getopt.m4 b/m4/getopt.m4 deleted file mode 100644 index c0a73b2..0000000 --- a/m4/getopt.m4 +++ /dev/null @@ -1,83 +0,0 @@ -# getopt.m4 serial 13 -dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# The getopt module assume you want GNU getopt, with getopt_long etc, -# rather than vanilla POSIX getopt. This means your code should -# always include for the getopt prototypes. - -AC_DEFUN([gl_GETOPT_SUBSTITUTE], -[ - AC_LIBOBJ([getopt]) - AC_LIBOBJ([getopt1]) - gl_GETOPT_SUBSTITUTE_HEADER - gl_PREREQ_GETOPT -]) - -AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], -[ - GETOPT_H=getopt.h - AC_DEFINE([__GETOPT_PREFIX], [[rpl_]], - [Define to rpl_ if the getopt replacement functions and variables - should be used.]) - AC_SUBST([GETOPT_H]) -]) - -AC_DEFUN([gl_GETOPT_CHECK_HEADERS], -[ - if test -z "$GETOPT_H"; then - AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h]) - fi - - if test -z "$GETOPT_H"; then - AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h]) - fi - - dnl BSD getopt_long uses an incompatible method to reset option processing, - dnl and (as of 2004-10-15) mishandles optional option-arguments. - if test -z "$GETOPT_H"; then - AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include ]) - fi - - dnl Solaris 10 getopt doesn't handle `+' as a leading character in an - dnl option string (as of 2005-05-05). - if test -z "$GETOPT_H"; then - AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt], - [AC_RUN_IFELSE( - [AC_LANG_PROGRAM([#include ], - [[ - char *myargv[3]; - myargv[0] = "conftest"; - myargv[1] = "-+"; - myargv[2] = 0; - return getopt (2, myargv, "+a") != '?'; - ]])], - [gl_cv_func_gnu_getopt=yes], - [gl_cv_func_gnu_getopt=no], - [dnl cross compiling - pessimistically guess based on decls - dnl Solaris 10 getopt doesn't handle `+' as a leading character in an - dnl option string (as of 2005-05-05). - AC_CHECK_DECL([getopt_clip], - [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes], - [#include ])])]) - if test "$gl_cv_func_gnu_getopt" = "no"; then - GETOPT_H=getopt.h - fi - fi -]) - -AC_DEFUN([gl_GETOPT_IFELSE], -[ - AC_REQUIRE([gl_GETOPT_CHECK_HEADERS]) - AS_IF([test -n "$GETOPT_H"], [$1], [$2]) -]) - -AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])]) - -# Prerequisites of lib/getopt*. -AC_DEFUN([gl_PREREQ_GETOPT], -[ - AC_CHECK_DECLS_ONCE([getenv]) -]) diff --git a/m4/getsubopt.m4 b/m4/getsubopt.m4 deleted file mode 100644 index 2c52c75..0000000 --- a/m4/getsubopt.m4 +++ /dev/null @@ -1,22 +0,0 @@ -# getsubopt.m4 serial 4 -dnl Copyright (C) 2004, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_GETSUBOPT], -[ - dnl Persuade glibc to declare getsubopt(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) - AC_CHECK_FUNCS_ONCE([getsubopt]) - if test $ac_cv_func_getsubopt = no; then - HAVE_GETSUBOPT=0 - AC_LIBOBJ([getsubopt]) - gl_PREREQ_GETSUBOPT - fi -]) - -# Prerequisites of lib/getsubopt.c. -AC_DEFUN([gl_PREREQ_GETSUBOPT], [:]) diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 deleted file mode 100644 index 14673c1..0000000 --- a/m4/gnulib-cache.m4 +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2004-2007 Free Software Foundation, Inc. -# -# This file is free software, distributed under the terms of the GNU -# General Public License. As a special exception to the GNU General -# Public License, this file may be distributed as part of a program -# that contains a configuration script generated by Autoconf, under -# the same distribution terms as the rest of that program. -# -# Generated by gnulib-tool. -# -# This file represents the specification of how gnulib-tool is used. -# It acts as a cache: It is written and read by gnulib-tool. -# In projects using CVS, this file is meant to be stored in CVS, -# like the configure.ac and various Makefile.am files. - - -# Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --aux-dir=. --libtool --macro-prefix=gl argp getsubopt progname - -# Specification in the form of a few gnulib-tool.m4 macro invocations: -gl_LOCAL_DIR([]) -gl_MODULES([argp getsubopt progname]) -gl_AVOID([]) -gl_SOURCE_BASE([lib]) -gl_M4_BASE([m4]) -gl_PO_BASE([]) -gl_DOC_BASE([doc]) -gl_TESTS_BASE([tests]) -gl_LIB([libgnu]) -gl_MAKEFILE_NAME([]) -gl_LIBTOOL -gl_MACRO_PREFIX([gl]) -gl_PO_DOMAIN([]) diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 deleted file mode 100644 index 5398010..0000000 --- a/m4/gnulib-common.m4 +++ /dev/null @@ -1,22 +0,0 @@ -# gnulib-common.m4 serial 2 -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# gl_MODULE_INDICATOR([modulename]) -# defines a C macro indicating the presence of the given module. -AC_DEFUN([gl_MODULE_INDICATOR], -[ - AC_DEFINE([GNULIB_]translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___]), [1], - [Define to 1 when using the gnulib module ]$1[.]) -]) - -# AC_PROG_MKDIR_P -# is a backport of autoconf-2.60's AC_PROG_MKDIR_P. -# Remove this macro when we can assume autoconf >= 2.60. -m4_ifdef([AC_PROG_MKDIR_P], [], [ - AC_DEFUN([AC_PROG_MKDIR_P], - [AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake - MKDIR_P='$(mkdir_p)' - AC_SUBST([MKDIR_P])])]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 deleted file mode 100644 index 364ecd1..0000000 --- a/m4/gnulib-comp.m4 +++ /dev/null @@ -1,251 +0,0 @@ -# DO NOT EDIT! GENERATED AUTOMATICALLY! -# Copyright (C) 2004-2007 Free Software Foundation, Inc. -# -# This file is free software, distributed under the terms of the GNU -# General Public License. As a special exception to the GNU General -# Public License, this file may be distributed as part of a program -# that contains a configuration script generated by Autoconf, under -# the same distribution terms as the rest of that program. -# -# Generated by gnulib-tool. -# -# This file represents the compiled summary of the specification in -# gnulib-cache.m4. It lists the computed macro invocations that need -# to be invoked from configure.ac. -# In projects using CVS, this file can be treated like other built files. - - -# This macro should be invoked from ./configure.in, in the section -# "Checks for programs", right after AC_PROG_CC, and certainly before -# any checks for libraries, header files, types and library functions. -AC_DEFUN([gl_EARLY], -[ - m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace - m4_pattern_allow([^gl_ES$])dnl a valid locale name - m4_pattern_allow([^gl_LIBOBJS$])dnl a variable - m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable - AC_REQUIRE([AC_PROG_RANLIB]) - AC_REQUIRE([AC_GNU_SOURCE]) - AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) -]) - -# This macro should be invoked from ./configure.in, in the section -# "Check for header files, types and library functions". -AC_DEFUN([gl_INIT], -[ - m4_pushdef([AC_LIBOBJ], m4_defn([gl_LIBOBJ])) - m4_pushdef([AC_REPLACE_FUNCS], m4_defn([gl_REPLACE_FUNCS])) - m4_pushdef([AC_LIBSOURCES], m4_defn([gl_LIBSOURCES])) - AM_CONDITIONAL([GL_COND_LIBTOOL], [true]) - gl_cond_libtool=true - gl_source_base='lib' -changequote(,)dnl -LTALLOCA=`echo "$ALLOCA" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'` -changequote([, ])dnl -AC_SUBST([LTALLOCA]) - gl_FUNC_ALLOCA - gl_ARGP - gl_DIRNAME - gl_DOUBLE_SLASH_ROOT - gl_ERROR - gl_EXITFAIL - gl_FLOAT_H - gl_GETOPT - gl_FUNC_GETSUBOPT - gl_STDLIB_MODULE_INDICATOR([getsubopt]) - AC_SUBST([LIBINTL]) - AC_SUBST([LTLIBINTL]) - gl_INLINE - AC_FUNC_MALLOC - gl_FUNC_MALLOC_POSIX - gl_STDLIB_MODULE_INDICATOR([malloc-posix]) - gl_FUNC_MEMPCPY - gl_STRING_MODULE_INDICATOR([mempcpy]) - gl_SIZE_MAX - gl_FUNC_SLEEP - gl_UNISTD_MODULE_INDICATOR([sleep]) - AM_STDBOOL_H - gl_STDINT_H - gl_STDIO_H - gl_STDLIB_H - gl_STRCASE - gl_FUNC_STRCHRNUL - gl_STRING_MODULE_INDICATOR([strchrnul]) - gl_FUNC_STRERROR - gl_STRING_MODULE_INDICATOR([strerror]) - gl_HEADER_STRING_H - gl_FUNC_STRNDUP - gl_STRING_MODULE_INDICATOR([strndup]) - gl_FUNC_STRNLEN - gl_STRING_MODULE_INDICATOR([strnlen]) - gl_SYSEXITS - gl_UNISTD_H - gl_FUNC_VASNPRINTF - gl_FUNC_VSNPRINTF - gl_STDIO_MODULE_INDICATOR([vsnprintf]) - gl_WCHAR_H - gl_XALLOC - gl_XSIZE - gl_XSTRNDUP - m4_popdef([AC_LIBSOURCES]) - m4_popdef([AC_REPLACE_FUNCS]) - m4_popdef([AC_LIBOBJ]) - AC_CONFIG_COMMANDS_PRE([ - gl_libobjs= - gl_ltlibobjs= - if test -n "$gl_LIBOBJS"; then - # Remove the extension. - sed_drop_objext='s/\.o$//;s/\.obj$//' - for i in `for i in $gl_LIBOBJS; do echo "$i"; done | sed "$sed_drop_objext" | sort | uniq`; do - gl_libobjs="$gl_libobjs $i.$ac_objext" - gl_ltlibobjs="$gl_ltlibobjs $i.lo" - done - fi - AC_SUBST([gl_LIBOBJS], [$gl_libobjs]) - AC_SUBST([gl_LTLIBOBJS], [$gl_ltlibobjs]) - ]) -]) - -# Like AC_LIBOBJ, except that the module name goes -# into gl_LIBOBJS instead of into LIBOBJS. -AC_DEFUN([gl_LIBOBJ], [ - AS_LITERAL_IF([$1], [gl_LIBSOURCES([$1.c])])dnl - gl_LIBOBJS="$gl_LIBOBJS $1.$ac_objext" -]) - -# Like AC_REPLACE_FUNCS, except that the module name goes -# into gl_LIBOBJS instead of into LIBOBJS. -AC_DEFUN([gl_REPLACE_FUNCS], [ - m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl - AC_CHECK_FUNCS([$1], , [gl_LIBOBJ($ac_func)]) -]) - -# Like AC_LIBSOURCES, except the directory where the source file is -# expected is derived from the gnulib-tool parametrization, -# and alloca is special cased (for the alloca-opt module). -# We could also entirely rely on EXTRA_lib..._SOURCES. -AC_DEFUN([gl_LIBSOURCES], [ - m4_foreach([_gl_NAME], [$1], [ - m4_if(_gl_NAME, [alloca.c], [], [ - m4_syscmd([test -r lib/]_gl_NAME[ || test ! -d lib])dnl - m4_if(m4_sysval, [0], [], - [AC_FATAL([missing lib/]_gl_NAME)]) - ]) - ]) -]) - -# This macro records the list of files which have been installed by -# gnulib-tool and may be removed by future gnulib-tool invocations. -AC_DEFUN([gl_FILE_LIST], [ - lib/alloca.c - lib/alloca.in.h - lib/argp-ba.c - lib/argp-eexst.c - lib/argp-fmtstream.c - lib/argp-fmtstream.h - lib/argp-fs-xinl.c - lib/argp-help.c - lib/argp-namefrob.h - lib/argp-parse.c - lib/argp-pin.c - lib/argp-pv.c - lib/argp-pvh.c - lib/argp-xinl.c - lib/argp.h - lib/asnprintf.c - lib/basename.c - lib/dirname.c - lib/dirname.h - lib/error.c - lib/error.h - lib/exitfail.c - lib/exitfail.h - lib/float+.h - lib/float.in.h - lib/getopt.c - lib/getopt.in.h - lib/getopt1.c - lib/getopt_int.h - lib/getsubopt.c - lib/gettext.h - lib/malloc.c - lib/mempcpy.c - lib/printf-args.c - lib/printf-args.h - lib/printf-parse.c - lib/printf-parse.h - lib/progname.c - lib/progname.h - lib/size_max.h - lib/sleep.c - lib/stdbool.in.h - lib/stdint.in.h - lib/stdio.in.h - lib/stdlib.in.h - lib/strcasecmp.c - lib/strchrnul.c - lib/strerror.c - lib/string.in.h - lib/stripslash.c - lib/strncasecmp.c - lib/strndup.c - lib/strnlen.c - lib/sysexits.in.h - lib/unistd.in.h - lib/vasnprintf.c - lib/vasnprintf.h - lib/vsnprintf.c - lib/wchar.in.h - lib/xalloc-die.c - lib/xalloc.h - lib/xmalloc.c - lib/xsize.h - lib/xstrndup.c - lib/xstrndup.h - m4/absolute-header.m4 - m4/alloca.m4 - m4/argp.m4 - m4/dirname.m4 - m4/dos.m4 - m4/double-slash-root.m4 - m4/eoverflow.m4 - m4/error.m4 - m4/exitfail.m4 - m4/extensions.m4 - m4/float_h.m4 - m4/getopt.m4 - m4/getsubopt.m4 - m4/gnulib-common.m4 - m4/include_next.m4 - m4/inline.m4 - m4/intmax_t.m4 - m4/inttypes_h.m4 - m4/longlong.m4 - m4/malloc.m4 - m4/mempcpy.m4 - m4/onceonly_2_57.m4 - m4/size_max.m4 - m4/sleep.m4 - m4/stdbool.m4 - m4/stdint.m4 - m4/stdint_h.m4 - m4/stdio_h.m4 - m4/stdlib_h.m4 - m4/strcase.m4 - m4/strchrnul.m4 - m4/strerror.m4 - m4/string_h.m4 - m4/strndup.m4 - m4/strnlen.m4 - m4/sysexits.m4 - m4/ulonglong.m4 - m4/unistd_h.m4 - m4/vasnprintf.m4 - m4/vsnprintf.m4 - m4/wchar.m4 - m4/wchar_t.m4 - m4/wint_t.m4 - m4/xalloc.m4 - m4/xsize.m4 - m4/xstrndup.m4 -]) diff --git a/m4/gnulib-tool.m4 b/m4/gnulib-tool.m4 deleted file mode 100644 index ef59320..0000000 --- a/m4/gnulib-tool.m4 +++ /dev/null @@ -1,33 +0,0 @@ -# gnulib-tool.m4 serial 1 -dnl Copyright (C) 2004-2005 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl The following macros need not be invoked explicitly. -dnl Invoking them does nothing except to declare default arguments -dnl for "gnulib-tool --import". - -dnl Usage: gl_MODULES([module1 module2 ...]) -AC_DEFUN([gl_MODULES], []) - -dnl Usage: gl_AVOID([module1 module2 ...]) -AC_DEFUN([gl_AVOID], []) - -dnl Usage: gl_SOURCE_BASE([DIR]) -AC_DEFUN([gl_SOURCE_BASE], []) - -dnl Usage: gl_M4_BASE([DIR]) -AC_DEFUN([gl_M4_BASE], []) - -dnl Usage: gl_LIB([LIBNAME]) -AC_DEFUN([gl_LIB], []) - -dnl Usage: gl_LGPL -AC_DEFUN([gl_LGPL], []) - -dnl Usage: gl_LIBTOOL -AC_DEFUN([gl_LIBTOOL], []) - -dnl Usage: gl_MACRO_PREFIX([PREFIX]) -AC_DEFUN([gl_MACRO_PREFIX], []) diff --git a/m4/include_next.m4 b/m4/include_next.m4 deleted file mode 100644 index 7ce472b..0000000 --- a/m4/include_next.m4 +++ /dev/null @@ -1,107 +0,0 @@ -# include_next.m4 serial 4 -dnl Copyright (C) 2006, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert and Derek Price. - -AC_DEFUN([gl_INCLUDE_NEXT], -[ - AC_LANG_PREPROC_REQUIRE() - AC_CACHE_CHECK([whether the preprocessor supports include_next], - [gl_cv_have_include_next], - [rm -rf conftestd1 conftestd2 - mkdir conftestd1 conftestd2 - cat < conftestd1/conftest.h -#define DEFINED_IN_CONFTESTD1 -#include_next -#ifdef DEFINED_IN_CONFTESTD2 -int foo; -#else -#error "include_next doesn't work" -#endif -EOF - cat < conftestd2/conftest.h -#ifndef DEFINED_IN_CONFTESTD1 -#error "include_next test doesn't work" -#endif -#define DEFINED_IN_CONFTESTD2 -EOF - save_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2" - AC_COMPILE_IFELSE([#include ], - [gl_cv_have_include_next=yes], - [gl_cv_have_include_next=no]) - CPPFLAGS="$save_CPPFLAGS" - rm -rf conftestd1 conftestd2 - ]) - if test $gl_cv_have_include_next = yes; then - - dnl FIXME: Remove HAVE_INCLUDE_NEXT and update everything that uses it - dnl to use @INCLUDE_NEXT@ instead. - AC_DEFINE([HAVE_INCLUDE_NEXT], 1, - [Define if your compiler supports the #include_next directive.]) - - INCLUDE_NEXT=include_next - else - INCLUDE_NEXT=include - fi - AC_SUBST([INCLUDE_NEXT]) -]) - -# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...) -# ------------------------------------------ -# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be -# ''; otherwise define it to be -# '"///usr/include/foo.h"', or whatever other absolute file name is suitable. -# That way, a header file with the following line: -# #@INCLUDE_NEXT@ @NEXT_FOO_H@ -# behaves (after sed substitution) as if it contained -# #include_next -# even if the compiler does not support include_next. -# The three "///" are to pacify Sun C 5.8, which otherwise would say -# "warning: #include of /usr/include/... may be non-portable". -# Use `""', not `<>', so that the /// cannot be confused with a C99 comment. -AC_DEFUN([gl_CHECK_NEXT_HEADERS], -[ - AC_REQUIRE([gl_INCLUDE_NEXT]) - AC_CHECK_HEADERS_ONCE([$1]) - - AC_FOREACH([gl_HEADER_NAME], [$1], - [AS_VAR_PUSHDEF([gl_next_header], - [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME]))) - if test $gl_cv_have_include_next = yes; then - AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) - else - AC_CACHE_CHECK( - [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], - m4_quote(m4_defn([gl_next_header])), - [AS_VAR_PUSHDEF([gl_header_exists], - [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME]))) - if test AS_VAR_GET(gl_header_exists) = yes; then - AC_LANG_CONFTEST( - [AC_LANG_SOURCE( - [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] - )]) - dnl eval is necessary to expand ac_cpp. - dnl Ultrix and Pyramid sh refuse to redirect output of eval, - dnl so use subshell. - AS_VAR_SET([gl_next_header], - ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | - sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{ - s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1# - s#^/[^/]#//&# - p - q - }'`'"']) - else - AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>']) - fi - AS_VAR_POPDEF([gl_header_exists])]) - fi - AC_SUBST( - AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))), - [AS_VAR_GET([gl_next_header])]) - AS_VAR_POPDEF([gl_next_header])]) -]) diff --git a/m4/inline.m4 b/m4/inline.m4 deleted file mode 100644 index a07076c..0000000 --- a/m4/inline.m4 +++ /dev/null @@ -1,40 +0,0 @@ -# inline.m4 serial 3 -dnl Copyright (C) 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Test for the 'inline' keyword or equivalent. -dnl Define 'inline' to a supported equivalent, or to nothing if not supported, -dnl like AC_C_INLINE does. Also, define HAVE_INLINE if 'inline' or an -dnl equivalent is effectively supported, i.e. if the compiler is likely to -dnl drop unused 'static inline' functions. -AC_DEFUN([gl_INLINE], -[ - AC_REQUIRE([AC_C_INLINE]) - AC_CACHE_CHECK([whether the compiler generally respects inline], - [gl_cv_c_inline_effective], - [if test $ac_cv_c_inline = no; then - gl_cv_c_inline_effective=no - else - dnl GCC defines __NO_INLINE__ if not optimizing or if -fno-inline is - dnl specified. - dnl Use AC_COMPILE_IFELSE here, not AC_EGREP_CPP, because the result - dnl depends on optimization flags, which can be in CFLAGS. - dnl (AC_EGREP_CPP looks only at the CPPFLAGS.) - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[]], - [[#ifdef __NO_INLINE__ - #error "inline is not effective" - #endif]])], - [gl_cv_c_inline_effective=yes], - [gl_cv_c_inline_effective=no]) - fi - ]) - if test $gl_cv_c_inline_effective = yes; then - AC_DEFINE([HAVE_INLINE], 1, - [Define to 1 if the compiler supports one of the keywords - 'inline', '__inline__', '__inline' and effectively inlines - functions marked as such.]) - fi -]) diff --git a/m4/intmax_t.m4 b/m4/intmax_t.m4 deleted file mode 100644 index 17c7b0a..0000000 --- a/m4/intmax_t.m4 +++ /dev/null @@ -1,61 +0,0 @@ -# intmax_t.m4 serial 5 -dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -AC_PREREQ(2.13) - -# Define intmax_t to 'long' or 'long long' -# if it is not already defined in or . - -AC_DEFUN([gl_AC_TYPE_INTMAX_T], -[ - dnl For simplicity, we assume that a header file defines 'intmax_t' if and - dnl only if it defines 'uintmax_t'. - AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) - AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - test $ac_cv_type_long_long = yes \ - && ac_type='long long' \ - || ac_type='long' - AC_DEFINE_UNQUOTED(intmax_t, $ac_type, - [Define to long or long long if and don't define.]) - else - AC_DEFINE(HAVE_INTMAX_T, 1, - [Define if you have the 'intmax_t' type in or .]) - fi -]) - -dnl An alternative would be to explicitly test for 'intmax_t'. - -AC_DEFUN([gt_AC_TYPE_INTMAX_T], -[ - AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) - AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, - [AC_TRY_COMPILE([ -#include -#include -#if HAVE_STDINT_H_WITH_UINTMAX -#include -#endif -#if HAVE_INTTYPES_H_WITH_UINTMAX -#include -#endif -], [intmax_t x = -1; return !x;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)]) - if test $gt_cv_c_intmax_t = yes; then - AC_DEFINE(HAVE_INTMAX_T, 1, - [Define if you have the 'intmax_t' type in or .]) - else - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - test $ac_cv_type_long_long = yes \ - && ac_type='long long' \ - || ac_type='long' - AC_DEFINE_UNQUOTED(intmax_t, $ac_type, - [Define to long or long long if and don't define.]) - fi -]) diff --git a/m4/inttypes_h.m4 b/m4/inttypes_h.m4 deleted file mode 100644 index edc8ecb..0000000 --- a/m4/inttypes_h.m4 +++ /dev/null @@ -1,26 +0,0 @@ -# inttypes_h.m4 serial 7 -dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_INTTYPES_H_WITH_UINTMAX if exists, -# doesn't clash with , and declares uintmax_t. - -AC_DEFUN([gl_AC_HEADER_INTTYPES_H], -[ - AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, - [AC_TRY_COMPILE( - [#include -#include ], - [uintmax_t i = (uintmax_t) -1; return !i;], - gl_cv_header_inttypes_h=yes, - gl_cv_header_inttypes_h=no)]) - if test $gl_cv_header_inttypes_h = yes; then - AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1, - [Define if exists, doesn't clash with , - and declares uintmax_t. ]) - fi -]) diff --git a/m4/longlong.m4 b/m4/longlong.m4 deleted file mode 100644 index 1f9e862..0000000 --- a/m4/longlong.m4 +++ /dev/null @@ -1,72 +0,0 @@ -# longlong.m4 serial 10 -dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_LONG_LONG_INT if 'long long int' works. -# This fixes a bug in Autoconf 2.60, but can be removed once we -# assume 2.61 everywhere. - -# Note: If the type 'long long int' exists but is only 32 bits large -# (as on some very old compilers), HAVE_LONG_LONG_INT will not be -# defined. In this case you can treat 'long long int' like 'long int'. - -AC_DEFUN([AC_TYPE_LONG_LONG_INT], -[ - AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[long long int ll = 9223372036854775807ll; - long long int nll = -9223372036854775807LL; - typedef int a[((-9223372036854775807LL < 0 - && 0 < 9223372036854775807ll) - ? 1 : -1)]; - int i = 63;]], - [[long long int llmax = 9223372036854775807ll; - return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) - | (llmax / ll) | (llmax % ll));]])], - [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004. - dnl If cross compiling, assume the bug isn't important, since - dnl nobody cross compiles for this platform as far as we know. - AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [[@%:@include - @%:@ifndef LLONG_MAX - @%:@ define HALF \ - (1LL << (sizeof (long long int) * CHAR_BIT - 2)) - @%:@ define LLONG_MAX (HALF - 1 + HALF) - @%:@endif]], - [[long long int n = 1; - int i; - for (i = 0; ; i++) - { - long long int m = n << i; - if (m >> i != n) - return 1; - if (LLONG_MAX / 2 < m) - break; - } - return 0;]])], - [ac_cv_type_long_long_int=yes], - [ac_cv_type_long_long_int=no], - [ac_cv_type_long_long_int=yes])], - [ac_cv_type_long_long_int=no])]) - if test $ac_cv_type_long_long_int = yes; then - AC_DEFINE([HAVE_LONG_LONG_INT], 1, - [Define to 1 if the system has the type `long long int'.]) - fi -]) - -# This macro is obsolescent and should go away soon. -AC_DEFUN([gl_AC_TYPE_LONG_LONG], -[ - AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) - ac_cv_type_long_long=$ac_cv_type_long_long_int - if test $ac_cv_type_long_long = yes; then - AC_DEFINE(HAVE_LONG_LONG, 1, - [Define if you have the 'long long' type.]) - fi -]) diff --git a/m4/malloc.m4 b/m4/malloc.m4 deleted file mode 100644 index 764f2a9..0000000 --- a/m4/malloc.m4 +++ /dev/null @@ -1,41 +0,0 @@ -# malloc.m4 serial 8 -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# gl_FUNC_MALLOC_POSIX -# -------------------- -# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it -# fails), and replace malloc if it is not. -AC_DEFUN([gl_FUNC_MALLOC_POSIX], -[ - AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) - if test $gl_cv_func_malloc_posix = yes; then - HAVE_MALLOC_POSIX=1 - AC_DEFINE([HAVE_MALLOC_POSIX], 1, - [Define if the 'malloc' function is POSIX compliant.]) - else - AC_LIBOBJ([malloc]) - HAVE_MALLOC_POSIX=0 - fi - AC_SUBST([HAVE_MALLOC_POSIX]) -]) - -# Test whether malloc, realloc, calloc are POSIX compliant, -# Set gl_cv_func_malloc_posix to yes or no accordingly. -AC_DEFUN([gl_CHECK_MALLOC_POSIX], -[ - AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant], - [gl_cv_func_malloc_posix], - [ - dnl It is too dangerous to try to allocate a large amount of memory: - dnl some systems go to their knees when you do that. So assume that - dnl all Unix implementations of the function are POSIX compliant. - AC_TRY_COMPILE([], - [#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - choke me - #endif - ], [gl_cv_func_malloc_posix=yes], [gl_cv_func_malloc_posix=no]) - ]) -]) diff --git a/m4/mempcpy.m4 b/m4/mempcpy.m4 deleted file mode 100644 index d1a12eb..0000000 --- a/m4/mempcpy.m4 +++ /dev/null @@ -1,26 +0,0 @@ -# mempcpy.m4 serial 9 -dnl Copyright (C) 2003, 2004, 2006, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_MEMPCPY], -[ - dnl Persuade glibc to declare mempcpy(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - dnl The mempcpy() declaration in lib/string.in.h uses 'restrict'. - AC_REQUIRE([AC_C_RESTRICT]) - - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_REPLACE_FUNCS(mempcpy) - if test $ac_cv_func_mempcpy = no; then - HAVE_MEMPCPY=0 - gl_PREREQ_MEMPCPY - fi -]) - -# Prerequisites of lib/mempcpy.c. -AC_DEFUN([gl_PREREQ_MEMPCPY], [ - : -]) diff --git a/m4/onceonly_2_57.m4 b/m4/onceonly_2_57.m4 deleted file mode 100644 index 15884b3..0000000 --- a/m4/onceonly_2_57.m4 +++ /dev/null @@ -1,86 +0,0 @@ -# onceonly_2_57.m4 serial 4 -dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc. -dnl This file is free software, distributed under the terms of the GNU -dnl General Public License. As a special exception to the GNU General -dnl Public License, this file may be distributed as part of a program -dnl that contains a configuration script generated by Autoconf, under -dnl the same distribution terms as the rest of that program. - -dnl This file defines some "once only" variants of standard autoconf macros. -dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS -dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS -dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS -dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL -dnl The advantage is that the check for each of the headers/functions/decls -dnl will be put only once into the 'configure' file. It keeps the size of -dnl the 'configure' file down, and avoids redundant output when 'configure' -dnl is run. -dnl The drawback is that the checks cannot be conditionalized. If you write -dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi -dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to -dnl empty, and the check will be inserted before the body of the AC_DEFUNed -dnl function. - -dnl This is like onceonly.m4, except that it uses diversions to named sections -dnl DEFAULTS and INIT_PREPARE in order to check all requested headers at once, -dnl thus reducing the size of 'configure'. Works with autoconf-2.57. The -dnl size reduction is ca. 9%. - -dnl Autoconf version 2.57 or newer is recommended. -AC_PREREQ(2.57) - -# AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of -# AC_CHECK_HEADERS(HEADER1 HEADER2 ...). -AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ - : - AC_FOREACH([gl_HEADER_NAME], [$1], [ - AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, - [./-], [___])), [ - m4_divert_text([INIT_PREPARE], - [gl_header_list="$gl_header_list gl_HEADER_NAME"]) - gl_HEADERS_EXPANSION - AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), - [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) - ]) - AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, - [./-], [___]))) - ]) -]) -m4_define([gl_HEADERS_EXPANSION], [ - m4_divert_text([DEFAULTS], [gl_header_list=]) - AC_CHECK_HEADERS([$gl_header_list]) - m4_define([gl_HEADERS_EXPANSION], []) -]) - -# AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of -# AC_CHECK_FUNCS(FUNC1 FUNC2 ...). -AC_DEFUN([AC_CHECK_FUNCS_ONCE], [ - : - AC_FOREACH([gl_FUNC_NAME], [$1], [ - AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [ - m4_divert_text([INIT_PREPARE], - [gl_func_list="$gl_func_list gl_FUNC_NAME"]) - gl_FUNCS_EXPANSION - AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])), - [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.]) - ]) - AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME])) - ]) -]) -m4_define([gl_FUNCS_EXPANSION], [ - m4_divert_text([DEFAULTS], [gl_func_list=]) - AC_CHECK_FUNCS([$gl_func_list]) - m4_define([gl_FUNCS_EXPANSION], []) -]) - -# AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of -# AC_CHECK_DECLS(DECL1, DECL2, ...). -AC_DEFUN([AC_CHECK_DECLS_ONCE], [ - : - AC_FOREACH([gl_DECL_NAME], [$1], [ - AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [ - AC_CHECK_DECLS(m4_defn([gl_DECL_NAME])) - ]) - AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME])) - ]) -]) diff --git a/m4/size_max.m4 b/m4/size_max.m4 deleted file mode 100644 index 6cb4868..0000000 --- a/m4/size_max.m4 +++ /dev/null @@ -1,68 +0,0 @@ -# size_max.m4 serial 6 -dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. - -AC_DEFUN([gl_SIZE_MAX], -[ - AC_CHECK_HEADERS(stdint.h) - dnl First test whether the system already has SIZE_MAX. - AC_MSG_CHECKING([for SIZE_MAX]) - AC_CACHE_VAL([gl_cv_size_max], [ - gl_cv_size_max= - AC_EGREP_CPP([Found it], [ -#include -#if HAVE_STDINT_H -#include -#endif -#ifdef SIZE_MAX -Found it -#endif -], gl_cv_size_max=yes) - if test -z "$gl_cv_size_max"; then - dnl Define it ourselves. Here we assume that the type 'size_t' is not wider - dnl than the type 'unsigned long'. Try hard to find a definition that can - dnl be used in a preprocessor #if, i.e. doesn't contain a cast. - AC_COMPUTE_INT([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1], - [#include -#include ], size_t_bits_minus_1=) - AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)], - [#include ], fits_in_uint=) - if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then - if test $fits_in_uint = 1; then - dnl Even though SIZE_MAX fits in an unsigned int, it must be of type - dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. - AC_TRY_COMPILE([#include - extern size_t foo; - extern unsigned long foo; - ], [], fits_in_uint=0) - fi - dnl We cannot use 'expr' to simplify this expression, because 'expr' - dnl works only with 'long' integers in the host environment, while we - dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. - if test $fits_in_uint = 1; then - gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" - else - gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" - fi - else - dnl Shouldn't happen, but who knows... - gl_cv_size_max='((size_t)~(size_t)0)' - fi - fi - ]) - AC_MSG_RESULT([$gl_cv_size_max]) - if test "$gl_cv_size_max" != yes; then - AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max], - [Define as the maximum value of type 'size_t', if the system doesn't define it.]) - fi -]) - -dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. -dnl Remove this when we can assume autoconf >= 2.61. -m4_ifdef([AC_COMPUTE_INT], [], [ - AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) -]) diff --git a/m4/sleep.m4 b/m4/sleep.m4 deleted file mode 100644 index 2c9d75c..0000000 --- a/m4/sleep.m4 +++ /dev/null @@ -1,19 +0,0 @@ -# sleep.m4 serial 1 -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_SLEEP], -[ - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - AC_CHECK_FUNCS_ONCE([sleep]) - if test $ac_cv_func_sleep = no; then - HAVE_SLEEP=0 - AC_LIBOBJ([sleep]) - gl_PREREQ_SLEEP - fi -]) - -# Prerequisites of lib/sleep.c. -AC_DEFUN([gl_PREREQ_SLEEP], [:]) diff --git a/m4/stdbool.m4 b/m4/stdbool.m4 deleted file mode 100644 index 2204ecd..0000000 --- a/m4/stdbool.m4 +++ /dev/null @@ -1,115 +0,0 @@ -# Check for stdbool.h that conforms to C99. - -dnl Copyright (C) 2002-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -# Prepare for substituting if it is not supported. - -AC_DEFUN([AM_STDBOOL_H], -[ - AC_REQUIRE([AC_HEADER_STDBOOL]) - - # Define two additional variables used in the Makefile substitution. - - if test "$ac_cv_header_stdbool_h" = yes; then - STDBOOL_H='' - else - STDBOOL_H='stdbool.h' - fi - AC_SUBST([STDBOOL_H]) - - if test "$ac_cv_type__Bool" = yes; then - HAVE__BOOL=1 - else - HAVE__BOOL=0 - fi - AC_SUBST([HAVE__BOOL]) -]) - -# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future. -AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H]) - -# This macro is only needed in autoconf <= 2.59. Newer versions of autoconf -# have this macro built-in. - -AC_DEFUN([AC_HEADER_STDBOOL], - [AC_CACHE_CHECK([for stdbool.h that conforms to C99], - [ac_cv_header_stdbool_h], - [AC_TRY_COMPILE( - [ - #include - #ifndef bool - "error: bool is not defined" - #endif - #ifndef false - "error: false is not defined" - #endif - #if false - "error: false is not 0" - #endif - #ifndef true - "error: true is not defined" - #endif - #if true != 1 - "error: true is not 1" - #endif - #ifndef __bool_true_false_are_defined - "error: __bool_true_false_are_defined is not defined" - #endif - - struct s { _Bool s: 1; _Bool t; } s; - - char a[true == 1 ? 1 : -1]; - char b[false == 0 ? 1 : -1]; - char c[__bool_true_false_are_defined == 1 ? 1 : -1]; - char d[(bool) 0.5 == true ? 1 : -1]; - bool e = &s; - char f[(_Bool) 0.0 == false ? 1 : -1]; - char g[true]; - char h[sizeof (_Bool)]; - char i[sizeof s.t]; - enum { j = false, k = true, l = false * true, m = true * 256 }; - _Bool n[m]; - char o[sizeof n == m * sizeof n[0] ? 1 : -1]; - char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; - #if defined __xlc__ || defined __GNUC__ - /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 - reported by James Lemley on 2005-10-05; see - http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html - This test is not quite right, since xlc is allowed to - reject this program, as the initializer for xlcbug is - not one of the forms that C requires support for. - However, doing the test right would require a run-time - test, and that would make cross-compilation harder. - Let us hope that IBM fixes the xlc bug, and also adds - support for this kind of constant expression. In the - meantime, this test will reject xlc, which is OK, since - our stdbool.h substitute should suffice. We also test - this with GCC, where it should work, to detect more - quickly whether someone messes up the test in the - future. */ - char digs[] = "0123456789"; - int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); - #endif - /* Catch a bug in an HP-UX C compiler. See - http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html - http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html - */ - _Bool q = true; - _Bool *pq = &q; - ], - [ - *pq |= q; - *pq |= ! q; - /* Refer to every declared value, to avoid compiler optimizations. */ - return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l - + !m + !n + !o + !p + !q + !pq); - ], - [ac_cv_header_stdbool_h=yes], - [ac_cv_header_stdbool_h=no])]) - AC_CHECK_TYPES([_Bool]) - if test $ac_cv_header_stdbool_h = yes; then - AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.]) - fi]) diff --git a/m4/stdint.m4 b/m4/stdint.m4 deleted file mode 100644 index bb6c34f..0000000 --- a/m4/stdint.m4 +++ /dev/null @@ -1,395 +0,0 @@ -# stdint.m4 serial 29 -dnl Copyright (C) 2001-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert and Bruno Haible. -dnl Test whether is supported or must be substituted. - -AC_DEFUN([gl_STDINT_H], -[ - AC_PREREQ(2.59)dnl - - dnl Check for long long int and unsigned long long int. - AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) - if test $ac_cv_type_long_long_int = yes; then - HAVE_LONG_LONG_INT=1 - else - HAVE_LONG_LONG_INT=0 - fi - AC_SUBST([HAVE_LONG_LONG_INT]) - AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) - if test $ac_cv_type_unsigned_long_long_int = yes; then - HAVE_UNSIGNED_LONG_LONG_INT=1 - else - HAVE_UNSIGNED_LONG_LONG_INT=0 - fi - AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) - - dnl Check for . - dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. - if test $ac_cv_header_inttypes_h = yes; then - HAVE_INTTYPES_H=1 - else - HAVE_INTTYPES_H=0 - fi - AC_SUBST([HAVE_INTTYPES_H]) - - dnl Check for . - dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. - if test $ac_cv_header_sys_types_h = yes; then - HAVE_SYS_TYPES_H=1 - else - HAVE_SYS_TYPES_H=0 - fi - AC_SUBST([HAVE_SYS_TYPES_H]) - - gl_CHECK_NEXT_HEADERS([stdint.h]) - if test $ac_cv_header_stdint_h = yes; then - HAVE_STDINT_H=1 - else - HAVE_STDINT_H=0 - fi - AC_SUBST([HAVE_STDINT_H]) - - dnl Now see whether we need a substitute . - if test $ac_cv_header_stdint_h = yes; then - AC_CACHE_CHECK([whether stdint.h conforms to C99], - [gl_cv_header_working_stdint_h], - [gl_cv_header_working_stdint_h=no - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ -#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ -#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ -#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ -#include -/* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in . */ -#if !(defined WCHAR_MIN && defined WCHAR_MAX) -#error "WCHAR_MIN, WCHAR_MAX not defined in " -#endif -] -gl_STDINT_INCLUDES -[ -#ifdef INT8_MAX -int8_t a1 = INT8_MAX; -int8_t a1min = INT8_MIN; -#endif -#ifdef INT16_MAX -int16_t a2 = INT16_MAX; -int16_t a2min = INT16_MIN; -#endif -#ifdef INT32_MAX -int32_t a3 = INT32_MAX; -int32_t a3min = INT32_MIN; -#endif -#ifdef INT64_MAX -int64_t a4 = INT64_MAX; -int64_t a4min = INT64_MIN; -#endif -#ifdef UINT8_MAX -uint8_t b1 = UINT8_MAX; -#else -typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; -#endif -#ifdef UINT16_MAX -uint16_t b2 = UINT16_MAX; -#endif -#ifdef UINT32_MAX -uint32_t b3 = UINT32_MAX; -#endif -#ifdef UINT64_MAX -uint64_t b4 = UINT64_MAX; -#endif -int_least8_t c1 = INT8_C (0x7f); -int_least8_t c1max = INT_LEAST8_MAX; -int_least8_t c1min = INT_LEAST8_MIN; -int_least16_t c2 = INT16_C (0x7fff); -int_least16_t c2max = INT_LEAST16_MAX; -int_least16_t c2min = INT_LEAST16_MIN; -int_least32_t c3 = INT32_C (0x7fffffff); -int_least32_t c3max = INT_LEAST32_MAX; -int_least32_t c3min = INT_LEAST32_MIN; -int_least64_t c4 = INT64_C (0x7fffffffffffffff); -int_least64_t c4max = INT_LEAST64_MAX; -int_least64_t c4min = INT_LEAST64_MIN; -uint_least8_t d1 = UINT8_C (0xff); -uint_least8_t d1max = UINT_LEAST8_MAX; -uint_least16_t d2 = UINT16_C (0xffff); -uint_least16_t d2max = UINT_LEAST16_MAX; -uint_least32_t d3 = UINT32_C (0xffffffff); -uint_least32_t d3max = UINT_LEAST32_MAX; -uint_least64_t d4 = UINT64_C (0xffffffffffffffff); -uint_least64_t d4max = UINT_LEAST64_MAX; -int_fast8_t e1 = INT_FAST8_MAX; -int_fast8_t e1min = INT_FAST8_MIN; -int_fast16_t e2 = INT_FAST16_MAX; -int_fast16_t e2min = INT_FAST16_MIN; -int_fast32_t e3 = INT_FAST32_MAX; -int_fast32_t e3min = INT_FAST32_MIN; -int_fast64_t e4 = INT_FAST64_MAX; -int_fast64_t e4min = INT_FAST64_MIN; -uint_fast8_t f1 = UINT_FAST8_MAX; -uint_fast16_t f2 = UINT_FAST16_MAX; -uint_fast32_t f3 = UINT_FAST32_MAX; -uint_fast64_t f4 = UINT_FAST64_MAX; -#ifdef INTPTR_MAX -intptr_t g = INTPTR_MAX; -intptr_t gmin = INTPTR_MIN; -#endif -#ifdef UINTPTR_MAX -uintptr_t h = UINTPTR_MAX; -#endif -intmax_t i = INTMAX_MAX; -uintmax_t j = UINTMAX_MAX; - -#include /* for CHAR_BIT */ -#define TYPE_MINIMUM(t) \ - ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) -#define TYPE_MAXIMUM(t) \ - ((t) ((t) 0 < (t) -1 ? (t) -1 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) -struct s { - int check_PTRDIFF: - PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t) - && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t) - ? 1 : -1; - /* Detect bug in FreeBSD 6.0 / ia64. */ - int check_SIG_ATOMIC: - SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t) - && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t) - ? 1 : -1; - int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1; - int check_WCHAR: - WCHAR_MIN == TYPE_MINIMUM (wchar_t) - && WCHAR_MAX == TYPE_MAXIMUM (wchar_t) - ? 1 : -1; - /* Detect bug in mingw. */ - int check_WINT: - WINT_MIN == TYPE_MINIMUM (wint_t) - && WINT_MAX == TYPE_MAXIMUM (wint_t) - ? 1 : -1; - - /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ - int check_UINT8_C: - (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; - int check_UINT16_C: - (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; - - /* Detect bugs in OpenBSD 3.9 stdint.h. */ -#ifdef UINT8_MAX - int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; -#endif -#ifdef UINT16_MAX - int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; -#endif -#ifdef UINT32_MAX - int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; -#endif -#ifdef UINT64_MAX - int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; -#endif - int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; - int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; - int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; - int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; - int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; - int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; - int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; - int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; - int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; - int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; - int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; -}; - ]])], - [gl_cv_header_working_stdint_h=yes])]) - fi - if test "$gl_cv_header_working_stdint_h" = yes; then - STDINT_H= - else - dnl Check for , and for - dnl (used in Linux libc4 >= 4.6.7 and libc5). - AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) - if test $ac_cv_header_sys_inttypes_h = yes; then - HAVE_SYS_INTTYPES_H=1 - else - HAVE_SYS_INTTYPES_H=0 - fi - AC_SUBST([HAVE_SYS_INTTYPES_H]) - if test $ac_cv_header_sys_bitypes_h = yes; then - HAVE_SYS_BITYPES_H=1 - else - HAVE_SYS_BITYPES_H=0 - fi - AC_SUBST([HAVE_SYS_BITYPES_H]) - - dnl Check for (missing in Linux uClibc when built without wide - dnl character support). - AC_CHECK_HEADERS_ONCE([wchar.h]) - - gl_STDINT_TYPE_PROPERTIES - STDINT_H=stdint.h - fi - AC_SUBST(STDINT_H) -]) - -dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) -dnl Determine the size of each of the given types in bits. -AC_DEFUN([gl_STDINT_BITSIZEOF], -[ - dnl Use a shell loop, to avoid bloating configure, and - dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into - dnl config.h.in, - dnl - extra AC_SUBST calls, so that the right substitutions are made. - AC_FOREACH([gltype], [$1], - [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), - [Define to the number of bits in type ']gltype['.])]) - for gltype in $1 ; do - AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], - [AC_COMPUTE_INT([result], [sizeof ($gltype) * CHAR_BIT], - [$2 -#include ], [result=unknown]) - eval gl_cv_bitsizeof_${gltype}=\$result - ]) - eval result=\$gl_cv_bitsizeof_${gltype} - if test $result = unknown; then - dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, - dnl do a syntax check even on unused #if conditions and give an error - dnl on valid C code like this: - dnl #if 0 - dnl # if > 32 - dnl # endif - dnl #endif - result=0 - fi - GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` - AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) - eval BITSIZEOF_${GLTYPE}=\$result - done - AC_FOREACH([gltype], [$1], - [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) -]) - -dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) -dnl Determine the signedness of each of the given types. -dnl Define HAVE_SIGNED_TYPE if type is signed. -AC_DEFUN([gl_CHECK_TYPES_SIGNED], -[ - dnl Use a shell loop, to avoid bloating configure, and - dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into - dnl config.h.in, - dnl - extra AC_SUBST calls, so that the right substitutions are made. - AC_FOREACH([gltype], [$1], - [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), - [Define to 1 if ']gltype[' is a signed integer type.])]) - for gltype in $1 ; do - AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([$2[ - int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], - result=yes, result=no) - eval gl_cv_type_${gltype}_signed=\$result - ]) - eval result=\$gl_cv_type_${gltype}_signed - GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` - if test "$result" = yes; then - AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1) - eval HAVE_SIGNED_${GLTYPE}=1 - else - eval HAVE_SIGNED_${GLTYPE}=0 - fi - done - AC_FOREACH([gltype], [$1], - [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) -]) - -dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) -dnl Determine the suffix to use for integer constants of the given types. -dnl Define t_SUFFIX for each such type. -AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], -[ - dnl Use a shell loop, to avoid bloating configure, and - dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into - dnl config.h.in, - dnl - extra AC_SUBST calls, so that the right substitutions are made. - AC_FOREACH([gltype], [$1], - [AH_TEMPLATE(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], - [Define to l, ll, u, ul, ull, etc., as suitable for - constants of type ']gltype['.])]) - for gltype in $1 ; do - AC_CACHE_CHECK([for $gltype integer literal suffix], - [gl_cv_type_${gltype}_suffix], - [eval gl_cv_type_${gltype}_suffix=no - eval result=\$gl_cv_type_${gltype}_signed - if test "$result" = yes; then - glsufu= - else - glsufu=u - fi - for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do - case $glsuf in - '') gltype1='int';; - l) gltype1='long int';; - ll) gltype1='long long int';; - i64) gltype1='__int64';; - u) gltype1='unsigned int';; - ul) gltype1='unsigned long int';; - ull) gltype1='unsigned long long int';; - ui64)gltype1='unsigned __int64';; - esac - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([$2 - extern $gltype foo; - extern $gltype1 foo;])], - [eval gl_cv_type_${gltype}_suffix=\$glsuf]) - eval result=\$gl_cv_type_${gltype}_suffix - test "$result" != no && break - done]) - GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` - eval result=\$gl_cv_type_${gltype}_suffix - test "$result" = no && result= - eval ${GLTYPE}_SUFFIX=\$result - AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], $result) - done - AC_FOREACH([gltype], [$1], - [AC_SUBST(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) -]) - -dnl gl_STDINT_INCLUDES -AC_DEFUN([gl_STDINT_INCLUDES], -[[ - /* BSD/OS 4.0.1 has a bug: , and must be - included before . */ - #include - #include - #if HAVE_WCHAR_H - # include - # include - # include - #endif -]]) - -dnl gl_STDINT_TYPE_PROPERTIES -dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t -dnl of interest to stdint.in.h. -AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], -[ - gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], - [gl_STDINT_INCLUDES]) - gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], - [gl_STDINT_INCLUDES]) - gl_cv_type_ptrdiff_t_signed=yes - gl_cv_type_size_t_signed=no - gl_INTEGER_TYPE_SUFFIX([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], - [gl_STDINT_INCLUDES]) -]) - -dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in. -dnl Remove this when we can assume autoconf >= 2.61. -m4_ifdef([AC_COMPUTE_INT], [], [ - AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])]) -]) - -# Hey Emacs! -# Local Variables: -# indent-tabs-mode: nil -# End: diff --git a/m4/stdint_h.m4 b/m4/stdint_h.m4 deleted file mode 100644 index db9a8ac..0000000 --- a/m4/stdint_h.m4 +++ /dev/null @@ -1,26 +0,0 @@ -# stdint_h.m4 serial 6 -dnl Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_STDINT_H_WITH_UINTMAX if exists, -# doesn't clash with , and declares uintmax_t. - -AC_DEFUN([gl_AC_HEADER_STDINT_H], -[ - AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, - [AC_TRY_COMPILE( - [#include -#include ], - [uintmax_t i = (uintmax_t) -1; return !i;], - gl_cv_header_stdint_h=yes, - gl_cv_header_stdint_h=no)]) - if test $gl_cv_header_stdint_h = yes; then - AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1, - [Define if exists, doesn't clash with , - and declares uintmax_t. ]) - fi -]) diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 deleted file mode 100644 index 45e54e2..0000000 --- a/m4/stdio_h.m4 +++ /dev/null @@ -1,86 +0,0 @@ -# stdio_h.m4 serial 8 -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_STDIO_H], -[ - AC_REQUIRE([gl_STDIO_H_DEFAULTS]) - gl_CHECK_NEXT_HEADERS([stdio.h]) -]) - -AC_DEFUN([gl_STDIO_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_STDIO_H_DEFAULTS]) - GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 -]) - -AC_DEFUN([gl_STDIO_H_DEFAULTS], -[ - GNULIB_FPRINTF_POSIX=0; AC_SUBST([GNULIB_FPRINTF_POSIX]) - GNULIB_PRINTF_POSIX=0; AC_SUBST([GNULIB_PRINTF_POSIX]) - GNULIB_SNPRINTF=0; AC_SUBST([GNULIB_SNPRINTF]) - GNULIB_SPRINTF_POSIX=0; AC_SUBST([GNULIB_SPRINTF_POSIX]) - GNULIB_VFPRINTF_POSIX=0; AC_SUBST([GNULIB_VFPRINTF_POSIX]) - GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX]) - GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF]) - GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX]) - GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF]) - GNULIB_FOPEN=0; AC_SUBST([GNULIB_FOPEN]) - GNULIB_FREOPEN=0; AC_SUBST([GNULIB_FREOPEN]) - GNULIB_FSEEK=0; AC_SUBST([GNULIB_FSEEK]) - GNULIB_FSEEKO=0; AC_SUBST([GNULIB_FSEEKO]) - GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL]) - GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO]) - GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH]) - GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM]) - GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE]) - dnl Assume proper GNU behavior unless another module says otherwise. - REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) - REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF]) - REPLACE_PRINTF=0; AC_SUBST([REPLACE_PRINTF]) - REPLACE_VPRINTF=0; AC_SUBST([REPLACE_VPRINTF]) - REPLACE_SNPRINTF=0; AC_SUBST([REPLACE_SNPRINTF]) - HAVE_DECL_SNPRINTF=1; AC_SUBST([HAVE_DECL_SNPRINTF]) - REPLACE_VSNPRINTF=0; AC_SUBST([REPLACE_VSNPRINTF]) - HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF]) - REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF]) - REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF]) - HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF]) - REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF]) - REPLACE_FOPEN=0; AC_SUBST([REPLACE_FOPEN]) - REPLACE_FREOPEN=0; AC_SUBST([REPLACE_FREOPEN]) - HAVE_FSEEKO=1; AC_SUBST([HAVE_FSEEKO]) - REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO]) - REPLACE_FSEEK=0; AC_SUBST([REPLACE_FSEEK]) - HAVE_FTELLO=1; AC_SUBST([HAVE_FTELLO]) - REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO]) - REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL]) - REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) - HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM]) - HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE]) - REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE]) -]) - -dnl Code shared by fseeko and ftello. Determine if large files are supported, -dnl but stdin does not start as a large file by default. -AC_DEFUN([gl_STDIN_LARGE_OFFSET], - [ - AC_CACHE_CHECK([whether stdin defaults to large file offsets], - [gl_cv_var_stdin_large_offset], - [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], -[#if defined __SL64 && defined __SCLE /* cygwin */ - /* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making - fseeko/ftello needlessly fail. This bug was fixed at the same time - that cygwin started exporting asnprintf (cygwin 1.7.0), so we use - that as a link-time test for cross-compiles rather than building - a runtime test. */ - size_t s; - if (asnprintf (NULL, &s, "")) - return 0; -#endif])], - [gl_cv_var_stdin_large_offset=yes], - [gl_cv_var_stdin_large_offset=no])]) -]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 deleted file mode 100644 index ea9286e..0000000 --- a/m4/stdlib_h.m4 +++ /dev/null @@ -1,35 +0,0 @@ -# stdlib_h.m4 serial 3 -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_STDLIB_H], -[ - AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) - gl_CHECK_NEXT_HEADERS([stdlib.h]) -]) - -AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) - GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 -]) - -AC_DEFUN([gl_STDLIB_H_DEFAULTS], -[ - GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX]) - GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX]) - GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX]) - GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) - GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) - GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX]) - HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) - HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX]) - HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) - HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX]) - REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) -]) diff --git a/m4/strcase.m4 b/m4/strcase.m4 deleted file mode 100644 index ae24215..0000000 --- a/m4/strcase.m4 +++ /dev/null @@ -1,44 +0,0 @@ -# strcase.m4 serial 8 -dnl Copyright (C) 2002, 2005-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_STRCASE], -[ - gl_FUNC_STRCASECMP - gl_FUNC_STRNCASECMP -]) - -AC_DEFUN([gl_FUNC_STRCASECMP], -[ - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_REPLACE_FUNCS(strcasecmp) - if test $ac_cv_func_strcasecmp = no; then - HAVE_STRCASECMP=0 - gl_PREREQ_STRCASECMP - fi -]) - -AC_DEFUN([gl_FUNC_STRNCASECMP], -[ - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_REPLACE_FUNCS(strncasecmp) - if test $ac_cv_func_strncasecmp = no; then - gl_PREREQ_STRNCASECMP - fi - AC_CHECK_DECLS(strncasecmp) - if test $ac_cv_have_decl_strncasecmp = no; then - HAVE_DECL_STRNCASECMP=0 - fi -]) - -# Prerequisites of lib/strcasecmp.c. -AC_DEFUN([gl_PREREQ_STRCASECMP], [ - : -]) - -# Prerequisites of lib/strncasecmp.c. -AC_DEFUN([gl_PREREQ_STRNCASECMP], [ - : -]) diff --git a/m4/strchrnul.m4 b/m4/strchrnul.m4 deleted file mode 100644 index 7c1273a..0000000 --- a/m4/strchrnul.m4 +++ /dev/null @@ -1,21 +0,0 @@ -# strchrnul.m4 serial 6 -dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_STRCHRNUL], -[ - dnl Persuade glibc to declare strchrnul(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_REPLACE_FUNCS(strchrnul) - if test $ac_cv_func_strchrnul = no; then - HAVE_STRCHRNUL=0 - gl_PREREQ_STRCHRNUL - fi -]) - -# Prerequisites of lib/strchrnul.c. -AC_DEFUN([gl_PREREQ_STRCHRNUL], [:]) diff --git a/m4/strerror.m4 b/m4/strerror.m4 deleted file mode 100644 index 52f3e3f..0000000 --- a/m4/strerror.m4 +++ /dev/null @@ -1,49 +0,0 @@ -# strerror.m4 serial 4 -dnl Copyright (C) 2002, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_STRERROR], -[ - AC_REQUIRE([gl_FUNC_STRERROR_SEPARATE]) - if test $gl_cv_func_working_strerror = no; then - AC_LIBOBJ([strerror]) - AC_DEFINE_UNQUOTED([REPLACE_STRERROR], [$REPLACE_STRERROR], - [Define this to 1 if strerror is broken.]) - fi -]) - -# Like gl_FUNC_STRERROR, except prepare for separate compilation (no AC_LIBOBJ). -AC_DEFUN([gl_FUNC_STRERROR_SEPARATE], -[ - AC_CHECK_FUNCS_ONCE([strerror]) - gl_PREREQ_STRERROR - if test $ac_cv_func_strerror = no; then - HAVE_DECL_STRERROR=0 - gl_cv_func_working_strerror=no - else - AC_CACHE_CHECK([for working strerror function], - [gl_cv_func_working_strerror], - [AC_RUN_IFELSE( - [AC_LANG_PROGRAM([ -#include - ], [return !*strerror (-2);])], - [gl_cv_func_working_strerror=yes], [gl_cv_func_working_strerror=no], - [dnl assume success except on Interix - AC_EGREP_CPP([assuming success], [ -#ifndef __INTERIX - assuming success -#endif - ], [gl_cv_func_working_strerror=yes], - [gl_cv_func_working_strerror=no])])]) - if test $gl_cv_func_working_strerror = no ; then - REPLACE_STRERROR=1 - fi - fi -]) - -# Prerequisites of lib/strerror.c. -AC_DEFUN([gl_PREREQ_STRERROR], [ - : -]) diff --git a/m4/string_h.m4 b/m4/string_h.m4 deleted file mode 100644 index d811e26..0000000 --- a/m4/string_h.m4 +++ /dev/null @@ -1,80 +0,0 @@ -# Configure a GNU-like replacement for . - -# Copyright (C) 2007 Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# Written by Paul Eggert. - -AC_DEFUN([gl_HEADER_STRING_H], -[ - dnl Use AC_REQUIRE here, so that the default behavior below is expanded - dnl once only, before all statements that occur in other macros. - AC_REQUIRE([gl_HEADER_STRING_H_BODY]) -]) - -AC_DEFUN([gl_HEADER_STRING_H_BODY], -[ - AC_REQUIRE([AC_C_RESTRICT]) - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - gl_CHECK_NEXT_HEADERS([string.h]) -]) - -AC_DEFUN([gl_STRING_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 -]) - -AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], -[ - GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) - GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) - GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) - GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY]) - GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) - GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) - GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) - GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) - GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) - GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) - GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) - GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) - GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) - GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN]) - GNULIB_MBSNLEN=0; AC_SUBST([GNULIB_MBSNLEN]) - GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR]) - GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR]) - GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR]) - GNULIB_MBSCASECMP=0; AC_SUBST([GNULIB_MBSCASECMP]) - GNULIB_MBSNCASECMP=0; AC_SUBST([GNULIB_MBSNCASECMP]) - GNULIB_MBSPCASECMP=0; AC_SUBST([GNULIB_MBSPCASECMP]) - GNULIB_MBSCASESTR=0; AC_SUBST([GNULIB_MBSCASESTR]) - GNULIB_MBSCSPN=0; AC_SUBST([GNULIB_MBSCSPN]) - GNULIB_MBSPBRK=0; AC_SUBST([GNULIB_MBSPBRK]) - GNULIB_MBSSPN=0; AC_SUBST([GNULIB_MBSSPN]) - GNULIB_MBSSEP=0; AC_SUBST([GNULIB_MBSSEP]) - GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R]) - GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM]) - HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) - HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) - HAVE_STPCPY=1; AC_SUBST([HAVE_STPCPY]) - HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY]) - HAVE_STRCASECMP=1; AC_SUBST([HAVE_STRCASECMP]) - HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP]) - HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL]) - HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP]) - HAVE_STRNDUP=1; AC_SUBST([HAVE_STRNDUP]) - HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP]) - HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN]) - HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK]) - HAVE_STRSEP=1; AC_SUBST([HAVE_STRSEP]) - HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) - HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) - HAVE_DECL_STRERROR=1; AC_SUBST([HAVE_DECL_STRERROR]) - REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) -]) diff --git a/m4/strndup.m4 b/m4/strndup.m4 deleted file mode 100644 index f7934ef..0000000 --- a/m4/strndup.m4 +++ /dev/null @@ -1,53 +0,0 @@ -# strndup.m4 serial 14 -dnl Copyright (C) 2002-2003, 2005-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_STRNDUP], -[ - dnl Persuade glibc to declare strndup(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_CHECK_DECLS_ONCE([strndup]) - if test $ac_cv_have_decl_strndup = no; then - HAVE_DECL_STRNDUP=0 - fi - - # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. - AC_CACHE_CHECK([for working strndup], gl_cv_func_strndup, - [AC_RUN_IFELSE([ - AC_LANG_PROGRAM([#include - #include ], [[ -#ifndef HAVE_DECL_STRNDUP - extern char *strndup (const char *, size_t); -#endif - char *s; - s = strndup ("some longer string", 15); - free (s); - s = strndup ("shorter string", 13); - return s[13] != '\0';]])], - [gl_cv_func_strndup=yes], - [gl_cv_func_strndup=no], - [AC_CHECK_FUNC([strndup], - [AC_EGREP_CPP([too risky], [ -#ifdef _AIX - too risky -#endif - ], - [gl_cv_func_strndup=no], - [gl_cv_func_strndup=yes])], - [gl_cv_func_strndup=no])])]) - if test $gl_cv_func_strndup = yes; then - AC_DEFINE([HAVE_STRNDUP], 1, - [Define if you have the strndup() function and it works.]) - else - HAVE_STRNDUP=0 - AC_LIBOBJ([strndup]) - gl_PREREQ_STRNDUP - fi -]) - -# Prerequisites of lib/strndup.c. -AC_DEFUN([gl_PREREQ_STRNDUP], [:]) diff --git a/m4/strnlen.m4 b/m4/strnlen.m4 deleted file mode 100644 index d8307ed..0000000 --- a/m4/strnlen.m4 +++ /dev/null @@ -1,31 +0,0 @@ -# strnlen.m4 serial 9 -dnl Copyright (C) 2002-2003, 2005-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_STRNLEN], -[ - dnl Persuade glibc to declare strnlen(). - AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) - AC_CHECK_DECLS_ONCE([strnlen]) - if test $ac_cv_have_decl_strnlen = no; then - HAVE_DECL_STRNLEN=0 - fi - - AC_FUNC_STRNLEN - if test $ac_cv_func_strnlen_working = no; then - # This is necessary because automake-1.6.1 doesn't understand - # that the above use of AC_FUNC_STRNLEN means we may have to use - # lib/strnlen.c. - #AC_LIBOBJ(strnlen) - AC_DEFINE(strnlen, rpl_strnlen, - [Define to rpl_strnlen if the replacement function should be used.]) - gl_PREREQ_STRNLEN - fi -]) - -# Prerequisites of lib/strnlen.c. -AC_DEFUN([gl_PREREQ_STRNLEN], [:]) diff --git a/m4/sysexits.m4 b/m4/sysexits.m4 deleted file mode 100644 index bbd6973..0000000 --- a/m4/sysexits.m4 +++ /dev/null @@ -1,43 +0,0 @@ -# sysexits.m4 serial 4 -dnl Copyright (C) 2003, 2005, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_SYSEXITS], -[ - AC_CHECK_HEADERS_ONCE([sysexits.h]) - if test $ac_cv_header_sysexits_h = yes; then - HAVE_SYSEXITS_H=1 - gl_CHECK_NEXT_HEADERS([sysexits.h]) - AC_TRY_COMPILE([#include ], - [switch (0) - { - case EX_OK: - case EX_USAGE: - case EX_DATAERR: - case EX_NOINPUT: - case EX_NOUSER: - case EX_NOHOST: - case EX_UNAVAILABLE: - case EX_SOFTWARE: - case EX_OSERR: - case EX_OSFILE: - case EX_CANTCREAT: - case EX_IOERR: - case EX_TEMPFAIL: - case EX_PROTOCOL: - case EX_NOPERM: - case EX_CONFIG: - break; - } - ], - [SYSEXITS_H=], - [SYSEXITS_H=sysexits.h]) - else - HAVE_SYSEXITS_H=0 - SYSEXITS_H=sysexits.h - fi - AC_SUBST([HAVE_SYSEXITS_H]) - AC_SUBST([SYSEXITS_H]) -]) diff --git a/m4/ulonglong.m4 b/m4/ulonglong.m4 deleted file mode 100644 index 9fae98e..0000000 --- a/m4/ulonglong.m4 +++ /dev/null @@ -1,48 +0,0 @@ -# ulonglong.m4 serial 6 -dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. -# This fixes a bug in Autoconf 2.60, but can be removed once we -# assume 2.61 everywhere. - -# Note: If the type 'unsigned long long int' exists but is only 32 bits -# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT -# will not be defined. In this case you can treat 'unsigned long long int' -# like 'unsigned long int'. - -AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], -[ - AC_CACHE_CHECK([for unsigned long long int], - [ac_cv_type_unsigned_long_long_int], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[unsigned long long int ull = 18446744073709551615ULL; - typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1 - ? 1 : -1)]; - int i = 63;]], - [[unsigned long long int ullmax = 18446744073709551615ull; - return (ull << 63 | ull >> 63 | ull << i | ull >> i - | ullmax / ull | ullmax % ull);]])], - [ac_cv_type_unsigned_long_long_int=yes], - [ac_cv_type_unsigned_long_long_int=no])]) - if test $ac_cv_type_unsigned_long_long_int = yes; then - AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, - [Define to 1 if the system has the type `unsigned long long int'.]) - fi -]) - -# This macro is obsolescent and should go away soon. -AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], -[ - AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) - ac_cv_type_unsigned_long_long=$ac_cv_type_unsigned_long_long_int - if test $ac_cv_type_unsigned_long_long = yes; then - AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, - [Define if you have the 'unsigned long long' type.]) - fi -]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 deleted file mode 100644 index b12f84e..0000000 --- a/m4/unistd_h.m4 +++ /dev/null @@ -1,56 +0,0 @@ -# unistd_h.m4 serial 9 -dnl Copyright (C) 2006-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Written by Simon Josefsson, Bruno Haible. - -AC_DEFUN([gl_UNISTD_H], -[ - dnl Use AC_REQUIRE here, so that the default behavior below is expanded - dnl once only, before all statements that occur in other macros. - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - - gl_CHECK_NEXT_HEADERS([unistd.h]) - - AC_CHECK_HEADERS_ONCE([unistd.h]) - if test $ac_cv_header_unistd_h = yes; then - HAVE_UNISTD_H=1 - else - HAVE_UNISTD_H=0 - fi - AC_SUBST([HAVE_UNISTD_H]) -]) - -AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 -]) - -AC_DEFUN([gl_UNISTD_H_DEFAULTS], -[ - GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) - GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) - GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) - GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) - GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) - GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) - GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN]) - GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) - GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK]) - GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_DUP2=1; AC_SUBST([HAVE_DUP2]) - HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) - HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) - HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) - HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) - REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) - REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) - REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) - REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) - REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) -]) diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4 deleted file mode 100644 index ef2de78..0000000 --- a/m4/vasnprintf.m4 +++ /dev/null @@ -1,197 +0,0 @@ -# vasnprintf.m4 serial 20 -dnl Copyright (C) 2002-2004, 2006-2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_VASNPRINTF], -[ - AC_REQUIRE([gl_EOVERFLOW]) - AC_CHECK_FUNCS_ONCE([vasnprintf]) - if test $ac_cv_func_vasnprintf = no; then - gl_REPLACE_VASNPRINTF - fi -]) - -AC_DEFUN([gl_REPLACE_VASNPRINTF], -[ - AC_CHECK_FUNCS_ONCE([vasnprintf]) - AC_LIBOBJ([vasnprintf]) - AC_LIBOBJ([printf-args]) - AC_LIBOBJ([printf-parse]) - AC_LIBOBJ([asnprintf]) - if test $ac_cv_func_vasnprintf = yes; then - AC_DEFINE([REPLACE_VASNPRINTF], 1, - [Define if vasnprintf exists but is overridden by gnulib.]) - fi - gl_PREREQ_PRINTF_ARGS - gl_PREREQ_PRINTF_PARSE - gl_PREREQ_VASNPRINTF - gl_PREREQ_ASNPRINTF -]) - -# Prequisites of lib/printf-args.h, lib/printf-args.c. -AC_DEFUN([gl_PREREQ_PRINTF_ARGS], -[ - AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) - AC_REQUIRE([gt_TYPE_WCHAR_T]) - AC_REQUIRE([gt_TYPE_WINT_T]) -]) - -# Prequisites of lib/printf-parse.h, lib/printf-parse.c. -AC_DEFUN([gl_PREREQ_PRINTF_PARSE], -[ - AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) - AC_REQUIRE([gt_TYPE_WCHAR_T]) - AC_REQUIRE([gt_TYPE_WINT_T]) - AC_REQUIRE([AC_TYPE_SIZE_T]) - AC_CHECK_TYPES(ptrdiff_t) - AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) -]) - -# Prerequisites of lib/vasnprintf.c. -AC_DEFUN([gl_PREREQ_VASNPRINTF], -[ - AC_REQUIRE([AC_FUNC_ALLOCA]) - AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) - AC_REQUIRE([gt_TYPE_WCHAR_T]) - AC_REQUIRE([gt_TYPE_WINT_T]) - AC_CHECK_FUNCS(snprintf wcslen) - dnl Use the _snprintf function only if it is declared (because on NetBSD it - dnl is defined as a weak alias of snprintf; we prefer to use the latter). - AC_CHECK_DECLS([_snprintf], , , [#include ]) -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting 'long double' -# arguments. -AC_DEFUN([gl_PREREQ_VASNPRINTF_LONG_DOUBLE], -[ - AC_REQUIRE([gl_PRINTF_LONG_DOUBLE]) - case "$gl_cv_func_printf_long_double" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_LONG_DOUBLE], 1, - [Define if the vasnprintf implementation needs special code for - 'long double' arguments.]) - ;; - esac -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'double' -# arguments. -AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE], -[ - AC_REQUIRE([gl_PRINTF_INFINITE]) - case "$gl_cv_func_printf_infinite" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_INFINITE_DOUBLE], 1, - [Define if the vasnprintf implementation needs special code for - infinite 'double' arguments.]) - ;; - esac -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting infinite 'long double' -# arguments. -AC_DEFUN([gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE], -[ - AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE]) - dnl There is no need to set NEED_PRINTF_INFINITE_LONG_DOUBLE if - dnl NEED_PRINTF_LONG_DOUBLE is already set. - AC_REQUIRE([gl_PREREQ_VASNPRINTF_LONG_DOUBLE]) - case "$gl_cv_func_printf_long_double" in - *yes) - case "$gl_cv_func_printf_infinite_long_double" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_INFINITE_LONG_DOUBLE], 1, - [Define if the vasnprintf implementation needs special code for - infinite 'long double' arguments.]) - ;; - esac - ;; - esac -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting the 'a' directive. -AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A], -[ - AC_REQUIRE([gl_PRINTF_DIRECTIVE_A]) - case "$gl_cv_func_printf_directive_a" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1, - [Define if the vasnprintf implementation needs special code for - the 'a' and 'A' directives.]) - AC_CHECK_FUNCS([nl_langinfo]) - ;; - esac -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive. -AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F], -[ - AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) - case "$gl_cv_func_printf_directive_f" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_DIRECTIVE_F], 1, - [Define if the vasnprintf implementation needs special code for - the 'F' directive.]) - ;; - esac -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag. -AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING], -[ - AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) - case "$gl_cv_func_printf_flag_grouping" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], 1, - [Define if the vasnprintf implementation needs special code for the - ' flag.]) - ;; - esac -]) - -# Extra prerequisites of lib/vasnprintf.c for supporting the 0 flag. -AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_ZERO], -[ - AC_REQUIRE([gl_PRINTF_FLAG_ZERO]) - case "$gl_cv_func_printf_flag_zero" in - *yes) - ;; - *) - AC_DEFINE([NEED_PRINTF_FLAG_ZERO], 1, - [Define if the vasnprintf implementation needs special code for the - 0 flag.]) - ;; - esac -]) - -# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance. -AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS], -[ - AC_REQUIRE([gl_PREREQ_VASNPRINTF]) - gl_PREREQ_VASNPRINTF_LONG_DOUBLE - gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE - gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE - gl_PREREQ_VASNPRINTF_DIRECTIVE_A - gl_PREREQ_VASNPRINTF_DIRECTIVE_F - gl_PREREQ_VASNPRINTF_FLAG_GROUPING - gl_PREREQ_VASNPRINTF_FLAG_ZERO -]) - -# Prerequisites of lib/asnprintf.c. -AC_DEFUN([gl_PREREQ_ASNPRINTF], -[ -]) diff --git a/m4/vsnprintf.m4 b/m4/vsnprintf.m4 deleted file mode 100644 index accc79f..0000000 --- a/m4/vsnprintf.m4 +++ /dev/null @@ -1,31 +0,0 @@ -# vsnprintf.m4 serial 4 -dnl Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_VSNPRINTF], -[ - AC_REQUIRE([gl_STDIO_H_DEFAULTS]) - AC_CHECK_FUNCS([vsnprintf]) - if test $ac_cv_func_vsnprintf = no; then - gl_REPLACE_VSNPRINTF - fi - AC_CHECK_DECLS_ONCE([vsnprintf]) - if test $ac_cv_have_decl_vsnprintf = no; then - HAVE_DECL_VSNPRINTF=0 - fi -]) - -AC_DEFUN([gl_REPLACE_VSNPRINTF], -[ - AC_REQUIRE([gl_STDIO_H_DEFAULTS]) - AC_LIBOBJ([vsnprintf]) - if test $ac_cv_func_vsnprintf = yes; then - REPLACE_VSNPRINTF=1 - fi - gl_PREREQ_VSNPRINTF -]) - -# Prerequisites of lib/vsnprintf.c. -AC_DEFUN([gl_PREREQ_VSNPRINTF], [:]) diff --git a/m4/wchar.m4 b/m4/wchar.m4 deleted file mode 100644 index 70b1248..0000000 --- a/m4/wchar.m4 +++ /dev/null @@ -1,54 +0,0 @@ -dnl A placeholder for ISO C99 , for platforms that have issues. - -dnl Copyright (C) 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl Written by Eric Blake. - -# wchar.m4 serial 4 - -AC_DEFUN([gl_WCHAR_H], -[ - AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) - AC_CACHE_CHECK([whether is standalone], - [gl_cv_header_wchar_h_standalone], - [AC_COMPILE_IFELSE([[#include -wchar_t w;]], - [gl_cv_header_wchar_h_standalone=yes], - [gl_cv_header_wchar_h_standalone=no])]) - if test $gl_cv_header_wchar_h_standalone != yes; then - WCHAR_H=wchar.h - fi - - dnl Prepare for creating substitute . - dnl Do it always: WCHAR_H may be empty here but can be set later. - dnl Check for (missing in Linux uClibc when built without wide - dnl character support). - AC_CHECK_HEADERS_ONCE([wchar.h]) - if test $ac_cv_header_wchar_h = yes; then - HAVE_WCHAR_H=1 - else - HAVE_WCHAR_H=0 - fi - AC_SUBST([HAVE_WCHAR_H]) - gl_CHECK_NEXT_HEADERS([wchar.h]) -]) - -AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], -[ - dnl Use AC_REQUIRE here, so that the default settings are expanded once only. - AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) - GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 -]) - -AC_DEFUN([gl_WCHAR_H_DEFAULTS], -[ - GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH]) - dnl Assume proper GNU behavior unless another module says otherwise. - HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) - REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) - WCHAR_H= - AC_SUBST([WCHAR_H]) -]) diff --git a/m4/wchar_t.m4 b/m4/wchar_t.m4 deleted file mode 100644 index cde2129..0000000 --- a/m4/wchar_t.m4 +++ /dev/null @@ -1,20 +0,0 @@ -# wchar_t.m4 serial 1 (gettext-0.12) -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. -dnl Test whether has the 'wchar_t' type. -dnl Prerequisite: AC_PROG_CC - -AC_DEFUN([gt_TYPE_WCHAR_T], -[ - AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t, - [AC_TRY_COMPILE([#include - wchar_t foo = (wchar_t)'\0';], , - gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)]) - if test $gt_cv_c_wchar_t = yes; then - AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.]) - fi -]) diff --git a/m4/wint_t.m4 b/m4/wint_t.m4 deleted file mode 100644 index 2cac1a7..0000000 --- a/m4/wint_t.m4 +++ /dev/null @@ -1,28 +0,0 @@ -# wint_t.m4 serial 2 (gettext-0.16.2) -dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. -dnl Test whether has the 'wint_t' type. -dnl Prerequisite: AC_PROG_CC - -AC_DEFUN([gt_TYPE_WINT_T], -[ - AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, - [AC_TRY_COMPILE([ -/* Tru64 with Desktop Toolkit C has a bug: must be included before - . - BSD/OS 4.0.1 has a bug: , and must be included - before . */ -#include -#include -#include -#include - wint_t foo = (wchar_t)'\0';], , - gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) - if test $gt_cv_c_wint_t = yes; then - AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.]) - fi -]) diff --git a/m4/xalloc.m4 b/m4/xalloc.m4 deleted file mode 100644 index 837a948..0000000 --- a/m4/xalloc.m4 +++ /dev/null @@ -1,24 +0,0 @@ -# xalloc.m4 serial 16 -dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_XALLOC], -[ - AC_LIBOBJ([xmalloc]) - - gl_PREREQ_XALLOC - gl_PREREQ_XMALLOC -]) - -# Prerequisites of lib/xalloc.h. -AC_DEFUN([gl_PREREQ_XALLOC], [ - AC_REQUIRE([gl_INLINE]) - : -]) - -# Prerequisites of lib/xmalloc.c. -AC_DEFUN([gl_PREREQ_XMALLOC], [ - : -]) diff --git a/m4/xsize.m4 b/m4/xsize.m4 deleted file mode 100644 index 85bb721..0000000 --- a/m4/xsize.m4 +++ /dev/null @@ -1,13 +0,0 @@ -# xsize.m4 serial 3 -dnl Copyright (C) 2003-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_XSIZE], -[ - dnl Prerequisites of lib/xsize.h. - AC_REQUIRE([gl_SIZE_MAX]) - AC_REQUIRE([AC_C_INLINE]) - AC_CHECK_HEADERS(stdint.h) -]) diff --git a/m4/xstrndup.m4 b/m4/xstrndup.m4 deleted file mode 100644 index 8a30ab1..0000000 --- a/m4/xstrndup.m4 +++ /dev/null @@ -1,15 +0,0 @@ -# xstrndup.m4 serial 2 -dnl Copyright (C) 2003 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_XSTRNDUP], -[ - gl_PREREQ_XSTRNDUP -]) - -# Prerequisites of lib/xstrndup.c. -AC_DEFUN([gl_PREREQ_XSTRNDUP], [ - : -]) diff --git a/options.c b/options.c dissimilarity index 88% index 4df5a79..c9ce86a 100644 --- a/options.c +++ b/options.c @@ -1,423 +1,258 @@ -#include -#include -#include -#include -#include "argp.h" -#include "config.h" - -#define MAXRAYS (POL_NO_DUAL | POL_INTEGER) - -#define ALLOC(type) (type*)malloc(sizeof(type)) - -void barvinok_stats_clear(struct barvinok_stats *stats) -{ - memset(stats, 0, sizeof(*stats)); -} - -void barvinok_stats_print(struct barvinok_stats *stats, FILE *out) -{ - fprintf(out, "Base cones: %ld\n", stats->base_cones); - if (stats->volume_simplices) - fprintf(out, "Volume simplices: %ld\n", stats->volume_simplices); - if (stats->topcom_chambers) { - fprintf(out, "TOPCOM empty chambers: %ld\n", - stats->topcom_empty_chambers); - fprintf(out, "TOPCOM chambers: %ld\n", stats->topcom_chambers); - fprintf(out, "TOPCOM distinct chambers: %ld\n", - stats->topcom_distinct_chambers); - } - if (stats->gbr_solved_lps) - fprintf(out, "LPs solved during GBR: %ld\n", stats->gbr_solved_lps); - if (stats->bernoulli_sums) - fprintf(out, "Bernoulli sums: %ld\n", stats->bernoulli_sums); -} - -struct barvinok_options *barvinok_options_new_with_defaults() -{ - struct barvinok_options *options = ALLOC(struct barvinok_options); - if (!options) - return NULL; - - options->stats = ALLOC(struct barvinok_stats); - if (!options->stats) { - free(options); - return NULL; - } - - barvinok_stats_clear(options->stats); - - options->LLL_a = 1; - options->LLL_b = 1; - - options->MaxRays = MAXRAYS; - -#ifdef USE_INCREMENTAL_BF - options->incremental_specialization = 2; -#elif defined USE_INCREMENTAL_DF - options->incremental_specialization = 1; -#else - options->incremental_specialization = 0; -#endif - options->max_index = 1; - options->primal = 0; -#ifdef USE_MODULO - options->lookup_table = 0; -#else - options->lookup_table = 1; -#endif - options->count_sample_infinite = 1; - options->try_Delaunay_triangulation = 0; - -#ifdef HAVE_GINAC - options->bound = BV_BOUND_BERNSTEIN; -#else - options->bound = BV_BOUND_RANGE; -#endif - options->chambers = BV_CHAMBERS_POLYLIB; - - options->polynomial_approximation = BV_APPROX_SIGN_NONE; - options->approximation_method = BV_APPROX_NONE; - options->scale_flags = 0; - options->volume_triangulate = BV_VOL_VERTEX; - -#ifdef HAVE_LIBGLPK - options->gbr_lp_solver = BV_GBR_GLPK; -#elif defined HAVE_LIBCDDGMP - options->gbr_lp_solver = BV_GBR_CDD; -#else - options->gbr_lp_solver = BV_GBR_PIP; -#endif - -#ifdef HAVE_LIBGLPK - options->lp_solver = BV_LP_GLPK; -#elif defined HAVE_LIBCDDGMP - options->lp_solver = BV_LP_CDD; -#else - options->lp_solver = BV_LP_PIP; -#endif - - options->summation = BV_SUM_LAURENT; - - options->bernstein_optimize = BV_BERNSTEIN_NONE; - - options->bernstein_recurse = BV_BERNSTEIN_FACTORS; - - options->integer_hull = BV_HULL_GBR; - - options->verbose = 0; - - options->print_stats = 0; - - options->gbr_only_first = 0; - - return options; -} - -void barvinok_options_free(struct barvinok_options *options) -{ - free(options->stats); - free(options); -} - -enum { - SCALE_FAST, - SCALE_SLOW, - SCALE_NARROW, - SCALE_NARROW2, - SCALE_CHAMBER, -}; - -const char *scale_opts[] = { - "fast", - "slow", - "narrow", - "narrow2", - "chamber", - NULL -}; - -static struct argp_option approx_argp_options[] = { - { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 }, - { "approximation-method", BV_OPT_APPROX, "scale|drop|volume|bernoulli", 0, - "method to use in polynomial approximation [default: drop]" }, - { "scale-options", BV_OPT_SCALE, - "fast|slow,narrow|narrow2,chamber", 0 }, - { "volume-triangulation", BV_OPT_VOL, "lift|vertex|barycenter", 0, - "type of triangulation to perform in volume computation [default: vertex]" }, - { 0 } -}; - -static struct argp_option barvinok_argp_options[] = { - { "index", BV_OPT_MAXINDEX, "int", 0, - "maximal index of simple cones in decomposition" }, - { "primal", BV_OPT_PRIMAL, 0, 0 }, - { "table", BV_OPT_TABLE, 0, 0 }, - { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random|todd]" }, -#ifdef HAVE_GINAC - { "bound", BV_OPT_BOUND, "bernstein|range", 0, - "algorithm to use for computing bounds [default: bernstein]" }, -#endif -#ifdef POINTS2TRIANGS_PATH - { "chamber-decomposition", BV_OPT_CHAMBERS, "polylib|topcom", 0, - "tool to use for chamber decomposition [default: polylib]" }, -#endif - { "gbr", BV_OPT_GBR, -#if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP) - "cdd|glpk|pip|pip-dual", -#elif defined(HAVE_LIBGLPK) - "glpk|pip|pip-dual", -#elif defined(HAVE_LIBCDDGMP) - "cdd|pip|pip-dual", -#else - "pip|pip-dual", -#endif - 0, "lp solver to use for basis reduction " -#ifdef HAVE_LIBGLPK - "[default: glpk]" -#elif defined HAVE_LIBCDDGMP - "[default: cdd]" -#else - "[default: pip]" -#endif - }, - { "lp", BV_OPT_LP, -#if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP) - "cdd|cddf|glpk|pip|polylib", -#elif defined(HAVE_LIBGLPK) - "glpk|pip|polylib", -#elif defined(HAVE_LIBCDDGMP) - "cdd|cddf|pip|polylib", -#else - "pip|polylib", -#endif - 0, "lp solver to use " -#if defined(HAVE_LIBGLPK) - "[default: glpk]", -#elif defined(HAVE_LIBCDDGMP) - "[default: cdd]", -#else - "[default: pip]", -#endif - }, - { "summation", BV_OPT_SUM, "box|bernoulli|euler|laurent", 0, - "[default: laurent]" }, - { "bernstein-recurse", BV_OPT_RECURSE, "none|factors|intervals|full", 0, - "[default: factors]" }, - { "recurse", BV_OPT_RECURSE, "", - OPTION_ALIAS | OPTION_HIDDEN }, - { "integer-hull", BV_OPT_HULL, -#ifdef USE_ZSOLVE - "gbr|hilbert", -#else - "gbr", -#endif - 0, "[default: gbr]" }, - { "version", 'V', 0, 0 }, - { "verbose", 'v' }, - { "print-stats", BV_OPT_PRINT_STATS, 0, 0 }, - { 0 } -}; - -static error_t approx_parse_opt(int key, char *arg, struct argp_state *state) -{ - struct barvinok_options *options = state->input; - char *subopt; - - switch (key) { - case BV_OPT_POLAPPROX: - if (!arg) { - options->polynomial_approximation = BV_APPROX_SIGN_APPROX; - if (options->approximation_method == BV_APPROX_NONE) - options->approximation_method = BV_APPROX_SCALE; - } else { - if (!strcmp(arg, "lower")) - options->polynomial_approximation = BV_APPROX_SIGN_LOWER; - else if (!strcmp(arg, "upper")) - options->polynomial_approximation = BV_APPROX_SIGN_UPPER; - if (options->approximation_method == BV_APPROX_NONE) - options->approximation_method = BV_APPROX_DROP; - } - break; - case BV_OPT_APPROX: - if (options->polynomial_approximation == BV_APPROX_SIGN_NONE) - options->polynomial_approximation = BV_APPROX_SIGN_APPROX; - if (!strcmp(arg, "scale")) - options->approximation_method = BV_APPROX_SCALE; - else if (!strcmp(arg, "drop")) - options->approximation_method = BV_APPROX_DROP; - else if (!strcmp(arg, "volume")) - options->approximation_method = BV_APPROX_VOLUME; - else if (!strcmp(arg, "bernoulli")) - options->approximation_method = BV_APPROX_BERNOULLI; - else - argp_error(state, "unknown value for --approximation-method option"); - break; - case BV_OPT_SCALE: - options->approximation_method = BV_APPROX_SCALE; - while (*arg != '\0') - switch (getsubopt(&arg, scale_opts, &subopt)) { - case SCALE_FAST: - options->scale_flags |= BV_APPROX_SCALE_FAST; - break; - case SCALE_SLOW: - options->scale_flags &= ~BV_APPROX_SCALE_FAST; - break; - case SCALE_NARROW: - options->scale_flags |= BV_APPROX_SCALE_NARROW; - options->scale_flags &= ~BV_APPROX_SCALE_NARROW2; - break; - case SCALE_NARROW2: - options->scale_flags |= BV_APPROX_SCALE_NARROW2; - options->scale_flags &= ~BV_APPROX_SCALE_NARROW; - break; - case SCALE_CHAMBER: - options->scale_flags |= BV_APPROX_SCALE_CHAMBER; - break; - default: - argp_error(state, "unknown suboption '%s'\n", subopt); - } - break; - case BV_OPT_VOL: - if (!strcmp(arg, "lift")) - options->volume_triangulate = BV_VOL_LIFT; - else if (!strcmp(arg, "vertex")) - options->volume_triangulate = BV_VOL_VERTEX; - else if (!strcmp(arg, "barycenter")) - options->volume_triangulate = BV_VOL_BARYCENTER; - break; - case ARGP_KEY_END: - if (options->polynomial_approximation == BV_APPROX_SIGN_NONE && - options->approximation_method != BV_APPROX_NONE) { - fprintf(stderr, - "no polynomial approximation selected; reseting approximation method\n"); - options->approximation_method = BV_APPROX_NONE; - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state) -{ - struct barvinok_options *options = state->input; - char *subopt; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options; - break; - case 'v': - options->verbose++; - break; - case 'V': - printf(barvinok_version()); - exit(0); - case BV_OPT_SPECIALIZATION: - if (!strcmp(arg, "bf")) - options->incremental_specialization = BV_SPECIALIZATION_BF; - else if (!strcmp(arg, "df")) - options->incremental_specialization = BV_SPECIALIZATION_DF; - else if (!strcmp(arg, "random")) - options->incremental_specialization = BV_SPECIALIZATION_RANDOM; - else if (!strcmp(arg, "todd")) - options->incremental_specialization = BV_SPECIALIZATION_TODD; - break; - case BV_OPT_PRIMAL: - options->primal = 1; - break; - case BV_OPT_TABLE: - options->lookup_table = 1; - break; - case BV_OPT_BOUND: - if (!strcmp(arg, "bernstein")) - options->bound = BV_BOUND_BERNSTEIN; - if (!strcmp(arg, "range")) - options->bound = BV_BOUND_RANGE; - break; - case BV_OPT_CHAMBERS: - if (!strcmp(arg, "polylib")) - options->chambers = BV_CHAMBERS_POLYLIB; - if (!strcmp(arg, "topcom")) - options->chambers = BV_CHAMBERS_TOPCOM; - break; - case BV_OPT_GBR: - if (!strcmp(arg, "cdd")) - options->gbr_lp_solver = BV_GBR_CDD; - if (!strcmp(arg, "glpk")) - options->gbr_lp_solver = BV_GBR_GLPK; - if (!strcmp(arg, "pip")) - options->gbr_lp_solver = BV_GBR_PIP; - if (!strcmp(arg, "pip-dual")) - options->gbr_lp_solver = BV_GBR_PIP_DUAL; - break; - case BV_OPT_LP: - if (!strcmp(arg, "cdd")) - options->lp_solver = BV_LP_CDD; - if (!strcmp(arg, "cddf")) - options->lp_solver = BV_LP_CDDF; - if (!strcmp(arg, "glpk")) - options->lp_solver = BV_LP_GLPK; - if (!strcmp(arg, "pip")) - options->lp_solver = BV_LP_PIP; - if (!strcmp(arg, "polylib")) - options->lp_solver = BV_LP_POLYLIB; - break; - case BV_OPT_MAXINDEX: - options->max_index = strtoul(arg, NULL, 0); - break; - case BV_OPT_SUM: - if (!strcmp(arg, "box")) - options->summation = BV_SUM_BOX; - else if (!strcmp(arg, "barvinok")) - options->summation = BV_SUM_BOX; - else if (!strcmp(arg, "euler")) - options->summation = BV_SUM_EULER; - else if (!strcmp(arg, "bernoulli")) - options->summation = BV_SUM_BERNOULLI; - else if (!strcmp(arg, "laurent")) - options->summation = BV_SUM_LAURENT; - else if (!strcmp(arg, "laurent_old")) - options->summation = BV_SUM_LAURENT_OLD; - else - argp_error(state, "unknown summation method '%s'\n", arg); - break; - case BV_OPT_RECURSE: - if (!strcmp(arg, "none")) - options->bernstein_recurse = 0; - else if (!strcmp(arg, "factors")) - options->bernstein_recurse = BV_BERNSTEIN_FACTORS; - else if (!strcmp(arg, "intervals")) - options->bernstein_recurse = BV_BERNSTEIN_INTERVALS; - else if (!strcmp(arg, "full")) - options->bernstein_recurse = - BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS; - break; - case BV_OPT_HULL: - if (!strcmp(arg, "gbr")) - options->integer_hull = BV_HULL_GBR; - else if (!strcmp(arg, "hilbert")) - options->integer_hull = BV_HULL_HILBERT; - break; - case BV_OPT_PRINT_STATS: - options->print_stats = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp approx_argp = { - approx_argp_options, approx_parse_opt, 0, 0 -}; - -static struct argp_child barvinok_children[] = { - { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX }, - { 0 } -}; - -struct argp barvinok_argp = { - barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children -}; +#include +#include +#include +#include +#include "config.h" + +#define MAXRAYS (POL_NO_DUAL | POL_INTEGER) + +void barvinok_stats_clear(struct barvinok_stats *stats) +{ + memset(stats, 0, sizeof(*stats)); +} + +void barvinok_stats_print(struct barvinok_stats *stats, FILE *out) +{ + fprintf(out, "Base cones: %ld\n", stats->base_cones); + if (stats->volume_simplices) + fprintf(out, "Volume simplices: %ld\n", stats->volume_simplices); + if (stats->topcom_chambers) { + fprintf(out, "TOPCOM empty chambers: %ld\n", + stats->topcom_empty_chambers); + fprintf(out, "TOPCOM chambers: %ld\n", stats->topcom_chambers); + fprintf(out, "TOPCOM distinct chambers: %ld\n", + stats->topcom_distinct_chambers); + } + if (stats->gbr_solved_lps) + fprintf(out, "LPs solved during GBR: %ld\n", stats->gbr_solved_lps); + if (stats->bernoulli_sums) + fprintf(out, "Bernoulli sums: %ld\n", stats->bernoulli_sums); +} + +static struct isl_arg_choice approx[] = { + {"lower", BV_APPROX_SIGN_LOWER}, + {"upper", BV_APPROX_SIGN_UPPER}, + {0} +}; + +static struct isl_arg_choice approx_method[] = { + {"drop", BV_APPROX_DROP}, + {"scale", BV_APPROX_SCALE}, + {"volume", BV_APPROX_VOLUME}, + {"bernoulli", BV_APPROX_BERNOULLI}, + {0} +}; + +static struct isl_arg_flags scale_flags[] = { + {"fast", BV_APPROX_SCALE_FAST, BV_APPROX_SCALE_FAST}, + {"slow", BV_APPROX_SCALE_FAST, 0}, + {"narrow", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2, + BV_APPROX_SCALE_NARROW}, + {"narrow2", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2, + BV_APPROX_SCALE_NARROW2}, + {"chamber", BV_APPROX_SCALE_CHAMBER, BV_APPROX_SCALE_CHAMBER}, + {0} +}; + +static struct isl_arg_choice triangulation[] = { + {"lift", BV_VOL_LIFT}, + {"vertex", BV_VOL_VERTEX}, + {"barycenter", BV_VOL_BARYCENTER}, + {0} +}; + +static struct isl_arg approx_options_arg[] = { +ISL_ARG_OPT_CHOICE(struct barvinok_approximation_options, approximation, 0, \ + "polynomial-approximation", approx, + BV_APPROX_SIGN_NONE, BV_APPROX_SIGN_APPROX, NULL) +ISL_ARG_OPT_CHOICE(struct barvinok_approximation_options, method, 0, + "approximation-method", approx_method, BV_APPROX_NONE, BV_APPROX_DROP, + "method to use in polynomial approximation") +ISL_ARG_FLAGS(struct barvinok_approximation_options, scale_flags, 0, + "scale-options", scale_flags, 0, NULL) +ISL_ARG_CHOICE(struct barvinok_approximation_options, volume_triangulate, 0, + "volume-triangulation", triangulation, BV_VOL_VERTEX, + "type of triangulation to perform in volume computation") +ISL_ARG_END +}; + +static int stats_init(void *user) +{ + struct barvinok_stats **stats = (struct barvinok_stats **)user; + *stats = isl_alloc_type(NULL, struct barvinok_stats); + if (*stats) + barvinok_stats_clear(*stats); + return *stats ? 0 : -1; +} +static void stats_clear(void *user) +{ + struct barvinok_stats **stats = (struct barvinok_stats **)user; + free(*stats); +} +static int maxrays_init(void *user) +{ + unsigned *MaxRays = (unsigned *)user; + *MaxRays = MAXRAYS; + return 0; +} +static int int_init_one(void *user) +{ + *((int *)user) = 1; + return 0; +} +static int int_init_zero(void *user) +{ + *((int *)user) = 0; + return 0; +} +static void print_version(void) +{ + printf("%s", barvinok_version()); +} + +#ifdef USE_INCREMENTAL_BF +#define DEFAULT_SPECIALIZATION BV_SPECIALIZATION_BF +#elif defined USE_INCREMENTAL_DF +#define DEFAULT_SPECIALIZATION BV_SPECIALIZATION_DF +#else +#define DEFAULT_SPECIALIZATION BV_SPECIALIZATION_RANDOM +#endif + +static struct isl_arg_choice specialization[] = { + {"bf", BV_SPECIALIZATION_BF}, + {"df", BV_SPECIALIZATION_DF}, + {"random", BV_SPECIALIZATION_RANDOM}, + {"todd", BV_SPECIALIZATION_TODD}, + {0} +}; + +#ifdef HAVE_GINAC +#define DEFAULT_BOUND BV_BOUND_BERNSTEIN +#else +#define DEFAULT_BOUND BV_BOUND_RANGE +#endif + +static struct isl_arg_choice bound[] = { + {"bernstein", BV_BOUND_BERNSTEIN}, + {"range", BV_BOUND_RANGE}, + {0} +}; + +#ifdef HAVE_LIBGLPK +#define DEFAULT_GBR BV_GBR_GLPK +#elif defined HAVE_LIBCDDGMP +#define DEFAULT_GBR BV_GBR_CDD +#else +#define DEFAULT_GBR BV_GBR_PIP +#endif + +static struct isl_arg_choice gbr[] = { +#ifdef HAVE_LIBGLPK + {"glpk", BV_GBR_GLPK}, +#endif +#ifdef HAVE_LIBCDDGMP + {"cdd", BV_GBR_CDD}, +#endif + {"pip", BV_GBR_PIP}, + {"pip-dual", BV_GBR_PIP_DUAL}, + {0} +}; + +static struct isl_arg_flags bernstein_recurse[] = { + {"none", BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS, 0}, + {"factors", BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS, + BV_BERNSTEIN_FACTORS}, + {"intervals", BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS, + BV_BERNSTEIN_INTERVALS}, + {"full", BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS, + BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS}, + {0} +}; + +#ifdef HAVE_LIBGLPK +#define DEFAULT_LP BV_LP_GLPK +#elif defined HAVE_LIBCDDGMP +#define DEFAULT_LP BV_LP_CDD +#else +#define DEFAULT_LP BV_LP_PIP +#endif + +static struct isl_arg_choice lp[] = { +#ifdef HAVE_LIBGLPK + {"glpk", BV_LP_GLPK}, +#endif +#ifdef HAVE_LIBCDDGMP + {"cdd", BV_LP_CDD}, + {"cddf", BV_LP_CDDF}, +#endif + {"pip", BV_LP_PIP}, + {"polylib", BV_LP_POLYLIB}, + {0} +}; + +static struct isl_arg_choice summation[] = { + {"box", BV_SUM_BOX}, + {"euler", BV_SUM_EULER}, + {"bernoulli", BV_SUM_BERNOULLI}, + {"laurent", BV_SUM_LAURENT}, + {"laurent_old", BV_SUM_LAURENT_OLD}, + {0} +}; + +static struct isl_arg_choice chambers[] = { + {"polylib", BV_CHAMBERS_POLYLIB}, +#ifdef POINTS2TRIANGS_PATH + {"topcom", BV_CHAMBERS_TOPCOM}, +#endif + {0} +}; + +static struct isl_arg_choice hull[] = { + {"gbr", BV_HULL_GBR}, +#ifdef USE_ZSOLVE + {"hilbert", BV_HULL_HILBERT}, +#endif + {0} +}; + +struct isl_arg barvinok_options_arg[] = { +ISL_ARG_CHILD(struct barvinok_options, isl, "isl", isl_options_arg, "isl options") +ISL_ARG_CHILD(struct barvinok_options, approx, NULL, + approx_options_arg, "polynomial approximation") +ISL_ARG_USER(struct barvinok_options, stats, &stats_init, &stats_clear) +ISL_ARG_USER(struct barvinok_options, MaxRays, &maxrays_init, NULL) +ISL_ARG_LONG(struct barvinok_options, LLL_a, 0, "lll-reduction-num", 1, + "LLL reduction parameter numerator") +ISL_ARG_LONG(struct barvinok_options, LLL_b, 0, "lll-reduction-den", 1, + "LLL reduction parameter denominator") +ISL_ARG_CHOICE(struct barvinok_options, incremental_specialization, + 0, "specialization", specialization, DEFAULT_SPECIALIZATION, NULL) +ISL_ARG_ULONG(struct barvinok_options, max_index, 0, "index", 1, + "maximal index of simple cones in decomposition") +ISL_ARG_BOOL(struct barvinok_options, primal, 0, "primal", 0, NULL) +ISL_ARG_BOOL(struct barvinok_options, lookup_table, 0, "table", 0, NULL) +ISL_ARG_USER(struct barvinok_options, count_sample_infinite, &int_init_one, NULL) +ISL_ARG_USER(struct barvinok_options, try_Delaunay_triangulation, &int_init_zero, NULL) +ISL_ARG_CHOICE(struct barvinok_options, gbr_lp_solver, 0, "gbr", gbr, + DEFAULT_GBR, "lp solver to use for basis reduction") +ISL_ARG_CHOICE(struct barvinok_options, bound, 0, "bound", bound, + DEFAULT_BOUND, "algorithm to use for computing bounds") +ISL_ARG_USER(struct barvinok_options, bernstein_optimize, &int_init_zero, NULL) +ISL_ARG_FLAGS(struct barvinok_options, bernstein_recurse, 0, + "bernstein-recurse", bernstein_recurse, BV_BERNSTEIN_FACTORS, NULL) +ISL_ARG_CHOICE(struct barvinok_options, lp_solver, 0, "lp", lp, + DEFAULT_LP, "lp solver to use") +ISL_ARG_CHOICE(struct barvinok_options, summation, 0, "summation", summation, + BV_SUM_LAURENT, NULL) +ISL_ARG_CHOICE(struct barvinok_options, chambers, 0, "chamber-decomposition", + chambers, BV_CHAMBERS_POLYLIB, "tool to use for chamber decomposition") +ISL_ARG_CHOICE(struct barvinok_options, integer_hull, 0, "integer-hull", + hull, BV_HULL_GBR, NULL) +ISL_ARG_USER(struct barvinok_options, gbr_only_first, &int_init_zero, NULL) +ISL_ARG_BOOL(struct barvinok_options, print_stats, 0, "print-stats", 0, NULL) +ISL_ARG_BOOL(struct barvinok_options, verbose, 0, "verbose", 0, NULL) +ISL_ARG_VERSION(print_version) +ISL_ARG_END +}; + +ISL_ARG_DEF(barvinok_options, struct barvinok_options, barvinok_options_arg) diff --git a/polyhedron_integer_hull.c b/polyhedron_integer_hull.c index 69f540a..5540239 100644 --- a/polyhedron_integer_hull.c +++ b/polyhedron_integer_hull.c @@ -1,7 +1,5 @@ #include #include -#include "argp.h" -#include "progname.h" #include "hull.h" int main(int argc, char **argv) @@ -10,8 +8,7 @@ int main(int argc, char **argv) Polyhedron *C; struct barvinok_options *options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); M = Matrix_Read(); C = Constraints2Polyhedron(M, options->MaxRays); diff --git a/polyhedron_sample.c b/polyhedron_sample.c index 0678162..edf6c03 100644 --- a/polyhedron_sample.c +++ b/polyhedron_sample.c @@ -1,9 +1,6 @@ #include #include #include -#include "config.h" -#include "argp.h" -#include "progname.h" int main(int argc, char **argv) { @@ -12,8 +9,7 @@ int main(int argc, char **argv) Vector *sample; struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, bv_options); + argc = barvinok_options_parse(bv_options, argc, argv, ISL_ARG_ALL); M = Matrix_Read(); P = Constraints2Polyhedron(M, bv_options->MaxRays); diff --git a/polytope_lattice_width.c b/polytope_lattice_width.c index cff1d0e..ae4663c 100644 --- a/polytope_lattice_width.c +++ b/polytope_lattice_width.c @@ -3,73 +3,48 @@ #include #include #include "lattice_width.h" -#include "argp.h" -#include "progname.h" - -struct argp_option argp_options[] = { - { "direction", 'd', 0, 0, "print width directions" }, - { 0 } -}; struct arguments { - struct barvinok_options *options; + struct barvinok_options *barvinok; int direction; }; -error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct arguments *arguments = state->input; +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct arguments, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_BOOL(struct arguments, direction, 'd', "direction", 0, + "print width directions") +ISL_ARG_END +}; - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = arguments->options; - arguments->direction = 0; - break; - case 'd': - arguments->direction = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} +ISL_ARG_DEF(options, struct arguments, options_arg) int main(int argc, char **argv) { Polyhedron *P, *C; Matrix *M; const char **param_name; - struct arguments arguments; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct barvinok_options *options = barvinok_options_new_with_defaults(); + struct arguments *options = options_new_with_defaults(); struct width_direction_array *dirs; int i; - arguments.options = options; - - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &arguments); + argc = options_parse(options, argc, argv, ISL_ARG_ALL); M = Matrix_Read(); assert(M); - P = Constraints2Polyhedron(M, options->MaxRays); + P = Constraints2Polyhedron(M, options->barvinok->MaxRays); Matrix_Free(M); M = Matrix_Read(); assert(M); - C = Constraints2Polyhedron(M, options->MaxRays); + C = Constraints2Polyhedron(M, options->barvinok->MaxRays); Matrix_Free(M); param_name = Read_ParamNames(stdin, C->Dimension); - dirs = Polyhedron_Lattice_Width_Directions(P, C, options); + dirs = Polyhedron_Lattice_Width_Directions(P, C, options->barvinok); for (i = 0; i < dirs->n; ++i) { evalue *E; Print_Domain(stdout, dirs->wd[i].domain, param_name); - if (arguments.direction) + if (options->direction) Vector_Print(stdout, P_VALUE_FMT, dirs->wd[i].dir); E = affine2evalue(dirs->wd[i].width->p, dirs->wd[i].width->p[C->Dimension+1], @@ -82,7 +57,7 @@ int main(int argc, char **argv) Free_ParamNames(param_name, C->Dimension); Polyhedron_Free(P); Polyhedron_Free(C); - barvinok_options_free(options); + options_free(options); return 0; } diff --git a/polytope_minimize.c b/polytope_minimize.c index 1377654..5cdff8a 100644 --- a/polytope_minimize.c +++ b/polytope_minimize.c @@ -1,8 +1,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" #include "ilp.h" #include "polysign.h" @@ -16,8 +14,7 @@ int main(int argc, char **argv) enum lp_result res; Value one; - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); P = Polyhedron_Read(options->MaxRays); obj = Vector_Read(); diff --git a/polytope_scan.c b/polytope_scan.c index 1991fc8..e33eba0 100644 --- a/polytope_scan.c +++ b/polytope_scan.c @@ -5,41 +5,22 @@ #include #include #include -#include "argp.h" #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type)) -struct argp_option argp_options[] = { - { "direct", 'd', 0, 0, - "don't apply generalized basis reduction first" }, - { 0 } -}; - struct options { struct barvinok_options *barvinok; int direct; }; -error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct options *options = state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->barvinok; - options->direct = 0; - break; - case 'd': - options->direct = 1; - break; - case 'V': - printf(barvinok_version()); - exit(0); - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct options, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_BOOL(struct options, direct, 'd', "direct", 0, + "don't apply generalized basis reduction first") +ISL_ARG_END +}; + +ISL_ARG_DEF(options, struct options, options_arg) static void scan_poly(Polyhedron *S, int pos, Value *z, Matrix *T) { @@ -82,26 +63,17 @@ int main(int argc, char **argv) int i, j, ok; Matrix *basis, *T, *inv; int c, ind = 0; - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct options options; - - options.barvinok = bv_options; + struct options *options = options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + argc = options_parse(options, argc, argv, ISL_ARG_ALL); - A = Polyhedron_Read(bv_options->MaxRays); + A = Polyhedron_Read(options->barvinok->MaxRays); - if (options.direct) { + if (options->direct) { inv = Identity(A->Dimension+1); P = A; } else { - basis = Polyhedron_Reduced_Basis(A, bv_options); + basis = Polyhedron_Reduced_Basis(A, options->barvinok); T = Matrix_Alloc(A->Dimension+1, A->Dimension+1); inv = Matrix_Alloc(A->Dimension+1, A->Dimension+1); @@ -115,12 +87,12 @@ int main(int argc, char **argv) assert(ok); Matrix_Free(T); - P = Polyhedron_Preimage(A, inv, bv_options->MaxRays); + P = Polyhedron_Preimage(A, inv, options->barvinok->MaxRays); Polyhedron_Free(A); } U = Universe_Polyhedron(0); - S = Polyhedron_Scan(P, U, bv_options->MaxRays); + S = Polyhedron_Scan(P, U, options->barvinok->MaxRays); p = ALLOCN(Value, P->Dimension+2); for(i=0;i<=P->Dimension;i++) { @@ -139,6 +111,6 @@ int main(int argc, char **argv) Domain_Free(S); Polyhedron_Free(P); Polyhedron_Free(U); - barvinok_options_free(bv_options); + options_free(options); return 0; } diff --git a/polytope_volume.c b/polytope_volume.c index a8b1400..2c3de88 100644 --- a/polytope_volume.c +++ b/polytope_volume.c @@ -17,7 +17,7 @@ int main(int argc, char **argv) Matrix_Free(M); param_name = Read_ParamNames(stdin, C->Dimension); - bv_options->polynomial_approximation = BV_APPROX_SIGN_APPROX; + bv_options->approx->approximation = BV_APPROX_SIGN_APPROX; EP = Param_Polyhedron_Volume(A, C, bv_options); print_evalue(stdout, EP, (const char **)param_name); fprintf(stdout, "\n"); diff --git a/scale.c b/scale.c index 4716d5a..fcded17 100644 --- a/scale.c +++ b/scale.c @@ -507,9 +507,9 @@ static Polyhedron *flate(Polyhedron *P, Lattice *L, unsigned nparam, int inflate, struct barvinok_options *options) { - if (options->scale_flags & BV_APPROX_SCALE_NARROW2) + if (options->approx->scale_flags & BV_APPROX_SCALE_NARROW2) return flate_narrow2(P, L, nparam, inflate, options->MaxRays); - else if (options->scale_flags & BV_APPROX_SCALE_NARROW) + else if (options->approx->scale_flags & BV_APPROX_SCALE_NARROW) return flate_narrow(P, L, nparam, inflate, options->MaxRays); else return Polyhedron_Flate(P, nparam, inflate, options->MaxRays); @@ -519,7 +519,7 @@ static void Param_Polyhedron_Scale(Param_Polyhedron *PP, Polyhedron **P, Lattice **L, Value *det, struct barvinok_options *options) { - if (options->scale_flags & BV_APPROX_SCALE_FAST) + if (options->approx->scale_flags & BV_APPROX_SCALE_FAST) Param_Polyhedron_Scale_Integer_Fast(PP, P, L, det, options->MaxRays); else Param_Polyhedron_Scale_Integer_Slow(PP, P, L, det, options->MaxRays); @@ -530,17 +530,17 @@ static evalue *enumerate_flated(Polyhedron *P, Polyhedron *C, Lattice *L, { unsigned nparam = C->Dimension; evalue *eres; - int save_approximation = options->polynomial_approximation; + int save_approximation = options->approx->approximation; - if (options->polynomial_approximation == BV_APPROX_SIGN_UPPER) + if (options->approx->approximation == BV_APPROX_SIGN_UPPER) P = flate(P, L, nparam, 1, options); - if (options->polynomial_approximation == BV_APPROX_SIGN_LOWER) + if (options->approx->approximation == BV_APPROX_SIGN_LOWER) P = flate(P, L, nparam, 0, options); /* Don't deflate/inflate again (on this polytope) */ - options->polynomial_approximation = BV_APPROX_SIGN_NONE; + options->approx->approximation = BV_APPROX_SIGN_NONE; eres = barvinok_enumerate_with_options(P, C, options); - options->polynomial_approximation = save_approximation; + options->approx->approximation = save_approximation; Polyhedron_Free(P); return eres; @@ -551,7 +551,7 @@ static evalue *PP_enumerate_narrow_flated(Param_Polyhedron *PP, struct barvinok_options *options) { Polyhedron *Porig = P; - int scale_narrow2 = options->scale_flags & BV_APPROX_SCALE_NARROW2; + int scale_narrow2 = options->approx->scale_flags & BV_APPROX_SCALE_NARROW2; Lattice *L = NULL; Value det; evalue *eres; @@ -566,9 +566,9 @@ static evalue *PP_enumerate_narrow_flated(Param_Polyhedron *PP, P = Porig; } /* Don't scale again (on this polytope) */ - options->approximation_method = BV_APPROX_NONE; + options->approx->method = BV_APPROX_NONE; eres = enumerate_flated(P, C, L, options); - options->approximation_method = BV_APPROX_SCALE; + options->approx->method = BV_APPROX_SCALE; Matrix_Free(L); if (P != Porig) Polyhedron_Free(P); @@ -633,7 +633,7 @@ static evalue *enumerate_narrow_flated(Polyhedron *P, Polyhedron *C, PP = Polyhedron2Param_Polyhedron(P, C, options); POL_UNSET(Rat_MaxRays, POL_INTEGER); - if ((options->scale_flags & BV_APPROX_SCALE_CHAMBER) && PP->D->next) { + if ((options->approx->scale_flags & BV_APPROX_SCALE_CHAMBER) && PP->D->next) { int nd = -1; evalue *tmp, *eres = NULL; Polyhedron *TC = true_context(P, C, options->MaxRays); @@ -680,11 +680,11 @@ static evalue *enumerate_narrow_flated(Polyhedron *P, Polyhedron *C, evalue *scale_bound(Polyhedron *P, Polyhedron *C, struct barvinok_options *options) { - int scale_narrow = options->scale_flags & BV_APPROX_SCALE_NARROW; - int scale_narrow2 = options->scale_flags & BV_APPROX_SCALE_NARROW2; + int scale_narrow = options->approx->scale_flags & BV_APPROX_SCALE_NARROW; + int scale_narrow2 = options->approx->scale_flags & BV_APPROX_SCALE_NARROW2; - if (options->polynomial_approximation == BV_APPROX_SIGN_NONE || - options->polynomial_approximation == BV_APPROX_SIGN_APPROX) + if (options->approx->approximation == BV_APPROX_SIGN_NONE || + options->approx->approximation == BV_APPROX_SIGN_APPROX) return NULL; if (scale_narrow || scale_narrow2) @@ -701,7 +701,7 @@ evalue *scale(Param_Polyhedron *PP, Polyhedron *P, Polyhedron *C, evalue *eres = NULL; Value det; - if ((options->scale_flags & BV_APPROX_SCALE_CHAMBER) && PP->D->next) { + if ((options->approx->scale_flags & BV_APPROX_SCALE_CHAMBER) && PP->D->next) { int nd = -1; evalue *tmp; Polyhedron *TC = true_context(P, C, options->MaxRays); diff --git a/semigroup_holes.cc b/semigroup_holes.cc index 49944cc..2662363 100644 --- a/semigroup_holes.cc +++ b/semigroup_holes.cc @@ -2,8 +2,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" /* This program computes the generating function of the holes in a semigroup. * The input is a matrix with the generators m_i of the semigroup as columns. @@ -168,8 +166,7 @@ int main(int argc, char **argv) gen_fun *holes; barvinok_options *options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); generators = Matrix_Read(); assert(generators); diff --git a/test.c b/test.c index 816ee2e..0d8b2ff 100644 --- a/test.c +++ b/test.c @@ -5,8 +5,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" #include "config.h" #include "evalue_read.h" #include "lattice_width.h" @@ -42,8 +40,7 @@ int main(int argc, char **argv) char s[128]; struct barvinok_options *options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); nbPol = nbVec = nbMat = 0; fgets(s, 128, stdin); diff --git a/test_approx.c b/test_approx.c index 9106df5..4e37f09 100644 --- a/test_approx.c +++ b/test_approx.c @@ -2,8 +2,6 @@ #include #include #include "verify.h" -#include "argp.h" -#include "progname.h" #ifdef HAVE_SYS_TIMES_H @@ -82,34 +80,18 @@ struct { #define nr_methods (sizeof(methods)/sizeof(*methods)) -struct argp_option argp_options[] = { - { "quiet", 'q' }, - { 0 } -}; - struct options { int quiet; - struct verify_options verify; + struct verify_options *verify; }; -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct options *options = (struct options*) state->input; +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct options, verify, NULL, verify_options_arg, NULL) +ISL_ARG_BOOL(struct options, quiet, 'q', "quiet", 0, NULL) +ISL_ARG_END +}; - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->verify.barvinok; - state->child_inputs[1] = &options->verify; - options->quiet = 0; - break; - case 'q': - options->quiet = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} +ISL_ARG_DEF(options, struct options, options_arg) struct result_data { Value n; @@ -333,12 +315,12 @@ void handle(FILE *in, struct result_data *result, struct verify_options *options for (i = 0; i < nr_methods; ++i) { struct tms st_cpu; struct tms en_cpu; - options->barvinok->polynomial_approximation = methods[i].sign; - options->barvinok->approximation_method = methods[i].method; + options->barvinok->approx->approximation = methods[i].sign; + options->barvinok->approx->method = methods[i].method; if (methods[i].method == BV_APPROX_SCALE) - options->barvinok->scale_flags = methods[i].flags; + options->barvinok->approx->scale_flags = methods[i].flags; else if (methods[i].method == BV_APPROX_VOLUME) - options->barvinok->volume_triangulate = methods[i].flags; + options->barvinok->approx->volume_triangulate = methods[i].flags; times(&st_cpu); EP[i] = barvinok_enumerate_with_options(A, C, options->barvinok); @@ -361,26 +343,17 @@ void handle(FILE *in, struct result_data *result, struct verify_options *options int main(int argc, char **argv) { - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); char path[PATH_MAX+1]; struct result_data all_result; int n = 0; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", BV_GRP_LAST+1 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct options options; - - options.verify.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); - - if (options.verify.M == INT_MIN) - options.verify.M = 100; - if (options.verify.m == INT_MAX) - options.verify.m = -100; + struct options *options = options_new_with_defaults(); + + argc = options_parse(options, argc, argv, ISL_ARG_ALL); + + if (options->verify->M == INT_MIN) + options->verify->M = 100; + if (options->verify->m == INT_MAX) + options->verify->m = -100; result_data_init(&all_result); @@ -395,10 +368,10 @@ int main(int argc, char **argv) *strchr(path, '\n') = '\0'; in = fopen(path, "r"); assert(in); - handle(in, &result, &options.verify); + handle(in, &result, options->verify); fclose(in); - if (!options.quiet) + if (!options->quiet) result_data_print(&result, 1); value_addto(all_result.n, all_result.n, result.n); @@ -410,7 +383,7 @@ int main(int argc, char **argv) result_data_clear(&result); - if (!options.quiet) { + if (!options->quiet) { fprintf(stderr, "average\n"); result_data_print(&all_result, n); } @@ -418,7 +391,7 @@ int main(int argc, char **argv) result_data_clear(&all_result); - barvinok_options_free(bv_options); + options_free(options); return 0; } diff --git a/test_bound.c b/test_bound.c index 78ff7c5..bcc005d 100644 --- a/test_bound.c +++ b/test_bound.c @@ -5,8 +5,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" #include "evalue_read.h" #include "verify.h" @@ -45,34 +43,18 @@ static struct { #define nr_methods (sizeof(methods)/sizeof(*methods)) -struct argp_option argp_options[] = { - { "quiet", 'q' }, - { 0 } -}; - struct options { - struct verify_options verify; + struct verify_options *verify; int quiet; }; -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct options *options = (struct options*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->verify.barvinok; - state->child_inputs[1] = &options->verify; - options->quiet = 0; - break; - case 'q': - options->quiet = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} +struct isl_arg options_arg[] = { +ISL_ARG_CHILD(struct options, verify, NULL, verify_options_arg, NULL) +ISL_ARG_BOOL(struct options, quiet, 'q', "quiet", 0, NULL) +ISL_ARG_END +}; + +ISL_ARG_DEF(options, struct options, options_arg) struct result_data { isl_int n; @@ -339,26 +321,17 @@ void handle(FILE *in, struct result_data *result, struct verify_options *options int main(int argc, char **argv) { - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); char path[PATH_MAX+1]; struct result_data all_result; int n = 0; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { &verify_argp, 0, "verification", BV_GRP_LAST+1 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct options options; - - options.verify.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); - - if (options.verify.M == INT_MIN) - options.verify.M = 100; - if (options.verify.m == INT_MAX) - options.verify.m = -100; + struct options *options = options_new_with_defaults(); + + argc = options_parse(options, argc, argv, ISL_ARG_ALL); + + if (options->verify->M == INT_MIN) + options->verify->M = 100; + if (options->verify->m == INT_MAX) + options->verify->m = -100; result_data_init(&all_result); @@ -373,10 +346,10 @@ int main(int argc, char **argv) *strchr(path, '\n') = '\0'; in = fopen(path, "r"); assert(in); - handle(in, &result, &options.verify); + handle(in, &result, options->verify); fclose(in); - if (!options.quiet) + if (!options->quiet) result_data_print(&result, 1); isl_int_add(all_result.n, all_result.n, result.n); @@ -388,7 +361,7 @@ int main(int argc, char **argv) result_data_clear(&result); - if (!options.quiet) { + if (!options->quiet) { fprintf(stderr, "average\n"); result_data_print(&all_result, n); } @@ -396,7 +369,7 @@ int main(int argc, char **argv) result_data_clear(&all_result); - barvinok_options_free(bv_options); + options_free(options); return 0; } diff --git a/vector_partition_chambers.c b/vector_partition_chambers.c index f55bcd9..8b9957b 100644 --- a/vector_partition_chambers.c +++ b/vector_partition_chambers.c @@ -1,6 +1,4 @@ #include -#include "argp.h" -#include "progname.h" #include "param_util.h" /* This program computes the full-dimensional chambers of the vector @@ -78,8 +76,7 @@ int main(int argc, char **argv) Param_Domain *PD; struct barvinok_options *options = barvinok_options_new_with_defaults(); - set_program_name(argv[0]); - argp_parse(&barvinok_argp, argc, argv, 0, 0, options); + argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); A = Matrix_Read(); assert(A); diff --git a/verif_ehrhart.c b/verif_ehrhart.c index 8b3e84c..792c360 100644 --- a/verif_ehrhart.c +++ b/verif_ehrhart.c @@ -36,7 +36,7 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, int k; int ok; Value c, tmp, one; - int pa = options->barvinok->polynomial_approximation; + int pa = options->barvinok->approx->approximation; struct check_poly_EP_data* EP_data = (struct check_poly_EP_data*) data; const evalue *EP = EP_data->EP; int exist = EP_data->exist; diff --git a/verify.c b/verify.c index 467db6b..1080259 100644 --- a/verify.c +++ b/verify.c @@ -21,65 +21,42 @@ /* if dimension >= VBIDDIM, use VSRANGE */ #define VBIGDIM 8 -static struct argp_option argp_options[] = { - { "verify", 'T', 0, 0 }, - { "exact", 'E', 0, 0 }, - { "print-all", 'A', 0, 0 }, - { "continue-on-error", 'C', 0, 0 }, - { "min", 'm', "int", 0 }, - { "max", 'M', "int", 0 }, - { "range", 'r', "int", 0 }, - { 0 } -}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) +static int set_m(void *opt, long val) { - struct verify_options *options = state->input; - - switch (key) { - case ARGP_KEY_INIT: - options->verify = 0; - options->exact = 0; - options->print_all = 0; - options->continue_on_error = 0; - options->m = INT_MAX; - options->M = INT_MIN; - options->r = -1; - break; - case ARGP_KEY_FINI: - break; - case 'T': + struct verify_options *options = (struct verify_options *)opt; + options->m = val; options->verify = 1; - break; - case 'E': - options->exact = 1; - break; - case 'A': - options->print_all = 1; - break; - case 'C': - options->continue_on_error = 1; - break; - case 'm': - options->m = atoi(arg); - options->verify = 1; - break; - case 'M': - options->M = atoi(arg); +} + +static int set_M(void *opt, long val) +{ + struct verify_options *options = (struct verify_options *)opt; + options->M = val; options->verify = 1; - break; - case 'r': - options->r = atoi(arg); - options->M = atoi(arg); - options->m = -options->M; +} + +static int set_r(void *opt, long val) +{ + struct verify_options *options = (struct verify_options *)opt; + options->r = val; + options->m = -val; + options->M = val; options->verify = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; } +struct isl_arg verify_options_arg[] = { +ISL_ARG_CHILD(struct verify_options, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_BOOL(struct verify_options, verify, 'T', "verify", 0, NULL) +ISL_ARG_BOOL(struct verify_options, exact, 'E', "exact", 0, NULL) +ISL_ARG_BOOL(struct verify_options, print_all, 'A', "print-all", 0, NULL) +ISL_ARG_BOOL(struct verify_options, continue_on_error, 'C', + "continue-on-error", 0, NULL) +ISL_ARG_USER_LONG(struct verify_options, m, 'm', "min", set_m, INT_MAX, NULL) +ISL_ARG_USER_LONG(struct verify_options, M, 'M', "max", set_M, INT_MIN, NULL) +ISL_ARG_USER_LONG(struct verify_options, r, 'r', "range", set_r, -1, NULL) +ISL_ARG_END +}; + void verify_options_set_range(struct verify_options *options, int dim) { int r; @@ -106,10 +83,6 @@ void verify_options_set_range(struct verify_options *options, int dim) } } -struct argp verify_argp = { - argp_options, parse_opt, 0, 0 -}; - static Polyhedron *project_on(Polyhedron *P, int i) { unsigned dim = P->Dimension; diff --git a/verify.h b/verify.h index 996feaf..aeae44e 100644 --- a/verify.h +++ b/verify.h @@ -1,8 +1,9 @@ #ifndef VERIFY_H #define VERIFY_H +#include +#include #include -#include "argp.h" #if defined(__cplusplus) extern "C" { @@ -13,9 +14,9 @@ struct verify_options { int exact; int print_all; int continue_on_error; - int m; - int M; - int r; + long m; + long M; + long r; /* "generated" options */ int st; @@ -23,7 +24,8 @@ struct verify_options { struct barvinok_options *barvinok; }; -extern struct argp verify_argp; +ISL_ARG_DECL(verify_options, struct verify_options, verify_options_arg) + void verify_options_set_range(struct verify_options *options, int dim); Polyhedron *check_poly_context_scan(Polyhedron *P, Polyhedron **C, diff --git a/verify_lexsmaller.c b/verify_lexsmaller.c index 59c92a1..3f15967 100644 --- a/verify_lexsmaller.c +++ b/verify_lexsmaller.c @@ -1,15 +1,6 @@ #include #include #include -#include "argp.h" -#include "progname.h" - -struct argp_option argp_options[] = { - { "continue", 'k' }, - { "max", 'M' }, - { "live", 'l' }, - { 0 } -}; struct arguments { int live; @@ -19,31 +10,15 @@ struct arguments { struct barvinok_options *barvinok; }; -static error_t parse_opt(int key, char *arg, struct argp_state *state) -{ - struct arguments *options = (struct arguments*) state->input; - - switch (key) { - case ARGP_KEY_INIT: - state->child_inputs[0] = options->barvinok; - options->keep_going = 0; - options->print_max = 0; - options->live = 0; - break; - case 'k': - options->keep_going = 1; - break; - case 'M': - options->print_max = 1; - break; - case 'l': - options->live = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} +struct isl_arg arguments_arg[] = { +ISL_ARG_CHILD(struct arguments, barvinok, NULL, barvinok_options_arg, NULL) +ISL_ARG_BOOL(struct arguments, live, 'l', "live", 0, NULL) +ISL_ARG_BOOL(struct arguments, print_max, 'M', "max", 0, NULL) +ISL_ARG_BOOL(struct arguments, keep_going, 'k', "continue", 0, NULL) +ISL_ARG_END +}; + +ISL_ARG_DEF(arguments, struct arguments, arguments_arg) #define LS_OK 1 #define LS_P 2 /* continue searching P */ @@ -203,24 +178,16 @@ int main(int argc,char *argv[]) Value count; char s[128]; unsigned dim; - struct arguments options; - static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, - { 0 } - }; - static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; - struct barvinok_options *bv_options = barvinok_options_new_with_defaults(); - - options.barvinok = bv_options; - set_program_name(argv[0]); - argp_parse(&argp, argc, argv, 0, 0, &options); + struct arguments *options = arguments_new_with_defaults(); + + argc = arguments_parse(options, argc, argv, ISL_ARG_ALL); M = Matrix_Read(); - P = Constraints2Polyhedron(M, bv_options->MaxRays); + P = Constraints2Polyhedron(M, options->barvinok->MaxRays); assert(P != NULL); Matrix_Free(M); M = Matrix_Read(); - D = Constraints2Polyhedron(M, bv_options->MaxRays); + D = Constraints2Polyhedron(M, options->barvinok->MaxRays); assert(D != NULL); Matrix_Free(M); @@ -229,18 +196,18 @@ int main(int argc,char *argv[]) fgets(s, 128, stdin); M = Matrix_Read(); - C = Constraints2Polyhedron(M, bv_options->MaxRays); + C = Constraints2Polyhedron(M, options->barvinok->MaxRays); assert(C != NULL); Matrix_Free(M); nb_parms = D->Dimension; param_name = Read_ParamNames(stdin, nb_parms); - EP = barvinok_lexsmaller_ev(P, D, dim, C, bv_options->MaxRays); - if (options.live) { + EP = barvinok_lexsmaller_ev(P, D, dim, C, options->barvinok->MaxRays); + if (options->live) { evalue mone; - evalue *EC = barvinok_lexsmaller_ev(D, D, dim, C, bv_options->MaxRays); - if (options.barvinok->verbose >= 2) { + evalue *EC = barvinok_lexsmaller_ev(D, D, dim, C, options->barvinok->MaxRays); + if (options->barvinok->verbose >= 2) { puts("EP"); print_evalue(stdout, EP, (const char **)param_name); puts("EC"); @@ -254,7 +221,7 @@ int main(int argc,char *argv[]) evalue_free(EC); reduce_evalue(EP); } - if (bv_options->verbose >= 1) { + if (options->barvinok->verbose >= 1) { puts("Enumeration"); print_evalue(stdout, EP, (const char **)param_name); } @@ -263,8 +230,8 @@ int main(int argc,char *argv[]) assert(C->Dimension == 0); /* for now */ /* S = scanning list of polyhedra */ - SP = Polyhedron_Scan(P, C, bv_options->MaxRays); - SD = Polyhedron_Scan(D, C, bv_options->MaxRays); + SP = Polyhedron_Scan(P, C, options->barvinok->MaxRays); + SD = Polyhedron_Scan(D, C, options->barvinok->MaxRays); zP = Vector_Alloc(1+P->Dimension+1); value_set_si(zP->p[1+P->Dimension], 1); @@ -272,17 +239,17 @@ int main(int argc,char *argv[]) value_set_si(zD->p[1+D->Dimension], 1); zE = Vector_Alloc(dim+C->Dimension); - if (options.print_max) - value_init(options.max); + if (options->print_max) + value_init(options->max); value_init(count); check_lexsmaller(SP, SD, en, 0, dim, zP->p, zD->p, zE->p, &count, &options); value_clear(count); - if (options.print_max) { + if (options->print_max) { printf("max = "); - value_print(stdout, VALUE_FMT, options.max); + value_print(stdout, VALUE_FMT, options->max); printf("\n"); - value_clear(options.max); + value_clear(options->max); } Enumeration_Free(en); @@ -295,6 +262,6 @@ int main(int argc,char *argv[]) Vector_Free(zP); Vector_Free(zD); Vector_Free(zE); - barvinok_options_free(bv_options); + arguments_free(options); return 0; } diff --git a/volume.c b/volume.c index c866b59..4056b31 100644 --- a/volume.c +++ b/volume.c @@ -291,13 +291,13 @@ static evalue *volume_triangulate(Param_Polyhedron *PP, Param_Domain *D, value_init(mone.d); evalue_set_si(&mone, -1, 1); - if (options->volume_triangulate == BV_VOL_BARYCENTER) + if (options->approx->volume_triangulate == BV_VOL_BARYCENTER) center = barycenter(PP, D); else center = triangulation_vertex(PP, D, F); for (j = 0; j < dim; ++j) matrix[row][j] = vertex2evalue(center->p[j], center->NbColumns - 2); - if (options->volume_triangulate == BV_VOL_BARYCENTER) + if (options->approx->volume_triangulate == BV_VOL_BARYCENTER) Matrix_Free(center); else v = Vector_Alloc(1+nparam+1); @@ -317,7 +317,7 @@ static evalue *volume_triangulate(Param_Polyhedron *PP, Param_Domain *D, Param_Domain *FD; if (First_Non_Zero(F->Constraint[j]+1, dim) == -1) continue; - if (options->volume_triangulate != BV_VOL_BARYCENTER) { + if (options->approx->volume_triangulate != BV_VOL_BARYCENTER) { Param_Inner_Product(F->Constraint[j], center, v->p); if (First_Non_Zero(v->p+1, nparam+1) == -1) continue; @@ -336,7 +336,7 @@ static evalue *volume_triangulate(Param_Polyhedron *PP, Param_Domain *D, Param_Domain_Free(FD); } - if (options->volume_triangulate != BV_VOL_BARYCENTER) + if (options->approx->volume_triangulate != BV_VOL_BARYCENTER) Vector_Free(v); for (j = 0; j < dim; ++j) @@ -512,7 +512,7 @@ static evalue *volume_in_domain(Param_Polyhedron *PP, Param_Domain *D, END_FORALL_PVertex_in_ParamPolyhedron; if (nbV > (dim-row) + 1) { - if (options->volume_triangulate == BV_VOL_LIFT) + if (options->approx->volume_triangulate == BV_VOL_LIFT) vol = volume_triangulate_lift(PP, D, dim, matrix, point, row, options); else @@ -542,20 +542,20 @@ evalue* Param_Polyhedron_Volume(Polyhedron *P, Polyhedron* C, Param_Domain *D; Polyhedron *TC; - if (options->polynomial_approximation == BV_APPROX_SIGN_NONE) + if (options->approx->approximation == BV_APPROX_SIGN_NONE) return NULL; - if (options->polynomial_approximation != BV_APPROX_SIGN_APPROX) { - int pa = options->polynomial_approximation; + if (options->approx->approximation != BV_APPROX_SIGN_APPROX) { + int pa = options->approx->approximation; assert(pa == BV_APPROX_SIGN_UPPER || pa == BV_APPROX_SIGN_LOWER); P = Polyhedron_Flate(P, nparam, pa == BV_APPROX_SIGN_UPPER, options->MaxRays); /* Don't deflate/inflate again (on this polytope) */ - options->polynomial_approximation = BV_APPROX_SIGN_APPROX; + options->approx->approximation = BV_APPROX_SIGN_APPROX; vol = barvinok_enumerate_with_options(P, C, options); - options->polynomial_approximation = pa; + options->approx->approximation = pa; Polyhedron_Free(P); return vol; -- 2.11.4.GIT