File:
[LON-CAPA] /
loncom /
xml /
style.pl
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Thu Jun 29 19:31:09 2000 UTC (24 years, 4 months ago) by
sakharuk
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
version_2_5_0,
version_2_4_X,
version_2_4_99_0,
version_2_4_2,
version_2_4_1,
version_2_4_0,
version_2_3_X,
version_2_3_99_0,
version_2_3_2,
version_2_3_1,
version_2_3_0,
version_2_2_X,
version_2_2_99_1,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_X,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
version_1_3_X,
version_1_3_3,
version_1_3_2,
version_1_3_1,
version_1_3_0,
version_1_2_X,
version_1_2_99_1,
version_1_2_99_0,
version_1_2_1,
version_1_2_0,
version_1_1_X,
version_1_1_99_5,
version_1_1_99_4,
version_1_1_99_3,
version_1_1_99_2,
version_1_1_99_1,
version_1_1_99_0,
version_1_1_3,
version_1_1_2,
version_1_1_1,
version_1_1_0,
version_1_0_99_3,
version_1_0_99_2,
version_1_0_99_1,
version_1_0_99,
version_1_0_3,
version_1_0_2,
version_1_0_1,
version_1_0_0,
version_0_99_5,
version_0_99_4,
version_0_99_3,
version_0_99_2,
version_0_99_1,
version_0_99_0,
version_0_6_2,
version_0_6,
version_0_5_1,
version_0_5,
version_0_4,
stable_2002_spring,
stable_2002_july,
stable_2002_april,
stable_2001_fall,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
conference_2003,
bz6209-base,
bz6209,
bz5969,
bz2851,
STABLE,
PRINT_INCOMPLETE_base,
PRINT_INCOMPLETE,
HEAD,
GCI_3,
GCI_2,
GCI_1,
BZ5971-printing-apage,
BZ5434-fox,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse
*** empty log message ***
#!/usr/local/bin/perl
use strict;
use HTML::TokeParser;
use IO::File;
{
my @content_of_style;
my $content_style_string;
my $target = 'web';
# read style file and put the content in string
{
my $filesty=IO::File->new('/home/sasha/final/attempt2.sty')
|| die "Couldn't open style file for reading: $!\n";
@content_of_style = <$filesty>;
}
$content_style_string = join(' ',@content_of_style);
# Call styleparser to parser syle string and create hash
my %style_for_target = &styleparser($target,$content_style_string);
}
# style subroutine
# create a table for defined target
# from the information from Style File
sub styleparser {
my ($target,$content_style_string) = @_;
my @target_list = ('target','web','tex','edit','modified','rat','answer','metadis');
my @value_style = ();
my $current_key = '';
my $current_value = '';
my $stoken;
my $flag;
my $iele;
my $flag_target;
my $pstyle = HTML::TokeParser->new(\$content_style_string);
while ($stoken = $pstyle->get_token) {
# start for tag definition
if ($stoken->[0] eq 'S' and $stoken->[1] eq 'definetag') {
# new key in hash
$current_key = $stoken->[2]{name};
$flag = 0;
# metadata output
if ($target eq 'meta') {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'definetag') {
if ($stoken->[0] eq 'S' and $stoken->[1] eq 'meta') {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'meta') {
$current_value .= $stoken->[1];
}
}
}
} else {
# render output
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'render') {
if ($stoken->[1] eq 'definetag') {
$flag = 1;
last;
}
}
if ($flag == 0) {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'definetag'
and $stoken->[1] ne 'render') {
# if token not equal to target $flag_target=0
$flag_target = 0;
for (my $i=0; $i<$#target_list; $i++) {
if ($stoken->[1] eq $target_list[$i]) {
$flag_target = 1;
}
}
if ($flag_target == 0) {
# target not found
if ($stoken->[0] eq 'T') {
$current_value .= $stoken->[1];
} elsif ($stoken->[0] eq 'S') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[4];
} else {
$current_value .= $value_style[$iele];
}
} elsif ($stoken->[0] eq 'E') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[2];
} else {
$current_value .= $value_style[$iele];
}
}
} else {
# target found
if ($stoken->[0] eq 'S' and $stoken->[1] eq 'target') {
# target defined via <target> tag
if (defined $stoken->[2]{dest}) {
if (index($stoken->[2]{dest},$target) == -1) {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'target') {
}
} elsif (index($stoken->[2]{dest},$target) != -1) {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'target') {
if ($stoken->[0] eq 'T') {
$current_value .= $stoken->[1];
} elsif ($stoken->[0] eq 'S') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[4];
} else {
$current_value .= $value_style[$iele];
}
} elsif ($stoken->[0] eq 'E') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[2];
} else {
$current_value .= $value_style[$iele];
}
}
}
}
} else {
if (index($stoken->[2]{excl},$target) != -1) {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'target') {
}
} elsif (index($stoken->[2]{excl},$target) == -1) {
while ($stoken = $pstyle->get_token and $stoken->[1] ne 'target') {
if ($stoken->[0] eq 'T') {
$current_value .= $stoken->[1];
} elsif ($stoken->[0] eq 'S') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[4];
} else {
$current_value .= $value_style[$iele];
}
} elsif ($stoken->[0] eq 'E') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[2];
} else {
$current_value .= $value_style[$iele];
}
}
}
}
}
} elsif ($stoken->[1] ne $target) {
#target defined via short-form tag
my $tempo_token = $stoken->[1];
while ($stoken = $pstyle->get_token and $stoken->[1] ne $tempo_token) {
}
} else {
my $tempo_token = $stoken->[1];
while ($stoken = $pstyle->get_token and $stoken->[1] ne $tempo_token) {
if ($stoken->[0] eq 'T') {
$current_value .= $stoken->[1];
} elsif ($stoken->[0] eq 'S') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[4];
} else {
$current_value .= $value_style[$iele];
}
} elsif ($stoken->[0] eq 'E') {
my $flagelem = 0;
for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
if ($stoken->[1] eq $value_style[$i]) {
$flagelem = 1;
$iele = $i + 1;
last;
}
}
if ($flagelem == 0) {
$current_value .= $stoken->[2];
} else {
$current_value .= $value_style[$iele];
}
}
}
}
}
}
}
}
}
$current_value =~ s/(\s)+/$1/g;
if ($current_value ne ' ' and $current_value ne '' ) {
push (@value_style,lc $current_key,$current_value);
}
$current_key = '';
$current_value = '';
}
my %style_for_target = @value_style;
# check printing
while (($current_key,$current_value) = each %style_for_target) {
print "$current_key => $current_value\n";
}
# return result
return %style_for_target;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>