This is an automated email from Gerrit. "Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8397
-- gerrit commit e9dda807a825defc57e6695efc78a796883e4b21 Author: Antonio Borneo <borneo.anto...@gmail.com> Date: Sun Jul 14 15:12:59 2024 +0200 binarybuffer: str_to_buf(): add support for binary numbers The GCC compiler accepts non-standard '0b' and '0B' prefix for binary numbers. Such prefix is also welcome in OpenOCD. Extend str_to_buf() to support binary numbers. Today only the commands 'jtag drscan', 'reg' and 'set_reg' use it. Change-Id: I00ed2504417cf3c8c5f0edf7287237ed911c2f87 Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com> diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c index ced1701d71..930cf12f90 100644 --- a/src/helper/binarybuffer.c +++ b/src/helper/binarybuffer.c @@ -198,12 +198,17 @@ static bool str_has_hex_prefix(const char *s) return (s[0] == '0') && (s[1] == 'x' || s[1] == 'X'); } +static bool str_has_binary_prefix(const char *s) +{ + /* Starts with "0b" or "0B" */ + return (s[0] == '0') && (s[1] == 'b' || s[1] == 'B'); +} + static bool str_has_octal_prefix(const char *s) { - /* - starts with '0', - * - has at least two characters, and - * - the second character is not 'x' or 'X' */ - return (s[0] == '0') && (s[1] != '\0') && (s[1] != 'x') && (s[1] != 'X'); + /* - starts with '0' and + * - the second character is an octal digit */ + return (s[0] == '0') && (s[1] >= '0') && (s[1] <= '7'); } /** @@ -218,14 +223,21 @@ static unsigned int str_radix_guess(const char *str) if (str_has_octal_prefix(str)) return 8; + if (str_has_binary_prefix(str)) + return 2; + /* Otherwise assume a decimal number. */ return 10; } -/** Strip leading "0x" or "0X" from hex numbers or "0" from octal numbers. */ +/** + * Strip leading "0x" or "0X" from hex numbers, "0b" or "0B" from hex numbers + * or "0" from octal numbers. + */ static const char *str_strip_number_prefix(const char *str, unsigned int radix) { switch (radix) { + case 2: case 16: return str + 2; case 8: --