]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/fty_enum.c
ncurses 6.2 - patch 20210619
[ncurses.git] / form / fty_enum.c
index d3351644ef1849f2aa9de6dfd7ab31674cc08e8c..16ffae11036fa1429353e7c92889238df0216ee1 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 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.26 2010/05/01 21:11:07 tom Exp $")
+MODULE_ID("$Id: fty_enum.c,v 1.33 2021/06/17 21:11:08 tom Exp $")
 
 typedef struct
   {
@@ -54,9 +55,9 @@ typedef struct
 enumParams;
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void *Generic_Enum_Type(void * arg)
-|   
+|
 |   Description   :  Allocate structure for enumeration type argument.
 |
 |   Return Values :  Pointer to argument structure or NULL on error
@@ -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,7 +77,6 @@ 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"), (void *)argp));
@@ -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)
@@ -117,9 +119,9 @@ Generic_Enum_Type(void *arg)
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void *Make_Enum_Type( va_list * ap )
-|   
+|
 |   Description   :  Allocate structure for enumeration type argument.
 |
 |   Return Values :  Pointer to argument structure or NULL on error
@@ -137,10 +139,10 @@ Make_Enum_Type(va_list *ap)
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void *Copy_Enum_Type( const void * argp )
-|   
-|   Description   :  Copy structure for enumeration type argument.  
+|
+|   Description   :  Copy structure for enumeration type argument.
 |
 |   Return Values :  Pointer to argument structure or NULL on error.
 +--------------------------------------------------------------------------*/
@@ -181,9 +183,9 @@ Copy_Enum_Type(const void *argp)
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static void Free_Enum_Type( void * argp )
-|   
+|
 |   Description   :  Free structure for enumeration type argument.
 |
 |   Return Values :  -
@@ -218,11 +220,11 @@ Free_Enum_Type(void *argp)
 #define EXACT   2
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
-|   Function      :  static int Compare(const unsigned char * s,  
+|   Facility      :  libnform
+|   Function      :  static int Compare(const unsigned char * s,
 |                                       const unsigned char * buf,
 |                                       bool  ccase )
-|   
+|
 |   Description   :  Check whether or not the text in 'buf' matches the
 |                    text in 's', at least partial.
 |
@@ -273,11 +275,11 @@ Compare(const unsigned char *s, const unsigned char *buf,
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static bool Check_Enum_Field(
 |                                      FIELD * field,
 |                                      const void  * argp)
-|   
+|
 |   Description   :  Validate buffer content to be a valid enumeration value
 |
 |   Return Values :  TRUE  - field is valid
@@ -291,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 */
@@ -330,10 +333,10 @@ static const char *dummy[] =
 {(char *)0};
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static bool Next_Enum(FIELD * field,
 |                                          const void * argp)
-|   
+|
 |   Description   :  Check for the next enumeration value
 |
 |   Return Values :  TRUE  - next value found and loaded
@@ -367,11 +370,11 @@ Next_Enum(FIELD *field, const void *argp)
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  static bool Previous_Enum(
 |                                          FIELD * field,
 |                                          const void * argp)
-|   
+|
 |   Description   :  Check for the previous enumeration value
 |
 |   Return Values :  TRUE  - previous value found and loaded
@@ -424,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;