]> git.sur5r.net Git - openocd/commitdiff
Improve jtag command argument parsing.
authorZachary T Welch <zw@superlucidity.net>
Fri, 23 Oct 2009 04:05:50 +0000 (21:05 -0700)
committerZachary T Welch <zw@superlucidity.net>
Fri, 6 Nov 2009 02:03:18 +0000 (18:03 -0800)
src/jtag/amt_jtagaccel.c
src/jtag/ft2232.c
src/jtag/gw16012.c
src/jtag/parport.c
src/jtag/tcl.c
src/jtag/vsllink.c

index b12aa7631635538014c0bdb33a53782b536da392..e3f440cce83fc6ba9fa99bed292c963a62e3401a 100644 (file)
@@ -534,9 +534,9 @@ static int amt_jtagaccel_handle_parport_port_command(
                /* only if the port wasn't overwritten by cmdline */
                if (amt_jtagaccel_port == 0)
                {
-                       int retval = parse_u16(args[0], &amt_jtagaccel_port);
-                       if (ERROR_OK != retval)
-                               return retval;
+                       uint16_t port;
+                       COMMAND_PARSE_NUMBER(u16, args[0], port);
+                       amt_jtagaccel_port = port;
                }
                else
                {
index bd910b35f2521e7dfa2c8d147d52cd9692fdbfda..b3389cc88253415463131f493138d15ece25ffe3 100644 (file)
@@ -2919,12 +2919,8 @@ static int ft2232_handle_vid_pid_command(struct command_context_s* cmd_ctx, char
        int retval = ERROR_OK;
        for (i = 0; i < argc; i += 2)
        {
-               retval = parse_u16(args[i], &ft2232_vid[i >> 1]);
-               if (ERROR_OK != retval)
-                       break;
-               retval = parse_u16(args[i + 1], &ft2232_pid[i >> 1]);
-               if (ERROR_OK != retval)
-                       break;
+               COMMAND_PARSE_NUMBER(u16, args[i], ft2232_vid[i >> 1]);
+               COMMAND_PARSE_NUMBER(u16, args[i + 1], ft2232_pid[i >> 1]);
        }
 
        /*
index 46635d073fb9330a6eaea80e2dc6a0f5c096f65d..4b0ffd73853a6c7e3a817dade2cbea026d4c6692 100644 (file)
@@ -576,9 +576,7 @@ static int gw16012_handle_parport_port_command(struct command_context_s *cmd_ctx
                /* only if the port wasn't overwritten by cmdline */
                if (gw16012_port == 0)
                {
-                       int retval = parse_u16(args[0], &gw16012_port);
-                       if (ERROR_OK != retval)
-                               return retval;
+                       COMMAND_PARSE_NUMBER(u16, args[0], gw16012_port);
                }
                else
                {
index 41e02475bfce2575002f722daeeea0c2337e0709..12a5eea56dbb27f45d80ba606321073e15ec91e7 100644 (file)
@@ -435,9 +435,7 @@ static int parport_handle_parport_port_command(struct command_context_s *cmd_ctx
                /* only if the port wasn't overwritten by cmdline */
                if (parport_port == 0)
                {
-                       int retval = parse_u16(args[0], &parport_port);
-                       if (ERROR_OK != retval)
-                               return retval;
+                       COMMAND_PARSE_NUMBER(u16, args[0], parport_port);
                }
                else
                {
index 5056a5c5d58ac10acdd9438f65a72628979d94ae..c064a825613bae5de8473d973f016fb3aa88cabc 100644 (file)
@@ -1050,9 +1050,8 @@ static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx,
        if (argc == 1)
        {
                unsigned delay;
-               int retval = parse_uint(args[0], &delay);
-               if (ERROR_OK != retval)
-                       return retval;
+               COMMAND_PARSE_NUMBER(uint, args[0], delay);
+
                jtag_set_nsrst_delay(delay);
        }
        command_print(cmd_ctx, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
@@ -1067,9 +1066,8 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx,
        if (argc == 1)
        {
                unsigned delay;
-               int retval = parse_uint(args[0], &delay);
-               if (ERROR_OK != retval)
-                       return retval;
+               COMMAND_PARSE_NUMBER(uint, args[0], delay);
+
                jtag_set_ntrst_delay(delay);
        }
        command_print(cmd_ctx, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
@@ -1084,9 +1082,8 @@ static int handle_jtag_nsrst_assert_width_command(struct command_context_s *cmd_
        if (argc == 1)
        {
                unsigned delay;
-               int retval = parse_uint(args[0], &delay);
-               if (ERROR_OK != retval)
-                       return retval;
+               COMMAND_PARSE_NUMBER(uint, args[0], delay);
+
                jtag_set_nsrst_assert_width(delay);
        }
        command_print(cmd_ctx, "jtag_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
@@ -1101,9 +1098,8 @@ static int handle_jtag_ntrst_assert_width_command(struct command_context_s *cmd_
        if (argc == 1)
        {
                unsigned delay;
-               int retval = parse_uint(args[0], &delay);
-               if (ERROR_OK != retval)
-                       return retval;
+               COMMAND_PARSE_NUMBER(uint, args[0], delay);
+
                jtag_set_ntrst_assert_width(delay);
        }
        command_print(cmd_ctx, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
@@ -1124,11 +1120,9 @@ static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cm
                LOG_DEBUG("handle jtag speed");
 
                unsigned cur_speed = 0;
-               int retval = parse_uint(args[0], &cur_speed);
-               if (ERROR_OK != retval)
-                       return retval;
-               retval = jtag_config_speed(cur_speed);
+               COMMAND_PARSE_NUMBER(uint, args[0], cur_speed);
 
+               retval = jtag_config_speed(cur_speed);
        }
        command_print(cmd_ctx, "jtag_speed: %d", jtag_get_speed());
 
@@ -1144,9 +1138,8 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd,
        if (argc == 1)
        {
                unsigned khz = 0;
-               int retval = parse_uint(args[0], &khz);
-               if (ERROR_OK != retval)
-                       return retval;
+               COMMAND_PARSE_NUMBER(uint, args[0], khz);
+
                retval = jtag_config_khz(khz);
                if (ERROR_OK != retval)
                        return retval;
@@ -1174,9 +1167,8 @@ static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd
        if (argc == 1)
        {
                unsigned khz = 0;
-               int retval = parse_uint(args[0], &khz);
-               if (ERROR_OK != retval)
-                       return retval;
+               COMMAND_PARSE_NUMBER(uint, args[0], khz);
+
                retval = jtag_config_rclk(khz);
                if (ERROR_OK != retval)
                        return retval;
@@ -1231,9 +1223,7 @@ static int handle_runtest_command(struct command_context_s *cmd_ctx,
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        unsigned num_clocks;
-       int retval = parse_uint(args[0], &num_clocks);
-       if (ERROR_OK != retval)
-               return retval;
+       COMMAND_PARSE_NUMBER(uint, args[0], num_clocks);
 
        jtag_add_runtest(num_clocks, TAP_IDLE);
        return jtag_execute_queue();
index ab55a19017818f3143b5ebcafdeee2c82a700f3d..1f1b86705621f8c73cca256fb2cb669013c5d4f5 100644 (file)
@@ -1407,7 +1407,8 @@ static int vsllink_handle_usb_vid_command(struct command_context_s *cmd_ctx, cha
                return ERROR_OK;
        }
 
-       return parse_u16(args[0], &vsllink_usb_vid);
+       COMMAND_PARSE_NUMBER(u16, args[0], vsllink_usb_vid);
+       return ERROR_OK;
 }
 
 static int vsllink_handle_usb_pid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@@ -1417,7 +1418,8 @@ static int vsllink_handle_usb_pid_command(struct command_context_s *cmd_ctx, cha
                LOG_ERROR("parameter error, should be one parameter for PID");
                return ERROR_OK;
        }
-       return parse_u16(args[0], &vsllink_usb_pid);
+       COMMAND_PARSE_NUMBER(u16, args[0], vsllink_usb_pid);
+       return ERROR_OK;
 }
 
 static int vsllink_handle_usb_bulkin_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@@ -1428,11 +1430,11 @@ static int vsllink_handle_usb_bulkin_command(struct command_context_s *cmd_ctx,
                return ERROR_OK;
        }
 
-       int retval = parse_u8(args[0], &vsllink_usb_bulkin);
-       if (ERROR_OK == retval)
-               vsllink_usb_bulkin |= 0x80;
+       COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_bulkin);
 
-       return retval;
+       vsllink_usb_bulkin |= 0x80;
+
+       return ERROR_OK;
 }
 
 static int vsllink_handle_usb_bulkout_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@@ -1443,11 +1445,11 @@ static int vsllink_handle_usb_bulkout_command(struct command_context_s *cmd_ctx,
                return ERROR_OK;
        }
 
-       int retval = parse_u8(args[0], &vsllink_usb_bulkout);
-       if (ERROR_OK == retval)
-               vsllink_usb_bulkout &= ~0x80;
+       COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_bulkin);
 
-       return retval;
+       vsllink_usb_bulkout &= ~0x80;
+
+       return ERROR_OK;
 }
 
 static int vsllink_handle_usb_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
@@ -1458,7 +1460,8 @@ static int vsllink_handle_usb_interface_command(struct command_context_s *cmd_ct
                return ERROR_OK;
        }
 
-       return parse_u8(args[0], &vsllink_usb_interface);
+       COMMAND_PARSE_NUMBER(u8, args[0], vsllink_usb_interface);
+       return ERROR_OK;
 }
 
 /***************************************************************************/