categories.subr revision 251268
1250323Sdteskeif [ ! "$_PACKAGES_CATEGORIES_SUBR" ]; then _PACKAGES_CATEGORIES_SUBR=1 2250323Sdteske# 3250323Sdteske# Copyright (c) 2013 Devin Teske 4250323Sdteske# All Rights Reserved. 5250323Sdteske# 6250323Sdteske# Redistribution and use in source and binary forms, with or without 7250323Sdteske# modification, are permitted provided that the following conditions 8250323Sdteske# are met: 9250323Sdteske# 1. Redistributions of source code must retain the above copyright 10250323Sdteske# notice, this list of conditions and the following disclaimer. 11250323Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12250323Sdteske# notice, this list of conditions and the following disclaimer in the 13250323Sdteske# documentation and/or other materials provided with the distribution. 14250323Sdteske# 15250323Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16250323Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17250323Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18250323Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19250323Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20250323Sdteske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21250323Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22250323Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23250323Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24250323Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25250323Sdteske# SUCH DAMAGE. 26250323Sdteske# 27250323Sdteske# $FreeBSD: head/usr.sbin/bsdconfig/share/packages/categories.subr 251268 2013-06-02 22:54:36Z dteske $ 28250323Sdteske# 29250323Sdteske############################################################ INCLUDES 30250323Sdteske 31250323SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32250323Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33250323Sdteskef_dprintf "%s: loading includes..." packages/categories.subr 34250323Sdteskef_include $BSDCFG_SHARE/strings.subr 35250323Sdteske 36250323SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 37250323Sdteskef_include_lang $BSDCFG_LIBE/include/messages.subr 38250323Sdteske 39250323Sdteske############################################################ GLOBALS 40250323Sdteske 41250323SdteskeCATEGORIES= 42250323Sdteske 43250323Sdteske############################################################ FUNCTIONS 44250323Sdteske 45250323Sdteske# f_category_desc_get $category [$var_to_set] 46250323Sdteske# 47250323Sdteske# Fetch the description of a given category. Returns success if a match was 48250323Sdteske# found, otherwise failure. 49250323Sdteske# 50250323Sdteske# If $var_to_set is missing or NULL, the category description is printed to 51250323Sdteske# standard out for capturing in a sub-shell (which is less-recommended because 52250323Sdteske# of performance degredation; for example, when called in a loop). 53250323Sdteske# 54250323Sdteskef_category_desc_get() 55250323Sdteske{ 56250323Sdteske local __category="$1" __var_to_set="$2" __cat __varcat 57250323Sdteske 58250323Sdteske # Return failure if $category 59250323Sdteske [ "$__category" ] || return $FAILURE 60250323Sdteske 61250323Sdteske for __cat in $CATEGORIES; do 62250323Sdteske [ "$__cat" = "$__category" ] || continue 63250323Sdteske f_str2varname $__cat __varcat 64250323Sdteske f_getvar _category_$__varcat $__var_to_set 65250323Sdteske return $? 66250323Sdteske done 67250323Sdteske return $FAILURE 68250323Sdteske} 69250323Sdteske 70250323Sdteske# f_category_desc_set $category $desc 71250323Sdteske# 72250323Sdteske# Store a description in-association with a category. $category should be 73250323Sdteske# alphanumeric and can include the underscore [_] but should not contain 74250323Sdteske# whitespace. Returns success unless $category is NULL or no arguments. Use the 75250323Sdteske# f_category_desc_get() routine with the same $category to retrieve the stored 76250323Sdteske# description. 77250323Sdteske# 78250323Sdteskef_category_desc_set() 79250323Sdteske{ 80250323Sdteske local category="$1" desc="$2" 81250323Sdteske local cat varcat found= 82250323Sdteske [ "$category" ] || return $FAILURE 83250323Sdteske for cat in $CATEGORIES; do 84250323Sdteske [ "$cat" = "$category" ] || continue 85250323Sdteske f_str2varname $cat varcat 86251268Sdteske f_isset _category_$varcat || continue 87250323Sdteske found=1 && break 88250323Sdteske done 89250323Sdteske if [ ! "$found" ]; then 90250323Sdteske CATEGORIES="$CATEGORIES $category" 91250323Sdteske fi 92250323Sdteske f_str2varname $category varcat 93250323Sdteske setvar "_category_$varcat" "$desc" 94250323Sdteske # Export the variable for awk(1) ENVIRON visibility 95250323Sdteske export "_category_$varcat" 96250323Sdteske return $SUCCESS 97250323Sdteske} 98250323Sdteske 99250323Sdteske############################################################ MAIN 100250323Sdteske 101250323Sdteske# 102250536Sdteske# Load descriptions for package categories. Note that we don't internationalize 103250539Sdteske# category names because this would be confusing for people used to browsing 104250536Sdteske# the FTP mirrors or are otherwise familiar with an interface that does not 105250536Sdteske# provide internationalized names. The descriptions can be used to provide i18n 106250536Sdteske# users a description of the non-i18n category name. 107250323Sdteske# 108250323Sdteskef_category() { f_category_desc_set "$1" "$2"; } 109250537Sdteskef_category All "$msg_all_desc" 110250323Sdteskef_category accessibility "$msg_accessibility_desc" 111250323Sdteskef_category afterstep "$msg_afterstep_desc" 112250323Sdteskef_category arabic "$msg_arabic_desc" 113250323Sdteskef_category archivers "$msg_archivers_desc" 114250323Sdteskef_category astro "$msg_astro_desc" 115250323Sdteskef_category audio "$msg_audio_desc" 116250323Sdteskef_category benchmarks "$msg_benchmarks_desc" 117250323Sdteskef_category biology "$msg_biology_desc" 118250323Sdteskef_category cad "$msg_cad_desc" 119250323Sdteskef_category chinese "$msg_chinese_desc" 120250323Sdteskef_category comms "$msg_comms_desc" 121250323Sdteskef_category converters "$msg_converters_desc" 122250323Sdteskef_category databases "$msg_databases_desc" 123250323Sdteskef_category deskutils "$msg_deskutils_desc" 124250323Sdteskef_category devel "$msg_devel_desc" 125250323Sdteskef_category dns "$msg_dns_desc" 126250323Sdteskef_category docs "$msg_docs_desc" 127250323Sdteskef_category editors "$msg_editors_desc" 128250323Sdteskef_category elisp "$msg_elisp_desc" 129250323Sdteskef_category emulators "$msg_emulators_desc" 130250323Sdteskef_category enlightenment "$msg_enlightenment_desc" 131250323Sdteskef_category finance "$msg_finance_desc" 132250323Sdteskef_category french "$msg_french_desc" 133250323Sdteskef_category ftp "$msg_ftp_desc" 134250323Sdteskef_category games "$msg_games_desc" 135250323Sdteskef_category geography "$msg_geography_desc" 136250323Sdteskef_category german "$msg_german_desc" 137250323Sdteskef_category gnome "$msg_gnome_desc" 138250323Sdteskef_category gnustep "$msg_gnustep_desc" 139250323Sdteskef_category graphics "$msg_graphics_desc" 140250323Sdteskef_category hamradio "$msg_hamradio_desc" 141250323Sdteskef_category haskell "$msg_haskell_desc" 142250323Sdteskef_category hebrew "$msg_hebrew_desc" 143250323Sdteskef_category hungarian "$msg_hungarian_desc" 144250323Sdteskef_category ipv6 "$msg_ipv6_desc" 145250323Sdteskef_category irc "$msg_irc_desc" 146250323Sdteskef_category japanese "$msg_japanese_desc" 147250323Sdteskef_category java "$msg_java_desc" 148250323Sdteskef_category kde "$msg_kde_desc" 149250323Sdteskef_category kld "$msg_kld_desc" 150250323Sdteskef_category korean "$msg_korean_desc" 151250323Sdteskef_category lang "$msg_lang_desc" 152250323Sdteskef_category linux "$msg_linux_desc" 153250323Sdteskef_category lisp "$msg_lisp_desc" 154250323Sdteskef_category mail "$msg_mail_desc" 155250323Sdteskef_category math "$msg_math_desc" 156250323Sdteskef_category mbone "$msg_mbone_desc" 157250323Sdteskef_category misc "$msg_misc_desc" 158250323Sdteskef_category multimedia "$msg_multimedia_desc" 159250323Sdteskef_category net "$msg_net_desc" 160250323Sdteskef_category net-im "$msg_net_im_desc" 161250323Sdteskef_category net-mgmt "$msg_net_mgmt_desc" 162250323Sdteskef_category net-p2p "$msg_net_p2p_desc" 163250323Sdteskef_category news "$msg_news_desc" 164250323Sdteskef_category palm "$msg_palm_desc" 165250323Sdteskef_category parallel "$msg_parallel_desc" 166250323Sdteskef_category pear "$msg_pear_desc" 167250323Sdteskef_category perl5 "$msg_perl5_desc" 168250323Sdteskef_category plan9 "$msg_plan9_desc" 169250323Sdteskef_category polish "$msg_polish_desc" 170250323Sdteskef_category ports-mgmt "$msg_ports_mgmt_desc" 171250323Sdteskef_category portuguese "$msg_portuguese_desc" 172250323Sdteskef_category print "$msg_print_desc" 173250323Sdteskef_category python "$msg_python_desc" 174250323Sdteskef_category ruby "$msg_ruby_desc" 175250323Sdteskef_category rubygems "$msg_rubygems_desc" 176250323Sdteskef_category russian "$msg_russian_desc" 177250323Sdteskef_category scheme "$msg_scheme_desc" 178250323Sdteskef_category science "$msg_science_desc" 179250323Sdteskef_category security "$msg_security_desc" 180250323Sdteskef_category shells "$msg_shells_desc" 181250323Sdteskef_category spanish "$msg_spanish_desc" 182250323Sdteskef_category sysutils "$msg_sysutils_desc" 183250323Sdteskef_category tcl "$msg_tcl_desc" 184250323Sdteskef_category textproc "$msg_textproc_desc" 185250323Sdteskef_category tk "$msg_tk_desc" 186250323Sdteskef_category ukrainian "$msg_ukrainian_desc" 187250323Sdteskef_category vietnamese "$msg_vietnamese_desc" 188250323Sdteskef_category windowmaker "$msg_windowmaker_desc" 189250323Sdteskef_category www "$msg_www_desc" 190250323Sdteskef_category x11 "$msg_x11_desc" 191250323Sdteskef_category x11-clocks "$msg_x11_clocks_desc" 192250323Sdteskef_category x11-drivers "$msg_x11_drivers_desc" 193250323Sdteskef_category x11-fm "$msg_x11_fm_desc" 194250323Sdteskef_category x11-fonts "$msg_x11_fonts_desc" 195250323Sdteskef_category x11-servers "$msg_x11_servers_desc" 196250323Sdteskef_category x11-themes "$msg_x11_themes_desc" 197250323Sdteskef_category x11-toolkits "$msg_x11_toolkits_desc" 198250323Sdteskef_category x11-wm "$msg_x11_wm_desc" 199250323Sdteskef_category xfce "$msg_xfce_desc" 200250323Sdteskef_category zope "$msg_zope_desc" 201250323Sdteske 202250323Sdteskef_dprintf "%s: Initialized %u package category descriptions." \ 203250323Sdteske packages/categories.subr "$( set -- $CATEGORIES; echo $# )" 204250323Sdteske 205250323Sdteskef_dprintf "%s: Successfully loaded." packages/categories.subr 206250323Sdteske 207250323Sdteskefi # ! $_PACKAGES_CATEGORIES_SUBR 208