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

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.106   ! www        16: # 8/7 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
                    175:        (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');
                    176:           menu.switchbutton
                    177:     (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)');
                    178:           menu.switchbutton
                    179:      (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');
                    180:           menu.switchbutton
                    181:        (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)');
                    182:           menu.switchbutton
                    183:      (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)');
1.94      www       184:           menu.switchbutton
                    185:                             (9,1,'sbkm.gif','set','bookmark','set_bookmark()');
                    186:           menu.switchbutton
                    187:                          (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()');
                    188:           menu.switchbutton
1.95      www       189:                                (9,3,'anot.gif','anno-','tations','annotate()');
1.87      www       190:           $hwkadd
1.69      www       191:     }
1.86      www       192: 
1.69      www       193:     function LONCAPAstale() {
1.86      www       194: 	  menu=window.open("","LONCAPAmenu");
                    195:           menu.currentStale=1;
                    196:           menu.switchbutton
                    197:             (3,1,'reload.gif','return','location','go(currentURL)');
1.90      www       198:           menu.clearbut(7,1);
                    199:           menu.clearbut(7,2);
                    200:           menu.clearbut(7,3);
1.86      www       201:           menu.menucltim=menu.setTimeout(
1.94      www       202:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
                    203:  'clearbut(9,1);clearbut(9,2);clearbut(9,3);',
1.86      www       204: 			  2000);
                    205: 
1.87      www       206:       }
1.86      www       207: 
                    208: // END LON-CAPA Internal
                    209: </script>
                    210: ENDREGTHIS
                    211: 
                    212:     } else {
                    213:         return (<<ENDDONOTREGTHIS);
                    214: 
                    215: <script language="JavaScript">
                    216: // BEGIN LON-CAPA Internal
                    217: 
                    218:     function LONCAPAreg() {
1.69      www       219: 	  menu=window.open("","LONCAPAmenu");
                    220:           menu.currentStale=1;
1.85      www       221:           menu.clearbut(2,1);
                    222:           menu.clearbut(2,3);
                    223:           menu.clearbut(8,1);
                    224:           menu.clearbut(8,2);
                    225:           menu.clearbut(8,3);
1.86      www       226:           if (menu.currentURL) {
                    227:              menu.switchbutton
                    228:               (3,1,'reload.gif','return','location','go(currentURL)');
                    229:  	  } else {
                    230: 	      menu.clearbut(3,1);
                    231:           }
                    232:     }
                    233: 
                    234:     function LONCAPAstale() {
1.68      www       235:     }
1.86      www       236: 
1.71      www       237: // END LON-CAPA Internal
1.68      www       238: </script>
1.86      www       239: ENDDONOTREGTHIS
                    240: 
                    241:     }
1.69      www       242: }
                    243: 
                    244: sub loadevents() {
                    245:     return 'LONCAPAreg();';
                    246: }
                    247: 
                    248: sub unloadevents() {
                    249:     return 'LONCAPAstale();';
1.68      www       250: }
                    251: 
1.48      albertel  252: sub printalltags {
                    253:   my $temp;
                    254:   foreach $temp (sort keys %Apache::lonxml::alltags) {
1.64      albertel  255:     &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
1.48      albertel  256:   }
                    257: }
1.31      sakharuk  258: 
1.3       sakharuk  259: sub xmlparse {
1.18      albertel  260:  my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.96      albertel  261: 
                    262:  &setup_globals($target);
1.48      albertel  263:  #&printalltags();
1.16      albertel  264:  my @pars = ();
1.23      albertel  265:  my $pwd=$ENV{'request.filename'};
                    266:  $pwd =~ s:/[^/]*$::;
                    267:  &newparser(\@pars,\$content_file_string,$pwd);
1.24      sakharuk  268: 
1.3       sakharuk  269:  my $safeeval = new Safe;
1.40      albertel  270:  my $safehole = new Safe::Hole;
1.82      ng        271:  &init_safespace($target,$safeeval,$safehole,$safeinit);
1.3       sakharuk  272: #-------------------- Redefinition of the target in the case of compound target
                    273: 
                    274:  ($target, my @tenta) = split('&&',$target);
                    275: 
                    276:  my @stack = (); 
                    277:  my @parstack = ();
1.17      albertel  278:  &initdepth;
1.67      www       279: 
1.101     albertel  280:  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
                    281: 				   $safeeval,\%style_for_target);
