Annotation of loncom/xml/lonxml.pm, revision 1.108

1.2       sakharuk    1: # The LearningOnline Network with CAPA
1.3       sakharuk    2: # XML Parser Module 
1.2       sakharuk    3: #
1.3       sakharuk    4: # last modified 06/26/00 by Alexander Sakharuk
1.33      www         5: # 11/6 Gerd Kortemeyer
1.45      www         6: # 6/1/1 Gerd Kortemeyer
1.56      albertel    7: # 2/21,3/13 Guy
1.68      www         8: # 3/29,5/4 Gerd Kortemeyer
1.73      harris41    9: # 5/10 Scott Harrison
1.78      www        10: # 5/26 Gerd Kortemeyer
1.80      harris41   11: # 5/27 H. K. Ng
1.89      www        12: # 6/2,6/3,6/8,6/9 Gerd Kortemeyer
1.93      ng         13: # 6/12,6/13 H. K. Ng
1.95      www        14: # 6/16 Gerd Kortemeyer
1.104     ng         15: # 7/27 H. K. Ng
1.108   ! www        16: # 8/7,8/9 Gerd Kortemeyer
1.2       sakharuk   17: 
1.4       albertel   18: package Apache::lonxml; 
1.33      www        19: use vars 
1.76      albertel   20: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
1.1       sakharuk   21: use strict;
                     22: use HTML::TokeParser;
1.106     www        23: use HTML::TreeBuilder;
1.3       sakharuk   24: use Safe;
1.40      albertel   25: use Safe::Hole;
1.81      ng         26: use Math::Cephes qw(:trigs :hypers :bessels erf erfc);
1.91      ng         27: use Math::Random qw(:all);
1.13      albertel   28: use Opcode;
1.72      albertel   29: 
                     30: sub register {
                     31:   my $space;
                     32:   my @taglist;
                     33:   my $temptag;
                     34:   ($space,@taglist) = @_;
                     35:   foreach $temptag (@taglist) {
                     36:     $Apache::lonxml::alltags{$temptag}=$space;
                     37:   }
                     38: }
                     39: 
1.46      www        40: use Apache::Constants qw(:common);
1.71      www        41: use Apache::lontexconvert;
1.72      albertel   42: use Apache::style;
                     43: use Apache::run;
                     44: use Apache::londefdef;
                     45: use Apache::scripttag;
                     46: use Apache::edit;
1.79      www        47: use Apache::lonnet;
                     48: use Apache::File;
                     49: 
1.72      albertel   50: #==================================================   Main subroutine: xmlparse  
                     51: #debugging control, to turn on debugging modify the correct handler
                     52: $Apache::lonxml::debug=0;
                     53: 
                     54: #path to the directory containing the file currently being processed
                     55: @pwd=();
                     56: 
                     57: #these two are used for capturing a subset of the output for later processing,
                     58: #don't touch them directly use &startredirection and &endredirection
                     59: @outputstack = ();
                     60: $redirection = 0;
                     61: 
                     62: #controls wheter the <import> tag actually does
                     63: $import = 1;
                     64: @extlinks=();
                     65: 
                     66: # meta mode is a bit weird only some output is to be turned off
                     67: #<output> tag turns metamode off (defined in londefdef.pm)
                     68: $metamode = 0;
                     69: 
                     70: # turns on and of run::evaluate actually derefencing var refs
                     71: $evaluate = 1;
1.7       albertel   72: 
1.74      albertel   73: # data structure for eidt mode, determines what tags can go into what other tags
                     74: %insertlist=();
1.68      www        75: 
1.99      albertel   76: # stores the list of active tag namespaces
1.76      albertel   77: @namespace=();
                     78: 
1.99      albertel   79: # has the dynamic menu been updated to know about this resource
                     80: $Apache::lonxml::registered=0;
                     81: 
1.68      www        82: sub xmlbegin {
                     83:   my $output='';
                     84:   if ($ENV{'browser.mathml'}) {
                     85:       $output='<?xml version="1.0"?>'
                     86:             .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
                     87:             .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                     88:             .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
                     89:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                     90: 		.'xmlns="http://www.w3.org/TR/REC-html40">';
                     91:   } else {
                     92:       $output='<html>';
                     93:   }
                     94:   return $output;
                     95: }
                     96: 
                     97: sub xmlend {
1.103     www        98:     my $discussion='';
                     99:     if ($ENV{'request.course.id'}) {
                    100:        my $symb=&Apache::lonnet::symbread();
                    101:        if ($symb) {
                    102:           my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
                    103:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    104: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    105:           if ($contrib{'version'}) {
                    106:               $discussion.=
                    107:                   '<address><hr /><h2>Course Discussion of Resource</h2>';
                    108:               my $idx;
                    109:               for ($idx=1;$idx<=$contrib{'version'};$idx++) {
                    110:                   my $message=$contrib{$idx.':message'};
                    111:                   $message=~s/\n/\<br \/\>/g;
                    112: 		  $discussion.='<p><b>'.$contrib{$idx.':sendername'}.' at '.
                    113: 		      $contrib{$idx.':senderdomain'}.'</b> ('.
                    114:                       localtime($contrib{$idx.':timestamp'}).
                    115:                       '):<blockquote>'.$message.
                    116:                       '</blockquote></p>'; 
                    117:               }
                    118:               $discussion.='</address>';
                    119:           }
                    120:        }
                    121:     }
                    122:     return $discussion.'</html>';
1.68      www       123: }
                    124: 
