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->permit("sort");
172: $safeeval->deny(":base_io");
173: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
174: #need to inspect this class of ops
175: # $safeeval->deny(":base_orig");
176: $safeinit .= ';$external::target='.$target.';';
177: $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
178: &Apache::run::run($safeinit,$safeeval);
179: #-------------------- Redefinition of the target in the case of compound target
180:
181: ($target, my @tenta) = split('&&',$target);
182:
183: my @stack = ();
184: my @parstack = ();
185: &initdepth;
186: my $token;
187: while ( $#pars > -1 ) {
188: while ($token = $pars[$#pars]->get_token) {
189: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
190: if ($metamode<1) { $result=$token->[1]; }
191: } elsif ($token->[0] eq 'PI') {
192: if ($metamode<1) { $result=$token->[2]; }
193: } elsif ($token->[0] eq 'S') {
194: # add tag to stack
195: push (@stack,$token->[1]);
196: # add parameters list to another stack
197: push (@parstack,&parstring($token));
198: &increasedepth($token);
199: if (exists $style_for_target{$token->[1]}) {
200: if ($Apache::lonxml::redirection) {
201: $Apache::lonxml::outputstack['-1'] .=
202: &recurse($style_for_target{$token->[1]},$target,$safeeval,
203: \%style_for_target,@parstack);
204: } else {
205: $finaloutput .= &recurse($style_for_target{$token->[1]},$target,
206: $safeeval,\%style_for_target,@parstack);
207: }
208: } else {
209: $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
210: \@pars, $safeeval, \%style_for_target);
211: }
212: } elsif ($token->[0] eq 'E') {
213: #clear out any tags that didn't end
214: while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) {
215: &Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']");
216: pop @stack;pop @parstack;&decreasedepth($token);
217: }
218:
219: if (exists $style_for_target{'/'."$token->[1]"}) {
220: if ($Apache::lonxml::redirection) {
221: $Apache::lonxml::outputstack['-1'] .=
222: &recurse($style_for_target{'/'."$token->[1]"},
223: $target,$safeeval,\%style_for_target,@parstack);
224: } else {
225: $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
226: $target,$safeeval,\%style_for_target,
227: @parstack);
228: }
229:
230: } else {
231: $result = &callsub("end_$token->[1]", $target, $token, \@parstack,
232: \@pars,$safeeval, \%style_for_target);
233: }
234: } else {
235: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
236: }
237: #evaluate variable refs in result
238: if ($result ne "") {
239: if ( $#parstack > -1 ) {
240: if ($Apache::lonxml::redirection) {
241: $Apache::lonxml::outputstack['-1'] .=
242: &Apache::run::evaluate($result,$safeeval,$parstack[$#parstack]);
243: } else {
244: $finaloutput .= &Apache::run::evaluate($result,$safeeval,
245: $parstack[$#parstack]);
246: }
247: } else {
248: $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
249: }
250: $result = '';
251: }
252: if ($token->[0] eq 'E') {
253: pop @stack;pop @parstack;&decreasedepth($token);
254: }
255: }
256: pop @pars;
257: pop @Apache::lonxml::pwd;
258: }
259:
260: # if ($target eq 'meta') {
261: # $finaloutput.=&endredirection;
262: # }
263:
264: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
265: $finaloutput=&afterburn($finaloutput);
266: }
267:
268: return $finaloutput;
269: }
270:
271:
272: sub recurse {
273:
274: my @innerstack = ();
275: my @innerparstack = ();
276: my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
277: my @pat = ();
278: &newparser(\@pat,\$newarg);
279: my $tokenpat;
280: my $partstring = '';
281: my $output='';
282: my $decls='';
283: while ( $#pat > -1 ) {
284: while ($tokenpat = $pat[$#pat]->get_token) {
285: if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
286: if ($metamode<1) { $partstring=$tokenpat->[1]; }
287: } elsif ($tokenpat->[0] eq 'PI') {
288: if ($metamode<1) { $partstring=$tokenpat->[2]; }
289: } elsif ($tokenpat->[0] eq 'S') {
290: push (@innerstack,$tokenpat->[1]);
291: push (@innerparstack,&parstring($tokenpat));
292: &increasedepth($tokenpat);
293: $partstring = &callsub("start_$tokenpat->[1]",
294: $target, $tokenpat, \@innerparstack,
295: \@pat, $safeeval, $style_for_target);
296: } elsif ($tokenpat->[0] eq 'E') {
297: #clear out any tags that didn't end
298: while ($tokenpat->[1] ne $innerstack[$#innerstack]
299: && ($#innerstack > -1)) {
300: &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
301: pop @innerstack;pop @innerparstack;&decreasedepth($tokenpat);
302: }
303: $partstring = &callsub("end_$tokenpat->[1]",
304: $target, $tokenpat, \@innerparstack,
305: \@pat, $safeeval, $style_for_target);
306: } else {
307: &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
308: }
309: #pass both the variable to the style tag, and the tag we
310: #are processing inside the <definedtag>
311: if ( $partstring ne "" ) {
312: if ( $#parstack > -1 ) {
313: if ( $#innerparstack > -1 ) {
314: $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
315: } else {
316: $decls= $parstack[$#parstack];
317: }
318: } else {
319: if ( $#innerparstack > -1 ) {
320: $decls=$innerparstack[$#innerparstack];
321: } else {
322: $decls='';
323: }
324: }
325: $output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
326: $partstring = '';
327: }
328: if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
329: &decreasedepth($tokenpat);}
330: }
331: pop @pat;
332: pop @Apache::lonxml::pwd;
333: }
334: return $output;
335: }
336:
337: sub callsub {
338: my ($sub,$target,$token,$parstack,$parser,$safeeval,$style)=@_;
339: my $currentstring='';
340: my $nodefault;
341: {
342: my $sub1;
343: no strict 'refs';
344: if ($target eq 'edit' && $token->[0] eq 'S') {
345: $currentstring = &Apache::edit::tag_start($target,$token,$parstack,$parser,
346: $safeeval,$style);
347: }
348: my $tag=$token->[1];
349: my $space=$Apache::lonxml::alltags{$tag};
350: if (!$space) {
351: $tag=~tr/A-Z/a-z/;
352: $sub=~tr/A-Z/a-z/;
353: $space=$Apache::lonxml::alltags{$tag}
354: }
355: if ($space) {
356: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
357: $sub1="$space\:\:$sub";
358: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
359: ($currentstring,$nodefault) = &$sub1($target,$token,$parstack,$parser,
360: $safeeval,$style);
361: } else {
362: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
363: if ($metamode <1) {
364: if (defined($token->[4]) && ($metamode < 1)) {
365: $currentstring = $token->[4];
366: } else {
367: $currentstring = $token->[2];
368: }
369: }
370: }
371: &Apache::lonxml::debug("nodefalt:$nodefault:");
372: if ($currentstring eq '' && $nodefault eq '') {
373: if ($target eq 'edit') {
374: &Apache::lonxml::debug("doing default edit for $token->[1]");
375: if ($token->[0] eq 'S') {
376: $currentstring = &Apache::edit::tag_start($target,$token);
377: } elsif ($token->[0] eq 'E') {
378: $currentstring = &Apache::edit::tag_end($target,$token);
379: }
380: } elsif ($target eq 'modified') {
381: if ($token->[0] eq 'S') {
382: $currentstring = $token->[4];
383: $currentstring.=&Apache::edit::handle_insert();
384: } else {
385: $currentstring = $token->[2];
386: }
387: }
388: }
389: use strict 'refs';
390: }
391: return $currentstring;
392: }
393:
394: sub startredirection {
395: $Apache::lonxml::redirection++;
396: push (@Apache::lonxml::outputstack, '');
397: }
398:
399: sub endredirection {
400: if (!$Apache::lonxml::redirection) {
401: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
402: return '';
403: }
404: $Apache::lonxml::redirection--;
405: pop @Apache::lonxml::outputstack;
406: }
407:
408: sub initdepth {
409: @Apache::lonxml::depthcounter=();
410: $Apache::lonxml::depth=-1;
411: $Apache::lonxml::olddepth=-1;
412: }
413:
414: sub increasedepth {
415: my ($token) = @_;
416: $Apache::lonxml::depth++;
417: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
418: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
419: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
420: }
421: my $curdepth=join('_',@Apache::lonxml::depthcounter);
422: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
423: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
424: }
425:
426: sub decreasedepth {
427: my ($token) = @_;
428: $Apache::lonxml::depth--;
429: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
430: $#Apache::lonxml::depthcounter--;
431: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
432: }
433: if ( $Apache::lonxml::depth < -1) {
434: &Apache::lonxml::warning("Unbalanced tags in resource");
435: $Apache::lonxml::depth='-1';
436: }
437: my $curdepth=join('_',@Apache::lonxml::depthcounter);
438: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
439: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
440: }
441:
442: sub get_all_text {
443:
444: my($tag,$pars)= @_;
445: my $depth=0;
446: my $token;
447: my $result='';
448: if ( $tag =~ m:^/: ) {
449: my $tag=substr($tag,1);
450: # &Apache::lonxml::debug("have:$tag:");
451: while (($depth >=0) && ($token = $pars->get_token)) {
452: # &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
453: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
454: $result.=$token->[1];
455: } elsif ($token->[0] eq 'PI') {
456: $result.=$token->[2];
457: } elsif ($token->[0] eq 'S') {
458: if ($token->[1] eq $tag) { $depth++; }
459: $result.=$token->[4];
460: } elsif ($token->[0] eq 'E') {
461: if ( $token->[1] eq $tag) { $depth--; }
462: #skip sending back the last end tag
463: if ($depth > -1) { $result.=$token->[2]; } else {
464: $pars->unget_token($token);
465: }
466: }
467: }
468: } else {
469: while ($token = $pars->get_token) {
470: # &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
471: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
472: $result.=$token->[1];
473: } elsif ($token->[0] eq 'PI') {
474: $result.=$token->[2];
475: } elsif ($token->[0] eq 'S') {
476: if ( $token->[1] eq $tag) {
477: $pars->unget_token($token); last;
478: } else {
479: $result.=$token->[4];
480: }
481: } elsif ($token->[0] eq 'E') {
482: $result.=$token->[2];
483: }
484: }
485: }
486: # &Apache::lonxml::debug("Exit:$result:");
487: return $result
488: }
489:
490: sub newparser {
491: my ($parser,$contentref,$dir) = @_;
492: push (@$parser,HTML::TokeParser->new($contentref));
493: $$parser['-1']->xml_mode('1');
494: if ( $dir eq '' ) {
495: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
496: } else {
497: push (@Apache::lonxml::pwd, $dir);
498: }
499: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
500: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
501: }
502:
503: sub parstring {
504: my ($token) = @_;
505: my $temp='';
506: map {
507: unless ($_=~/\W/) {
508: my $val=$token->[2]->{$_};
509: $val =~ s/([\%\@\\])/\\$1/g;
510: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
511: $temp .= "my \$$_=\"$val\";"
512: }
513: } @{$token->[3]};
514: return $temp;
515: }
516:
517: sub writeallows {
518: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
519: my $thisdir=$thisurl;
520: $thisdir=~s/\/[^\/]+$//;
521: my %httpref=();
522: map {
523: $httpref{'httpref.'.
524: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl; } @extlinks;
525: &Apache::lonnet::appenv(%httpref);
526: }
527:
528: #
529: # Afterburner handles anchors, highlights and links
530: #
531: sub afterburn {
532: my $result=shift;
533: map {
534: my ($name, $value) = split(/=/,$_);
535: $value =~ tr/+/ /;
536: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
537: if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
538: unless ($ENV{'form.'.$name}) {
539: $ENV{'form.'.$name}=$value;
540: }
541: }
542: } (split(/&/,$ENV{'QUERY_STRING'}));
543: if ($ENV{'form.highlight'}) {
544: map {
545: my $anchorname=$_;
546: my $matchthis=$anchorname;
547: $matchthis=~s/\_+/\\s\+/g;
548: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
549: } split(/\,/,$ENV{'form.highlight'});
550: }
551: if ($ENV{'form.link'}) {
552: map {
553: my ($anchorname,$linkurl)=split(/\>/,$_);
554: my $matchthis=$anchorname;
555: $matchthis=~s/\_+/\\s\+/g;
556: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
557: } split(/\,/,$ENV{'form.link'});
558: }
559: if ($ENV{'form.anchor'}) {
560: my $anchorname=$ENV{'form.anchor'};
561: my $matchthis=$anchorname;
562: $matchthis=~s/\_+/\\s\+/g;
563: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
564: $result.=(<<"ENDSCRIPT");
565: <script>
566: document.location.hash='$anchorname';
567: </script>
568: ENDSCRIPT
569: }
570: return $result;
571: }
572:
573: sub handler {
574: my $request=shift;
575:
576: my $target='web';
577:
578: $Apache::lonxml::debug=0;
579:
580: if ($ENV{'browser.mathml'}) {
581: $request->content_type('text/xml');
582: } else {
583: $request->content_type('text/html');
584: }
585:
586: # $request->print(<<ENDHEADER);
587: #<html>
588: #<head>
589: #<title>Just test</title>
590: #</head>
591: #<body bgcolor="#FFFFFF">
592: #ENDHEADER
593: # &Apache::lonhomework::send_header($request);
594: $request->send_http_header;
595:
596: return OK if $request->header_only;
597:
598:
599: my $file=&Apache::lonnet::filelocation("",$request->uri);
600: my %mystyle;
601: my $result = '';
602: my $filecontents=&Apache::lonnet::getfile($file);
603: if ($filecontents == -1) {
604: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
605: $filecontents='';
606: } else {
607: $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
608: }
609:
610: $request->print($result);
611:
612: writeallows($request->uri);
613: return OK;
614: }
615:
616: sub debug {
617: if ($Apache::lonxml::debug eq 1) {
618: print "DEBUG:".$_[0]."<br />\n";
619: }
620: }
621:
622: sub error {
623: if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
624: print "<b>ERROR:</b>".$_[0]."<br />\n";
625: } else {
626: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
627: #notify author
628: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
629: #notify course
630: if ( $ENV{'request.course.id'} ) {
631: my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
632: foreach my $user (split /\,/, $users) {
633: ($user,my $domain) = split /:/, $user;
634: &Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
635: }
636: }
637:
638: #FIXME probably shouldn't have me get everything forever.
639: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
640: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
641: }
642: }
643:
644: sub warning {
645: if ($ENV{'request.state'} eq 'construct') {
646: print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
647: }
648: }
649:
650: sub register_insert {
651: my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
652: my $i;
653: my $tagnum=0;
654: my @order;
655: for ($i=0;$i < $#data; $i++) {
656: my $line = $data[$i];
657: if ( $line =~ /^\#/ || $line =~ /^\s*\n/) { next; }
658: if ( $line =~ /TABLE/ ) { last; }
659: my ($tag,$descrip,$function,$show) = split(/,/, $line);
660: $insertlist{"$tagnum.tag"} = $tag;
661: $insertlist{"$tagnum.description"} = $descrip;
662: $insertlist{"$tagnum.function"} = $function;
663: $insertlist{"$tagnum.show"}= $show;
664: $tagnum++;
665: }
666: $i++; #skipping TABLE line
667: $tagnum = 0;
668: for (;$i < $#data;$i++) {
669: my $line = $data[$i];
670: my ($mnemonic,@which) = split(/ +/,$line);
671: my $tag = $insertlist{"$tagnum.tag"};
672: for (my $j=0;$j <$#which;$j++) {
673: if ( $which[$j] eq 'Y' ) {
674: if ($insertlist{"$j.show"} ne 'no') {
675: push(@{ $insertlist{"$tag.which"} },$j);
676: }
677: }
678: }
679: $tagnum++;
680: }
681: }
682: 1;
683: __END__
684:
685:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>