X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffty_enum.c;h=16ffae11036fa1429353e7c92889238df0216ee1;hp=71978e3aeebd9c79aa6c5b860ec320b1f47635f5;hb=9f479192e3ca3413d235c66bf058f8cc63764898;hpb=47d2fb4537d9ad5bb14f4810561a327930ca4280 diff --git a/form/fty_enum.c b/form/fty_enum.c index 71978e3a..16ffae11 100644 --- a/form/fty_enum.c +++ b/form/fty_enum.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * 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 * @@ -35,7 +35,7 @@ #include "form.priv.h" -MODULE_ID("$Id: fty_enum.c,v 1.27 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: fty_enum.c,v 1.33 2021/06/17 21:11:08 tom Exp $") typedef struct { @@ -55,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 @@ -66,7 +66,7 @@ static void * Generic_Enum_Type(void *arg) { enumARG *argp = (enumARG *)0; - enumParams *params = (enumParams *) arg; + enumParams *params = (enumParams *)arg; if (params) { @@ -77,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)); @@ -96,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) @@ -118,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 @@ -138,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. +--------------------------------------------------------------------------*/ @@ -182,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 : - @@ -219,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. | @@ -274,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 @@ -292,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 */ @@ -331,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 @@ -368,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 @@ -425,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;