From 609736948528958464542e83ed45caf67c31f7c1 Mon Sep 17 00:00:00 2001 From: Kolja Waschk Date: Tue, 6 Nov 2007 18:09:48 +0000 Subject: [PATCH] [ 972649 ] make jtag more tolerant of case git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@685 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/src/cmd/bit.c | 9 +++++++-- jtag/src/cmd/cable.c | 2 +- jtag/src/cmd/dr.c | 4 ++-- jtag/src/cmd/endian.c | 4 ++-- jtag/src/cmd/flashmem.c | 4 ++-- jtag/src/cmd/get.c | 2 +- jtag/src/cmd/print.c | 6 +++--- jtag/src/cmd/register.c | 4 ++-- jtag/src/cmd/set.c | 6 +++--- jtag/src/cmd/shift.c | 4 ++-- jtag/src/part/part.c | 4 ++-- jtag/src/tap/parport/direct.c | 12 +++++++++--- jtag/src/tap/parport/ppdev.c | 2 +- 13 files changed, 37 insertions(+), 26 deletions(-) diff --git a/jtag/src/cmd/bit.c b/jtag/src/cmd/bit.c index 2911d590..6cff8ffc 100644 --- a/jtag/src/cmd/bit.c +++ b/jtag/src/cmd/bit.c @@ -82,19 +82,24 @@ cmd_bit_run( char *params[] ) if (strlen( params[2] ) != 1) return -1; switch (params[2][0]) { - case 'I': + case 'I': + case 'i': type = BSBIT_INPUT; break; case 'O': + case 'o': type = BSBIT_OUTPUT; break; case 'B': + case 'b': type = BSBIT_BIDIR; break; case 'C': + case 'c': type = BSBIT_CONTROL; break; case 'X': + case 'x': type = BSBIT_INTERNAL; break; default: @@ -134,7 +139,7 @@ cmd_bit_run( char *params[] ) part->bsbits[bit]->control_value = (params[6][0] == '1') ? 1 : 0; /* control state */ - if ((strlen( params[7] ) != 1) || (params[7][0] != 'Z')) + if (strcasecmp(params[7], "Z")) return -1; part->bsbits[bit]->control_state = BSBIT_STATE_Z; diff --git a/jtag/src/cmd/cable.c b/jtag/src/cmd/cable.c index 9b62a539..f481ac48 100644 --- a/jtag/src/cmd/cable.c +++ b/jtag/src/cmd/cable.c @@ -47,7 +47,7 @@ cmd_cable_run( char *params[] ) /* search connection type driver */ for (i = 0; parport_drivers[i]; i++) - if (strcmp( params[1], parport_drivers[i]->type ) == 0) + if (strcasecmp( params[1], parport_drivers[i]->type ) == 0) break; if (!parport_drivers[i]) { printf( _("Unknown connection type: %s\n"), params[1] ); diff --git a/jtag/src/cmd/dr.c b/jtag/src/cmd/dr.c index 655d86a5..077d1736 100644 --- a/jtag/src/cmd/dr.c +++ b/jtag/src/cmd/dr.c @@ -55,9 +55,9 @@ cmd_dr_run( char *params[] ) } if (params[1]) { - if (strcmp( params[1], "in" ) == 0) + if (strcasecmp( params[1], "in" ) == 0) dir = 0; - else if (strcmp( params[1], "out" ) == 0) + else if (strcasecmp( params[1], "out" ) == 0) dir = 1; else return -1; diff --git a/jtag/src/cmd/endian.c b/jtag/src/cmd/endian.c index 45e2cfb9..7d739ffc 100644 --- a/jtag/src/cmd/endian.c +++ b/jtag/src/cmd/endian.c @@ -46,11 +46,11 @@ cmd_endian_run( char *params[] ) } - if (strcmp( params[1], "little" ) == 0) { + if (strcasecmp( params[1], "little" ) == 0) { big_endian = 0; return 1; } - if (strcmp( params[1], "big" ) == 0) { + if (strcasecmp( params[1], "big" ) == 0) { big_endian = 1; return 1; } diff --git a/jtag/src/cmd/flashmem.c b/jtag/src/cmd/flashmem.c index d47b6188..d76957ea 100644 --- a/jtag/src/cmd/flashmem.c +++ b/jtag/src/cmd/flashmem.c @@ -48,11 +48,11 @@ cmd_flashmem_run( char *params[] ) return 1; } - msbin = strcmp( "msbin", params[1] ) == 0; + msbin = strcasecmp( "msbin", params[1] ) == 0; if (!msbin && cmd_get_number( params[1], &adr )) return -1; - f = fopen( params[2], "r" ); + f = fopen( params[2], "rb" ); if (!f) { printf( _("Unable to open file `%s'!\n"), params[2] ); return 1; diff --git a/jtag/src/cmd/get.c b/jtag/src/cmd/get.c index 4c61d0c7..bc71b7fc 100644 --- a/jtag/src/cmd/get.c +++ b/jtag/src/cmd/get.c @@ -42,7 +42,7 @@ cmd_get_run( char *params[] ) if (cmd_params( params ) != 3) return -1; - if (strcmp( params[1], "signal") != 0) + if (strcasecmp( params[1], "signal") != 0) return -1; if (!cmd_test_cable()) diff --git a/jtag/src/cmd/print.c b/jtag/src/cmd/print.c index ecafc049..4e0d38fe 100644 --- a/jtag/src/cmd/print.c +++ b/jtag/src/cmd/print.c @@ -58,9 +58,9 @@ cmd_print_run( char *params[] ) } if (cmd_params( params ) == 2) { - if ((strcmp( params[1], "chain" ) != 0) && (strcmp( params[1], "bus") != 0)) + if ((strcasecmp( params[1], "chain" ) != 0) && (strcasecmp( params[1], "bus") != 0)) return -1; - if (strcmp( params[1], "bus") == 0) + if (strcasecmp( params[1], "bus") == 0) noheader = 1; } @@ -118,7 +118,7 @@ cmd_print_run( char *params[] ) return 1; } - if (strcmp( params[1], "chain" ) == 0) { + if (strcasecmp( params[1], "chain" ) == 0) { parts_print( chain->parts ); return 1; } diff --git a/jtag/src/cmd/register.c b/jtag/src/cmd/register.c index 6e1c3cb9..715ea570 100644 --- a/jtag/src/cmd/register.c +++ b/jtag/src/cmd/register.c @@ -76,7 +76,7 @@ cmd_register_run( char *params[] ) part->data_registers = dr; /* Boundary Scan Register */ - if (strcmp( dr->name, "BSR" ) == 0) { + if (strcasecmp( dr->name, "BSR" ) == 0) { int i; part->boundary_length = len; @@ -90,7 +90,7 @@ cmd_register_run( char *params[] ) } /* Device Identification Register */ - if (strcmp( dr->name, "DIR" ) == 0) + if (strcasecmp( dr->name, "DIR" ) == 0) register_init( dr->out, register_get_string( part->id ) ); return 1; diff --git a/jtag/src/cmd/set.c b/jtag/src/cmd/set.c index d3b05233..9049a750 100644 --- a/jtag/src/cmd/set.c +++ b/jtag/src/cmd/set.c @@ -43,7 +43,7 @@ cmd_set_run( char *params[] ) if (cmd_params( params ) < 4 || cmd_params( params ) > 5) return -1; - if (strcmp( params[1], "signal" ) != 0) + if (strcasecmp( params[1], "signal" ) != 0) return -1; if (!cmd_test_cable()) @@ -60,10 +60,10 @@ cmd_set_run( char *params[] ) } /* direction */ - if (strcmp( params[3], "in" ) != 0 && strcmp( params[3], "out" ) != 0) + if (strcasecmp( params[3], "in" ) != 0 && strcasecmp( params[3], "out" ) != 0) return -1; - dir = (strcmp( params[3], "in" ) == 0) ? 0 : 1; + dir = (strcasecmp( params[3], "in" ) == 0) ? 0 : 1; if (dir) { if (cmd_get_number( params[4], &data )) diff --git a/jtag/src/cmd/shift.c b/jtag/src/cmd/shift.c index e27435bd..3101c6e5 100644 --- a/jtag/src/cmd/shift.c +++ b/jtag/src/cmd/shift.c @@ -41,11 +41,11 @@ cmd_shift_run( char *params[] ) if (!cmd_test_cable()) return 1; - if (strcmp( params[1], "ir" ) == 0) { + if (strcasecmp( params[1], "ir" ) == 0) { chain_shift_instructions( chain ); return 1; } - if (strcmp( params[1], "dr" ) == 0) { + if (strcasecmp( params[1], "dr" ) == 0) { chain_shift_data_registers( chain, 1 ); return 1; } diff --git a/jtag/src/part/part.c b/jtag/src/part/part.c index 3b598d1e..38fcc664 100644 --- a/jtag/src/part/part.c +++ b/jtag/src/part/part.c @@ -111,7 +111,7 @@ part_find_instruction( part_t *p, const char *iname ) i = p->instructions; while (i) { - if (strcmp( iname, i->name ) == 0) + if (strcasecmp( iname, i->name ) == 0) break; i = i->next; } @@ -129,7 +129,7 @@ part_find_data_register( part_t *p, const char *drname ) dr = p->data_registers; while (dr) { - if (strcmp( drname, dr->name ) == 0) + if (strcasecmp( drname, dr->name ) == 0) break; dr = dr->next; } diff --git a/jtag/src/tap/parport/direct.c b/jtag/src/tap/parport/direct.c index e353c8ed..c16eaf33 100644 --- a/jtag/src/tap/parport/direct.c +++ b/jtag/src/tap/parport/direct.c @@ -152,6 +152,7 @@ static cable_t * direct_connect( const char **par, int parnum ) { int i; + long int port_scan_val; unsigned int port; port_node_t *pn = ports; parport_t *parport; @@ -162,11 +163,16 @@ direct_connect( const char **par, int parnum ) return NULL; } - if ((sscanf( par[0], "0x%x", &port ) != 1) && (sscanf( par[0], "%d", &port ) != 1)) { + port_scan_val = strtol(par[0], NULL, 0); + + // if ((sscanf( par[0], "0x%x", &port ) != 1) && (sscanf( par[0], "%d", &port ) != 1)) { + if (port_scan_val < 0 || (port_scan_val + 3) > 0xffff) { printf( _("Invalid port address!\n") ); return NULL; } + port = (unsigned int )port_scan_val; + while (pn) for (pn = ports; pn; pn = pn->next) { unsigned int aport; @@ -179,13 +185,13 @@ direct_connect( const char **par, int parnum ) } } - if (strcmp( par[1], "none" ) == 0) { + if (strcasecmp( par[1], "none" ) == 0) { printf( _("Changed cable to 'none'\n") ); return NULL; } for (i = 0; cable_drivers[i]; i++) - if (strcmp( par[1], cable_drivers[i]->name ) == 0) + if (strcasecmp( par[1], cable_drivers[i]->name ) == 0) break; if (!cable_drivers[i]) { diff --git a/jtag/src/tap/parport/ppdev.c b/jtag/src/tap/parport/ppdev.c index e533ee9f..b6c3446b 100644 --- a/jtag/src/tap/parport/ppdev.c +++ b/jtag/src/tap/parport/ppdev.c @@ -126,7 +126,7 @@ ppdev_connect( const char **par, int parnum ) break; } - if (strcmp( par[1], "none" ) == 0) { + if (strcasecmp( par[1], "none" ) == 0) { printf( _("Changed cable to 'none'\n") ); return NULL; }