1.70      www       125: sub fontsettings() {
                    126:     my $headerstring='';
                    127:     if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) { 
                    128:          $headerstring.=
                    129:              '<meta Content-Type="text/html; charset=x-mac-roman">';
                    130:     }
                    131:     return $headerstring;
                    132: }
                    133: 
1.68      www       134: sub registerurl {
1.100     www       135:     my $forcereg=shift;
1.99      albertel  136:     if ($Apache::lonxml::registered) { return ''; }
1.105     albertel  137:     $Apache::lonxml::registered=1;
1.100     www       138:     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.87      www       139:         my $hwkadd='';
                    140:         if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    141: 	    if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
                    142: 		$hwkadd.=(<<ENDSUBM);
                    143:                      menu.switchbutton
                    144:            (7,1,'subm.gif','view sub','missions',
1.88      www       145:                 'gocmd("/adm/grades","submission")');
1.87      www       146: ENDSUBM
                    147:             }
                    148: 	    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
                    149: 		$hwkadd.=(<<ENDGRDS);
                    150:                      menu.switchbutton
                    151:            (7,2,'pgrd.gif','problem','grades',
1.88      www       152:                 'gocmd("/adm/grades","viewgrades")');
1.87      www       153: ENDGRDS
                    154:             }
                    155: 	    if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
                    156: 		$hwkadd.=(<<ENDPARM);
                    157:                      menu.switchbutton
                    158:            (7,3,'pparm.gif','problem','parms',
1.88      www       159:                 'gocmd("/adm/parmset","set")');
1.87      www       160: ENDPARM
                    161:             }
                    162: 	}
1.86      www       163: 	return (<<ENDREGTHIS);
1.87      www       164:      
1.68      www       165: <script language="JavaScript">
1.71      www       166: // BEGIN LON-CAPA Internal
1.86      www       167: 
1.69      www       168:     function LONCAPAreg() {
                    169: 	  menu=window.open("","LONCAPAmenu");
1.86      www       170:           menu.clearTimeout(menu.menucltim);
1.69      www       171: 	  menu.currentURL=window.location.pathname;
                    172:           menu.currentStale=0;
1.85      www       173:           menu.clearbut(3,1);
                    174:           menu.switchbutton
1.108   ! www       175:        (6,3,'catalog.gif','catalog','info','catalog_info()');
        !           176:           menu.switchbutton
1.85      www       177:        (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');
                    178:           menu.switchbutton
                    179:     (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)');
                    180:           menu.switchbutton
                    181:      (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');
                    182:           menu.switchbutton
                    183:        (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)');
                    184:           menu.switchbutton
                    185:      (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)');
1.94      www       186:           menu.switchbutton
                    187:                             (9,1,'sbkm.gif','set','bookmark','set_bookmark()');
                    188:           menu.switchbutton
                    189:                          (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()');
                    190:           menu.switchbutton
1.95      www       191:                                (9,3,'anot.gif','anno-','tations','annotate()');
1.87      www       192:           $hwkadd
1.69      www       193:     }
1.86      www       194: 
1.69      www       195:     function LONCAPAstale() {
1.86      www       196: 	  menu=window.open("","LONCAPAmenu");
                    197:           menu.currentStale=1;
                    198:           menu.switchbutton
                    199:             (3,1,'reload.gif','return','location','go(currentURL)');
1.90      www       200:           menu.clearbut(7,1);
                    201:           menu.clearbut(7,2);
                    202:           menu.clearbut(7,3);
1.86      www       203:           menu.menucltim=menu.setTimeout(
1.94      www       204:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.108   ! www       205:  'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3)',
1.86      www       206: 			  2000);
                    207: 
1.87      www       208:       }
1.86      www       209: 
                    210: // END LON-CAPA Internal
                    211: </script>
                    212: ENDREGTHIS
                    213: 
                    214:     } else {
                    215:         return (<<ENDDONOTREGTHIS);
                    216: 
                    217: <script language="JavaScript">
                    218: // BEGIN LON-CAPA Internal
                    219: 
                    220:     function LONCAPAreg() {
1.69      www       221: 	  menu=window.open("","LONCAPAmenu");
                    222:           menu.currentStale=1;
1.85      www       223:           menu.clearbut(2,1);
                    224:           menu.clearbut(2,3);
                    225:           menu.clearbut(8,1);
                    226:           menu.clearbut(8,2);
                    227:           menu.clearbut(8,3);
1.86      www       228:           if (menu.currentURL) {
                    229:              menu.switchbutton
                    230:               (3,1,'reload.gif','return','location','go(currentURL)');
                    231:  	  } else {
                    232: 	      menu.clearbut(3,1);
                    233:           }
                    234:     }
                    235: 
                    236:     function LONCAPAstale() {
1.68      www       237:     }
1.86      www       238: 
1.71      www       239: // END LON-CAPA Internal
1.68      www       240: </script>
1.86      www       241: ENDDONOTREGTHIS
                    242: 
                    243:     }
1.69      www       244: }
                    245: 
                    246: sub loadevents() {
                    247:     return 'LONCAPAreg();';
                    248: }
                    249: 
                    250: sub unloadevents() {
                    251:     return 'LONCAPAstale();';
1.68      www       252: }
                    253: 
1.48      albertel  254: sub printalltags {
                    255:   my $temp;
                    256:   foreach $temp (sort keys %Apache::lonxml::alltags) {
1.64      albertel  257:     &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
1.48      albertel  258:   }
                    259: }
1.31      sakharuk  260: 
1.3       sakharuk  261: sub xmlparse {
1.18      albertel  262:  my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96      albertel  263: 
                    264:  &setup_globals($target);
1.48      albertel  265:  #&printalltags();
1.16      albertel  266:  my @pars = ();
1.23      albertel  267:  my $pwd=$ENV{'request.filename'};
                    268:  $pwd =~ s:/[^/]*$::;
                    269:  &newparser(\@pars,\$content_file_string,$pwd);
1.24      sakharuk  270: 
1.3       sakharuk  271:  my $safeeval = new Safe;
1.40      albertel  272:  my $safehole = new Safe::Hole;
1.82      ng        273:  &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3       sakharuk  274: #-------------------- Redefinition of the target in the case of compound target
                    275: 
                    276:  ($target, my @tenta) = split('&&',$target);
                    277: 
                    278:  my @stack = (); 
                    279:  my @parstack = ();
1.17      albertel  280:  &initdepth;
1.67      www       281: 
1.101     albertel  282:  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
                    283: 				   $safeeval,\%style_for_target);
1.67      www       284: 
1.3       sakharuk  285:  return $finaloutput;
1.106     www       286: }
                    287: 
                    288: sub htmlclean {
1.107     www       289:     my ($raw,$full)=@_;
1.106     www       290: 
                    291:     my $tree = HTML::TreeBuilder->new;
                    292:     $tree->ignore_unknown(0);
                    293:     
                    294:     $tree->parse($raw);
                    295: 
1.107     www       296:     my $output= $tree->as_HTML(undef,' ');
1.106     www       297:      
                    298:     $output=~s/\<(br|hr|img)([^\>\/]*)\>/\<$1$2 \/\>/gis;
                    299:     $output=~s/\<\/(br|hr|img)\>//gis;
1.107     www       300:     unless ($full) {
                    301:        $output=~s/\<[\/]*(body|head|html)\>//gis;
                    302:     }
1.106     www       303: 
                    304:     $tree = $tree->delete;
                    305: 
                    306:     return $output;
1.15      albertel  307: }
                    308: 
