Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to master sorcery by Ismael Luceno (dcaf96986b54ba37eeff3fe0b5642f67700581f0)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Ismael Luceno <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to master sorcery by Ismael Luceno (dcaf96986b54ba37eeff3fe0b5642f67700581f0)
  • Date: Tue, 9 Sep 2014 14:16:10 -0500

GIT changes to master sorcery by Ismael Luceno <ismael AT sourcemage.org>:

usr/sbin/cabal | 11 +++---
usr/sbin/cast | 15 ++++-----
usr/sbin/cleanse | 45 ++++++++++++++-------------
usr/sbin/gaze | 18 +++++++---
usr/sbin/sorcery | 2 -
var/lib/sorcery/modules/libcast | 2 -
var/lib/sorcery/modules/libcodex | 47 ++++++++++++----------------
var/lib/sorcery/modules/libdepends | 60
++++++++++++++++++++----------------
var/lib/sorcery/modules/libgrimoire | 2 -
var/lib/sorcery/modules/libmisc | 14 ++++----
var/lib/sorcery/modules/libstate | 17 ++++------
var/lib/sorcery/modules/libtime | 31 +++++++++---------
var/lib/sorcery/modules/liburl | 17 +++-------
13 files changed, 144 insertions(+), 137 deletions(-)

New commits:
commit dcaf96986b54ba37eeff3fe0b5642f67700581f0
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>

Avoid eval of AWK output, and improve AWK code

commit b30979fb7c8b52aaf52e0898cff76dc7ba5360bf
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>

cleanse: Optimize pass three, merge second sed command into the first

commit 48b21f2eb9df2a0558a981530135e11d48dc32db
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>

Improve some AWK code

commit 9d04280be54f1ca1af55a06696696f38e22d56fb
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>

cast: Simplify pass_two process killing step

diff --git a/usr/sbin/cabal b/usr/sbin/cabal
index c056a7b..0e6973b 100755
--- a/usr/sbin/cabal
+++ b/usr/sbin/cabal
@@ -1,7 +1,7 @@
#!/bin/bash
#---------------------------------------------------------------------
## @Synopsis A set of functions for the Cabal distributed administration
system.
-## @Copyright Copyright 2002 by the Source Mage Team. Some parts Copyright
2001 by Kyle Sallee
+## @Copyright Copyright 2002, 2014 by the Source Mage Team. Some parts
Copyright 2001 by Kyle Sallee
## Control a set of SourceMage boxes on a network. This documentation was
## written by someone who never used cabal or looked at this code before.
##
@@ -17,11 +17,12 @@ function read_cabal_names() {

mkdir -p $CABAL_DIRECTORY

- [ -f $CABAL_NAMES ] || return
-
-
- eval `awk '{ print "CABALS[" NR-1 "]=\"" $0 "\""; }' "$CABAL_NAMES"`
+ [ -f $CABAL_NAMES ] || return

+ awk '{ print n++, $0 }' "$CABAL_NAMES" |
+ while read v name; do
+ CABALS[$v]="$name"
+ done
}

#--------------------
diff --git a/usr/sbin/cast b/usr/sbin/cast
index 44a656b..36ce894 100755
--- a/usr/sbin/cast
+++ b/usr/sbin/cast
@@ -3,7 +3,7 @@
## @Synopsis cast is the spell installation utility. It can be called by the
user or by sorcery
## @Copyright Original version Copyright 2001 by Kyle Sallee
## @Copyright Some parts copyright 2002 Anders Bruun Olsen et al
-## @Copyright Other additions/corrections Copyright 2002 by the Source Mage
Team
+## @Copyright Other additions/corrections Copyright 2002, 2014 by the Source
Mage Team
## Script to cast spells.
#---------------------------------------------------------------------

