1if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1 2# 3# Copyright (c) 2013 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/index.subr 252745 2013-07-05 01:44:59Z dteske $ |
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." packages/index.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/media/common.subr --- 201 unchanged lines hidden (view full) --- 237 printf "%s%s", ( n > 1 ? "'\''\n" : "" ), 238 var_basename "_" ++page "='\''" 239 printf "%s%s", ( starting_new_page ? "" : "\n" ), $0 240 } 241 END { if ( n > 0 ) print "'\''" }' 242 )" 243} 244 |
245# f_index_search $var_to_get $name [$var_to_set] 246# 247# Search the package INDEX ($PACKAGE_INDEX by default if/when $var_to)get is 248# NULL; but should not be missing) for $name, returning the first match. 249# Matches are strict (not regular expressions) and must match the beginning 250# portion of the package name to be considered a match. If $var_to_set is 251# missing or NULL, output is sent to standard output. If a match is found, 252# returns success; otherwise failure. 253# 254f_index_search() 255{ 256 local __var_to_get="${1:-PACKAGE_INDEX}" __pkg_basename="$2" 257 local __var_to_set="$3" 258 259 f_dprintf "f_index_search: Searching package data (in %s) for %s" \ 260 "$__var_to_get" "$__pkg_basename" 261 262 local __pkg= 263 __pkg=$( debug= f_getvar "$__var_to_get" | 264 awk -F'|' -v basename="$__pkg_basename" ' 265 BEGIN { n = length(basename) } 266 substr($1, 0, n) == basename { print $1; exit } 267 ' ) 268 if [ ! "$__pkg" ]; then 269 f_dprintf "f_index_search: No packages matching %s found" \ 270 "$__pkg_basename" 271 return $FAILURE 272 fi 273 274 f_dprintf "f_index_search: Found package %s" "$__pkg" 275 if [ "$__var_to_set" ]; then 276 setvar "$__var_to_set" "$__pkg" 277 else 278 echo "$__pkg" 279 fi 280 return $SUCCESS 281} 282 |
283############################################################ MAIN 284 285f_dprintf "%s: Successfully loaded." packages/index.subr 286 287fi # ! $_PACKAGES_INDEX_SUBR |