1.67      www       282: 
1.3       sakharuk  283:  return $finaloutput;
1.106   ! www       284: }
        !           285: 
        !           286: sub htmlclean {
        !           287:     my $raw=shift;
        !           288: 
        !           289:     my $tree = HTML::TreeBuilder->new;
        !           290:     $tree->ignore_unknown(0);
        !           291:     
        !           292:     $tree->parse($raw);
        !           293:     my %emptyhash=();
        !           294: 
        !           295:     my $output= $tree->as_HTML(undef,' ',\%emptyhash), "\n";
        !           296:      
        !           297:     $output=~s/\<(br|hr|img)([^\>\/]*)\>/\<$1$2 \/\>/gis;
        !           298:     $output=~s/\<\/(br|hr|img)\>//gis;
        !           299:     $output=~s/\<[\/]*(body|head|html)\>//gis;
        !           300: 
        !           301:     $tree = $tree->delete;
        !           302: 
        !           303:     return $output;
1.15      albertel  304: }
                    305: 
1.101     albertel  306: sub inner_xmlparse {
                    307:   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
                    308:   &Apache::lonxml::debug('Reentrant parser starting, again?');
                    309:   my $finaloutput = '';
                    310:   my $result;
                    311:   my $token;
                    312:   while ( $#$pars > -1 ) {
                    313:     while ($token = $$pars['-1']->get_token) {
                    314:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
                    315: 	if ($metamode<1) {
                    316: 	  $result=$token->[1];
                    317: 	}
                    318:       } elsif ($token->[0] eq 'PI') {
                    319: 	if ($metamode<1) {
                    320: 	  $result=$token->[2];
                    321: 	}
                    322:       } elsif ($token->[0] eq 'S') {
                    323: 	# add tag to stack 	    
                    324: 	push (@$stack,$token->[1]);
                    325: 	# add parameters list to another stack
                    326: 	push (@$parstack,&parstring($token));
                    327: 	&increasedepth($token);       
                    328: 	if (exists $$style_for_target{$token->[1]}) {
                    329: 	  if ($Apache::lonxml::redirection) {
                    330: 	    $Apache::lonxml::outputstack['-1'] .=  
                    331: 	      &recurse($$style_for_target{$token->[1]},$target,$safeeval,
                    332: 		       $style_for_target,@$parstack);
                    333: 	  } else {
                    334: 	    $finaloutput .= &recurse($$style_for_target{$token->[1]},$target,
                    335: 				     $safeeval,$style_for_target,@$parstack);
                    336: 	  }
                    337: 	} else {
                    338: 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
                    339: 			     $parstack, $pars, $safeeval, $style_for_target);
                    340: 	}              
                    341:       } elsif ($token->[0] eq 'E') {
                    342: 	#clear out any tags that didn't end
                    343: 	while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
                    344: 	  &Apache::lonxml::warning("Unbalanced tags in resource $$stack['-1']");
                    345: 	  &end_tag($stack,$parstack,$token);
                    346: 	}
                    347: 		
                    348: 	if (exists $$style_for_target{'/'."$token->[1]"}) {
                    349: 	  if ($Apache::lonxml::redirection) {
                    350: 	    $Apache::lonxml::outputstack['-1'] .=  
                    351: 	      &recurse($$style_for_target{'/'."$token->[1]"},
                    352: 		       $target,$safeeval,$style_for_target,@$parstack);
                    353: 	  } else {
                    354: 	    $finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"},
                    355: 				     $target,$safeeval,$style_for_target,
                    356: 				     @$parstack);
                    357: 	  }
                    358: 		    
                    359: 	} else {
                    360: 	  $result = &callsub("end_$token->[1]", $target, $token, $stack,
                    361: 			     $parstack, $pars,$safeeval, $style_for_target);
                    362: 	}
                    363:       } else {
                    364: 	&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
                    365:       }
                    366:       #evaluate variable refs in result
                    367:       if ($result ne "") {
                    368: 	if ( $#$parstack > -1 ) {
                    369: 	  if ($Apache::lonxml::redirection) {
                    370: 	    $Apache::lonxml::outputstack['-1'] .= 
                    371: 	      &Apache::run::evaluate($result,$safeeval,$$parstack['-1']);
                    372: 	  } else {
                    373: 	    $finaloutput .= &Apache::run::evaluate($result,$safeeval,
                    374: 						   $$parstack['-1']);
                    375: 	  }
                    376: 	} else {
                    377: 	  $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
                    378: 	}
                    379: 	$result = '';
                    380:       } 
                    381:       if ($token->[0] eq 'E') { 
                    382: 	&end_tag($stack,$parstack,$token);
                    383:       }
                    384:     }
                    385:     pop @$pars;
                    386:     pop @Apache::lonxml::pwd;
                    387:   }
                    388: 
                    389:   # if ($target eq 'meta') {
                    390:   #   $finaloutput.=&endredirection;
                    391:   # }
                    392: 
                    393:   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
                    394:     $finaloutput=&afterburn($finaloutput);
                    395:   }
                    396:   return $finaloutput;
                    397: }
