]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/infocmp.c
ncurses 6.4 - patch 20231202
[ncurses.git] / progs / infocmp.c
index c1b95088b113e23c0cbb990032a719a35aa9194c..69a6483d587cc62c8dd63b3a458f600673b28391 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2020-2021,2022 Thomas E. Dickey                                *
+ * Copyright 2020-2022,2023 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -43,7 +43,7 @@
 
 #include <dump_entry.h>
 
-MODULE_ID("$Id: infocmp.c,v 1.155 2022/09/03 23:28:48 tom Exp $")
+MODULE_ID("$Id: infocmp.c,v 1.159 2023/12/02 17:29:01 tom Exp $")
 
 #define MAX_STRING     1024    /* maximum formatted string */
 
@@ -158,7 +158,7 @@ no_numeric(int value)
 }
 
 static bool
-no_string(char *value)
+no_string(const char *const value)
 {
     bool result = (value == ABSENT_STRING);
     if (!strcmp(s_absent, s_cancel))
@@ -209,15 +209,18 @@ use_predicate(unsigned type, PredIdx idx)
             * unlike numbers and strings, whose cancelled/absent state is
             * recorded in the terminfo database.
             */
-           for (ep = &entries[1]; ep < entries + termcount; ep++)
-               if (ep->tterm.Booleans[idx] == TRUE) {
-                   is_set = entries[0].tterm.Booleans[idx];
-                   break;
+           if (idx < NUM_BOOLEANS(&(entries[0].tterm))) {
+               for (ep = &entries[1]; ep < entries + termcount; ep++) {
+                   if (idx < NUM_BOOLEANS(&(ep->tterm))
+                       && ep->tterm.Booleans[idx] == TRUE) {
+                       is_set = entries[0].tterm.Booleans[idx];
+                       break;
+                   }
                }
-           if (is_set != entries[0].tterm.Booleans[idx])
-               return (!is_set);
-           else
-               return (FAIL);
+               if (is_set != entries[0].tterm.Booleans[idx])
+                   return (!is_set);
+           }
+           return (FAIL);
        }
 
     case NUMBER:
@@ -229,16 +232,18 @@ use_predicate(unsigned type, PredIdx idx)
             * capability gets the first non-default value found
             * in the sequence of use entries'.
             */
-           for (ep = &entries[1]; ep < entries + termcount; ep++)
-               if (VALID_NUMERIC(ep->tterm.Numbers[idx])) {
-                   value = ep->tterm.Numbers[idx];
-                   break;
-               }
+           if (idx < NUM_NUMBERS(&(entries[0].tterm))) {
+               for (ep = &entries[1]; ep < entries + termcount; ep++)
+                   if (idx < NUM_NUMBERS(&(ep->tterm))
+                       && VALID_NUMERIC(ep->tterm.Numbers[idx])) {
+                       value = ep->tterm.Numbers[idx];
+                       break;
+                   }
 
-           if (value != entries[0].tterm.Numbers[idx])
-               return (value != ABSENT_NUMERIC);
-           else
-               return (FAIL);
+               if (value != entries[0].tterm.Numbers[idx])
+                   return (value != ABSENT_NUMERIC);
+           }
+           return (FAIL);
        }
 
     case STRING:
@@ -252,18 +257,20 @@ use_predicate(unsigned type, PredIdx idx)
             * capability gets the first non-default value found
             * in the sequence of use entries'.
             */
-           for (ep = &entries[1]; ep < entries + termcount; ep++)
-               if (ep->tterm.Strings[idx]) {
-                   usestr = ep->tterm.Strings[idx];
-                   break;
-               }
+           if (idx < NUM_STRINGS(&(entries[0].tterm))) {
+               for (ep = &entries[1]; ep < entries + termcount; ep++)
+                   if (idx < NUM_STRINGS(&(ep->tterm))
+                       && ep->tterm.Strings[idx]) {
+                       usestr = ep->tterm.Strings[idx];
+                       break;
+                   }
 
-           if (usestr == ABSENT_STRING && termstr == ABSENT_STRING)
-               return (FAIL);
-           else if (!usestr || !termstr || capcmp(idx, usestr, termstr))
-               return (TRUE);
-           else
-               return (FAIL);
+               if (usestr == ABSENT_STRING && termstr == ABSENT_STRING)
+                   return (FAIL);
+               else if (!usestr || !termstr || capcmp(idx, usestr, termstr))
+                   return (TRUE);
+           }
+           return (FAIL);
        }
     }
 
@@ -905,7 +912,6 @@ analyze_string(const char *name, const char *cap, TERMTYPE2 *tp)
                       sizeof(buf2));
            _nc_STRNCPY(buf3, sp + csi, len);
            buf3[len] = '\0';
-           len += (size_t) csi + 1;
 
            expansion = lookup_params(std_modes, buf2, buf3);
        }
@@ -926,7 +932,6 @@ analyze_string(const char *name, const char *cap, TERMTYPE2 *tp)
                       sizeof(buf2));
            _nc_STRNCPY(buf3, sp + csi + 1, len);
            buf3[len] = '\0';
-           len += (size_t) csi + 2;
 
            expansion = lookup_params(private_modes, buf2, buf3);
        }
@@ -1860,8 +1865,16 @@ main(int argc, char *argv[])
        }
 
 #if NCURSES_XNAMES
-       if (termcount > 1)
-           _nc_align_termtype(&entries[0].tterm, &entries[1].tterm);
+       if (termcount > 1) {
+           /*
+            * User-defined capabilities in different terminal descriptions
+            * may have the same name/type but different indices.  Line up
+            * the names to use comparable indices.  We may have more than two
+            * entries to compare when processing the "-u" option.
+            */
+           for (c = 1; c < termcount; ++c)
+               _nc_align_termtype(&entries[c].tterm, &entries[0].tterm);
+       }
 #endif
 
        /* dump as C initializer for the terminal type */