support 3-key configurations with IP input too: wrap around limits
This commit is contained in:
+10
-9
@@ -1272,21 +1272,22 @@ MenuResult menuitem_process_input_ip (MenuItem *item, MenuToken token, char * ke
|
|||||||
num = (int) strtol(&str[pos - (pos % (ipinfo->width + 1))], (char **) NULL, ipinfo->base);
|
num = (int) strtol(&str[pos - (pos % (ipinfo->width + 1))], (char **) NULL, ipinfo->base);
|
||||||
// increase the number depending on the position
|
// increase the number depending on the position
|
||||||
num += ipinfo->posValue[(pos - (pos / (ipinfo->width + 1))) % ipinfo->width];
|
num += ipinfo->posValue[(pos - (pos / (ipinfo->width + 1))) % ipinfo->width];
|
||||||
if (num <= ipinfo->limit) {
|
// wrap around upper limit
|
||||||
snprintf(numstr, 5, ipinfo->format, num);
|
if (num > ipinfo->limit)
|
||||||
memcpy(&str[pos - (pos % (ipinfo->width + 1))], numstr, ipinfo->width);
|
num = 0;
|
||||||
}
|
snprintf(numstr, 5, ipinfo->format, num);
|
||||||
|
memcpy(&str[pos - (pos % (ipinfo->width + 1))], numstr, ipinfo->width);
|
||||||
return MENURESULT_NONE;
|
return MENURESULT_NONE;
|
||||||
case MENUTOKEN_DOWN:
|
case MENUTOKEN_DOWN:
|
||||||
// convert string starting at the beginning / previous dot into a number
|
// convert string starting at the beginning / previous dot into a number
|
||||||
num = (int) strtol(&str[pos - (pos % (ipinfo->width + 1))], (char **) NULL, ipinfo->base);
|
num = (int) strtol(&str[pos - (pos % (ipinfo->width + 1))], (char **) NULL, ipinfo->base);
|
||||||
// decrease the number depending on the position
|
// decrease the number depending on the position
|
||||||
num -= ipinfo->posValue[(pos - (pos / (ipinfo->width + 1))) % ipinfo->width];
|
num -= ipinfo->posValue[(pos - (pos / (ipinfo->width + 1))) % ipinfo->width];
|
||||||
if (num >= 0) {
|
// wrap around lower limit 0
|
||||||
snprintf(numstr, 5, ipinfo->format, num);
|
if (num < 0)
|
||||||
memcpy(&str[pos - (pos % (ipinfo->width + 1))], numstr, ipinfo->width);
|
num = ipinfo->limit;
|
||||||
}
|
snprintf(numstr, 5, ipinfo->format, num);
|
||||||
|
memcpy(&str[pos - (pos % (ipinfo->width + 1))], numstr, ipinfo->width);
|
||||||
return MENURESULT_NONE;
|
return MENURESULT_NONE;
|
||||||
case MENUTOKEN_RIGHT:
|
case MENUTOKEN_RIGHT:
|
||||||
if (pos < item->data.ip.maxlength - 1) {
|
if (pos < item->data.ip.maxlength - 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user