version 1.3, 2002/02/20 00:21:42
|
version 1.6, 2002/05/21 19:13:53
|
Line 1
|
Line 1
|
#!/usr/bin/perl |
#!/usr/bin/perl |
|
|
|
# -------------------------------------------------------- Documentation notice |
|
# Run "perldoc ./lpml_parse.pl" in order to best view the software |
|
# documentation internalized in this program. |
|
|
|
# --------------------------------------------------------- License Information |
|
# The LearningOnline Network with CAPA |
|
# piml_parse.pl - Linux Packaging Markup Language parser |
|
# |
|
# $Id$ |
|
# |
|
# Written by Scott Harrison, codeharrison@yahoo.com |
|
# |
|
# Copyright Michigan State University Board of Trustees |
|
# |
|
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
|
# |
|
# LON-CAPA is free software; you can redistribute it and/or modify |
|
# it under the terms of the GNU General Public License as published by |
|
# the Free Software Foundation; either version 2 of the License, or |
|
# (at your option) any later version. |
|
# |
|
# LON-CAPA is distributed in the hope that it will be useful, |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
# GNU General Public License for more details. |
|
# |
|
# You should have received a copy of the GNU General Public License |
|
# along with LON-CAPA; if not, write to the Free Software |
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
# |
|
# /home/httpd/html/adm/gpl.txt |
|
# |
|
# http://www.lon-capa.org/ |
|
# |
# YEAR=2002 |
# YEAR=2002 |
# 1/26,1/27,1/28,1/29,1/30,1/31 - Scott Harrison |
# 1/26,1/27,1/28,1/29,1/30,1/31,2/20,4/8 - Scott Harrison |
# |
# |
### |
### |
|
|
Line 27 use HTML::TokeParser;
|
Line 61 use HTML::TokeParser;
|
use strict; |
use strict; |
|
|
unless (@ARGV) { |
unless (@ARGV) { |
print <<END; |
print(<<END); |
Incorrect invocation. |
Incorrect invocation. |
Example usages: |
Example usages: |
cat loncapafiles.lpml | perl xfml_parse.pl valid_hosts.xfml |
cat loncapafiles.lpml | perl xfml_parse.pl valid_hosts.xfml |
Line 39 my %eh;
|
Line 73 my %eh;
|
|
|
# ---------------------------------------------- Read in filter file from @ARGV |
# ---------------------------------------------- Read in filter file from @ARGV |
my $tofilter=shift @ARGV; |
my $tofilter=shift @ARGV; |
open IN,"<$tofilter"; my @lines=<IN>; |
open(IN,"<$tofilter"); my @lines=<IN>; |
my $parsestring=join('',@lines); undef @lines; close IN; |
my $parsestring=join('',@lines); undef @lines; close IN; |
my $parser = HTML::TokeParser->new(\$parsestring) or |
my $parser = HTML::TokeParser->new(\$parsestring) or |
die('can\'t create TokeParser object'); |
die('can\'t create TokeParser object'); |
Line 113 while (my $token = $parser->get_tag('cla
|
Line 147 while (my $token = $parser->get_tag('cla
|
$ttype='E'; |
$ttype='E'; |
$excludeflag=0; |
$excludeflag=0; |
$outcache.=$token->[2]; |
$outcache.=$token->[2]; |
my $retval=&evalconditions($outcache); |
|
if (&evalconditions($outcache)) { |
if (&evalconditions($outcache)) { |
$output.=$outcache; |
$output.='<!-- FILTERED OUT -->'; |
} |
} |
else { |
else { |
$output.='<!-- FILTERED OUT -->'; |
$output.=$outcache; |
} |
} |
$outcache=''; |
$outcache=''; |
} |
} |
Line 142 sub evalconditions {
|
Line 175 sub evalconditions {
|
my $eparser = HTML::TokeParser->new(\$parsetext); |
my $eparser = HTML::TokeParser->new(\$parsetext); |
unless (@{$conditions{'name'}} or |
unless (@{$conditions{'name'}} or |
@{$conditions{'attribute'}}) { |
@{$conditions{'attribute'}}) { |
return 0; |
return 1; |
} |
} |
my $nameflag=0; |
my $nameflag=0; |
my $cdataflag=0; |
my $cdataflag=0; |
Line 286 sub format_choice_exclude {
|
Line 319 sub format_choice_exclude {
|
[@{$conditions{'cdata'}}]; |
[@{$conditions{'cdata'}}]; |
return ''; |
return ''; |
} |
} |
|
|
|
# ----------------------------------- POD (plain old documentation, CPAN style) |
|
|
|
=pod |
|
|
|
=head1 NAME |
|
|
|
xfml_parse.pl - This is meant to parse XFML files (XML Filtering Markup Language.) |
|
|
|
=head1 SYNOPSIS |
|
|
|
Usage is for lpml file to come in through standard input. |
|
|
|
=over 4 |
|
|
|
=item * |
|
|
|
1st argument is name of xfml file. |
|
|
|
=back |
|
|
|
Example: |
|
|
|
cat loncapafiles.lpml | perl xfml_parse.pl valid_hosts.xfml |
|
|
|
or |
|
|
|
perl xfml_parse.pl valid_hosts.xfml loncapafiles.lpml |
|
|
|
=head1 DESCRIPTION |
|
|
|
I am using a multiple pass-through approach to parsing |
|
the xfml file. This saves memory and makes sure the server |
|
will never be overloaded. |
|
|
|
=head1 README |
|
|
|
I am using a multiple pass-through approach to parsing |
|
the xfml file. This saves memory and makes sure the server |
|
will never be overloaded. |
|
|
|
=head1 PREREQUISITES |
|
|
|
HTML::TokeParser |
|
|
|
=head1 COREQUISITES |
|
|
|
=head1 OSNAMES |
|
|
|
linux |
|
|
|
=head1 SCRIPT CATEGORIES |
|
|
|
Packaging/Administrative |
|
|
|
=head1 AUTHOR |
|
|
|
Scott Harrison |
|
codeharrison@yahoo.com |
|
|
|
Please let me know how/if you are finding this script useful and |
|
any/all suggestions. -Scott |
|
|
|
=cut |
|
|