]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/fty_enum.c
ncurses 6.2 - patch 20210605
[ncurses.git] / form / fty_enum.c
index c249b5b039632a203c42dad423e9b0622cb301c3..c3a27ffa76e87979ab432ccea9da40649978eadd 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2009 Free Software Foundation, Inc.              *
+ * Copyright 2020,2021 Thomas E. Dickey                                     *
+ * Copyright 1998-2009,2010 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            *
@@ -34,7 +35,7 @@
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: fty_enum.c,v 1.24 2009/11/07 20:17:58 tom Exp $")
+MODULE_ID("$Id: fty_enum.c,v 1.32 2021/03/27 23:49:53 tom Exp $")
 
 typedef struct
   {
@@ -65,7 +66,7 @@ static void *
 Generic_Enum_Type(void *arg)
 {
   enumARG *argp = (enumARG *)0;
-  enumParams *params = (enumParams *) arg;
+  enumParams *params = (enumParams *)arg;
 
   if (params)
     {
@@ -76,10 +77,9 @@ Generic_Enum_Type(void *arg)
          int cnt = 0;
          char **kp = (char **)0;
          char **kwds = (char **)0;
-         char **kptarget;
          int ccase, cunique;
 
-         T((T_CREATE("enumARG %p"), argp));
+         T((T_CREATE("enumARG %p"), (void *)argp));
          kwds = params->kwds;
          ccase = params->ccase;
          cunique = params->cunique;
@@ -95,6 +95,8 @@ Generic_Enum_Type(void *arg)
 
          if (cnt > 0)
            {
+             char **kptarget;
+
              /* We copy the keywords, because we can't rely on the fact
                 that the caller doesn't relocate or free the memory used
                 for the keywords (maybe he has GC)
@@ -102,12 +104,14 @@ Generic_Enum_Type(void *arg)
              argp->kwds = typeMalloc(char *, cnt + 1);
 
              kp = kwds;
-             kptarget = argp->kwds;
-             while (kptarget && kp && (*kp))
+             if ((kptarget = argp->kwds) != 0)
                {
-                 (*kptarget++) = strdup(*kp++);
+                 while (kp && (*kp))
+                   {
+                     (*kptarget++) = strdup(*kp++);
+                   }
+                 *kptarget = (char *)0;
                }
-             *kptarget = (char *)0;
            }
        }
     }
@@ -155,7 +159,7 @@ Copy_Enum_Type(const void *argp)
 
       if (result)
        {
-         T((T_CREATE("enumARG %p"), result));
+         T((T_CREATE("enumARG %p"), (void *)result));
          *result = *ap;
 
          if (ap->count > 0)
@@ -164,12 +168,14 @@ Copy_Enum_Type(const void *argp)
              char **kp = ap->kwds;
              result->kwds = typeMalloc(char *, 1 + ap->count);
 
-             kptarget = result->kwds;
-             while (kptarget && kp && (*kp))
+             if ((kptarget = result->kwds) != 0)
                {
-                 (*kptarget++) = strdup(*kp++);
+                 while (kp && (*kp))
+                   {
+                     (*kptarget++) = strdup(*kp++);
+                   }
+                 *kptarget = (char *)0;
                }
-             *kptarget = (char *)0;
            }
        }
     }
@@ -287,10 +293,11 @@ Check_Enum_Field(FIELD *field, const void *argp)
   bool unique = ((const enumARG *)argp)->checkunique;
   unsigned char *bp = (unsigned char *)field_buffer(field, 0);
   char *s, *t, *p;
-  int res;
 
   while (kwds && (s = (*kwds++)))
     {
+      int res;
+
       if ((res = Compare((unsigned char *)s, bp, ccase)) != NOMATCH)
        {
          p = t = s;            /* t is at least a partial match */
@@ -420,15 +427,14 @@ static FIELDTYPE typeENUM =
 #endif
 };
 
-NCURSES_EXPORT_VAR(FIELDTYPE *)
-TYPE_ENUM = &typeENUM;
+FORM_EXPORT_VAR(FIELDTYPE *) TYPE_ENUM = &typeENUM;
 
 #if NCURSES_INTEROP_FUNCS
 /* The next routines are to simplify the use of ncurses from
-   programming languages with restictions on interop with C level
+   programming languages with restrictions on interop with C level
    constructs (e.g. variable access or va_list + ellipsis constructs)
 */
-NCURSES_EXPORT(FIELDTYPE *)
+FORM_EXPORT(FIELDTYPE *)
 _nc_TYPE_ENUM(void)
 {
   return TYPE_ENUM;