mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-01-22 14:22:19 +08:00
add helper define for max string length, allow default commands to receive options
This commit is contained in:
parent
650f12ab23
commit
8cfb4c0897
@ -40,6 +40,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
struct valstr {
|
struct valstr {
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
@ -67,4 +68,12 @@ void ipmi_start_daemon(void);
|
|||||||
# define __max(a, b) ((a) > (b) ? (a) : (b))
|
# define __max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#endif
|
#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 */
|
#endif /* IPMI_HELPER_H */
|
||||||
|
|||||||
@ -120,8 +120,7 @@ uint16_t str2val(const char *str, const struct valstr *vs)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (vs[i].str != NULL) {
|
while (vs[i].str != NULL) {
|
||||||
if (!strncasecmp(vs[i].str, str,
|
if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0)
|
||||||
__max(strlen(str), strlen(vs[i].str))))
|
|
||||||
return vs[i].val;
|
return vs[i].val;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -219,8 +219,7 @@ ipmi_event_find_offset(uint8_t code,
|
|||||||
|
|
||||||
while (evt->type) {
|
while (evt->type) {
|
||||||
if (evt->code == code && evt->desc != NULL &&
|
if (evt->code == code && evt->desc != NULL &&
|
||||||
strncasecmp(desc, evt->desc,
|
strncasecmp(desc, evt->desc, __maxlen(desc, evt->desc)) == 0)
|
||||||
__max(strlen(desc), strlen(evt->desc))) == 0)
|
|
||||||
return evt->offset;
|
return evt->offset;
|
||||||
evt++;
|
evt++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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++) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if (cmd->func == NULL) {
|
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);
|
lprintf(LOG_ERR, "Invalid command: %s", name);
|
||||||
ipmi_cmd_print(intf->cmdlist);
|
ipmi_cmd_print(intf->cmdlist);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -3660,7 +3660,7 @@ ipmi_sdr_print_type(struct ipmi_intf * intf, char * type)
|
|||||||
else {
|
else {
|
||||||
for (x = 1; x < SENSOR_TYPE_MAX; x++) {
|
for (x = 1; x < SENSOR_TYPE_MAX; x++) {
|
||||||
if (strncasecmp(sensor_type_desc[x], type,
|
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;
|
sensor_type = x;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user