| 1565 | | set flags [lrange $source 1 end] |
| 1566 | | set source [lindex $source 0] |
| 1567 | | if {[macports::getprotocol $source] == "mports"} { |
| 1568 | | array set attrs [list name $pattern] |
| 1569 | | set res [macports::index::search $macports::portdbpath $source [array get attrs]] |
| 1570 | | eval lappend matches $res |
| 1571 | | } else { |
| 1572 | | if {[catch {set fd [open [macports::getindex $source] r]} result]} { |
| 1573 | | ui_warn "Can't open index file for source: $source" |
| | 1563 | set sourceURL [lindex $source 0] |
| | 1564 | if {[macports::getprotocol $sourceURL] != "mports"} { |
| | 1565 | if {[catch {set fd [open [macports::getindex $sourceURL] r]} result]} { |
| | 1566 | ui_warn "Can't open index file for source $sourceURL" |
| 1582 | | |
| 1583 | | if {$easy} { |
| 1584 | | set target $name |
| 1585 | | } else { |
| 1586 | | array set portinfo $line |
| 1587 | | if {![info exists portinfo($field)]} continue |
| 1588 | | set target $portinfo($field) |
| 1589 | | } |
| 1590 | | |
| 1591 | | switch $matchstyle { |
| 1592 | | exact { |
| 1593 | | set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )] |
| 1594 | | } |
| 1595 | | glob { |
| 1596 | | set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]] |
| 1597 | | } |
| 1598 | | regexp - |
| 1599 | | default { |
| 1600 | | set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]] |
| 1601 | | } |
| 1602 | | } |
| 1603 | | |
| 1604 | | if {$matchres == 1} { |
| 1605 | | if {$easy} { |
| 1606 | | array set portinfo $line |
| 1607 | | } |
| 1608 | | switch -regexp -- [macports::getprotocol ${source}] { |
| 1609 | | {^rsync$} { |
| 1610 | | # Rsync files are local |
| 1611 | | set source_url "file://[macports::getsourcepath $source]" |
| 1612 | | } |
| 1613 | | {^https?$|^ftp$} { |
| 1614 | | if {[_source_is_snapshot $source filename extension]} { |
| 1615 | | # daily snapshot tarball |
| 1616 | | set source_url "file://[macports::getsourcepath $source]" |
| 1617 | | } else { |
| 1618 | | # default action |
| 1619 | | set source_url $source |
| 1620 | | } |
| 1621 | | } |
| 1622 | | default { |
| 1623 | | set source_url $source |
| 1624 | | } |
| 1625 | | } |
| 1626 | | if {[info exists portinfo(portarchive)]} { |
| 1627 | | set porturl ${source_url}/$portinfo(portarchive) |
| 1628 | | } elseif {[info exists portinfo(portdir)]} { |
| 1629 | | set porturl ${source_url}/$portinfo(portdir) |
| 1630 | | } |
| 1631 | | if {[info exists porturl]} { |
| 1632 | | lappend line porturl $porturl |
| 1633 | | ui_debug "Found port in $porturl" |
| 1634 | | } else { |
| 1635 | | ui_debug "Found port info: $line" |
| 1636 | | } |
| 1637 | | lappend matches $name |
| 1638 | | lappend matches $line |
| 1639 | | } |
| | 1574 | set macports::mportsearch_portindex([list $sourceURL $name]) $line |
| | 1589 | } |
| | 1590 | |
| | 1591 | proc mportsearch {pattern {case_sensitive yes} {matchstyle regexp} {field name}} { |
| | 1592 | global macports::mportsearch_portindex |
| | 1593 | if {![array exists macports::mportsearch_portindex]} { |
| | 1594 | mportsearch_load_portindex |
| | 1595 | } |
| | 1596 | |
| | 1597 | set matches [list] |
| | 1598 | set easy [expr { $field == "name" }] |
| | 1599 | |
| | 1600 | foreach {port_url_and_name line} [array get macports::mportsearch_portindex] { |
| | 1601 | array unset portinfo |
| | 1602 | set source [lindex $port_url_and_name 0] |
| | 1603 | set name [lindex $port_url_and_name 1] |
| | 1604 | if {$easy} { |
| | 1605 | set target $name |
| | 1606 | } else { |
| | 1607 | array set portinfo $line |
| | 1608 | if {![info exists portinfo($field)]} continue |
| | 1609 | set target $portinfo($field) |
| | 1610 | } |
| | 1611 | |
| | 1612 | switch $matchstyle { |
| | 1613 | exact { |
| | 1614 | set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )] |
| | 1615 | } |
| | 1616 | glob { |
| | 1617 | set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]] |
| | 1618 | } |
| | 1619 | regexp - |
| | 1620 | default { |
| | 1621 | set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]] |
| | 1622 | } |
| | 1623 | } |
| | 1624 | |
| | 1625 | if {$matchres == 1} { |
| | 1626 | if {$easy} { |
| | 1627 | array set portinfo $line |
| | 1628 | } |
| | 1629 | switch -regexp -- [macports::getprotocol ${source}] { |
| | 1630 | {^rsync$} { |
| | 1631 | # Rsync files are local |
| | 1632 | set source_url "file://[macports::getsourcepath $source]" |
| | 1633 | } |
| | 1634 | {^https?$|^ftp$} { |
| | 1635 | if {[_source_is_snapshot $source filename extension]} { |
| | 1636 | # daily snapshot tarball |
| | 1637 | set source_url "file://[macports::getsourcepath $source]" |
| | 1638 | } else { |
| | 1639 | # default action |
| | 1640 | set source_url $source |
| | 1641 | } |
| | 1642 | } |
| | 1643 | default { |
| | 1644 | set source_url $source |
| | 1645 | } |
| | 1646 | } |
| | 1647 | if {[info exists portinfo(portarchive)]} { |
| | 1648 | set porturl ${source_url}/$portinfo(portarchive) |
| | 1649 | } elseif {[info exists portinfo(portdir)]} { |
| | 1650 | set porturl ${source_url}/$portinfo(portdir) |
| | 1651 | } |
| | 1652 | if {[info exists porturl]} { |
| | 1653 | lappend line porturl $porturl |
| | 1654 | ui_debug "Found port in $porturl" |
| | 1655 | } else { |
| | 1656 | ui_debug "Found port info: $line" |
| | 1657 | } |
| | 1658 | lappend matches $name |
| | 1659 | lappend matches $line |
| | 1660 | } |
| | 1661 | } |