From owner-freebsd-ports-bugs@FreeBSD.ORG Wed Jun 15 09:40:10 2011 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 397961065673 for ; Wed, 15 Jun 2011 09:40:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id DA3C28FC1A for ; Wed, 15 Jun 2011 09:40:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p5F9e9ne051594 for ; Wed, 15 Jun 2011 09:40:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p5F9e9EK051593; Wed, 15 Jun 2011 09:40:09 GMT (envelope-from gnats) Resent-Date: Wed, 15 Jun 2011 09:40:09 GMT Resent-Message-Id: <201106150940.p5F9e9EK051593@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Michael Osipov <1983-01-06@gmx.net> Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 94BBB1065670 for ; Wed, 15 Jun 2011 09:31:41 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 845168FC14 for ; Wed, 15 Jun 2011 09:31:41 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p5F9VfI9009136 for ; Wed, 15 Jun 2011 09:31:41 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p5F9VfZb009135; Wed, 15 Jun 2011 09:31:41 GMT (envelope-from nobody) Message-Id: <201106150931.p5F9VfZb009135@red.freebsd.org> Date: Wed, 15 Jun 2011 09:31:41 GMT From: Michael Osipov <1983-01-06@gmx.net> To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: ports/157899: Port 'p5-XML-XPath' xpath script missing quiet option X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2011 09:40:10 -0000 >Number: 157899 >Category: ports >Synopsis: Port 'p5-XML-XPath' xpath script missing quiet option >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jun 15 09:40:09 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Michael Osipov >Release: FreeBSD 8.2-STABLE >Organization: >Environment: FreeBSD blnn719x.ww004.siemens.net 8.2-STABLE FreeBSD 8.2-STABLE #11: Thu Apr 21 23:33:30 CEST 2011 root@blnn719x.ww004.siemens.net:/usr/obj/usr/src/sys/BLNN719X i386 >Description: I am used to use this under Ubuntu and it offers a few more options compared to the FreeBSD version. There are some but the most important is the '-q' switch. The regular output contains the XML element type which makes the output not valid XML. Quiet switch omits it. The ubuntu package is here: http://packages.ubuntu.com/natty/libxml-xpath-perl I have attached a patch from FreeBSD's script to Ubuntu's script. >How-To-Repeat: >Fix: Patch attached with submission follows: --- /usr/local/bin/xpath 2011-06-15 10:07:15.000000000 +0200 +++ /net/home/osipovmi/bin/xpath 2010-01-18 08:58:18.000000000 +0100 @@ -1,77 +1,118 @@ -#!/usr/local/bin/perl -w +#!/usr/bin/perl -w -eval 'exec /usr/local/bin/perl -w -S $0 ${1+"$@"}' +eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' + if 0; # not running under some shell + +eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell use strict; $| = 1; -unless (@ARGV >= 1) { - print STDERR qq(Usage: -$0 [filename] query - - If no filename is given, supply XML on STDIN. -); - exit; -} - use XML::XPath; -my $xpath; - +my @paths; my $pipeline; +my $SUFFIX = "\n"; +my $PREFIX = ""; +my $quiet = 0; -if ($ARGV[0] eq '-p') { - # pipeline mode - $pipeline = 1; - shift @ARGV; -} -if (@ARGV >= 2) { - $xpath = XML::XPath->new(filename => shift(@ARGV)); -} -else { - $xpath = XML::XPath->new(ioref => \*STDIN); + +PARSE: while ((@ARGV >= 1) && ($ARGV[0] =~ /^-./ )) { + OPTIONS: { + if ($ARGV[0] eq "-e") { + shift; + push @paths, shift; + last OPTIONS; + } + if ($ARGV[0] eq "-p") { + shift; + $PREFIX = shift; + last OPTIONS; + } + if ($ARGV[0] eq "-s") { + shift; + $SUFFIX = shift; + last OPTIONS; + } + if ($ARGV[0] eq "-q") { + $quiet = 1; + shift; + last OPTIONS; + } + print STDERR "Unknown option ignore: ", shift; + } } -my $nodes = $xpath->find(shift @ARGV); +unless (@paths >= 1) { + print STDERR qq(Usage: +$0 [options] -e query [-e query...] [filename...] -unless ($nodes->isa('XML::XPath::NodeSet')) { -NOTNODES: - print STDERR "Query didn't return a nodeset. Value: "; - print $nodes->value, "\n"; + If no filenams are given, supply XML on STDIN. + You must provide at least one query. Each supplementary + query is done in order, the previous query giving the + context of the next one. + + Options: + + -q quiet. Only output the resulting PATH + -s suffix use suffix instead of linefeed. + -p postfix use prefix instead of nothing. +); exit; } -if ($pipeline) { - $nodes = find_more($nodes); - goto NOTNODES unless $nodes->isa('XML::XPath::NodeSet'); -} +do +{ + my $xpath; + my @curpaths = @paths; + my $filename; + if (@ARGV >= 1) { + $filename = shift @ARGV; + $xpath = XML::XPath->new(filename => $filename); + } + else { + $filename = 'stdin'; + $xpath = XML::XPath->new(ioref => \*STDIN); + } -if ($nodes->size) { - print STDERR "Found ", $nodes->size, " nodes:\n"; - foreach my $node ($nodes->get_nodelist) { - print STDERR "-- NODE --\n"; - print $node->toString; + my $nodes = $xpath->find(shift @curpaths); + + if ($nodes->isa('XML::XPath::NodeSet')) { + while (@curpaths >= 1) { + $nodes = find_more($xpath, shift @curpaths, $nodes); + last unless $nodes->isa('XML::XPath::NodeSet'); + } + } + + if ($nodes->isa('XML::XPath::NodeSet')) { + if ($nodes->size) { + print STDERR "Found ", $nodes->size, " nodes in $filename:\n" unless $quiet; + foreach my $node ($nodes->get_nodelist) { + print STDERR "-- NODE --\n" unless $quiet; + print $PREFIX, $node->toString, $SUFFIX; + } + } + else { + print STDERR "No nodes found in $filename\n" unless $quiet; + } + } + else { + print STDERR "Query didn't return a nodeset. Value: "; + print $nodes->value, "\n"; } -} -else { - print STDERR "No nodes found"; -} -print STDERR "\n"; +} until (@ARGV < 1); exit; sub find_more { + my $xpath = shift; + my $find = shift; my ($nodes) = @_; - if (!@ARGV) { - return $nodes; - } my $newnodes = XML::XPath::NodeSet->new; - my $find = shift @ARGV; - foreach my $node ($nodes->get_nodelist) { my $new = $xpath->find($find, $node); if ($new->isa('XML::XPath::NodeSet')) { @@ -82,5 +123,83 @@ } } - return find_more($newnodes); + return $newnodes; } + +__END__ + +=head1 NAME + +xpath - a script to query XPath statements in XML documents. + +=head1 SYNOPSIS + +B + +=head1 DESCRIPTION + +B uses the L perl module to make XPath queries +to any XML document. The L module aims to comply exactly +to the XPath specification at C and yet +allows extensions to be added in the form of functions. + +The script takes any number of XPath pointers and tries to apply them +to each XML document given on the command line. If no file arguments +are given, the query is done using C as an XML document. + +When multiple queries exist, the result of the last query is used as +context for the next query and only the result of the last one is output. +The context of the first query is always the root of the current document. + +=head1 OPTIONS + +=head2 B<-q> + +Be quiet. Output only errors (and no separator) on stderr. + +=head2 B<-s suffix> + +Place C at the end of each entry. Default is a linefeed. + +=head2 B<-p prefix> + +Place C preceding each entry. Default is nothing. + +=head1 BUGS + +The author of this man page is not very fluant in english. Please, +send him (L) any corrections concerning this text. + +See also L. + +=head1 SEE ALSO + +L. + +=head1 HISTORY + +This module is copyright 2000 Fastnet Software Ltd. This is free +software, and as such comes with NO WARRANTY. No dates are used in this +module. You may distribute this module under the terms of either the +Gnu GPL, or under specific licencing from Fastnet Software Ltd. +Special free licencing consideration will be given to similarly free +software. Please don't flame me for this licence - I've put a lot of +hours into this code, and if someone uses my software in their product +I expect them to have the courtesy to contact me first. + +Full support for this module is available from Fastnet Software Ltd on +a pay per incident basis. Alternatively subscribe to the Perl-XML +mailing list by mailing lyris@activestate.com with the text: + + SUBSCRIBE Perl-XML + +in the body of the message. There are lots of friendly people on the +list, including myself, and we'll be glad to get you started. + +Matt Sergeant, matt@sergeant.org + +This man page was added as well as some serious modifications to the script +by Fabien Ninoles for the Debian Project. + +=cut + >Release-Note: >Audit-Trail: >Unformatted: