On Sat, 12 Nov 2005, Xun Sun wrote:

On 11/12/05, David Lee <[EMAIL PROTECTED]> wrote:
On Sat, 12 Nov 2005, Xun Sun wrote:

Hi David,

In this commit you defined ocf_is_hexadecimal in ocf-shellfuncs.in,
but used ocf_is_hex in other places, which looks inconsistent to me.
Unfortunately you seem unaware of this problem even though I mentioned
it in my last two mails ;-)

So I have just committed a one-liner fix for this. Feel free to change
to other appropriate things.

Yes.  My mistake entirely, for which my apologies.  Thanks for fixing it.

I also saw your other point about my re-implementing the pattern matching
(rewriting the "case" statement into a "tr").  I'm still looking at that.

The original "case" was failing on my Solaris "sh", hence my looking for

How did it fail, syntax error or giving wrong output (in this case it
is possible that my original script is faulty) ? Could you please send
me a transcript if possible?

It turned out to be a very simple thing. The "case" syntax "[^...]" (i.e. the "^" for negation) is non-portable. But changing this to "[!...]" (i.e. the "!") seems both functionally equivalent and portable.

Proposed patch attached.

--

:  David Lee                                I.T. Service          :
:  Senior Systems Programmer                Computer Centre       :
:                                           Durham University     :
:  http://www.dur.ac.uk/t.d.lee/            South Road            :
:                                           Durham DH1 3LE        :
:  Phone: +44 191 334 2752                  U.K.                  :
--- resources/OCF/ocf-shellfuncs.in.orig        Sat Nov 12 15:01:55 2005
+++ resources/OCF/ocf-shellfuncs.in     Sun Nov 13 12:20:31 2005
@@ -45,19 +45,42 @@
        [ $1 = "uid=0(root)" ]
 }
 
+# Portability comments:
+# o The following rely on Bourne "sh" pattern-matching, which is usually
+#   that for filename generation (note: not regexp).
+# o The "*) true ;;" clause is probably unnecessary, but is included
+#   here for completeness.
+# o The negation in the pattern uses "!".  This seems to be common
+#   across many OSes (whereas the alternative "^" fails on some).
+# o If an OS is encountered where this negation fails, then a possible
+#   alternative would be to replace the function contents by (e.g.):
+#      [ -z "`echo $1 | tr -d '[0-9]'`" ]
+#
 ocf_is_decimal() {
-        # test: delete all decimal digits: result should be zero-length
-        [ -z "`echo $1 | tr -d '[0-9]'`" ]
+       case "$1" in
+       *[!0-9]*)       # got invalid char
+               false ;;
+       *)
+               true ;;
+       esac
 }
 
 ocf_is_hex() {
-        # test: delete all hex digits: result should be zero-length
-        [ -z "`echo $1 | tr -d '[0-9a-fA-F]'`" ]
+       case "$1" in
+        *[!0-9a-fA-F]*)        # got invalid char
+               false ;;
+       *)
+               true ;;
+       esac
 }
 
 ocf_is_octal() {
-        # test: delete all octal digits: result should be zero-length
-        [ -z "`echo $1 | tr -d '[0-7]'`" ]
+       case "$1" in
+        *[!0-7]*)      # got invalid char
+               false ;;
+       *)
+               true ;;
+       esac
 }
 
 __ocf_set_defaults() {
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to