1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
#!@PATH_PERL@ -w
eval 'exec @PATH_PERL@ -S $0 ${1+"$@"}'
if $running_under_some_shell;
## divert -- Diversion Filter
## Copyright (c) 1997-2001 Ralf S. Engelschall, All Rights Reserved.
## Copyright (c) 1999-2001 Denis Barbier, All Rights Reserved.
use strict;
use warnings;
use lib '@INSTALLPRIVLIB@';
use lib '@INSTALLARCHLIB@';
use lib "/usr/share/wml";
#
# create output file
#
use TheWML::Backends::Divert::Main ();
TheWML::Backends::Divert::Main->new( argv => \@ARGV )->main;
##EOF##
__END__
=head1 NAME
Divert - Text Diversion Filter
=head1 SYNOPSIS
B<divert>
[B<-o> I<outputfile>]
[B<-q>]
[B<-v>]
[I<inputfile>]
=head1 DESCRIPTION
The F<divert> program reads I<inputfile> or from C<stdin> and applies a 2-pass
diversion filter to its contents. In pass 1 all diversion locations are
accumulated and in pass 2 these locations are recursively expanded at their
dump positions. The diversion filter is controlled by directives found in the
input data:
=over 4
=item B<{#>I<NAME>B<#}> (or B<E<lt>E<lt>>I<NAME>B<E<gt>E<gt>>)
This defines the dump position of the location I<NAME>. All accumulated data
which I<finally> has to been diverted to I<NAME> is inserted at this data
position. Notice: the final data of a location I<NAME> has not to be known at
this point, because the expansion of such location dumps are done in pass 2.
You can also dump a location more than once, but the contents is always the
same, independent of the data position where the location dump tag stays. The
I<NAME> can be any symbolic name matching C<[a-zA-Z][a-zA-Z0-9_]*>.
=item B<{#>[B<!>]I<NAME>[B<!>]B<#:> (or B<..>[B<!>]I<NAME>[B<!>]B<E<gt>E<gt>>)
This enters the location I<NAME> (or I<diverts> the data flow to it, hence the
name for this filter). In other words: the data flow now goes on at location
I<NAME>. All following data (up to end of file or the next location leave tag)
gets appended to location I<NAME>. You can nest diversions by entering other
locations at any point, because the locations are remembered on a stack. The
default entered location is named ``C<main>''. The top most location is named
``C<null>'' which neither can be entered nor leaved explicitly. But of course
the ``C<null>'' diversion can be manually dumped, for instance when using it
for error messages.
There are two special features for diverting data which are controlled by the
"C<!>" characters preceding or following the I<NAME> identifier:
=over 4
=item B<!>I<NAME>
This sets the data flow position to the I<begin> of location I<NAME>, i.e. it
actually discards the current (already diverted) contents of location I<NAME>
before entering it. Use this to overwrite a locations contents.
=item I<NAME>B<!>
This marks this location entry as I<overwritable>, i.e. it enters location
I<NAME> but when the corresponding leave tag is found, the data-flow position
for I<NAME> gets automatically reset to its begin. Use this if you want to set
the default contents for a location which only gets used if no other
diversions occur to it (because any following diversions to this location
will be overwrite the contents). This feature is usually used for a
template scheme.
=item B<!>I<NAME>B<!>
Just the combination of the above two features. Use this to both discard the
current contents of location I<NAME> and set a new default for it.
=back
=item B<:#>[I<NAME>]B<#}> (or B<E<lt>E<lt>>[I<NAME>]B<..>)
This leaves the current location, i.e. enters again the location which was
active when this location was entered. There is no need to leave all
locations at the end of the input data. All still entered locations are
automatically left at end of file because this is essential for a template
scheme.
=back
Notice that there are two ways of using (and thinking) about the filtering
mechanism this program provides:
=over 4
=item B<Macro Mechanism>
This is the "predefined" way of thinking here. Use it like this:
FOO
{#BAR#}
QUUX
{#BAR#:
BAZ
:##}
Here you are thinking of the mechanism as a macro mechanism where you
I<expand> a macro at one data position while you define it via I<begin> and
I<end> tags.
=item B<Diversion Mechanism>
This is the alternative way of thinking. Use it like this:
FOO
<<BAR>>
QUUX
..BAR>>
BAZ
<<..
In other words: You are thinking of the mechanism as a diversion mechanism
where you I<dump> a location at one data position while you divert to it by
I<entering> end I<leaving> the location (here B<BAR>) at other positions.
=back
You can even intermix both ways because both are just alternative syntax
variants which are treated the same.
=head1 EXAMPLE
{#HEAD#}
{#BODY#}
{#FOOT#}
{#FOOT#:
Quux
:##}
{#BODY#:
Bar
:##}
{#HEAD#:
Foo
:##}
=head1 OPTIONS
=over
=item B<-o> I<outputfile>
This redirects the output to I<outputfile>. Usually the output will be send to
F<stdout> if no such option is specified or I<outputfile> is ``C<->''.
=item B<-q>
This sets quiet mode where warnings are suppressed.
=item B<-v>
This sets verbose mode where some processing information will be given on
F<stderr>.
=back
=head1 AUTHORS
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
Denis Barbier
barbier@engelschall.com
=cut
# vim:ft=perl
|