1.101     albertel  309: sub inner_xmlparse {
                    310:   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
                    311:   &Apache::lonxml::debug('Reentrant parser starting, again?');
                    312:   my $finaloutput = '';
                    313:   my $result;
                    314:   my $token;
                    315:   while ( $#$pars > -1 ) {
                    316:     while ($token = $$pars['-1']->get_token) {
                    317:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
                    318: 	if ($metamode<1) {
                    319: 	  $result=$token->[1];
                    320: 	}
                    321:       } elsif ($token->[0] eq 'PI') {
                    322: 	if ($metamode<1) {
                    323: 	  $result=$token->[2];
                    324: 	}
                    325:       } elsif ($token->[0] eq 'S') {
                    326: 	# add tag to stack 	    
                    327: 	push (@$stack,$token->[1]);
                    328: 	# add parameters list to another stack
                    329: 	push (@$parstack,&parstring($token));
                    330: 	&increasedepth($token);       
                    331: 	if (exists $$style_for_target{$token->[1]}) {
                    332: 	  if ($Apache::lonxml::redirection) {
                    333: 	    $Apache::lonxml::outputstack['-1'] .=  
                    334: 	      &recurse($$style_for_target{$token->[1]},$target,$safeeval,
                    335: 		       $style_for_target,@$parstack);
                    336: 	  } else {
                    337: 	    $finaloutput .= &recurse($$style_for_target{$token->[1]},$target,
                    338: 				     $safeeval,$style_for_target,@$parstack);
                    339: 	  }
                    340: 	} else {
                    341: 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
                    342: 			     $parstack, $pars, $safeeval, $style_for_target);
                    343: 	}              
                    344:       } elsif ($token->[0] eq 'E') {
                    345: 	#clear out any tags that didn't end
                    346: 	while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
                    347: 	  &Apache::lonxml::warning("Unbalanced tags in resource $$stack['-1']");
                    348: 	  &end_tag($stack,$parstack,$token);
                    349: 	}
                    350: 		
                    351: 	if (exists $$style_for_target{'/'."$token->[1]"}) {
                    352: 	  if ($Apache::lonxml::redirection) {
                    353: 	    $Apache::lonxml::outputstack['-1'] .=  
                    354: 	      &recurse($$style_for_target{'/'."$token->[1]"},
                    355: 		       $target,$safeeval,$style_for_target,@$parstack);
                    356: 	  } else {
                    357: 	    $finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"},
                    358: 				     $target,$safeeval,$style_for_target,
                    359: 				     @$parstack);
                    360: 	  }
                    361: 		    
                    362: 	} else {
                    363: 	  $result = &callsub("end_$token->[1]", $target, $token, $stack,
                    364: 			     $parstack, $pars,$safeeval, $style_for_target);
                    365: 	}
                    366:       } else {
                    367: 	&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
                    368:       }
                    369:       #evaluate variable refs in result
                    370:       if ($result ne "") {
                    371: 	if ( $#$parstack > -1 ) {
                    372: 	  if ($Apache::lonxml::redirection) {
                    373: 	    $Apache::lonxml::outputstack['-1'] .= 
                    374: 	      &Apache::run::evaluate($result,$safeeval,$$parstack['-1']);
                    375: 	  } else {
                    376: 	    $finaloutput .= &Apache::run::evaluate($result,$safeeval,
                    377: 						   $$parstack['-1']);
                    378: 	  }
                    379: 	} else {
                    380: 	  $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
                    381: 	}
                    382: 	$result = '';
                    383:       } 
                    384:       if ($token->[0] eq 'E') { 
                    385: 	&end_tag($stack,$parstack,$token);
                    386:       }
                    387:     }
                    388:     pop @$pars;
                    389:     pop @Apache::lonxml::pwd;
                    390:   }
                    391: 
                    392:   # if ($target eq 'meta') {
                    393:   #   $finaloutput.=&endredirection;
                    394:   # }
                    395: 
                    396:   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
                    397:     $finaloutput=&afterburn($finaloutput);
                    398:   }
                    399:   return $finaloutput;
                    400: }
1.67      www       401: 
1.15      albertel  402: sub recurse {
                    403:   my @innerstack = (); 
                    404:   my @innerparstack = ();
                    405:   my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16      albertel  406:   my @pat = ();
1.23      albertel  407:   &newparser(\@pat,\$newarg);
1.15      albertel  408:   my $tokenpat;
                    409:   my $partstring = '';
                    410:   my $output='';
1.16      albertel  411:   my $decls='';
                    412:   while ( $#pat > -1 ) {
                    413:     while  ($tokenpat = $pat[$#pat]->get_token) {
1.57      albertel  414:       if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61      albertel  415: 	if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57      albertel  416:       } elsif ($tokenpat->[0] eq 'PI') {
1.61      albertel  417: 	if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16      albertel  418:       } elsif ($tokenpat->[0] eq 'S') {
                    419: 	push (@innerstack,$tokenpat->[1]);
                    420: 	push (@innerparstack,&parstring($tokenpat));
1.19      albertel  421: 	&increasedepth($tokenpat);
1.84      albertel  422: 	$partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat,
                    423: 			       \@innerstack, \@innerparstack, \@pat,
                    424: 			       $safeeval, $style_for_target);
1.16      albertel  425:       } elsif ($tokenpat->[0] eq 'E') {
                    426: 	#clear out any tags that didn't end
                    427: 	while ($tokenpat->[1] ne $innerstack[$#innerstack] 
1.43      albertel  428: 	       && ($#innerstack > -1)) {
1.49      albertel  429: 	  &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.97      albertel  430: 	  &end_tag(\@innerstack,\@innerparstack,$tokenpat);
1.43      albertel  431: 	}
1.84      albertel  432: 	$partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,
                    433: 			       \@innerstack, \@innerparstack, \@pat,
                    434: 			       $safeeval, $style_for_target);
1.57      albertel  435:       } else {
                    436: 	&Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16      albertel  437:       }
                    438:       #pass both the variable to the style tag, and the tag we 
                    439:       #are processing inside the <definedtag>
                    440:       if ( $partstring ne "" ) {
                    441: 	if ( $#parstack > -1 ) { 
                    442: 	  if ( $#innerparstack > -1 ) { 
                    443: 	    $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
                    444: 	  } else {
                    445: 	    $decls= $parstack[$#parstack];
                    446: 	  }
                    447: 	} else {
                    448: 	  if ( $#innerparstack > -1 ) { 
                    449: 	    $decls=$innerparstack[$#innerparstack];
                    450: 	  } else {
                    451: 	    $decls='';
                    452: 	  }
                    453: 	}
                    454: 	$output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
                    455: 	$partstring = '';
                    456:       }
1.17      albertel  457:       if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19      albertel  458: 				 &decreasedepth($tokenpat);}
1.15      albertel  459:     }
1.16      albertel  460:     pop @pat;
1.23      albertel  461:     pop @Apache::lonxml::pwd;
1.15      albertel  462:   }
                    463:   return $output;
1.7       albertel  464: }
                    465: 
                    466: sub callsub {
1.84      albertel  467:   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7       albertel  468:   my $currentstring='';
1.72      albertel  469:   my $nodefault;
1.7       albertel  470:   {
1.59      albertel  471:     my $sub1;
1.7       albertel  472:     no strict 'refs';
1.68      www       473:     my $tag=$token->[1];
                    474:     my $space=$Apache::lonxml::alltags{$tag};
                    475:     if (!$space) {
                    476: 	$tag=~tr/A-Z/a-z/;
                    477: 	$sub=~tr/A-Z/a-z/;
                    478: 	$space=$Apache::lonxml::alltags{$tag}
                    479:     }
1.97      albertel  480: 
                    481:     my $deleted=0;
                    482:     $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
                    483:     if (($token->[0] eq 'S') && ($target eq 'modified')) {
                    484:       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
                    485: 					     $parstack,$parser,$safeeval,
                    486: 					     $style);
                    487:     }
                    488:     if (!$deleted) {
                    489:       if ($space) {
                    490: 	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
                    491: 	$sub1="$space\:\:$sub";
                    492: 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
                    493: 					     $parstack,$parser,$safeeval,
                    494: 					     $style);
                    495:       } else {
                    496: 	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
                    497: 	if ($metamode <1) {
                    498: 	  if (defined($token->[4]) && ($metamode < 1)) {
                    499: 	    $currentstring = $token->[4];
                    500: 	  } else {
                    501: 	    $currentstring = $token->[2];
                    502: 	  }
1.62      sakharuk  503: 	}
1.7       albertel  504:       }
1.97      albertel  505:       #    &Apache::lonxml::debug("nodefalt:$nodefault:");
                    506:       if ($currentstring eq '' && $nodefault eq '') {
                    507: 	if ($target eq 'edit') {
                    508: 	  &Apache::lonxml::debug("doing default edit for $token->[1]");
                    509: 	  if ($token->[0] eq 'S') {
                    510: 	    $currentstring = &Apache::edit::tag_start($target,$token);
                    511: 	  } elsif ($token->[0] eq 'E') {
                    512: 	    $currentstring = &Apache::edit::tag_end($target,$token);
                    513: 	  }
                    514: 	} elsif ($target eq 'modified') {
                    515: 	  if ($token->[0] eq 'S') {
                    516: 	    $currentstring = $token->[4];
                    517: 	    $currentstring.=&Apache::edit::handle_insert();
                    518: 	  } else {
                    519: 	    $currentstring = $token->[2];
                    520: 	  }
1.72      albertel  521: 	}
                    522:       }
1.7       albertel  523:     }
                    524:     use strict 'refs';
                    525:   }
                    526:   return $currentstring;
1.82      ng        527: }
                    528: 
1.96      albertel  529: sub setup_globals {
                    530:   my ($target)=@_;
1.99      albertel  531:   $Apache::lonxml::registered = 0;
1.101     albertel  532:   @Apache::lonxml::pwd=();
1.96      albertel  533:   if ($target eq 'meta') {
                    534:     $Apache::lonxml::redirection = 0;
                    535:     $Apache::lonxml::metamode = 1;
                    536:     $Apache::lonxml::evaluate = 1;
                    537:     $Apache::lonxml::import = 0;
                    538:   } elsif ($target eq 'grade') {
                    539:     &startredirection;
                    540:     $Apache::lonxml::metamode = 0;
                    541:     $Apache::lonxml::evaluate = 1;
                    542:     $Apache::lonxml::import = 1;
                    543:   } elsif ($target eq 'modified') {
                    544:     $Apache::lonxml::redirection = 0;
                    545:     $Apache::lonxml::metamode = 0;
                    546:     $Apache::lonxml::evaluate = 0;
                    547:     $Apache::lonxml::import = 0;
                    548:   } elsif ($target eq 'edit') {
                    549:     $Apache::lonxml::redirection = 0;
                    550:     $Apache::lonxml::metamode = 0;
                    551:     $Apache::lonxml::evaluate = 0;
                    552:     $Apache::lonxml::import = 0;
                    553:   } else {
                    554:     $Apache::lonxml::redirection = 0;
                    555:     $Apache::lonxml::metamode = 0;
                    556:     $Apache::lonxml::evaluate = 1;
                    557:     $Apache::lonxml::import = 1;
                    558:   }
                    559: }
                    560: 
1.82      ng        561: sub init_safespace {
                    562:   my ($target,$safeeval,$safehole,$safeinit) = @_;
                    563:   $safeeval->permit("entereval");
                    564:   $safeeval->permit(":base_math");
                    565:   $safeeval->permit("sort");
                    566:   $safeeval->deny(":base_io");
1.102     albertel  567:   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.82      ng        568:   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
                    569:   
                    570:   $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
                    571:   $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
                    572:   $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
                    573:   $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
                    574:   $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
                    575:   $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
                    576:   $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
                    577:   $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
                    578:   $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
                    579:   $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
                    580:   $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
                    581:   $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
                    582:   $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
                    583:   $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
                    584:   $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
                    585:   $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
                    586:   $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
                    587:   $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
                    588:   $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.91      ng        589:   $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
                    590:   $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
                    591:   $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
                    592:   $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
                    593:   $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
                    594:   $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
                    595:   $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
                    596:   $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
                    597:   $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
                    598:   $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
                    599:   $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93      ng        600:   $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91      ng        601:   $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
                    602:   $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
                    603:   $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
                    604:   $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
                    605:   $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
                    606:   $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
                    607:   $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
                    608:   $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
                    609:   $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
                    610: 
1.82      ng        611: #need to inspect this class of ops
                    612: # $safeeval->deny(":base_orig");
1.91      ng        613:   $safeinit .= ';$external::target="'.$target.'";';
1.82      ng        614:   $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
                    615:   &Apache::run::run($safeinit,$safeeval);
1.17      albertel  616: }
                    617: 
1.55      albertel  618: sub startredirection {
                    619:   $Apache::lonxml::redirection++;
                    620:   push (@Apache::lonxml::outputstack, '');
                    621: }
                    622: 
                    623: sub endredirection {
                    624:   if (!$Apache::lonxml::redirection) {
1.72      albertel  625:     &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
1.55      albertel  626:     return '';
                    627:   }
                    628:   $Apache::lonxml::redirection--;
                    629:   pop @Apache::lonxml::outputstack;
1.97      albertel  630: }
                    631: 
                    632: sub end_tag {
                    633:   my ($tagstack,$parstack,$token)=@_;
                    634:   pop(@$tagstack);
                    635:   pop(@$parstack);
                    636:   &decreasedepth($token);
1.55      albertel  637: }
                    638: 
1.17      albertel  639: sub initdepth {
                    640:   @Apache::lonxml::depthcounter=();
                    641:   $Apache::lonxml::depth=-1;
                    642:   $Apache::lonxml::olddepth=-1;
                    643: }
                    644: 
                    645: sub increasedepth {
1.19      albertel  646:   my ($token) = @_;
1.17      albertel  647:   $Apache::lonxml::depth++;
                    648:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
                    649:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
                    650:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
                    651:   }
1.42      albertel  652:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64      albertel  653:   &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54      albertel  654: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17      albertel  655: }
                    656: 
                    657: sub decreasedepth {
1.19      albertel  658:   my ($token) = @_;
1.17      albertel  659:   $Apache::lonxml::depth--;
1.36      albertel  660:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
                    661:     $#Apache::lonxml::depthcounter--;
                    662:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
                    663:   }
1.43      albertel  664:   if (  $Apache::lonxml::depth < -1) {
1.49      albertel  665:     &Apache::lonxml::warning("Unbalanced tags in resource");   
1.43      albertel  666:     $Apache::lonxml::depth='-1';
                    667:   }
1.42      albertel  668:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64      albertel  669:   &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54      albertel  670: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1       sakharuk  671: }
1.19      albertel  672: 
                    673: sub get_all_text {
                    674: 
                    675:  my($tag,$pars)= @_;
                    676:  my $depth=0;
                    677:  my $token;
                    678:  my $result='';
1.57      albertel  679:  if ( $tag =~ m:^/: ) { 
                    680:    my $tag=substr($tag,1); 
                    681: #   &Apache::lonxml::debug("have:$tag:");
                    682:    while (($depth >=0) && ($token = $pars->get_token)) {
                    683: #     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
                    684:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    685:        $result.=$token->[1];
                    686:      } elsif ($token->[0] eq 'PI') {
                    687:        $result.=$token->[2];
                    688:      } elsif ($token->[0] eq 'S') {
                    689:        if ($token->[1] eq $tag) { $depth++; }
                    690:        $result.=$token->[4];
                    691:      } elsif ($token->[0] eq 'E')  {
                    692:        if ( $token->[1] eq $tag) { $depth--; }
                    693:        #skip sending back the last end tag
                    694:        if ($depth > -1) { $result.=$token->[2]; } else {
                    695: 	 $pars->unget_token($token);
                    696:        }
                    697:      }
                    698:    }
                    699:  } else {
                    700:    while ($token = $pars->get_token) {
                    701: #     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
                    702:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    703:        $result.=$token->[1];
                    704:      } elsif ($token->[0] eq 'PI') {
                    705:        $result.=$token->[2];
                    706:      } elsif ($token->[0] eq 'S') {
                    707:        if ( $token->[1] eq $tag) { 
                    708: 	 $pars->unget_token($token); last;
                    709:        } else {
                    710: 	 $result.=$token->[4];
                    711:        }
                    712:      } elsif ($token->[0] eq 'E')  {
                    713:        $result.=$token->[2];
1.36      albertel  714:      }
1.19      albertel  715:    }
                    716:  }
1.49      albertel  717: # &Apache::lonxml::debug("Exit:$result:");
1.19      albertel  718:  return $result
                    719: }
                    720: 
1.23      albertel  721: sub newparser {
                    722:   my ($parser,$contentref,$dir) = @_;
                    723:   push (@$parser,HTML::TokeParser->new($contentref));
1.56      albertel  724:   $$parser['-1']->xml_mode('1');
1.23      albertel  725:   if ( $dir eq '' ) {
                    726:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
                    727:   } else {
                    728:     push (@Apache::lonxml::pwd, $dir);
                    729:   } 
                    730: #  &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
                    731: #  &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
                    732: }
