X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fperl%2FQuery.pm;h=9a8b168e79978047138394ffbd537829a5ef6fc0;hb=3cf2b0aaf15a2076c18de7e684703c175ed05d4e;hp=b39b5ac0d9abcdcbc38fad953d1c6c502f82a7e4;hpb=f56916dc7057593bc6d257d81512863f77eac8e9;p=libucw.git diff --git a/lib/perl/Query.pm b/lib/perl/Query.pm index b39b5ac0..9a8b168e 100644 --- a/lib/perl/Query.pm +++ b/lib/perl/Query.pm @@ -1,6 +1,6 @@ # Perl module for sending queries to Sherlock search servers and parsing answers # -# (c) 2002 Martin Mares +# (c) 2002--2003 Martin Mares # # This software may be freely distributed and used according to the terms # of the GNU Lesser General Public License. @@ -117,6 +117,7 @@ sub command($$) { # Status line my $stat = <$sock>; + $stat = "-903 Incomplete reply" if !defined $stat; chomp $stat; $stat =~ /^[+-]/ or return "-901 Reply parse error"; @@ -141,41 +142,26 @@ sub command($$) { } our $hdr_syntax = { - 'D' => { - 'D' => "", + '(D' => { 'W' => [], 'P' => [], 'n' => [], - 'T' => "", - '-' => "", '.' => [], }, '.' => [], - '' => "" }; our $card_syntax = { - 'U' => { - 'U' => "", - 'D' => "", - 'E' => "", - 'L' => "", - 'T' => "", - 'c' => "", - 's' => "", + '(U' => { 'V' => [], - 'b' => "", - 'i' => "", 'y' => [], - 'z' => "", + 'E' => [], }, 'M' => [], 'X' => [], - '' => "" }; our $footer_syntax = { - '' => "" }; sub query($$) { @@ -221,18 +207,19 @@ sub do_parse_tree($$$$) { my $syntax = shift @_; while ($i < @$raw) { - $raw->[$i] =~ /^(.)(.*)/; - if (!defined($syntax->{$1}) && !defined($syntax->{''})) { return $i; } - if (ref $syntax->{$1} eq "ARRAY") { + $raw->[$i] =~ /^([^(]|\(.)(.*)/; + if ($1 eq ")") { + return $i; + } elsif (!defined($syntax->{$1})) { + $cooked->{$1} = $2 if !defined($cooked->{$1}); + $i++; + } elsif (ref $syntax->{$1} eq "ARRAY") { push @{$cooked->{$1}}, $2; $i++; } elsif (ref $syntax->{$1} eq "HASH") { my $block = {}; push @{$cooked->{$1}}, $block; - $i = do_parse_tree($raw, $i, $block, $syntax->{$1}); - } else { - $cooked->{$1} = $2 if !defined($cooked->{$1}); - $i++; + $i = do_parse_tree($raw, $i+1, $block, $syntax->{$1}); } } return $i;