#
# This file is created by Template of umsCodeGenerator version 0.3 candidate
#


				
				
package txt2perl;

#
# Decoder Common Routines
#
# 2004/11/09 - release 0.1 - Created by KM
# 2004/11/09 - release 0.2 - Modified by KM
#

sub ums::readReset {
  $ums::output = "";
}

sub ums::txtCopy {
  my $spos, $epos;
  ($spos, $epos) = @_;
  $ums::output = $ums::output . substr($ums::input, $spos/8, ($epos-$spos)/8);
}

sub ums::txtRead {
  my $spos, $epos;
  ($spos, $epos) = @_;
  return substr($ums::input, $spos/8, ($epos-$spos)/8);
}

sub ums::signedRead {
  my $spos, $epos;
  ($spos, $epos) = @_;

  my $n = unpack("C", substr($ums::input, int($spos/8), 1));
  my $tmp = (($n >> (7-$spos%8)) & 1) * -1;

  for($i=$spos+1; $i < $epos; $i++ ){
    my $n = unpack("C", substr($ums::input, int($i/8), 1));
    $tmp = $tmp * 2;
    $tmp += ($n >> (7-$i%8)) & 1;
  }
  return $tmp;
}

sub ums::unsignedRead {
  my $spos, $epos;
  ($spos, $epos) = @_;

  my $n = unpack("C", substr($ums::input, int($spos/8), 1));
  my $tmp = (($n >> (7-$spos%8)) & 1) * +1;

  for(my $i=$spos+1; $i < $epos; $i++ ){
    my $n = unpack("C", substr($ums::input, int($i/8), 1));
    $tmp = $tmp * 2;
    $tmp += ($n >> (7-$i%8)) & 1;
  }
  return $tmp;
}

sub ums::ieee754singleRead {
  my $spos, $epos;
  ($spos, $epos) = @_;

  return unpack("f", substr($ums::input, int($spos/8), 4));
}

sub ums::ieee754doubleRead {
  my $spos, $epos;
  ($spos, $epos) = @_;

  return unpack("d", substr($ums::input, int($spos/8), 8));
}
#
#  Definition of Decoder (matcher)
#

# < operl:decoderSub> #
sub match {
  my $label, $epos1;
  ($label,$epos1) = @_;

  $ums::pos0  = $ums::pos;

  $ums::found = &match1($label, $epos1);
  if($ums::found == 0 ){ $ums::pos = $ums::pos0; }
  return $ums::found;
}

