Eliminate four copy-paste versions of nibble(), stick to rpmstring.h
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 8 Apr 2008 09:35:36 +0000 (12:35 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 8 Apr 2008 09:35:36 +0000 (12:35 +0300)
- the one in signature.c wasn't even used...

lib/query.c
lib/rpmfi.c
lib/signature.c
rpmdb/rpmdb.c
rpmio/rpmstring.h

index 20068af..8791c37 100644 (file)
@@ -390,22 +390,6 @@ int rpmcliShowMatches(QVA_t qva, rpmts ts)
     return ec;
 }
 
-/**
- * Convert hex to binary nibble.
- * @param c            hex character
- * @return             binary nibble
- */
-static inline unsigned char nibble(char c)
-{
-    if (c >= '0' && c <= '9')
-       return (c - '0');
-    if (c >= 'A' && c <= 'F')
-       return (c - 'A') + 10;
-    if (c >= 'a' && c <= 'f')
-       return (c - 'a') + 10;
-    return 0;
-}
-
 /* LCL: segfault (realpath annotation?) */
 int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
 {
@@ -473,7 +457,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
 
        MD5[0] = '\0';
         for (i = 0, t = MD5, s = arg; i < 16; i++, t++, s += 2)
-            *t = (nibble(s[0]) << 4) | nibble(s[1]);
+            *t = (rnibble(s[0]) << 4) | rnibble(s[1]);
        
        qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_SIGMD5, MD5, sizeof(MD5));
        if (qva->qva_mi == NULL) {
@@ -514,7 +498,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg)
 
        MD5[0] = '\0';
         for (i = 0, t = MD5, s = arg; i < 16; i++, t++, s += 2)
-            *t = (nibble(s[0]) << 4) | nibble(s[1]);
+            *t = (rnibble(s[0]) << 4) | rnibble(s[1]);
 
        qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_FILEMD5S, MD5, sizeof(MD5));
        if (qva->qva_mi == NULL) {
index ab979f9..5905b4d 100644 (file)
@@ -1111,22 +1111,6 @@ fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
     return NULL;
 }
 
-/**
- * Convert hex to binary nibble.
- * @param c            hex character
- * @return             binary nibble
- */
-static inline unsigned char nibble(char c)
-{
-    if (c >= '0' && c <= '9')
-       return (c - '0');
-    if (c >= 'A' && c <= 'F')
-       return (c - 'A') + 10;
-    if (c >= 'a' && c <= 'f')
-       return (c - 'a') + 10;
-    return 0;
-}
-
 #define        _fdupe(_fi, _data)      \
     if ((_fi)->_data != NULL)  \
        (_fi)->_data = memcpy(xmalloc((_fi)->fc * sizeof(*(_fi)->_data)), \
@@ -1253,7 +1237,7 @@ if (fi->actions == NULL)
                continue;
            }
            for (j = 0; j < 16; j++, t++, fmd5 += 2)
-               *t = (nibble(fmd5[0]) << 4) | nibble(fmd5[1]);
+               *t = (rnibble(fmd5[0]) << 4) | rnibble(fmd5[1]);
        }
        fi->fmd5s = hfd(fi->fmd5s, RPM_FORCEFREE_TYPE);
     }
index 787448c..bbcaba6 100644 (file)
@@ -1070,22 +1070,6 @@ exit:
 }
 
 /**
- * Convert hex to binary nibble.
- * @param c            hex character
- * @return             binary nibble
- */
-static inline unsigned char nibble(char c)
-{
-    if (c >= '0' && c <= '9')
-       return (c - '0');
-    if (c >= 'A' && c <= 'F')
-       return (c - 'A') + 10;
-    if (c >= 'a' && c <= 'f')
-       return (c - 'a') + 10;
-    return 0;
-}
-
-/**
  * Verify RSA signature.
  * @param ts           transaction set
  * @retval msg         rbose success/failure text
index d00cdfa..6f96ade 100644 (file)
@@ -87,22 +87,6 @@ static inline pbm_set * PBM_REALLOC(pbm_set ** sp, int * odp, int nd)
     return *sp;
 }
 
-/**
- * Convert hex to binary nibble.
- * @param c            hex character
- * @return             binary nibble
- */
-static inline unsigned char nibble(char c)
-{
-    if (c >= '0' && c <= '9')
-       return (c - '0');
-    if (c >= 'A' && c <= 'F')
-       return (c - 'A') + 10;
-    if (c >= 'a' && c <= 'f')
-       return (c - 'a') + 10;
-    return 0;
-}
-
 #ifdef DYING
 /**
  * Check key for printable characters.
@@ -2574,7 +2558,7 @@ if (dbiByteSwapped(dbi) == 1)
                        s = rpmvals[i];
                        t = bin;
                        for (j = 0; j < 16; j++, t++, s += 2)
-                           *t = (nibble(s[0]) << 4) | nibble(s[1]);
+                           *t = (rnibble(s[0]) << 4) | rnibble(s[1]);
                        key->data = bin;
                        key->size = 16;
                        break;
@@ -2977,7 +2961,7 @@ data->size = 0;
                        s = rpmvals[i];
                        t = bin;
                        for (j = 0; j < 16; j++, t++, s += 2)
-                           *t = (nibble(s[0]) << 4) | nibble(s[1]);
+                           *t = (rnibble(s[0]) << 4) | rnibble(s[1]);
                        key->data = bin;
                        key->size = 16;
                        break;
index cb8bc7a..5b8af0c 100644 (file)
@@ -77,6 +77,22 @@ static inline int rtoupper(int c)  {
     return ((rislower(c)) ? (c & ~('a' - 'A')) : c);
 }
 
+/**
+ * Convert hex to binary nibble.
+ * @param c            hex character
+ * @return             binary nibble
+ */
+static inline unsigned char rnibble(char c)
+{
+    if (c >= '0' && c <= '9')
+       return (c - '0');
+    if (c >= 'A' && c <= 'F')
+       return (c - 'A') + 10;
+    if (c >= 'a' && c <= 'f')
+       return (c - 'a') + 10;
+    return 0;
+}
+
 /** \ingroup rpmstring
  * Locale insensitive strcasecmp(3).
  */