mirror of
https://github.com/transmission/transmission
synced 2025-02-03 04:53:27 +00:00
#1099: transmission-remote confuses -ph, -pn and -pl (priorities) options with the -p (port) option
This commit is contained in:
parent
c47c620a47
commit
5da99a7360
2 changed files with 44 additions and 38 deletions
|
@ -318,6 +318,10 @@ readargs( int argc, const char ** argv )
|
||||||
case 912: tr_bencDictAddStr( &top, "method", "session-set" );
|
case 912: tr_bencDictAddStr( &top, "method", "session-set" );
|
||||||
tr_bencDictAddStr( args, "encryption", "tolerated" );
|
tr_bencDictAddStr( args, "encryption", "tolerated" );
|
||||||
break;
|
break;
|
||||||
|
case TR_OPT_ERR:
|
||||||
|
fprintf( stderr, "invalid option\n" );
|
||||||
|
showUsage( );
|
||||||
|
break;
|
||||||
default: fprintf( stderr, "got opt [%d]\n", (int)c );
|
default: fprintf( stderr, "got opt [%d]\n", (int)c );
|
||||||
showUsage( );
|
showUsage( );
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -111,45 +111,47 @@ tr_getopt_usage( const char * progName,
|
||||||
static const tr_option *
|
static const tr_option *
|
||||||
findOption( const tr_option * opts,
|
findOption( const tr_option * opts,
|
||||||
const char * str,
|
const char * str,
|
||||||
const char ** nested )
|
const char ** setme_arg )
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t matchlen = 0;
|
||||||
|
const char * arg = NULL;
|
||||||
const tr_option * o;
|
const tr_option * o;
|
||||||
|
const tr_option * match = NULL;
|
||||||
|
|
||||||
/* try all the longopts first to avoid collisions between
|
/* find the longest matching option */
|
||||||
long options, and short options with args appended to them */
|
|
||||||
for( o=opts; o->val; ++o ) {
|
|
||||||
if( o->longName && (str[0]=='-') && (str[1]=='-') ) {
|
|
||||||
if( !strcmp( o->longName, str+2 ) ) {
|
|
||||||
if( nested ) *nested = NULL;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
len = strlen( o->longName );
|
|
||||||
if( !memcmp( o->longName, str+2, len ) && str[len+2]=='=' ) {
|
|
||||||
if( nested ) *nested = str+len+3;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* look for a matching shortopt */
|
|
||||||
for( o=opts; o->val; ++o )
|
for( o=opts; o->val; ++o )
|
||||||
{
|
{
|
||||||
if( o->shortName && (str[0]=='-') ) {
|
size_t len = o->longName ? strlen( o->longName ) : 0;
|
||||||
if( !strcmp( o->shortName, str+1 ) ) {
|
|
||||||
if( nested ) *nested = NULL;
|
if( ( matchlen < len ) && !memcmp( str, "--", 2 )
|
||||||
return o;
|
&& !memcmp( str+2, o->longName, len )
|
||||||
}
|
&& ( str[len+2]=='\0' || ( o->has_arg && str[len+2]=='=' ) ) )
|
||||||
len = strlen( o->shortName );
|
{
|
||||||
if( !memcmp( o->shortName, str+1, len ) ) {
|
matchlen = len;
|
||||||
if( nested )
|
match = o;
|
||||||
*nested = str[len+1]=='=' ? str+len+2 : str+len+1;
|
arg = str[len+2]=='=' ? str+len+3 : NULL;
|
||||||
return o;
|
}
|
||||||
|
|
||||||
|
len = o->shortName ? strlen( o->shortName ) : 0;
|
||||||
|
|
||||||
|
if( ( matchlen < len ) && !memcmp( str, "-", 1 )
|
||||||
|
&& !memcmp( str+1, o->shortName, len )
|
||||||
|
&& ( str[len+1]=='\0' || o->has_arg ) )
|
||||||
|
{
|
||||||
|
matchlen = len;
|
||||||
|
match = o;
|
||||||
|
switch( str[len+1] ) {
|
||||||
|
case '\0': arg = NULL; break;
|
||||||
|
case '=': arg = str + len + 2; break;
|
||||||
|
default: arg = str + len + 1; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
if( setme_arg )
|
||||||
|
*setme_arg = arg;
|
||||||
|
|
||||||
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -160,7 +162,7 @@ tr_getopt( const char * usage,
|
||||||
const char ** setme_optarg )
|
const char ** setme_optarg )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char * nest = NULL;
|
const char * arg = NULL;
|
||||||
const tr_option * o = NULL;
|
const tr_option * o = NULL;
|
||||||
|
|
||||||
*setme_optarg = NULL;
|
*setme_optarg = NULL;
|
||||||
|
@ -177,7 +179,7 @@ tr_getopt( const char * usage,
|
||||||
if( argc==1 || tr_optind>=argc )
|
if( argc==1 || tr_optind>=argc )
|
||||||
return TR_OPT_DONE;
|
return TR_OPT_DONE;
|
||||||
|
|
||||||
o = findOption( opts, argv[tr_optind], &nest );
|
o = findOption( opts, argv[tr_optind], &arg );
|
||||||
if( !o ) {
|
if( !o ) {
|
||||||
/* let the user know we got an unknown option... */
|
/* let the user know we got an unknown option... */
|
||||||
*setme_optarg = argv[tr_optind++];
|
*setme_optarg = argv[tr_optind++];
|
||||||
|
@ -186,17 +188,17 @@ tr_getopt( const char * usage,
|
||||||
|
|
||||||
if( !o->has_arg ) {
|
if( !o->has_arg ) {
|
||||||
/* no argument needed for this option, so we're done */
|
/* no argument needed for this option, so we're done */
|
||||||
if( nest )
|
if( arg )
|
||||||
return TR_OPT_ERR;
|
return TR_OPT_ERR;
|
||||||
*setme_optarg = NULL;
|
*setme_optarg = NULL;
|
||||||
tr_optind++;
|
++tr_optind;
|
||||||
return o->val;
|
return o->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* option needed an argument, and it was nested in this string */
|
/* option needed an argument, and it was embedded in this string */
|
||||||
if( nest ) {
|
if( arg ) {
|
||||||
*setme_optarg = nest;
|
*setme_optarg = arg;
|
||||||
tr_optind++;
|
++tr_optind;
|
||||||
return o->val;
|
return o->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue