diff -Nru confget-2.0.0/CHANGES confget-2.1.0/CHANGES --- confget-2.0.0/CHANGES 2016-04-04 19:21:47.000000000 +0000 +++ confget-2.1.0/CHANGES 2017-11-11 21:07:36.000000000 +0000 @@ -1,5 +1,12 @@ Change log for confget, the configuration file variable extractor +2.1.0 2017/11/11 + - allow the installation commands to be overridden, e.g. for + package builds which do not require root privileges + - add "-q features" and "-q feature NAME" with only the "BASE" + feature defined so far + - support "--help" and "--version" + 2.0.0 2016/04/03 INCOMPATIBLE CHANGES: diff -Nru confget-2.0.0/confget.c confget-2.1.0/confget.c --- confget-2.0.0/confget.c 2016-04-04 19:21:47.000000000 +0000 +++ confget-2.1.0/confget.c 2017-11-11 21:07:36.000000000 +0000 @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008, 2009, 2012, 2013, 2016 Peter Pentchev + * Copyright (c) 2008, 2009, 2012, 2013, 2016, 2017 Peter Pentchev * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -99,6 +99,10 @@ static bool Lflag; /* Query for the names of the sections in the configuration file? */ bool qsections; +/* Query for a single feature? */ +bool qfeature; +/* Query for all the features? */ +bool qfeatures; /* Shell-quote the variable values? */ static bool Sflag; #ifdef HAVE_PCRE @@ -134,6 +138,8 @@ " [-p prefix]\n" " [-s section] [-t type] -l\n" "confget [-f filename] -q sections [-t type]\n\n" + "confget -q features\n" + "confget -q feature NAME\n\n" "confget [-hTV]\n\n"; const char * const s2 = "\t-c\tcheck if the variable is defined in the file;\n" @@ -179,7 +185,7 @@ void version(void) { - puts("confget 2.0.0"); + puts("confget 2.1.0"); } /*** @@ -205,7 +211,7 @@ output_prefix = output_postfix = ""; size_t bidx = find_backend("ini"); int ch; - while ((ch = getopt(argc, argv, "cf:hLlm:NnOP:p:q:Ss:Tt:xV")) != EOF) { + while ((ch = getopt(argc, argv, "cf:hLlm:NnOP:p:q:Ss:Tt:xV-:")) != EOF) { switch (ch) { case 'c': cflag = true; @@ -257,10 +263,15 @@ break; case 'q': - /* TODO: Implement better query parsing */ - if (strcmp(optarg, "sections") != 0) - errx(1, "Only the 'sections' query is supported for the present"); - qsections = true; + if (strcmp(optarg, "sections") == 0) { + qsections = true; + } else if (strcmp(optarg, "feature") == 0) { + qfeature = true; + } else if (strcmp(optarg, "features") == 0) { + qfeatures = true; + } else { + errx(1, "Unsupported query type"); + } break; case 'S': @@ -291,6 +302,15 @@ do_version = true; break; + case '-': + if (strcmp(optarg, "help") == 0) + do_help = true; + else if (strcmp(optarg, "version") == 0) + do_version = true; + else + errx(1, "Unknown long option"); + break; + case '?': default: usage(true); @@ -313,6 +333,37 @@ margc = argc - optind; margv = argv + optind; + const char * const features[][2] = { + { "BASE", "2.1" }, + { NULL, NULL }, + }; + if (qsections + qfeature + qfeatures > 1) { + errx(1, "Only a single query at a time, please!"); + } else if (qfeatures) { + if (margc > 0) + errx(1, "No arguments with -q features"); + bool started = false; + for (size_t i = 0; features[i][0] != NULL; i++) { + if (started) + putchar(' '); + else + started = true; + printf("%s=%s", features[i][0], features[i][1]); + } + putchar('\n'); + exit(0); + } else if (qfeature) { + if (margc != 1) + errx(1, "A single feature name expected"); + for (size_t i = 0; features[i][0] != NULL; i++) + if (strcmp(margv[0], features[i][0]) == 0) { + puts(features[i][1]); + exit(0); + } + /* Feature not found */ + exit(1); + } + if (cflag && (lflag || Lflag)) errx(1, "The -c flag may not be used with -l or -L"); if (margc == 0 && !lflag && !qsections) diff -Nru confget-2.0.0/debian/changelog confget-2.1.0/debian/changelog --- confget-2.0.0/debian/changelog 2017-09-25 09:24:14.000000000 +0000 +++ confget-2.1.0/debian/changelog 2017-11-11 21:21:21.000000000 +0000 @@ -1,3 +1,13 @@ +confget (2.1.0-1) unstable; urgency=medium + + * Declare compliance with Debian Policy 4.1.1 with no changes. + * Let dpkg-buildflags take care of the LFS compiler and linker flags. + * New upstream version; update the copyright years. + * Add "Rules-Requires-Root: no" to the source control stanza and + override the upstream Makefile's install(1) invocations. + + -- Peter Pentchev Sat, 11 Nov 2017 23:21:21 +0200 + confget (2.0.0-3) unstable; urgency=medium * Update the package for compliance with Debian Policy 4.1.0: diff -Nru confget-2.0.0/debian/control confget-2.1.0/debian/control --- confget-2.0.0/debian/control 2017-09-25 09:20:11.000000000 +0000 +++ confget-2.1.0/debian/control 2017-11-11 21:08:26.000000000 +0000 @@ -3,10 +3,11 @@ Priority: optional Maintainer: Peter Pentchev Build-Depends: debhelper (>> 10.8~), libpcre3-dev -Standards-Version: 4.1.0 +Standards-Version: 4.1.1 Homepage: https://devel.ringlet.net/textproc/confget/ Vcs-Git: https://gitlab.com/confget/confget.git -b debian Vcs-Browser: https://gitlab.com/confget/confget/tree/debian +Rules-Requires-Root: no Package: confget Architecture: any diff -Nru confget-2.0.0/debian/copyright confget-2.1.0/debian/copyright --- confget-2.0.0/debian/copyright 2016-11-17 12:08:57.000000000 +0000 +++ confget-2.1.0/debian/copyright 2017-11-11 21:08:26.000000000 +0000 @@ -5,7 +5,7 @@ License: BSD-2-clause Files: * -Copyright: Copyright (c) 2008 - 2016 Peter Pentchev +Copyright: Copyright (c) 2008 - 2017 Peter Pentchev License: BSD-2-clause Files: makedep.sh t/t1.ini t/t2.ini t/t3.ini @@ -14,7 +14,7 @@ This file is hereby placed in the public domain. Files: debian/* -Copyright: Copyright (c) 2008 - 2014, 2016 Peter Pentchev +Copyright: Copyright (c) 2008 - 2014, 2016, 2017 Peter Pentchev License: BSD-2-clause License: BSD-2-clause diff -Nru confget-2.0.0/debian/rules confget-2.1.0/debian/rules --- confget-2.0.0/debian/rules 2017-09-25 08:44:41.000000000 +0000 +++ confget-2.1.0/debian/rules 2017-11-11 21:08:26.000000000 +0000 @@ -3,7 +3,7 @@ # Debian build rules for confget, the configuration variable extractor # Aim for the top, adapt if anything should break on the buildds. -DEB_BUILD_MAINT_OPTIONS= hardening=+all +DEB_BUILD_MAINT_OPTIONS= hardening=+all future=+lfs export DEB_BUILD_MAINT_OPTIONS DEB_CFLAGS_MAINT_APPEND= -pipe -Wall -W -std=c99 -pedantic -Wbad-function-cast \ @@ -18,17 +18,15 @@ export PCRE_CPPFLAGS=-DHAVE_PCRE export PCRE_LIBS=-lpcre -# Large File Support -LFS_CPPFLAGS:= $(shell getconf LFS_CFLAGS 2>/dev/null || echo "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64") -LFS_LDFLAGS:= $(shell getconf LFS_LDFLAGS 2>/dev/null || true) -export LFS_CPPFLAGS LFS_LDFLAGS - ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES))) DEB_NODOC=0 else DEB_NODOC=1 endif +override_dh_auto_build: + dh_auto_build -- LFS_CPPFLAGS= LFS_LDFLAGS= + override_dh_auto_install: ifeq (${DEB_NODOC},1) mv -f Makefile Makefile.bak @@ -36,7 +34,9 @@ endif dh_auto_install -- DESTDIR=${CURDIR}/debian/confget PREFIX=/usr \ MANDIR=/usr/share/man/man BINGRP=root MANGRP=root \ - EXAMPLESDIR=/usr/share/doc/confget/examples + EXAMPLESDIR=/usr/share/doc/confget/examples \ + INSTALL_PROGRAM='install -m 755' \ + INSTALL_SCRIPT='install -m 755' INSTALL_DATA='install -m 644' ifeq (${DEB_NODOC},1) mv -f Makefile.bak Makefile endif diff -Nru confget-2.0.0/Makefile confget-2.1.0/Makefile --- confget-2.0.0/Makefile 2016-04-04 19:21:47.000000000 +0000 +++ confget-2.1.0/Makefile 2017-11-11 21:07:36.000000000 +0000 @@ -1,4 +1,4 @@ -# Copyright (c) 2008, 2009, 2011, 2012, 2013, 2016 Peter Pentchev +# Copyright (c) 2008, 2009, 2011 - 2013, 2016, 2017 Peter Pentchev # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -64,14 +64,18 @@ BINGRP?= wheel BINMODE?= 555 -MANOWN?= ${BINOWN} -MANGRP?= ${BINGRP} -MANMODE?= 644 - SHAREOWN?= ${BINOWN} SHAREGRP?= ${BINGRP} SHAREMODE?= 644 +INSTALL?= install +COPY?= -c +STRIP?= -s + +INSTALL_PROGRAM?= ${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} +INSTALL_SCRIPT?= ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} +INSTALL_DATA?= ${INSTALL} ${COPY} -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} + # development/debugging flags, you may safely ignore them BDECFLAGS= -W -Wall -std=c99 -pedantic -Wbad-function-cast -Wcast-align \ -Wcast-qual -Wchar-subscripts -Winline \ @@ -102,16 +106,16 @@ install-bin: -${MKDIR} ${DESTDIR}${BINDIR} - install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}/ + ${INSTALL_PROGRAM} ${PROG} ${DESTDIR}${BINDIR}/ install-man: -${MKDIR} ${DESTDIR}${MANDIR}1 - install -c -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} ${MAN1GZ} ${DESTDIR}${MANDIR}1/ + ${INSTALL_DATA} ${MAN1GZ} ${DESTDIR}${MANDIR}1/ install-examples: -${MKDIR} ${DESTDIR}${EXAMPLESDIR}/tests - install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} t/*.t ${DESTDIR}${EXAMPLESDIR}/tests/ - install -c -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} t/*.ini ${DESTDIR}${EXAMPLESDIR}/tests/ + ${INSTALL_SCRIPT} t/*.t ${DESTDIR}${EXAMPLESDIR}/tests/ + ${INSTALL_DATA} t/*.ini ${DESTDIR}${EXAMPLESDIR}/tests/ depend: touch readaline.h diff -Nru confget-2.0.0/t/13-features.t confget-2.1.0/t/13-features.t --- confget-2.0.0/t/13-features.t 1970-01-01 00:00:00.000000000 +0000 +++ confget-2.1.0/t/13-features.t 2017-11-11 21:07:36.000000000 +0000 @@ -0,0 +1,110 @@ +#!/bin/sh +# +# Copyright (c) 2008, 2011, 2017 Peter Pentchev +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +[ -z "$CONFGET" ] && CONFGET='./confget' + +echo '1..11' + +# First, make sure '-q features' reports 'BASE=...' +all="$($CONFGET -q features)" +if [ -n "$all" ]; then + echo 'ok 1' +else + echo 'not ok 1 -q features did not output anything' +fi + +if [ "${all%%=*}" = 'BASE' ]; then + base_and_all="${all#BASE=}" +else + base_and_all="${all#* BASE=}" +fi +if [ "$base_and_all" != "$all" ]; then + echo 'ok 2' +else + echo "not ok 2 -q features did not contain 'BASE=': $all" +fi + +just_base="${base_and_all%% *}" +if [ -n "$just_base" ]; then + echo 'ok 3' +else + echo "not ok 3 -q features contained an empty 'BASE=': $all" +fi + +second_base="${base_and_all#* BASE=}" +if [ "$base_and_all" = "$second_base" ]; then + echo 'ok 4' +else + echo "not ok 4 -q features contained more than one 'BASE=': $all" +fi + +# Now check that '-q feature BASE' outputs BASE +base="$($CONFGET -q feature BASE)" +if [ "$base" = "$just_base" ]; then + echo 'ok 5' +else + echo "not ok 5 -q feature BASE did not return the same string as in -q features: '$just_base' vs '$base'" +fi + +# Now for some failure cases... +res=0 +out="$($CONFGET -q features something 2>/dev/null)" || res="$?" +if [ "$res" -ne 0 ]; then + echo 'ok 6' +else + echo "not ok 6 '-q features' with an argument succeeded" +fi +if [ "$out" = '' ]; then + echo 'ok 7' +else + echo "not ok 7 '-q features' with an argument output something: $out" +fi + +res=0 +out="$($CONFGET -q feature 2>/dev/null)" || res="$?" +if [ "$res" -ne 0 ]; then + echo 'ok 8' +else + echo "not ok 8 '-q feature' with no argument succeeded" +fi +if [ "$out" = '' ]; then + echo 'ok 9' +else + echo "not ok 9 '-q feature' with no argument output something: $out" +fi + +res=0 +out="$($CONFGET -q feature BASE something 2>/dev/null)" || res="$?" +if [ "$res" -ne 0 ]; then + echo 'ok 10' +else + echo "not ok 10 '-q feature' with two arguments succeeded" +fi +if [ "$out" = '' ]; then + echo 'ok 11' +else + echo "not ok 11 '-q feature' with two arguments output something: $out" +fi