1 |
#! /bin/sh |
2 |
|
3 |
#================================================================ |
4 |
# extfxmantotxt |
5 |
# Convert man (troff-andoc) into plain text. |
6 |
#================================================================ |
7 |
|
8 |
|
9 |
# set variables |
10 |
PATH="$PATH:/usr/local/bin:$HOME/bin:." ; export PATH |
11 |
MANWIDTH=262144 ; export MANWIDTH |
12 |
progname="estfxmantotxt" |
13 |
|
14 |
|
15 |
# check arguments |
16 |
if [ $# -lt 1 ] |
17 |
then |
18 |
printf '%s: usage: %s infile [outfile]\n' "$progname" "$progname" 1>&2 |
19 |
exit 1 |
20 |
fi |
21 |
infile="$1" |
22 |
outfile="$2" |
23 |
if [ -n "$ESTORIGFILE" ] && [ -f "$ESTORIGFILE" ] |
24 |
then |
25 |
infile="$ESTORIGFILE" |
26 |
fi |
27 |
|
28 |
|
29 |
# check the input |
30 |
if [ "!" -f "$infile" ] |
31 |
then |
32 |
printf '%s: %s: no such file\n' "$progname" "$infile" 1>&2 |
33 |
exit 1 |
34 |
fi |
35 |
|
36 |
|
37 |
# initialize the output file |
38 |
if [ -n "$outfile" ] |
39 |
then |
40 |
rm -f "$outfile" |
41 |
fi |
42 |
|
43 |
|
44 |
# function to output |
45 |
output(){ |
46 |
if [ -n "$outfile" ] |
47 |
then |
48 |
cat >> "$outfile" |
49 |
else |
50 |
cat |
51 |
fi |
52 |
} |
53 |
|
54 |
|
55 |
# output the result |
56 |
man "$infile" 2> "/dev/null" | col -b | tr '\t' ' ' | output |
57 |
|
58 |
|
59 |
# exit normally |
60 |
exit 0 |
61 |
|
62 |
|
63 |
|
64 |
# END OF FILE |