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
This commit is contained in:
zwelch 2009-06-09 02:23:27 +00:00
parent 1c74d0e3a4
commit 9f185eef7d
1 changed files with 16 additions and 23 deletions

View File

@ -281,29 +281,22 @@ void jtag_tap_add(struct jtag_tap_s *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 */
char *cp; jtag_tap_t *t = jtag_all_taps();
while (t)
t = jtag_all_taps(); {
/* try name first */ if (0 == strcmp(t->dotted_name, s))
while(t){ return t;
if( 0 == strcmp( t->dotted_name, s ) ){
break;
} else {
t = t->next_tap; t = t->next_tap;
} }
}
/* backup plan is by number */ /* no tap found by name, so try to parse the name as a number */
if( t == NULL ){ char *cp;
/* ok - is "s" a number? */ unsigned n = strtoul(s, &cp, 0);
int n; if ((s == cp) || (*cp != 0))
n = strtol( s, &cp, 0 ); return NULL;
if( (s != cp) && (*cp == 0) ){
/* Then it is... */ return jtag_tap_by_abs_position(n);
t = jtag_tap_by_abs_position(n);
}
}
return t;
} }
jtag_tap_t * jtag_tap_by_jim_obj( Jim_Interp *interp, Jim_Obj *o ) jtag_tap_t * jtag_tap_by_jim_obj( Jim_Interp *interp, Jim_Obj *o )