diff options
Diffstat (limited to 'columns')
-rw-r--r-- | columns/Makefile.am | 70 | ||||
-rw-r--r-- | columns/Makefile.in | 739 | ||||
-rw-r--r-- | columns/columns.c | 769 | ||||
-rw-r--r-- | columns/opts.c | 1055 | ||||
-rw-r--r-- | columns/opts.def | 357 | ||||
-rw-r--r-- | columns/opts.h | 239 |
6 files changed, 3229 insertions, 0 deletions
diff --git a/columns/Makefile.am b/columns/Makefile.am new file mode 100644 index 0000000..e18853e --- /dev/null +++ b/columns/Makefile.am @@ -0,0 +1,70 @@ +## -*- Mode: Makefile -*- +## +## Makefile.am -- process this file with automake to produce Makefile.in +## +## Time-stamp: "2011-03-06 14:06:37 bkorb" +## Copyright (c) 1992-2012 by Bruce Korb +## +## This file is part of AutoGen. +## +## AutoGen is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by the +## Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## AutoGen is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License along +## with this program. If not, see <http://www.gnu.org/licenses/>. + +bin_PROGRAMS = columns +csrc = opts.h columns.c opts.c +nodist_columns_SOURCES = cols.c + +LO_LIB = $(top_builddir)/autoopts/libopts.la +columns_LDADD = $(LO_LIB) $(LIBGUILE_LIBS) + +BUILT_SOURCES = columns.menu columns.texi columns.1 +EXTRA_DIST = opts.def $(csrc) + +RUNAG = $(AGexe) -L$(top_srcdir)/autoopts/tpl \ + -L$(top_builddir)/autoopts/tpl -MF$@ +man_MANS = columns.1 + +INCLUDES = @INCLIST@ + +CONFIG_CLEAN_FILES = $(BUILT_SOURCES) stamp-* +MAINTAINERCLEANFILES = $(CONFIG_CLEAN_FILES) +DISTCLEANFILES = cols.c + +gen : $(BUILT_SOURCES) + +all : gen + +## opts.h cannot be built until columns is built, so no rules for it. + +columns.menu columns.texi : stamp-agtexi +columns.1 : stamp-agman + +cols.c : Makefile + exec > $@ ; \ + echo '#undef PKGDATADIR' ; \ + echo '#define PKGDATADIR "$(pkgdatadir)"' ; \ + echo ; echo '#define DEFINING 1' ; \ + echo '#include "autoopts/project.h"' ; \ + for f in $(csrc) ; do echo "#include \"$$f\"" ; done + +stamp-agtexi : opts.def columns$(EXEEXT) + top_builddir=$(top_builddir) \ + $(RUNAG) -Tagtexi-cmd.tpl -DLEVEL=section $(srcdir)/opts.def + +stamp-agman : opts.def columns$(EXEEXT) + top_builddir=$(top_builddir) \ + $(RUNAG) -Tagman-cmd.tpl $(srcdir)/opts.def + +.NOTPARALLEL: + +# Makefile.am ends here diff --git a/columns/Makefile.in b/columns/Makefile.in new file mode 100644 index 0000000..0ff7c31 --- /dev/null +++ b/columns/Makefile.in @@ -0,0 +1,739 @@ +# Makefile.in generated by automake 1.12.2 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2012 Free Software Foundation, Inc. + +# This Makefile.in 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 program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__make_dryrun = \ + { \ + am__dry=no; \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ + esac; \ + test $$am__dry = yes; \ + } +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +bin_PROGRAMS = columns$(EXEEXT) +subdir = columns +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(top_srcdir)/config/depcomp +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/config/ag_macros.m4 \ + $(top_srcdir)/config/extensions.m4 \ + $(top_srcdir)/config/libopts.m4 \ + $(top_srcdir)/config/libtool.m4 \ + $(top_srcdir)/config/ltoptions.m4 \ + $(top_srcdir)/config/ltsugar.m4 \ + $(top_srcdir)/config/ltversion.m4 \ + $(top_srcdir)/config/lt~obsolete.m4 \ + $(top_srcdir)/config/onceonly.m4 \ + $(top_srcdir)/config/snprintfv.m4 \ + $(top_srcdir)/config/unlocked-io.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" +PROGRAMS = $(bin_PROGRAMS) +nodist_columns_OBJECTS = cols.$(OBJEXT) +columns_OBJECTS = $(nodist_columns_OBJECTS) +am__DEPENDENCIES_1 = +columns_DEPENDENCIES = $(LO_LIB) $(am__DEPENDENCIES_1) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/config/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(nodist_columns_SOURCES) +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +man1dir = $(mandir)/man1 +NROFF = nroff +MANS = $(man_MANS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AGEN5_TESTS = @AGEN5_TESTS@ +AG_GUILE = @AG_GUILE@ +AG_LDFLAGS = @AG_LDFLAGS@ +AG_MAJOR_VERSION = @AG_MAJOR_VERSION@ +AG_MINOR_VERSION = @AG_MINOR_VERSION@ +AG_TIMEOUT = @AG_TIMEOUT@ +AG_VERSION = @AG_VERSION@ +AG_XML2 = @AG_XML2@ +AGexe = @AGexe@ +AGnam = @AGnam@ +AMTAR = @AMTAR@ +AO_AGE = @AO_AGE@ +AO_CURRENT = @AO_CURRENT@ +AO_REVISION = @AO_REVISION@ +AO_TEMPLATE_VERSION = @AO_TEMPLATE_VERSION@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLexe = @CLexe@ +CLnam = @CLnam@ +CONFIG_SHELL = @CONFIG_SHELL@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEBUG_ENABLED = @DEBUG_ENABLED@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +DYNAMIC_AG = @DYNAMIC_AG@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ENABLE_STATIC = @ENABLE_STATIC@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GDexe = @GDexe@ +GDnam = @GDnam@ +GO_AGE = @GO_AGE@ +GO_CURRENT = @GO_CURRENT@ +GO_REVISION = @GO_REVISION@ +GREP = @GREP@ +GUILE_VERSION = @GUILE_VERSION@ +INCLIST = @INCLIST@ +INCSNPRINTFV = @INCSNPRINTFV@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBGUILE_CFLAGS = @LIBGUILE_CFLAGS@ +LIBGUILE_LIBS = @LIBGUILE_LIBS@ +LIBGUILE_PATH = @LIBGUILE_PATH@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSNPRINTFV = @LIBSNPRINTFV@ +LIBTOOL = @LIBTOOL@ +LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ +LIBXML2_LIBS = @LIBXML2_LIBS@ +LIBXML2_PATH = @LIBXML2_PATH@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +M4_SRC = @M4_SRC@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OPTS_TESTDIR = @OPTS_TESTDIR@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +POSIX_SHELL = @POSIX_SHELL@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TEXI2HTML = @TEXI2HTML@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_aux_dir = @ac_aux_dir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +csrc = opts.h columns.c opts.c +nodist_columns_SOURCES = cols.c +LO_LIB = $(top_builddir)/autoopts/libopts.la +columns_LDADD = $(LO_LIB) $(LIBGUILE_LIBS) +BUILT_SOURCES = columns.menu columns.texi columns.1 +EXTRA_DIST = opts.def $(csrc) +RUNAG = $(AGexe) -L$(top_srcdir)/autoopts/tpl \ + -L$(top_builddir)/autoopts/tpl -MF$@ + +man_MANS = columns.1 +INCLUDES = @INCLIST@ +CONFIG_CLEAN_FILES = $(BUILT_SOURCES) stamp-* +MAINTAINERCLEANFILES = $(CONFIG_CLEAN_FILES) +DISTCLEANFILES = cols.c +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu columns/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu columns/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +columns$(EXEEXT): $(columns_OBJECTS) $(columns_DEPENDENCIES) $(EXTRA_columns_DEPENDENCIES) + @rm -f columns$(EXEEXT) + $(LINK) $(columns_OBJECTS) $(columns_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cols.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-man1: $(man_MANS) + @$(NORMAL_INSTALL) + @list1=''; \ + list2='$(man_MANS)'; \ + test -n "$(man1dir)" \ + && test -n "`echo $$list1$$list2`" \ + || exit 0; \ + echo " $(MKDIR_P) '$(DESTDIR)$(man1dir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(man1dir)" || exit 1; \ + { for i in $$list1; do echo "$$i"; done; \ + if test -n "$$list2"; then \ + for i in $$list2; do echo "$$i"; done \ + | sed -n '/\.1[a-z]*$$/p'; \ + fi; \ + } | while read p; do \ + if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; echo "$$p"; \ + done | \ + sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \ + -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ + sed 'N;N;s,\n, ,g' | { \ + list=; while read file base inst; do \ + if test "$$base" = "$$inst"; then list="$$list $$file"; else \ + echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \ + $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \ + fi; \ + done; \ + for i in $$list; do echo "$$i"; done | $(am__base_list) | \ + while read files; do \ + test -z "$$files" || { \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \ + done; } + +uninstall-man1: + @$(NORMAL_UNINSTALL) + @list=''; test -n "$(man1dir)" || exit 0; \ + files=`{ for i in $$list; do echo "$$i"; done; \ + l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ + sed -n '/\.1[a-z]*$$/p'; \ + } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \ + -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ + dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir) + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +cscopelist: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @list='$(MANS)'; if test -n "$$list"; then \ + list=`for p in $$list; do \ + if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; else :; fi; done`; \ + if test -n "$$list" && \ + grep 'ab help2man is required to generate this page' $$list >/dev/null; then \ + echo "error: found man pages containing the 'missing help2man' replacement text:" >&2; \ + grep -l 'ab help2man is required to generate this page' $$list | sed 's/^/ /' >&2; \ + echo " to fix them, install help2man, remove and regenerate the man pages;" >&2; \ + echo " typically 'make maintainer-clean' will remove them" >&2; \ + exit 1; \ + else :; fi; \ + else :; fi + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(PROGRAMS) $(MANS) +installdirs: + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-man + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: install-man1 + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS uninstall-man + +uninstall-man: uninstall-man1 + +.MAKE: all check install install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool cscopelist ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-binPROGRAMS install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-man1 install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-binPROGRAMS \ + uninstall-man uninstall-man1 + + +gen : $(BUILT_SOURCES) + +all : gen + +columns.menu columns.texi : stamp-agtexi +columns.1 : stamp-agman + +cols.c : Makefile + exec > $@ ; \ + echo '#undef PKGDATADIR' ; \ + echo '#define PKGDATADIR "$(pkgdatadir)"' ; \ + echo ; echo '#define DEFINING 1' ; \ + echo '#include "autoopts/project.h"' ; \ + for f in $(csrc) ; do echo "#include \"$$f\"" ; done + +stamp-agtexi : opts.def columns$(EXEEXT) + top_builddir=$(top_builddir) \ + $(RUNAG) -Tagtexi-cmd.tpl -DLEVEL=section $(srcdir)/opts.def + +stamp-agman : opts.def columns$(EXEEXT) + top_builddir=$(top_builddir) \ + $(RUNAG) -Tagman-cmd.tpl $(srcdir)/opts.def + +.NOTPARALLEL: + +# Makefile.am ends here + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/columns/columns.c b/columns/columns.c new file mode 100644 index 0000000..7819c00 --- /dev/null +++ b/columns/columns.c @@ -0,0 +1,769 @@ + +/* + * \file columns.c + * + * Time-stamp: "2012-03-31 13:37:39 bkorb" + * + * Columns Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * Columns is free software. + * This file is part of AutoGen. + * + * AutoGen copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoGen is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AutoGen is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef NUL +# define NUL '\0' +#endif + +struct print_list { + char** papz; + int index; +}; + +typedef struct print_list tPrintList, *tpPrintList; + +int maxEntryWidth = 0; +int fillColumnCt = 0; + +#define LINE_LIMIT 4096 +char zLine[ LINE_LIMIT ]; +char zFmtLine[ LINE_LIMIT ]; + +char** papzLines = (char**)NULL; +char const * pzLinePfx = ""; +char const * pzFirstPfx = NULL; +size_t allocCt = 0; +size_t usedCt = 0; +size_t columnCt = 0; +size_t columnSz = 0; +size_t indentSize = 0; + +/* = = = START-STATIC-FORWARD = = = */ +static void +fserr_die(char const * fmt, ...); + +static inline void * +malloc_or_die(size_t sz); + +static char const * +construct_first_pfx(char const * f_indent); + +static uint32_t +pad_indentation(char const * pzIndentArg, char const ** pfx); + +static void +readLines(void); + +static void +writeColumns(void); + +static void +trim_last_separation(void); + +static void +writeRows(void); + +static int +emitWord(char const * word, size_t len, int col); + +static void +writeFill(void); + +static int +compProc(const void * p1, const void * p2); +/* = = = END-STATIC-FORWARD = = = */ + +int +main(int argc, char ** argv) +{ + (void)optionProcess( &columnsOptions, argc, argv ); + + if (HAVE_OPT( INDENT )) { + indentSize = pad_indentation( OPT_ARG(INDENT), &pzLinePfx); + OPT_VALUE_WIDTH -= indentSize; + + pzFirstPfx = HAVE_OPT(FIRST_INDENT) + ? construct_first_pfx( OPT_ARG(FIRST_INDENT)) + : pzLinePfx; + } + + if (HAVE_OPT( LINE_SEPARATION )) + OPT_VALUE_WIDTH -= strlen( OPT_ARG( LINE_SEPARATION )); + + if (HAVE_OPT( COL_WIDTH )) + columnSz = OPT_VALUE_COL_WIDTH; + + if (HAVE_OPT( COLUMNS )) + columnCt = OPT_VALUE_COLUMNS; + + if (OPT_VALUE_WIDTH <= 16) + OPT_VALUE_WIDTH = 16; + + readLines(); + + if (HAVE_OPT( SORT )) + qsort( (void*)papzLines, usedCt, sizeof( char* ), &compProc ); + + if (HAVE_OPT( BY_COLUMNS )) + writeColumns(); + else if (HAVE_OPT(FILL)) + writeFill(); + else writeRows(); + + return EXIT_SUCCESS; +} + + +static void +fserr_die(char const * fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(stderr, "%s fserr %d (%s): ", columnsOptions.pzProgName, + errno, strerror(errno)); + vfprintf(stderr, fmt, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + +static inline void * +malloc_or_die(size_t sz) +{ + void * res = malloc(sz); + if (res == NULL) { + errno = ENOMEM; + fserr_die("could not allocate %d bytes", sz); + } + return res; +} + +static char const * +construct_first_pfx(char const * f_indent) +{ + static char const pad_fmt[] = "%%-%ds"; + // 24 > log10(0xFFFFFFFFFFFFFFFFULL) + char pfx_buf[24 + sizeof(pad_fmt)]; + size_t firstSize = pad_indentation(f_indent, &pzFirstPfx); + size_t len; + char * res; + + /* + * If this first line exceeds the indentation size, then we + * need to append a newline and any indentation. + */ + if (firstSize > indentSize) { + size_t sep_len = HAVE_OPT(LINE_SEPARATION) + ? strlen( OPT_ARG(LINE_SEPARATION)) : 0; + len = firstSize + sep_len + indentSize + 3; + sprintf(pfx_buf, pad_fmt, (int)firstSize); + } else { + len = indentSize + 3; + sprintf(pfx_buf, pad_fmt, (int)indentSize); + } + + res = malloc_or_die(len); + snprintf(res, len, pfx_buf, pzFirstPfx); + pzFirstPfx = res; + + if (firstSize > indentSize) { + char * p = res + firstSize; + + if (HAVE_OPT( LINE_SEPARATION )) { + len = strlen(OPT_ARG(LINE_SEPARATION)); + memcpy(p, OPT_ARG(LINE_SEPARATION), len); + p += len; + } + + sprintf(p, "\n%s", pzLinePfx); + } + + return res; +} + +static uint32_t +pad_indentation(char const * pzIndentArg, char const ** pfx) +{ + char * pz; + unsigned int cct; + + errno = 0; + cct = (unsigned int)strtoul(pzIndentArg, &pz, 0); + + /* + * IF the indent argument is a number + */ + if ((*pz == NUL) && (errno == 0) && (cct < OPT_VALUE_WIDTH)) { + char * p; + + /* + * Allocate a string to hold the line prefix + */ + *pfx = p = malloc_or_die( (size_t)cct + 1 ); + + /* + * Set it to a NUL terminated string of spaces + */ + if (cct > 0) + memset(p, ' ', (size_t)cct); + p[cct] = NUL; + + } else { + /* + * Otherwise, set the line prefix to whatever the string is. + * It will not be the empty string because that is handled + * as an indent count of zero and is ignored. + */ + char const * p = pzIndentArg; + *pfx = pzIndentArg; + cct = 0; + + for (;;) { + /* + * Compute the length of the last line of the prefix. + */ + switch (*p++) { + case NUL: + goto colsCounted; + + case '\t': + cct += OPT_VALUE_TAB_WIDTH; + cct -= (cct % OPT_VALUE_TAB_WIDTH); + break; + + case '\n': + case '\f': + case '\r': + cct = 0; + break; + + default: + cct++; + break; + + case '\a': + break; + } + } colsCounted:; + } + + return cct; +} + + +static void +readLines(void) +{ + int sepLen; + + if (HAVE_OPT(SEPARATION)) + sepLen = strlen(OPT_ARG(SEPARATION)); + else sepLen = 0; + + + /* + * Read the input text, stripping trailing white space + */ + for (;;) { + char* pzL; + char* pzText = fgets(zLine, (int)sizeof( zLine ), stdin); + size_t len; + + if (pzText == NULL) + break; + + /* + * Trim off trailing white space. + */ + len = strlen( pzText ); + pzText += len; + while (isspace(pzText[-1])) { + if (--pzText == zLine) { + if (HAVE_OPT(FILL)) + break; + goto next_line; + } + len--; + } + + *pzText = NUL; + + /* + * IF the input lines are to be reformatted, + * THEN the length is the result of the sprintf + * Else, compute the length. + */ + if (HAVE_OPT(FORMAT)) { + pzText = zFmtLine; + len = snprintf(zFmtLine, sizeof(zFmtLine), OPT_ARG(FORMAT), zLine); + } else { + pzText = zLine; + } + + /* + * Allocate a string and space in the pointer array. + */ + len += sepLen + 1; + pzL = (char*)malloc_or_die( len ); + if (++usedCt > allocCt) { + allocCt += 128; + papzLines = (char**)realloc( (void*)papzLines, + sizeof( char* ) * allocCt ); + } + papzLines[ usedCt-1 ] = pzL; + + /* + * Copy the text and append the separation character + */ + strcpy( pzL, pzText ); + + /* + * Initially, all strings have the separator, + * the entries may get reordered. + */ + if (sepLen > 0) + strcat(pzL, OPT_ARG(SEPARATION)); + + if ((int)len > maxEntryWidth) + maxEntryWidth = len; + next_line:; + } + + if (maxEntryWidth == 0) { + fputs( "columns warning: no input text was read\n", stderr ); + exit( EXIT_SUCCESS ); + } + + /* + * Set the line width to the amount of space we have to play with. + */ + if ((OPT_VALUE_WIDTH < maxEntryWidth) && (! HAVE_OPT(FILL))) + OPT_VALUE_WIDTH = maxEntryWidth; + + /* + * If we do not have a column size set, + * then figure out what it must be. + */ + if (columnSz == 0) { + /* + * IF the column count has not been set, + * THEN compute it. + */ + if (columnCt == 0) + columnCt = OPT_VALUE_WIDTH / maxEntryWidth; + + /* + * IF there are to be multiple columns, ... + */ + if (columnCt > 1) { + int spreadwidth = OPT_VALUE_WIDTH - maxEntryWidth; + int sz = spreadwidth / (columnCt-1); + + /* + * Either there is room for added space, + * or we must (possibly) reduce the number of columns + */ + if (sz >= maxEntryWidth) + columnSz = sz; + else { + columnCt = (spreadwidth / maxEntryWidth) + 1; + if (columnCt > 1) + columnSz = spreadwidth / (columnCt - 1); + else columnSz = OPT_VALUE_WIDTH; + } + } + } + + /* + * Otherwise, the column size has been set. Ensure it is sane. + */ + else { + bool compute_val = (columnCt == 0); + + /* + * Increase the column size to the width of the widest entry + */ + if (maxEntryWidth > (int)columnSz) + columnSz = maxEntryWidth; + + /* + * IF we have not been provided a column count + * *OR* we are set to overfill the output line, + * THEN compute the number of columns. + */ + if (! compute_val) { + unsigned long width = maxEntryWidth + (columnSz * (columnCt-1)); + compute_val = width > (unsigned)OPT_VALUE_WIDTH; + } + if (compute_val) + columnCt = ((OPT_VALUE_WIDTH - maxEntryWidth) / columnSz) + 1; + } + + /* + * Ensure that any "spread" we added to the column size + * does not exceed the parameterized limit. + */ + if ( HAVE_OPT( SPREAD ) + && ((maxEntryWidth + OPT_VALUE_SPREAD - 1) < (int)columnSz)) + columnSz = maxEntryWidth + OPT_VALUE_SPREAD - 1; +} + + +static void +writeColumns(void) +{ + char zFmt[ 12 ]; + int colCt, rowCt, col, row; + tpPrintList pPL; + + colCt = columnCt; + snprintf(zFmt, sizeof(zFmt), "%%-%ds", (int)columnSz); + + if (colCt == 1) { + writeRows(); + return; + } + + pPL = (tpPrintList)malloc_or_die( colCt * sizeof( tPrintList )); + + /* + * This "loop" is normally executed half way through and exited. + * IF, however, we would produce an empty final column, + * we will reduce our column count and line width and then + * try the top-of-column pointer computation again. + * + * The problem solved here is that sometimes, when the + * number of entries in a row is greater than the number of rows, + * it is possible that all the entries that would have been + * in the last column are, instead, essentially put on the + * last row. That will leave the final column empty. + * We could regroup at that point and spread the columns some more, + * but, if done, is an exercise for later. + */ + for (;;) { + int rem; + int fsz; + + rowCt = (usedCt/colCt) + ((usedCt % colCt) ? 1 : 0); + + /* + * FOR each column, compute the address of the pointer to + * the string at the top of the column, and the index of + * that entry. + */ + for (col = 0; col < colCt ; col++) { + pPL[col].papz = papzLines + (col * rowCt); + pPL[col].index = col * rowCt; + } + + /* + * IF the final column is not empty, + * THEN break out and start printing. + */ + if (pPL[colCt-1].index < (int)usedCt) + break; + + /* + * The last column is blank, so we reduce our column count, + * even if the user specified a count!! + */ + colCt--; + rem = OPT_VALUE_WIDTH - (colCt * maxEntryWidth); + + if ((rem == 0) || (colCt < 2) || (columnSz > 0)) + fsz = maxEntryWidth; + else + fsz = maxEntryWidth + (rem / (colCt-1)); + snprintf( zFmt, sizeof(zFmt), "%%-%ds", fsz ); + } + + /* + * Now, actually print each row... + */ + for ( row = 0 ;; ) { + char* pzL; + char* pzE; + + if (pzLinePfx != NULL) + fputs( pzLinePfx, stdout ); + + /* + * Increment the index of the current entry in the last column. + * IF it goes beyond the end of the entries in use, + * THEN reduce our column count. + */ + if ((pPL[colCt-1].index)++ >= (int)usedCt) + colCt--; + + /* + * Get the address of the string in the last column. + */ + pzE = *(pPL[colCt-1].papz++); + + col = 0; + + /* + * FOR every column except the last, + * print the entry with the width format + * + * No need to worry about referring to a non-existent entry. Only + * the last column might have that problem, and we addressed it above + * where the column count got decremented. + */ + while (++col < colCt) { + pzL = *(pPL[col-1].papz++); + fprintf( stdout, zFmt, pzL ); + free( (void*)pzL ); + } + + /* + * See if we are on the last row. If so, then this is the last entry. + * Strip any separation characters, emit the entry and break out. + */ + if (++row == rowCt) { + /* + * IF we have a separator, + * THEN remove it from the last entry. + */ + if (HAVE_OPT( SEPARATION )) { + char* pz = pzE + strlen( pzE ) + - strlen( OPT_ARG(SEPARATION)); + *pz = NUL; + } + + fputs(pzE, stdout); + if (HAVE_OPT(ENDING)) + fputs(OPT_ARG(ENDING), stdout); + + putc( '\n', stdout ); + break; + } + + /* + * Print the last entry on the line, without the width format. + * If we have line separation (which does not apply to the last + * line), then emit those characters, too. + */ + fputs( pzE, stdout ); + if (HAVE_OPT( LINE_SEPARATION )) + fputs( OPT_ARG( LINE_SEPARATION ), stdout ); + + putc( '\n', stdout ); + free( (void*)pzE ); + } + + free(pPL); +} + +static void +trim_last_separation(void) +{ + char* pz = papzLines[ usedCt-1 ]; + pz += strlen(pz) - strlen( OPT_ARG(SEPARATION)); + *pz = NUL; +} + +static void +writeRows(void) +{ + char zFmt[32]; + int colCt; + + colCt = columnCt; + snprintf(zFmt, sizeof(zFmt), "%%-%ds", (int)columnSz); + + if (HAVE_OPT( SEPARATION )) + trim_last_separation(); + + if (pzFirstPfx != NULL) { + fputs( pzFirstPfx, stdout ); + pzFirstPfx = pzLinePfx; + } + + { + char** ppzLL = papzLines; + size_t left = usedCt; + int lnNo = 0; + + /* + * FOR every entry we are to emit, ... + */ + for (;;) { + char* pzL = *ppzLL++; + + /* + * IF this is the last entry, + * THEN emit it and a new line and break out + */ + if (--left <= 0) { + fputs(pzL, stdout); + if (HAVE_OPT(ENDING)) + fputs(OPT_ARG(ENDING), stdout); + + putc('\n', stdout); + free((void*)pzL); + break; + } + + /* + * IF the count of entries on this line is still less + * than the number of columns, + * THEN emit the padded entry + * ELSE ... + */ + if (++lnNo < colCt) + fprintf( stdout, zFmt, pzL ); + + else { + lnNo = 0; + /* + * Last entry on the line. Emit the string without padding. + * IF we have a line separation string, emit that too. + */ + fputs( pzL, stdout ); + if (HAVE_OPT( LINE_SEPARATION )) + fputs( OPT_ARG( LINE_SEPARATION ), stdout ); + + putc( '\n', stdout ); + + /* + * Start the next line with any required indentation + */ + if (pzFirstPfx != NULL) { + fputs( pzFirstPfx, stdout ); + pzFirstPfx = pzLinePfx; + } + } + + free( (void*)pzL ); + } + } +} + +static int +emitWord(char const * word, size_t len, int col) +{ + static int ended_with_period = 0; + + if (col > 0) { + if ((int)len >= (OPT_VALUE_WIDTH - col)) { + putc('\n', stdout); + if (pzLinePfx != NULL) + fputs(pzLinePfx, stdout); + col = 0; + + } else { + if (ended_with_period) { + putc(' ', stdout); + col++; + } + putc(' ', stdout); + col++; + } + } + + fwrite(word, len, 1, stdout); + col += len; + ended_with_period = (word[len - 1] == '.'); + + return col; +} + +/* + * writeFill -- fill the output. Pack together as much as will fit + * on each line. + */ +static void +writeFill(void) +{ + char** ppzLL = papzLines; + size_t left = usedCt; + int colNo = 0; + + if (HAVE_OPT( SEPARATION )) + trim_last_separation(); + + if (pzFirstPfx != NULL) + fputs(pzFirstPfx, stdout); + + /* + * FOR every entry we are to emit, ... + */ + while (left-- > 0) { + char* pzL = *ppzLL; + + while (isspace(*pzL)) pzL++; + + /* + * Blank lines are magical and trigger a blank line in output. + */ + if (*pzL == NUL) { + if (! HAVE_OPT(SORT)) { + if (colNo > 0) /* guard against multiple blank lines */ + putc('\n', stdout); + putc('\n', stdout); + colNo = -2; + } + + free(*(ppzLL++)); + continue; + } + + /* + * We are going to emit some output. Make sure we're indented. + */ + if (colNo < 0) { + if (pzLinePfx != NULL) + fputs(pzLinePfx, stdout); + colNo = 0; + } + + do { + size_t tknlen; + + for (tknlen = 0; pzL[tknlen] != NUL; tknlen++) + if (isspace(pzL[tknlen])) + break; + colNo = emitWord(pzL, tknlen, colNo); + pzL += tknlen; + while (isspace(*pzL)) pzL++; + } while (*pzL != NUL); + + free(*(ppzLL++)); + } + + if (HAVE_OPT(ENDING) && (left == 0)) + fputs(OPT_ARG(ENDING), stdout); + + putc('\n', stdout); +} + + +/* + * Line comparison procedure + */ +static int +compProc(const void * p1, const void * p2) +{ + char const * pz1 = *(char* const*)p1; + char const * pz2 = *(char* const*)p2; + return strcmp(pz1, pz2); +} +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of columns/columns.c */ diff --git a/columns/opts.c b/columns/opts.c new file mode 100644 index 0000000..9c0187f --- /dev/null +++ b/columns/opts.c @@ -0,0 +1,1055 @@ +/* -*- buffer-read-only: t -*- vi: set ro: + * + * DO NOT EDIT THIS FILE (opts.c) + * + * It has been AutoGen-ed August 11, 2012 at 09:41:50 AM by AutoGen 5.16.2pre7 + * From the definitions opts.def + * and the template file options + * + * Generated from AutoOpts 36:5:11 templates. + * + * AutoOpts is a copyrighted work. This source file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the columns author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. + * + * The columns program is copyrighted and licensed + * under the following terms: + * + * Copyright (C) 1999-2012 Bruce Korb, all rights reserved. + * This is free software. It is licensed for use, modification and + * redistribution under the terms of the + * GNU General Public License, version 3 or later + * <http://gnu.org/licenses/gpl.html> + * + * columns is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * columns is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __doxygen__ +#define OPTION_CODE_COMPILE 1 +#include "opts.h" +#include <sys/types.h> + +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + +#ifdef __cplusplus +extern "C" { +#endif +extern FILE * option_usage_fp; + +/* TRANSLATORS: choose the translation for option names wisely because you + cannot ever change your mind. */ +#define zCopyright (columns_opt_strs+0) +#define zLicenseDescrip (columns_opt_strs+272) + +/* + * global included definitions + */ + +#include <errno.h> + +#define OPEN_ERROR_FMT (columns_opt_strs+875) + +#ifndef NULL +# define NULL 0 +#endif + +/* + * columns option static const strings + */ +static char const columns_opt_strs[2143] = +/* 0 */ "columns (GNU AutoGen) 1.2\n" + "Copyright (C) 1999-2012 Bruce Korb, all rights reserved.\n" + "This is free software. It is licensed for use, modification and\n" + "redistribution under the terms of the\n" + "GNU General Public License, version 3 or later\n" + " <http://gnu.org/licenses/gpl.html>\n\0" +/* 272 */ "columns is free software: you can redistribute it and/or modify it under\n" + "the terms of the GNU General Public License as published by the Free\n" + "Software Foundation, either version 3 of the License, or (at your option)\n" + "any later version.\n\n" + "columns is distributed in the hope that it will be useful, but WITHOUT ANY\n" + "WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n" + "FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n" + "details.\n\n" + "You should have received a copy of the GNU General Public License along\n" + "with this program. If not, see <http://www.gnu.org/licenses/>.\n\0" +/* 875 */ "Error %d (%s) opening %s\n\0" +/* 901 */ "Specify the output dimensions:\0" +/* 932 */ "Maximum Line Width\0" +/* 951 */ "WIDTH\0" +/* 957 */ "width\0" +/* 963 */ "Desired number of columns\0" +/* 989 */ "COLUMNS\0" +/* 997 */ "columns\0" +/* 1005 */ "Set width of each column\0" +/* 1030 */ "COL_WIDTH\0" +/* 1040 */ "col-width\0" +/* 1050 */ "tab width\0" +/* 1060 */ "TAB_WIDTH\0" +/* 1070 */ "tab-width\0" +/* 1080 */ "Specify how to lay out the text:\0" +/* 1113 */ "maximum spread added to column width\0" +/* 1150 */ "SPREAD\0" +/* 1157 */ "spread\0" +/* 1164 */ "Fill lines with input\0" +/* 1186 */ "FILL\0" +/* 1191 */ "fill\0" +/* 1196 */ "Line prefix or indentation\0" +/* 1223 */ "INDENT\0" +/* 1230 */ "indent\0" +/* 1237 */ "First line prefix\0" +/* 1255 */ "FIRST_INDENT\0" +/* 1268 */ "first-indent\0" +/* 1281 */ "Formatting string for each input\0" +/* 1314 */ "FORMAT\0" +/* 1321 */ "format\0" +/* 1328 */ "Separation string - follows all but last\0" +/* 1369 */ "SEPARATION\0" +/* 1380 */ "separation\0" +/* 1391 */ "string at end of all lines but last\0" +/* 1427 */ "LINE_SEPARATION\0" +/* 1443 */ "line-separation\0" +/* 1459 */ "string at end of last line\0" +/* 1486 */ "ENDING\0" +/* 1493 */ "ending\0" +/* 1500 */ "Specify the ordering of the entries:\0" +/* 1537 */ "Print entries in column order\0" +/* 1567 */ "BY_COLUMNS\0" +/* 1578 */ "by-columns\0" +/* 1589 */ "Sort input text\0" +/* 1605 */ "SORT\0" +/* 1610 */ "sort\0" +/* 1615 */ "Redirecting stdin to an alternate file:\0" +/* 1655 */ "Input file (if not stdin)\0" +/* 1681 */ "INPUT\0" +/* 1687 */ "input\0" +/* 1693 */ "Display extended usage information and exit\0" +/* 1737 */ "help\0" +/* 1742 */ "Extended usage information passed thru pager\0" +/* 1787 */ "more-help\0" +/* 1797 */ "Output version information and exit\0" +/* 1833 */ "version\0" +/* 1841 */ "Save the option state to a config file\0" +/* 1880 */ "save-opts\0" +/* 1890 */ "Load options from a config file\0" +/* 1922 */ "LOAD_OPTS\0" +/* 1932 */ "no-load-opts\0" +/* 1945 */ "no\0" +/* 1948 */ "columns (GNU AutoGen) - Columnize Input Text - Ver. 1.2\n" + "USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0" +/* 2062 */ ".\0" +/* 2064 */ "$HOME\0" +/* 2070 */ ".columnsrc\0" +/* 2081 */ "autogen-users@lists.sourceforge.net\0" +/* 2117 */ "columns (GNU AutoGen) 1.2"; + +/* + * dimensions option description: + */ +#define DIMENSIONS_DESC (columns_opt_strs+901) +#define DIMENSIONS_FLAGS (OPTST_DOCUMENT | OPTST_NO_INIT) + +/* + * width option description: + */ +#define WIDTH_DESC (columns_opt_strs+932) +#define WIDTH_NAME (columns_opt_strs+951) +#define WIDTH_name (columns_opt_strs+957) +#define WIDTH_DFT_ARG ((char const*)79) +#define WIDTH_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC)) + +/* + * columns option description: + */ +#define COLUMNS_DESC (columns_opt_strs+963) +#define COLUMNS_NAME (columns_opt_strs+989) +#define COLUMNS_name (columns_opt_strs+997) +#define COLUMNS_DFT_ARG ((char const*)0) +#define COLUMNS_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC)) + +/* + * col_width option description: + */ +#define COL_WIDTH_DESC (columns_opt_strs+1005) +#define COL_WIDTH_NAME (columns_opt_strs+1030) +#define COL_WIDTH_name (columns_opt_strs+1040) +#define COL_WIDTH_DFT_ARG ((char const*)0) +#define COL_WIDTH_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC)) + +/* + * tab_width option description: + */ +#define TAB_WIDTH_DESC (columns_opt_strs+1050) +#define TAB_WIDTH_NAME (columns_opt_strs+1060) +#define TAB_WIDTH_name (columns_opt_strs+1070) +#define TAB_WIDTH_DFT_ARG ((char const*)8) +#define TAB_WIDTH_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC)) + +/* + * treatment option description: + */ +#define TREATMENT_DESC (columns_opt_strs+1080) +#define TREATMENT_FLAGS (OPTST_DOCUMENT | OPTST_NO_INIT) + +/* + * spread option description: + */ +#define SPREAD_DESC (columns_opt_strs+1113) +#define SPREAD_NAME (columns_opt_strs+1150) +#define SPREAD_name (columns_opt_strs+1157) +#define SPREAD_DFT_ARG ((char const*)0) +#define SPREAD_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC)) + +/* + * fill option description with + * "Must also have options" and "Incompatible options": + */ +#define FILL_DESC (columns_opt_strs+1164) +#define FILL_NAME (columns_opt_strs+1186) +#define FILL_name (columns_opt_strs+1191) +static int const aFillCantList[] = { + INDEX_OPT_SPREAD, + INDEX_OPT_COL_WIDTH, + INDEX_OPT_BY_COLUMNS, NO_EQUIVALENT }; +#define FILL_FLAGS (OPTST_DISABLED) + +/* + * indent option description: + */ +#define INDENT_DESC (columns_opt_strs+1196) +#define INDENT_NAME (columns_opt_strs+1223) +#define INDENT_name (columns_opt_strs+1230) +#define INDENT_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * first_indent option description with + * "Must also have options" and "Incompatible options": + */ +#define FIRST_INDENT_DESC (columns_opt_strs+1237) +#define FIRST_INDENT_NAME (columns_opt_strs+1255) +#define FIRST_INDENT_name (columns_opt_strs+1268) +static int const aFirst_IndentMustList[] = { + INDEX_OPT_INDENT, NO_EQUIVALENT }; +#define FIRST_INDENT_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * format option description: + */ +#define FORMAT_DESC (columns_opt_strs+1281) +#define FORMAT_NAME (columns_opt_strs+1314) +#define FORMAT_name (columns_opt_strs+1321) +#define FORMAT_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * separation option description: + */ +#define SEPARATION_DESC (columns_opt_strs+1328) +#define SEPARATION_NAME (columns_opt_strs+1369) +#define SEPARATION_name (columns_opt_strs+1380) +#define SEPARATION_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * line_separation option description: + */ +#define LINE_SEPARATION_DESC (columns_opt_strs+1391) +#define LINE_SEPARATION_NAME (columns_opt_strs+1427) +#define LINE_SEPARATION_name (columns_opt_strs+1443) +#define LINE_SEPARATION_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * ending option description: + */ +#define ENDING_DESC (columns_opt_strs+1459) +#define ENDING_NAME (columns_opt_strs+1486) +#define ENDING_name (columns_opt_strs+1493) +#define ENDING_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * ordering option description: + */ +#define ORDERING_DESC (columns_opt_strs+1500) +#define ORDERING_FLAGS (OPTST_DOCUMENT | OPTST_NO_INIT) + +/* + * by_columns option description: + */ +#define BY_COLUMNS_DESC (columns_opt_strs+1537) +#define BY_COLUMNS_NAME (columns_opt_strs+1567) +#define BY_COLUMNS_name (columns_opt_strs+1578) +#define BY_COLUMNS_FLAGS (OPTST_DISABLED) + +/* + * sort option description: + */ +#define SORT_DESC (columns_opt_strs+1589) +#define SORT_NAME (columns_opt_strs+1605) +#define SORT_name (columns_opt_strs+1610) +#define SORT_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | OPTST_ARG_OPTIONAL) + +/* + * input-text option description: + */ +#define INPUT_TEXT_DESC (columns_opt_strs+1615) +#define INPUT_TEXT_FLAGS (OPTST_DOCUMENT | OPTST_NO_INIT) + +/* + * input option description: + */ +#define INPUT_DESC (columns_opt_strs+1655) +#define INPUT_NAME (columns_opt_strs+1681) +#define INPUT_name (columns_opt_strs+1687) +#define INPUT_FLAGS (OPTST_DISABLED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * Help/More_Help/Version option descriptions: + */ +#define HELP_DESC (columns_opt_strs+1693) +#define HELP_name (columns_opt_strs+1737) +#ifdef HAVE_WORKING_FORK +#define MORE_HELP_DESC (columns_opt_strs+1742) +#define MORE_HELP_name (columns_opt_strs+1787) +#define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) +#else +#define MORE_HELP_DESC NULL +#define MORE_HELP_name NULL +#define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) +#endif +#ifdef NO_OPTIONAL_OPT_ARGS +# define VER_FLAGS (OPTST_IMM | OPTST_NO_INIT) +#else +# define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ + OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT) +#endif +#define VER_DESC (columns_opt_strs+1797) +#define VER_name (columns_opt_strs+1833) +#define SAVE_OPTS_DESC (columns_opt_strs+1841) +#define SAVE_OPTS_name (columns_opt_strs+1880) +#define LOAD_OPTS_DESC (columns_opt_strs+1890) +#define LOAD_OPTS_NAME (columns_opt_strs+1922) +#define NO_LOAD_OPTS_name (columns_opt_strs+1932) +#define LOAD_OPTS_pfx (columns_opt_strs+1945) +#define LOAD_OPTS_name (NO_LOAD_OPTS_name + 3) +/* + * Declare option callback procedures + */ +extern tOptProc + optionBooleanVal, optionNestedVal, optionNumericVal, + optionPagedUsage, optionPrintVersion, optionResetOpt, + optionStackArg, optionTimeDate, optionTimeVal, + optionUnstackArg, optionVendorOption; +static tOptProc + doOptCol_Width, doOptColumns, doOptInput, doOptSpread, + doOptWidth, doUsageOpt; +#define VER_PROC optionPrintVersion + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Define the columns Option Descriptions. + * This is an array of OPTION_CT entries, one for each + * option that the columns program responds to. + */ +static tOptDesc optDesc[OPTION_CT] = { + { /* entry idx, value */ 0, 0, + /* equiv idx, value */ 0, 0, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 0, 0, + /* opt state flags */ DIMENSIONS_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ DIMENSIONS_DESC, NULL, NULL, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 1, VALUE_OPT_WIDTH, + /* equiv idx, value */ 1, VALUE_OPT_WIDTH, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ WIDTH_FLAGS, 0, + /* last opt argumnt */ { WIDTH_DFT_ARG }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doOptWidth, + /* desc, NAME, name */ WIDTH_DESC, WIDTH_NAME, WIDTH_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 2, VALUE_OPT_COLUMNS, + /* equiv idx, value */ 2, VALUE_OPT_COLUMNS, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ COLUMNS_FLAGS, 0, + /* last opt argumnt */ { COLUMNS_DFT_ARG }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doOptColumns, + /* desc, NAME, name */ COLUMNS_DESC, COLUMNS_NAME, COLUMNS_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 3, VALUE_OPT_COL_WIDTH, + /* equiv idx, value */ 3, VALUE_OPT_COL_WIDTH, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ COL_WIDTH_FLAGS, 0, + /* last opt argumnt */ { COL_WIDTH_DFT_ARG }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doOptCol_Width, + /* desc, NAME, name */ COL_WIDTH_DESC, COL_WIDTH_NAME, COL_WIDTH_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 4, VALUE_OPT_TAB_WIDTH, + /* equiv idx, value */ 4, VALUE_OPT_TAB_WIDTH, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ TAB_WIDTH_FLAGS, 0, + /* last opt argumnt */ { TAB_WIDTH_DFT_ARG }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ optionNumericVal, + /* desc, NAME, name */ TAB_WIDTH_DESC, TAB_WIDTH_NAME, TAB_WIDTH_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 0, 0, + /* equiv idx, value */ 0, 0, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 0, 0, + /* opt state flags */ TREATMENT_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ TREATMENT_DESC, NULL, NULL, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 6, VALUE_OPT_SPREAD, + /* equiv idx, value */ 6, VALUE_OPT_SPREAD, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ SPREAD_FLAGS, 0, + /* last opt argumnt */ { SPREAD_DFT_ARG }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doOptSpread, + /* desc, NAME, name */ SPREAD_DESC, SPREAD_NAME, SPREAD_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 7, VALUE_OPT_FILL, + /* equiv idx, value */ 7, VALUE_OPT_FILL, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ FILL_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --fill */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, aFillCantList, + /* option proc */ NULL, + /* desc, NAME, name */ FILL_DESC, FILL_NAME, FILL_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 8, VALUE_OPT_INDENT, + /* equiv idx, value */ 8, VALUE_OPT_INDENT, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ INDENT_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --indent */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ INDENT_DESC, INDENT_NAME, INDENT_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 9, VALUE_OPT_FIRST_INDENT, + /* equiv idx, value */ 9, VALUE_OPT_FIRST_INDENT, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ FIRST_INDENT_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --first_indent */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ aFirst_IndentMustList, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ FIRST_INDENT_DESC, FIRST_INDENT_NAME, FIRST_INDENT_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 10, VALUE_OPT_FORMAT, + /* equiv idx, value */ 10, VALUE_OPT_FORMAT, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ FORMAT_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --format */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ FORMAT_DESC, FORMAT_NAME, FORMAT_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 11, VALUE_OPT_SEPARATION, + /* equiv idx, value */ 11, VALUE_OPT_SEPARATION, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ SEPARATION_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --separation */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ SEPARATION_DESC, SEPARATION_NAME, SEPARATION_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 12, VALUE_OPT_LINE_SEPARATION, + /* equiv idx, value */ 12, VALUE_OPT_LINE_SEPARATION, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ LINE_SEPARATION_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --line_separation */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ LINE_SEPARATION_DESC, LINE_SEPARATION_NAME, LINE_SEPARATION_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 13, VALUE_OPT_ENDING, + /* equiv idx, value */ 13, VALUE_OPT_ENDING, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ ENDING_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --ending */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ ENDING_DESC, ENDING_NAME, ENDING_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 0, 0, + /* equiv idx, value */ 0, 0, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 0, 0, + /* opt state flags */ ORDERING_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ ORDERING_DESC, NULL, NULL, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 15, VALUE_OPT_BY_COLUMNS, + /* equiv idx, value */ 15, VALUE_OPT_BY_COLUMNS, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ BY_COLUMNS_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --by_columns */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ BY_COLUMNS_DESC, BY_COLUMNS_NAME, BY_COLUMNS_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 16, VALUE_OPT_SORT, + /* equiv idx, value */ 16, VALUE_OPT_SORT, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ SORT_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --sort */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ SORT_DESC, SORT_NAME, SORT_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 0, 0, + /* equiv idx, value */ 0, 0, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 0, 0, + /* opt state flags */ INPUT_TEXT_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ INPUT_TEXT_DESC, NULL, NULL, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 18, VALUE_OPT_INPUT, + /* equiv idx, value */ 18, VALUE_OPT_INPUT, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ INPUT_FLAGS, 0, + /* last opt argumnt */ { NULL }, /* --input */ + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doOptInput, + /* desc, NAME, name */ INPUT_DESC, INPUT_NAME, INPUT_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION, + /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_VERSION, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ VER_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ VER_PROC, + /* desc, NAME, name */ VER_DESC, NULL, VER_name, + /* disablement strs */ NULL, NULL }, + + + + { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP, + /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_HELP, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doUsageOpt, + /* desc, NAME, name */ HELP_DESC, NULL, HELP_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP, + /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_MORE_HELP, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ MORE_HELP_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ optionPagedUsage, + /* desc, NAME, name */ MORE_HELP_DESC, NULL, MORE_HELP_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS, + /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_SAVE_OPTS, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) + | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ SAVE_OPTS_DESC, NULL, SAVE_OPTS_name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS, + /* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_LOAD_OPTS, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, NOLIMIT, 0, + /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) + | OPTST_DISABLE_IMM, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ optionLoadOpt, + /* desc, NAME, name */ LOAD_OPTS_DESC, LOAD_OPTS_NAME, LOAD_OPTS_name, + /* disablement strs */ NO_LOAD_OPTS_name, LOAD_OPTS_pfx } +}; + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Define the columns Option Environment + */ +#define zPROGNAME (columns_opt_strs+989) +#define zUsageTitle (columns_opt_strs+1948) +#define zRcName (columns_opt_strs+2070) +static char const * const apzHomeList[3] = { + columns_opt_strs+2062, + columns_opt_strs+2064, + NULL }; +#define zBugsAddr (columns_opt_strs+2081) +#define zExplain (NULL) +#define zDetail (NULL) +#define zFullVersion (columns_opt_strs+2117) +/* extracted from optcode.tlib near line 350 */ + +#if defined(ENABLE_NLS) +# define OPTPROC_BASE OPTPROC_TRANSLATE + static tOptionXlateProc translate_option_strings; +#else +# define OPTPROC_BASE OPTPROC_NONE +# define translate_option_strings NULL +#endif /* ENABLE_NLS */ + + +#define columns_full_usage (NULL) + +#define columns_short_usage (NULL) + +#endif /* not defined __doxygen__ */ + +/* + * Create the static procedure(s) declared above. + */ +/** + * The callout function that invokes the optionUsage function. + * + * @param pOptions the AutoOpts option description structure + * @param pOptDesc the descriptor for the "help" (usage) option. + * @noreturn + */ +static void +doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) +{ + optionUsage(&columnsOptions, COLUMNS_EXIT_SUCCESS); + /* NOTREACHED */ + (void)pOptDesc; + (void)pOptions; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Code to handle the width option. + * + * @param pOptions the columns options data structure + * @param pOptDesc the option descriptor for this option. + */ +static void +doOptWidth(tOptions* pOptions, tOptDesc* pOptDesc) +{ + static struct {long rmin, rmax;} const rng[1] = { + { 16, 4095 } }; + int ix; + + if (pOptions <= OPTPROC_EMIT_LIMIT) + goto emit_ranges; + optionNumericVal(pOptions, pOptDesc); + + for (ix = 0; ix < 1; ix++) { + if (pOptDesc->optArg.argInt < rng[ix].rmin) + continue; /* ranges need not be ordered. */ + if (pOptDesc->optArg.argInt == rng[ix].rmin) + return; + if (rng[ix].rmax == LONG_MIN) + continue; + if (pOptDesc->optArg.argInt <= rng[ix].rmax) + return; + } + + option_usage_fp = stderr; + +emit_ranges: + optionShowRange(pOptions, pOptDesc, (void *)rng, 1); +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Code to handle the columns option. + * + * @param pOptions the columns options data structure + * @param pOptDesc the option descriptor for this option. + */ +static void +doOptColumns(tOptions* pOptions, tOptDesc* pOptDesc) +{ + static struct {long rmin, rmax;} const rng[1] = { + { 1, 2048 } }; + int ix; + + if (pOptions <= OPTPROC_EMIT_LIMIT) + goto emit_ranges; + optionNumericVal(pOptions, pOptDesc); + + for (ix = 0; ix < 1; ix++) { + if (pOptDesc->optArg.argInt < rng[ix].rmin) + continue; /* ranges need not be ordered. */ + if (pOptDesc->optArg.argInt == rng[ix].rmin) + return; + if (rng[ix].rmax == LONG_MIN) + continue; + if (pOptDesc->optArg.argInt <= rng[ix].rmax) + return; + } + + option_usage_fp = stderr; + +emit_ranges: + optionShowRange(pOptions, pOptDesc, (void *)rng, 1); +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Code to handle the col_width option. + * + * @param pOptions the columns options data structure + * @param pOptDesc the option descriptor for this option. + */ +static void +doOptCol_Width(tOptions* pOptions, tOptDesc* pOptDesc) +{ + static struct {long rmin, rmax;} const rng[1] = { + { 1, 2048 } }; + int ix; + + if (pOptions <= OPTPROC_EMIT_LIMIT) + goto emit_ranges; + optionNumericVal(pOptions, pOptDesc); + + for (ix = 0; ix < 1; ix++) { + if (pOptDesc->optArg.argInt < rng[ix].rmin) + continue; /* ranges need not be ordered. */ + if (pOptDesc->optArg.argInt == rng[ix].rmin) + return; + if (rng[ix].rmax == LONG_MIN) + continue; + if (pOptDesc->optArg.argInt <= rng[ix].rmax) + return; + } + + option_usage_fp = stderr; + +emit_ranges: + optionShowRange(pOptions, pOptDesc, (void *)rng, 1); +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Code to handle the spread option. + * + * @param pOptions the columns options data structure + * @param pOptDesc the option descriptor for this option. + */ +static void +doOptSpread(tOptions* pOptions, tOptDesc* pOptDesc) +{ + static struct {long rmin, rmax;} const rng[1] = { + { 1, 1024 } }; + int ix; + + if (pOptions <= OPTPROC_EMIT_LIMIT) + goto emit_ranges; + optionNumericVal(pOptions, pOptDesc); + + for (ix = 0; ix < 1; ix++) { + if (pOptDesc->optArg.argInt < rng[ix].rmin) + continue; /* ranges need not be ordered. */ + if (pOptDesc->optArg.argInt == rng[ix].rmin) + return; + if (rng[ix].rmax == LONG_MIN) + continue; + if (pOptDesc->optArg.argInt <= rng[ix].rmax) + return; + } + + option_usage_fp = stderr; + +emit_ranges: + optionShowRange(pOptions, pOptDesc, (void *)rng, 1); +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Code to handle the input option. + * + * @param pOptions the columns options data structure + * @param pOptDesc the option descriptor for this option. + */ +static void +doOptInput(tOptions* pOptions, tOptDesc* pOptDesc) +{ + /* extracted from opts.def, line 302 */ + FILE* fp = freopen( + pOptDesc->optArg.argString, "r" FOPEN_BINARY_FLAG, stdin); + + if (fp == (FILE*)NULL) { + fprintf(stderr, OPEN_ERROR_FMT, errno, strerror(errno), + pOptDesc->optArg.argString); + USAGE(EXIT_FAILURE); + } + (void)pOptions; +} +/* extracted from optmain.tlib near line 1146 */ + +/** + * The directory containing the data associated with columns. + */ +#ifndef PKGDATADIR +# define PKGDATADIR "" +#endif + +/** + * Information about the person or institution that packaged columns + * for the current distribution. + */ +#ifndef WITH_PACKAGER +# define columns_packager_info NULL +#else +static char const columns_packager_info[] = + "Packaged by " WITH_PACKAGER + +# ifdef WITH_PACKAGER_VERSION + " ("WITH_PACKAGER_VERSION")" +# endif + +# ifdef WITH_PACKAGER_BUG_REPORTS + "\nReport columns bugs to " WITH_PACKAGER_BUG_REPORTS +# endif + "\n"; +#endif +#ifndef __doxygen__ + +#endif /* __doxygen__ */ +/** + * The option definitions for columns. The one structure that + * binds them all. + */ +tOptions columnsOptions = { + OPTIONS_STRUCT_VERSION, + 0, NULL, /* original argc + argv */ + ( OPTPROC_BASE + + OPTPROC_ERRSTOP + + OPTPROC_SHORTOPT + + OPTPROC_LONGOPT + + OPTPROC_NO_REQ_OPT + + OPTPROC_ENVIRON + + OPTPROC_NO_ARGS ), + 0, NULL, /* current option index, current option */ + NULL, NULL, zPROGNAME, + zRcName, zCopyright, zLicenseDescrip, + zFullVersion, apzHomeList, zUsageTitle, + zExplain, zDetail, optDesc, + zBugsAddr, /* address to send bugs to */ + NULL, NULL, /* extensions/saved state */ + optionUsage, /* usage procedure */ + translate_option_strings, /* translation procedure */ + /* + * Indexes to special options + */ + { INDEX_OPT_MORE_HELP, /* more-help option index */ + INDEX_OPT_SAVE_OPTS, /* save option index */ + NO_EQUIVALENT, /* '-#' option index */ + NO_EQUIVALENT /* index of default opt */ + }, + 24 /* full option count */, 19 /* user option count */, + columns_full_usage, columns_short_usage, + NULL, NULL, + PKGDATADIR, columns_packager_info +}; + +#if ENABLE_NLS +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <autoopts/usage-txt.h> + +static char* AO_gettext(char const* pz); +static void coerce_it(void** s); + +/** + * AutoGen specific wrapper function for gettext. + * It relies on the macro _() to convert from English to the target + * language, then strdup-duplicates the result string. + * + * @param[in] pz the input text used as a lookup key. + * @returns the translated text (if there is one), + * or the original text (if not). + */ +static char * +AO_gettext(char const* pz) +{ + char* pzRes; + if (pz == NULL) + return NULL; + pzRes = _(pz); + if (pzRes == pz) + return pzRes; + pzRes = strdup(pzRes); + if (pzRes == NULL) { + fputs(_("No memory for duping translated strings\n"), stderr); + exit(COLUMNS_EXIT_FAILURE); + } + return pzRes; +} + +static void coerce_it(void** s) { *s = AO_gettext(*s); +} + +/** + * Translate all the translatable strings in the columnsOptions + * structure defined above. This is done only once. + */ +static void +translate_option_strings(void) +{ + tOptions * const pOpt = &columnsOptions; + + /* + * Guard against re-translation. It won't work. The strings will have + * been changed by the first pass through this code. One shot only. + */ + if (option_usage_text.field_ct != 0) { + /* + * Do the translations. The first pointer follows the field count + * field. The field count field is the size of a pointer. + */ + tOptDesc * pOD = pOpt->pOptDesc; + char ** ppz = (char**)(void*)&(option_usage_text); + int ix = option_usage_text.field_ct; + + do { + ppz++; + *ppz = AO_gettext(*ppz); + } while (--ix > 0); + + coerce_it((void*)&(pOpt->pzCopyright)); + coerce_it((void*)&(pOpt->pzCopyNotice)); + coerce_it((void*)&(pOpt->pzFullVersion)); + coerce_it((void*)&(pOpt->pzUsageTitle)); + coerce_it((void*)&(pOpt->pzExplain)); + coerce_it((void*)&(pOpt->pzDetail)); + coerce_it((void*)&(pOpt->pzPackager)); + option_usage_text.field_ct = 0; + + for (ix = pOpt->optCt; ix > 0; ix--, pOD++) + coerce_it((void*)&(pOD->pzText)); + } + + if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) { + tOptDesc * pOD = pOpt->pOptDesc; + int ix; + + for (ix = pOpt->optCt; ix > 0; ix--, pOD++) { + coerce_it((void*)&(pOD->pz_Name)); + coerce_it((void*)&(pOD->pz_DisableName)); + coerce_it((void*)&(pOD->pz_DisablePfx)); + } + /* prevent re-translation */ + columnsOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT; + } +} + +#endif /* ENABLE_NLS */ + +#ifdef __cplusplus +} +#endif +/* opts.c ends here */ diff --git a/columns/opts.def b/columns/opts.def new file mode 100644 index 0000000..a2c0af1 --- /dev/null +++ b/columns/opts.def @@ -0,0 +1,357 @@ +/* -*- Mode: conf -*- */ + +autogen definitions options; + +/* + * Time-stamp: "2012-04-07 09:30:18 bkorb" + * + * AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoGen is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AutoGen is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +copyright = { + date = "1999-2012"; + type = gpl; + owner = "Bruce Korb"; + eaddr = 'autogen-users@lists.sourceforge.net'; +}; + +prog-name = "columns"; +prog-title = "Columnize Input Text"; +package = 'GNU AutoGen'; +homerc = '.', '$HOME'; +environrc; +long-opts; + +version = "1.2"; + +export = <<- EOExport + #include "config.h" + #include <ctype.h> + #include <errno.h> + #include <stdarg.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + EOExport; + +include = "[= AutoGen5 Template =]"; +include = "#include <errno.h>"; + +flag = { + name = dimensions; + documentation; + + descrip = 'Specify the output dimensions'; +}; + +flag = { + name = width; + value = W; + arg-type = number; + arg-default = 79; + arg-name = num; + arg-range = '16->4095'; + descrip = "Maximum Line Width"; + doc = <<- _EODoc_ + This option specifies the full width of the output line, + including any start-of-line indentation. The output will fill + each line as completely as possible, unless the column width has + been explicitly specified. If the maximum width is less than + the length of the widest input, you will get a single column + of output. + _EODoc_; +}; + +flag = { + name = columns; + value = c; + arg-type = number; + arg-default = 0; + arg-name = count; + arg-range = '1->2048'; + descrip = "Desired number of columns"; + doc = <<- _EODoc_ + Use this option to specify exactly how many columns to produce. + If that many columns will not fit within @var{line_width}, then + the count will be reduced to the number that fit. + _EODoc_; +}; + +flag = { + name = col_width; + value = w; + arg-type = number; + arg-default = 0; + arg-name = num; + arg-range = '1->2048'; + descrip = "Set width of each column"; + doc = <<- _EODoc_ + Use this option to specify exactly how many characters are to be + allocated for each column. If it is narrower than the widest entry, + it will be over-ridden with the required width. + _EODoc_; +}; + +flag = { + name = tab_width; + arg-type = number; + arg-default = 8; + arg-name = num; + descrip = "tab width"; + doc = <<- _EODoc_ + If an indentation string contains tabs, then this value is used to + compute the ending column of the prefix string. + _EODoc_; +}; + +#ifdef LATER +flag = { + name = page_len; + arg-type = number; + arg-name = num; + descrip = "Page Length"; + doc = <<- _EODoc_ + This many lines will be printed before a form feed is emitted. + The 'by_columns' ordering will wrap columns within a page. + _EODoc_; +}; +#endif + +flag = { + name = treatment; + documentation; + descrip = 'Specify how to lay out the text'; +}; + +flag = { + name = spread; + arg-type = number; + arg-default = 0; + arg-name = num; + arg-range = '1->1024'; + descrip = "maximum spread added to column width"; + doc = <<- _EODoc_ + Use this option to specify exactly how many characters may be + added to each column. It allows you to prevent columns from + becoming too far apart. Without this option, @file{columns} + will attempt to widen columns to fill the full width. + _EODoc_; +}; + +flag = { + name = fill; + descrip = "Fill lines with input"; + flags-cant = spread, col_width, by_columns; + doc = <<- _EODoc_ + Instead of columnizing the input text, fill the output lines + with the input lines. Blank lines on input will cause a + blank line in the output, unless the output is sorted. + With sorted output, blank lines are ignored. + _EODoc_; +}; + +flag = { + name = indent; + value = I; + arg-type = string; + arg-name = l-pfx; + descrip = "Line prefix or indentation"; + doc = <<- _EODoc_ + If a number, then this many spaces will be inserted at the start of + every line. Otherwise, it is a line prefix that will be inserted + at the start of every line. + _EODoc_; +}; + +flag = { + name = first_indent; + arg-type = string; + flags_must = indent; + arg-name = l-pfx; + descrip = "First line prefix"; + doc = <<- _EODoc_ + If a number, then this many spaces will be inserted at the start of + the first line. Otherwise, it is a line prefix that will be inserted + at the start of that line. If its length exceeds "indent", then it + will be emitted on a line by itself, suffixed by any line separation + string. For example: + + @example + $ columns --first='#define TABLE' -c 2 -I4 --line=' \' <<_EOF_ + one + two + three + four + _EOF_ + #define TABLE \ + one two \ + three four + @end example + _EODoc_; // ' +}; + +flag = { + name = format; + value = f; + arg-type = string; + arg-name = fmt-str; + descrip = "Formatting string for each input"; + doc = <<- _EODoc_ + If you need to reformat each input text, the argument to this + option is interpreted as an @code{sprintf(3)} format that is used + to produce each output entry. + _EODoc_; +}; + +flag = { + name = separation; + value = S; + arg-type = string; + arg-name = sep-str; + descrip = "Separation string - follows all but last"; + doc = <<- _EODoc_ + Use this option if, for example, you wish a comma to appear after + each entry except the last. + _EODoc_; +}; + +flag = { + name = line_separation; + arg-type = string; + arg-name = sep-str; + descrip = "string at end of all lines but last"; + doc = <<- _EODoc_ + Use this option if, for example, you wish a backslash to appear at + the end of every line, except the last. + _EODoc_; +}; + +flag = { + name = ending; + arg-type = string; + arg-name = end-str; + descrip = "string at end of last line"; + doc = <<- _EODoc_ + This option puts the specified string at the end of the output. + _EODoc_; +}; + +flag = { + name = ordering; + documentation; + descrip = 'Specify the ordering of the entries'; +}; + +flag = { + name = by_columns; + descrip = "Print entries in column order"; + doc = <<- _EODoc_ + Normally, the entries are printed out in order by rows and then columns. + This option will cause the entries to be ordered within columns. + The final column, instead of the final row, may be shorter than the + others. + _EODoc_; +}; + +flag = { + name = sort; + value = s; + arg-type = string; + arg-optional; + arg-name = key-pat; + descrip = "Sort input text"; + doc = <<- _EODoc_ + Causes the input text to be sorted. If an argument is supplied, + it is presumed to be a pattern and the sort is based upon the + matched text. If the pattern starts with or consists of + an asterisk (@code{*}), then the sort is case insensitive. + _EODoc_; +}; + +flag = { + name = input-text; + documentation; + descrip = 'Redirecting stdin to an alternate file'; +}; + +include = + '#define OPEN_ERROR_FMT ([= + (string-table-add-ref opt-strs + "Error %d (%s) opening %s\n")=])'; + +flag = { + name = input; + value = i; + arg-type = string; + arg-name = file; + descrip = "Input file (if not stdin)"; + flag-code = <<- _EODoc_ + FILE* fp = freopen( + pOptDesc->optArg.argString, "r" FOPEN_BINARY_FLAG, stdin); + + if (fp == (FILE*)NULL) { + fprintf(stderr, OPEN_ERROR_FMT, errno, strerror(errno), + pOptDesc->optArg.argString); + USAGE(EXIT_FAILURE); + } + _EODoc_; + doc = <<- _EODoc_ + This program normally runs as a @code{filter}, reading from standard + input, columnizing and writing to standard out. This option redirects + input to a file. + _EODoc_; +}; + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Program Documentation + */ +option-doc-format = texi; + +/* prog_man_descrip = -- unchanged; */ + +doc-section = { + ds-type = "SEE ALSO"; + ds-format = texi; + ds-text = <<- _EndOfMan_ + This program is documented more fully in the Columns section + of the Add-On chapter in the @code{AutoGen} Info system documentation. + _EndOfMan_; +}; + +prog_descrip = <<- _EndOfMan_ + This program was designed for the purpose of generating compact, + columnized tables. It will read a list of text items from standard + in or a specified input file and produce a columnized listing of + all the non-blank lines. Leading white space on each line is + preserved, but trailing white space is stripped. Methods of + applying per-entry and per-line embellishments are provided. + See the formatting and separation arguments below. + + This program is used by AutoGen to help clean up and organize + its output. + + See @file{autogen/agen5/fsm.tpl} and the generated output + @file{pseudo-fsm.h}. + + This function was not implemented as an expression function because + either it would have to be many expression functions, or a provision + would have to be added to provide options to expression functions. + Maybe not a bad idea, but it is not being implemented at the moment. + + A side benefit is that you can use it outside of @code{autogen} to + columnize input, a la the @code{ls} command. + _EndOfMan_; diff --git a/columns/opts.h b/columns/opts.h new file mode 100644 index 0000000..caa5fde --- /dev/null +++ b/columns/opts.h @@ -0,0 +1,239 @@ +/* -*- buffer-read-only: t -*- vi: set ro: + * + * DO NOT EDIT THIS FILE (opts.h) + * + * It has been AutoGen-ed August 11, 2012 at 09:41:50 AM by AutoGen 5.16.2pre7 + * From the definitions opts.def + * and the template file options + * + * Generated from AutoOpts 36:5:11 templates. + * + * AutoOpts is a copyrighted work. This header file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the columns author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. + * + * The columns program is copyrighted and licensed + * under the following terms: + * + * Copyright (C) 1999-2012 Bruce Korb, all rights reserved. + * This is free software. It is licensed for use, modification and + * redistribution under the terms of the + * GNU General Public License, version 3 or later + * <http://gnu.org/licenses/gpl.html> + * + * columns is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * columns is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ +/* + * This file contains the programmatic interface to the Automated + * Options generated for the columns program. + * These macros are documented in the AutoGen info file in the + * "AutoOpts" chapter. Please refer to that doc for usage help. + */ +#ifndef AUTOOPTS_OPTS_H_GUARD +#define AUTOOPTS_OPTS_H_GUARD 1 +#include <autoopts/options.h> + +/* + * Ensure that the library used for compiling this generated header is at + * least as new as the version current when the header template was released + * (not counting patch version increments). Also ensure that the oldest + * tolerable version is at least as old as what was current when the header + * template was released. + */ +#define AO_TEMPLATE_VERSION 147461 +#if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ + || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) +# error option template version mismatches autoopts/options.h header + Choke Me. +#endif + +/* + * Enumeration of each option: + */ +typedef enum { + INDEX_OPT_WIDTH = 1, + INDEX_OPT_COLUMNS = 2, + INDEX_OPT_COL_WIDTH = 3, + INDEX_OPT_TAB_WIDTH = 4, + INDEX_OPT_SPREAD = 6, + INDEX_OPT_FILL = 7, + INDEX_OPT_INDENT = 8, + INDEX_OPT_FIRST_INDENT = 9, + INDEX_OPT_FORMAT = 10, + INDEX_OPT_SEPARATION = 11, + INDEX_OPT_LINE_SEPARATION = 12, + INDEX_OPT_ENDING = 13, + INDEX_OPT_BY_COLUMNS = 15, + INDEX_OPT_SORT = 16, + INDEX_OPT_INPUT = 18, + INDEX_OPT_VERSION = 19, + INDEX_OPT_HELP = 20, + INDEX_OPT_MORE_HELP = 21, + INDEX_OPT_SAVE_OPTS = 22, + INDEX_OPT_LOAD_OPTS = 23 +} teOptIndex; + +#define OPTION_CT 24 +#define COLUMNS_VERSION "1.2" +#define COLUMNS_FULL_VERSION "columns (GNU AutoGen) 1.2" + +/* + * Interface defines for all options. Replace "n" with the UPPER_CASED + * option name (as in the teOptIndex enumeration above). + * e.g. HAVE_OPT(DIMENSIONS) + */ +#define DESC(n) (columnsOptions.pOptDesc[INDEX_OPT_## n]) +#define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n))) +#define OPT_ARG(n) (DESC(n).optArg.argString) +#define STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK) +#define COUNT_OPT(n) (DESC(n).optOccCt) +#define ISSEL_OPT(n) (SELECTED_OPT(&DESC(n))) +#define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n))) +#define ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n))) +#define STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt) +#define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs) +#define CLEAR_OPT(n) STMTS( \ + DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \ + if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \ + DESC(n).fOptState |= OPTST_DISABLED; \ + DESC(n).optCookie = NULL ) + +/* * * * * * + * + * Enumeration of columns exit codes + */ +typedef enum { + COLUMNS_EXIT_SUCCESS = 0, + COLUMNS_EXIT_FAILURE = 1, + COLUMNS_EXIT_NO_CONFIG_INPUT = 66, + COLUMNS_EXIT_LIBOPTS_FAILURE = 70 +} columns_exit_code_t; +/* * * * * * + * + * Interface defines for specific options. + */ +#define VALUE_OPT_WIDTH 'W' + +#define OPT_VALUE_WIDTH (DESC(WIDTH).optArg.argInt) +#define VALUE_OPT_COLUMNS 'c' + +#define OPT_VALUE_COLUMNS (DESC(COLUMNS).optArg.argInt) +#define VALUE_OPT_COL_WIDTH 'w' + +#define OPT_VALUE_COL_WIDTH (DESC(COL_WIDTH).optArg.argInt) +#define VALUE_OPT_TAB_WIDTH 4 + +#define OPT_VALUE_TAB_WIDTH (DESC(TAB_WIDTH).optArg.argInt) +#define VALUE_OPT_SPREAD 6 + +#define OPT_VALUE_SPREAD (DESC(SPREAD).optArg.argInt) +#define VALUE_OPT_FILL 7 +#define VALUE_OPT_INDENT 'I' +#define VALUE_OPT_FIRST_INDENT 9 +#define VALUE_OPT_FORMAT 'f' +#define VALUE_OPT_SEPARATION 'S' +#define VALUE_OPT_LINE_SEPARATION 12 +#define VALUE_OPT_ENDING 13 +#define VALUE_OPT_BY_COLUMNS 15 +#define VALUE_OPT_SORT 's' +#define VALUE_OPT_INPUT 'i' +#define VALUE_OPT_HELP '?' +#define VALUE_OPT_MORE_HELP '!' +#define VALUE_OPT_VERSION 'v' +#define VALUE_OPT_SAVE_OPTS '>' +#define VALUE_OPT_LOAD_OPTS '<' +#define SET_OPT_SAVE_OPTS(a) STMTS( \ + DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \ + DESC(SAVE_OPTS).fOptState |= OPTST_SET; \ + DESC(SAVE_OPTS).optArg.argString = (char const*)(a) ) +/* + * Interface defines not associated with particular options + */ +#define ERRSKIP_OPTERR STMTS(columnsOptions.fOptSet &= ~OPTPROC_ERRSTOP) +#define ERRSTOP_OPTERR STMTS(columnsOptions.fOptSet |= OPTPROC_ERRSTOP) +#define RESTART_OPT(n) STMTS( \ + columnsOptions.curOptIdx = (n); \ + columnsOptions.pzCurOpt = NULL) +#define START_OPT RESTART_OPT(1) +#define USAGE(c) (*columnsOptions.pUsageProc)(&columnsOptions, c) +/* extracted from opthead.tlib near line 484 */ + +#ifdef __cplusplus +extern "C" { +#endif +/* + * global exported definitions + */ +#include "config.h" +#include <ctype.h> +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +/* * * * * * + * + * Declare the columns option descriptor. + */ +extern tOptions columnsOptions; + +#if defined(ENABLE_NLS) +# ifndef _ +# include <stdio.h> +# ifndef HAVE_GETTEXT + extern char * gettext(char const *); +# else +# include <libintl.h> +# endif + +static inline char* aoGetsText(char const* pz) { + if (pz == NULL) return NULL; + return (char*)gettext(pz); +} +# define _(s) aoGetsText(s) +# endif /* _() */ + +# define OPT_NO_XLAT_CFG_NAMES STMTS(columnsOptions.fOptSet |= \ + OPTPROC_NXLAT_OPT_CFG;) +# define OPT_NO_XLAT_OPT_NAMES STMTS(columnsOptions.fOptSet |= \ + OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;) + +# define OPT_XLAT_CFG_NAMES STMTS(columnsOptions.fOptSet &= \ + ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);) +# define OPT_XLAT_OPT_NAMES STMTS(columnsOptions.fOptSet &= \ + ~OPTPROC_NXLAT_OPT;) + +#else /* ENABLE_NLS */ +# define OPT_NO_XLAT_CFG_NAMES +# define OPT_NO_XLAT_OPT_NAMES + +# define OPT_XLAT_CFG_NAMES +# define OPT_XLAT_OPT_NAMES + +# ifndef _ +# define _(_s) _s +# endif +#endif /* ENABLE_NLS */ + +#ifdef __cplusplus +} +#endif +#endif /* AUTOOPTS_OPTS_H_GUARD */ +/* opts.h ends here */ |