Changeset 6379
- Timestamp:
- Jul 21, 2008, 7:24:35 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/remote.c
r6378 r6379 318 318 case 912: tr_bencDictAddStr( &top, "method", "session-set" ); 319 319 tr_bencDictAddStr( args, "encryption", "tolerated" ); 320 break; 321 case TR_OPT_ERR: 322 fprintf( stderr, "invalid option\n" ); 323 showUsage( ); 320 324 break; 321 325 default: fprintf( stderr, "got opt [%d]\n", (int)c ); -
trunk/libtransmission/tr-getopt.c
r6316 r6379 112 112 findOption( const tr_option * opts, 113 113 const char * str, 114 const char ** nested ) 115 { 116 size_t len; 114 const char ** setme_arg ) 115 { 116 size_t matchlen = 0; 117 const char * arg = NULL; 117 118 const tr_option * o; 118 119 /* try all the longopts first to avoid collisions between 120 long options, and short options with args appended to them */ 121 for( o=opts; o->val; ++o ) { 122 if( o->longName && (str[0]=='-') && (str[1]=='-') ) { 123 if( !strcmp( o->longName, str+2 ) ) { 124 if( nested ) *nested = NULL; 125 return o; 126 } 127 len = strlen( o->longName ); 128 if( !memcmp( o->longName, str+2, len ) && str[len+2]=='=' ) { 129 if( nested ) *nested = str+len+3; 130 return o; 119 const tr_option * match = NULL; 120 121 /* find the longest matching option */ 122 for( o=opts; o->val; ++o ) 123 { 124 size_t len = o->longName ? strlen( o->longName ) : 0; 125 126 if( ( matchlen < len ) && !memcmp( str, "--", 2 ) 127 && !memcmp( str+2, o->longName, len ) 128 && ( str[len+2]=='\0' || ( o->has_arg && str[len+2]=='=' ) ) ) 129 { 130 matchlen = len; 131 match = o; 132 arg = str[len+2]=='=' ? str+len+3 : NULL; 133 } 134 135 len = o->shortName ? strlen( o->shortName ) : 0; 136 137 if( ( matchlen < len ) && !memcmp( str, "-", 1 ) 138 && !memcmp( str+1, o->shortName, len ) 139 && ( str[len+1]=='\0' || o->has_arg ) ) 140 { 141 matchlen = len; 142 match = o; 143 switch( str[len+1] ) { 144 case '\0': arg = NULL; break; 145 case '=': arg = str + len + 2; break; 146 default: arg = str + len + 1; break; 131 147 } 132 148 } 133 149 } 134 150 135 /* look for a matching shortopt */ 136 for( o=opts; o->val; ++o ) 137 { 138 if( o->shortName && (str[0]=='-') ) { 139 if( !strcmp( o->shortName, str+1 ) ) { 140 if( nested ) *nested = NULL; 141 return o; 142 } 143 len = strlen( o->shortName ); 144 if( !memcmp( o->shortName, str+1, len ) ) { 145 if( nested ) 146 *nested = str[len+1]=='=' ? str+len+2 : str+len+1; 147 return o; 148 } 149 } 150 } 151 152 return NULL; 151 if( setme_arg ) 152 *setme_arg = arg; 153 154 return match; 153 155 } 154 156 … … 161 163 { 162 164 int i; 163 const char * nest= NULL;165 const char * arg = NULL; 164 166 const tr_option * o = NULL; 165 167 … … 178 180 return TR_OPT_DONE; 179 181 180 o = findOption( opts, argv[tr_optind], & nest);182 o = findOption( opts, argv[tr_optind], &arg ); 181 183 if( !o ) { 182 184 /* let the user know we got an unknown option... */ … … 187 189 if( !o->has_arg ) { 188 190 /* no argument needed for this option, so we're done */ 189 if( nest)191 if( arg ) 190 192 return TR_OPT_ERR; 191 193 *setme_optarg = NULL; 192 tr_optind++;194 ++tr_optind; 193 195 return o->val; 194 196 } 195 197 196 /* option needed an argument, and it was nested in this string */197 if( nest) {198 *setme_optarg = nest;199 tr_optind++;198 /* option needed an argument, and it was embedded in this string */ 199 if( arg ) { 200 *setme_optarg = arg; 201 ++tr_optind; 200 202 return o->val; 201 203 }
Note: See TracChangeset
for help on using the changeset viewer.