Commit bb84ad01 authored by Alessandro Rubini's avatar Alessandro Rubini

shell: replace strcasecmp with strcmp

when trying a compiler built with a newer newlib, I got a size increase
of 2kB in wrc.elf. This is due du "smarter" strcasecmp, which is
now localized, with wide-character support and so on.

We may implement our own ascii-only strcasecmp, but avoinding case-insensitive
comparisons we save 400 bytes, and the binary size doesn't change changing
newlib in the compiler.

Nobody is expected to use uppercase commands in the wrpc shell, and there
is no technical need to support them, when all documentation hints to
use lower-case anyways.

Change trivially performed by

   sed -i s/strcasecmp/strcmp/ shell/*.c
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 4e6a3eab
......@@ -24,7 +24,7 @@ static int cmd_calibration(const char *args[])
{
uint32_t trans;
if (args[0] && !strcasecmp(args[0], "force")) {
if (args[0] && !strcmp(args[0], "force")) {
if (measure_t24p(&trans) < 0)
return -1;
return storage_phtrans(&trans, 1);
......
......@@ -27,7 +27,7 @@ static int cmd_diag(const char *args[])
return 0;
}
if (!strcasecmp(args[0], "ro") && args[1]) {
if (!strcmp(args[0], "ro") && args[1]) {
addr = atoi(args[1]);
ret = diag_read_word(addr, DIAG_RO_BANK, &val);
if (!ret)
......@@ -35,7 +35,7 @@ static int cmd_diag(const char *args[])
return ret;
}
if (!strcasecmp(args[0], "rw") && args[1]) {
if (!strcmp(args[0], "rw") && args[1]) {
addr = atoi(args[1]);
ret = diag_read_word(addr, DIAG_RW_BANK, &val);
if (!ret)
......@@ -43,7 +43,7 @@ static int cmd_diag(const char *args[])
return ret;
}
if (!strcasecmp(args[0], "w") && args[1] && args[2]) {
if (!strcmp(args[0], "w") && args[1] && args[2]) {
addr = atoi(args[1]);
val = atoi(args[2]);
ret = diag_write_word(addr, val);
......
......@@ -16,18 +16,18 @@
static int cmd_init(const char *args[])
{
if (args[0] && !strcasecmp(args[0], "erase")) {
if (args[0] && !strcmp(args[0], "erase")) {
if (storage_init_erase() < 0)
pp_printf("Could not erase init script\n");
} else if (args[1] && !strcasecmp(args[0], "add")) {
} else if (args[1] && !strcmp(args[0], "add")) {
if (storage_init_add(args) < 0)
pp_printf("Could not add the command\n");
else
pp_printf("OK.\n");
} else if (args[0] && !strcasecmp(args[0], "show")) {
} else if (args[0] && !strcmp(args[0], "show")) {
shell_show_build_init();
storage_init_show();
} else if (args[0] && !strcasecmp(args[0], "boot")) {
} else if (args[0] && !strcmp(args[0], "boot")) {
shell_boot_script();
}
......
......@@ -40,9 +40,9 @@ static int cmd_ip(const char *args[])
unsigned char ip[4];
char buf[20];
if (!args[0] || !strcasecmp(args[0], "get")) {
if (!args[0] || !strcmp(args[0], "get")) {
getIP(ip);
} else if (!strcasecmp(args[0], "set") && args[1]) {
} else if (!strcmp(args[0], "set") && args[1]) {
ip_status = IP_OK_STATIC;
decode_ip(args[1], ip);
setIP(ip);
......
......@@ -43,18 +43,18 @@ static int cmd_mac(const char *args[])
unsigned char mac[6];
char buf[32];
if (!args[0] || !strcasecmp(args[0], "get")) {
if (!args[0] || !strcmp(args[0], "get")) {
/* get current MAC */
get_mac_addr(mac);
} else if (!strcasecmp(args[0], "getp")) {
} else if (!strcmp(args[0], "getp")) {
/* get persistent MAC */
get_mac_addr(mac);
get_persistent_mac(ONEWIRE_PORT, mac);
} else if (!strcasecmp(args[0], "set") && args[1]) {
} else if (!strcmp(args[0], "set") && args[1]) {
decode_mac(args[1], mac);
set_mac_addr(mac);
pfilter_init_default();
} else if (!strcasecmp(args[0], "setp") && args[1]) {
} else if (!strcmp(args[0], "setp") && args[1]) {
decode_mac(args[1], mac);
set_persistent_mac(ONEWIRE_PORT, mac);
} else {
......
......@@ -18,42 +18,42 @@ static int cmd_pll(const char *args[])
{
int cur, tgt;
if (!strcasecmp(args[0], "init")) {
if (!strcmp(args[0], "init")) {
if (!args[3])
return -EINVAL;
spll_init(atoi(args[1]), atoi(args[2]), atoi(args[3]));
} else if (!strcasecmp(args[0], "cl")) {
} else if (!strcmp(args[0], "cl")) {
if (!args[1])
return -EINVAL;
pp_printf("%d\n", spll_check_lock(atoi(args[1])));
} else if (!strcasecmp(args[0], "stat")) {
} else if (!strcmp(args[0], "stat")) {
spll_show_stats();
} else if (!strcasecmp(args[0], "sps")) {
} else if (!strcmp(args[0], "sps")) {
if (!args[2])
return -EINVAL;
spll_set_phase_shift(atoi(args[1]), atoi(args[2]));
} else if (!strcasecmp(args[0], "gps")) {
} else if (!strcmp(args[0], "gps")) {
if (!args[1])
return -EINVAL;
spll_get_phase_shift(atoi(args[1]), &cur, &tgt);
pp_printf("%d %d\n", cur, tgt);
} else if (!strcasecmp(args[0], "start")) {
} else if (!strcmp(args[0], "start")) {
if (!args[1])
return -EINVAL;
spll_start_channel(atoi(args[1]));
} else if (!strcasecmp(args[0], "stop")) {
} else if (!strcmp(args[0], "stop")) {
if (!args[1])
return -EINVAL;
spll_stop_channel(atoi(args[1]));
} else if (!strcasecmp(args[0], "sdac")) {
} else if (!strcmp(args[0], "sdac")) {
if (!args[2])
return -EINVAL;
spll_set_dac(atoi(args[1]), atoi(args[2]));
} else if (!strcasecmp(args[0], "gdac")) {
} else if (!strcmp(args[0], "gdac")) {
if (!args[1])
return -EINVAL;
pp_printf("%d\n", spll_get_dac(atoi(args[1])));
} else if(!strcasecmp(args[0], "checkvco"))
} else if(!strcmp(args[0], "checkvco"))
check_vco_frequencies();
else
return -EINVAL;
......
......@@ -19,11 +19,11 @@ static int cmd_ps(const char *args[])
struct wrc_task *t;
if (args[0]) {
if(!strcasecmp(args[0], "reset")) {
if(!strcmp(args[0], "reset")) {
for_each_task(t)
t->nrun = t->seconds = t->nanos = t->max_run_ticks = 0;
return 0;
} else if (!strcasecmp(args[0], "max")) {
} else if (!strcmp(args[0], "max")) {
if (args[1])
print_task_time_threshold = atoi(args[1]);
pp_printf("print_task_time_threshold %d\n",
......
......@@ -56,7 +56,7 @@ static int cmd_ptp(const char *args[])
for (j = 0; args[j]; j++) {
for (i = 0, c = subcmd; i < ARRAY_SIZE(subcmd); i++, c++) {
if (!strcasecmp(args[j], c->name)) {
if (!strcmp(args[j], c->name)) {
ret = c->fun(c->arg);
if (ret < 0)
return ret;
......
......@@ -21,11 +21,11 @@ extern int wrc_phase_tracking;
static int cmd_ptrack(const char *args[])
{
if (args[0] && !strcasecmp(args[0], "enable")) {
if (args[0] && !strcmp(args[0], "enable")) {
wr_servo_enable_tracking(1);
wrc_phase_tracking = 1;
}
else if (args[0] && !strcasecmp(args[0], "disable")) {
else if (args[0] && !strcmp(args[0], "disable")) {
wr_servo_enable_tracking(0);
wrc_phase_tracking = 0;
}
......
......@@ -40,14 +40,14 @@ static int cmd_sdb(const char *args[])
i2c_adr = atoi(args[3]);
/* Writing SDBFS image */
if (!strcasecmp(args[0], "fs") && args[2]) {
if (!strcmp(args[0], "fs") && args[2]) {
/* if all the parameters were specified from the cmd line, we
* use these */
storage_gensdbfs(atoi(args[1]), atoi(args[2]), blocksize,
i2c_adr);
return 0;
}
if (!strcasecmp(args[0], "fs") && storage_cfg.valid &&
if (!strcmp(args[0], "fs") && storage_cfg.valid &&
(atoi(args[1]) == MEM_FLASH ||
atoi(args[1]) == MEM_FRAM)) {
/* if available, we can also use Flash parameters specified with
......@@ -57,12 +57,12 @@ static int cmd_sdb(const char *args[])
return 0;
}
/* Erasing SDBFS image */
if (!strcasecmp(args[0], "fse") && args[2]) {
if (!strcmp(args[0], "fse") && args[2]) {
storage_sdbfs_erase(atoi(args[1]), atoi(args[2]), blocksize,
i2c_adr);
return 0;
}
if (!strcasecmp(args[0], "fse") && storage_cfg.valid &&
if (!strcmp(args[0], "fse") && storage_cfg.valid &&
(atoi(args[1]) == MEM_FLASH ||
atoi(args[1]) == MEM_FRAM)) {
storage_sdbfs_erase(atoi(args[1]), storage_cfg.baseadr,
......
......@@ -41,13 +41,13 @@ static int cmd_sfp(const char *args[])
pp_printf("Wrong parameter\n");
return -EINVAL;
}
if (!strcasecmp(args[0], "erase")) {
if (!strcmp(args[0], "erase")) {
if (storage_sfpdb_erase() == EE_RET_I2CERR) {
pp_printf("Could not erase DB\n");
return -EIO;
}
return 0;
} else if (args[4] && !strcasecmp(args[0], "add")) {
} else if (args[4] && !strcmp(args[0], "add")) {
temp = strnlen(args[1], SFP_PN_LEN);
for (i = 0; i < temp; ++i)
sfp.pn[i] = args[1][i];
......@@ -69,7 +69,7 @@ static int cmd_sfp(const char *args[])
}
pp_printf("%d SFPs in DB\n", temp);
return 0;
} else if (!strcasecmp(args[0], "show")) {
} else if (!strcmp(args[0], "show")) {
for (i = 0; i < sfpcount; ++i) {
sfpcount = storage_get_sfp(&sfp, SFP_GET, i);
if (sfpcount == 0) {
......@@ -87,7 +87,7 @@ static int cmd_sfp(const char *args[])
sfp.dRx, sfp.alpha);
}
return 0;
} else if (!strcasecmp(args[0], "match")) {
} else if (!strcmp(args[0], "match")) {
ret = sfp_match();
if (ret == -ENODEV) {
pp_printf("No SFP.\n");
......@@ -111,7 +111,7 @@ static int cmd_sfp(const char *args[])
pp_printf("SFP matched, dTx=%d dRx=%d alpha=%d\n",
sfp_deltaTx, sfp_deltaRx, sfp_alpha);
return ret;
} else if (args[1] && !strcasecmp(args[0], "ena")) {
} else if (args[1] && !strcmp(args[0], "ena")) {
ep_sfp_enable(atoi(args[1]));
return 0;
} else {
......
......@@ -27,12 +27,12 @@ static int cmd_stat(const char *args[])
}
/* arguments: bts, on, off */
if (!strcasecmp(args[0], "bts")) {
if (!strcmp(args[0], "bts")) {
pp_printf("%d ps\n", ep_get_bitslide());
} else if (!strcasecmp(args[0], "on")) {
} else if (!strcmp(args[0], "on")) {
wrc_stat_running = 1;
wrc_stats_last--; /* force a line to be printed */
} else if (!strcasecmp(args[0], "off")) {
} else if (!strcmp(args[0], "off")) {
wrc_stat_running = 0;
pp_printf("statistics now off\n");
} else
......
......@@ -31,24 +31,24 @@ static int cmd_time(const char *args[])
shw_pps_gen_get_time(&sec, &nsec);
if (args[2] && !strcasecmp(args[0], "set")) {
if (args[2] && !strcmp(args[0], "set")) {
if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) {
shw_pps_gen_set_time((uint64_t) atoi(args[1]),
atoi(args[2]), PPSG_SET_ALL);
return 0;
} else
return -EBUSY;
} else if (args[0] && !strcasecmp(args[0], "setsec")) {
} else if (args[0] && !strcmp(args[0], "setsec")) {
if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) {
shw_pps_gen_set_time((int64_t) atoi(args[1]), 0, PPSG_SET_SEC);
return 0;
}
} else if (args[0] && !strcasecmp(args[0], "setnsec")) {
} else if (args[0] && !strcmp(args[0], "setnsec")) {
if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) {
shw_pps_gen_set_time(0, atoi(args[1]), PPSG_SET_NSEC);
return 0;
}
} else if (args[0] && !strcasecmp(args[0], "raw")) {
} else if (args[0] && !strcmp(args[0], "raw")) {
pp_printf("%d %d\n", (uint32_t) sec, nsec);
return 0;
}
......
......@@ -16,9 +16,9 @@ static int cmd_vlan(const char *args[])
{
int i;
if (!args[0] || !strcasecmp(args[0], "get")) {
if (!args[0] || !strcmp(args[0], "get")) {
/* nothing... */
} else if (!strcasecmp(args[0], "set") && args[1]) {
} else if (!strcmp(args[0], "set") && args[1]) {
fromdec(args[1], &i);
if (i < 1 || i > 4095) {
pp_printf("%i (\"%s\") out of range\n", i, args[1]);
......@@ -26,7 +26,7 @@ static int cmd_vlan(const char *args[])
}
wrc_vlan_number = i;
pfilter_init_default();
} else if (!strcasecmp(args[0], "off")) {
} else if (!strcmp(args[0], "off")) {
wrc_vlan_number = 0;
pfilter_init_default();
......
......@@ -104,7 +104,7 @@ static int _shell_exec(void)
return 0;
for (p = __cmd_begin; p < __cmd_end; p++)
if (!strcasecmp(p->name, tokptr[0])) {
if (!strcmp(p->name, tokptr[0])) {
rv = p->exec((const char **)(tokptr + 1));
if (rv < 0)
pp_printf("Command \"%s\": error %d\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment