SCP: Add sim_strncasecmp for platforms which may not have strncasecmp
Consolidated the existing two previously implementations which existed in sim_serial and sim_ether.
This commit is contained in:
parent
052fafc62e
commit
4065f47f8c
4 changed files with 28 additions and 48 deletions
23
scp.c
23
scp.c
|
@ -7412,6 +7412,29 @@ int sim_isalnum (char c)
|
|||
return (c & 0x80) ? 0 : isalnum (c);
|
||||
}
|
||||
|
||||
/* strncasecmp() is not available on all platforms */
|
||||
int sim_strncasecmp (const char* string1, const char* string2, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char s1, s2;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
s1 = (unsigned char)string1[i];
|
||||
s2 = (unsigned char)string2[i];
|
||||
if (sim_islower (s1))
|
||||
s1 = (unsigned char)toupper (s1);
|
||||
if (sim_islower (s2))
|
||||
s2 = (unsigned char)toupper (s2);
|
||||
if (s1 < s2)
|
||||
return -1;
|
||||
if (s1 > s2)
|
||||
return 1;
|
||||
if (s1 == 0)
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get_yn yes/no question
|
||||
|
||||
Inputs:
|
||||
|
|
1
scp.h
1
scp.h
|
@ -148,6 +148,7 @@ int sim_isprint (char c);
|
|||
int sim_isdigit (char c);
|
||||
int sim_isgraph (char c);
|
||||
int sim_isalnum (char c);
|
||||
int sim_strncasecmp (const char* string1, const char* string2, size_t len);
|
||||
CONST char *get_sim_opt (int32 opt, CONST char *cptr, t_stat *st);
|
||||
CONST char *get_glyph (const char *iptr, char *optr, char mchar);
|
||||
CONST char *get_glyph_nc (const char *iptr, char *optr, char mchar);
|
||||
|
|
25
sim_ether.c
25
sim_ether.c
|
@ -692,27 +692,6 @@ const char* eth_getname_bydesc(const char* desc, char* name, char *ndesc)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* strncasecmp() is not available on all platforms */
|
||||
int eth_strncasecmp(const char* string1, const char* string2, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char s1, s2;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
s1 = string1[i];
|
||||
s2 = string2[i];
|
||||
if (islower (s1)) s1 = (unsigned char)toupper (s1);
|
||||
if (islower (s2)) s2 = (unsigned char)toupper (s2);
|
||||
|
||||
if (s1 < s2)
|
||||
return -1;
|
||||
if (s1 > s2)
|
||||
return 1;
|
||||
if (s1 == 0) return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* eth_getname_byname(const char* name, char* temp, char *desc)
|
||||
{
|
||||
ETH_LIST list[ETH_MAX_DEVICE];
|
||||
|
@ -724,7 +703,7 @@ char* eth_getname_byname(const char* name, char* temp, char *desc)
|
|||
n = strlen(name);
|
||||
for (i=0; i<count && !found; i++) {
|
||||
if ((n == strlen(list[i].name)) &&
|
||||
(eth_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
(sim_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
found = 1;
|
||||
strcpy(temp, list[i].name); /* only case might be different */
|
||||
strcpy(desc, list[i].desc);
|
||||
|
@ -744,7 +723,7 @@ char* eth_getdesc_byname(char* name, char* temp)
|
|||
n = strlen(name);
|
||||
for (i=0; i<count && !found; i++) {
|
||||
if ((n == strlen(list[i].name)) &&
|
||||
(eth_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
(sim_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
found = 1;
|
||||
strcpy(temp, list[i].desc);
|
||||
}
|
||||
|
|
27
sim_serial.c
27
sim_serial.c
|
@ -291,29 +291,6 @@ for (i=0; i<count; i++) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* strncasecmp() is not available on all platforms */
|
||||
static int sim_serial_strncasecmp (char* string1, char* string2, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char s1, s2;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
s1 = string1[i];
|
||||
s2 = string2[i];
|
||||
if (islower (s1))
|
||||
s1 = (unsigned char)toupper (s1);
|
||||
if (islower (s2))
|
||||
s2 = (unsigned char)toupper (s2);
|
||||
if (s1 < s2)
|
||||
return -1;
|
||||
if (s1 > s2)
|
||||
return 1;
|
||||
if (s1 == 0)
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char* sim_serial_getname_byname (char* name, char* temp)
|
||||
{
|
||||
SERIAL_LIST list[SER_MAX_DEVICE];
|
||||
|
@ -325,7 +302,7 @@ found = 0;
|
|||
n = strlen(name);
|
||||
for (i=0; i<count && !found; i++) {
|
||||
if ((n == strlen(list[i].name)) &&
|
||||
(sim_serial_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
(sim_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
found = 1;
|
||||
strcpy(temp, list[i].name); /* only case might be different */
|
||||
}
|
||||
|
@ -344,7 +321,7 @@ found = 0;
|
|||
n = strlen(name);
|
||||
for (i=0; i<count && !found; i++) {
|
||||
if ((n == strlen(list[i].name)) &&
|
||||
(sim_serial_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
(sim_strncasecmp(name, list[i].name, n) == 0)) {
|
||||
found = 1;
|
||||
strcpy(temp, list[i].desc);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue