Don't clobber self-describing manpages.
[cfd] / txtlib.in
1 #! /bin/sh
2
3 # -*-sh-*-
4 #
5 # $Id: txtlib.in,v 1.3 2001/01/20 12:02:12 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.3 2001/01/20 12:02:12 mdw
34 # Honour TMPDIR environment variable.
35 #
36 # Revision 1.2 1999/11/11 17:49:15 mdw
37 # Regular expression fixes for parsing version numbers.
38 #
39 # Revision 1.1.1.1 1999/05/05 19:23:47 mdw
40 # New import. The old CVS repository was lost in a disk disaster.
41 #
42
43 # --- Handle command line arguments ---
44
45 files=""
46 mode=x
47 out=""
48
49 # --- Parse command line arguments ---
50
51 while [ $# -gt 0 ]; do
52 case $1 in
53 -h | --h | --he | --hel | --help)
54 cat <<EOF
55 Usage: txtlib [-lx] [-o FILE] [LIBRARY...]
56
57 In \`extract' mode (-x, default), extracts chunks named on standard input
58 from the list of libraries, and writes the result to standard output.
59
60 In \`list' mode (-l), lists the chunks defined in the text libraries given.
61
62 Options:
63
64 -h, --help Print this help text.
65 -v, --version Print the program's version number.
66 -l, --list List chunks defined in text libraries.
67 -x, --extract Extract chunks from text libraries (default).
68 -o, --output=FILE Extract chunks to FILE, not standard output.
69 EOF
70 exit 0
71 ;;
72 -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
73 version=`echo '$Revision: 1.3 $' |
74 sed -n -e 's;^.*: \([0-9.]*\) *\\$;\1;p'`
75 echo "txtlib $version; Common Files Distribution version @VERSION@"
76 exit 0
77 ;;
78 -o | --o | --ou | --out | --outp | --outpu | --output)
79 out="$2";
80 shift
81 ;;
82 -o*)
83 out=`echo $1 | sed -e 's/^-[a-z]//'`
84 ;;
85 --o=* | --ou=* | --out=* | --outp=* | --outpu=* | --output=*)
86 out=`echo $1 | sed -e 's/^--[a-z]*=//'`
87 ;;
88 -l | --l | --li | --lis | --list)
89 mode=l
90 ;;
91 -x | --e | --ex | --ext | --extr | --extra | --extrac | --extract)
92 mode=x
93 ;;
94 --)
95 shift
96 break
97 ;;
98 -)
99 break
100 ;;
101 -*)
102 echo "txtlib: unknown option \`$1'" >&2
103 exit 1
104 ;;
105 *)
106 break
107 ;;
108 esac
109 shift
110 done
111
112 test "$out" = "-" && out=""
113
114 # --- Build a `sed' script ---
115
116 case $mode in
117 l)
118 sed -n -e "/^.*\*@-\([-a-zA-Z0-9_]*\)-@\*.*$/ s//\1/p" "$@"
119 ;;
120 x)
121 t=${TMPDIR-/tmp}/txtlib.$$
122 if mkdir -m 700 $t; then :
123 else
124 echo >&2 "txtlib: could not create temporary directory"
125 exit 1
126 fi
127 sedfile=/$t/sed
128 while read LINE; do
129 echo "/\*@-$LINE-@\*/,/\*@-#-@\*/ p"
130 done >$sedfile
131 test -z "$out" || exec >$out
132 sed -e '/\*@-[-a-zA-Z0-9_]*-@\*/ i\
133 *@-#-@*' "$@" | sed -n -f $sedfile | sed -e '/\*@-#-@\*/ d'
134 rm -rf $t
135 ;;
136 esac