categories.subr revision 250539
13447SN/Aif [ ! "$_PACKAGES_CATEGORIES_SUBR" ]; then _PACKAGES_CATEGORIES_SUBR=1
23447SN/A#
33447SN/A# Copyright (c) 2013 Devin Teske
43447SN/A# All Rights Reserved.
53447SN/A#
63447SN/A# Redistribution and use in source and binary forms, with or without
73447SN/A# modification, are permitted provided that the following conditions
83447SN/A# are met:
93447SN/A# 1. Redistributions of source code must retain the above copyright
103447SN/A#    notice, this list of conditions and the following disclaimer.
113447SN/A# 2. Redistributions in binary form must reproduce the above copyright
123447SN/A#    notice, this list of conditions and the following disclaimer in the
133447SN/A#    documentation and/or other materials provided with the distribution.
143447SN/A#
153447SN/A# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
163447SN/A# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
173447SN/A# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
183447SN/A# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
193447SN/A# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
203447SN/A# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
213447SN/A# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
223447SN/A# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
233447SN/A# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
243447SN/A# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
253447SN/A# SUCH DAMAGE.
263447SN/A#
273447SN/A# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/categories.subr 250539 2013-05-12 00:50:18Z dteske $
283447SN/A#
2911707Stpivovarova############################################################ INCLUDES
3011707Stpivovarova
3111707StpivovarovaBSDCFG_SHARE="/usr/share/bsdconfig"
323447SN/A. $BSDCFG_SHARE/common.subr || exit 1
333447SN/Af_dprintf "%s: loading includes..." packages/categories.subr
3411707Stpivovarovaf_include $BSDCFG_SHARE/strings.subr
3511707Stpivovarova
363447SN/ABSDCFG_LIBE="/usr/libexec/bsdconfig"
373447SN/Af_include_lang $BSDCFG_LIBE/include/messages.subr
383447SN/A
393447SN/A############################################################ GLOBALS
403447SN/A
413447SN/ACATEGORIES=
423447SN/A
433447SN/A############################################################ FUNCTIONS
443447SN/A
453447SN/A# f_category_desc_get $category [$var_to_set]
463447SN/A#
473447SN/A# Fetch the description of a given category. Returns success if a match was
483447SN/A# found, otherwise failure.
493447SN/A#
503447SN/A# If $var_to_set is missing or NULL, the category description is printed to
513447SN/A# standard out for capturing in a sub-shell (which is less-recommended because
523447SN/A# of performance degredation; for example, when called in a loop).
533447SN/A#
543447SN/Af_category_desc_get()
553447SN/A{
563447SN/A	local __category="$1" __var_to_set="$2" __cat __varcat
573447SN/A
583447SN/A	# Return failure if $category
593447SN/A	[ "$__category" ] || return $FAILURE
603447SN/A
613447SN/A	for __cat in $CATEGORIES; do
623447SN/A		[ "$__cat" = "$__category" ] || continue
633447SN/A		f_str2varname $__cat __varcat
643447SN/A		f_getvar _category_$__varcat $__var_to_set
653447SN/A		return $?
663447SN/A	done
673447SN/A	return $FAILURE
683447SN/A}
693447SN/A
703447SN/A# f_category_desc_set $category $desc
713447SN/A#
723447SN/A# Store a description in-association with a category. $category should be
733447SN/A# alphanumeric and can include the underscore [_] but should not contain
743447SN/A# whitespace. Returns success unless $category is NULL or no arguments. Use the
753447SN/A# f_category_desc_get() routine with the same $category to retrieve the stored
763447SN/A# description.
773447SN/A#
783447SN/Af_category_desc_set()
793447SN/A{
803447SN/A	local category="$1" desc="$2"
813447SN/A	local cat varcat found=
823447SN/A	[ "$category" ] || return $FAILURE
833447SN/A	for cat in $CATEGORIES; do
843447SN/A		[ "$cat" = "$category" ] || continue
853447SN/A		f_str2varname $cat varcat
863447SN/A		f_quietly f_getvar _category_$varcat || continue
873447SN/A		found=1 && break
883447SN/A	done
893447SN/A	if [ ! "$found" ]; then
903447SN/A		CATEGORIES="$CATEGORIES $category"
913447SN/A	fi
923447SN/A	f_str2varname $category varcat
933447SN/A	setvar "_category_$varcat" "$desc"
943447SN/A	# Export the variable for awk(1) ENVIRON visibility
953447SN/A	export "_category_$varcat"
963447SN/A	return $SUCCESS
973447SN/A}
983447SN/A
993447SN/A############################################################ MAIN
1003447SN/A
1013447SN/A#
1023447SN/A# Load descriptions for package categories. Note that we don't internationalize
1033447SN/A# category names because this would be confusing for people used to browsing
1043447SN/A# the FTP mirrors or are otherwise familiar with an interface that does not
1053447SN/A# provide internationalized names. The descriptions can be used to provide i18n
1063447SN/A# users a description of the non-i18n category name.
1073447SN/A#
1083447SN/Af_category() { f_category_desc_set "$1" "$2"; }
1093447SN/Af_category All           "$msg_all_desc"
1103447SN/Af_category accessibility "$msg_accessibility_desc"
1113447SN/Af_category afterstep     "$msg_afterstep_desc"
1123447SN/Af_category arabic        "$msg_arabic_desc"
1133447SN/Af_category archivers     "$msg_archivers_desc"
1143447SN/Af_category astro         "$msg_astro_desc"
1153447SN/Af_category audio         "$msg_audio_desc"
1163447SN/Af_category benchmarks    "$msg_benchmarks_desc"
1173447SN/Af_category biology       "$msg_biology_desc"
1183447SN/Af_category cad           "$msg_cad_desc"
1193447SN/Af_category chinese       "$msg_chinese_desc"
1203447SN/Af_category comms         "$msg_comms_desc"
1213447SN/Af_category converters    "$msg_converters_desc"
1223447SN/Af_category databases     "$msg_databases_desc"
1233447SN/Af_category deskutils     "$msg_deskutils_desc"
1243447SN/Af_category devel         "$msg_devel_desc"
1253447SN/Af_category dns           "$msg_dns_desc"
1263447SN/Af_category docs          "$msg_docs_desc"
1273447SN/Af_category editors       "$msg_editors_desc"
1283447SN/Af_category elisp         "$msg_elisp_desc"
1293447SN/Af_category emulators     "$msg_emulators_desc"
1303447SN/Af_category enlightenment "$msg_enlightenment_desc"
1313447SN/Af_category finance       "$msg_finance_desc"
1323447SN/Af_category french        "$msg_french_desc"
1333447SN/Af_category ftp           "$msg_ftp_desc"
1343447SN/Af_category games         "$msg_games_desc"
1353447SN/Af_category geography     "$msg_geography_desc"
1363447SN/Af_category german        "$msg_german_desc"
1373447SN/Af_category gnome         "$msg_gnome_desc"
1383447SN/Af_category gnustep       "$msg_gnustep_desc"
1393447SN/Af_category graphics      "$msg_graphics_desc"
1403447SN/Af_category hamradio      "$msg_hamradio_desc"
1413447SN/Af_category haskell       "$msg_haskell_desc"
1423447SN/Af_category hebrew        "$msg_hebrew_desc"
1433447SN/Af_category hungarian     "$msg_hungarian_desc"
1443447SN/Af_category ipv6          "$msg_ipv6_desc"
1453447SN/Af_category irc           "$msg_irc_desc"
1463447SN/Af_category japanese      "$msg_japanese_desc"
1473447SN/Af_category java          "$msg_java_desc"
1483447SN/Af_category kde           "$msg_kde_desc"
1493447SN/Af_category kld           "$msg_kld_desc"
1503447SN/Af_category korean        "$msg_korean_desc"
1513447SN/Af_category lang          "$msg_lang_desc"
1523447SN/Af_category linux         "$msg_linux_desc"
1533447SN/Af_category lisp          "$msg_lisp_desc"
1543447SN/Af_category mail          "$msg_mail_desc"
1553447SN/Af_category math          "$msg_math_desc"
1563447SN/Af_category mbone         "$msg_mbone_desc"
1573447SN/Af_category misc          "$msg_misc_desc"
1583447SN/Af_category multimedia    "$msg_multimedia_desc"
1593447SN/Af_category net           "$msg_net_desc"
1603447SN/Af_category net-im        "$msg_net_im_desc"
1613447SN/Af_category net-mgmt      "$msg_net_mgmt_desc"
1623447SN/Af_category net-p2p       "$msg_net_p2p_desc"
1633447SN/Af_category news          "$msg_news_desc"
1643447SN/Af_category palm          "$msg_palm_desc"
1653447SN/Af_category parallel      "$msg_parallel_desc"
1663447SN/Af_category pear          "$msg_pear_desc"
1673447SN/Af_category perl5         "$msg_perl5_desc"
1683447SN/Af_category plan9         "$msg_plan9_desc"
1693447SN/Af_category polish        "$msg_polish_desc"
1703447SN/Af_category ports-mgmt    "$msg_ports_mgmt_desc"
1713447SN/Af_category portuguese    "$msg_portuguese_desc"
1723447SN/Af_category print         "$msg_print_desc"
1733447SN/Af_category python        "$msg_python_desc"
1743447SN/Af_category ruby          "$msg_ruby_desc"
1753447SN/Af_category rubygems      "$msg_rubygems_desc"
1763447SN/Af_category russian       "$msg_russian_desc"
1773447SN/Af_category scheme        "$msg_scheme_desc"
1783447SN/Af_category science       "$msg_science_desc"
1793447SN/Af_category security      "$msg_security_desc"
1803447SN/Af_category shells        "$msg_shells_desc"
1813447SN/Af_category spanish       "$msg_spanish_desc"
1823447SN/Af_category sysutils      "$msg_sysutils_desc"
1833447SN/Af_category tcl           "$msg_tcl_desc"
1843447SN/Af_category textproc      "$msg_textproc_desc"
1853447SN/Af_category tk            "$msg_tk_desc"
1863447SN/Af_category ukrainian     "$msg_ukrainian_desc"
1873447SN/Af_category vietnamese    "$msg_vietnamese_desc"
1883447SN/Af_category windowmaker   "$msg_windowmaker_desc"
1893447SN/Af_category www           "$msg_www_desc"
1903447SN/Af_category x11           "$msg_x11_desc"
1913447SN/Af_category x11-clocks    "$msg_x11_clocks_desc"
1923447SN/Af_category x11-drivers   "$msg_x11_drivers_desc"
1933447SN/Af_category x11-fm        "$msg_x11_fm_desc"
1943447SN/Af_category x11-fonts     "$msg_x11_fonts_desc"
1953447SN/Af_category x11-servers   "$msg_x11_servers_desc"
1963447SN/Af_category x11-themes    "$msg_x11_themes_desc"
1973447SN/Af_category x11-toolkits  "$msg_x11_toolkits_desc"
1983447SN/Af_category x11-wm        "$msg_x11_wm_desc"
1993447SN/Af_category xfce          "$msg_xfce_desc"
2003447SN/Af_category zope          "$msg_zope_desc"
2013447SN/A
2023447SN/Af_dprintf "%s: Initialized %u package category descriptions." \
2033447SN/A          packages/categories.subr "$( set -- $CATEGORIES; echo $# )"
2043447SN/A
2053447SN/Af_dprintf "%s: Successfully loaded." packages/categories.subr
2063447SN/A
2073447SN/Afi # ! $_PACKAGES_CATEGORIES_SUBR
2083447SN/A