All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dracut-functions: fun. vercmp optimized; credits go to Victor Lowther
@ 2010-06-09 15:29 Amadeusz Żołnowski
       [not found] ` <20100609172936.752221c5-YdJE6FOikKfe60hTmSeVGxfX6IwIUJvj@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Amadeusz Żołnowski @ 2010-06-09 15:29 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 1222 bytes --]

---
 dracut-functions |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/dracut-functions b/dracut-functions
index fbac282..500e3ae 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -27,19 +27,20 @@ strstr() { [[ $1 =~ $2 ]]; }
 # Version comparision function.  Returns result similar to C strcmp,
 # but instead of -1 is 2.  Function assumes version scheme like does
 # Linux kernel.
+# $1 < $2 -> 2
+# $1 = $2 -> 0
+# $1 > $2 -> 1
+# To remember it easy, ask the question: Which argument is greater? ;-)
 vercmp() {
-    local n1 n2 i=1
-
-    while true
-    do
-        n1=$(echo $1 | cut -d'.' -f$i)
-        n2=$(echo $2 | cut -d'.' -f$i)
-
-        [[ ! $n1 && ! $n2 ]] && return 0
-        [[ $n1 -lt $n2 ]] && return 2
-        [[ $n1 -gt $n2 ]] && return 1
-
-        ((i++))
+    local i n1=(${1//./ }) n2=(${2//./ })
+
+    for ((i=0; ; i++))
+    do 
+        [[ ${n1[i]} && ! ${n2[i]} ]] && return 1
+        [[ ! ${n1[i]} && ${n2[i]} ]] && return 2
+        [[ ${n1[i]} && ${n2[i]} ]] || return 0
+        ((${n1[i]} > ${n2[i]})) && return 1
+        ((${n1[i]} < ${n2[i]})) && return 2
     done
 }
 
-- 
1.7.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-06-09 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-09 15:29 [PATCH] dracut-functions: fun. vercmp optimized; credits go to Victor Lowther Amadeusz Żołnowski
     [not found] ` <20100609172936.752221c5-YdJE6FOikKfe60hTmSeVGxfX6IwIUJvj@public.gmane.org>
2010-06-09 15:40   ` Harald Hoyer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.