]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/picsmap.c
ncurses 6.2 - patch 20200718
[ncurses.git] / test / picsmap.c
index 624eda88959080ce6126945e62f1f0982a690160..3c4eb697a4de710a91be75b4e3aa3732bff09dbb 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2017-2018,2019 Free Software Foundation, Inc.              *
+ * Copyright 2018-2019,2020 Thomas E. Dickey                                *
+ * Copyright 2017,2018 Free Software Foundation, Inc.                       *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -26,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: picsmap.c,v 1.131 2019/12/14 23:51:39 tom Exp $
+ * $Id: picsmap.c,v 1.134 2020/07/11 23:01:49 tom Exp $
  *
  * Author: Thomas E. Dickey
  *
  *
  * Author: Thomas E. Dickey
  *
@@ -954,6 +955,20 @@ parse_rgb(char **data)
     return result;
 }
 
     return result;
 }
 
+#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
+
+static int
+CaselessCmp(const char *a, const char *b)
+{                              /* strcasecmp isn't portable */
+    while (*a && *b) {
+       int cmp = LOWERCASE(*a) - LOWERCASE(*b);
+       if (cmp != 0)
+           break;
+       a++, b++;
+    }
+    return LOWERCASE(*a) - LOWERCASE(*b);
+}
+
 static RGB_NAME *
 lookup_rgb(const char *name)
 {
 static RGB_NAME *
 lookup_rgb(const char *name)
 {
@@ -961,7 +976,7 @@ lookup_rgb(const char *name)
     if (rgb_table != 0) {
        int n;
        for (n = 0; rgb_table[n].name != 0; ++n) {
     if (rgb_table != 0) {
        int n;
        for (n = 0; rgb_table[n].name != 0; ++n) {
-           if (!strcasecmp(name, rgb_table[n].name)) {
+           if (!CaselessCmp(name, rgb_table[n].name)) {
                result = &rgb_table[n];
                break;
            }
                result = &rgb_table[n];
                break;
            }