#! /usr/bin/perl -w
# vim:set ts=2 sw=2 expandtab:

# doc-cmd - filter to process embedded shell commands in XML document

# Suppose a document contains this:
# <!-- ../xmlformat.rb -f doc2.conf4 doc2.xml | xmlize -C -t screen -->
# <screen>
# ... a bunch of stuff here
# </screen>

# Then you mark the lines in the file from the comment to the closing
# </screen> tag and shove it through doc-cmd.  In vi, with the cursor
# on the comment line, you could do this with 4!!./doc-cmd.  doc-cmd
# reads the first line, extracts the command, runs it, and writes as
# its output the original comment line plus the output from the command.

# This provides a way to embed within an XML document a command that
# produces part of a document, plus an easy way to re-run the command
# should the document fragment need to be regenerated.

use strict;

$_ = <>;
die "Did not find an XML comment containing a command\n"
  unless /\<!--\s*(.*)\s--\>/;
#my $cmd = $1;
print;                # echo original command line
system ($1);        # execute command