@@ -474,14 +474,13 @@ function pass_two() {
let i+=5
if [[ $i -gt 60 ]] ; then
message "Download pass did not finish, killing it off."
- # this is rather violent, but job control in bash lame and theres
+ # this is rather violent, but job control in bash lame and there's
# no other way to kill everything off effectively :-(
- ps x|grep $TMP_DIR|awk '{print $1}'|grep -v $$|xargs kill &>/dev/null
- echo -n .; sleep 1
- ps x|grep $TMP_DIR|awk '{print $1}'|grep -v $$|xargs kill &>/dev/null
- echo -n .; sleep 1
- ps x|grep $TMP_DIR|awk '{print $1}'|grep -v $$|xargs kill -9
&>/dev/null
- echo -n .; sleep 1
+ pids="`ps x | awk -v t="$TMP_DIR" -v p=$$ -- '$0 ~ t && $1 != p {print
$1}'`"
+ for i in '' '' -9; do
+ kill $i $pids >/dev/null 2>&1
+ echo -n .; sleep 1
+ done
echo
break
fi
diff --git a/usr/sbin/cleanse b/usr/sbin/cleanse
index 5a4cff6..77954a5 100755
--- a/usr/sbin/cleanse
+++ b/usr/sbin/cleanse
@@ -6,6 +6,7 @@
## remove corrupted lines, and ensure the information all agrees
## with itself. It is also to clean out unused lines and files.
##
+## @Copyright Copyright 2014 by Ismael Luceno for Source Mage
## @Copyright Copyright 2004 by Paul Mahon for Source Mage
## @Licence Relased under the GNU GPL version 2
##
@@ -227,13 +228,16 @@ function delint()
generic_remove_stale "$DEPENDS_STATUS" depends two

