Replace m4 macros with use of libmakepkg extensions.
Signed-off-by: Eli Schwartz <eschwartz(a)archlinux.org>
---
configure.ac | 5 ++
lib/Makefile.am | 5 +-
lib/output_format.sh | 32 ----------
lib/parseopts.sh | 137 -----------------------------------------
lib/term_colors.sh | 21 -------
src/Makefile.am | 9 +--
src/checkupdates.sh.in | 20 ++++--
src/paccache.sh.in | 14 ++++-
src/pacdiff.sh.in | 12 +++-
9 files changed, 48 insertions(+), 207 deletions(-)
delete mode 100644 lib/output_format.sh
delete mode 100644 lib/parseopts.sh
delete mode 100644 lib/term_colors.sh
diff --git a/configure.ac b/configure.ac
index ecb34db..82c16b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,10 @@ PKG_CHECK_MODULES(LIBARCHIVE, [libarchive >= 2.8.0], ,
PKG_CHECK_MODULES(LIBALPM, [libalpm], ,
AC_MSG_ERROR([*** libalpm is needed to build pacman-contrib!]))
+PKG_CHECK_VAR(LIBMAKEPKGDIR, [libmakepkg], [libmakepkgdir], ,
+ AC_MSG_ERROR([*** libmakepkg is needed to build pacman-contrib!]))
+AC_SUBST(LIBMAKEPKGDIR)
+
# Enable or disable use of git version in version string
AC_MSG_CHECKING(whether to use git version if available)
if test "x$wantgitver" = "xyes" ; then
@@ -173,6 +177,7 @@ ${PACKAGE_NAME}:
localstatedir : $(eval echo ${localstatedir})
database dir : $(eval echo ${localstatedir})/lib/pacman/
cache dir : $(eval echo ${localstatedir})/cache/pacman/pkg/
+ libmakepkg dir : $(eval echo ${LIBMAKEPKGDIR})
compiler : ${CC}
compiler flags : ${WARNING_CFLAGS} ${CFLAGS}
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8b18cb5..c7a1385 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,9 +3,6 @@ SUBDIRS=
DIST_SUBDIRS = $(SUBDIRS)
EXTRA_DIST = \
- output_format.sh \
- parseopts.sh \
- size_to_human.sh \
- term_colors.sh
+ size_to_human.sh
# vim:set noet:
diff --git a/lib/output_format.sh b/lib/output_format.sh
deleted file mode 100644
index 9f02c00..0000000
--- a/lib/output_format.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-plain() {
- (( QUIET )) && return
- local mesg=$1; shift
- printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
-}
-
-msg() {
- (( QUIET )) && return
- local mesg=$1; shift
- printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
-}
-
-msg2() {
- (( QUIET )) && return
- local mesg=$1; shift
- printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
-}
-
-ask() {
- local mesg=$1; shift
- printf "${BLUE}::${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}" "$@" >&1
-}
-
-warning() {
- local mesg=$1; shift
- printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-error() {
- local mesg=$1; shift
- printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
diff --git a/lib/parseopts.sh b/lib/parseopts.sh
deleted file mode 100644
index cf6aa6c..0000000
--- a/lib/parseopts.sh
+++ /dev/null
@@ -1,137 +0,0 @@
-# getopt-like parser
-parseopts() {
- local opt= optarg= i= shortopts=$1
- local -a longopts=() unused_argv=()
-
- shift
- while [[ $1 && $1 != '--' ]]; do
- longopts+=("$1")
- shift
- done
- shift
-
- longoptmatch() {
- local o longmatch=()
- for o in "${longopts[@]}"; do
- if [[ ${o%:} = "$1" ]]; then
- longmatch=("$o")
- break
- fi
- [[ ${o%:} = "$1"* ]] && longmatch+=("$o")
- done
-
- case ${#longmatch[*]} in
- 1)
- # success, override with opt and return arg req (0 == none, 1 == required)
- opt=${longmatch%:}
- if [[ $longmatch = *: ]]; then
- return 1
- else
- return 0
- fi ;;
- 0)
- # fail, no match found
- return 255 ;;
- *)
- # fail, ambiguous match
- printf "@SCRIPTNAME@: $(gettext "option '%s' is ambiguous; possibilities:")" "--$1"
- printf " '%s'" "${longmatch[@]%:}"
- printf '\n'
- return 254 ;;
- esac >&2
- }
-
- while (( $# )); do
- case $1 in
- --) # explicit end of options
- shift
- break
- ;;
- -[!-]*) # short option
- for (( i = 1; i < ${#1}; i++ )); do
- opt=${1:i:1}
-
- # option doesn't exist
- if [[ $shortopts != *$opt* ]]; then
- printf "@SCRIPTNAME@: $(gettext "invalid option") -- '%s'\n" "$opt" >&2
- OPTRET=(--)
- return 1
- fi
-
- OPTRET+=("-$opt")
- # option requires optarg
- if [[ $shortopts = *$opt:* ]]; then
- # if we're not at the end of the option chunk, the rest is the optarg
- if (( i < ${#1} - 1 )); then
- OPTRET+=("${1:i+1}")
- break
- # if we're at the end, grab the the next positional, if it exists
- elif (( i == ${#1} - 1 )) && [[ $2 ]]; then
- OPTRET+=("$2")
- shift
- break
- # parse failure
- else
- printf "@SCRIPTNAME@: $(gettext "option requires an argument") -- '%s'\n" "$opt" >&2
- OPTRET=(--)
- return 1
- fi
- fi
- done
- ;;
- --?*=*|--?*) # long option
- IFS='=' read -r opt optarg <<< "${1#--}"
- longoptmatch "$opt"
- case $? in
- 0)
- # parse failure
- if [[ $optarg ]]; then
- printf "@SCRIPTNAME@: $(gettext "option '%s' does not allow an argument")\n" "--$opt" >&2
- OPTRET=(--)
- return 1
- # --longopt
- else
- OPTRET+=("--$opt")
- fi
- ;;
- 1)
- # --longopt=optarg
- if [[ $optarg ]]; then
- OPTRET+=("--$opt" "$optarg")
- # --longopt optarg
- elif [[ $2 ]]; then
- OPTRET+=("--$opt" "$2" )
- shift
- # parse failure
- else
- printf "@SCRIPTNAME@: $(gettext "option '%s' requires an argument")\n" "--$opt" >&2
- OPTRET=(--)
- return 1
- fi
- ;;
- 254)
- # ambiguous option -- error was reported for us by longoptmatch()
- OPTRET=(--)
- return 1
- ;;
- 255)
- # parse failure
- printf "@SCRIPTNAME@: $(gettext "invalid option") '--%s'\n" "$opt" >&2
- OPTRET=(--)
- return 1
- ;;
- esac
- ;;
- *) # non-option arg encountered, add it as a parameter
- unused_argv+=("$1")
- ;;
- esac
- shift
- done
-
- # add end-of-opt terminator and any leftover positional parameters
- OPTRET+=('--' "${unused_argv[@]}" "$@")
- unset longoptmatch
-
- return 0
-}
diff --git a/lib/term_colors.sh b/lib/term_colors.sh
deleted file mode 100644
index 87e95ee..0000000
--- a/lib/term_colors.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-# check if messages are to be printed using color
-unset ALL_OFF BOLD BLUE GREEN RED YELLOW
-if [[ -t 2 && ! $USE_COLOR = "n" && ! $TERM = "dumb" ]]; then
- # prefer terminal safe colored and bold text when tput is supported
- if tput setaf 0 &>/dev/null; then
- ALL_OFF="$(tput sgr0)"
- BOLD="$(tput bold)"
- BLUE="${BOLD}$(tput setaf 4)"
- GREEN="${BOLD}$(tput setaf 2)"
- RED="${BOLD}$(tput setaf 1)"
- YELLOW="${BOLD}$(tput setaf 3)"
- else
- ALL_OFF="\e[1;0m"
- BOLD="\e[1;1m"
- BLUE="${BOLD}\e[1;34m"
- GREEN="${BOLD}\e[1;32m"
- RED="${BOLD}\e[1;31m"
- YELLOW="${BOLD}\e[1;33m"
- fi
-fi
-readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
diff --git a/src/Makefile.am b/src/Makefile.am
index 08dde4b..2efd416 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -92,10 +92,11 @@ AM_CFLAGS = \
$(LIBALPM_CFLAGS)
edit = sed \
- -e 's|@bindir[@]|${bindir}|g' \
+ -e 's|@bindir[@]|$(bindir)|g' \
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \
-e 's|@localstatedir[@]|$(localstatedir)|g' \
-e 's|@PACKAGE_VERSION[@]|$(REAL_PACKAGE_VERSION)|g' \
+ -e 's|@libmakepkgdir[@]|$(LIBMAKEPKGDIR)|g' \
-e 's|@SIZECMD[@]|$(SIZECMD)|g' \
-e 's|@SCRIPTNAME[@]|$@|g' \
-e '1s|!/bin/bash|!$(BASH_SHELL)|g' \
@@ -121,9 +122,9 @@ $(OURFILES): Makefile
all-am: $(OURSCRIPTS) $(OURFILES)
-checkupdates: $(srcdir)/checkupdates.sh.in $(top_srcdir)/lib/output_format.sh $(top_srcdir)/lib/term_colors.sh
-paccache: $(srcdir)/paccache.sh.in $(top_srcdir)/lib/output_format.sh $(top_srcdir)/lib/parseopts.sh $(top_srcdir)/lib/size_to_human.sh $(top_srcdir)/lib/term_colors.sh
-pacdiff: $(srcdir)/pacdiff.sh.in $(top_srcdir)/lib/output_format.sh $(top_srcdir)/lib/term_colors.sh
+checkupdates: $(srcdir)/checkupdates.sh.in
+paccache: $(srcdir)/paccache.sh.in
+pacdiff: $(srcdir)/pacdiff.sh.in
paclist: $(srcdir)/paclist.sh.in
paclog-pkglist: $(srcdir)/paclog-pkglist.sh.in
pacscripts: $(srcdir)/pacscripts.sh.in
diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in
index 0885983..eecb4a7 100644
--- a/src/checkupdates.sh.in
+++ b/src/checkupdates.sh.in
@@ -21,11 +21,14 @@
declare -r myname='checkupdates'
declare -r myver='@PACKAGE_VERSION@'
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
DOWNLOAD_CACHE=0
+USE_COLOR=0
-m4_include(../lib/output_format.sh)
-m4_include(../lib/term_colors.sh)
-m4_include(../lib/parseopts.sh)
+# Import libmakepkg
+source "$LIBRARY"/util/message.sh
+source "$LIBRARY"/util/parseopts.sh
usage() {
cat << __EOF__
@@ -45,7 +48,7 @@ __EOF__
}
OPT_SHORT='dh'
-OPT_LONG=('download' 'help')
+OPT_LONG=('download' 'help' 'nocolor')
if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
exit 1
@@ -60,6 +63,8 @@ while :; do
-h|--help)
usage
exit 0 ;;
+ --nocolor)
+ USE_COLOR='n';;
--)
shift
break ;;
@@ -67,6 +72,13 @@ while :; do
shift
done
+# check if messages are to be printed using color
+if [[ -t 2 && $USE_COLOR != "n" ]]; then
+ colorize
+else
+ unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+fi
+
if ! type -P fakeroot >/dev/null; then
error 'Cannot find the fakeroot binary.'
exit 1
diff --git a/src/paccache.sh.in b/src/paccache.sh.in
index c7265ba..af901f4 100644
--- a/src/paccache.sh.in
+++ b/src/paccache.sh.in
@@ -25,6 +25,8 @@ shopt -s extglob
declare -r myname='paccache'
declare -r myver='@PACKAGE_VERSION@'
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=()
declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0
declare -i min_atime=0 min_mtime=0
@@ -33,8 +35,9 @@ declare delim=$'\n' keep=3 movedir= scanarch=
QUIET=0
USE_COLOR='y'
-m4_include(../lib/output_format.sh)
-m4_include(../lib/parseopts.sh)
+# Import libmakepkg
+source "$LIBRARY"/util/message.sh
+source "$LIBRARY"/util/parseopts.sh
die() {
error "$@"
@@ -310,7 +313,12 @@ while :; do
shift
done
-m4_include(../lib/term_colors.sh)
+# check if messages are to be printed using color
+if [[ -t 2 && $USE_COLOR != "n" ]]; then
+ colorize
+else
+ unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+fi
# setting default cachedirs
if [[ -z $cachedirs ]]; then
diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in
index 8a70d4e..e3b8f8c 100644
--- a/src/pacdiff.sh.in
+++ b/src/pacdiff.sh.in
@@ -23,13 +23,16 @@ shopt -s extglob
declare -r myname='pacdiff'
declare -r myver='@PACKAGE_VERSION@'
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
diffprog=${DIFFPROG:-'vim -d'}
diffsearchpath=${DIFFSEARCHPATH:-/etc}
USE_COLOR='y'
declare -a oldsaves
declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
-m4_include(../lib/output_format.sh)
+# Import libmakepkg
+source "$LIBRARY"/util/message.sh
usage() {
cat <<EOF
@@ -116,7 +119,12 @@ while [[ -n "$1" ]]; do
shift
done
-m4_include(../lib/term_colors.sh)
+# check if messages are to be printed using color
+if [[ -t 2 && $USE_COLOR != "n" ]]; then
+ colorize
+else
+ unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+fi
if ! type -p ${diffprog%% *} >/dev/null && (( ! OUTPUTONLY )); then
error "Cannot find the $diffprog binary required for viewing differences."
--
2.23.0