Annotation of loncom/xml/style.pl, revision 1.1
1.1 ! sakharuk 1: #!/usr/local/bin/perl
! 2:
! 3: use strict;
! 4: use HTML::TokeParser;
! 5: use IO::File;
! 6:
! 7: {
! 8: my @content_of_style;
! 9: my $content_style_string;
! 10:
! 11: my $target = 'web';
! 12:
! 13: # read style file and put the content in string
! 14: {
! 15: my $filesty=IO::File->new('/home/sasha/final/attempt2.sty')
! 16: || die "Couldn't open style file for reading: $!\n";
! 17: @content_of_style = <$filesty>;
! 18: }
! 19: $content_style_string = join(' ',@content_of_style);
! 20:
! 21: # Call styleparser to parser syle string and create hash
! 22:
! 23: my %style_for_target = &styleparser($target,$content_style_string);
! 24:
! 25: }
! 26:
! 27: # style subroutine
! 28: # create a table for defined target
! 29: # from the information from Style File
! 30:
! 31: sub styleparser {
! 32:
! 33: my ($target,$content_style_string) = @_;
! 34: my @target_list = ('target','web','tex','edit','modified','rat','answer','metadis');
! 35: my @value_style = ();
! 36: my $current_key = '';
! 37: my $current_value = '';
! 38: my $stoken;
! 39: my $flag;
! 40: my $iele;
! 41: my $flag_target;
! 42:
! 43: my $pstyle = HTML::TokeParser->new(\$content_style_string);
! 44:
! 45: while ($stoken = $pstyle->get_token) {
! 46: # start for tag definition
! 47: if ($stoken->[0] eq 'S' and $stoken->[1] eq 'definetag') {
! 48: # new key in hash
! 49: $current_key = $stoken->[2]{name};
! 50: $flag = 0;
! 51: # metadata output
! 52: if ($target eq 'meta') {
! 53: while ($stoken = $pstyle->get_token and $stoken->[1] ne 'definetag') {
! 54: if ($stoken->[0] eq 'S' and $stoken->[1] eq 'meta') {
! 55: while ($stoken = $pstyle->get_token and $stoken->[1] ne 'meta') {
! 56: $current_value .= $stoken->[1];
! 57: }
! 58: }
! 59: }
! 60: } else {
! 61: # render output
! 62: while ($stoken = $pstyle->get_token and $stoken->[1] ne 'render') {
! 63: if ($stoken->[1] eq 'definetag') {
! 64: $flag = 1;
! 65: last;
! 66: }
! 67: }
! 68: if ($flag == 0) {
! 69: while ($stoken = $pstyle->get_token and $stoken->[1] ne 'definetag'
! 70: and $stoken->[1] ne 'render') {
! 71: # if token not equal to target $flag_target=0
! 72: $flag_target = 0;
! 73: for (my $i=0; $i<$#target_list; $i++) {
! 74: if ($stoken->[1] eq $target_list[$i]) {
! 75: $flag_target = 1;
! 76: }
! 77: }
! 78: if ($flag_target == 0) {
! 79: # target not found
! 80: if ($stoken->[0] eq 'T') {
! 81: $current_value .= $stoken->[1];
! 82: } elsif ($stoken->[0] eq 'S') {
! 83: my $flagelem = 0;
! 84: for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
! 85: if ($stoken->[1] eq $value_style[$i]) {
! 86: $flagelem = 1;
! 87: $iele = $i + 1;
! 88: last;
! 89: }
! 90: }
! 91: if ($flagelem == 0) {
! 92: $current_value .= $stoken->[4];
! 93: } else {
! 94: $current_value .= $value_style[$iele];
! 95: }
! 96: } elsif ($stoken->[0] eq 'E') {
! 97: my $flagelem = 0;
! 98: for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
! 99: if ($stoken->[1] eq $value_style[$i]) {
! 100: $flagelem = 1;
! 101: $iele = $i + 1;
! 102: last;
! 103: }
! 104: }
! 105: if ($flagelem == 0) {
! 106: $current_value .= $stoken->[2];
! 107: } else {
! 108: $current_value .= $value_style[$iele];
! 109: }
! 110: }
! 111: } else {
! 112: # target found
! 113: if ($stoken->[0] eq 'S' and $stoken->[1] eq 'target') {
! 114: # target defined via <target> tag
! 115: if (index $stoken->[2]{dest},$target =! -1) {
! 116: while ($stoken = $pstyle->get_token and $stoken->[1] ne 'target') {
! 117: }
! 118: } else {
! 119: while ($stoken = $pstyle->get_token and $stoken->[1] ne 'target') {
! 120: if ($stoken->[0] eq 'T') {
! 121: $current_value .= $stoken->[1];
! 122: } elsif ($stoken->[0] eq 'S') {
! 123: my $flagelem = 0;
! 124: for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
! 125: if ($stoken->[1] eq $value_style[$i]) {
! 126: $flagelem = 1;
! 127: $iele = $i + 1;
! 128: last;
! 129: }
! 130: }
! 131: if ($flagelem == 0) {
! 132: $current_value .= $stoken->[4];
! 133: } else {
! 134: $current_value .= $value_style[$iele];
! 135: }
! 136: } elsif ($stoken->[0] eq 'E') {
! 137: my $flagelem = 0;
! 138: for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
! 139: if ($stoken->[1] eq $value_style[$i]) {
! 140: $flagelem = 1;
! 141: $iele = $i + 1;
! 142: last;
! 143: }
! 144: }
! 145: if ($flagelem == 0) {
! 146: $current_value .= $stoken->[2];
! 147: } else {
! 148: $current_value .= $value_style[$iele];
! 149: }
! 150: }
! 151: }
! 152: }
! 153: } elsif ($stoken->[1] ne $target) {
! 154: #target defined via short-form tag
! 155: my $tempo_token = $stoken->[1];
! 156: while ($stoken = $pstyle->get_token and $stoken->[1] ne $tempo_token) {
! 157: }
! 158: } else {
! 159: my $tempo_token = $stoken->[1];
! 160: while ($stoken = $pstyle->get_token and $stoken->[1] ne $tempo_token) {
! 161: if ($stoken->[0] eq 'T') {
! 162: $current_value .= $stoken->[1];
! 163: } elsif ($stoken->[0] eq 'S') {
! 164: my $flagelem = 0;
! 165: for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
! 166: if ($stoken->[1] eq $value_style[$i]) {
! 167: $flagelem = 1;
! 168: $iele = $i + 1;
! 169: last;
! 170: }
! 171: }
! 172: if ($flagelem == 0) {
! 173: $current_value .= $stoken->[4];
! 174: } else {
! 175: $current_value .= $value_style[$iele];
! 176: }
! 177: } elsif ($stoken->[0] eq 'E') {
! 178: my $flagelem = 0;
! 179: for (my $i=$#value_style-1;$i>=0;$i=$i-2) {
! 180: if ($stoken->[1] eq $value_style[$i]) {
! 181: $flagelem = 1;
! 182: $iele = $i + 1;
! 183: last;
! 184: }
! 185: }
! 186: if ($flagelem == 0) {
! 187: $current_value .= $stoken->[2];
! 188: } else {
! 189: $current_value .= $value_style[$iele];
! 190: }
! 191: }
! 192: }
! 193: }
! 194: }
! 195: }
! 196:
! 197: }
! 198: }
! 199: }
! 200: $current_value =~ s/(\s)+/$1/g;
! 201: if ($current_value ne ' ' and $current_value ne '' ) {
! 202: push (@value_style,lc $current_key,$current_value);
! 203: }
! 204: $current_key = '';
! 205: $current_value = '';
! 206: }
! 207: my %style_for_target = @value_style;
! 208: # check printing
! 209: while (($current_key,$current_value) = each %style_for_target) {
! 210: print "$current_key => $current_value\n";
! 211: }
! 212: # return result
! 213: return %style_for_target;
! 214: }
! 215:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>