message "Pass three (duplicate depends entries)"
- for LINE in $( sed -n 's/^\([^:]*\):\([^:]*\):.*$/\1:\2/p' $DEPENDS_STATUS
| sed 's/+/\\+/' | sort | uniq -d ) ; do
+ for LINE in $( sed 's/^\([^:]*\):\([^:]*\):.*$/\1:\2/;tp;d;:p;s/+/\\+/}'
$DEPENDS_STATUS | sort | uniq -d ) ; do
message
options=()
- eval $(awk '/^'$LINE':/{
- if(!ENTRIES[$0]) {
- printf("options[%d]=\"%s\"\n", count++, $0); ENTRIES[$0]=1;
- } }' $DEPENDS_STATUS)
+ awk -v line="^$LINE:" -- '
+ $0 ~ line && !($0 in seen) {print count++, $0; seen[$0]}
+ ' $DEPENDS_STATUS |
+ while read v opt; do
+ options[$v]="$opt"
+ done
+
if [ ${#options[@]} -gt 1 ] ; then
select_list choice "" "${options[@]}"
message "Removing other entries and keeping selected entry"
@@ -281,16 +285,16 @@ function generic_remove_stale() {
message "Pass $3 (stale $2 entries)"
local tmp=$TMP_DIR/delint.$2.stale
local t
- awk -F: '
+ awk -F: -v status="$SPELL_STATUS" '
BEGIN {
- while (getline < "'$SPELL_STATUS'")
- Installed[$1] = 1;
+ while (getline < status)
+ Installed[$1]
}
{
- if ( ! Installed[$1])
- print $0;
+ if (!($1 in Installed))
+ print $0
}' "$1" |tee $tmp
- t=$(wc -l $tmp | awk '{print $1;}')
+ t=$(wc -l $tmp | awk '{print $1}')
message "\t$t bad lines, $(( $(wc -l $1| cut -f1 -d' ') - t))" \
"good lines in your $2 file."
if [[ $t -gt 0 ]] ; then
@@ -328,18 +332,17 @@ function prune_depends()

# Get a list of bad dependencies
# Output is in the form "SPELL DEPENDENCY optional/reqired PROVIDER"
- bad=( $( awk -F: '
+ bad=( $( awk -F: -v status="$SPELL_STATUS" '
BEGIN {
- while (getline < "'$SPELL_STATUS'")
- Installed[$1] = 1;
+ while (getline < status)
+ Installed[$1]
}
- $3=="on"{
- if($2 ~ "[(].*[)]")
- prov=gensub("^.*\\((.*)\\).*$", "\\1", 1, $2);
- else
- prov="__BLANK__";
+ $3 == "on" {
+ prov = ($2 ~ "[(].*[)]") ?
+ gensub("^.*\\((.*)\\).*$", "\\1", 1, $2) :
+ "__BLANK__"
gsub("\\(.*\\)", "", $2)
- if ( Installed[$1] && ! Installed[$2] && $2!="")
+ if ($1 in Installed && !($2 in Installed) && $2 != "")
printf("%s %s %s %s\n", $1, $2, $4, prov);
}' $DEPENDS_STATUS ) )

@@ -487,7 +490,7 @@ function packages()
done
)
if [[ $t ]] && query "\tRemove all but one of each set of duplicates?" "n"
; then
- awk -F: '{if(!LINES[$1]) { LINES[$1]=1; print $0; } }' $SPELL_STATUS >
$TMP_DIR/packages.3
+ awk -F: '!($1 in LINES){LINES[$1]; print}' $SPELL_STATUS >
$TMP_DIR/packages.3
message "\tRemoving bad entries"
mv $TMP_DIR/packages.3 $SPELL_STATUS
fi
diff --git a/usr/sbin/gaze b/usr/sbin/gaze
index 1329f2b..d90ac2d 100755
--- a/usr/sbin/gaze
+++ b/usr/sbin/gaze
@@ -592,7 +592,7 @@ function newer() {
local COMPUTE

if [ x"$DATE" == x"last_sorcery_update" ]; then
- COMPUTE='($3=="update") { a=a+1; if (a>1) { print $1 ; exit } }'
+ COMPUTE='($3=="update") { if (++a > 1) { print $1 ; exit } }'
elif [ x"$DATE" == x"last_cast" ]; then
COMPUTE='($3 == "cast" && $6 == "success") { print $1 ; exit }'
elif ! date -d "$DATE" +%Y%m%d > /dev/null; then
@@ -1613,7 +1613,7 @@ function gaze_show_depends() {
show_up_depends "$1" "$2" "$fast" "$all"
else
show_up_depends "$1" "$2" "verbose" "$all"|
- awk -F: '{ printf("%s depends on %s (%s)\n",$1,$2,$4);}'
+ awk -F: '{print $1, "depends on", $2, "(" $4 ")"}'
fi


@@ -1773,7 +1773,11 @@ function gaze_show_size_all () {
done <<< "$installed_spells"
clear_line
echo $spell_count $total_size $total_files | awk \
- 'END { print $1" spells -> "$2" bytes ("int($2/1024+0.5)" K,
"int($2/1024/1024+0.5)" M, "int($2/1024/1024/1024+0.5)" G) in "$3" files." }'
+ 'END {
+ print $1, "spells ->", $2, "bytes ("int($2/1024+0.5), "K,",
+ int($2/1024/1024+0.5), "M,", int($2/1024/1024/1024+0.5),
+ "G) in", $3, "files."
+ }'
echo
echo "Largest spell:"
gaze_show_size $max_spell
@@ -1812,8 +1816,12 @@ function gaze_show_size () {
while read each; do
test -f "$each" && echo $each
done < $file | xargs du -b |
- awk '{ x += $1 }
- END { print "'$spell' -> " x " bytes ("int(x/1024+0.5)" K,
"int(x/1024/1024+0.5)" M) in " NR " files." }'
+ awk -v spell="$spell" '
+ { x += $1 }
+ END {
+ print spell, "->", x, "bytes (" int(x/1024+0.5), "K,",
+ int(x/1024/1024+0.5), "M) in", NR, "files."
+ }'
done
}

diff --git a/usr/sbin/sorcery b/usr/sbin/sorcery
index c58f921..28965e0 100755
--- a/usr/sbin/sorcery
+++ b/usr/sbin/sorcery
@@ -92,7 +92,7 @@ mirror_list() {
local mirror_list
for mirror_list in $MIRRORS; do
[[ -f $mirror_list/$1 ]] || continue
- sort $mirror_list/$1 | awk '{ print "\""$NF"\""; NF--; print $0; }'
+ sort $mirror_list/$1 | awk '{ print "\"" $NF "\""; NF--; print $0 }'
break # only list duplicate mirror lists once
done
}
diff --git a/var/lib/sorcery/modules/libcast b/var/lib/sorcery/modules/libcast
index bd47f8e..df23ff1 100755
--- a/var/lib/sorcery/modules/libcast
+++ b/var/lib/sorcery/modules/libcast
@@ -98,7 +98,7 @@ function query_conflicts() {
local output=${2:-$CONFLICT_LIST}

# skip if the spell was already processed (avoids a double query for
in-cast resurrects)
- [[ -s $output ]] && awk -v s=$SPELL '{ if ($1 == s) {rc=1} } END {exit
!rc}' $output && return 0
+ [[ -s $output ]] && awk -v s=$SPELL '{ if ($1 == s) {rc=1; exit} } END
{exit !rc}' $output && return 0

if [[ -x $SCRIPT_DIRECTORY/CONFLICTS ]]; then
local CONFLICTS=$(run_spell_file CONFLICTS conflicts) || return 1
diff --git a/var/lib/sorcery/modules/libcodex
b/var/lib/sorcery/modules/libcodex
index 176225a..d6abe64 100755
--- a/var/lib/sorcery/modules/libcodex
+++ b/var/lib/sorcery/modules/libcodex
@@ -548,7 +548,7 @@ function codex_get_spells_in_section() {
message "${PROBLEM_COLOR}${section:-<null>} is not a section
directory!${DEFAULT_COLOR}"
return 1
fi
- grep "/$section$" < $index | awk '{ printf("%s/%s\n",$2,$1); }'
+ grep "/$section$" < $index | awk '{ print $2 "/" $1 }'

}

@@ -729,7 +729,7 @@ function codex_set_current_spell_by_name() {

#---------------------------------------------------------------------
## @param spell name
-## Returns the features a spell is a provider off.
+## Returns the features a spell is a provider of.
## Example, firefox: GECKO, GRAPHICAL-WEB-BROWSER, WEB-BROWSER,
## NS-PLUGIN-COMPATIBLE
##
@@ -739,7 +739,7 @@ function codex_find_spell_provides() {
local feature grimoire
local features=$(
for grimoire in $(codex_get_all_grimoires); do
- gawk '/\/'$spell'$/ { print $1 }' \
+ awk -v re="/$spell\$" -- '$0 ~ re { print $1 }' \
"$grimoire/$PROVIDE_INDEX_FILE"
done | sort -u)

@@ -773,7 +773,7 @@ function find_providers() {
local provider GRIMOIRE spell_path
local providers=$(
for GRIMOIRE in $(codex_get_all_grimoires); do
- gawk '/^'"$feature"'[[:blank:]]/ { print $2 }' \
+ gawk -v re="^$feature[[:blank:]]" -- '$0 ~ re { print $2 }' \
"$GRIMOIRE/$PROVIDE_INDEX_FILE"
done | get_basenames|sort -u)

@@ -879,24 +879,22 @@ function codex_create_in_memory_cache() {
eval $(
for each in "$@"; do
cat $each/$SPELL_INDEX_FILE
- done | awk -v i=$list -v hash=$hash '{
- if ( ! ($1 in map)) {
- map[$1]=$2;
- }
- } END {
- if (i) {
- FS=":";
- while (getline < i) {
- if( $3=="installed" || $3=="held") {
- printf("hash_put %s %s \"%s/%s\";\n",hash,$1,map[$1],$1);
- }
- }
- } else {
- for (spell in map) {
- printf("hash_put %s %s \"%s/%s\";\n",hash,spell,map[spell],spell);
- }
- }
- }'
+ done | awk -v i="$list" -v hash="$hash" '
+ { if (!($1 in map)) map[$1] = $2 }
+ function phash(hash, spell) {
+ printf("hash_put %s %s \"%s/%s\";\n", hash, spell,
map[spell], spell)
+ }
+ END {
+ if (i) {
+ FS=":"
+ while (getline < i)
+ if ($3 == "installed" || $3 == "held")
+ phash(hash, $1)
+ } else {
+ for (spell in map)
+ phash(hash, spell)
+ }
+ }'
)

}
@@ -935,10 +933,7 @@ function codex_list_provides () {

for file in $(codex_find_in_grimoire $grimoire "PROVIDES"); do
smgl_dirname "$file" spell
- for provides in $(gawk '{if (/provides/) { print $2 }
- else { print $1 }}' $file); do
- echo "$provides $spell"
- done
+ awk -v s="$spell" '/provides/{$1 = $2} {print $1, s}' $file
done | sort
}

diff --git a/var/lib/sorcery/modules/libdepends
b/var/lib/sorcery/modules/libdepends
index 5fa0f41..02d6b86 100755
--- a/var/lib/sorcery/modules/libdepends
+++ b/var/lib/sorcery/modules/libdepends
@@ -306,19 +306,23 @@ function compute_installed_depends() {
lock_file "$DEPENDS_STATUS"
lock_file "$SPELL_STATUS"
# sub(/(.*)/, "", $2) removes a provider name
- eval $(awk -v pattern="$pattern" -v status="$status" -F : 'BEGIN {
- while (getline < ARGV[1] ) {
- if( $3==status && ( $4 ~ pattern ) ) {
- sub(/\(.*\)/, "", $2);
- depmap[$1]=depmap[$1]" "$2" "
- }
- }
- while (getline < ARGV[2] ) {
- if( $3=="installed" || $3=="held") {
- printf("hash_put $hash %s \"%s\";\n",$1,depmap[$1]);
- }
- }
- }' $DEPENDS_STATUS $SPELL_STATUS )
+ awk -v pattern="$pattern" -v status="$status" -F : '
+ FNR == 1 { file++ }
+ file == 1 {
+ if ($3 == status && ($4 ~ pattern)) {
+ sub(/\(.*\)/, "", $2);
+ depmap[$1] = depmap[$1] " " $2 " "
+ }
+ next
+ }
+ {
+ if ($3 == "installed" || $3 == "held")
+ print $1, depmap[$1]
+ }
+ ' "$DEPENDS_STATUS" "$SPELL_STATUS" |
+ while read a b; do
+ hash_put "$hash" "$a" "$b"
+ done
unlock_file "$DEPENDS_STATUS"
unlock_file "$SPELL_STATUS"
}
@@ -348,19 +352,23 @@ function compute_reverse_installed_depends() {
lock_file "$DEPENDS_STATUS"
lock_file "$SPELL_STATUS"
# sub(/(.*)/, "", $2) removes a provider name
- eval $(awk -v pattern="$pattern" -v status="$status" -F : 'BEGIN {
- while (getline < ARGV[1] ) {
- if( $3==status && ( $4 ~ pattern ) ) {
- sub(/\(.*\)/, "", $2);
- depmap[$2]=depmap[$2]" "$1" "
- }
- }
- while (getline < ARGV[2] ) {
- if( $3=="installed" || $3=="held") {
- printf("hash_put $hash %s \"%s\";\n",$1,depmap[$1]);
- }
- }
- }' $DEPENDS_STATUS $SPELL_STATUS )
+ awk -v pattern="$pattern" -v status="$status" -F : '
+ FNR == 1 { file++ }
+ file == 1 {
+ if ($3 == status && ($4 ~ pattern)) {
+ sub(/\(.*\)/, "", $2);
+ depmap[$2] = depmap[$2] " " $1 " "
+ }
+ next
+ }
+ {
+ if ($3 == "installed" || $3 == "held")
+ print $1, depmap[$1]
+ }
+ ' "$DEPENDS_STATUS" "$SPELL_STATUS" |
+ while read a b; do
+ hash_put "$hash" "$a" "$b"
+ done
unlock_file "$DEPENDS_STATUS"
unlock_file "$SPELL_STATUS"
}
diff --git a/var/lib/sorcery/modules/libgrimoire
b/var/lib/sorcery/modules/libgrimoire
index 4bc2d24..79614ce 100755
--- a/var/lib/sorcery/modules/libgrimoire
+++ b/var/lib/sorcery/modules/libgrimoire
@@ -215,7 +215,7 @@ function real_installed_version() {
##
#---------------------------------------------------------------------
function private_installed_version() {
- awk -F: -v spell="$1" '{ if(spell == $1) {print $4; exit}}' $SPELL_STATUS
2>/dev/null
+ awk -F: -v spell="$1" '$1 == spell { print $4; exit }' $SPELL_STATUS
2>/dev/null
}

#---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/libmisc b/var/lib/sorcery/modules/libmisc
index ed33b42..7df7cf1 100755
--- a/var/lib/sorcery/modules/libmisc
+++ b/var/lib/sorcery/modules/libmisc
@@ -346,7 +346,7 @@ function init_hooks() {
declare -F hook_marker &>/dev/null && return 0

local hook_file
- local hookdir_perms="$(ls -lnd $SORCERY_HOOKS 2>/dev/null|awk '{printf
"%s:%s:%s\n" ,$1,$3,$4;}')"
+ local hookdir_perms="$(ls -lnd $SORCERY_HOOKS 2>/dev/null|awk '{print $1
":" $3 ":" $4}')"
local hooks_list=""

if [[ $hookdir_perms == "drwxr-xr-x:0:0" ]]; then
@@ -1214,7 +1214,7 @@ function mk_tmp_dirs() {



- tmp=$(ls -lnd $BASE_DIR 2>/dev/null|awk '{printf "%s:%s:%s\n" ,$1,$3,$4;
}')
+ tmp=$(ls -lnd $BASE_DIR 2>/dev/null|awk '{print $1 ":" $3 ":" $4}')
if [[ "$tmp" != "drwxr-xr-x:0:0" ]] ; then
test -d $BASE_DIR &&
message "$BASE_DIR has unknown permissions and ownership, replacing it"
>&2
@@ -1224,20 +1224,20 @@ function mk_tmp_dirs() {
fi || mk_tmp_dir_error $BASE_DIR

# double check
- tmp=$(ls -lnd $BASE_DIR 2>/dev/null|awk '{printf "%s:%s:%s\n" ,$1,$3,$4;
}')
+ tmp=$(ls -lnd $BASE_DIR 2>/dev/null|awk '{print $1 ":" $3 ":" $4}')
if [[ "$tmp" != "drwxr-xr-x:0:0" ]] ; then
mk_tmp_dir_error $BASE_DIR
fi


- tmp=$(ls -lnd $SCRIPT_DIR 2>/dev/null|awk '{printf "%s:%s:%s\n" ,$1,$3,$4;
}')
+ tmp=$(ls -lnd $SCRIPT_DIR 2>/dev/null|awk '{print $1 ":" $3 ":" $4}')
if [[ "$tmp" != "drwxr-xr-x:0:0" ]] ; then
rm -rf $SCRIPT_DIR
install -d -o root -g root -m 755 "$SCRIPT_DIR"
fi || mk_tmp_dir_error $SCRIPT_DIR

# double check
- tmp=$(ls -lnd $SCRIPT_DIR|awk '{printf "%s:%s:%s\n" ,$1,$3,$4; }')
+ tmp=$(ls -lnd $SCRIPT_DIR|awk '{print $1 ":" $3 ":" $4}')
if [[ "$tmp" != "drwxr-xr-x:0:0" ]] ; then
mk_tmp_dir_error $SCRIPT_DIR
fi
@@ -1249,7 +1249,7 @@ function mk_tmp_dirs() {
fi

install -d -o root -g root -m 755 "$FULL_DIR" || mk_tmp_dir_error $FULL_DIR
- tmp=$(ls -lnd $SCRIPT_DIR|awk '{printf "%s:%s:%s\n" ,$1,$3,$4; }')
+ tmp=$(ls -lnd $SCRIPT_DIR|awk '{print $1 ":" $3 ":" $4}')
if [[ "$tmp" != "drwxr-xr-x:0:0" ]] ; then
mk_tmp_dir_error $FULL_DIR
fi
@@ -1520,7 +1520,7 @@ function upvar() {
## Like uniq, but doesnt require a sorted list, implemented in awk.
#---------------------------------------------------------------------
function awkuniq() {
- awk '{ if ( seen[$0] != 1) { seen[$0]=1;print $0;}}'
+ awk '{if (!($0 in seen)) { seen[$0]; print }}'
}

#---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/libstate
b/var/lib/sorcery/modules/libstate
index 81ee6d4..2f3f94a 100755
--- a/var/lib/sorcery/modules/libstate
+++ b/var/lib/sorcery/modules/libstate
@@ -187,7 +187,7 @@ function get_depends_options()
esc_str "$1" START
debug "libstate" "get_depends_options() - START=$START"
lock_file "$depends_status"
- awk -F ':' -v start=$START "{ if (\$1 == start) if (\$3 == \"on\") OPTS =
OPTS \" \" \$5; else OPTS = OPTS \" \" \$6; } END { print OPTS; }"
$depends_status 2> /dev/null
+ awk -F ':' -v start=$START '$1 == start { OPTS = OPTS " " ($3 == "on" ? $5
: $6) } END { print OPTS }' $depends_status 2> /dev/null
unlock_file "$depends_status"
}

@@ -249,9 +249,9 @@ function toggle_depends_status() {
local t_status
lock_start_transaction "$depends_status" t_status
awk -F ':' -v OFS=':' \
- '/^'$spell:$dependency':(on|off):(optional|suggest):/ \
- { if ($3 == "on") $3 = "off"; else $3 = "on"; }
- { print; }' $depends_status > $t_status
+ -v re="^$spell:$dependency:(on|off):(optional|suggest):" -- \
+ '$0 ~ re { $3 = ($3 == "on") ? "off" : "on" } { print; }' \
+ $depends_status > $t_status
lock_commit_transaction "$depends_status"
}

@@ -728,10 +728,10 @@ function query_spell_status()
if [[ -z $3 ]]; then
[[ -z $2 ]] && return 0
return_var="$2"
- __status=$(awk -F: -v spell="$1" '{ if (spell == $1) status=$3 }
END{print status}' "$SPELL_STATUS" 2>/dev/null)
+ __status=$(awk -F: -v spell="$1" '$1 == spell { status = $3 } END {
print status }' "$SPELL_STATUS" 2>/dev/null)
else
return_var="$3"
- __status=$(awk -F: -v spell="$1" -v version="$2" '{ if (spell == $1 &&
version == $4) status=$3 } END{print status}' "$SPELL_STATUS" 2>/dev/null)
+ __status=$(awk -F: -v spell="$1" -v version="$2" '$1 == spell && $4 ==
version { status = $3 } END { print status }' "$SPELL_STATUS" 2>/dev/null)
fi
unlock_file "$SPELL_STATUS"

@@ -991,10 +991,9 @@ function get_all_spells_with_status () {
local status=$1
lock_file $SPELL_STATUS
if [[ $status != ok ]]; then
- gawk -F: 'BEGIN { status="'$status'" }
- ($3 == status) { print $1 }' $SPELL_STATUS
+ awk -F: -v status="$status" '$3 == status { print $1 }' $SPELL_STATUS
else
- awk -F: '{ if ($3 == "installed" || $3 == "held") print $1 }'
$SPELL_STATUS
+ awk -F: '$3 == "installed" || $3 == "held" { print $1 }' $SPELL_STATUS
fi
unlock_file $SPELL_STATUS
}
diff --git a/var/lib/sorcery/modules/libtime b/var/lib/sorcery/modules/libtime
index 02cdd60..0b6e68a 100755
--- a/var/lib/sorcery/modules/libtime
+++ b/var/lib/sorcery/modules/libtime
@@ -19,7 +19,7 @@
## @Stdout casting time(s)
#---------------------------------------------------------------------
function compute_cast_times() {
- gawk -v spell=$1 -v version=$2 '
+ awk -v spell=$1 -v version=$2 '
# log timestamps are in the "%Y%m%d:%H%M\(%z\)" format
(20080625:0853(+0000))
# we need them in "%Y %m %d %H %M %S" and %s (epoch time). We ignore the
# timezone, since the time is stored in UTC and %z is always +0000
@@ -134,24 +134,23 @@ function compute_all_cast_times() {
## @Stdout mean and its error
#---------------------------------------------------------------------
function compute_mean() {
- gawk '
- BEGIN { mean = 0; variance = 0; }
-
- { sum += $0; numbers[NR] = $0; }
-
+ awk '
+ {
+ sum += $0
+ numbers[NR] = $0
+ }
END {
if (NR == 0) exit
- mean = sum/NR;
+ mean = sum / NR
if (NR == 1) {
- error = 0;
+ error = 0
} else {
- for (i in numbers) {
- variance += (numbers[i] - mean)^2;
- }
- error = int(sqrt(variance/(NR-1)/NR)*1.96 + 0.5);
+ variance = 0
+ for (i in numbers)
+ variance += (numbers[i] - mean) ^ 2
+ error = int(sqrt(variance / (NR-1) / NR) * 1.96 + .5);
}
-
- print int(mean+0.5), error
+ print int(mean + .5), error
}'
}

@@ -216,8 +215,8 @@ function compute_median() {
#---------------------------------------------------------------------
function compute_total_error() {
tr ' ' '\n' <<< "$@" |
- gawk '
- { total += $0^2 }
+ awk '
+ { total += $0 ^ 2 }

END {
print int(sqrt(total))
diff --git a/var/lib/sorcery/modules/liburl b/var/lib/sorcery/modules/liburl
index f9e993f..a4f26f9 100755
--- a/var/lib/sorcery/modules/liburl
+++ b/var/lib/sorcery/modules/liburl
@@ -300,17 +300,12 @@ function url_rank() {
for tmp_prefix in $(hash_get_table_fields url_div_hash) ; do
hash_get_ref url_div_hash $tmp_prefix tmp_list
debug liburl "urls are $tmp_list"
- # the awk command turns netselect output like this:
- # 69 url1
- # 234 url2
- # into the following bash code, which is then executed
- # url_speed[69]="${url_speed[69]} url1"
- # url_speed[234]="${url_speed[234]} url2"
- eval $(url_netselect $tmp_list|
- awk '{ if ($2 > 0 && $2 < 65536 ) {
- printf "url_speed[%s]=\"${url_speed[%s]} %s\";",$1,$1,$2
- }
- }')
+ url_netselect $tmp_list |
+ awk '$2 > 0 && $2 < 65536 { print $1, $2 }' |
+ while read a b; do
+ url_speed[$a]+=" $b"
+ done
+
done

# since we put things in url_speed indexed by speed, the * should




Archive powered by MHonArc 2.6.24.

Top of Page