Diff for /loncom/xml/lonxml.pm between versions 1.211 and 1.212

version 1.211, 2002/11/06 22:36:08 version 1.212, 2002/11/06 23:05:02
Line 148  $Apache::lonxml::request=''; Line 148  $Apache::lonxml::request='';
 $Apache::lonxml::counter=0;  $Apache::lonxml::counter=0;
 $Apache::lonxml::counter_changed=0;  $Apache::lonxml::counter_changed=0;
   
   #internal check on whether to look at style defs
   $Apache::lonxml::usestyle=1;
   
 sub xmlbegin {  sub xmlbegin {
   my $output='';    my $output='';
   if ($ENV{'browser.mathml'}) {    if ($ENV{'browser.mathml'}) {
Line 630  sub inner_xmlparse { Line 633  sub inner_xmlparse {
  # add parameters list to another stack   # add parameters list to another stack
  push (@$parstack,&parstring($token));   push (@$parstack,&parstring($token));
  &increasedepth($token);   &increasedepth($token);
  if (exists $$style_for_target{$token->[1]}) {   if ($Apache::lonxml::usestyle &&
   if ($Apache::lonxml::redirection) {      exists($$style_for_target{$token->[1]})) {
     $Apache::lonxml::outputstack['-1'] .=      $Apache::lonxml::usestyle=0;
       &recurse($$style_for_target{$token->[1]},$target,$safeeval,      my $string=$$style_for_target{$token->[1]}.
        $style_for_target,@$parstack);        '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
   } else {      &Apache::lonxml::newparser($pars,\$string);
     $finaloutput .= &recurse($$style_for_target{$token->[1]},$target,  
      $safeeval,$style_for_target,@$parstack);  
   }  
  } else {   } else {
   $result = &callsub("start_$token->[1]", $target, $token, $stack,    $result = &callsub("start_$token->[1]", $target, $token, $stack,
      $parstack, $pars, $safeeval, $style_for_target);       $parstack, $pars, $safeeval, $style_for_target);
Line 656  sub inner_xmlparse { Line 656  sub inner_xmlparse {
   }    }
  }   }
   
  if (exists($$style_for_target{'/'."$token->[1]"})) {   if ($Apache::lonxml::usestyle &&
   if ($Apache::lonxml::redirection) {      exists($$style_for_target{'/'."$token->[1]"})) {
     $Apache::lonxml::outputstack['-1'] .=        $Apache::lonxml::usestyle=0;
       &recurse($$style_for_target{'/'."$token->[1]"},      my $string=$$style_for_target{'/'.$token->[1]}.
        $target,$safeeval,$style_for_target,@$parstack);        '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
   } else {      &Apache::lonxml::newparser($pars,\$string);
     $finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"},  
      $target,$safeeval,$style_for_target,  
      @$parstack);  
   }  
  } else {   } else {
   $result = &callsub("end_$token->[1]", $target, $token, $stack,    $result = &callsub("end_$token->[1]", $target, $token, $stack,
      $parstack, $pars,$safeeval, $style_for_target);       $parstack, $pars,$safeeval, $style_for_target);
Line 702  sub inner_xmlparse { Line 698  sub inner_xmlparse {
  &end_tag($stack,$parstack,$token);   &end_tag($stack,$parstack,$token);
       }        }
     }      }
     pop @$pars;      if ($#$pars > -1) {
     pop @Apache::lonxml::pwd;   pop @$pars;
    pop @Apache::lonxml::pwd;
       }
   }    }
   
   # if ($target eq 'meta') {    # if ($target eq 'meta') {
Line 717  sub inner_xmlparse { Line 715  sub inner_xmlparse {
   return $finaloutput;    return $finaloutput;
 }  }
   
 sub recurse {  
   my @innerstack = ();   
   my @innerparstack = ();  
   my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;  
   my @pat = ();  
   &newparser(\@pat,\$newarg);  
   my $tokenpat;  
   my $partstring = '';  
   my $output='';  
   my $decls='';  
   &Apache::lonxml::debug("Recursing");  
   while ( $#pat > -1 ) {  
     while  ($tokenpat = $pat[$#pat]->get_token) {  
       if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {  
  if ($metamode<1) { $partstring=$tokenpat->[1]; }  
       } elsif ($tokenpat->[0] eq 'PI') {  
  if ($metamode<1) { $partstring=$tokenpat->[2]; }  
       } elsif ($tokenpat->[0] eq 'S') {  
  push (@innerstack,$tokenpat->[1]);  
  push (@innerparstack,&parstring($tokenpat));  
  &increasedepth($tokenpat);  
  $partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat,  
        \@innerstack, \@innerparstack, \@pat,  
        $safeeval, $style_for_target);  
       } elsif ($tokenpat->[0] eq 'E') {  
  #clear out any tags that didn't end  
  while ($tokenpat->[1] ne $innerstack[$#innerstack]  
        && ($#innerstack > -1)) {  
   my $lasttag=$innerstack[-1];  
   if ($tokenpat->[1] =~ /^$lasttag$/i) {  
     &Apache::lonxml::warning('Using tag &lt;/'.$tokenpat->[1].'&gt; as end tag to &lt;'.$innerstack[-1].'&gt;');  
     last;  
   } else {  
     &Apache::lonxml::warning('Found tag &lt;/'.$tokenpat->[1].'&gt; when looking for &lt;/'.$innerstack[-1].'&gt; in file');  
     &end_tag(\@innerstack,\@innerparstack,$tokenpat);  
   }  
  }  
  $partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,  
        \@innerstack, \@innerparstack, \@pat,  
        $safeeval, $style_for_target);  
       } else {  
  &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");  
       }  
       #pass both the variable to the style tag, and the tag we   
       #are processing inside the <definedtag>  
       if ( $partstring ne "" ) {  
  if ( $#parstack > -1 ) {   
   if ( $#innerparstack > -1 ) {   
     $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];  
   } else {  
     $decls= $parstack[$#parstack];  
   }  
  } else {  
   if ( $#innerparstack > -1 ) {   
     $decls=$innerparstack[$#innerparstack];  
   } else {  
     $decls='';  
   }  
  }  
  $output .= &Apache::run::evaluate($partstring,$safeeval,$decls);  
  $partstring = '';  
       }  
       if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;  
  &decreasedepth($tokenpat);}  
     }  
     pop @pat;  
     pop @Apache::lonxml::pwd;  
   }  
   &Apache::lonxml::debug("Exiting Recursing");  
   return $output;  
 }  
   
 sub callsub {  sub callsub {
   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;    my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   my $currentstring='';    my $currentstring='';
Line 862  sub setup_globals { Line 788  sub setup_globals {
   $errorcount=0;    $errorcount=0;
   $warningcount=0;    $warningcount=0;
   $Apache::lonxml::default_homework_loaded=0;    $Apache::lonxml::default_homework_loaded=0;
     $Apache::lonxml::usestyle=1;
   &init_counter();    &init_counter();
   @Apache::lonxml::pwd=();    @Apache::lonxml::pwd=();
   @Apache::lonxml::extlinks=();    @Apache::lonxml::extlinks=();
Line 1080  sub store_counter { Line 1007  sub store_counter {
   
 sub get_all_text {  sub get_all_text {
  my($tag,$pars)= @_;   my($tag,$pars)= @_;
    &Apache::lonxml::debug("Got a ".ref($pars));
    if (ref($pars) ne 'ARRAY') {
        $pars=[$pars];
    }
  my $depth=0;   my $depth=0;
  my $token;   my $token;
  my $result='';   my $result='';
  if ( $tag =~ m:^/: ) {    if ( $tag =~ m:^/: ) { 
    my $tag=substr($tag,1);      my $tag=substr($tag,1); 
 #   &Apache::lonxml::debug("have:$tag:");     #&Apache::lonxml::debug("have:$tag:");
    while (($depth >=0) && ($token = $pars->get_token)) {     while (($depth >=0) && ($#$pars > -1)) {
 #     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");       while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {         #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
        $result.=$token->[1];         if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
      } elsif ($token->[0] eq 'PI') {   $result.=$token->[1];
        $result.=$token->[2];         } elsif ($token->[0] eq 'PI') {
      } elsif ($token->[0] eq 'S') {   $result.=$token->[2];
        if ($token->[1] =~ /^$tag$/i) { $depth++; }         } elsif ($token->[0] eq 'S') {
        $result.=$token->[4];   if ($token->[1] =~ /^$tag$/i) { $depth++; }
      } elsif ($token->[0] eq 'E')  {   $result.=$token->[4];
        if ( $token->[1] =~ /^$tag$/i) { $depth--; }         } elsif ($token->[0] eq 'E')  {
        #skip sending back the last end tag   if ( $token->[1] =~ /^$tag$/i) { $depth--; }
        if ($depth > -1) { $result.=$token->[2]; } else {   #skip sending back the last end tag
  $pars->unget_token($token);   if ($depth > -1) { $result.=$token->[2]; } else {
      $$pars[-1]->unget_token($token);
    }
        }         }
      }       }
        if (($depth >=0) && ($#$pars > 0) ) {
          pop(@$pars);
          pop(@Apache::lonxml::pwd);
        }
    }     }
  } else {   } else {
    while ($token = $pars->get_token) {       while ($#$pars > -1) {
 #     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");   while ($token = $$pars[-1]->get_token) {
      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {       #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
        $result.=$token->[1];       if (($token->[0] eq 'T')||($token->[0] eq 'C')||
      } elsif ($token->[0] eq 'PI') {   ($token->[0] eq 'D')) {
        $result.=$token->[2];   $result.=$token->[1];
      } elsif ($token->[0] eq 'S') {       } elsif ($token->[0] eq 'PI') {
        if ( $token->[1] =~ /^$tag$/i) {   $result.=$token->[2];
  $pars->unget_token($token); last;       } elsif ($token->[0] eq 'S') {
        } else {   if ( $token->[1] =~ /^$tag$/i) {
  $result.=$token->[4];       $$pars[-1]->unget_token($token); last;
        }   } else {
      } elsif ($token->[0] eq 'E')  {       $result.=$token->[4];
        $result.=$token->[2];   }
        } elsif ($token->[0] eq 'E')  {
    $result.=$token->[2];
        }
    }
    if (($#$pars > 0) ) {
        pop(@$pars);
        pop(@Apache::lonxml::pwd);
    } else { last; }
      }       }
    }  
  }   }
 # &Apache::lonxml::debug("Exit:$result:");   if ($result =~ m|<LONCAPA_INTERNAL_TURN_STYLE_ON />|) {
        $Apache::lonxml::usestyle=1;
    }
    #&Apache::lonxml::debug("Exit:$result:");
  return $result   return $result
 }  }
   

Removed from v.1.211  
changed lines
  Added in v.1.212


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>