add helper define for max string length, allow default commands to receive options

This commit is contained in:
Duncan Laurie 2005-05-17 21:05:21 +00:00
parent 650f12ab23
commit 8cfb4c0897
5 changed files with 16 additions and 6 deletions

View File

@ -40,6 +40,7 @@
#include <sys/types.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
struct valstr {
uint16_t val;
@ -67,4 +68,12 @@ void ipmi_start_daemon(void);
# define __max(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef __minlen
# define __minlen(a, b) ({ int x=strlen(a); int y=strlen(b); (x < y) ? x : y;})
#endif
#ifndef __maxlen
# define __maxlen(a, b) ({ int x=strlen(a); int y=strlen(b); (x > y) ? x : y;})
#endif
#endif /* IPMI_HELPER_H */

View File

@ -120,8 +120,7 @@ uint16_t str2val(const char *str, const struct valstr *vs)
int i = 0;
while (vs[i].str != NULL) {
if (!strncasecmp(vs[i].str, str,
__max(strlen(str), strlen(vs[i].str))))
if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0)
return vs[i].val;
i++;
}

View File

@ -219,8 +219,7 @@ ipmi_event_find_offset(uint8_t code,
while (evt->type) {
if (evt->code == code && evt->desc != NULL &&
strncasecmp(desc, evt->desc,
__max(strlen(desc), strlen(evt->desc))) == 0)
strncasecmp(desc, evt->desc, __maxlen(desc, evt->desc)) == 0)
return evt->offset;
evt++;
}

View File

@ -196,10 +196,13 @@ ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv)
}
for (cmd=intf->cmdlist; cmd->func != NULL; cmd++) {
if (strncmp(name, cmd->name, strlen(cmd->name)) == 0)
if (strncmp(name, cmd->name, __maxlen(cmd->name, name)) == 0)
break;
}
if (cmd->func == NULL) {
cmd = intf->cmdlist;
if (strncmp(cmd->name, "default", 7) == 0)
return cmd->func(intf, argc+1, argv-1);
lprintf(LOG_ERR, "Invalid command: %s", name);
ipmi_cmd_print(intf->cmdlist);
return -1;

View File

@ -3660,7 +3660,7 @@ ipmi_sdr_print_type(struct ipmi_intf * intf, char * type)
else {
for (x = 1; x < SENSOR_TYPE_MAX; x++) {
if (strncasecmp(sensor_type_desc[x], type,
__max(strlen(type), strlen(sensor_type_desc[x]))) == 0) {
__maxlen(type, sensor_type_desc[x])) == 0) {
sensor_type = x;
break;
}