1.67      www       398: 
1.15      albertel  399: sub recurse {
                    400:   my @innerstack = (); 
                    401:   my @innerparstack = ();
                    402:   my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16      albertel  403:   my @pat = ();
1.23      albertel  404:   &newparser(\@pat,\$newarg);
1.15      albertel  405:   my $tokenpat;
                    406:   my $partstring = '';
                    407:   my $output='';
1.16      albertel  408:   my $decls='';
                    409:   while ( $#pat > -1 ) {
                    410:     while  ($tokenpat = $pat[$#pat]->get_token) {
1.57      albertel  411:       if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61      albertel  412: 	if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57      albertel  413:       } elsif ($tokenpat->[0] eq 'PI') {
1.61      albertel  414: 	if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16      albertel  415:       } elsif ($tokenpat->[0] eq 'S') {
                    416: 	push (@innerstack,$tokenpat->[1]);
                    417: 	push (@innerparstack,&parstring($tokenpat));
1.19      albertel  418: 	&increasedepth($tokenpat);
1.84      albertel  419: 	$partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat,
                    420: 			       \@innerstack, \@innerparstack, \@pat,
                    421: 			       $safeeval, $style_for_target);
1.16      albertel  422:       } elsif ($tokenpat->[0] eq 'E') {
                    423: 	#clear out any tags that didn't end
                    424: 	while ($tokenpat->[1] ne $innerstack[$#innerstack] 
1.43      albertel  425: 	       && ($#innerstack > -1)) {
1.49      albertel  426: 	  &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.97      albertel  427: 	  &end_tag(\@innerstack,\@innerparstack,$tokenpat);
1.43      albertel  428: 	}
1.84      albertel  429: 	$partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,
                    430: 			       \@innerstack, \@innerparstack, \@pat,
                    431: 			       $safeeval, $style_for_target);
1.57      albertel  432:       } else {
                    433: 	&Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16      albertel  434:       }
                    435:       #pass both the variable to the style tag, and the tag we 
                    436:       #are processing inside the <definedtag>
                    437:       if ( $partstring ne "" ) {
                    438: 	if ( $#parstack > -1 ) { 
                    439: 	  if ( $#innerparstack > -1 ) { 
                    440: 	    $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
                    441: 	  } else {
                    442: 	    $decls= $parstack[$#parstack];
                    443: 	  }
                    444: 	} else {
                    445: 	  if ( $#innerparstack > -1 ) { 
                    446: 	    $decls=$innerparstack[$#innerparstack];
                    447: 	  } else {
                    448: 	    $decls='';
                    449: 	  }
                    450: 	}
                    451: 	$output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
                    452: 	$partstring = '';
                    453:       }
1.17      albertel  454:       if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19      albertel  455: 				 &decreasedepth($tokenpat);}
1.15      albertel  456:     }
1.16      albertel  457:     pop @pat;
1.23      albertel  458:     pop @Apache::lonxml::pwd;
1.15      albertel  459:   }
                    460:   return $output;
1.7       albertel  461: }
                    462: 
                    463: sub callsub {
1.84      albertel  464:   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.7       albertel  465:   my $currentstring='';
1.72      albertel  466:   my $nodefault;
1.7       albertel  467:   {
1.59      albertel  468:     my $sub1;
1.7       albertel  469:     no strict 'refs';
1.68      www       470:     my $tag=$token->[1];
                    471:     my $space=$Apache::lonxml::alltags{$tag};
                    472:     if (!$space) {
                    473: 	$tag=~tr/A-Z/a-z/;
                    474: 	$sub=~tr/A-Z/a-z/;
                    475: 	$space=$Apache::lonxml::alltags{$tag}
                    476:     }
1.97      albertel  477: 
                    478:     my $deleted=0;
                    479:     $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
                    480:     if (($token->[0] eq 'S') && ($target eq 'modified')) {
                    481:       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
                    482: 					     $parstack,$parser,$safeeval,
                    483: 					     $style);
                    484:     }
                    485:     if (!$deleted) {
                    486:       if ($space) {
                    487: 	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
                    488: 	$sub1="$space\:\:$sub";
                    489: 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
                    490: 					     $parstack,$parser,$safeeval,
                    491: 					     $style);
                    492:       } else {
                    493: 	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
                    494: 	if ($metamode <1) {
                    495: 	  if (defined($token->[4]) && ($metamode < 1)) {
                    496: 	    $currentstring = $token->[4];
                    497: 	  } else {
                    498: 	    $currentstring = $token->[2];
                    499: 	  }
1.62      sakharuk  500: 	}
1.7       albertel  501:       }
1.97      albertel  502:       #    &Apache::lonxml::debug("nodefalt:$nodefault:");
                    503:       if ($currentstring eq '' && $nodefault eq '') {
                    504: 	if ($target eq 'edit') {
                    505: 	  &Apache::lonxml::debug("doing default edit for $token->[1]");
                    506: 	  if ($token->[0] eq 'S') {
                    507: 	    $currentstring = &Apache::edit::tag_start($target,$token);
                    508: 	  } elsif ($token->[0] eq 'E') {
                    509: 	    $currentstring = &Apache::edit::tag_end($target,$token);
                    510: 	  }
                    511: 	} elsif ($target eq 'modified') {
                    512: 	  if ($token->[0] eq 'S') {
                    513: 	    $currentstring = $token->[4];
                    514: 	    $currentstring.=&Apache::edit::handle_insert();
                    515: 	  } else {
                    516: 	    $currentstring = $token->[2];
                    517: 	  }
1.72      albertel  518: 	}
                    519:       }
1.7       albertel  520:     }
                    521:     use strict 'refs';
                    522:   }
                    523:   return $currentstring;
