summaryrefslogtreecommitdiff
path: root/form/fty_enum.c
diff options
context:
space:
mode:
Diffstat (limited to 'form/fty_enum.c')
-rw-r--r--form/fty_enum.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/form/fty_enum.c b/form/fty_enum.c
index 16ffae11036f..59c3ff77a9d8 100644
--- a/form/fty_enum.c
+++ b/form/fty_enum.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020,2021 Thomas E. Dickey *
+ * Copyright 2020-2024,2025 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.33 2021/06/17 21:11:08 tom Exp $")
+MODULE_ID("$Id: fty_enum.c,v 1.36 2025/11/15 18:12:38 tom Exp $")
typedef struct
{
@@ -104,7 +104,7 @@ Generic_Enum_Type(void *arg)
argp->kwds = typeMalloc(char *, cnt + 1);
kp = kwds;
- if ((kptarget = argp->kwds) != 0)
+ if ((kptarget = argp->kwds) != NULL)
{
while (kp && (*kp))
{
@@ -168,7 +168,7 @@ Copy_Enum_Type(const void *argp)
char **kp = ap->kwds;
result->kwds = typeMalloc(char *, 1 + ap->count);
- if ((kptarget = result->kwds) != 0)
+ if ((kptarget = result->kwds) != NULL)
{
while (kp && (*kp))
{
@@ -209,6 +209,7 @@ Free_Enum_Type(void *argp)
}
assert(cnt == ap->count);
free(ap->kwds);
+ (void) cnt;
}
free(argp);
}
@@ -291,21 +292,21 @@ Check_Enum_Field(FIELD *field, const void *argp)
char **kwds = ((const enumARG *)argp)->kwds;
bool ccase = ((const enumARG *)argp)->checkcase;
bool unique = ((const enumARG *)argp)->checkunique;
- unsigned char *bp = (unsigned char *)field_buffer(field, 0);
- char *s, *t, *p;
+ const unsigned char *bp = (unsigned char *)field_buffer(field, 0);
+ const char *s, *t, *p;
while (kwds && (s = (*kwds++)))
{
int res;
- if ((res = Compare((unsigned char *)s, bp, ccase)) != NOMATCH)
+ if ((res = Compare((const unsigned char *)s, bp, ccase)) != NOMATCH)
{
p = t = s; /* t is at least a partial match */
if ((unique && res != EXACT))
{
while (kwds && (p = *kwds++))
{
- if ((res = Compare((unsigned char *)p, bp, ccase)) != NOMATCH)
+ if ((res = Compare((const unsigned char *)p, bp, ccase)) != NOMATCH)
{
if (res == EXACT)
{
@@ -313,7 +314,7 @@ Check_Enum_Field(FIELD *field, const void *argp)
break;
}
else
- t = (char *)0;
+ t = NULL;
}
}
}
@@ -347,12 +348,13 @@ Next_Enum(FIELD *field, const void *argp)
{
const enumARG *args = (const enumARG *)argp;
char **kwds = args->kwds;
- bool ccase = args->checkcase;
- int cnt = args->count;
- unsigned char *bp = (unsigned char *)field_buffer(field, 0);
+ const unsigned char *bp = (const unsigned char *)field_buffer(field, 0);
if (kwds)
{
+ int cnt = args->count;
+ bool ccase = args->checkcase;
+
while (cnt--)
{
if (Compare((unsigned char *)(*kwds++), bp, ccase) == EXACT)
@@ -386,26 +388,25 @@ Previous_Enum(FIELD *field, const void *argp)
const enumARG *args = (const enumARG *)argp;
int cnt = args->count;
char **kwds = &args->kwds[cnt - 1];
+ const unsigned char *bp = (const unsigned char *)field_buffer(field, 0);
+
bool ccase = args->checkcase;
- unsigned char *bp = (unsigned char *)field_buffer(field, 0);
- if (kwds)
+ while (cnt--)
{
- while (cnt--)
- {
- if (Compare((unsigned char *)(*kwds--), bp, ccase) == EXACT)
- break;
- }
+ if (Compare((unsigned char *)(*kwds--), bp, ccase) == EXACT)
+ break;
+ }
- if (cnt <= 0)
- kwds = &args->kwds[args->count - 1];
+ 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 ((cnt >= 0) || (Compare((const unsigned char *)dummy, bp, ccase) == EXACT))
+ {
+ set_field_buffer(field, 0, *kwds);
+ return TRUE;
}
+
return FALSE;
}