#! /usr/local/bin/bash

## texi2plain -- script to convert texi-isms to plain text
##
## Time-stamp:      "2011-01-28 13:09:24 bkorb"
## Author:          Jim Van Zandt <jrv@vanzandt.mv.com>
##
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  43b91e8ca915626ed3818ffb1b71248b COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f COPYING.mbsd

## This script converts texi-isms into plain text.  Its original usage is to
## process command-line argument document and detail text.
##
## We leave any unrecognized tokens alone - this way we have an easier time
## finding them so we can fix them.

sed \
 -e   's;@code{\([^}]*\)};\1;g' \
 -e    's;@var{\([^}]*\)};\1;g' \
 -e   's;@samp{\([^}]*\)};\1;g' \
 -e 's;@option{\([^}]*\)};\1;g' \
 -e      's;@i{\([^}]*\)};\1;g' \
 -e   's;@file{\([^}]*\)};\1;g' \
 -e   's;@emph{\([^}]*\)};\1;g' \
 -e 's;@strong{\([^}]*\)};\1;g'

# Tags from texi2man that we probably do not need:
# -e 's/@\([{}]\)/\1/g' \
# -e 's,^\$\*$,.br,' \
# -e '/@ *example/,/@ *end *example/s/^/    /' \
# -e 's/^ *@ *example/.nf/' \
# -e 's/^ *@ *end *example/.fi/' \
# -e  '/^ *@ *noindent/d' \
# -e  '/^ *@ *enumerate/d' \
# -e 's/^ *@ *end *enumerate/.br/' \
# -e  '/^ *@ *table/d' \
# -e 's/^ *@ *end *table/.br/' \
# -e 's/^@item \(.*\)/.sp\
#.IR "\1"/' \
# -e 's/^@item/.sp 1/' \
# -e 's/\*\([a-zA-Z0-9:~=_ -]*\)\*/\\fB\1\\fP/g' \
# -e 's/``\([a-zA-Z0-9:~+=_ -]*\)'"''"'/\\(lq\1\\(rq/g' \
# -e "s/^'/\\'/" \
# -e 's/^@\*/.br/' \
# -e 's/ -/ \\-/g;s/^\.in \\-/.in -/'
