chiark / gitweb /
Debianization.
[runlisp] / txtlib.in
1 #! /bin/sh
2
3 # -*-sh-*-
4 #
5 # $Id: txtlib.in,v 1.4 2003/09/24 22:45:57 mdw Exp $
6 #
7 # Manipulate simple libraries of text chunks
8 #
9 # (c) 1997 Mark Wooding
10 #
11
12 #----- Licensing notice -----------------------------------------------------
13 #
14 # This file is part of the Common Files Distribution (`common').
15 #
16 # `Common' is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # `Common' is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with `common'; if not, write to the Free Software Foundation,
28 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
30 #----- Revision history -----------------------------------------------------
31 #
32 # $Log: txtlib.in,v $
33 # Revision 1.4  2003/09/24 22:45:57  mdw
34 # Support Automake's `aclocal' scheme.  Deposit Autoconf fragments in
35 # `aclocal's' repository.  Apply heinous bodging to `txtlib' and
36 # `mkaclocal'.
37 #
38 # Revision 1.3  2001/01/20 12:02:12  mdw
39 # Honour TMPDIR environment variable.
40 #
41 # Revision 1.2  1999/11/11 17:49:15  mdw
42 # Regular expression fixes for parsing version numbers.
43 #
44 # Revision 1.1.1.1  1999/05/05 19:23:47  mdw
45 # New import.  The old CVS repository was lost in a disk disaster.
46 #
47
48 set -e
49
50 # --- Handle command line arguments ---
51
52 files=""
53 mode=x
54 out=""
55
56 # --- Parse command line arguments ---
57
58 while [ $# -gt 0 ]; do
59   case $1 in
60     -h | --h | --he | --hel | --help)
61       cat <<EOF
62 Usage: txtlib [-lx] [-o FILE] [LIBRARY...]
63
64 In \`extract' mode (-x, default), extracts chunks named on standard input
65 from the list of libraries, and writes the result to standard output.
66
67 In \`list' mode (-l), lists the chunks defined in the text libraries given.
68
69 Options:
70
71 -h, --help              Print this help text.
72 -v, --version           Print the program's version number.
73 -l, --list              List chunks defined in text libraries.
74 -x, --extract           Extract chunks from text libraries (default).
75 -o, --output=FILE       Extract chunks to FILE, not standard output.
76 EOF
77       exit 0
78       ;;
79     -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
80       version=`echo '$Revision: 1.4 $' |
81         sed -n -e 's;^.*: \([0-9.]*\) *\\$;\1;p'`
82       echo "txtlib $version; Common Files Distribution version @VERSION@"
83       exit 0
84       ;;
85     -o | --o | --ou | --out | --outp | --outpu | --output)
86       out="$2";
87       shift
88       ;;
89     -o*)
90       out=`echo $1 | sed -e 's/^-[a-z]//'`
91       ;;
92     --o=* | --ou=* | --out=* | --outp=* | --outpu=* | --output=*)
93       out=`echo $1 | sed -e 's/^--[a-z]*=//'`
94       ;;
95     -l | --l | --li | --lis | --list)
96       mode=l
97       ;;
98     -x | --e | --ex | --ext | --extr | --extra | --extrac | --extract)
99       mode=x
100       ;;
101     --)
102       shift
103       break
104       ;;
105     -)
106       break
107       ;;
108     -*)
109       echo "txtlib: unknown option \`$1'" >&2
110       exit 1
111       ;;
112     *)
113       break
114       ;;
115   esac
116   shift
117 done
118
119 test "$out" = "-" && out=""
120
121 # --- Build a `sed' script ---
122
123 case $mode in
124   l)
125     sed -n -e "/^.*\*@-\([-a-zA-Z0-9_]*\)-@\*.*$/ s//\1/p" /dev/null "$@"
126     ;;
127   x)
128     t=${TMPDIR-/tmp}/txtlib.$$
129     if mkdir -m 700 $t; then :
130     else
131       echo >&2 "txtlib: could not create temporary directory"
132       exit 1
133     fi
134     sedfile=/$t/sed
135     while read LINE; do
136       echo "/\*@-$LINE-@\*/,/\*@-#-@\*/ p"
137     done >$sedfile
138     test -z "$out" || exec >"$out"
139     sed -e '/\*@-[-a-zA-Z0-9_]*-@\*/ i\
140     *@-#-@*' /dev/null "$@" | sed -n -f $sedfile | sed -e '/\*@-#-@\*/ d'
141     rm -rf $t
142     ;;
143 esac