summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-09 02:23:27 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-09 02:23:27 +0000
commit9f185eef7d69e3c9d4390f5f7dd78a7644b01c80 (patch)
tree12328cf7849dc9e387e44cb4b0aef4974c402003
parent1c74d0e3a4037400e81147b15e2da09b033fb46f (diff)
downloadopenocd+libswd-9f185eef7d69e3c9d4390f5f7dd78a7644b01c80.tar.gz
openocd+libswd-9f185eef7d69e3c9d4390f5f7dd78a7644b01c80.tar.bz2
openocd+libswd-9f185eef7d69e3c9d4390f5f7dd78a7644b01c80.tar.xz
openocd+libswd-9f185eef7d69e3c9d4390f5f7dd78a7644b01c80.zip
Simplify and fix bug in jtag_tap_by_string:
- Bug fix: Use unsigned type and strtoul when parsing for position number. - Simplify logic by returning directly when a tap is found by name. - Reduce scope: declare temporary variables with first use. - Bring code up to current style guidelines. git-svn-id: svn://svn.berlios.de/openocd/trunk@2141 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r--src/jtag/jtag.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index a057453b..6e2f63d2 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -279,31 +279,24 @@ void jtag_tap_add(struct jtag_tap_s *t)
*tap = t;
}
-jtag_tap_t *jtag_tap_by_string( const char *s )
+jtag_tap_t *jtag_tap_by_string(const char *s)
{
- jtag_tap_t *t;
+ /* try by name first */
+ jtag_tap_t *t = jtag_all_taps();
+ while (t)
+ {
+ if (0 == strcmp(t->dotted_name, s))
+ return t;
+ t = t->next_tap;
+ }
+
+ /* no tap found by name, so try to parse the name as a number */
char *cp;
+ unsigned n = strtoul(s, &cp, 0);
+ if ((s == cp) || (*cp != 0))
+ return NULL;
- t = jtag_all_taps();
- /* try name first */
- while(t){
- if( 0 == strcmp( t->dotted_name, s ) ){
- break;
- } else {
- t = t->next_tap;
- }
- }
- /* backup plan is by number */
- if( t == NULL ){
- /* ok - is "s" a number? */
- int n;
- n = strtol( s, &cp, 0 );
- if( (s != cp) && (*cp == 0) ){
- /* Then it is... */
- t = jtag_tap_by_abs_position(n);
- }
- }
- return t;
+ return jtag_tap_by_abs_position(n);
}
jtag_tap_t * jtag_tap_by_jim_obj( Jim_Interp *interp, Jim_Obj *o )