File:  [LON-CAPA] / loncom / xml / lonxml.pm
Revision 1.120: download - view: text, annotated - select for diffs
Mon Aug 20 16:12:46 2001 UTC (22 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Token input field

    1: # The LearningOnline Network with CAPA
    2: # XML Parser Module 
    3: #
    4: # last modified 06/26/00 by Alexander Sakharuk
    5: # 11/6 Gerd Kortemeyer
    6: # 6/1/1 Gerd Kortemeyer
    7: # 2/21,3/13 Guy
    8: # 3/29,5/4 Gerd Kortemeyer
    9: # 5/10 Scott Harrison
   10: # 5/26 Gerd Kortemeyer
   11: # 5/27 H. K. Ng
   12: # 6/2,6/3,6/8,6/9 Gerd Kortemeyer
   13: # 6/12,6/13 H. K. Ng
   14: # 6/16 Gerd Kortemeyer
   15: # 7/27 H. K. Ng
   16: # 8/7,8/9,8/10,8/11,8/15,8/16,8/17,8/18,8/20 Gerd Kortemeyer
   17: 
   18: package Apache::lonxml; 
   19: use vars 
   20: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
   21: use strict;
   22: use HTML::TokeParser;
   23: use HTML::TreeBuilder;
   24: use Safe;
   25: use Safe::Hole;
   26: use Math::Cephes qw(:trigs :hypers :bessels erf erfc);
   27: use Math::Random qw(:all);
   28: use Opcode;
   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: 
   40: use Apache::Constants qw(:common);
   41: use Apache::lontexconvert;
   42: use Apache::style;
   43: use Apache::run;
   44: use Apache::londefdef;
   45: use Apache::scripttag;
   46: use Apache::edit;
   47: use Apache::lonnet;
   48: use Apache::File;
   49: 
   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;
   72: 
   73: # data structure for eidt mode, determines what tags can go into what other tags
   74: %insertlist=();
   75: 
   76: # stores the list of active tag namespaces
   77: @namespace=();
   78: 
   79: # has the dynamic menu been updated to know about this resource
   80: $Apache::lonxml::registered=0;
   81: 
   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 {
   98:     my $discussion='';
   99:     if ($ENV{'request.course.id'}) {
  100:        my $crs='/'.$ENV{'request.course.id'};
  101:        if ($ENV{'request.course.sec'}) {
  102:           $crs.='_'.$ENV{'request.course.sec'};
  103:        }                 
  104:        $crs=~s/\_/\//g;
  105:        my $seeid=&Apache::lonnet::allowed('rin',$crs);
  106:        my $symb=&Apache::lonnet::symbread();
  107:        if ($symb) {
  108:           my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
  109:                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  110: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  111:           if ($contrib{'version'}) {
  112:               $discussion.=
  113:                   '<address><hr /><h2>Course Discussion of Resource</h2>';
  114:               my $idx;
  115:               for ($idx=1;$idx<=$contrib{'version'};$idx++) {
  116: 		my $hidden=($contrib{'hidden'}=~/\.$idx\./);
  117: 		unless (($hidden) && (!$seeid)) {
  118:                  my $message=$contrib{$idx.':message'};
  119:                  $message=~s/\n/\<br \/\>/g;
  120:                  if ($message) {
  121:                   if ($hidden) {
  122: 		      $message='<font color="#888888">'.$message.'</font>';
  123:                   }
  124:                   my $sender='Anonymous';
  125:                   if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
  126:                       $sender=$contrib{$idx.':sendername'}.' at '.
  127: 		      $contrib{$idx.':senderdomain'};
  128:                       if ($contrib{$idx.':anonymous'}) {
  129: 			  $sender.=' (anonymous)';
  130:                       }
  131:                       if ($seeid) {
  132: 			  if ($hidden) {
  133:                              $sender.=' <a href="/adm/feedback?unhide='.
  134: 				 $symb.':::'.$idx.'">Make Visible</a>';
  135:                           } else {
  136:                              $sender.=' <a href="/adm/feedback?hide='.
  137: 				 $symb.':::'.$idx.'">Hide</a>';
  138: 			  }
  139:                       }                   
  140:                   }
  141: 		  $discussion.='<p><b>'.$sender.'</b> ('.
  142:                       localtime($contrib{$idx.':timestamp'}).
  143:                       '):<blockquote>'.$message.
  144:                       '</blockquote></p>';
  145: 	        }
  146:                } 
  147:               }
  148:               $discussion.='</address>';
  149:           }
  150:        }
  151:     }
  152:     return $discussion.'</html>';
  153: }
  154: 
  155: sub tokeninputfield {
  156:     my $defhost=$Apache::lonnet::perlvar{'lonHostID'};
  157:     $defhost=~tr/a-z/A-Z/;
  158:     return (<<ENDINPUTFIELD)
  159: <script>
  160:     function updatetoken() {
  161: 	var comp=new Array;
  162:         var barcode=unescape(document.tokeninput.barcode.value);
  163:         comp=barcode.split('*');
  164:         if (typeof(comp[0])!="undefined") {
  165: 	    document.tokeninput.codeone.value=comp[0];
  166: 	}
  167:         if (typeof(comp[1])!="undefined") {
  168: 	    document.tokeninput.codetwo.value=comp[1];
  169: 	}
  170:         if (typeof(comp[2])!="undefined") {
  171:             comp[2]=comp[2].toUpperCase();
  172: 	    document.tokeninput.codethree.value=comp[2];
  173: 	}
  174:         document.tokeninput.barcode.value='';
  175:     }  
  176: </script>
  177: <form method="post" name="tokeninput">
  178: <table border="2" bgcolor="#FFFFBB">
  179: <tr><th>DocID Checkin</th></tr>
  180: <tr><td>
  181: <table>
  182: <tr>
  183: <td>Scan in Barcode</td>
  184: <td><input type="text" size="22" name="barcode" 
  185: onChange="updatetoken()"/></td>
  186: </tr>
  187: <tr><td><i>or</i> Type in DocID</td>
  188: <td>
  189: <input type="text" size="5" name="codeone" />
  190: <b><font size="+2">*</font></b>
  191: <input type="text" size="5" name="codetwo" />
  192: <b><font size="+2">*</font></b>
  193: <input type="text" size="10" name="codethree" value="$defhost" 
  194: onChange="this.value=this.value.toUpperCase()" />
  195: </td></tr>
  196: </table>
  197: </td></tr>
  198: <tr><td><input type="submit" value="Check in DocID" /></td></tr>
  199: </table>
  200: </form>
  201: ENDINPUTFIELD
  202: }
  203: 
  204: sub maketoken {
  205:     my ($symb,$tuname,$tudom,$tcrsid)=@_;
  206:     unless ($symb) {
  207: 	$symb=&Apache::lonnet::symbread();
  208:     }
  209:     unless ($tuname) {
  210: 	$tuname=$ENV{'user.name'};
  211:         $tudom=$ENV{'user.domain'};
  212:         $tcrsid=$ENV{'request.course.id'};
  213:     }
  214: 
  215:     return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid);
  216: }
  217: 
  218: sub printtokenheader {
  219:     my ($target,$token,$symb,$tuname,$tudom,$tcrsid)=@_;
  220:     unless ($token) { return ''; }
  221: 
  222:     unless ($symb) {
  223: 	$symb=&Apache::lonnet::symbread();
  224:     }
  225:     unless ($tuname) {
  226: 	$tuname=$ENV{'user.name'};
  227:         $tudom=$ENV{'user.domain'};
  228:         $tcrsid=$ENV{'request.course.id'};
  229:     }
  230: 
  231:     my %reply=&Apache::lonnet::get('environment',
  232:               ['firstname','middlename','lastname','generation'],
  233:               $tudom,$tuname);
  234:     my $plainname=$reply{'firstname'}.' '. 
  235:                   $reply{'middlename'}.' '.
  236:                   $reply{'lastname'}.' '.
  237: 		  $reply{'generation'};
  238: 
  239:     if ($target eq 'web') {
  240: 	return 
  241:  '<img align="right" src="/cgi-bin/barcode.gif?encode='.$token.'" />'.
  242:                'Checked out for '.$plainname.
  243:                '<br />User: '.$tuname.' at '.$tudom.
  244: 	       '<br />CourseID: '.$tcrsid.
  245:                '<br />DocID: '.$token.
  246:                '<br />Time: '.localtime().'<hr />';
  247:     } else {
  248:         return $token;                         
  249:     }
  250: }
  251: 
  252: sub fontsettings() {
  253:     my $headerstring='';
  254:     if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) { 
  255:          $headerstring.=
  256:              '<meta Content-Type="text/html; charset=x-mac-roman">';
  257:     }
  258:     return $headerstring;
  259: }
  260: 
  261: sub registerurl {
  262:     my $forcereg=shift;
  263:     if ($Apache::lonxml::registered) { return ''; }
  264:     $Apache::lonxml::registered=1;
  265:     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
  266:         my $hwkadd='';
  267:         if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  268: 	    if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  269: 		$hwkadd.=(<<ENDSUBM);
  270:                      menu.switchbutton
  271:            (7,1,'subm.gif','view sub','missions',
  272:                 'gocmd("/adm/grades","submission")');
  273: ENDSUBM
  274:             }
  275: 	    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
  276: 		$hwkadd.=(<<ENDGRDS);
  277:                      menu.switchbutton
  278:            (7,2,'pgrd.gif','problem','grades',
  279:                 'gocmd("/adm/grades","viewgrades")');
  280: ENDGRDS
  281:             }
  282: 	    if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
  283: 		$hwkadd.=(<<ENDPARM);
  284:                      menu.switchbutton
  285:            (7,3,'pparm.gif','problem','parms',
  286:                 'gocmd("/adm/parmset","set")');
  287: ENDPARM
  288:             }
  289: 	}
  290: 	return (<<ENDREGTHIS);
  291:      
  292: <script language="JavaScript">
  293: // BEGIN LON-CAPA Internal
  294: 
  295:     function LONCAPAreg() {
  296: 	  menu=window.open("","LONCAPAmenu");
  297:           menu.clearTimeout(menu.menucltim);
  298: 	  menu.currentURL=window.location.pathname;
  299:           menu.currentStale=0;
  300:           menu.clearbut(3,1);
  301:           menu.switchbutton
  302:        (6,3,'catalog.gif','catalog','info','catalog_info()');
  303:           menu.switchbutton
  304:        (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');
  305:           menu.switchbutton
  306:     (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)');
  307:           menu.switchbutton
  308:      (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');
  309:           menu.switchbutton
  310:        (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)');
  311:           menu.switchbutton
  312:      (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)');
  313:           menu.switchbutton
  314:                             (9,1,'sbkm.gif','set','bookmark','set_bookmark()');
  315:           menu.switchbutton
  316:                          (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()');
  317:           menu.switchbutton
  318:                                (9,3,'anot.gif','anno-','tations','annotate()');
  319:           $hwkadd
  320:     }
  321: 
  322:     function LONCAPAstale() {
  323: 	  menu=window.open("","LONCAPAmenu");
  324:           menu.currentStale=1;
  325:           menu.switchbutton
  326:             (3,1,'reload.gif','return','location','go(currentURL)');
  327:           menu.clearbut(7,1);
  328:           menu.clearbut(7,2);
  329:           menu.clearbut(7,3);
  330:           menu.menucltim=menu.setTimeout(
  331:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  332:  'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3)',
  333: 			  2000);
  334: 
  335:       }
  336: 
  337: // END LON-CAPA Internal
  338: </script>
  339: ENDREGTHIS
  340: 
  341:     } else {
  342:         return (<<ENDDONOTREGTHIS);
  343: 
  344: <script language="JavaScript">
  345: // BEGIN LON-CAPA Internal
  346: 
  347:     function LONCAPAreg() {
  348: 	  menu=window.open("","LONCAPAmenu");
  349:           menu.currentStale=1;
  350:           menu.clearbut(2,1);
  351:           menu.clearbut(2,3);
  352:           menu.clearbut(8,1);
  353:           menu.clearbut(8,2);
  354:           menu.clearbut(8,3);
  355:           if (menu.currentURL) {
  356:              menu.switchbutton
  357:               (3,1,'reload.gif','return','location','go(currentURL)');
  358:  	  } else {
  359: 	      menu.clearbut(3,1);
  360:           }
  361:     }
  362: 
  363:     function LONCAPAstale() {
  364:     }
  365: 
  366: // END LON-CAPA Internal
  367: </script>
  368: ENDDONOTREGTHIS
  369: 
  370:     }
  371: }
  372: 
  373: sub loadevents() {
  374:     return 'LONCAPAreg();';
  375: }
  376: 
  377: sub unloadevents() {
  378:     return 'LONCAPAstale();';
  379: }
  380: 
  381: sub printalltags {
  382:   my $temp;
  383:   foreach $temp (sort keys %Apache::lonxml::alltags) {
  384:     &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
  385:   }
  386: }
  387: 
  388: sub xmlparse {
  389:  my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
  390: 
  391:  &setup_globals($target);
  392:  #&printalltags();
  393:  my @pars = ();
  394:  my $pwd=$ENV{'request.filename'};
  395:  $pwd =~ s:/[^/]*$::;
  396:  &newparser(\@pars,\$content_file_string,$pwd);
  397: 
  398:  my $safeeval = new Safe;
  399:  my $safehole = new Safe::Hole;
  400:  &init_safespace($target,$safeeval,$safehole,$safeinit);
  401: #-------------------- Redefinition of the target in the case of compound target
  402: 
  403:  ($target, my @tenta) = split('&&',$target);
  404: 
  405:  my @stack = (); 
  406:  my @parstack = ();
  407:  &initdepth;
  408: 
  409:  my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
  410: 				   $safeeval,\%style_for_target);
  411: 
  412:  return $finaloutput;
  413: }
  414: 
  415: sub htmlclean {
  416:     my ($raw,$full)=@_;
  417: 
  418:     my $tree = HTML::TreeBuilder->new;
  419:     $tree->ignore_unknown(0);
  420:     
  421:     $tree->parse($raw);
  422: 
  423:     my $output= $tree->as_HTML(undef,' ');
  424:      
  425:     $output=~s/\<(br|hr|img|meta|allow)([^\>\/]*)\>/\<$1$2 \/\>/gis;
  426:     $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
  427:     unless ($full) {
  428:        $output=~s/\<[\/]*(body|head|html)\>//gis;
  429:     }
  430: 
  431:     $tree = $tree->delete;
  432: 
  433:     return $output;
  434: }
  435: 
  436: sub inner_xmlparse {
  437:   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
  438:   &Apache::lonxml::debug('Reentrant parser starting, again?');
  439:   my $finaloutput = '';
  440:   my $result;
  441:   my $token;
  442:   while ( $#$pars > -1 ) {
  443:     while ($token = $$pars['-1']->get_token) {
  444:       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
  445: 	if ($metamode<1) {
  446: 	  $result=$token->[1];
  447: 	}
  448:       } elsif ($token->[0] eq 'PI') {
  449: 	if ($metamode<1) {
  450: 	  $result=$token->[2];
  451: 	}
  452:       } elsif ($token->[0] eq 'S') {
  453: 	# add tag to stack 	    
  454: 	push (@$stack,$token->[1]);
  455: 	# add parameters list to another stack
  456: 	push (@$parstack,&parstring($token));
  457: 	&increasedepth($token);       
  458: 	if (exists $$style_for_target{$token->[1]}) {
  459: 	  if ($Apache::lonxml::redirection) {
  460: 	    $Apache::lonxml::outputstack['-1'] .=  
  461: 	      &recurse($$style_for_target{$token->[1]},$target,$safeeval,
  462: 		       $style_for_target,@$parstack);
  463: 	  } else {
  464: 	    $finaloutput .= &recurse($$style_for_target{$token->[1]},$target,
  465: 				     $safeeval,$style_for_target,@$parstack);
  466: 	  }
  467: 	} else {
  468: 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
  469: 			     $parstack, $pars, $safeeval, $style_for_target);
  470: 	}              
  471:       } elsif ($token->[0] eq 'E') {
  472: 	#clear out any tags that didn't end
  473: 	while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) {
  474: 	  &Apache::lonxml::warning("Unbalanced tags in resource $$stack['-1']");
  475: 	  &end_tag($stack,$parstack,$token);
  476: 	}
  477: 		
  478: 	if (exists $$style_for_target{'/'."$token->[1]"}) {
  479: 	  if ($Apache::lonxml::redirection) {
  480: 	    $Apache::lonxml::outputstack['-1'] .=  
  481: 	      &recurse($$style_for_target{'/'."$token->[1]"},
  482: 		       $target,$safeeval,$style_for_target,@$parstack);
  483: 	  } else {
  484: 	    $finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"},
  485: 				     $target,$safeeval,$style_for_target,
  486: 				     @$parstack);
  487: 	  }
  488: 		    
  489: 	} else {
  490: 	  $result = &callsub("end_$token->[1]", $target, $token, $stack,
  491: 			     $parstack, $pars,$safeeval, $style_for_target);
  492: 	}
  493:       } else {
  494: 	&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
  495:       }
  496:       #evaluate variable refs in result
  497:       if ($result ne "") {
  498: 	if ( $#$parstack > -1 ) {
  499: 	  if ($Apache::lonxml::redirection) {
  500: 	    $Apache::lonxml::outputstack['-1'] .= 
  501: 	      &Apache::run::evaluate($result,$safeeval,$$parstack['-1']);
  502: 	  } else {
  503: 	    $finaloutput .= &Apache::run::evaluate($result,$safeeval,
  504: 						   $$parstack['-1']);
  505: 	  }
  506: 	} else {
  507: 	  $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
  508: 	}
  509: 	$result = '';
  510:       } 
  511:       if ($token->[0] eq 'E') { 
  512: 	&end_tag($stack,$parstack,$token);
  513:       }
  514:     }
  515:     pop @$pars;
  516:     pop @Apache::lonxml::pwd;
  517:   }
  518: 
  519:   # if ($target eq 'meta') {
  520:   #   $finaloutput.=&endredirection;
  521:   # }
  522: 
  523:   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
  524:     $finaloutput=&afterburn($finaloutput);
  525:   }
  526:   return $finaloutput;
  527: }
  528: 
  529: sub recurse {
  530:   my @innerstack = (); 
  531:   my @innerparstack = ();
  532:   my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
  533:   my @pat = ();
  534:   &newparser(\@pat,\$newarg);
  535:   my $tokenpat;
  536:   my $partstring = '';
  537:   my $output='';
  538:   my $decls='';
  539:   while ( $#pat > -1 ) {
  540:     while  ($tokenpat = $pat[$#pat]->get_token) {
  541:       if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
  542: 	if ($metamode<1) { $partstring=$tokenpat->[1]; }
  543:       } elsif ($tokenpat->[0] eq 'PI') {
  544: 	if ($metamode<1) { $partstring=$tokenpat->[2]; }
  545:       } elsif ($tokenpat->[0] eq 'S') {
  546: 	push (@innerstack,$tokenpat->[1]);
  547: 	push (@innerparstack,&parstring($tokenpat));
  548: 	&increasedepth($tokenpat);
  549: 	$partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat,
  550: 			       \@innerstack, \@innerparstack, \@pat,
  551: 			       $safeeval, $style_for_target);
  552:       } elsif ($tokenpat->[0] eq 'E') {
  553: 	#clear out any tags that didn't end
  554: 	while ($tokenpat->[1] ne $innerstack[$#innerstack] 
  555: 	       && ($#innerstack > -1)) {
  556: 	  &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
  557: 	  &end_tag(\@innerstack,\@innerparstack,$tokenpat);
  558: 	}
  559: 	$partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,
  560: 			       \@innerstack, \@innerparstack, \@pat,
  561: 			       $safeeval, $style_for_target);
  562:       } else {
  563: 	&Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
  564:       }
  565:       #pass both the variable to the style tag, and the tag we 
  566:       #are processing inside the <definedtag>
  567:       if ( $partstring ne "" ) {
  568: 	if ( $#parstack > -1 ) { 
  569: 	  if ( $#innerparstack > -1 ) { 
  570: 	    $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
  571: 	  } else {
  572: 	    $decls= $parstack[$#parstack];
  573: 	  }
  574: 	} else {
  575: 	  if ( $#innerparstack > -1 ) { 
  576: 	    $decls=$innerparstack[$#innerparstack];
  577: 	  } else {
  578: 	    $decls='';
  579: 	  }
  580: 	}
  581: 	$output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
  582: 	$partstring = '';
  583:       }
  584:       if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
  585: 				 &decreasedepth($tokenpat);}
  586:     }
  587:     pop @pat;
  588:     pop @Apache::lonxml::pwd;
  589:   }
  590:   return $output;
  591: }
  592: 
  593: sub callsub {
  594:   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  595:   my $currentstring='';
  596:   my $nodefault;
  597:   {
  598:     my $sub1;
  599:     no strict 'refs';
  600:     my $tag=$token->[1];
  601:     my $space=$Apache::lonxml::alltags{$tag};
  602:     if (!$space) {
  603: 	$tag=~tr/A-Z/a-z/;
  604: 	$sub=~tr/A-Z/a-z/;
  605: 	$space=$Apache::lonxml::alltags{$tag}
  606:     }
  607: 
  608:     my $deleted=0;
  609:     $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
  610:     if (($token->[0] eq 'S') && ($target eq 'modified')) {
  611:       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
  612: 					     $parstack,$parser,$safeeval,
  613: 					     $style);
  614:     }
  615:     if (!$deleted) {
  616:       if ($space) {
  617: 	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
  618: 	$sub1="$space\:\:$sub";
  619: 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
  620: 					     $parstack,$parser,$safeeval,
  621: 					     $style);
  622:       } else {
  623: 	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
  624: 	if ($metamode <1) {
  625: 	  if (defined($token->[4]) && ($metamode < 1)) {
  626: 	    $currentstring = $token->[4];
  627: 	  } else {
  628: 	    $currentstring = $token->[2];
  629: 	  }
  630: 	}
  631:       }
  632:       #    &Apache::lonxml::debug("nodefalt:$nodefault:");
  633:       if ($currentstring eq '' && $nodefault eq '') {
  634: 	if ($target eq 'edit') {
  635: 	  &Apache::lonxml::debug("doing default edit for $token->[1]");
  636: 	  if ($token->[0] eq 'S') {
  637: 	    $currentstring = &Apache::edit::tag_start($target,$token);
  638: 	  } elsif ($token->[0] eq 'E') {
  639: 	    $currentstring = &Apache::edit::tag_end($target,$token);
  640: 	  }
  641: 	} elsif ($target eq 'modified') {
  642: 	  if ($token->[0] eq 'S') {
  643: 	    $currentstring = $token->[4];
  644: 	    $currentstring.=&Apache::edit::handle_insert();
  645: 	  } else {
  646: 	    $currentstring = $token->[2];
  647: 	  }
  648: 	}
  649:       }
  650:     }
  651:     use strict 'refs';
  652:   }
  653:   return $currentstring;
  654: }
  655: 
  656: sub setup_globals {
  657:   my ($target)=@_;
  658:   $Apache::lonxml::registered = 0;
  659:   @Apache::lonxml::pwd=();
  660:   if ($target eq 'meta') {
  661:     $Apache::lonxml::redirection = 0;
  662:     $Apache::lonxml::metamode = 1;
  663:     $Apache::lonxml::evaluate = 1;
  664:     $Apache::lonxml::import = 0;
  665:   } elsif ($target eq 'grade') {
  666:     &startredirection;
  667:     $Apache::lonxml::metamode = 0;
  668:     $Apache::lonxml::evaluate = 1;
  669:     $Apache::lonxml::import = 1;
  670:   } elsif ($target eq 'modified') {
  671:     $Apache::lonxml::redirection = 0;
  672:     $Apache::lonxml::metamode = 0;
  673:     $Apache::lonxml::evaluate = 0;
  674:     $Apache::lonxml::import = 0;
  675:   } elsif ($target eq 'edit') {
  676:     $Apache::lonxml::redirection = 0;
  677:     $Apache::lonxml::metamode = 0;
  678:     $Apache::lonxml::evaluate = 0;
  679:     $Apache::lonxml::import = 0;
  680:   } else {
  681:     $Apache::lonxml::redirection = 0;
  682:     $Apache::lonxml::metamode = 0;
  683:     $Apache::lonxml::evaluate = 1;
  684:     $Apache::lonxml::import = 1;
  685:   }
  686: }
  687: 
  688: sub init_safespace {
  689:   my ($target,$safeeval,$safehole,$safeinit) = @_;
  690:   $safeeval->permit("entereval");
  691:   $safeeval->permit(":base_math");
  692:   $safeeval->permit("sort");
  693:   $safeeval->deny(":base_io");
  694:   $safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse');
  695:   $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
  696:   
  697:   $safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin');
  698:   $safehole->wrap(\&Math::Cephes::acos,$safeeval,'&acos');
  699:   $safehole->wrap(\&Math::Cephes::atan,$safeeval,'&atan');
  700:   $safehole->wrap(\&Math::Cephes::sinh,$safeeval,'&sinh');
  701:   $safehole->wrap(\&Math::Cephes::cosh,$safeeval,'&cosh');
  702:   $safehole->wrap(\&Math::Cephes::tanh,$safeeval,'&tanh');
  703:   $safehole->wrap(\&Math::Cephes::asinh,$safeeval,'&asinh');
  704:   $safehole->wrap(\&Math::Cephes::acosh,$safeeval,'&acosh');
  705:   $safehole->wrap(\&Math::Cephes::atanh,$safeeval,'&atanh');
  706:   $safehole->wrap(\&Math::Cephes::erf,$safeeval,'&erf');
  707:   $safehole->wrap(\&Math::Cephes::erfc,$safeeval,'&erfc');
  708:   $safehole->wrap(\&Math::Cephes::j0,$safeeval,'&j0');
  709:   $safehole->wrap(\&Math::Cephes::j1,$safeeval,'&j1');
  710:   $safehole->wrap(\&Math::Cephes::jn,$safeeval,'&jn');
  711:   $safehole->wrap(\&Math::Cephes::jv,$safeeval,'&jv');
  712:   $safehole->wrap(\&Math::Cephes::y0,$safeeval,'&y0');
  713:   $safehole->wrap(\&Math::Cephes::y1,$safeeval,'&y1');
  714:   $safehole->wrap(\&Math::Cephes::yn,$safeeval,'&yn');
  715:   $safehole->wrap(\&Math::Cephes::yv,$safeeval,'&yv');
  716:   $safehole->wrap(\&Math::Random::random_beta,$safeeval,'&math_random_beta');
  717:   $safehole->wrap(\&Math::Random::random_chi_square,$safeeval,'&math_random_chi_square');
  718:   $safehole->wrap(\&Math::Random::random_exponential,$safeeval,'&math_random_exponential');
  719:   $safehole->wrap(\&Math::Random::random_f,$safeeval,'&math_random_f');
  720:   $safehole->wrap(\&Math::Random::random_gamma,$safeeval,'&math_random_gamma');
  721:   $safehole->wrap(\&Math::Random::random_multivariate_normal,$safeeval,'&math_random_multivariate_normal');
  722:   $safehole->wrap(\&Math::Random::random_multinomial,$safeeval,'&math_random_multinomial');
  723:   $safehole->wrap(\&Math::Random::random_noncentral_chi_square,$safeeval,'&math_random_noncentral_chi_square');
  724:   $safehole->wrap(\&Math::Random::random_noncentral_f,$safeeval,'&math_random_noncentral_f');
  725:   $safehole->wrap(\&Math::Random::random_normal,$safeeval,'&math_random_normal');
  726:   $safehole->wrap(\&Math::Random::random_permutation,$safeeval,'&math_random_permutation');
  727:   $safehole->wrap(\&Math::Random::random_permuted_index,$safeeval,'&math_random_permuted_index');
  728:   $safehole->wrap(\&Math::Random::random_uniform,$safeeval,'&math_random_uniform');
  729:   $safehole->wrap(\&Math::Random::random_poisson,$safeeval,'&math_random_poisson');
  730:   $safehole->wrap(\&Math::Random::random_uniform_integer,$safeeval,'&math_random_uniform_integer');
  731:   $safehole->wrap(\&Math::Random::random_negative_binomial,$safeeval,'&math_random_negative_binomial');
  732:   $safehole->wrap(\&Math::Random::random_binomial,$safeeval,'&math_random_binomial');
  733:   $safehole->wrap(\&Math::Random::random_seed_from_phrase,$safeeval,'&random_seed_from_phrase');
  734:   $safehole->wrap(\&Math::Random::random_set_seed_from_phrase,$safeeval,'&random_set_seed_from_phrase');
  735:   $safehole->wrap(\&Math::Random::random_get_seed,$safeeval,'&random_get_seed');
  736:   $safehole->wrap(\&Math::Random::random_set_seed,$safeeval,'&random_set_seed');
  737: 
  738: #need to inspect this class of ops
  739: # $safeeval->deny(":base_orig");
  740:   $safeinit .= ';$external::target="'.$target.'";';
  741:   $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
  742:   &Apache::run::run($safeinit,$safeeval);
  743: }
  744: 
  745: sub startredirection {
  746:   $Apache::lonxml::redirection++;
  747:   push (@Apache::lonxml::outputstack, '');
  748: }
  749: 
  750: sub endredirection {
  751:   if (!$Apache::lonxml::redirection) {
  752:     &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
  753:     return '';
  754:   }
  755:   $Apache::lonxml::redirection--;
  756:   pop @Apache::lonxml::outputstack;
  757: }
  758: 
  759: sub end_tag {
  760:   my ($tagstack,$parstack,$token)=@_;
  761:   pop(@$tagstack);
  762:   pop(@$parstack);
  763:   &decreasedepth($token);
  764: }
  765: 
  766: sub initdepth {
  767:   @Apache::lonxml::depthcounter=();
  768:   $Apache::lonxml::depth=-1;
  769:   $Apache::lonxml::olddepth=-1;
  770: }
  771: 
  772: sub increasedepth {
  773:   my ($token) = @_;
  774:   $Apache::lonxml::depth++;
  775:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
  776:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
  777:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
  778:   }
  779:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
  780:   &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
  781: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
  782: }
  783: 
  784: sub decreasedepth {
  785:   my ($token) = @_;
  786:   $Apache::lonxml::depth--;
  787:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
  788:     $#Apache::lonxml::depthcounter--;
  789:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
  790:   }
  791:   if (  $Apache::lonxml::depth < -1) {
  792:     &Apache::lonxml::warning("Unbalanced tags in resource");   
  793:     $Apache::lonxml::depth='-1';
  794:   }
  795:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
  796:   &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
  797: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
  798: }
  799: 
  800: sub get_all_text {
  801: 
  802:  my($tag,$pars)= @_;
  803:  my $depth=0;
  804:  my $token;
  805:  my $result='';
  806:  if ( $tag =~ m:^/: ) { 
  807:    my $tag=substr($tag,1); 
  808: #   &Apache::lonxml::debug("have:$tag:");
  809:    while (($depth >=0) && ($token = $pars->get_token)) {
  810: #     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
  811:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
  812:        $result.=$token->[1];
  813:      } elsif ($token->[0] eq 'PI') {
  814:        $result.=$token->[2];
  815:      } elsif ($token->[0] eq 'S') {
  816:        if ($token->[1] eq $tag) { $depth++; }
  817:        $result.=$token->[4];
  818:      } elsif ($token->[0] eq 'E')  {
  819:        if ( $token->[1] eq $tag) { $depth--; }
  820:        #skip sending back the last end tag
  821:        if ($depth > -1) { $result.=$token->[2]; } else {
  822: 	 $pars->unget_token($token);
  823:        }
  824:      }
  825:    }
  826:  } else {
  827:    while ($token = $pars->get_token) {
  828: #     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
  829:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
  830:        $result.=$token->[1];
  831:      } elsif ($token->[0] eq 'PI') {
  832:        $result.=$token->[2];
  833:      } elsif ($token->[0] eq 'S') {
  834:        if ( $token->[1] eq $tag) { 
  835: 	 $pars->unget_token($token); last;
  836:        } else {
  837: 	 $result.=$token->[4];
  838:        }
  839:      } elsif ($token->[0] eq 'E')  {
  840:        $result.=$token->[2];
  841:      }
  842:    }
  843:  }
  844: # &Apache::lonxml::debug("Exit:$result:");
  845:  return $result
  846: }
  847: 
  848: sub newparser {
  849:   my ($parser,$contentref,$dir) = @_;
  850:   push (@$parser,HTML::TokeParser->new($contentref));
  851:   $$parser['-1']->xml_mode('1');
  852:   if ( $dir eq '' ) {
  853:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
  854:   } else {
  855:     push (@Apache::lonxml::pwd, $dir);
  856:   } 
  857: #  &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
  858: #  &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
  859: }
  860: 
  861: sub parstring {
  862:   my ($token) = @_;
  863:   my $temp='';
  864:   map {
  865:     unless ($_=~/\W/) {
  866:       my $val=$token->[2]->{$_};
  867:       $val =~ s/([\%\@\\])/\\$1/g;
  868:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
  869:       $temp .= "my \$$_=\"$val\";"
  870:     }
  871:   } @{$token->[3]};
  872:   return $temp;
  873: }
  874: 
  875: sub writeallows {
  876:     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
  877:     if ($ENV{'httpref.'.$thisurl}) {
  878: 	$thisurl=$ENV{'httpref.'.$thisurl};
  879:     }
  880:     my $thisdir=$thisurl;
  881:     $thisdir=~s/\/[^\/]+$//;
  882:     my %httpref=();
  883:     map {
  884:        $httpref{'httpref.'.
  885:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;              } @extlinks;
  886:     &Apache::lonnet::appenv(%httpref);
  887: }
  888: 
  889: #
  890: # Afterburner handles anchors, highlights and links
  891: #
  892: sub afterburn {
  893:     my $result=shift;
  894:     map {
  895:        my ($name, $value) = split(/=/,$_);
  896:        $value =~ tr/+/ /;
  897:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  898:        if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
  899:            unless ($ENV{'form.'.$name}) {
  900:               $ENV{'form.'.$name}=$value;
  901: 	   }
  902:        }
  903:     } (split(/&/,$ENV{'QUERY_STRING'}));
  904:     if ($ENV{'form.highlight'}) {
  905:         map {
  906:            my $anchorname=$_;
  907: 	   my $matchthis=$anchorname;
  908:            $matchthis=~s/\_+/\\s\+/g;
  909:            $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
  910:        } split(/\,/,$ENV{'form.highlight'});
  911:     }
  912:     if ($ENV{'form.link'}) {
  913:         map {
  914:            my ($anchorname,$linkurl)=split(/\>/,$_);
  915: 	   my $matchthis=$anchorname;
  916:            $matchthis=~s/\_+/\\s\+/g;
  917:            $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
  918:        } split(/\,/,$ENV{'form.link'});
  919:     }
  920:     if ($ENV{'form.anchor'}) {
  921:         my $anchorname=$ENV{'form.anchor'};
  922: 	my $matchthis=$anchorname;
  923:         $matchthis=~s/\_+/\\s\+/g;
  924:         $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
  925:         $result.=(<<"ENDSCRIPT");
  926: <script>
  927:     document.location.hash='$anchorname';
  928: </script>
  929: ENDSCRIPT
  930:     }
  931:     return $result;
  932: }
  933: 
  934: sub storefile {
  935:     my ($file,$contents)=@_;
  936:     if (my $fh=Apache::File->new('>'.$file)) {
  937: 	print $fh $contents;
  938:         $fh->close();
  939:     }
  940: }
  941: 
  942: sub inserteditinfo {
  943:       my ($result,$filecontents)=@_;
  944:       unless ($filecontents) {
  945: 	  $filecontents=(<<SIMPLECONTENT);
  946: <html>
  947: <head>
  948: <title>
  949:                            Title of Document Goes Here
  950: </title>
  951: </head>
  952: <body bgcolor="#FFFFFF">
  953: 
  954:                            Body of Document Goes Here
  955: 
  956: </body>
  957: </html>
  958: SIMPLECONTENT
  959:       }
  960:       my $editheader='<a href="#editsection">Edit below</a><hr />';
  961:       my $editfooter=(<<ENDFOOTER);
  962: <hr />
  963: <a name="editsection" />
  964: <form method="post">
  965: <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
  966: <br />
  967: <input type="submit" name="attemptclean" 
  968:        value="Save and then attempt to clean HTML" />
  969: <input type="submit" name="savethisfile" value="Save this" />
  970: </form>
  971: ENDFOOTER
  972:       $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
  973:       $result=~s/(\<\/body\>)/$editfooter/is;
  974:       return $result;
  975: }
  976: 
  977: sub handler {
  978:   my $request=shift;
  979: 
  980:   my $target='web';
  981: 
  982:   $Apache::lonxml::debug=0;
  983: 
  984:   if ($ENV{'browser.mathml'}) {
  985:     $request->content_type('text/xml');
  986:   } else {
  987:     $request->content_type('text/html');
  988:   }
  989:   
  990:   $request->send_http_header;
  991:   
  992:   return OK if $request->header_only;
  993: 
  994: 
  995:   my $file=&Apache::lonnet::filelocation("",$request->uri);
  996: #
  997: # Edit action? Save file.
  998: #
  999:   unless ($ENV{'request.state'} eq 'published') {
 1000:       if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
 1001: 	  &storefile($file,$ENV{'form.filecont'});
 1002:       }
 1003:   }
 1004:   my %mystyle;
 1005:   my $result = ''; 
 1006:   my $filecontents=&Apache::lonnet::getfile($file);
 1007:   if ($filecontents == -1) {
 1008:     $result=(<<ENDNOTFOUND);
 1009: <html>
 1010: <head>
 1011: <title>File not found</title>
 1012: </head>
 1013: <body bgcolor="#FFFFFF">
 1014: <b>File not found: $file</b>
 1015: </body>
 1016: </html>
 1017: ENDNOTFOUND
 1018:     $filecontents='';
 1019:   } else {
 1020:       unless ($ENV{'request.state'} eq 'published') {
 1021:          if ($ENV{'form.attemptclean'}) {
 1022: 	    $filecontents=&htmlclean($filecontents,1);
 1023:          }
 1024:       }
 1025:     $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
 1026:   }
 1027: 
 1028: #
 1029: # Edit action? Insert editing commands
 1030: #
 1031:   unless ($ENV{'request.state'} eq 'published') {
 1032:       $result=&inserteditinfo($result,$filecontents);
 1033:   }
 1034: 
 1035:   $request->print($result);
 1036: 
 1037:   writeallows($request->uri);
 1038:   return OK;
 1039: }
 1040:  
 1041: sub debug {
 1042:   if ($Apache::lonxml::debug eq 1) {
 1043:     print("DEBUG:".$_[0]."<br />\n");
 1044:   }
 1045: }
 1046: 
 1047: sub error {
 1048:   if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
 1049:     print "<b>ERROR:</b>".$_[0]."<br />\n";
 1050:   } else {
 1051:     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
 1052:     #notify author
 1053:     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
 1054:     #notify course
 1055:     if ( $ENV{'request.course.id'} ) {
 1056:       my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
 1057:       foreach my $user (split /\,/, $users) {
 1058: 	($user,my $domain) = split /:/, $user;
 1059: 	&Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
 1060:       }
 1061:     }
 1062: 
 1063:     #FIXME probably shouldn't have me get everything forever.
 1064:     &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
 1065:     #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
 1066:   }
 1067: }
 1068: 
 1069: sub warning {
 1070:   if ($ENV{'request.state'} eq 'construct') {
 1071:     print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
 1072:   }
 1073: }
 1074: 
 1075: sub get_param {
 1076:   my ($param,$parstack,$safeeval,$context) = @_;
 1077:   if ( ! $context ) { $context = -1; }
 1078:   my $args ='';
 1079:   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
 1080:   return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
 1081: }
 1082: 
 1083: sub register_insert {
 1084:   my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
 1085:   my $i;
 1086:   my $tagnum=0;
 1087:   my @order;
 1088:   for ($i=0;$i < $#data; $i++) {
 1089:     my $line = $data[$i];
 1090:     if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
 1091:     if ( $line =~ /TABLE/ ) { last; }
 1092:     my ($tag,$descrip,$color,$function,$show) = split(/,/, $line);
 1093:     $insertlist{"$tagnum.tag"} = $tag;
 1094:     $insertlist{"$tagnum.description"} = $descrip;
 1095:     $insertlist{"$tagnum.color"} = $color;
 1096:     $insertlist{"$tagnum.function"} = $function;
 1097:     $insertlist{"$tagnum.show"}= $show;
 1098:     $insertlist{"$tag.num"}=$tagnum;
 1099:     $tagnum++;
 1100:   }
 1101:   $i++; #skipping TABLE line
 1102:   $tagnum = 0;
 1103:   for (;$i < $#data;$i++) {
 1104:     my $line = $data[$i];
 1105:     my ($mnemonic,@which) = split(/ +/,$line);
 1106:     my $tag = $insertlist{"$tagnum.tag"};
 1107:     for (my $j=0;$j <$#which;$j++) {
 1108:       if ( $which[$j] eq 'Y' ) {
 1109: 	if ($insertlist{"$j.show"} ne 'no') {
 1110: 	  push(@{ $insertlist{"$tag.which"} },$j);
 1111: 	}
 1112:       }
 1113:     }
 1114:     $tagnum++;
 1115:   }
 1116: }
 1117: 
 1118: sub description {
 1119:   my ($token)=@_;
 1120:   return $insertlist{$insertlist{"$token->[1].num"}.'.description'};
 1121: }
 1122: 1;
 1123: __END__
 1124: 
 1125: 

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