aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/form/fty_enum.c
diff options
context:
space:
mode:
authorPeter Wemm <peter@FreeBSD.org>2000-10-11 07:31:01 +0000
committerPeter Wemm <peter@FreeBSD.org>2000-10-11 07:31:01 +0000
commit18259542b2f8fa7e3f76f4bb0dd37995dfd424aa (patch)
tree9ec00b41242bbe63b83c0ac5316c539466d9f9de /contrib/ncurses/form/fty_enum.c
parent15589c42fa2774d2f8ee650f4f31eb8d3a861316 (diff)
downloadsrc-18259542b2f8fa7e3f76f4bb0dd37995dfd424aa.tar.gz
src-18259542b2f8fa7e3f76f4bb0dd37995dfd424aa.zip
Import ncurses-5.1-20001009 onto the vendor branch
Notes
Notes: svn path=/vendor/ncurses/dist/; revision=66963
Diffstat (limited to 'contrib/ncurses/form/fty_enum.c')
-rw-r--r--contrib/ncurses/form/fty_enum.c74
1 files changed, 40 insertions, 34 deletions
diff --git a/contrib/ncurses/form/fty_enum.c b/contrib/ncurses/form/fty_enum.c
index 701d80f81f11..490bf261842b 100644
--- a/contrib/ncurses/form/fty_enum.c
+++ b/contrib/ncurses/form/fty_enum.c
@@ -13,7 +13,7 @@
#include "form.priv.h"
-MODULE_ID("$Id: fty_enum.c,v 1.11 2000/03/19 01:09:56 Bruno.Haible Exp $")
+MODULE_ID("$Id: fty_enum.c,v 1.13 2000/09/10 00:55:26 juergen Exp $")
typedef struct {
char **kwds;
@@ -33,20 +33,21 @@ typedef struct {
static void *Make_Enum_Type(va_list * ap)
{
enumARG *argp = (enumARG *)malloc(sizeof(enumARG));
- char **kp;
- int cnt=0;
if (argp)
{
+ int cnt = 0;
+ char **kp = (char **)0;
int ccase, cunique;
+
argp->kwds = va_arg(*ap,char **);
ccase = va_arg(*ap,int);
cunique = va_arg(*ap,int);
argp->checkcase = ccase ? TRUE : FALSE;
argp->checkunique = cunique ? TRUE : FALSE;
-
+
kp = argp->kwds;
- while( (*kp++) ) cnt++;
+ while( (kp && *kp++) ) cnt++;
argp->count = cnt;
}
return (void *)argp;
@@ -62,11 +63,12 @@ static void *Make_Enum_Type(va_list * ap)
+--------------------------------------------------------------------------*/
static void *Copy_Enum_Type(const void * argp)
{
- const enumARG *ap = (const enumARG *)argp;
enumARG *result = (enumARG *)0;
if (argp)
{
+ const enumARG *ap = (const enumARG *)argp;
+
result = (enumARG *)malloc(sizeof(enumARG));
if (result)
*result = *ap;
@@ -165,14 +167,14 @@ static bool Check_Enum_Field(FIELD * field, const void * argp)
char *s, *t, *p;
int res;
- while( (s=(*kwds++)) )
+ while( kwds && (s=(*kwds++)) )
{
if ((res=Compare((unsigned char *)s,bp,ccase))!=NOMATCH)
{
p=t=s; /* t is at least a partial match */
if ((unique && res!=EXACT))
{
- while( (p = *kwds++) )
+ while( kwds && (p = *kwds++) )
{
if ((res=Compare((unsigned char *)p,bp,ccase))!=NOMATCH)
{
@@ -218,18 +220,20 @@ static bool Next_Enum(FIELD * field, const void * argp)
int cnt = args->count;
unsigned char *bp = (unsigned char *)field_buffer(field,0);
- while(cnt--)
- {
- if (Compare((unsigned char *)(*kwds++),bp,ccase)==EXACT)
- break;
- }
- if (cnt<=0)
- kwds = args->kwds;
- if ((cnt>=0) || (Compare((const unsigned char *)dummy,bp,ccase)==EXACT))
- {
- set_field_buffer(field,0,*kwds);
- return TRUE;
- }
+ if (kwds) {
+ while(cnt--)
+ {
+ if (Compare((unsigned char *)(*kwds++),bp,ccase)==EXACT)
+ break;
+ }
+ if (cnt<=0)
+ kwds = args->kwds;
+ if ((cnt>=0) || (Compare((const unsigned char *)dummy,bp,ccase)==EXACT))
+ {
+ set_field_buffer(field,0,*kwds);
+ return TRUE;
+ }
+ }
return FALSE;
}
@@ -252,20 +256,22 @@ static bool Previous_Enum(FIELD * field, const void * argp)
bool ccase = args->checkcase;
unsigned char *bp = (unsigned char *)field_buffer(field,0);
- while(cnt--)
- {
- if (Compare((unsigned char *)(*kwds--),bp,ccase)==EXACT)
- break;
- }
-
- if (cnt<=0)
- kwds = &args->kwds[args->count-1];
-
- if ((cnt>=0) || (Compare((const unsigned char *)dummy,bp,ccase)==EXACT))
- {
- set_field_buffer(field,0,*kwds);
- return TRUE;
- }
+ if (kwds) {
+ while(cnt--)
+ {
+ if (Compare((unsigned char *)(*kwds--),bp,ccase)==EXACT)
+ break;
+ }
+
+ if (cnt<=0)
+ kwds = &args->kwds[args->count-1];
+
+ if ((cnt>=0) || (Compare((const unsigned char *)dummy,bp,ccase)==EXACT))
+ {
+ set_field_buffer(field,0,*kwds);
+ return TRUE;
+ }
+ }
return FALSE;
}