sub match1 {
  my $label, $epos1;
  ($label, $epos1) = @_;

  my $level   =  -1;
  LOOP: while(1){
    # < idat:byte> #
    {
      my $found1 = 0;
      if ($level >= 0 || $label == 3){ $level++; }
      LOOP: while(1){
        # < group> #
        {
          my $found2 = 0;

          if ($level >= 0 || $label == 4){ $level++; }
          LOOP: while(1){
            # < operl:readerSub> #
            # < group> #
            {
              my $found3 = 0;

              if ($level >= 0 || $label == 6){ $level++; }
              LOOP: while(1){
                # < idat:byte> #
                {
                  my $found4 = 0;
                  if ($level >= 0 || $label == 7){ $level++; }
                  LOOP: while(1){
                    my $epos2 = $ums::pos + 6 * 8; 
                    # < data> #
                    {
                      my $found = 1;
                      my $eposd = $epos2;
                      if ($level >= 0 || $label == 9){ $level++; }
                      if ($level >= 0){ $level--;
                        $ums::pos = $eposd;
                        if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                        if (!$found){ last LOOP; }
                      }
                    }
                    # </data> #
                    if ($level < 0){ last LOOP; }
                    if($ums::pos == $epos2 ){ $found4 = 1; }else{ $found4 = 0; }
                    $found4 = 1;
                    last LOOP;                           
                  }
                  if ($level >= 0){ $level--;
                    if ($level < 0){ return $found4; }
                    if ($found4==0){ last LOOP; }
                  }
                }
                # </idat:byte> #
                # < idat:byte> #
                {
                  my $found4 = 0;
                  if ($level >= 0 || $label == 10){ $level++; }
                  LOOP: while(1){
                    my $epos2 = $ums::pos + 1 * 8; 
                    # < data> #
                    {
                      my $found = 1;
                      my $eposd = $epos2;
                      if ($level >= 0 || $label == 11){ $level++; }
                      # < param> #
                      if ($level >= 0 && $found){        
                        my $tmp = &ums::txtRead($ums::pos, $eposd);
                        $found = ($tmp =~ /^[\s]+/ );
                        if($found){$eposd = $ums::pos + 8*length($&);}
                      }
                      # </param> #
                      if ($level >= 0){ $level--;
                        $ums::pos = $eposd;
                        if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                        if (!$found){ last LOOP; }
                      }
                    }
                    # </data> #
                    if ($level < 0){ last LOOP; }
                    if($ums::pos == $epos2 ){ $found4 = 1; }else{ $found4 = 0; }
                    $found4 = 1;
                    last LOOP;                           
                  }
                  if ($level >= 0){ $level--;
                    if ($level < 0){ return $found4; }
                    if ($found4==0){ last LOOP; }
                  }
                }
                # </idat:byte> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 14){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[a-zA-Z_][a-zA-Z0-9_]*/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < value> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 16){ $level++; }
                  if ($level >= 0 && $found){        
                    my $len = length("(");
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ( substr($tmp,0, $len) eq "(" );
                    $eposd = $ums::pos + $len*8;
                  }
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </value> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 17){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[\s]*/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 20){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[0-9]+/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 22){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[\s]*/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < value> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 24){ $level++; }
                  if ($level >= 0 && $found){        
                    my $len = length(")");
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ( substr($tmp,0, $len) eq ")" );
                    $eposd = $ums::pos + $len*8;
                  }
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </value> #
                if ($level < 0){ last LOOP; }
                $found3 = 1; 
                last LOOP;                           
              }
              if ($level >= 0){ $level--;
                if ($level < 0){ return $found3; }
                if ($found3==0){ last LOOP; }
              }
            }
            # </group> #
            # < zeroOrMore> #
            {
              my $pos1 = $ums::pos;
              my $found3 = 0;

              if ($level >= 0 || $label == 25){ $level++; }
              LOOP: while(1){
                # < loopGroup> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 28){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[\s]+/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 31){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[0-9]+/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # </loopGroup> #
                if ($level < 0){ last LOOP; }
                $pos1 = $ums::pos;
                $found3 ++;
              }
              if ($level >= 0){ $level--;
                $ums::pos = $pos1;
                if ($level < 0){
                  if ($found3 < 0){ $found3 = 0; }
                  return $found3; 
                }
                if ($found3 < 0){ last LOOP; }
              }
            }
            # </zeroOrMore> #
            # < choice> #
            { 
              my $pos1 = $ums::pos;
              my $found3 = 0;

              if ($level >= 0 || $label == 33){ $level++; }
              # < choiceGroup> #
              if ($level >= 0 || $label == 34){ $level++; }
              LOOP: while($found3 == 0){
                # < value> #
                # </value> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 37){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^[\s]+/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 39){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^#/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                # < data> #
                {
                  my $found = 1;
                  my $eposd = $epos1;
                  if ($level >= 0 || $label == 42){ $level++; }
                  # < param> #
                  if ($level >= 0 && $found){        
                    my $tmp = &ums::txtRead($ums::pos, $eposd);
                    $found = ($tmp =~ /^.+/ );
                    if($found){$eposd = $ums::pos + 8*length($&);}
                  }
                  # </param> #
                  if ($level >= 0){ $level--;
                    $ums::pos = $eposd;
                    if ($level < 0){ if($found){ return 1; }else{ return 0; }}
                    if (!$found){ last LOOP; }
                  }
                }
                # </data> #
                if ($level < 0){ last LOOP; }
                $found3 = 1;
                last LOOP;
              }
              if ($level >= 0){ $level--;
                if ($found3==0){ $ums::pos = $pos1; }
                if ($level < 0){ return $found3; }
              }
              # </choiceGroup> #
              # < choiceGroup> #
              if ($level >= 0 || $label == 44){ $level++; }
              LOOP: while($found3 == 0){
                # < value> #
                # </value> #
                if ($level < 0){ last LOOP; }
                $found3 = 1;
                last LOOP;
              }
              if ($level >= 0){ $level--;
                if ($found3==0){ $ums::pos = $pos1; }
                if ($level < 0){ return $found3; }
              }
              # </choiceGroup> #
              if ($level >= 0){ $level--;
                if ($level < 0){ return $found3; }
                if ($found3==0){ last LOOP; }
              }
            }
            # </choice> #
            # </operl:readerSub> #
            if ($level < 0){ last LOOP; }
            $found2 = 1; 
            last LOOP;                           
          }
          if ($level >= 0){ $level--;
            if ($level < 0){ return $found2; }
            if ($found2==0){ last LOOP; }
          }
        }
        # </group> #
        if ($level < 0){ last LOOP; }
        if($ums::pos == $epos1 ){ $found1 = 1; }else{ $found1 = 0; }
        $found1 = 1;
        last LOOP;                           
      }
      if ($level >= 0){ $level--;
        if ($level < 0){ return $found1; }
        if ($found1==0){ last LOOP; }
      }
    }
    # </idat:byte> #
  }
  die("ums:match() - internal error");
  return 0;
}
# </operl:decoderSub> #

