[LON-CAPA-cvs] cvs: loncom /xml lonxml.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sun, 18 Feb 2007 02:10:04 -0000


albertel		Sat Feb 17 21:10:04 2007 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
  Log:
  - cleanup some nasty old bookkeeping code
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.438 loncom/xml/lonxml.pm:1.439
--- loncom/xml/lonxml.pm:1.438	Sat Feb 17 21:07:11 2007
+++ loncom/xml/lonxml.pm	Sat Feb 17 21:10:04 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.438 2007/02/18 02:07:11 albertel Exp $
+# $Id: lonxml.pm,v 1.439 2007/02/18 02:10:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -901,58 +901,50 @@
 
 sub initdepth {
   @Apache::lonxml::depthcounter=();
-  $Apache::lonxml::depth=-1;
-  $Apache::lonxml::olddepth=-1;
+  undef($Apache::lonxml::last_depth_count);
 }
 
 
 my @timers;
 my $lasttime;
-# $Apache::lonxml::depth -> current stack depth
 # @Apache::lonxml::depthcounter -> count of tags that exist so
 #                                  far at each level
-# $Apache::lonxml::olddepth -> when ascending, need to remember the count for the level below the current level (for example going from 1_2 -> 1 -> 1_3 need to rember that ) 
+# $Apache::lonxml::last_depth_count -> when ascending, need to
+# remember the count for the level below the current level (for
+# example going from 1_2 -> 1 -> 1_3 need to remember the 2 )
 
 sub increasedepth {
   my ($token) = @_;
-  $Apache::lonxml::depth++;
-  $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
-  if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
-    $Apache::lonxml::olddepth=$Apache::lonxml::depth;
-  }
+  push(@Apache::lonxml::depthcounter,$Apache::lonxml::last_depth_count+1);
+  undef($Apache::lonxml::last_depth_count);
   my $time;
   if ($Apache::lonxml::debug eq "1") {
       push(@timers,[&gettimeofday()]);
       $time=&tv_interval($lasttime);
       $lasttime=[&gettimeofday()];
   }
-  my $spacing='  'x($Apache::lonxml::depth-1);
+  my $spacing='  'x($#Apache::lonxml::depthcounter);
   $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
-  &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time");
+#  &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time");
 #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
 }
 
 sub decreasedepth {
   my ($token) = @_;
-  $Apache::lonxml::depth--;
-  if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
-    $#Apache::lonxml::depthcounter--;
-    $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
-  }
-  if (  $Apache::lonxml::depth < -1) {
-    &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
-    $Apache::lonxml::depth='-1';
+  if (  $#Apache::lonxml::depthcounter == -1) {
+      &Apache::lonxml::warning(&mt("Missing tags, unable to properly run file."));
   }
+  $Apache::lonxml::last_depth_count = pop(@Apache::lonxml::depthcounter);
+
   my ($timer,$time);
   if ($Apache::lonxml::debug eq "1") {
       $timer=pop(@timers);
       $time=&tv_interval($lasttime);
       $lasttime=[&gettimeofday()];
   }
-  my $spacing='  'x$Apache::lonxml::depth;
-  $Apache::lonxml::curdepth=
-      join('_',@Apache::lonxml::depthcounter[0..$Apache::lonxml::depth]);
-  &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time : ".&tv_interval($timer));
+  my $spacing='  'x($#Apache::lonxml::depthcounter);
+  $Apache::lonxml::curdepth = join('_',@Apache::lonxml::depthcounter);
+#  &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time : ".&tv_interval($timer));
 #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
 }