1.82      ng        524: }
                    525: 
1.96      albertel  526: sub setup_globals {
                    527:   my ($target)=@_;
1.99      albertel  528:   $Apache::lonxml::registered = 0;
1.101     albertel  529:   @Apache::lonxml::pwd=();
1.96      albertel  530:   if ($target eq 'meta') {
                    531:     $Apache::lonxml::redirection = 0;
                    532:     $Apache::lonxml::metamode = 1;
                    533:     $Apache::lonxml::evaluate = 1;
                    534:     $Apache::lonxml::import = 0;
                    535:   } elsif ($target eq 'grade') {
                    536:     &startredirection;
                    537:     $Apache::lonxml::metamode = 0;
                    538:     $Apache::lonxml::evaluate = 1;
                    539:     $Apache::lonxml::import = 1;
                    540:   } elsif ($target eq 'modified') {
                    541:     $Apache::lonxml::redirection = 0;
                    542:     $Apache::lonxml::metamode = 0;
                    543:     $Apache::lonxml::evaluate = 0;
                    544:     $Apache::lonxml::import = 0;
                    545:   } elsif ($target eq 'edit') {
                    546:     $Apache::lonxml::redirection = 0;
                    547:     $Apache::lonxml::metamode = 0;
                    548:     $Apache::lonxml::evaluate = 0;
                    549:     $Apache::lonxml::import = 0;
                    550:   } else {
                    551:     $Apache::lonxml::redirection = 0;
                    552:     $Apache::lonxml::metamode = 0;
                    553:     $Apache::lonxml::evaluate = 1;
                    554:     $Apache::lonxml::import = 1;
                    555:   }
                    556: }
                    557: 
