summaryrefslogtreecommitdiff
path: root/src/svf
diff options
context:
space:
mode:
authorsimon qian <simonqian.openocd@gmail.com>2010-01-18 04:56:08 +0800
committerDavid Brownell <dbrownell@users.sourceforge.net>2010-01-23 14:24:10 -0800
commit9ff16575d2838527afa635058c4cb95d641533ba (patch)
treeb4baed0ad99c66cd5f22511866875cfb536152ac /src/svf
parent718ee762e7d6a81037670612a2f3d21da4784f56 (diff)
downloadopenocd+libswd-9ff16575d2838527afa635058c4cb95d641533ba.tar.gz
openocd+libswd-9ff16575d2838527afa635058c4cb95d641533ba.tar.bz2
openocd+libswd-9ff16575d2838527afa635058c4cb95d641533ba.tar.xz
openocd+libswd-9ff16575d2838527afa635058c4cb95d641533ba.zip
SVF: insert space before '(' and after ')'
See http://forum.sparkfun.com/viewtopic.php?p=90983#90983 for discussion; basically, the SVF parser wrongly expects "TDI (123)" but the space is optional and it should accept "TDI(123)" too. In the same way, "TDI(123)TDO(456)" should work too. Rather than update the command parsing, this just makes sure the expected spaces are present. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Diffstat (limited to 'src/svf')
-rw-r--r--src/svf/svf.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/svf/svf.c b/src/svf/svf.c
index 7cb22007..275bced8 100644
--- a/src/svf/svf.c
+++ b/src/svf/svf.c
@@ -504,27 +504,49 @@ static int svf_read_command_from_file(int fd)
default:
if (!comment)
{
- if (cmd_pos >= svf_command_buffer_size - 1)
+ /* The parsing code currently expects a space
+ * before parentheses -- "TDI (123)". Also a
+ * space afterwards -- "TDI (123) TDO(456)".
+ * But such spaces are optional... instead of
+ * parser updates, cope with that by adding the
+ * spaces as needed.
+ *
+ * Ensure there are 3 bytes available, for:
+ * - current character
+ * - added space.
+ * - terminating NUL ('\0')
+ */
+ if ((cmd_pos + 2) >= svf_command_buffer_size)
{
- tmp_buffer = (char*)malloc(svf_command_buffer_size + SVFP_CMD_INC_CNT); // 1 more byte for '\0'
+ /* REVISIT use realloc(); simpler */
+ tmp_buffer = malloc(
+ svf_command_buffer_size
+ + SVFP_CMD_INC_CNT);
if (NULL == tmp_buffer)
{
LOG_ERROR("not enough memory");
return ERROR_FAIL;
}
if (svf_command_buffer_size > 0)
- {
- memcpy(tmp_buffer, svf_command_buffer, svf_command_buffer_size);
- }
+ memcpy(tmp_buffer,
+ svf_command_buffer,
+ svf_command_buffer_size);
if (svf_command_buffer != NULL)
- {
free(svf_command_buffer);
- }
svf_command_buffer = tmp_buffer;
svf_command_buffer_size += SVFP_CMD_INC_CNT;
tmp_buffer = NULL;
}
+
+ /* insert a space before '(' */
+ if ('(' == ch)
+ svf_command_buffer[cmd_pos++] = ' ';
+
svf_command_buffer[cmd_pos++] = (char)toupper(ch);
+
+ /* insert a space after ')' */
+ if (')' == ch)
+ svf_command_buffer[cmd_pos++] = ' ';
}
break;
}