--- rat/lonuserstate.pm 2000/08/02 15:27:10 1.2 +++ rat/lonuserstate.pm 2000/08/06 03:25:24 1.3 @@ -10,7 +10,7 @@ # 7/1 Gerd Kortemeyer) # 7/1,7/3,7/4,7/7,7/8,7/10 Gerd Kortemeyer) # -# 7/15,7/17,7/18,8/1,8/2 Gerd Kortemeyer +# 7/15,7/17,7/18,8/1,8/2,8/4,8/5 Gerd Kortemeyer package Apache::lonuserstate; @@ -175,21 +175,49 @@ sub loadmap { } } +# --------------------------------------------------------- Simplify expression + +sub simplify { + my $expression=shift; +# "True and" is nothing + $expression=~s/0\&//g; +# (8)=8 + $expression=~s/\((\d+)\)/$1/g; +# 8&8=8 + $expression=~s/(\d+)\&\1/$1/g; +# 8|8=8 + $expression=~s/(\d+)\|\1/$1/g; +# (5&3)&4=5&3&4 + $expression=~s/\((\d+)\&(\d+)\)\&(\d+)/$1\&$2\&$3/g; +# (((5&3)|(4&6)))=((5&3)|(4&6)) + $expression=~ + s/\((\(\(\d+(?:\&\d+)*\)(?:\|\(\d+(?:\&\d+)*\))+\))\)/$1/g; +# ((5&3)|(4&6))|(1&2)=(5&3)|(4&6)|(1&2) + $expression=~ + s/\((\(\d+(?:\&\d+)*\))((?:\|\(\d+(?:\&\d+)*\))+)\)\|(\(\d+(?:\&\d+)*\))/\($1$2\|$3\)/g; + return $expression; +} + # -------------------------------------------------------- Build condition hash sub traceroute { - my ($sofar,$rid,$beenhere)=shift; + my ($sofar,$rid,$beenhere)=@_; + $sofar=simplify($sofar); unless ($beenhere=~/\&$rid\&/) { $beenhere.=$rid.'&'; if (defined($hash{'conditions_'.$rid})) { - $hash{'conditions_'.$rid}= - '('.$hash{'conditions_'.$rid}.')|('.$sofar.')'; + $hash{'conditions_'.$rid}=simplify( + '('.$hash{'conditions_'.$rid}.')|('.$sofar.')'); } else { $hash{'conditions_'.$rid}=$sofar; } if (defined($hash{'is_map_'.$rid})) { - if () { - &traceroute($sofar,$startrid,'&'); + if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) { + &traceroute($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},'&'); + if (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) { + $sofar= + $hash{'conditions_'.$hash{'map_finish_'.$hash{'src_'.$rid}}}; + } } } if (defined($hash{'to_'.$rid})) { @@ -197,7 +225,8 @@ sub traceroute { my $further=$sofar; if ($hash{'undercond_'.$_}) { if (defined($hash{'condid_'.$hash{'undercond_'.$_}})) { - $further.='&'.$hash{'condid_'.$hash{'undercond_'.$_}}; + $further=simplify('('.$further.')&('. + $hash{'condid_'.$hash{'undercond_'.$_}}.')'); } else { $errtext.='Undefined condition ID: ' .$hash{'undercond_'.$_}.'. '; @@ -213,11 +242,14 @@ sub traceroute { sub readmap { my $uri=shift; - @cond=(); + @cond=('true:normal'); %hash=(); $errtext=''; $pc=0; loadmap($uri); + if (defined($hash{'map_start_'.$uri})) { + &traceroute('0',$hash{'map_start_'.$uri},'&'); + } } # ---------------------------------------------------------------- Testing only