[PATCH v1 3/3] Use memeq() instead of its pattern

Alejandro Colomar <[email protected]>
Newsgroups gmane.comp.printing.groff.general
Message-ID <682f6c9f7e48fab7a4cb5e0a573d548c19194b7b.1771717050.git.alx@kernel.org>
Signed-off-by: Alejandro Colomar <[email protected]>
---
 src/devices/grops/psrm.cpp      |  8 ++++----
 src/include/stringclass.h       |  8 +++-----
 src/libs/libbib/index.cpp       |  2 +-
 src/preproc/preconv/preconv.cpp |  2 +-
 src/preproc/refer/label.ypp     | 14 ++++++--------
 src/preproc/refer/ref.cpp       |  4 ++--
 src/preproc/refer/refer.cpp     |  2 +-
 src/preproc/refer/token.cpp     |  2 +-
 src/utils/indxbib/indxbib.cpp   |  2 +-
 src/utils/tfmtodit/tfmtodit.cpp |  2 +-
 10 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/devices/grops/psrm.cpp b/src/devices/grops/psrm.cpp
index e8c931953c10..67123fe06289 100644
--- a/src/devices/grops/psrm.cpp
+++ b/src/devices/grops/psrm.cpp
@@ -198,7 +198,7 @@ resource *resource_manager::lookup_font(const char *name)
   for (r = resource_list; r; r = r->next)
     if (r->type == RESOURCE_FONT
 	&& strlen(name) == (size_t)r->name.length()
-	&& memcmp(name, r->name.contents(), r->name.length()) == 0)
+	&& memeq(name, r->name.contents(), r->name.length()))
       return r;
   string s(name);
   r = new resource(RESOURCE_FONT, s);
@@ -737,7 +737,7 @@ int read_one_of(const char **ptr, const char **s, int n)
   } while (**ptr != '\0' && !white_space(**ptr));
   for (int i = 0; i < n; i++)
     if (strlen(s[i]) == size_t(*ptr - start)
-	&& memcmp(s[i], start, *ptr - start) == 0)
+	&& memeq(s[i], start, *ptr - start))
       return i;
   return -1;
 }
@@ -907,7 +907,7 @@ static unsigned parse_extensions(const char *ptr)
     size_t i;
     for (i = 0; i < NEXTENSIONS; i++)
       if (strlen(extension_table[i]) == size_t(ptr - name)
-	  && memcmp(extension_table[i], name, ptr - name) == 0) {
+	  && memeq(extension_table[i], name, ptr - name)) {
 	flags |= (1 << i);
 	break;
       }
