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:
11: package Apache::lonxml;
12: use vars
13: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
14: use strict;
15: use HTML::TokeParser;
16: use Safe;
17: use Safe::Hole;
18: use Opcode;
19:
20: sub register {
21: my $space;
22: my @taglist;
23: my $temptag;
24: ($space,@taglist) = @_;
25: foreach $temptag (@taglist) {
26: $Apache::lonxml::alltags{$temptag}=$space;
27: }
28: }
29:
30: use Apache::Constants qw(:common);
31: use Apache::lontexconvert;
32: use Apache::style;
33: use Apache::run;
34: use Apache::londefdef;
35: use Apache::scripttag;
36: use Apache::edit;
37: #================================================== Main subroutine: xmlparse
38: #debugging control, to turn on debugging modify the correct handler
39: $Apache::lonxml::debug=0;
40:
41: #path to the directory containing the file currently being processed
42: @pwd=();
43:
44: #these two are used for capturing a subset of the output for later processing,
45: #don't touch them directly use &startredirection and &endredirection
46: @outputstack = ();
47: $redirection = 0;
48:
49: #controls wheter the <import> tag actually does
50: $import = 1;
51: @extlinks=();
52:
53: # meta mode is a bit weird only some output is to be turned off
54: #<output> tag turns metamode off (defined in londefdef.pm)
55: $metamode = 0;
56:
57: # turns on and of run::evaluate actually derefencing var refs
58: $evaluate = 1;
59:
60: # data structure for eidt mode, determines what tags can go into what other tags
61: %insertlist=();
62:
63: #stores the list of active tag namespaces
64: @namespace=();
65:
66: sub xmlbegin {
67: my $output='';
68: if ($ENV{'browser.mathml'}) {
69: $output='<?xml version="1.0"?>'
70: .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
71: .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
72: .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
73: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
74: .'xmlns="http://www.w3.org/TR/REC-html40">';
75: } else {
76: $output='<html>';
77: }
78: return $output;
79: }
80:
81: sub xmlend {
82: return '</html>';
83: }
84:
85: sub fontsettings() {
86: my $headerstring='';
87: if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) {
88: $headerstring.=
89: '<meta Content-Type="text/html; charset=x-mac-roman">';
90: }
91: return $headerstring;
92: }
93:
94: sub registerurl {
95: return (<<ENDSCRIPT);
96: <script language="JavaScript">
97: // BEGIN LON-CAPA Internal
98: function LONCAPAreg() {
99: if (window.location.pathname!="/res/adm/pages/menu.html") {
100: menu=window.open("","LONCAPAmenu");
101: menu.currentURL=window.location.pathname;
102: menu.currentStale=0;
103: }
104: }
105:
106: function LONCAPAstale() {
107: if (window.location.pathname!="/res/adm/pages/menu.html") {
108: menu=window.open("","LONCAPAmenu");
109: menu.currentStale=1;
110: }
111: }
112: // END LON-CAPA Internal
113: </script>
114: ENDSCRIPT
115: }
116:
117: sub loadevents() {
118: return 'LONCAPAreg();';
119: }
120:
121: sub unloadevents() {
122: return 'LONCAPAstale();';
123: }
124:
125: sub printalltags {
126: my $temp;
127: foreach $temp (sort keys %Apache::lonxml::alltags) {
128: &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
129: }
130: }
131:
132: sub xmlparse {
133:
134: my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
135: if ($target eq 'meta') {
136: $Apache::lonxml::redirection = 0;
137: $Apache::lonxml::metamode = 1;
138: $Apache::lonxml::evaluate = 1;
139: $Apache::lonxml::import = 0;
140: } elsif ($target eq 'grade') {
141: &startredirection;
142: $Apache::lonxml::metamode = 0;
143: $Apache::lonxml::evaluate = 1;
144: $Apache::lonxml::import = 1;
145: } elsif ($target eq 'modified') {
146: $Apache::lonxml::redirection = 0;
147: $Apache::lonxml::metamode = 0;
148: $Apache::lonxml::evaluate = 0;
149: $Apache::lonxml::import = 0;
150: } else {
151: $Apache::lonxml::redirection = 0;
152: $Apache::lonxml::metamode = 0;
153: $Apache::lonxml::evaluate = 1;
154: $Apache::lonxml::import = 1;
155: }
156: #&printalltags();
157: my @pars = ();
158: @Apache::lonxml::pwd=();
159: my $pwd=$ENV{'request.filename'};
160: $pwd =~ s:/[^/]*$::;
161: &newparser(\@pars,\$content_file_string,$pwd);
162: my $currentstring = '';
163: my $finaloutput = '';
164: my $newarg = '';
165: my $result;
166:
167: my $safeeval = new Safe;
168: my $safehole = new Safe::Hole;
169: $safeeval->permit("entereval");
170: $safeeval->permit(":base_math");
171: $safeeval->deny(":base_io");
172: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
173: #need to inspect this class of ops
174: # $safeeval->deny(":base_orig");
175: $safeinit .= ';$external::target='.$target.';';
176: $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
177: &Apache::run::run($safeinit,$safeeval);
178: #-------------------- Redefinition of the target in the case of compound target
179:
180: ($target, my @tenta) = split('&&',$target);
181:
182: my @stack = ();
183: my @parstack = ();
184: &initdepth;
185: my $token;
186: while ( $#pars > -1 ) {
187: while ($token = $pars[$#pars]->get_token) {
188: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
189: if ($metamode<1) { $result=$token->[1]; }
190: } elsif ($token->[0] eq 'PI') {
191: if ($metamode<1) { $result=$token->[2]; }
192: } elsif ($token->[0] eq 'S') {
193: # add tag to stack
194: push (@stack,$token->[1]);
195: # add parameters list to another stack
196: push (@parstack,&parstring($token));
197: &increasedepth($token);
198: if (exists $style_for_target{$token->[1]}) {
199: if ($Apache::lonxml::redirection) {
200: $Apache::lonxml::outputstack['-1'] .=
201: &recurse($style_for_target{$token->[1]},$target,$safeeval,
202: \%style_for_target,@parstack);
203: } else {
204: $finaloutput .= &recurse($style_for_target{$token->[1]},$target,
205: $safeeval,\%style_for_target,@parstack);
206: }
207: } else {
208: $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
209: \@pars, $safeeval, \%style_for_target);
210: }
211: } elsif ($token->[0] eq 'E') {
212: #clear out any tags that didn't end
213: while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) {
214: &Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']");
215: pop @stack;pop @parstack;&decreasedepth($token);
216: }
217:
218: if (exists $style_for_target{'/'."$token->[1]"}) {
219: if ($Apache::lonxml::redirection) {
220: $Apache::lonxml::outputstack['-1'] .=
221: &recurse($style_for_target{'/'."$token->[1]"},
222: $target,$safeeval,\%style_for_target,@parstack);
223: } else {
224: $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
225: $target,$safeeval,\%style_for_target,
226: @parstack);
227: }
228:
229: } else {
230: $result = &callsub("end_$token->[1]", $target, $token, \@parstack,
231: \@pars,$safeeval, \%style_for_target);
232: }
233: } else {
234: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
235: }
236: #evaluate variable refs in result
237: if ($result ne "") {
238: if ( $#parstack > -1 ) {
239: if ($Apache::lonxml::redirection) {
240: $Apache::lonxml::outputstack['-1'] .=
241: &Apache::run::evaluate($result,$safeeval,$parstack[$#parstack]);
242: } else {
243: $finaloutput .= &Apache::run::evaluate($result,$safeeval,
244: $parstack[$#parstack]);
245: }
246: } else {
247: $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
248: }
249: $result = '';
250: }
251: if ($token->[0] eq 'E') {
252: pop @stack;pop @parstack;&decreasedepth($token);
253: }
254: }
255: pop @pars;
256: pop @Apache::lonxml::pwd;
257: }
258:
259: # if ($target eq 'meta') {
260: # $finaloutput.=&endredirection;
261: # }
262:
263: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
264: $finaloutput=&afterburn($finaloutput);
265: }
266:
267: return $finaloutput;
268: }
269:
270:
271: sub recurse {
272:
273: my @innerstack = ();
274: my @innerparstack = ();
275: my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
276: my @pat = ();
277: &newparser(\@pat,\$newarg);
278: my $tokenpat;
279: my $partstring = '';
280: my $output='';
281: my $decls='';
282: while ( $#pat > -1 ) {
283: while ($tokenpat = $pat[$#pat]->get_token) {
284: if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
285: if ($metamode<1) { $partstring=$tokenpat->[1]; }
286: } elsif ($tokenpat->[0] eq 'PI') {
287: if ($metamode<1) { $partstring=$tokenpat->[2]; }
288: } elsif ($tokenpat->[0] eq 'S') {
289: push (@innerstack,$tokenpat->[1]);
290: push (@innerparstack,&parstring($tokenpat));
291: &increasedepth($tokenpat);
292: $partstring = &callsub("start_$tokenpat->[1]",
293: $target, $tokenpat, \@innerparstack,
294: \@pat, $safeeval, $style_for_target);
295: } elsif ($tokenpat->[0] eq 'E') {
296: #clear out any tags that didn't end
297: while ($tokenpat->[1] ne $innerstack[$#innerstack]
298: && ($#innerstack > -1)) {
299: &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
300: pop @innerstack;pop @innerparstack;&decreasedepth($tokenpat);
301: }
302: $partstring = &callsub("end_$tokenpat->[1]",
303: $target, $tokenpat, \@innerparstack,
304: \@pat, $safeeval, $style_for_target);
305: } else {
306: &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
307: }
308: #pass both the variable to the style tag, and the tag we
309: #are processing inside the <definedtag>
310: if ( $partstring ne "" ) {
311: if ( $#parstack > -1 ) {
312: if ( $#innerparstack > -1 ) {
313: $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
314: } else {
315: $decls= $parstack[$#parstack];
316: }
317: } else {
318: if ( $#innerparstack > -1 ) {
319: $decls=$innerparstack[$#innerparstack];
320: } else {
321: $decls='';
322: }
323: }
324: $output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
325: $partstring = '';
326: }
327: if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
328: &decreasedepth($tokenpat);}
329: }
330: pop @pat;
331: pop @Apache::lonxml::pwd;
332: }
333: return $output;
334: }
335:
336: sub callsub {
337: my ($sub,$target,$token,$parstack,$parser,$safeeval,$style)=@_;
338: my $currentstring='';
339: my $nodefault;
340: {
341: my $sub1;
342: no strict 'refs';
343: if ($target eq 'edit' && $token->[0] eq 'S') {
344: $currentstring = &Apache::edit::tag_start($target,$token,$parstack,$parser,
345: $safeeval,$style);
346: }
347: my $tag=$token->[1];
348: my $space=$Apache::lonxml::alltags{$tag};
349: if (!$space) {
350: $tag=~tr/A-Z/a-z/;
351: $sub=~tr/A-Z/a-z/;
352: $space=$Apache::lonxml::alltags{$tag}
353: }
354: if ($space) {
355: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
356: $sub1="$space\:\:$sub";
357: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
358: ($currentstring,$nodefault) = &$sub1($target,$token,$parstack,$parser,
359: $safeeval,$style);
360: } else {
361: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
362: if ($metamode <1) {
363: if (defined($token->[4]) && ($metamode < 1)) {
364: $currentstring = $token->[4];
365: } else {
366: $currentstring = $token->[2];
367: }
368: }
369: }
370: &Apache::lonxml::debug("nodefalt:$nodefault:");
371: if ($currentstring eq '' && $nodefault eq '') {
372: if ($target eq 'edit') {
373: &Apache::lonxml::debug("doing default edit for $token->[1]");
374: if ($token->[0] eq 'S') {
375: $currentstring = &Apache::edit::tag_start($target,$token);
376: } elsif ($token->[0] eq 'E') {
377: $currentstring = &Apache::edit::tag_end($target,$token);
378: }
379: } elsif ($target eq 'modified') {
380: if ($token->[0] eq 'S') {
381: $currentstring = $token->[4];
382: $currentstring.=&Apache::edit::handle_insert();
383: } else {
384: $currentstring = $token->[2];
385: }
386: }
387: }
388: use strict 'refs';
389: }
390: return $currentstring;
391: }
392:
393: sub startredirection {
394: $Apache::lonxml::redirection++;
395: push (@Apache::lonxml::outputstack, '');
396: }
397:
398: sub endredirection {
399: if (!$Apache::lonxml::redirection) {
400: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
401: return '';
402: }
403: $Apache::lonxml::redirection--;
404: pop @Apache::lonxml::outputstack;
405: }
406:
407: sub initdepth {
408: @Apache::lonxml::depthcounter=();
409: $Apache::lonxml::depth=-1;
410: $Apache::lonxml::olddepth=-1;
411: }
412:
413: sub increasedepth {
414: my ($token) = @_;
415: $Apache::lonxml::depth++;
416: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
417: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
418: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
419: }
420: my $curdepth=join('_',@Apache::lonxml::depthcounter);
421: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
422: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
423: }
424:
425: sub decreasedepth {
426: my ($token) = @_;
427: $Apache::lonxml::depth--;
428: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
429: $#Apache::lonxml::depthcounter--;
430: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
431: }
432: if ( $Apache::lonxml::depth < -1) {
433: &Apache::lonxml::warning("Unbalanced tags in resource");
434: $Apache::lonxml::depth='-1';
435: }
436: my $curdepth=join('_',@Apache::lonxml::depthcounter);
437: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
438: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
439: }
440:
441: sub get_all_text {
442:
443: my($tag,$pars)= @_;
444: my $depth=0;
445: my $token;
446: my $result='';
447: if ( $tag =~ m:^/: ) {
448: my $tag=substr($tag,1);
449: # &Apache::lonxml::debug("have:$tag:");
450: while (($depth >=0) && ($token = $pars->get_token)) {
451: # &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
452: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
453: $result.=$token->[1];
454: } elsif ($token->[0] eq 'PI') {
455: $result.=$token->[2];
456: } elsif ($token->[0] eq 'S') {
457: if ($token->[1] eq $tag) { $depth++; }
458: $result.=$token->[4];
459: } elsif ($token->[0] eq 'E') {
460: if ( $token->[1] eq $tag) { $depth--; }
461: #skip sending back the last end tag
462: if ($depth > -1) { $result.=$token->[2]; } else {
463: $pars->unget_token($token);
464: }
465: }
466: }
467: } else {
468: while ($token = $pars->get_token) {
469: # &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
470: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
471: $result.=$token->[1];
472: } elsif ($token->[0] eq 'PI') {
473: $result.=$token->[2];
474: } elsif ($token->[0] eq 'S') {
475: if ( $token->[1] eq $tag) {
476: $pars->unget_token($token); last;
477: } else {
478: $result.=$token->[4];
479: }
480: } elsif ($token->[0] eq 'E') {
481: $result.=$token->[2];
482: }
483: }
484: }
485: # &Apache::lonxml::debug("Exit:$result:");
486: return $result
487: }
488:
489: sub newparser {
490: my ($parser,$contentref,$dir) = @_;
491: push (@$parser,HTML::TokeParser->new($contentref));
492: $$parser['-1']->xml_mode('1');
493: if ( $dir eq '' ) {
494: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
495: } else {
496: push (@Apache::lonxml::pwd, $dir);
497: }
498: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
499: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
500: }
501:
502: sub parstring {
503: my ($token) = @_;
504: my $temp='';
505: map {
506: unless ($_=~/\W/) {
507: my $val=$token->[2]->{$_};
508: $val =~ s/([\%\@\\])/\\$1/g;
509: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
510: $temp .= "my \$$_=\"$val\";"
511: }
512: } @{$token->[3]};
513: return $temp;
514: }
515:
516: sub writeallows {
517: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
518: my $thisdir=$thisurl;
519: $thisdir=~s/\/[^\/]+$//;
520: my %httpref=();
521: map {
522: $httpref{'httpref.'.
523: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl; } @extlinks;
524: &Apache::lonnet::appenv(%httpref);
525: }
526:
527: #
528: # Afterburner handles anchors, highlights and links
529: #
530: sub afterburn {
531: my $result=shift;
532: map {
533: my ($name, $value) = split(/=/,$_);
534: $value =~ tr/+/ /;
535: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
536: if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
537: unless ($ENV{'form.'.$name}) {
538: $ENV{'form.'.$name}=$value;
539: }
540: }
541: } (split(/&/,$ENV{'QUERY_STRING'}));
542: if ($ENV{'form.highlight'}) {
543: map {
544: my $anchorname=$_;
545: my $matchthis=$anchorname;
546: $matchthis=~s/\_+/\\s\+/g;
547: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
548: } split(/\,/,$ENV{'form.highlight'});
549: }
550: if ($ENV{'form.link'}) {
551: map {
552: my ($anchorname,$linkurl)=split(/\>/,$_);
553: my $matchthis=$anchorname;
554: $matchthis=~s/\_+/\\s\+/g;
555: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
556: } split(/\,/,$ENV{'form.link'});
557: }
558: if ($ENV{'form.anchor'}) {
559: my $anchorname=$ENV{'form.anchor'};
560: my $matchthis=$anchorname;
561: $matchthis=~s/\_+/\\s\+/g;
562: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
563: $result.=(<<"ENDSCRIPT");
564: <script>
565: document.location.hash='$anchorname';
566: </script>
567: ENDSCRIPT
568: }
569: return $result;
570: }
571:
572: sub handler {
573: my $request=shift;
574:
575: my $target='web';
576:
577: $Apache::lonxml::debug=0;
578:
579: if ($ENV{'browser.mathml'}) {
580: $request->content_type('text/xml');
581: } else {
582: $request->content_type('text/html');
583: }
584:
585: # $request->print(<<ENDHEADER);
586: #<html>
587: #<head>
588: #<title>Just test</title>
589: #</head>
590: #<body bgcolor="#FFFFFF">
591: #ENDHEADER
592: # &Apache::lonhomework::send_header($request);
593: $request->send_http_header;
594:
595: return OK if $request->header_only;
596:
597:
598: my $file=&Apache::lonnet::filelocation("",$request->uri);
599: my %mystyle;
600: my $result = '';
601: my $filecontents=&Apache::lonnet::getfile($file);
602: if ($filecontents == -1) {
603: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
604: $filecontents='';
605: } else {
606: $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
607: }
608:
609: $request->print($result);
610:
611: writeallows($request->uri);
612: return OK;
613: }
614:
615: sub debug {
616: if ($Apache::lonxml::debug eq 1) {
617: print "DEBUG:".$_[0]."<br />\n";
618: }
619: }
620:
621: sub error {
622: if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
623: print "<b>ERROR:</b>".$_[0]."<br />\n";
624: } else {
625: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
626: #notify author
627: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
628: #notify course
629: if ( $ENV{'request.course.id'} ) {
630: my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
631: foreach my $user (split /\,/, $users) {
632: ($user,my $domain) = split /:/, $user;
633: &Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
634: }
635: }
636:
637: #FIXME probably shouldn't have me get everything forever.
638: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
639: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
640: }
641: }
642:
643: sub warning {
644: if ($ENV{'request.state'} eq 'construct') {
645: print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
646: }
647: }
648:
649: sub register_insert {
650: my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
651: my $i;
652: my $tagnum=0;
653: my @order;
654: for ($i=0;$i < $#data; $i++) {
655: my $line = $data[$i];
656: if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
657: if ( $line =~ /TABLE/ ) { last; }
658: my ($tag,$descrip,$function,$show) = split(/,/, $line);
659: $insertlist{"$tagnum.tag"} = $tag;
660: $insertlist{"$tagnum.description"} = $descrip;
661: $insertlist{"$tagnum.function"} = $function;
662: $insertlist{"$tagnum.show"}= $show;
663: $tagnum++;
664: }
665: $i++; #skipping TABLE line
666: $tagnum = 0;
667: for (;$i < $#data;$i++) {
668: my $line = $data[$i];
669: my ($mnemonic,@which) = split(/ +/,$line);
670: my $tag = $insertlist{"$tagnum.tag"};
671: for (my $j=0;$j <$#which;$j++) {
672: if ( $which[$j] eq 'Y' ) {
673: if ($insertlist{"$j.show"} ne 'no') {
674: push(@{ $insertlist{"$tag.which"} },$j);
675: }
676: }
677: }
678: $tagnum++;
679: }
680: }
681: 1;
682: __END__
683:
684:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>