Give up and use autotools and CDBS.
*.o
stamp
space
+Makefile.in
+aclocal.m4
+config
+configure
+COPYING
--- /dev/null
+COPYING
+config/confsubst
+++ /dev/null
-## Makefile for miscellaneous stuff
-##
-## No proper build system here. Just kludgy hacks.
-
-PACKAGE = nsict-utils
-VERSION = 1.1.1
-
-BINSCRIPTS = \
- cdb-assign cdb-map cdb-list check-sender unfwd \
- splitconf z buf create inplace
-SBINSCRIPTS = shadowfix
-SCRIPTS = $(BINSCRIPTS) $(SBINSCRIPTS)
-BINPROGS = \
- space not \
- cdb-probe cdb-check-domain \
- gorp locking if-mtu pause stamp
-SBINPROGS = qmail-checkspam
-PROGS = $(BINPROGS) $(SBINPROGS)
-PERLLIBS = MdwOpt.pm
-LIBS = xtitle.so
-DISTMAN1 = \
- not.1 z.1 cdb-assign.1 cdb-map.1 cdb-list.1 cdb-probe.1 \
- cdb-check-domain.1 \
- gorp.1 unfwd.1 splitconf.1 locking.1 if-mtu.1 pause.1 stamp.1 \
- buf.1 create.1 inplace.1
-MAN1 = $(DISTMAN1)
-DISTMAN8 = qmail-checkspam.8
-MAN8 = $(DISTMAN8) shadowfix.8
-BUILDFILES = shadowfix.8
-SOURCES = \
- not.c cdb-probe.c cdb-check-domain.c gorp.c locking.c if-mtu.c \
- qmail-checkspam.c xtitle.c pause.c
-
-CC = gcc
-LD = gcc
-CFLAGS = -O2 -g -pedantic -Wall -DVERSION=\"$(VERSION)\"
-LINK = $(LD) $(LDFLAGS) -o $@ $^
-
-INST =
-prefix = /usr/local
-bindir = $(prefix)/bin
-sbindir = $(prefix)/sbin
-mandir = $(prefix)/man
-man1dir = $(mandir)/man1
-man8dir = $(mandir)/man8
-libdir = $(prefix)/lib
-perllibdir = $(libdir)/site_perl
-
-all: $(BUILDFILES) $(PROGS) $(LIBS)
-
-install: all
- [ -d $(INST)$(libdir) ] || install -d $(INST)$(libdir)
- install -m644 $(LIBS) $(INST)$(libdir)
- [ -d $(INST)$(perllibdir) ] || install -d $(INST)$(perllibdir)
- install -m644 $(PERLLIBS) $(INST)$(perllibdir)
- [ -d $(INST)$(bindir) ] || install -d $(INST)$(bindir)
- install -m775 $(BINPROGS) $(BINSCRIPTS) $(INST)$(bindir)
- [ -d $(INST)$(sbindir) ] || install -d $(INST)$(sbindir)
- install -m775 $(SBINPROGS) $(SBINSCRIPTS) $(INST)$(sbindir)
- [ -d $(INST)$(man1dir) ] || install -d $(INST)$(man1dir)
- install -m644 $(MAN1) $(INST)$(man1dir)
- [ -d $(INST)$(man8dir) ] || install -d $(INST)$(man8dir)
- install -m644 $(MAN8) $(INST)$(man8dir)
-
-uninstall:
- for i in $(LIBS); do rm -f $(INST)$(libdir)/$$i; done
- for i in $(PERLLIBS); do rm -f $(INST)$(perllibdir)/$$i; done
- for i in $(BINPROGS) $(BINSCRIPTS); do \
- rm -f $(INST)$(bindir)/$$i; done
- for i in $(SBINPROGS) $(SBINSCRIPTS); do \
- rm -f $(INST)$(sbindir)/$$i; done
- for i in $(MAN1); do rm -f $(INST)$(man1dir)/$$i; done
- for i in $(MAN8); do rm -f $(INST)$(man8dir)/$$i; done
-
-qmail-checkspam: qmail-checkspam.o
- $(LINK) -lspamc
-
-cdb-probe: cdb-probe.o
- $(LINK) -lcdb
-
-cdb-check-domain: cdb-check-domain.o
- $(LINK) -lcdb
-
-space: space.o
- $(LINK)
-
-not: not.o
- $(LINK)
-
-xtitle.o: xtitle.c
- $(CC) $(CFLAGS) -c -fpic -I/usr/include/bash -DBASH_BUILTIN -o $@ $^
-xtitle.so: xtitle.o
- $(LINK) -shared
-
-gorp: gorp.o
- $(LINK) -lcatacomb -lmLib
-
-pause: pause.o
- $(LINK) -lmLib
-
-locking: locking.o
- $(LINK) -lmLib
-
-if-mtu: if-mtu.o
- $(LINK)
-
-stamp: stamp.o
- $(LINK) -lmLib
-
-shadowfix.8: shadowfix
- pod2man --section 8 shadowfix >shadowfix.8.new
- mv shadowfix.8.new shadowfix.8
-
-clean:; rm -f *.o *~ $(PROGS) $(OTHERS)
-
-DISTDIR = $(PACKAGE)-$(VERSION)
-DISTFILES = \
- Makefile \
- $(SCRIPTS) $(DISTMAN1) $(DISTMAN8) $(SOURCES) $(PERLLIBS) \
- debian/changelog debian/control debian/copyright \
- debian/rules debian/inst
-distdir: $(DISTFILES)
- $(RM) -rf $(DISTDIR)
- mkdir $(DISTDIR) $(DISTDIR)/debian
- for i in $(DISTFILES); do \
- case $$i in \
- */*) \
- dir=$${i%/*}; \
- up=`echo $$dir | sed 's:[^/]\+:..:g'`; \
- mkdir -p $(DISTDIR)/$$dir;; \
- *) dir= up=;; \
- esac; \
- ln -s ../$$up/$$i $(DISTDIR)/$$i; \
- done
-disttar: distdir
- tar chofz $(INST)$(DISTDIR).tar.gz $(DISTDIR)
-dist: disttar
- $(RM) -rf $(DISTDIR)
-distcheck: dist
- @echo "*** Packing..."
- $(MAKE) dist
- @echo "*** Unpacking..."
- tar xfz $(DISTDIR).tar.gz
- @echo "*** Test building..."
- set -e; \
- cd $(DISTDIR); \
- $(MAKE) clean; \
- $(MAKE); \
- $(MAKE) install INST=inst; \
- $(MAKE) dist
- @echo "*** Tidying up..."
- rm -rf $(DISTDIR)
- @echo "*** All OK"
-
-.PHONY: all clean install dist distdir disttar
--- /dev/null
+### -*-makefile-*-
+###
+### Build script for nsict-utils
+###
+### (c) 2008 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This program is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+###
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with this program; if not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+EXTRA_DIST =
+CLEANFILES =
+
+man_MANS =
+dist_man_MANS =
+
+###--------------------------------------------------------------------------
+### Tools in C.
+
+bin_PROGRAMS =
+sbin_PROGRAMS =
+
+AM_CFLAGS = $(mLib_CFLAGS) $(catacomb_CFLAGS)
+
+## space
+bin_PROGRAMS += space
+space_SOURCES = space.c
+dist_man_MANS += space.1
+
+## not
+bin_PROGRAMS += not
+not_SOURCES = not.c
+dist_man_MANS += not.1
+
+## if-mtu
+bin_PROGRAMS += if-mtu
+if_mtu_SOURCES = if-mtu.c
+dist_man_MANS += if-mtu.1
+
+## xtitle
+bin_PROGRAMS += xtitle
+xtitle_SOURCES = xtitle.c
+## !UNDOCUMENTED
+
+## pause
+if HAVE_MLIB
+bin_PROGRAMS += pause
+pause_SOURCES = pause.c
+pause_LDADD = $(mLib_LIBS) $(MATH_LIBS)
+dist_man_MANS += pause.1
+endif
+
+## stamp
+if HAVE_MLIB
+bin_PROGRAMS += stamp
+stamp_SOURCES = stamp.c
+stamp_LDADD = $(mLib_LIBS)
+dist_man_MANS += stamp.1
+endif
+
+## locking
+if HAVE_MLIB
+bin_PROGRAMS += locking
+locking_SOURCES = locking.c
+locking_LDADD = $(mLib_LIBS)
+dist_man_MANS += locking.1
+endif
+
+## gorp
+if HAVE_CATACOMB
+bin_PROGRAMS += gorp
+gorp_SOURCES = gorp.c
+gorp_LDADD = $(catacomb_LIBS)
+dist_man_MANS += gorp.1
+endif
+
+## qmail-checkspam
+if HAVE_LIBSPAMC
+sbin_PROGRAMS += qmail-checkspam
+qmail_checkspam_SOURCES = qmail-checkspam.c
+qmail_checkspam_LDADD = -lspamc
+dist_man_MANS += qmail-checkspam.8
+endif
+
+## cdb tools
+if HAVE_LIBCDB
+bin_PROGRAMS += cdb-probe cdb-check-domain
+cdb_probe_SOURCES = cdb-probe.c
+cdb_probe_LDADD = -lcdb
+cdb_check_domain_SOURCES = cdb-check-domain.c
+cdb_check_domain_LDADD = -lcdb
+dist_man_MANS += cdb-probe.1 cdb-check-domain.1
+endif
+
+###--------------------------------------------------------------------------
+### Tools in scripts.
+
+bin_SCRIPTS =
+dist_bin_SCRIPTS =
+sbin_SCRIPTS =
+dist_sbin_SCRIPTS =
+
+## Making substitutions.
+confsubst = $(top_srcdir)/config/confsubst
+SUBSTITUTIONS = \
+ PACKAGE=$(PACKAGE) VERSION=$(VERSION) \
+ PYTHON=$(PYTHON) \
+ PERL=$(PERL) \
+ TCLSH=$(TCLSH)
+
+EXTRA_DIST += config/confsubst
+
+## Shell scripts.
+dist_bin_SCRIPTS += check-sender
+dist_man_MANS += check-sender.1
+
+dist_bin_SCRIPTS += buf
+dist_man_MANS += buf.1
+
+dist_bin_SCRIPTS += create
+dist_man_MANS += create.1
+
+dist_bin_SCRIPTS += z
+dist_man_MANS += z.1
+
+## bash scripts.
+if HAVE_BASH
+
+bin_SCRIPTS += inplace
+CLEANFILES += inplace
+EXTRA_DIST += inplace.in
+dist_man_MANS += inplace.1
+
+inplace: inplace.in Makefile
+ $(confsubst) $(srcdir)/inplace.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+endif
+
+## Python scripts.
+if HAVE_PYTHON
+
+if HAVE_PYMOD_CDB
+bin_SCRIPTS += cdb-assign
+dist_man_MANS += cdb-assign.1
+endif
+
+CLEANFILES += cdb-assign
+EXTRA_DIST += cdb-assign.in
+
+cdb-assign: cdb-assign.in Makefile
+ $(confsubst) $(srcdir)/cdb-assign.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+if HAVE_PYMOD_CDB
+bin_SCRIPTS += cdb-list
+dist_man_MANS += cdb-list.1
+endif
+
+CLEANFILES += cdb-list
+EXTRA_DIST += cdb-list.in
+
+cdb-list: cdb-list.in Makefile
+ $(confsubst) $(srcdir)/cdb-list.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+if HAVE_PYMOD_CDB
+bin_SCRIPTS += cdb-map
+dist_man_MANS += cdb-map.1
+endif
+
+CLEANFILES += cdb-map
+EXTRA_DIST += cdb-map.in
+
+cdb-map: cdb-map.in Makefile
+ $(confsubst) $(srcdir)/cdb-map.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+endif
+
+## Perl scripts.
+if HAVE_PERL
+
+sbin_SCRIPTS += shadowfix
+CLEANFILES += shadowfix
+EXTRA_DIST += shadowfix.in
+
+shadowfix: shadowfix.in Makefile
+ $(confsubst) $(srcdir)/shadowfix.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+man_MANS += shadowfix.8
+CLEANFILES += shadowfix.8
+
+shadowfix.8: shadowfix.in
+ pod2man --section 8 $(srcdir)/shadowfix.in >$@.new && mv $@.new $@
+
+bin_SCRIPTS += unfwd
+CLEANFILES += unfwd
+EXTRA_DIST += unfwd.in
+dist_man_MANS += unfwd.1
+
+unfwd: unfwd.in Makefile
+ $(confsubst) $(srcdir)/unfwd.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+endif
+
+## Perl modules.
+if HAVE_PERL
+dist_perlmod_DATA = MdwOpt.pm
+endif
+
+## Tcl scripts.
+if HAVE_TCLSH
+
+bin_SCRIPTS += splitconf
+CLEANFILES += splitconf
+EXTRA_DIST += splitconf.in
+dist_man_MANS += splitconf.1
+
+splitconf: splitconf.in Makefile
+ $(confsubst) $(srcdir)/splitconf.in >$@.new $(SUBSTITUTIONS) && \
+ chmod +x $@.new && mv $@.new $@
+
+endif
+
+###----- That's all, folks --------------------------------------------------
-#! /usr/bin/python
+#! @PYTHON@
from cdb import cdbmake
from sre import compile as r_compile, sub as r_sub
-#! /usr/bin/python
+#! @PYTHON@
from cdb import cdbmake
from sre import compile as r_compile, sub as r_sub
-#! /usr/bin/python
+#! @PYTHON@
from cdb import cdbmake
from sre import sub as r_sub
--- /dev/null
+dnl -*-autoconf-*-
+dnl
+dnl Configuration script for nsict-utils
+dnl
+dnl (c) 2008 Mark Wooding
+dnl
+
+dnl ----- Licensing notice --------------------------------------------------
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software Foundation,
+dnl Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+dnl--------------------------------------------------------------------------
+dnl Initialization.
+
+mdw_AUTO_VERSION
+AC_INIT([nsict-utils], AUTO_VERSION, [mdw@distorted.org.uk])
+AC_CONFIG_SRCDIR([shadowfix.in])
+AC_CONFIG_AUX_DIR([config])
+AM_INIT_AUTOMAKE([foreign])
+
+dnl--------------------------------------------------------------------------
+dnl C programming environment.
+
+## Compiler.
+AC_PROG_CC
+AX_CFLAGS_WARN_ALL
+
+## Libraries.
+OLIBS=$LIBS
+AC_SEARCH_LIBS([floor], [m])
+AC_SUBST([MATH_LIBS], [$LIBS])
+LIBS=$OLIBS
+
+AC_CHECK_LIB([cdb], [cdb_seek], [have_cdb=yes], [have_cdb=no])
+AM_CONDITIONAL([HAVE_LIBCDB], [test $have_cdb = yes])
+
+AC_CHECK_LIB([spamc], [message_filter], [have_spamc=yes], [have_spamc=no])
+AM_CONDITIONAL([HAVE_LIBSPAMC], [test $have_spamc = yes])
+
+## Packages.
+PKG_CHECK_MODULES([mLib], [mLib >= 2.0.4], [have_mLib=yes], [have_mLib=no])
+AM_CONDITIONAL([HAVE_MLIB], [test $have_mLib = yes])
+
+PKG_CHECK_MODULES([catacomb], [catacomb >= 2.1.1],
+ [have_catacomb=yes], [have_catacomb=no])
+AM_CONDITIONAL([HAVE_CATACOMB], [test $have_catacomb = yes])
+
+dnl--------------------------------------------------------------------------
+dnl Python, Perl and other scripting languages.
+
+## Python.
+AM_PATH_PYTHON([2.4], [have_python=yes], [have_python=no])
+AM_CONDITIONAL([HAVE_PYTHON], [test $have_python = yes])
+
+AC_PYTHON_MODULE([cdb])
+AM_CONDITIONAL([HAVE_PYMOD_CDB], [test $HAVE_PYMOD_CDB = yes])
+
+## Perl.
+AC_ARG_VAR([PERL], [Path to your favourite Perl binary.])
+AC_PATH_PROGS([PERL], [perl perl5], [false])
+AC_PROG_PERL_VERSION([5.004], [have_perl=yes], [have_perl=no])
+AM_CONDITIONAL([HAVE_PERL], [test $have_perl = yes])
+
+AC_ARG_WITH(
+ [perlmoddir],
+ AS_HELP_STRING([--perlmoddir=DIR],
+ [Install Perl modules here.]),
+ [perlmoddir=$withval],
+ [perlmoddir='${libdir}/site_perl'])
+AC_SUBST([perlmoddir])
+
+## Tcl.
+have_tcl=yes
+AC_ARG_VAR([TCLSH], [Path to your favourite tclsh binary.])
+AC_PATH_PROG([TCLSH], [tclsh], [false])
+
+AC_MSG_CHECKING([Tcl version])
+case "$TCLSH" in false) have_tcl=no ;; esac
+case "$have_tcl" in
+ yes)
+ tclver=$(echo "puts \$tcl_version" | tclsh -)
+ tclver_hack=$(echo "$tclver" | sed 's/\.//')
+ if test "$tclver_hack" -ge 83; then
+ AC_MSG_RESULT([$tclver])
+ else
+ have_tcl=no
+ AC_MSG_RESULT([too old ($tclver)])
+ fi
+esac
+AM_CONDITIONAL([HAVE_TCLSH], [test $have_tcl = yes])
+
+## Bash.
+case "$BASH" in /bin/sh) unset BASH ;; esac
+AC_ARG_VAR([BASH], [Path to the Bourne Again Shell.])
+AC_PATH_PROG([BASH], [bash], [false])
+AC_MSG_CHECKING([bash version])
+bashver=$("$BASH" -c 'echo $BASH_VERSION')
+if "$BASH" 2>/dev/null -c '[[[ ${BASH_VERSINFO[0]} -ge 3 ]]]'; then
+ have_bash=yes
+ AC_MSG_RESULT([$bashver])
+else
+ have_bash=no
+ AC_MSG_RESULT([too old ($bashver)])
+fi
+AM_CONDITIONAL([HAVE_BASH], [test $have_bash = yes])
+
+dnl--------------------------------------------------------------------------
+dnl Output.
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+
+dnl ----- That's all, folks -------------------------------------------------
buf
create
inplace
-
+*.install
+stamp-*
+tmp
+compat
Section: utils
Priority: extra
Maintainer: Mark Wooding <mdw@distorted.org.uk>
-Build-Depends: tinycdb, bash-builtins, debhelper (>= 4.0.2), python,
- catacomb-dev (>= 2.0.0), mlib-dev (>= 2.0.0), libspamc-dev
+Build-Depends: tinycdb, cdbs, python, python-cdb,
+ catacomb-dev (>= 2.1.1), mlib-dev (>= 2.0.4), libspamc-dev
Standards-Version: 3.1.1
Package: nsict-utils
Package: nsict-cdb
Architecture: any
Section: utils
-Depends: ${shlibs:Depends}, ${python:Depends}, python-cdb
+Depends: ${shlibs:Depends}, python (>= 2.4), python-cdb
Description: Simple utilities for messing with CDB files.
Package: locking
Package: xtitle
Architecture: any
-Depends: ${shlibs:Depends}, bash (>= 2.0.0)
+Depends: ${shlibs:Depends}
Recommends: x-terminal-emulator
Section: utils
-Description: Bash builtin for messing with xterm title bars.
+Description: Simple program for messing with xterm (or compatible) title bars.
Package: splitconf
Architecture: all
create.1 create /usr/share/man/man1
gorp gorp /usr/bin
gorp.1 gorp /usr/share/man/man1
-if-mtu if-mtu /usr/sbin
+if-mtu if-mtu /usr/bin
if-mtu.1 if-mtu /usr/share/man/man1
inplace inplace /usr/bin
inplace.1 inplace /usr/share/man/man1
stamp.1 stamp /usr/share/man/man1
unfwd nsict-mail /usr/bin
unfwd.1 nsict-mail /usr/share/man/man1
-xtitle.so xtitle /usr/lib/bash
+xtitle xtitle /usr/bin
z zz /usr/bin
z.1 zz /usr/share/man/man1
#! /usr/bin/make -f
-export DH_COMPAT = 4
-
-build:
- make
- touch build
-
-clean:
- dh_clean
- make clean
- rm -f build
-
-install: build
- dh_clean
- while read file package dir; do \
- mkdir -p debian/$$package$$dir; \
- cp $$file debian/$$package$$dir/$$file; \
- done <debian/inst
- mkdir -p debian/nsict-utils
-
-binary-indep:
- dh_testdir -i
- dh_testroot -i
- dh_compress -i
- dh_installdocs -i
- dh_perl -i
- dh_python -i
- dh_gencontrol -i
- dh_fixperms -i
- dh_installdeb -i
- dh_md5sums -i
- dh_builddeb -i
-
-binary-arch:
- dh_testdir -a
- dh_testroot -a
- dh_compress -a
- dh_installdocs -a
- dh_strip -a
- dh_shlibdeps -a
- dh_python -a
- dh_gencontrol -a
- dh_fixperms -a
- dh_installdeb -a
- dh_md5sums -a
- dh_builddeb -a
-
-binary: install binary-indep binary-arch
-
-source:
- rm -rf =inst=
- mkdir -p =inst=/=deb=
- make dist INST==inst=/
- cd =inst=/=deb=; tar xvfz ../*.tar.gz
- d=`pwd`; cd ..; dpkg-source -i -b $$d/=inst=/=deb=/*
- rm -rf =inst=
-
-.PHONY: binary binary-arch binary-indep clean install source
+CDBS = /usr/share/cdbs/1
+
+include $(CDBS)/class/autotools.mk
+include $(CDBS)/rules/debhelper.mk
+
+###--------------------------------------------------------------------------
+### General settings.
+
+DEB_BUILDDIR = $(CURDIR)/build
+
+###--------------------------------------------------------------------------
+### Correct configuration.
+
+DEB_CONFIGURE_EXTRA_FLAGS = \
+ --with-perlmoddir=/usr/share/perl5
+
+###--------------------------------------------------------------------------
+### Installation.
+###
+### Rather than have lots (and /lots/) of little *.install files, we just
+### have one big list of everything and split it out as we go.
+
+clean::; rm -f debian/*.install
+
+$(addprefix install/, $(DEB_ALL_PACKAGES)):: install/%: debian/%.install
+
+debian/%.install: debian/inst
+ while read file pkg dir; do \
+ if [ "$$pkg" = "$*" ]; then \
+ echo "debian/tmp$$dir/$$file"; \
+ fi; \
+ done <debian/inst >$@.new && mv $@.new $@
+
+###----- That's all, folks --------------------------------------------------
-#! /bin/bash
+#! @BASH@
set -e
usage () { echo >&2 "$0 FILE ... -- PROG ARGS"; exit 1; }
-#! /usr/bin/perl
+#! @PERL@
#
# Sanitise Linux password and group databases
#
-#! /usr/bin/tclsh
+#! @TCLSH@
#----- Miscellaneous utilities ----------------------------------------------
#include <string.h>
#include <fcntl.h>
-#ifdef BASH_BUILTIN
-#include "bash/config.h"
-#include "bash/shell.h"
-#include "bash/builtins.h"
-#include "bash/builtins/common.h"
-#include "bash/builtins/bashgetopt.h"
-#endif
-
-#ifdef BASH_BUILTIN
-int xtitle_builtin(WORD_LIST *list)
-#else
int main(int argc, char *argv[])
-#endif
{
int query = 0;
int fd;
int openned = 0;
+ int i;
-#ifdef BASH_BUILTIN
- reset_internal_getopt();
-#endif
for (;;) {
-#ifdef BASH_BUILTIN
- int i;
- i = internal_getopt(list, "q");
-#else
- int i = getopt(argc, argv, "q");
-#endif
+ i = getopt(argc, argv, "q");
if (i < 0)
break;
switch (i) {
query = 1;
break;
default:
-#ifdef BASH_BUILTIN
- builtin_usage();
-#else
- fprintf(stderr, "usage: xtitle [-q] [string]\n");
-#endif
+ fprintf(stderr, "usage: xtitle [-q] [STRING]\n");
return (1);
}
}
-#ifdef BASH_BUILTIN
- if (!query && loptend == 0) {
-#else
if (!query && optind == argc) {
-#endif
fprintf(stderr, "xtitle: no string to set\n");
return (1);
}
}
if (!query) {
-#ifdef BASH_BUILTIN
- WORD_LIST *l = loptend;
- char sp = ' ';
- write(fd, "\33]0;", 4);
- while (l) {
- write(fd, l->word->word, strlen(l->word->word));
- if (l->next)
- write(fd, &sp, 1);
- l = l->next;
- }
- write(fd, "\7", 2);
-#else
- int i;
char sp = ' ';
write(fd, "\33]0;", 4);
for (i = optind; i < argc; i++) {
write(fd, &sp, 1);
}
write(fd, "\7", 2);
-#endif
} else {
struct termios o, n;
char hack;
return (0);
}
-
-
-#ifdef BASH_BUILTIN
-
-static char *xtitle_doc[] = {
- "Either set or read the title of the current xterm window. With the",
- "-q option, writes the current xterm title to standard output. Without",
- "the -q option, sets the xterm title to be the arguments given,",
- "separated by space characters. [By Mark Wooding, mdw@nsict.org]",
- 0
-};
-
-struct builtin xtitle_struct = {
- "xtitle",
- xtitle_builtin,
- BUILTIN_ENABLED,
- xtitle_doc,
- "xtitle [-q] [arguments]",
- 0
-};
-
-#endif