@@ -984,7 +984,7 @@ void resource_manager::process_file(int rank, FILE *fp,
     return;
   }
   if ((size_t)buf.length() < sizeof PS_MAGIC
-      || memcmp(buf.contents(), PS_MAGIC, (sizeof PS_MAGIC) - 1) != 0) {
+      || !memeq(buf.contents(), PS_MAGIC, (sizeof PS_MAGIC) - 1)) {
     if (outfp) {
       do {
 	if (!(broken_flags & STRIP_PERCENT_BANG)
diff --git a/src/include/stringclass.h b/src/include/stringclass.h
index 4640586bd5ae..73ce92dd392a 100644
--- a/src/include/stringclass.h
+++ b/src/include/stringclass.h
@@ -20,7 +20,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 #define GROFF_STRINGCLASS_H
 
 #include <assert.h>
-#include <string.h> // memcmp(), strlen()
+#include <string.h> // strlen()
 #include <stdio.h> // FILE
 
 // Ensure that the first declaration of functions that are later
@@ -160,14 +160,12 @@ inline string operator+(char c, const string &s)
 
 inline int operator==(const string &s1, const string &s2)
 {
-  return (s1.len == s2.len
-	  && (s1.len == 0 || memcmp(s1.ptr, s2.ptr, s1.len) == 0));
+  return (s1.len == s2.len && (s1.len == 0 || memeq(s1.ptr, s2.ptr, s1.len)));
 }
 
 inline int operator!=(const string &s1, const string &s2)
 {
-  return (s1.len != s2.len
-	  || (s1.len != 0 && memcmp(s1.ptr, s2.ptr, s1.len) != 0));
+  return (s1.len != s2.len || (s1.len != 0 && !memeq(s1.ptr, s2.ptr, s1.len)));
 }
 
 inline string string::substring(int i, int n) const
diff --git a/src/libs/libbib/index.cpp b/src/libs/libbib/index.cpp
index 0ccf0b866479..f33a560c2bc7 100644
--- a/src/libs/libbib/index.cpp
+++ b/src/libs/libbib/index.cpp
@@ -533,7 +533,7 @@ const int *index_search_item::search1(const char **pp, const char *end)
 	 common_words_table[h];
 	 --h) {
       if (strlen(common_words_table[h]) == (size_t)len
-	  && memcmp(common_words_table[h], key_buffer, len) == 0)
+	  && memeq(common_words_table[h], key_buffer, len))
 	return 0;
       if (h == 0)
 	h = common_words_table_size;
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index b35257f7d460..a7d54795635e 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -823,7 +823,7 @@ get_BOM(FILE *fp, string &BOM, string &data)
   int i;
   for (i = 0; i < BOM_table_len; i++) {
     if (BOM_table[i].len <= len
-	&& memcmp(BOM_string, BOM_table[i].str, BOM_table[i].len) == 0)
+	&& memeq(BOM_string, BOM_table[i].str, BOM_table[i].len))
       break;
   }
   int j = 0;
diff --git a/src/preproc/refer/label.ypp b/src/preproc/refer/label.ypp
index 7c8774340cce..9e76f181ac8d 100644
--- a/src/preproc/refer/label.ypp
+++ b/src/preproc/refer/label.ypp
@@ -923,8 +923,7 @@ int reference::merge_labels_by_parts(reference **v, int n, label_type type,
   const substring_position &sp = get_separator_pos(type);
   if (sp.start < 0
       || sp.start != v[0]->get_separator_pos(type).start
-      || memcmp(lb.contents(), v[0]->get_label(type).contents(),
-		sp.start) != 0)
+      || !memeq(lb.contents(), v[0]->get_label(type).contents(), sp.start))
     return 0;
   result = lb;
   int i = 0;
@@ -936,8 +935,7 @@ int reference::merge_labels_by_parts(reference **v, int n, label_type type,
 		  v[i]->get_label(type).length() - sep_end_pos);
   } while (++i < n
 	   && sp.start == v[i]->get_separator_pos(type).start
-	   && memcmp(lb.contents(), v[i]->get_label(type).contents(),
-		     sp.start) == 0);
+	   && memeq(lb.contents(), v[i]->get_label(type).contents(), sp.start));
   return i;
 }
 
@@ -969,8 +967,8 @@ label_info *lookup_label(const string &label)
        ? (ptr = label_table + label_table_size - 1)
        : ptr--)
     if ((*ptr)->length == label.length()
-	&& memcmp(label_pool.contents() + (*ptr)->start, label.contents(),
-		  label.length()) == 0) {
+	&& memeq(label_pool.contents() + (*ptr)->start, label.contents(),
+		 label.length())) {
       (*ptr)->total += 1;
       return *ptr;
     }
@@ -1093,7 +1091,7 @@ int same_author_last_name(const reference &r1, const reference &r2, int n)
   const char *as2 = r2.get_sort_field(0, n, 0, &ae2);
   if (!as1 && !as2) return 1;	// they are the same
   if (!as1 || !as2) return 0;
-  return ae1 - as1 == ae2 - as2 && memcmp(as1, as2, ae1 - as1) == 0;
+  return ae1 - as1 == ae2 - as2 && memeq(as1, as2, ae1 - as1);
 }
 
 int same_author_name(const reference &r1, const reference &r2, int n)
@@ -1104,7 +1102,7 @@ int same_author_name(const reference &r1, const reference &r2, int n)
   const char *as2 = r2.get_sort_field(0, n, -1, &ae2);
   if (!as1 && !as2) return 1;	// they are the same
   if (!as1 || !as2) return 0;
