mdw-setup: Fix for constructing Makefile.am from m4 source.
[cfd] / txtlib.in
CommitLineData
b91e2391 1#! /bin/sh
2
3# -*-sh-*-
4#
a1af6b50 5# $Id: txtlib.in,v 1.5 2004/04/08 01:36:24 mdw Exp $
b91e2391 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
a7855629 30set -e
31
b91e2391 32# --- Handle command line arguments ---
33
34files=""
35mode=x
36out=""
37
38# --- Parse command line arguments ---
39
40while [ $# -gt 0 ]; do
41 case $1 in
42 -h | --h | --he | --hel | --help)
43 cat <<EOF
44Usage: txtlib [-lx] [-o FILE] [LIBRARY...]
45
46In \`extract' mode (-x, default), extracts chunks named on standard input
47from the list of libraries, and writes the result to standard output.
48
49In \`list' mode (-l), lists the chunks defined in the text libraries given.
50
51Options:
52
53-h, --help Print this help text.
54-v, --version Print the program's version number.
55-l, --list List chunks defined in text libraries.
56-x, --extract Extract chunks from text libraries (default).
57-o, --output=FILE Extract chunks to FILE, not standard output.
58EOF
59 exit 0
60 ;;
61 -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
a1af6b50 62 version=`echo '$Revision: 1.5 $' |
4969747b 63 sed -n -e 's;^.*: \([0-9.]*\) *\\$;\1;p'`
b91e2391 64 echo "txtlib $version; Common Files Distribution version @VERSION@"
65 exit 0
66 ;;
67 -o | --o | --ou | --out | --outp | --outpu | --output)
68 out="$2";
69 shift
70 ;;
71 -o*)
72 out=`echo $1 | sed -e 's/^-[a-z]//'`
73 ;;
74 --o=* | --ou=* | --out=* | --outp=* | --outpu=* | --output=*)
75 out=`echo $1 | sed -e 's/^--[a-z]*=//'`
76 ;;
77 -l | --l | --li | --lis | --list)
78 mode=l
79 ;;
80 -x | --e | --ex | --ext | --extr | --extra | --extrac | --extract)
81 mode=x
82 ;;
83 --)
84 shift
85 break
86 ;;
87 -)
88 break
89 ;;
90 -*)
91 echo "txtlib: unknown option \`$1'" >&2
92 exit 1
93 ;;
94 *)
95 break
96 ;;
97 esac
98 shift
99done
100
101test "$out" = "-" && out=""
102
103# --- Build a `sed' script ---
104
105case $mode in
106 l)
a7855629 107 sed -n -e "/^.*\*@-\([-a-zA-Z0-9_]*\)-@\*.*$/ s//\1/p" /dev/null "$@"
b91e2391 108 ;;
109 x)
8ab91619 110 t=${TMPDIR-/tmp}/txtlib.$$
b91e2391 111 if mkdir -m 700 $t; then :
112 else
113 echo >&2 "txtlib: could not create temporary directory"
114 exit 1
115 fi
116 sedfile=/$t/sed
117 while read LINE; do
118 echo "/\*@-$LINE-@\*/,/\*@-#-@\*/ p"
119 done >$sedfile
a7855629 120 test -z "$out" || exec >"$out"
b91e2391 121 sed -e '/\*@-[-a-zA-Z0-9_]*-@\*/ i\
a7855629 122 *@-#-@*' /dev/null "$@" | sed -n -f $sedfile | sed -e '/\*@-#-@\*/ d'
b91e2391 123 rm -rf $t
124 ;;
125esac