xref: /freebsd/usr.sbin/bsdconfig/share/packages/categories.subr (revision d8a0fe102c0cfdfcd5b818f850eff09d8536c9bc)
1if [ ! "$_PACKAGES_CATEGORIES_SUBR" ]; then _PACKAGES_CATEGORIES_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:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, 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$
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." packages/categories.subr
34f_include $BSDCFG_SHARE/strings.subr
35
36BSDCFG_LIBE="/usr/libexec/bsdconfig"
37f_include_lang $BSDCFG_LIBE/include/messages.subr
38
39############################################################ GLOBALS
40
41CATEGORIES=
42NCATEGORIES=0
43
44############################################################ FUNCTIONS
45
46# f_category_desc_get $category [$var_to_set]
47#
48# Fetch the description of a given category. Returns success if a match was
49# found, otherwise failure.
50#
51# If $var_to_set is missing or NULL, the category description is printed to
52# standard out for capturing in a sub-shell (which is less-recommended because
53# of performance degredation; for example, when called in a loop).
54#
55f_category_desc_get()
56{
57	local __category="$1" __var_to_set="$2" __cat __varcat
58
59	# Return failure if $category
60	[ "$__category" ] || return $FAILURE
61
62	for __cat in $CATEGORIES; do
63		[ "$__cat" = "$__category" ] || continue
64		f_str2varname $__cat __varcat
65		f_getvar _category_$__varcat $__var_to_set
66		return $?
67	done
68	return $FAILURE
69}
70
71# f_category_desc_set $category $desc
72#
73# Store a description in-association with a category. $category should be
74# alphanumeric and can include the underscore [_] but should not contain
75# whitespace. Returns success unless $category is NULL or no arguments. Use the
76# f_category_desc_get() routine with the same $category to retrieve the stored
77# description.
78#
79f_category_desc_set()
80{
81	local category="$1" desc="$2"
82	local cat varcat found=
83	[ "$category" ] || return $FAILURE
84	for cat in $CATEGORIES; do
85		[ "$cat" = "$category" ] || continue
86		f_str2varname $cat varcat
87		f_isset _category_$varcat || continue
88		found=1 && break
89	done
90	if [ ! "$found" ]; then
91		CATEGORIES="$CATEGORIES $category"
92	fi
93	f_str2varname $category varcat
94	setvar "_category_$varcat" "$desc"
95	# Export the variable for awk(1) ENVIRON visibility
96	export "_category_$varcat"
97	return $SUCCESS
98}
99
100############################################################ MAIN
101
102#
103# Load descriptions for package categories. Note that we don't internationalize
104# category names because this would be confusing for people used to browsing
105# the FTP mirrors or are otherwise familiar with an interface that does not
106# provide internationalized names. The descriptions can be used to provide i18n
107# users a description of the non-i18n category name.
108#
109f_category() { f_category_desc_set "$1" "$2"; }
110f_category All           "$msg_all_desc"
111f_category accessibility "$msg_accessibility_desc"
112f_category afterstep     "$msg_afterstep_desc"
113f_category arabic        "$msg_arabic_desc"
114f_category archivers     "$msg_archivers_desc"
115f_category astro         "$msg_astro_desc"
116f_category audio         "$msg_audio_desc"
117f_category benchmarks    "$msg_benchmarks_desc"
118f_category biology       "$msg_biology_desc"
119f_category cad           "$msg_cad_desc"
120f_category chinese       "$msg_chinese_desc"
121f_category comms         "$msg_comms_desc"
122f_category converters    "$msg_converters_desc"
123f_category databases     "$msg_databases_desc"
124f_category deskutils     "$msg_deskutils_desc"
125f_category devel         "$msg_devel_desc"
126f_category dns           "$msg_dns_desc"
127f_category docs          "$msg_docs_desc"
128f_category editors       "$msg_editors_desc"
129f_category elisp         "$msg_elisp_desc"
130f_category emulators     "$msg_emulators_desc"
131f_category enlightenment "$msg_enlightenment_desc"
132f_category finance       "$msg_finance_desc"
133f_category french        "$msg_french_desc"
134f_category ftp           "$msg_ftp_desc"
135f_category games         "$msg_games_desc"
136f_category geography     "$msg_geography_desc"
137f_category german        "$msg_german_desc"
138f_category gnome         "$msg_gnome_desc"
139f_category gnustep       "$msg_gnustep_desc"
140f_category graphics      "$msg_graphics_desc"
141f_category hamradio      "$msg_hamradio_desc"
142f_category haskell       "$msg_haskell_desc"
143f_category hebrew        "$msg_hebrew_desc"
144f_category hungarian     "$msg_hungarian_desc"
145f_category ipv6          "$msg_ipv6_desc"
146f_category irc           "$msg_irc_desc"
147f_category japanese      "$msg_japanese_desc"
148f_category java          "$msg_java_desc"
149f_category kde           "$msg_kde_desc"
150f_category kld           "$msg_kld_desc"
151f_category korean        "$msg_korean_desc"
152f_category lang          "$msg_lang_desc"
153f_category linux         "$msg_linux_desc"
154f_category lisp          "$msg_lisp_desc"
155f_category mail          "$msg_mail_desc"
156f_category math          "$msg_math_desc"
157f_category mbone         "$msg_mbone_desc"
158f_category misc          "$msg_misc_desc"
159f_category multimedia    "$msg_multimedia_desc"
160f_category net           "$msg_net_desc"
161f_category net-im        "$msg_net_im_desc"
162f_category net-mgmt      "$msg_net_mgmt_desc"
163f_category net-p2p       "$msg_net_p2p_desc"
164f_category news          "$msg_news_desc"
165f_category palm          "$msg_palm_desc"
166f_category parallel      "$msg_parallel_desc"
167f_category pear          "$msg_pear_desc"
168f_category perl5         "$msg_perl5_desc"
169f_category plan9         "$msg_plan9_desc"
170f_category polish        "$msg_polish_desc"
171f_category ports-mgmt    "$msg_ports_mgmt_desc"
172f_category portuguese    "$msg_portuguese_desc"
173f_category print         "$msg_print_desc"
174f_category python        "$msg_python_desc"
175f_category ruby          "$msg_ruby_desc"
176f_category rubygems      "$msg_rubygems_desc"
177f_category russian       "$msg_russian_desc"
178f_category scheme        "$msg_scheme_desc"
179f_category science       "$msg_science_desc"
180f_category security      "$msg_security_desc"
181f_category shells        "$msg_shells_desc"
182f_category spanish       "$msg_spanish_desc"
183f_category sysutils      "$msg_sysutils_desc"
184f_category tcl           "$msg_tcl_desc"
185f_category textproc      "$msg_textproc_desc"
186f_category tk            "$msg_tk_desc"
187f_category ukrainian     "$msg_ukrainian_desc"
188f_category vietnamese    "$msg_vietnamese_desc"
189f_category windowmaker   "$msg_windowmaker_desc"
190f_category www           "$msg_www_desc"
191f_category x11           "$msg_x11_desc"
192f_category x11-clocks    "$msg_x11_clocks_desc"
193f_category x11-drivers   "$msg_x11_drivers_desc"
194f_category x11-fm        "$msg_x11_fm_desc"
195f_category x11-fonts     "$msg_x11_fonts_desc"
196f_category x11-servers   "$msg_x11_servers_desc"
197f_category x11-themes    "$msg_x11_themes_desc"
198f_category x11-toolkits  "$msg_x11_toolkits_desc"
199f_category x11-wm        "$msg_x11_wm_desc"
200f_category xfce          "$msg_xfce_desc"
201f_category zope          "$msg_zope_desc"
202
203f_count NCATEGORIES $CATEGORIES
204f_dprintf "%s: Initialized %u package category descriptions." \
205          packages/categories.subr $NCATEGORIES
206
207f_dprintf "%s: Successfully loaded." packages/categories.subr
208
209fi # ! $_PACKAGES_CATEGORIES_SUBR
210