-# $MirOS: src/bin/mksh/dot.mkshrc,v 1.59 2011/02/09 19:32:35 tg Exp $
+# $MirOS: src/bin/mksh/dot.mkshrc,v 1.64 2011/07/18 00:35:45 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
# Thorsten Glaser <tg@mirbsd.org>
# Jenkins one-at-a-time hash (not via stdio, for speed)
typeset -Z11 -Uui16 Loaathash_result
+if true; then
+# not NUL safe
function Loaathash_add {
- [[ -o utf8-mode ]]; typeset u=$?
+ [[ -o utf8-mode ]]; local u=$?
set +U
- typeset s="$*"
+ local s="$*"
[[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
- typeset -i i=0 n=${#s}
+ local -i i=0 n=${#s}
while (( i < n )); do
((# Loaathash_result = (Loaathash_result + 1#${s:(i++):1}) *
(( u )) || set -U
}
+else
+# NUL safe; needs mksh R40
+function Loaathash_add {
+ [[ -o utf8-mode ]]; local u=$?
+ set +U
+ local s
+ if (( $# )); then
+ read -raN-1 s <<<"$*"
+ unset s[${#s[*]}-1]
+ else
+ read -raN-1 s
+ fi
+ local -i i=0 n=${#s[*]}
+
+ while (( i < n )); do
+ ((# Loaathash_result = (Loaathash_result + s[i++]) *
+ 1025 ))
+ ((# Loaathash_result ^= Loaathash_result >> 6 ))
+ done
+
+ (( u )) || set -U
+}
+fi
function Loaathash_do {
Loaathash_add "$@"
((# Loaathash_result += Loaathash_result << 3 ))