--- loncom/xml/lonxml.pm 2004/07/08 14:35:12 1.327
+++ loncom/xml/lonxml.pm 2004/10/21 02:43:34 1.346
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.327 2004/07/08 14:35:12 sakharuk Exp $
+# $Id: lonxml.pm,v 1.346 2004/10/21 02:43:34 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,7 +51,7 @@ use Math::Cephes();
use Math::Random();
use Opcode();
use POSIX qw(strftime);
-
+use Time::HiRes qw( gettimeofday tv_interval );
sub register {
my ($space,@taglist) = @_;
@@ -159,19 +159,28 @@ sub xmlbegin {
.'';
} else {
- $output='';
+ $output='
+';
}
return $output;
}
sub xmlend {
+ my ($target,$parser)=@_;
my $mode='xml';
my $status='OPEN';
if ($Apache::lonhomework::parsing_a_problem) {
$mode='problem';
$status=$Apache::inputtags::status[-1];
}
- return &Apache::lonfeedback::list_discussion($mode,$status).'';
+ my $discussion=&Apache::lonfeedback::list_discussion($mode,$status);
+ if ($target eq 'tex') {
+ $discussion.='\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\end{document}';
+ &Apache::lonxml::newparser($parser,\$discussion,'');
+ return '';
+ } else {
+ return $discussion.'';
+ }
}
sub tokeninputfield {
@@ -279,7 +288,7 @@ sub fontsettings() {
my $headerstring='';
if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) {
$headerstring.=
- '';
+ '';
} elsif (!$ENV{'browser.mathml'} && $ENV{'browser.unicode'}) {
$headerstring.=
'';
@@ -312,13 +321,15 @@ sub xmlparse {
my $bodytext=
$ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
if ($bodytext) {
- my $location=&Apache::lonnet::filelocation('',$bodytext);
- my $styletext=&Apache::lonnet::getfile($location);
- if ($styletext ne '-1') {
- %style_for_target = (%style_for_target,
- &Apache::style::styleparser($target,$styletext));
- }
- }
+ foreach my $file (split(',',$bodytext)) {
+ my $location=&Apache::lonnet::filelocation('',$file);
+ my $styletext=&Apache::lonnet::getfile($location);
+ if ($styletext ne '-1') {
+ %style_for_target = (%style_for_target,
+ &Apache::style::styleparser($target,$styletext));
+ }
+ }
+ }
} elsif ($ENV{'construct.style'} && ($ENV{'request.state'} eq 'construct')) {
my $location=&Apache::lonnet::filelocation('',$ENV{'construct.style'});
my $styletext=&Apache::lonnet::getfile($location);
@@ -389,9 +400,10 @@ sub latex_special_symbols {
} else {
$string=~s/\\/\\ensuremath{\\backslash}/g;
$string=~s/([^\\]|^)\%/$1\\\%/g;
- $string=~s/\b_{2,}\b/ \\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
- $string=~s/([^\\]|^)(\$|_)/$1\\$2/g;
+ $string=~s/([^\\]|^)\$/$1\\\$/g;
+ $string=~s/([^\\])\_/$1\\_/g;
$string=~s/\$\$/\$\\\$/g;
+ $string=~s/\_\_/\_\\\_/g;
$string=~s/\#\#/\#\\\#/g;
$string=~s/([^\\]|^)(\~|\^)/$1\\$2\\strut /g;
$string=~s/(>|<)/\\ensuremath\{$1\}/g; #more or less
@@ -399,6 +411,7 @@ sub latex_special_symbols {
# any & or # leftover should be safe to just escape
$string=~s/([^\\]|^)\&/$1\\\&/g;
$string=~s/([^\\]|^)\#/$1\\\#/g;
+ $string=~s/\|/\$\\mid\$/g;
#single { or } How to escape?
}
return $string;
@@ -745,6 +758,7 @@ sub init_safespace {
#need to inspect this class of ops
# $safeeval->deny(":base_orig");
+ $safeeval->permit("require");
$safeinit .= ';$external::target="'.$target.'";';
my $rndseed;
my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
@@ -753,27 +767,6 @@ sub init_safespace {
&Apache::lonxml::debug("Setting rndseed to $rndseed");
&Apache::run::run($safeinit,$safeeval);
- my $subroutine=<<'EVALUATESUB';
-sub __LC_INTERNAL_EVALUATE__ {
- my ($__LC__a,$__LC__b,$__LC__c)=@_;
- my $__LC__prefix;
- while(1){
- {
- use strict;
- no strict "vars";
- if (eval(defined(eval($__LC__a.$__LC__b)))) {
- return $__LC__prefix.eval($__LC__a.$__LC__b.$__LC__c);
- }
- }
- $__LC__prefix.=substr($__LC__a,0,1,"");
- if ($__LC__a!~/^(\$|&|\#)/) { last; }
- }
- return $__LC__prefix.$__LC__a.$__LC__b.$__LC__c;
-}
-EVALUATESUB
- $safeeval->permit("require");
- $safeeval->reval($subroutine);
- $safeeval->deny("require");
}
sub default_homework_load {
@@ -788,18 +781,26 @@ sub default_homework_load {
}
}
+my $metamode_was;
sub startredirection {
- $Apache::lonxml::redirection++;
- push (@Apache::lonxml::outputstack, '');
+ if (!$Apache::lonxml::redirection) {
+ $metamode_was=$Apache::lonxml::metamode;
+ }
+ $Apache::lonxml::metamode=0;
+ $Apache::lonxml::redirection++;
+ push (@Apache::lonxml::outputstack, '');
}
sub endredirection {
- if (!$Apache::lonxml::redirection) {
- &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
- return '';
- }
- $Apache::lonxml::redirection--;
- pop @Apache::lonxml::outputstack;
+ if (!$Apache::lonxml::redirection) {
+ &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
+ return '';
+ }
+ $Apache::lonxml::redirection--;
+ if (!$Apache::lonxml::redirection) {
+ $Apache::lonxml::metamode=$metamode_was;
+ }
+ pop @Apache::lonxml::outputstack;
}
sub end_tag {
@@ -815,6 +816,8 @@ sub initdepth {
$Apache::lonxml::olddepth=-1;
}
+my @timers;
+my $lasttime;
sub increasedepth {
my ($token) = @_;
$Apache::lonxml::depth++;
@@ -822,8 +825,15 @@ sub increasedepth {
if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
$Apache::lonxml::olddepth=$Apache::lonxml::depth;
}
+ my $time;
+ if ($Apache::lonxml::debug eq "1") {
+ push(@timers,[&gettimeofday()]);
+ $time=&tv_interval($lasttime);
+ $lasttime=[&gettimeofday()];
+ }
+ my $spacing=' 'x($Apache::lonxml::depth-1);
my $curdepth=join('_',@Apache::lonxml::depthcounter);
- &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
+ &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : \n");
#print "
s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
}
@@ -838,8 +848,15 @@ sub decreasedepth {
&Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
$Apache::lonxml::depth='-1';
}
+ my ($timer,$time);
+ if ($Apache::lonxml::debug eq "1") {
+ $timer=pop(@timers);
+ $time=&tv_interval($lasttime);
+ $lasttime=[&gettimeofday()];
+ }
+ my $spacing=' 'x$Apache::lonxml::depth;
my $curdepth=join('_',@Apache::lonxml::depthcounter);
- &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
+ &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : ".&tv_interval($timer)."\n");
#print "
e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
}
@@ -1012,6 +1029,8 @@ sub parstring {
unless ($_=~/\W/) {
my $val=$token->[2]->{$_};
$val =~ s/([\%\@\\\"\'])/\\$1/g;
+ $val =~ s/(\$[^{a-zA-Z_])/\\$1/g;
+ $val =~ s/(\$)$/\\$1/;
#if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
$temp .= "my \$$_=\"$val\";";
}
@@ -1137,7 +1156,8 @@ sub inserteditinfo {
my $initialize='';
if ($filetype eq 'html') {
my $addbuttons=&Apache::lonhtmlcommon::htmlareaaddbuttons();
- $initialize=&Apache::lonhtmlcommon::htmlareaheaders().(<
$addbuttons
@@ -1167,11 +1187,13 @@ $cleanbut
BUTTONS
+ $buttons.=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
+ $buttons.=&Apache::lonhtmlcommon::htmlareaselectactive('filecont');
my $editfooter=(<
-