1.82      ng        558: sub init_safespace {
                    559:   my ($target,$safeeval,$safehole,$safeinit) = @_;
                    560:   $safeeval->permit("entereval");
                    561:   $safeeval->permit(":base_math");
                    562:   $safeeval->permit("sort");
                    563:   $safeeval->deny(":base_io");
1.102     albertel  564:   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
1.82      ng        565:   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
                    566:   
                    567:   $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
                    568:   $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
                    569:   $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
                    570:   $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
                    571:   $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
                    572:   $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
                    573:   $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
                    574:   $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
                    575:   $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
                    576:   $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
                    577:   $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
                    578:   $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
                    579:   $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
                    580:   $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
                    581:   $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
                    582:   $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
                    583:   $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
                    584:   $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
                    585:   $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
1.91      ng        586:   $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
                    587:   $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
                    588:   $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
                    589:   $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
                    590:   $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
                    591:   $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
                    592:   $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
                    593:   $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
                    594:   $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
                    595:   $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
                    596:   $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
1.93      ng        597:   $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
1.91      ng        598:   $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
                    599:   $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
                    600:   $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
                    601:   $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
                    602:   $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
                    603:   $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
                    604:   $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
                    605:   $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
                    606:   $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
                    607: 
1.82      ng        608: #need to inspect this class of ops
                    609: # $safeeval->deny(":base_orig");
1.91      ng        610:   $safeinit .= ';$external::target="'.$target.'";';
1.82      ng        611:   $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
                    612:   &Apache::run::run($safeinit,$safeeval);
1.17      albertel  613: }
                    614: 
1.55      albertel  615: sub startredirection {
                    616:   $Apache::lonxml::redirection++;
                    617:   push (@Apache::lonxml::outputstack, '');
                    618: }
                    619: 
                    620: sub endredirection {
                    621:   if (!$Apache::lonxml::redirection) {
1.72      albertel  622:     &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
1.55      albertel  623:     return '';
                    624:   }
                    625:   $Apache::lonxml::redirection--;
                    626:   pop @Apache::lonxml::outputstack;
1.97      albertel  627: }
                    628: 
                    629: sub end_tag {
                    630:   my ($tagstack,$parstack,$token)=@_;
                    631:   pop(@$tagstack);
                    632:   pop(@$parstack);
                    633:   &decreasedepth($token);
1.55      albertel  634: }
                    635: 
1.17      albertel  636: sub initdepth {
                    637:   @Apache::lonxml::depthcounter=();
                    638:   $Apache::lonxml::depth=-1;
                    639:   $Apache::lonxml::olddepth=-1;
                    640: }
                    641: 
                    642: sub increasedepth {
1.19      albertel  643:   my ($token) = @_;
1.17      albertel  644:   $Apache::lonxml::depth++;
                    645:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
                    646:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
                    647:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
                    648:   }
1.42      albertel  649:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64      albertel  650:   &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54      albertel  651: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17      albertel  652: }
                    653: 
                    654: sub decreasedepth {
1.19      albertel  655:   my ($token) = @_;
1.17      albertel  656:   $Apache::lonxml::depth--;
1.36      albertel  657:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
                    658:     $#Apache::lonxml::depthcounter--;
                    659:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
                    660:   }
1.43      albertel  661:   if (  $Apache::lonxml::depth < -1) {
1.49      albertel  662:     &Apache::lonxml::warning("Unbalanced tags in resource");   
1.43      albertel  663:     $Apache::lonxml::depth='-1';
                    664:   }