1.1       sakharuk  733: 
1.8       albertel  734: sub parstring {
                    735:   my ($token) = @_;
                    736:   my $temp='';
1.20      albertel  737:   map {
1.35      www       738:     unless ($_=~/\W/) {
1.42      albertel  739:       my $val=$token->[2]->{$_};
1.53      albertel  740:       $val =~ s/([\%\@\\])/\\$1/g;
1.51      albertel  741:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42      albertel  742:       $temp .= "my \$$_=\"$val\";"
1.20      albertel  743:     }
                    744:   } @{$token->[3]};
1.8       albertel  745:   return $temp;
                    746: }
1.22      albertel  747: 
1.34      www       748: sub writeallows {
                    749:     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
                    750:     my $thisdir=$thisurl;
                    751:     $thisdir=~s/\/[^\/]+$//;
                    752:     my %httpref=();
                    753:     map {
                    754:        $httpref{'httpref.'.
                    755:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;              } @extlinks;
                    756:     &Apache::lonnet::appenv(%httpref);
                    757: }
                    758: 
1.66      www       759: #
                    760: # Afterburner handles anchors, highlights and links
                    761: #
                    762: sub afterburn {
                    763:     my $result=shift;
                    764:     map {
                    765:        my ($name, $value) = split(/=/,$_);
                    766:        $value =~ tr/+/ /;
                    767:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    768:        if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
                    769:            unless ($ENV{'form.'.$name}) {
                    770:               $ENV{'form.'.$name}=$value;
                    771: 	   }
                    772:        }
                    773:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    774:     if ($ENV{'form.highlight'}) {
                    775:         map {
                    776:            my $anchorname=$_;
                    777: 	   my $matchthis=$anchorname;
                    778:            $matchthis=~s/\_+/\\s\+/g;
                    779:            $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
                    780:        } split(/\,/,$ENV{'form.highlight'});
                    781:     }
                    782:     if ($ENV{'form.link'}) {
                    783:         map {
                    784:            my ($anchorname,$linkurl)=split(/\>/,$_);
                    785: 	   my $matchthis=$anchorname;
                    786:            $matchthis=~s/\_+/\\s\+/g;
                    787:            $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
                    788:        } split(/\,/,$ENV{'form.link'});
                    789:     }
                    790:     if ($ENV{'form.anchor'}) {
                    791:         my $anchorname=$ENV{'form.anchor'};
                    792: 	my $matchthis=$anchorname;
                    793:         $matchthis=~s/\_+/\\s\+/g;
                    794:         $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
                    795:         $result.=(<<"ENDSCRIPT");
                    796: <script>
                    797:     document.location.hash='$anchorname';
                    798: </script>
                    799: ENDSCRIPT
                    800:     }
                    801:     return $result;
                    802: }
                    803: 
1.79      www       804: sub storefile {
                    805:     my ($file,$contents)=@_;
                    806:     if (my $fh=Apache::File->new('>'.$file)) {
                    807: 	print $fh $contents;
                    808:         $fh->close();
                    809:     }
                    810: }
                    811: 
1.78      www       812: sub inserteditinfo {
                    813:       my ($result,$filecontents)=@_;
                    814:       unless ($filecontents) {
                    815: 	  $filecontents=(<<SIMPLECONTENT);
                    816: <html>
                    817: <head>
                    818: <title>
                    819:                            Title of Document Goes Here
                    820: </title>
                    821: </head>
                    822: <body bgcolor="#FFFFFF">
                    823: 
                    824:                            Body of Document Goes Here
                    825: 
                    826: </body>
                    827: </html>
                    828: SIMPLECONTENT
                    829:       }
                    830:       my $editheader='<a href="#editsection">Edit below</a><hr />';
                    831:       my $editfooter=(<<ENDFOOTER);
                    832: <hr />
                    833: <a name="editsection" />
                    834: <form method="post">
                    835: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
                    836: <br />
1.107     www       837: <input type="submit" name="attemptclean" 
                    838:        value="Save and then attempt to clean HTML" />
                    839: <input type="submit" name="savethisfile" value="Save this" />
1.78      www       840: </form>
                    841: ENDFOOTER
                    842:       $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
                    843:       $result=~s/(\<\/body\>)/$editfooter/is;
                    844:       return $result;
                    845: }
                    846: 
1.24      sakharuk  847: sub handler {
                    848:   my $request=shift;
1.68      www       849: 
1.64      albertel  850:   my $target='web';
1.68      www       851: 
1.65      albertel  852:   $Apache::lonxml::debug=0;
1.68      www       853: 
1.25      sakharuk  854:   if ($ENV{'browser.mathml'}) {
1.27      albertel  855:     $request->content_type('text/xml');
                    856:   } else {
                    857:     $request->content_type('text/html');
1.25      sakharuk  858:   }
1.64      albertel  859:   
1.27      albertel  860:   $request->send_http_header;
1.64      albertel  861:   
1.45      www       862:   return OK if $request->header_only;
1.27      albertel  863: 
1.79      www       864: 
                    865:   my $file=&Apache::lonnet::filelocation("",$request->uri);
1.78      www       866: #
                    867: # Edit action? Save file.
                    868: #
                    869:   unless ($ENV{'request.state'} eq 'published') {
1.107     www       870:       if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
1.79      www       871: 	  &storefile($file,$ENV{'form.filecont'});
1.78      www       872:       }
                    873:   }
1.24      sakharuk  874:   my %mystyle;
1.50      albertel  875:   my $result = ''; 
                    876:   my $filecontents=&Apache::lonnet::getfile($file);
                    877:   if ($filecontents == -1) {
1.78      www       878:     $result=(<<ENDNOTFOUND);
                    879: <html>
                    880: <head>
                    881: <title>File not found</title>
                    882: </head>
                    883: <body bgcolor="#FFFFFF">
                    884: <b>File not found: $file</b>
                    885: </body>
                    886: </html>
                    887: ENDNOTFOUND
1.50      albertel  888:     $filecontents='';
                    889:   } else {
1.107     www       890:       unless ($ENV{'request.state'} eq 'published') {
                    891:          if ($ENV{'form.attemptclean'}) {
                    892: 	    $filecontents=&htmlclean($filecontents,1);
                    893:          }
                    894:       }
1.50      albertel  895:     $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
1.78      www       896:   }
                    897: 
                    898: #
                    899: # Edit action? Insert editing commands
                    900: #
                    901:   unless ($ENV{'request.state'} eq 'published') {
                    902:       $result=&inserteditinfo($result,$filecontents);
1.66      www       903:   }
1.50      albertel  904: 
1.67      www       905:   $request->print($result);
1.64      albertel  906: 
1.34      www       907:   writeallows($request->uri);
1.45      www       908:   return OK;
1.24      sakharuk  909: }
                    910:  