#
#  Definition of Decoder (mapping decoder)
#

# < operl:decoderSub> #
sub parse {
  ($ums::input) = @_;
  my $epos1 = 8*length($ums::input);
  &ums::readReset();

  $ums::pos = 0;
  # < idat:byte> #
  &match(3, $epos1);
  {
    my $epos2 = $ums::pos;
    $ums::pos = $ums::pos0;
    {
    # < group> #
    &match(4, $epos2);
    {
      my $epos3 = $ums::pos;
      $ums::pos = $ums::pos0;
      {
        # < operl:readerSub> #
        # < group> #
        &match(6, $epos3);
        {
          my $epos4 = $ums::pos;
          $ums::pos = $ums::pos0;
          {
            # < idat:byte> #
            &match(7, $epos4);
            {
              my $epos5 = $ums::pos;
              $ums::pos = $ums::pos0;
              {
              # < data> #
              &match(9, $epos5);
              $type = &ums::txtRead($ums::pos0, $ums::pos);
              # </data> #
              }
              $ums::pos = $epos5;
            }
            # </idat:byte> #
            # < idat:byte> #
            &match(10, $epos4);
            {
              my $epos5 = $ums::pos;
              $ums::pos = $ums::pos0;
              {
              # < data> #
              &match(11, $epos5);
              # < param> #
              # </param> #
              # </data> #
              }
              $ums::pos = $epos5;
            }
            # </idat:byte> #
            # < data> #
            &match(14, $epos4);
            # < param> #
            # </param> #
            $name = &ums::txtRead($ums::pos0, $ums::pos);
            # </data> #
            # < value> #
            &match(16, $epos4);
            # </value> #
            # < data> #
            &match(17, $epos4);
            # < param> #
            # </param> #
            # </data> #
            # < data> #
            &match(20, $epos4);
            # < param> #
            # </param> #
            $order = &ums::txtRead($ums::pos0, $ums::pos);
            # </data> #
            # < data> #
            &match(22, $epos4);
            # < param> #
            # </param> #
            # </data> #
            # < value> #
            &match(24, $epos4);
            # </value> #
          }
          $ums::pos = $epos4;
        }
        # </group> #
        # < zeroOrMore> #
        &match(25, $epos3);
        {
          my $epos4 = $ums::pos;
          $ums::pos = $ums::pos0;
          my $i25, $n = $ums::found;
          for($i25=0; $i25 < $n; $i25++ ){
            # < loopGroup> #
            # < data> #
            &match(28, $epos4);
            # < param> #
            # </param> #
            # </data> #
            # < data> #
            &match(31, $epos4);
            # < param> #
            # </param> #
            $value[$i25] = &ums::txtRead($ums::pos0, $ums::pos);
            # </data> #
            # </loopGroup> #
          }
          $ums::pos = $epos4;
        }
        # </zeroOrMore> #
        # < choice> #
        &match(33, $epos3);
        {
          my $epos4 = $ums::pos;
          $ums::pos = $ums::pos0;
          if( 0 ){ ; }
          # < choiceGroup> #
          elsif (&match(34, $epos4) != 0){
            my $epos5 = $ums::pos;
            $ums::pos = $ums::pos0;
            {
              # < value> #
              $hasComment
 = "1";
              # </value> #
              # < data> #
              &match(37, $epos5);
              # < param> #
              # </param> #
              # </data> #
              # < data> #
              &match(39, $epos5);
              # < param> #
              # </param> #
              # </data> #
              # < data> #
              &match(42, $epos5);
              # < param> #
              # </param> #
              $comment = &ums::txtRead($ums::pos0, $ums::pos);
              # </data> #
            }
            $ums::pos = $epos5;
          }
          # </choiceGroup> #
          # < choiceGroup> #
          elsif (&match(44, $epos4) != 0){
            my $epos5 = $ums::pos;
            $ums::pos = $ums::pos0;
            {
              # < value> #
              $hasComment
 = "0";
              # </value> #
            }
            $ums::pos = $epos5;
          }
          # </choiceGroup> #
          $ums::pos = $epos4;
        }
        # </choice> #
        &userProgram();
        # </operl:readerSub> #
      }
      $ums::pos = $epos3;
    }
    # </group> #
    }
    $ums::pos = $epos2;
  }
  # </idat:byte> #
  return 0;
}
# </operl:decoderSub> #

1;
