index.subr (25fcf889bd7d46fa0d1524073e38b3883a97f9c9) | index.subr (6d3c0798ccbe7f6d3b677eed31206efc1227be50) |
---|---|
1if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1 2# 3# Copyright (c) 2013-2016 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: --- 132 unchanged lines hidden (view full) --- 141 ( # Get digest as the first word on first line 142 read digest rest_ignored 143 144 # 145 # If the stored digest matches the calculated- 146 # one populate the environment from the on-disk 147 # cache and provide success exit status. 148 # | 1if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1 2# 3# Copyright (c) 2013-2016 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: --- 132 unchanged lines hidden (view full) --- 141 ( # Get digest as the first word on first line 142 read digest rest_ignored 143 144 # 145 # If the stored digest matches the calculated- 146 # one populate the environment from the on-disk 147 # cache and provide success exit status. 148 # |
149 if [ "$digest" = "$__sqlite_digest" ]; then | 149 if [ "$digest" = "#$__sqlite_digest" ]; then |
150 cat 151 exit $SUCCESS 152 else 153 # Otherwise, return the current value 154 eval echo \"\$__var_to_set\" 155 exit $FAILURE 156 fi 157 ) < "$PACKAGES_INDEX_CACHEFILE" 2> /dev/null --- 8 unchanged lines hidden (view full) --- 166 fi 167 # Otherwise, fall-thru to create a fresh cache from scratch 168 fi 169 170 # 171 # If we reach this point, we need to generate the data from scratch 172 # 173 | 150 cat 151 exit $SUCCESS 152 else 153 # Otherwise, return the current value 154 eval echo \"\$__var_to_set\" 155 exit $FAILURE 156 fi 157 ) < "$PACKAGES_INDEX_CACHEFILE" 2> /dev/null --- 8 unchanged lines hidden (view full) --- 166 fi 167 # Otherwise, fall-thru to create a fresh cache from scratch 168 fi 169 170 # 171 # If we reach this point, we need to generate the data from scratch 172 # 173 |
174 eval "$__var_to_set"='$( pkg rquery -I | ( 175 exec 2<&1; dpv -ko /dev/stderr >&$TERMINAL_STDOUT_PASSTHRU \ 176 -b "$DIALOG_BACKTITLE" \ 177 -- "$msg_generating_index_from_pkg_database" 178 ) | sort )' 179 180 # 181 # Attempt to create the persistent on-disk cache 182 # 183 | |
184 # Create a new temporary file to write to 185 local __tmpfile 186 if f_eval_catch -dk __tmpfile $__funcname mktemp \ | 174 # Create a new temporary file to write to 175 local __tmpfile 176 if f_eval_catch -dk __tmpfile $__funcname mktemp \ |
187 'mktemp -t "%s"' "$pgm" 188 then | 177 'mktemp -t "%s"' "$pgm"; then 178 local _npkg |
189 # Write the temporary file contents | 179 # Write the temporary file contents |
190 echo "$__sqlite_digest" > "$__tmpfile" 191 debug= f_getvar "$__var_to_set" >> "$__tmpfile" | 180 echo "#$__sqlite_digest" > "$__tmpfile" 181 f_eval_catch -k _npkg $__funcname pkg \ 182 "pkg stat -r | awk '%s'" '/Packages available/ { print $3 }' 183 pkg rquery -I | awk -v npkg=$_npkg \ 184 -v msg="$msg_generating_index_from_pkg_database" \ 185 -v tmpfile="$__tmpfile" \ 186 -v valid_chars="$VALID_VARNAME_CHARS" \ 187 -v default_desc="$msg_no_description_provided" \ 188 -v packages="$msg_packages" \ 189 -v msg_all="$msg_all" \ 190 -v msg_all_desc="$msg_all_desc" \ 191 -F "|" \ 192 -f $BSDCFG_SHARE/packages/index.awk | \ 193 $DIALOG --backtitle "$DIALOG_BACKTITLE" \ 194 --gauge "$msg_generating_index_from_pkg_database" 0 0 |
192 193 # Finally, move the temporary file into place 194 case "$PACKAGES_INDEX_CACHEFILE" in 195 */*) f_eval_catch -d $__funcname mkdir \ 196 'mkdir -p "%s"' "${PACKAGES_INDEX_CACHEFILE%/*}" 197 esac 198 f_eval_catch -d $__funcname mv 'mv -f "%s" "%s"' \ 199 "$__tmpfile" "$PACKAGES_INDEX_CACHEFILE" | 195 196 # Finally, move the temporary file into place 197 case "$PACKAGES_INDEX_CACHEFILE" in 198 */*) f_eval_catch -d $__funcname mkdir \ 199 'mkdir -p "%s"' "${PACKAGES_INDEX_CACHEFILE%/*}" 200 esac 201 f_eval_catch -d $__funcname mv 'mv -f "%s" "%s"' \ 202 "$__tmpfile" "$PACKAGES_INDEX_CACHEFILE" |
203 else 204 return $FAILURE |
|
200 fi 201 202 if ! f_index_read "$__var_to_set"; then | 205 fi 206 207 if ! f_index_read "$__var_to_set"; then |
203 f_show_err "$msg_io_or_format_error_on_index_file" | 208 f_show_err \ 209 "$msg_io_or_format_error_on_index_file" |
204 return $FAILURE 205 fi 206 207 _INDEX_INITTED=1 208 return $SUCCESS 209} 210 211# f_index_read [$var_to_get] --- 17 unchanged lines hidden (view full) --- 229 local var_to_get="${1:-PACKAGE_INDEX}" 230 231 # Export variables required by awk(1) below 232 export msg_no_description_provided 233 export msg_all msg_all_desc 234 export VALID_VARNAME_CHARS 235 export msg_packages 236 | 210 return $FAILURE 211 fi 212 213 _INDEX_INITTED=1 214 return $SUCCESS 215} 216 217# f_index_read [$var_to_get] --- 17 unchanged lines hidden (view full) --- 235 local var_to_get="${1:-PACKAGE_INDEX}" 236 237 # Export variables required by awk(1) below 238 export msg_no_description_provided 239 export msg_all msg_all_desc 240 export VALID_VARNAME_CHARS 241 export msg_packages 242 |
237 eval "$( debug= f_getvar "$var_to_get" | awk -F'|' ' 238 function _asorti(src, dest) 239 { 240 k = nitems = 0 241 242 # Copy src indices to dest and calculate array length 243 for (i in src) dest[++nitems] = i 244 245 # Sort the array of indices (dest) using insertion sort method 246 for (i = 1; i <= nitems; k = i++) 247 { 248 idx = dest[i] 249 while ((k > 0) && (dest[k] > idx)) 250 { 251 dest[k+1] = dest[k] 252 k-- 253 } 254 dest[k+1] = idx 255 } 256 257 return nitems 258 } 259 function print_category(category, npkgs, desc) 260 { 261 cat = category 262 # Accent the category if the first page has been 263 # cached (also acting as a visitation indicator) 264 if ( ENVIRON["_index_page_" varcat "_1"] ) 265 cat = cat "*" 266 printf "'\''%s'\'' '\''%s " packages "'\'' '\''%s'\''\n", 267 cat, npkgs, desc 268 } 269 BEGIN { 270 valid_chars = ENVIRON["VALID_VARNAME_CHARS"] 271 default_desc = ENVIRON["msg_no_description_provided"] 272 packages = ENVIRON["msg_packages"] 273 tpkgs = 0 274 prefix = "" 275 } 276 { 277 tpkgs++ 278 varpkg = $1 279 gsub("[^" valid_chars "]", "_", varpkg) 280 print "_categories_" varpkg "=\"" $7 "\"" 281 split($7, pkg_categories, /[[:space:]]+/) 282 for (pkg_category in pkg_categories) 283 categories[pkg_categories[pkg_category]]++ 284 print "_rundeps_" varpkg "=\"" $9 "\"" 285 } 286 END { 287 print "_npkgs=" tpkgs # For convenience, total package count 288 289 n = _asorti(categories, categories_sorted) 290 291 # Produce package counts for each category 292 for (i = 1; i <= n; i++) 293 { 294 cat = varcat = categories_sorted[i] 295 npkgs = categories[cat] 296 gsub("[^" valid_chars "]", "_", varcat) 297 print "_npkgs_" varcat "=\"" npkgs "\"" 298 } 299 300 # Create menu list and generate list of categories at same time 301 print "CATEGORY_MENU_LIST=\"" 302 print_category(ENVIRON["msg_all"], tpkgs, 303 ENVIRON["msg_all_desc"]) 304 category_list = "" 305 for (i = 1; i <= n; i++) 306 { 307 cat = varcat = categories_sorted[i] 308 npkgs = categories[cat] 309 cur_prefix = tolower(substr(cat, 1, 1)) 310 if ( prefix != cur_prefix ) 311 prefix = cur_prefix 312 else 313 cat = " " cat 314 gsub("[^" valid_chars "]", "_", varcat) 315 desc = ENVIRON["_category_" varcat] 316 if ( ! desc ) desc = default_desc 317 print_category(cat, npkgs, desc) 318 category_list = category_list " " cat 319 } 320 print "\"" 321 322 # Produce the list of categories (calculated in above block) 323 sub(/^ /, "", category_list) 324 print "PACKAGE_CATEGORIES=\"" category_list "\"" 325 326 }' | ( exec 2<&1; dpv -ko /dev/stderr >&$TERMINAL_STDOUT_PASSTHRU \ 327 -b "$DIALOG_BACKTITLE" -- "$msg_reading_package_index_data" 328 ) )" # End-Quote | 243 . $PACKAGES_INDEX_CACHEFILE |
329} 330 331# f_index_extract_pages $var_to_get $var_basename $pagesize [$category] 332# 333# Extracts the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is 334# NULL; but should not be missing) into a series of sequential variables 335# corresponding to "pages" containing up to $pagesize packages. The package 336# INDEX data must be contained in the variable $var_to_get. The extracted pages 337# are stored in variables ${var_basename}_# -- where "#" is a the page number. 338# If $category is set, only packages for that category are extracted. 339# Otherwise, if $category is "All", missing, or NULL, all packages are 340# extracted and no filtering is done. 341# 342f_index_extract_pages() 343{ 344 local var_to_get="${1:-PACKAGE_INDEX}" var_basename="$2" pagesize="$3" | 244} 245 246# f_index_extract_pages $var_to_get $var_basename $pagesize [$category] 247# 248# Extracts the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is 249# NULL; but should not be missing) into a series of sequential variables 250# corresponding to "pages" containing up to $pagesize packages. The package 251# INDEX data must be contained in the variable $var_to_get. The extracted pages 252# are stored in variables ${var_basename}_# -- where "#" is a the page number. 253# If $category is set, only packages for that category are extracted. 254# Otherwise, if $category is "All", missing, or NULL, all packages are 255# extracted and no filtering is done. 256# 257f_index_extract_pages() 258{ 259 local var_to_get="${1:-PACKAGE_INDEX}" var_basename="$2" pagesize="$3" |
345 local category="$4" # Optional | |
346 347 eval "$( 348 debug= f_getvar "$var_to_get" | awk -F'|' \ | 260 261 eval "$( 262 debug= f_getvar "$var_to_get" | awk -F'|' \ |
349 -v cat="$category" \ | |
350 -v pagesize="$pagesize" \ | 263 -v pagesize="$pagesize" \ |
351 -v var_basename="$var_basename" \ 352 -v i18n_all="$msg_all" ' | 264 -v var_basename="$var_basename" ' \ |
353 BEGIN { n = page = 0 } 354 /'\''/{ gsub(/'\''/, "'\''\\'\'\''") } 355 { | 265 BEGIN { n = page = 0 } 266 /'\''/{ gsub(/'\''/, "'\''\\'\'\''") } 267 { |
356 if ( cat !~ "(^$|^" i18n_all "$)" && $7 !~ \ 357 "(^|[[:space:]])" cat "([[:space:]]|$)" ) next | |
358 starting_new_page = (n++ == (pagesize * page)) 359 if ( starting_new_page ) 360 printf "%s%s", ( n > 1 ? "'\''\n" : "" ), 361 var_basename "_" ++page "='\''" 362 printf "%s%s", ( starting_new_page ? "" : "\n" ), $0 363 } 364 END { if ( n > 0 ) print "'\''" }' 365 )" --- 45 unchanged lines hidden --- | 268 starting_new_page = (n++ == (pagesize * page)) 269 if ( starting_new_page ) 270 printf "%s%s", ( n > 1 ? "'\''\n" : "" ), 271 var_basename "_" ++page "='\''" 272 printf "%s%s", ( starting_new_page ? "" : "\n" ), $0 273 } 274 END { if ( n > 0 ) print "'\''" }' 275 )" --- 45 unchanged lines hidden --- |