1.22      albertel  911: sub debug {
                    912:   if ($Apache::lonxml::debug eq 1) {
1.96      albertel  913:     print("DEBUG:".$_[0]."<br />\n");
1.22      albertel  914:   }
                    915: }
1.49      albertel  916: 
1.22      albertel  917: sub error {
1.74      albertel  918:   if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
1.55      albertel  919:     print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52      albertel  920:   } else {
                    921:     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
                    922:     #notify author
                    923:     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
                    924:     #notify course
                    925:     if ( $ENV{'request.course.id'} ) {
                    926:       my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
                    927:       foreach my $user (split /\,/, $users) {
                    928: 	($user,my $domain) = split /:/, $user;
1.54      albertel  929: 	&Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52      albertel  930:       }
                    931:     }
1.74      albertel  932: 
1.52      albertel  933:     #FIXME probably shouldn't have me get everything forever.
1.54      albertel  934:     &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
1.74      albertel  935:     #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52      albertel  936:   }
1.22      albertel  937: }
1.49      albertel  938: 
1.22      albertel  939: sub warning {
1.73      harris41  940:   if ($ENV{'request.state'} eq 'construct') {
1.55      albertel  941:     print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.73      harris41  942:   }
1.83      albertel  943: }
                    944: 
                    945: sub get_param {
                    946:   my ($param,$parstack,$safeeval,$context) = @_;
                    947:   if ( ! $context ) { $context = -1; }
                    948:   my $args ='';
                    949:   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
                    950:   return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1.22      albertel  951: }
                    952: 
1.74      albertel  953: sub register_insert {
1.75      albertel  954:   my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1.74      albertel  955:   my $i;
1.76      albertel  956:   my $tagnum=0;
1.74      albertel  957:   my @order;
                    958:   for ($i=0;$i < $#data; $i++) {
                    959:     my $line = $data[$i];
                    960:     if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
                    961:     if ( $line =~ /TABLE/ ) { last; }
1.92      albertel  962:     my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
1.76      albertel  963:     $insertlist{"$tagnum.tag"} = $tag;
                    964:     $insertlist{"$tagnum.description"} = $descrip;
1.92      albertel  965:     $insertlist{"$tagnum.color"} = $color;
1.76      albertel  966:     $insertlist{"$tagnum.function"} = $function;
                    967:     $insertlist{"$tagnum.show"}= $show;
1.92      albertel  968:     $insertlist{"$tag.num"}=$tagnum;
1.76      albertel  969:     $tagnum++;
1.74      albertel  970:   }
1.76      albertel  971:   $i++; #skipping TABLE line
                    972:   $tagnum = 0;
1.74      albertel  973:   for (;$i < $#data;$i++) {
                    974:     my $line = $data[$i];
1.76      albertel  975:     my ($mnemonic,@which) = split(/ +/,$line);
                    976:     my $tag = $insertlist{"$tagnum.tag"};
1.74      albertel  977:     for (my $j=0;$j <$#which;$j++) {
                    978:       if ( $which[$j] eq 'Y' ) {
1.76      albertel  979: 	if ($insertlist{"$j.show"} ne 'no') {
                    980: 	  push(@{ $insertlist{"$tag.which"} },$j);
                    981: 	}
1.74      albertel  982:       }
                    983:     }
1.76      albertel  984:     $tagnum++;
1.74      albertel  985:   }
                    986: }
1.98      albertel  987: 
                    988: sub description {
                    989:   my ($token)=@_;
                    990:   return $insertlist{$insertlist{"$token->[1].num"}.'.description'};
                    991: }
1.1       sakharuk  992: 1;
                    993: __END__
1.68      www       994: 
                    995: 

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