head	1.7;
access;
symbols
	RELEASE_2_4_6:1.5
	RELEASE_2_4_5:1.5
	RELEASE_2_4_3:1.5
	RELEASE_2_4_2:1.5
	RELEASE_2_4_1:1.5
	RELEASE_2_4_0:1.5
	RELEASE_2_3_2:1.5
	RELEASE_2_3_1:1.4
	STABLE_2_3:1.4.0.2
	RELEASE_2_3_0:1.4
	RELEASE_2_2_6:1.3.2.1
	RELEASE_2_2_5:1.3.2.1
	RELEASE_2_2_4:1.4
	RELEASE_2_2_3:1.3.2.1
	STABLE_2_2:1.3.0.2
	RELEASE_2_2_2:1.3
	RELEASE_2_2_1:1.3
	RELEASE_2_2_0:1.3
	RELEASE_2_1_3_3:1.1.1.1
	RELEASE_2_1_7:1.3
	RELEASE_2_1_6:1.2
	RELEASE_2_1_3_2:1.1.1.1
	RELEASE_2_1_5:1.2
	RELEASE_2_1_3_1:1.1.1.1.0.4
	STABLE:1.1.1.1.0.2
	PKGTOOLS_2_1_4:1.2
	PKGTOOLS_2_1_3:1.1.1.1
	sem:1.1.1;
locks; strict;
comment	@# @;


1.7
date	2011.08.19.00.57.22;	author stas;	state dead;
branches;
next	1.6;

1.6
date	2008.07.17.00.26.38;	author sem;	state Exp;
branches;
next	1.5;

1.5
date	2008.01.08.11.32.27;	author sem;	state Exp;
branches;
next	1.4;

1.4
date	2007.02.22.13.36.34;	author sem;	state Exp;
branches;
next	1.3;

1.3
date	2006.08.13.11.15.21;	author sem;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2006.06.14.11.52.38;	author sem;	state Exp;
branches;
next	1.1;

1.1
date	2006.06.13.12.59.01;	author sem;	state Exp;
branches
	1.1.1.1;
next	;

1.3.2.1
date	2007.02.22.14.00.37;	author sem;	state Exp;
branches;
next	;

1.1.1.1
date	2006.06.13.12.59.01;	author sem;	state Exp;
branches;
next	;


desc
@@


