#!/bin/sh
#***************************************************************************
# PROJECT : MusixTeX Preprocessor  
# FILE    : doc/dompp ... silly name
# TITLE   : filter an mpp section of doc through mpp
# ABSTRACT:
#   functionality
#   * find an mpp environment in a tex document
#   * filter contents of environment through mpp
#   * change mpp environment to verbatim environment
#   * insert a new music that contains musixtex code of mpp environment source
#
#   description
#   * replace first "\begin{mpp}" with "\begin{current}
#   * replace first "\end{mpp}" with "\end{current}"
#   * write lines from "\begin{current}" + 1  to "\end{current} - 1 to x.mpp
#   * convert x.mpp to x.tex; extrac mode
#   * insert before first "\begin{mpp}": 
#       <signature>
#       "\begin{music}" 
#          <x.tex> 
#       "\end{mpp}"
#       "which was coded as"
#   * replace "\begin{current}" with "\begin{verbatim}"
#   * replace "\end{current}" with "\end{verbatim}"
#
#***************************************************************************

# usage: docpp <mpp-doc>
if test $# -ne 1 
then
	exit 1
fi

# unix: man ex
#     -s       Suppress all interactive-user feedback.  This is useful in
#              processing editor scripts.                                 
# LINUX: man elvis
#     -e       Elvis will start up in colon command mode.
#     -s       This set the safer" option,  which  disables  many
#              potentially harmful commands.  It has not been rig-
#              orously proven to be absolutely secure, however.
# in addition, elvis needs the "1" command.
# does no harm to ex
# it works! for linux extra find/replace needed because
# the insert/append command behaves differently under linux (elvis).
#
# unix: ex
# linux: elvis
#ex -s $1 <<EOF
#elvis -e $1 <<EOF
good-ex $1 <<EOF
1
/begin{mpp}/s//begin{currentmpp}/
/end{mpp}/s//end{currentmpp}/
1
/begin{current}/+,/end{current}/-w! x.mpp
!mpp -e x.mpp
1
/begin{currentmpp}/-
a
\begin{currentmusic}
% File x.mpp was autmatically created by dodoc
% From the music below
\end{music}

which was coded as:

.
1
/begin{currentmusic}/++
r x.tex
/begin{currentmusic}/s//begin{music}/
/begin{currentmpp}/s//begin{verbatim}/
/end{currentmpp}/s//end{verbatim}/
 1
w
q
EOF