1.42      albertel  665:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64      albertel  666:   &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54      albertel  667: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1       sakharuk  668: }
1.19      albertel  669: 
                    670: sub get_all_text {
                    671: 
                    672:  my($tag,$pars)= @_;
                    673:  my $depth=0;
                    674:  my $token;
                    675:  my $result='';
1.57      albertel  676:  if ( $tag =~ m:^/: ) { 
                    677:    my $tag=substr($tag,1); 
                    678: #   &Apache::lonxml::debug("have:$tag:");
                    679:    while (($depth >=0) && ($token = $pars->get_token)) {
                    680: #     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
                    681:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    682:        $result.=$token->[1];
                    683:      } elsif ($token->[0] eq 'PI') {
                    684:        $result.=$token->[2];
                    685:      } elsif ($token->[0] eq 'S') {
                    686:        if ($token->[1] eq $tag) { $depth++; }
                    687:        $result.=$token->[4];
                    688:      } elsif ($token->[0] eq 'E')  {
                    689:        if ( $token->[1] eq $tag) { $depth--; }
                    690:        #skip sending back the last end tag
                    691:        if ($depth > -1) { $result.=$token->[2]; } else {
                    692: 	 $pars->unget_token($token);
                    693:        }
                    694:      }
                    695:    }
                    696:  } else {
                    697:    while ($token = $pars->get_token) {
                    698: #     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
                    699:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    700:        $result.=$token->[1];
                    701:      } elsif ($token->[0] eq 'PI') {
                    702:        $result.=$token->[2];
                    703:      } elsif ($token->[0] eq 'S') {
                    704:        if ( $token->[1] eq $tag) { 
                    705: 	 $pars->unget_token($token); last;
                    706:        } else {
                    707: 	 $result.=$token->[4];
                    708:        }
                    709:      } elsif ($token->[0] eq 'E')  {
                    710:        $result.=$token->[2];
1.36      albertel  711:      }
1.19      albertel  712:    }
                    713:  }
1.49      albertel  714: # &Apache::lonxml::debug("Exit:$result:");
1.19      albertel  715:  return $result
                    716: }
                    717: 
1.23      albertel  718: sub newparser {
                    719:   my ($parser,$contentref,$dir) = @_;
                    720:   push (@$parser,HTML::TokeParser->new($contentref));
1.56      albertel  721:   $$parser['-1']->xml_mode('1');
1.23      albertel  722:   if ( $dir eq '' ) {
                    723:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
                    724:   } else {
                    725:     push (@Apache::lonxml::pwd, $dir);
                    726:   } 
                    727: #  &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
                    728: #  &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
                    729: }
1.1       sakharuk  730: 
1.8       albertel  731: sub parstring {
                    732:   my ($token) = @_;
                    733:   my $temp='';
1.20      albertel  734:   map {
1.35      www       735:     unless ($_=~/\W/) {
1.42      albertel  736:       my $val=$token->[2]->{$_};
1.53      albertel  737:       $val =~ s/([\%\@\\])/\\$1/g;
1.51      albertel  738:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42      albertel  739:       $temp .= "my \$$_=\"$val\";"
1.20      albertel  740:     }
                    741:   } @{$token->[3]};
1.8       albertel  742:   return $temp;
                    743: }