1.7
log
@- The project data has moved to github (https://github.com/stass/pkgtools).
@
text
@#!/usr/bin/env ruby
# -*- ruby -*-
#
# Copyright (c) 2000-2004 Akinori MUSHA
# Copyright (c) 2006-2008 Sergey Matveychuk <sem@@FreeBSD.org>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

MYREVISION = %w$Rev: 52 $[1]
MYDATE = %w$Date: 2008/01/08 11:32:27 $[1]
MYNAME = File.basename($0)

require "optparse"
require "pkgtools"

COLUMNSIZE = 24
NEXTLINE = "\n%*s" % [5 + COLUMNSIZE, '']

def init_global
  $exclude_ports = []
  $fetch_index = false
  $force = false
  $master_recursive = false
  $noconfig = false
  $recursive = false
  #$sanity_check = true
  #$slave_recursive = false
  $tempdir = ""
  $update_db = false
  $update_index = false
  $upward_recursive = false
end

def main(argv)
  usage = <<-"EOF"
usage: #{MYNAME} [-hfFMqrRuU] [-x port_glob] [port_glob ...]
    EOF

  banner = <<-"EOF"
#{MYNAME} #{Version} (#{MYDATE})

#{usage}
  EOF

  dry_parse = true

  OptionParser.new(banner, COLUMNSIZE) do |opts|
    opts.def_option("-h", "--help", "Show this message") {
      print opts
      exit 0
    }

    opts.def_option("-f", "--force", "Force to update database regardless of timestamps") { |v|
      $force = v
    }

    opts.def_option("-F", "--fetchindex", "Fetch INDEX") { |b|
      $update_index = $fetch_index = b
    }

    opts.def_option("-M", "--master-recursive", "List all the master ports of the given packages#{NEXTLINE}as well") { |v|
      $master_recursive = v
    }

#    opts.def_option("-O", "--omit-check", "Omit sanity checks for dependencies.") {
#      $sanity_check = false
#    }

    opts.def_option("-q", "--noconfig", "Do not read pkgtools.conf") { |v|
      $noconfig = v
    }

    opts.def_option("-r", "--recursive", "List all those depending on the given packages#{NEXTLINE}as well") { |v|
      $recursive = v
    }

    opts.def_option("-R", "--upward-recursive", "List all those required by the given packages#{NEXTLINE}as well") { |v|
      $upward_recursive = v
    }

#    opts.def_option("-S", "--slave-recursive", "List all the slave ports of the given packages#{NEXTLINE}as well") { |v|
#      $slave_recursive = v
#    }

    opts.def_option("-u", "--update", "Update INDEX.db") { |v|
      $update_db = v
    }

    opts.def_option("-U", "--updateindex", "Update INDEX") { |v|
      $update_index = v
    }

    opts.def_option("-x", "--exclude=GLOB", "Exclude ports matching the specified glob#{NEXTLINE}pattern") { |arg|
      begin
	pattern = parse_pattern(arg)
      rescue RegexpError => e
	warning_message e.message.capitalize
	break
      end

      $exclude_ports |= $portsdb.glob(pattern).collect { |portinfo| portinfo.origin }
    }

    opts.def_tail_option '
If a port_glob is specified, the ports matching the pattern are listed.
A pattern can be either in the pkgname from or in the origin form including
a slash (\'/\'), and in which you can use wildcards *, ?, and [..],
or an extended regular expression preceded by a colon (:).

Environment Variables [default]:
    PKGTOOLS_CONF            configuration file [$PREFIX/etc/pkgtools.conf]
    PORTSDIR                 ports directory [/usr/ports]
    PORTS_DBDIR              ports db directory [$PORTSDIR]
    PORTS_INDEX              ports index file [$PORTSDIR/INDEX]'

    if argv.empty?
      print opts
      return 0
    end

    begin
      init_global
      init_pkgtools_global

      rest = opts.order(*argv)

      unless $noconfig
	load_config
      else
	argv = rest
      end

      dry_parse = false

      opts.order!(argv)

      if $update_index
	$portsdb.update($fetch_index)
      end

      if $update_db
	$portsdb.update_db($force)
      end

      list = []
      
      opts.order(*argv) do |arg|
	pattern = $portsdb.strip(arg) || arg	# allow pkgname_glob

	begin
	  pattern = parse_pattern(pattern)
	rescue RegexpError => e
	  warning_message e.message.capitalize
	  next
	end

	$portsdb.glob(pattern) do |portinfo|
	  list |= $portsdb.recurse(portinfo, $recursive, $upward_recursive)
	end
      end

      ports = []

      list.each do |portinfo|
	if $master_recursive
	  if masters = portinfo.masters
	    masters.each do |master|
	      ports << $portsdb.origin(master)
	    end
	  end
	end

        ports << portinfo.origin
      end

      ports -= $exclude_ports

      $portsdb.sort!(ports)

      puts(*ports) unless ports.empty?
    rescue OptionParser::ParseError => e
      STDERR.puts "#{MYNAME}: #{e}", usage
      exit 64
    rescue => e
      STDERR.puts "#{MYNAME}: #{e}"
      exit 1
    end
  end

  0
end

if $0 == __FILE__
  set_signal_handlers

  exit(main(ARGV) || 1)
end
@


1.6
log
@Adapt to ruby 1.9
@
text
@@


1.5
log
@New year in COPYRIGHTS
@
text
@d32 1
a32 1
MYDATE = %w$Date: 2007/02/22 13:36:34 $[1]
d75 2
a76 2
    opts.def_option("-f", "--force", "Force to update database regardless of timestamps") {
      |$force|
d79 1
a79 2
    opts.def_option("-F", "--fetchindex", "Fetch INDEX") {
      |b|
d83 2
a84 2
    opts.def_option("-M", "--master-recursive", "List all the master ports of the given packages#{NEXTLINE}as well") {
      |$master_recursive|
d91 2
a92 2
    opts.def_option("-q", "--noconfig", "Do not read pkgtools.conf") {
      |$noconfig|
d95 2
a96 2
    opts.def_option("-r", "--recursive", "List all those depending on the given packages#{NEXTLINE}as well") {
      |$recursive|
d99 2
a100 2
    opts.def_option("-R", "--upward-recursive", "List all those required by the given packages#{NEXTLINE}as well") {
      |$upward_recursive|
d103 2
a104 2
#    opts.def_option("-S", "--slave-recursive", "List all the slave ports of the given packages#{NEXTLINE}as well") {
#      |$slave_recursive|
d107 2
a108 2
    opts.def_option("-u", "--update", "Update INDEX.db") {
      |$update_db|
d111 2
a112 2
    opts.def_option("-U", "--updateindex", "Update INDEX") {
      |$update_index|
d115 1
a115 2
    opts.def_option("-x", "--exclude=GLOB", "Exclude ports matching the specified glob#{NEXTLINE}pattern") {
      |arg|
@


1.4
log
@Update COPYRIGHTS
@
text
@d5 1
a5 1
# Copyright (c) 2006,2007 Sergey Matveychuk <sem@@FreeBSD.org>
d32 1
a32 1
MYDATE = %w$Date: 2006/08/13 11:15:21 $[1]
@


1.3
log
@Adjust Copyright notices
@
text
@d5 1
a5 1
# Copyright (c) 2006 Sergey Matveychuk <sem@@FreeBSD.org>
d32 1
a32 1
MYDATE = %w$Date: 2006/06/14 11:52:38 $[1]
@


1.3.2.1
log
@Merge patches from HEAD
@
text
@d5 1
a5 1
# Copyright (c) 2006,2007 Sergey Matveychuk <sem@@FreeBSD.org>
d32 1
a32 1
MYDATE = %w$Date: 2007/02/22 13:36:34 $[1]
@


1.2
log
@- Refactoring:
  * Get rid of warnings with ruby --debug
  * Rework ugly init_pkgtools_global call. Now it's more consistent.
@
text
@d5 1
d32 1
a32 1
MYDATE = %w$Date: 2006/06/13 12:59:01 $[1]
@


1.1
log
@Initial revision
@
text
@d31 1
a31 1
MYDATE = %w$Date: 2006-01-01 15:26:59 +0900 (Sun, 01 Jan 2006) $[1]
d49 1
d146 1
a150 1
	init_global
@


1.1.1.1
log
@Initial import
@
text
@@
