]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/fty_enum.c
ncurses 5.0
[ncurses.git] / form / fty_enum.c
index 0e128083689a7847a2a351946d0fe911ab60f289..9716159b384fe8ba77b5a459ba476770b675f569 100644 (file)
@@ -7,13 +7,13 @@
  */
 /***************************************************************************
 *                                                                          *
-*  Author : Juergen Pfeifer, Juergen.Pfeifer@T-Online.de                   *
+*  Author : Juergen Pfeifer, juergen.pfeifer@gmx.net                       *
 *                                                                          *
 ***************************************************************************/
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: fty_enum.c,v 1.5 1997/02/15 17:33:59 tom Exp $")
+MODULE_ID("$Id: fty_enum.c,v 1.10 1999/05/16 17:23:14 juergen Exp $")
 
 typedef struct {
   char **kwds;
@@ -63,15 +63,15 @@ static void *Make_Enum_Type(va_list * ap)
 static void *Copy_Enum_Type(const void * argp)
 {
   const enumARG *ap = (const enumARG *)argp;
-  enumARG *new = (enumARG *)0;
+  enumARG *result = (enumARG *)0;
 
   if (argp)
     {
-      new = (enumARG *)malloc(sizeof(enumARG));
-      if (new)
-       *new = *ap;
+      result = (enumARG *)malloc(sizeof(enumARG));
+      if (result)
+       *result = *ap;
     }
-  return (void *)new;
+  return (void *)result;
 }
 
 /*---------------------------------------------------------------------------
@@ -127,9 +127,8 @@ static int Compare(const unsigned char *s, const unsigned char *buf,
        } 
       else 
        {
-         while(toupper(*s)==toupper(*buf))
+         while(toupper(*s++)==toupper(*buf))
            {
-             s++;
              if (*buf++=='\0') return EXACT;
            }
        }
@@ -170,7 +169,7 @@ static bool Check_Enum_Field(FIELD * field, const void  * argp)
     {
       if ((res=Compare((unsigned char *)s,bp,ccase))!=NOMATCH)
        {
-         t=s;
+         p=t=s; /* t is at least a partial match */
          if ((unique && res!=EXACT)) 
            {
              while( (p = *kwds++) )
@@ -181,16 +180,19 @@ static bool Check_Enum_Field(FIELD * field, const void  * argp)
                        {
                          t = p;
                          break;
-                       }       
-                     t = (char *)0;
+                       }
+                     else
+                       t = (char *)0;
                    }
                }
-           }
+           }     
          if (t)
            {
              set_field_buffer(field,0,t);
              return TRUE;
            }
+         if (!p)
+           break;
        }
     }
   return FALSE;