1.22      albertel  744: 
1.34      www       745: sub writeallows {
                    746:     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
                    747:     my $thisdir=$thisurl;
                    748:     $thisdir=~s/\/[^\/]+$//;
                    749:     my %httpref=();
                    750:     map {
                    751:        $httpref{'httpref.'.
                    752:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;              } @extlinks;
                    753:     &Apache::lonnet::appenv(%httpref);
                    754: }
                    755: 
1.66      www       756: #
                    757: # Afterburner handles anchors, highlights and links
                    758: #
                    759: sub afterburn {
                    760:     my $result=shift;
                    761:     map {
                    762:        my ($name, $value) = split(/=/,$_);
                    763:        $value =~ tr/+/ /;
                    764:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    765:        if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
                    766:            unless ($ENV{'form.'.$name}) {
                    767:               $ENV{'form.'.$name}=$value;
                    768: 	   }
                    769:        }
                    770:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    771:     if ($ENV{'form.highlight'}) {
                    772:         map {
                    773:            my $anchorname=$_;
                    774: 	   my $matchthis=$anchorname;
                    775:            $matchthis=~s/\_+/\\s\+/g;
                    776:            $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
                    777:        } split(/\,/,$ENV{'form.highlight'});
                    778:     }
                    779:     if ($ENV{'form.link'}) {
                    780:         map {
                    781:            my ($anchorname,$linkurl)=split(/\>/,$_);
                    782: 	   my $matchthis=$anchorname;
                    783:            $matchthis=~s/\_+/\\s\+/g;
                    784:            $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
                    785:        } split(/\,/,$ENV{'form.link'});
                    786:     }
                    787:     if ($ENV{'form.anchor'}) {
                    788:         my $anchorname=$ENV{'form.anchor'};
                    789: 	my $matchthis=$anchorname;
                    790:         $matchthis=~s/\_+/\\s\+/g;
                    791:         $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
                    792:         $result.=(<<"ENDSCRIPT");
                    793: <script>
                    794:     document.location.hash='$anchorname';
                    795: </script>
                    796: ENDSCRIPT
                    797:     }
                    798:     return $result;
                    799: }
                    800: 
1.79      www       801: sub storefile {
                    802:     my ($file,$contents)=@_;
                    803:     if (my $fh=Apache::File->new('>'.$file)) {
                    804: 	print $fh $contents;
                    805:         $fh->close();
                    806:     }
                    807: }
                    808: 
1.78      www       809: sub inserteditinfo {
                    810:       my ($result,$filecontents)=@_;
                    811:       unless ($filecontents) {
                    812: 	  $filecontents=(<<SIMPLECONTENT);
                    813: <html>
                    814: <head>
                    815: <title>
                    816:                            Title of Document Goes Here
                    817: </title>
                    818: </head>
                    819: <body bgcolor="#FFFFFF">
                    820: 
                    821:                            Body of Document Goes Here
                    822: 
                    823: </body>
                    824: </html>
                    825: SIMPLECONTENT
                    826:       }
                    827:       my $editheader='<a href="#editsection">Edit below</a><hr />';
                    828:       my $editfooter=(<<ENDFOOTER);
                    829: <hr />
                    830: <a name="editsection" />
                    831: <form method="post">
                    832: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
                    833: <br />
                    834: <input type="submit" name="savethisfile" value="Save this file" />
                    835: </form>
                    836: ENDFOOTER
                    837:       $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
                    838:       $result=~s/(\<\/body\>)/$editfooter/is;
                    839:       return $result;
                    840: }
                    841: 
1.24      sakharuk  842: sub handler {
                    843:   my $request=shift;
1.68      www       844: 
1.64      albertel  845:   my $target='web';
1.68      www       846: 
1.65      albertel  847:   $Apache::lonxml::debug=0;
1.68      www       848: 
1.25      sakharuk  849:   if ($ENV{'browser.mathml'}) {
1.27      albertel  850:     $request->content_type('text/xml');
                    851:   } else {
                    852:     $request->content_type('text/html');
1.25      sakharuk  853:   }
1.64      albertel  854:   
1.27      albertel  855:   $request->send_http_header;
1.64      albertel  856:   
1.45      www       857:   return OK if $request->header_only;
1.27      albertel  858: 
1.79      www       859: 
                    860:   my $file=&Apache::lonnet::filelocation("",$request->uri);
1.78      www       861: #
                    862: # Edit action? Save file.
                    863: #
                    864:   unless ($ENV{'request.state'} eq 'published') {
                    865:       if ($ENV{'form.savethisfile'}) {
1.79      www       866: 	  &storefile($file,$ENV{'form.filecont'});
1.78      www       867:       }
                    868:   }
1.24      sakharuk  869:   my %mystyle;
1.50      albertel  870:   my $result = ''; 
                    871:   my $filecontents=&Apache::lonnet::getfile($file);
                    872:   if ($filecontents == -1) {
1.78      www       873:     $result=(<<ENDNOTFOUND);
                    874: <html>
                    875: <head>
                    876: <title>File not found</title>
                    877: </head>
                    878: <body bgcolor="#FFFFFF">
                    879: <b>File not found: $file</b>
                    880: </body>
                    881: </html>
                    882: ENDNOTFOUND
1.50      albertel  883:     $filecontents='';
                    884:   } else {
                    885:     $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
1.78      www       886:   }
                    887: 
                    888: #
                    889: # Edit action? Insert editing commands
                    890: #
                    891:   unless ($ENV{'request.state'} eq 'published') {
                    892:       $result=&inserteditinfo($result,$filecontents);
1.66      www       893:   }
1.50      albertel  894: 
1.67      www       895:   $request->print($result);
1.64      albertel  896: 
1.34      www       897:   writeallows($request->uri);
1.45      www       898:   return OK;
1.24      sakharuk  899: }
                    900:  
1.22      albertel  901: sub debug {
                    902:   if ($Apache::lonxml::debug eq 1) {
1.96      albertel  903:     print("DEBUG:".$_[0]."<br />\n");
1.22      albertel  904:   }
                    905: }
1.49      albertel  906: 
1.22      albertel  907: sub error {
1.74      albertel  908:   if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
1.55      albertel  909:     print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52      albertel  910:   } else {
                    911:     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
                    912:     #notify author
                    913:     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
                    914:     #notify course
                    915:     if ( $ENV{'request.course.id'} ) {
                    916:       my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
                    917:       foreach my $user (split /\,/, $users) {
                    918: 	($user,my $domain) = split /:/, $user;
1.54      albertel  919: 	&Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52      albertel  920:       }
                    921:     }
1.74      albertel  922: 
1.52      albertel  923:     #FIXME probably shouldn't have me get everything forever.
1.54      albertel  924:     &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
1.74      albertel  925:     #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52      albertel  926:   }
1.22      albertel  927: }
1.49      albertel  928: 
1.22      albertel  929: sub warning {
1.73      harris41  930:   if ($ENV{'request.state'} eq 'construct') {
1.55      albertel  931:     print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.73      harris41  932:   }
1.83      albertel  933: }
                    934: 
                    935: sub get_param {
                    936:   my ($param,$parstack,$safeeval,$context) = @_;
                    937:   if ( ! $context ) { $context = -1; }
                    938:   my $args ='';
                    939:   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
                    940:   return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
1.22      albertel  941: }
                    942: 
1.74      albertel  943: sub register_insert {
1.75      albertel  944:   my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
1.74      albertel  945:   my $i;
1.76      albertel  946:   my $tagnum=0;
1.74      albertel  947:   my @order;
                    948:   for ($i=0;$i < $#data; $i++) {
                    949:     my $line = $data[$i];
                    950:     if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
                    951:     if ( $line =~ /TABLE/ ) { last; }
1.92      albertel  952:     my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
1.76      albertel  953:     $insertlist{"$tagnum.tag"} = $tag;
                    954:     $insertlist{"$tagnum.description"} = $descrip;
1.92      albertel  955:     $insertlist{"$tagnum.color"} = $color;
1.76      albertel  956:     $insertlist{"$tagnum.function"} = $function;
                    957:     $insertlist{"$tagnum.show"}= $show;
1.92      albertel  958:     $insertlist{"$tag.num"}=$tagnum;
1.76      albertel  959:     $tagnum++;
1.74      albertel  960:   }
1.76      albertel  961:   $i++; #skipping TABLE line
                    962:   $tagnum = 0;
1.74      albertel  963:   for (;$i < $#data;$i++) {
                    964:     my $line = $data[$i];
1.76      albertel  965:     my ($mnemonic,@which) = split(/ +/,$line);
                    966:     my $tag = $insertlist{"$tagnum.tag"};
1.74      albertel  967:     for (my $j=0;$j <$#which;$j++) {
                    968:       if ( $which[$j] eq 'Y' ) {
1.76      albertel  969: 	if ($insertlist{"$j.show"} ne 'no') {
                    970: 	  push(@{ $insertlist{"$tag.which"} },$j);
                    971: 	}
1.74      albertel  972:       }
                    973:     }
1.76      albertel  974:     $tagnum++;
1.74      albertel  975:   }
                    976: }
1.98      albertel  977: 
                    978: sub description {
                    979:   my ($token)=@_;
                    980:   return $insertlist{$insertlist{"$token->[1].num"}.'.description'};
                    981: }
1.1       sakharuk  982: 1;
                    983: __END__
1.68      www       984: 
                    985: 

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