-  return ae1 - as1 == ae2 - as2 && memcmp(as1, as2, ae1 - as1) == 0;
+  return ae1 - as1 == ae2 - as2 && memeq(as1, as2, ae1 - as1);
 }
 
 
diff --git a/src/preproc/refer/ref.cpp b/src/preproc/refer/ref.cpp
index 778af6f22eae..a73259a8723e 100644
--- a/src/preproc/refer/ref.cpp
+++ b/src/preproc/refer/ref.cpp
@@ -1097,7 +1097,7 @@ int same_year(const reference &r1, const reference &r2)
   else if (ye1 - ys1 != ye2 - ys2)
     return 0;
   else
-    return memcmp(ys1, ys2, ye1 - ys1) == 0;
+    return memeq(ys1, ys2, ye1 - ys1);
 }
 
 int same_date(const reference &r1, const reference &r2)
@@ -1113,7 +1113,7 @@ int same_date(const reference &r1, const reference &r2)
   else if (e1 - s1 != e2 - s2)
     return 0;
   else
-    return memcmp(s1, s2, e1 - s1) == 0;
+    return memeq(s1, s2, e1 - s1);
 }
 
 const char *reference::get_sort_field(int i, int si, int ssi,
diff --git a/src/preproc/refer/refer.cpp b/src/preproc/refer/refer.cpp
index f7a8346e61e4..6788d34069ca 100644
--- a/src/preproc/refer/refer.cpp
+++ b/src/preproc/refer/refer.cpp
@@ -453,7 +453,7 @@ static bool is_list(const string &str)
     end--;
   while (start < end && csspace(*start))
     start++;
-  return end - start == 6 && memcmp(start, "$LIST$", 6) == 0;
+  return end - start == 6 && memeq(start, "$LIST$", 6);
 }
 
 static void do_file(const char *filename)
diff --git a/src/preproc/refer/token.cpp b/src/preproc/refer/token.cpp
index 8cc697c6f244..77f458ff58e6 100644
--- a/src/preproc/refer/token.cpp
+++ b/src/preproc/refer/token.cpp
@@ -184,7 +184,7 @@ const token_info *lookup_token(const char *start, const char *end)
     if (token_table[n].tok == 0)
       break;
     if (strlen(token_table[n].tok) == size_t(end - start)
-	&& memcmp(token_table[n].tok, start, end - start) == 0)
+	&& memeq(token_table[n].tok, start, end - start))
       return &(token_table[n].ti);
     if (n == 0)
       n = TOKEN_TABLE_SIZE - 1;
diff --git a/src/utils/indxbib/indxbib.cpp b/src/utils/indxbib/indxbib.cpp
index 498ecd03479d..397f944345cf 100644
--- a/src/utils/indxbib/indxbib.cpp
+++ b/src/utils/indxbib/indxbib.cpp
@@ -744,7 +744,7 @@ static int store_key(char *s, int len)
   int h = hash(s, len) % hash_table_size;
   if (common_words_table) {
     for (word_list *ptr = common_words_table[h]; ptr; ptr = ptr->next)
-      if (len == ptr->len && memcmp(s, ptr->str, len) == 0)
+      if (len == ptr->len && memeq(s, ptr->str, len))
 	return 0;
   }
   table_entry *pp =  hash_table + h;
diff --git a/src/utils/tfmtodit/tfmtodit.cpp b/src/utils/tfmtodit/tfmtodit.cpp
index 40255006a7a8..b41e3b68dbb6 100644
--- a/src/utils/tfmtodit/tfmtodit.cpp
+++ b/src/utils/tfmtodit/tfmtodit.cpp
@@ -505,7 +505,7 @@ int gf::load(const char *file)
 	if (fread(buf, 1, len, fp) != (size_t)len)
 	  goto eof;
 	if (len == 10 /* strlen("adjustment") */
-	    && memcmp(buf, "adjustment", len) == 0) {
+	    && memeq(buf, "adjustment", len)) {
 	  int c = getc(fp);
 	  if (c != yyy) {
 	    if (c != EOF)
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.