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