
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by rubble!jerry on Fri Oct 23 10:39:59 EDT 1992
# Contents:  bipp.info bipp
 
echo extracting - bipp.info
sed 's/^X//' > "bipp.info" <<'X//E*O*F bipp.info//'
XDate:    Thu, 24 Sep 92 11:43:54 EDT
XFrom:    Jerry Peek <jerry@ora.com>
XTo:      Jerry Sweet <jsweet@irvine.com>
XSubject: Re: MH tweaks wanted 
XIn-reply-to: Message from Jerry Sweet <agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!sample.eng.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!news!shrike.irvine.com!jsweet@ucbvax.berkeley.edu> 
X	 of "22 Sep 92 21:32:46 +0000." <Bv016M.J7t@irvine.com> 
XMessage-ID: <545.717349434@rubble>
X
X> 1. A facility whereby the output of a program invocation can be
X> 	placed into message headers, possibly via an escape
X> 	sequence in a comp/repl/forw components template and/or
X> 	an mhl template.  Sort of like shell back-ticks.  This
X> 	would allow me to call programs that print various kinds of
X> 	information, such as the current folder name, for inclusion
X> 	in a header component.
X
XThat was an interesting problem.  I hacked up a "nawk" editor script
Xthat does what you want, I think.  I always like to post stuff like this
Xto the list so other people can see the technique and comment on it...
Xbut I decided to send it to you privately to see if it's what you're
Xthinking of.  (BTW, when your message got to the mh-users mailing list
Xfrom USENET, there was no reply-able address on it.  I added yours by
Xhand, but I wonder if anyone else is having trouble answering you?)
X
XAnyway, you run this script from your MH profile.  It's a front-end
Xthat calls prompter after it's edited your message:
X
X	comp: -editor bipp
X	repl: -editor bipp
X	forw: -editor bipp
X
XHere's a sample "components" file:
X
X	To: 
X	Cc: 
X	Fcc: `folder -fast`
X	X-local-time: `date`
X	Subject:
X	-----------
X	This should not be expanded: `date`
X
XAnd here's a test run.  I typed in the "To:" and "Subject:" from the
Xkeyboard:
X
X	% comp -editor bipp -form /tmp/components
X	To: jerry
X	Cc: 
X	Fcc: inbox
X	X-local-time: Thu Sep 24 11:40:23 EDT 1992
X	Subject: test test
X
X	--------Enter initial text
X
X	^D
X	This should not be expanded: `date`
X	--------
X
X	What now? q d
X//E*O*F bipp.info//
chmod u=rw,g=r,o=r bipp.info
 
echo extracting - bipp
sed 's/^X//' > "bipp" <<'X//E*O*F bipp//'
X#! /bin/sh
X# $Header: /home/jerry/.bin/RCS/bipp,v 1.4 92/10/23 10:41:28 jerry Exp $
X###	bipp - backquote interpolating prompter preprocessor :-)
X###	Usage (in MH profile):  comp: -editor bipp   (etc., or Editor: bipp)
X## Reads a "components" file, runs commands between backquotes (in header only!)
X## starts "prompter" on the edited file.  Sort of a hack, but it's a good start.
X#
X# Placed in the public domain by Jerry Peek, jerry@ora.com, 23 October 1992.
X# Use this at your own risk, inspect and fix before you use it, etc.
X# If this doesn't work the way you expect it to, that's your responsibility!
X
Xstat=1  # DEFAULT EXIT STATUS (RESET TO 0 FOR NORMAL EXIT)
Xtemp=/tmp/EDIT$$
Xtrap 'rm -f $temp; exit $stat' 0 1 2 15
X
Xnawk '
XBEGIN {
X    inheader = 1
X}
Xinheader == 1 {
X    if ($0 ~ /^-*$/) {
X	# END OF HEADER
X	inheader = 0
X    }
X    else if (match($0, /`.*`/)) {
X	# GET STRING, WITHOUT THE BACKQUOTES:
X	torun = substr($0, RSTART + 1, RLENGTH - 2)
X	# QUICK-AND-DIRTY: GET ONE LINE OF OUTPUT FROM torun:
X	torun | getline tosub
X	if (sub(/`.*`/, tosub) != 1) {
X	    printf "**** ERROR RUNNING `%s` ***\n", torun
X	    next
X	}
X    }
X}
X{
X    print
X}' $1 > $temp
X# REPLACE DRAFT WITH EDITED VERSION; START prompter IF cp WORKED:
Xif cp $temp $1
Xthen
X    prompter $1
X    stat=$?       # EXIT WITH STATUS FROM prompter
Xfi
X//E*O*F bipp//
chmod u=r,g=r,o=r bipp
 
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
      58     295    1968 bipp.info
      44     231    1315 bipp
     102     526    3283 total
!!!
wc  bipp.info bipp | sed 's/^X//' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0
