Changeset 6306
- Timestamp:
- Jul 9, 2008, 3:31:35 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/cli.c
r6302 r6306 55 55 static sig_atomic_t manualUpdate = 0; 56 56 57 static const char * torrentPath 58 static const char * downloadDir 57 static const char * torrentPath = NULL; 58 static const char * downloadDir = NULL; 59 59 static const char * finishCall = NULL; 60 60 static const char * announce = NULL; … … 166 166 inf->pieceSize, inf->totalSize % inf->pieceSize ); 167 167 168 if( inf->comment [0])168 if( inf->comment && *inf->comment ) 169 169 fprintf( out, "comment:\t%s\n", inf->comment ); 170 if( inf->creator [0])170 if( inf->creator && *inf->creator ) 171 171 fprintf( out, "creator:\t%s\n", inf->creator ); 172 172 if( inf->isPrivate ) … … 175 175 fprintf( out, "file(s):\n" ); 176 176 for( ff=0; ff<inf->fileCount; ++ff ) 177 fprintf( out, "\t%s (%"PRIu64")\n", inf->files[ff].name, inf->files[ff].length ); 177 fprintf( out, "\t%s (%"PRIu64")\n", inf->files[ff].name, 178 inf->files[ff].length ); 178 179 } 179 180 … … 214 215 st->rateUpload, ratioStr ); 215 216 } 216 else if( st->status & TR_STATUS_STOPPED ) 217 { 218 *buf = '\0'; 219 } 217 else *buf = '\0'; 220 218 } 221 219 … … 297 295 { 298 296 int err; 299 tr_metainfo_builder * b uilder= tr_metaInfoBuilderCreate( h, sourceFile );297 tr_metainfo_builder * b = tr_metaInfoBuilderCreate( h, sourceFile ); 300 298 tr_tracker_info ti; 301 299 ti.tier = 0; 302 300 ti.announce = (char*) announce; 303 tr_makeMetaInfo( b uilder, torrentPath, &ti, 1, comment, isPrivate );304 while( !b uilder->isDone ) {301 tr_makeMetaInfo( b, torrentPath, &ti, 1, comment, isPrivate ); 302 while( !b->isDone ) { 305 303 tr_wait( 1000 ); 306 304 printf( "." ); 307 305 } 308 err = b uilder->result;309 tr_metaInfoBuilderFree( b uilder);306 err = b->result; 307 tr_metaInfoBuilderFree( b ); 310 308 return err; 311 309 } … … 339 337 ++leftToScrape; 340 338 tr_webRun( h, url, NULL, scrapeDoneFunc, host ); 339 tr_free( host ); 341 340 tr_free( url ); 342 341 } … … 394 393 if( gotsig ) { 395 394 gotsig = 0; 396 fprintf( stderr,"stopping torrent...\n" );395 printf( "stopping torrent...\n" ); 397 396 tr_torrentStop( tor ); 398 397 } … … 401 400 manualUpdate = 0; 402 401 if ( !tr_torrentCanManualUpdate( tor ) ) 403 fprintf( stderr, "\ rReceived SIGHUP, but can't send a manual update now\n" );402 fprintf( stderr, "\nReceived SIGHUP, but can't send a manual update now\n" ); 404 403 else { 405 fprintf( stderr, "\ rReceived SIGHUP: manual update scheduled\n" );404 fprintf( stderr, "\nReceived SIGHUP: manual update scheduled\n" ); 406 405 tr_torrentManualUpdate( tor ); 407 406 } … … 413 412 414 413 getStatusStr( st, line, sizeof( line ) ); 415 printf( " %-*s\n", LINEWIDTH, line );414 printf( "\r%-*s", LINEWIDTH, line ); 416 415 if( st->error ) 417 printf( " %s\n", st->errorString );416 printf( "\n%s\n", st->errorString ); 418 417 } 419 418 -
trunk/libtransmission/tr-getopt.c
r6298 r6306 2 2 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com> 3 3 * 4 * This file is licensed by the GPL version 2. Works owned by the 5 * Transmission project are granted a special exemption to clause 2(b) 6 * so that the bulk of its code can remain under the MIT license. 7 * This exemption does not extend to derived works not owned by 8 * the Transmission project. 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 9 21 * 10 22 * $Id:$ … … 21 33 #endif 22 34 23 int option_index= 1;35 int tr_optind = 1; 24 36 25 37 static const char* 26 38 getArgName( const tr_option * opt ) 27 39 { 28 if( !opt->has_arg ) return ""; 29 if( opt->argName ) return opt->argName; 30 return "<args>"; 40 char * arg; 41 42 if( !opt->has_arg ) 43 arg = ""; 44 else if( opt->argName ) 45 arg = opt->argName; 46 else 47 arg = "<args>"; 48 49 return arg; 31 50 } 32 51 … … 44 63 } 45 64 65 static void 66 maxWidth( const struct tr_option * o, 67 int * longWidth, int * shortWidth, int * argWidth ) 68 { 69 const char * arg; 70 71 if( o->longName ) 72 *longWidth = MAX( *longWidth, (int)strlen( o->longName ) ); 73 74 if( o->shortName ) 75 *shortWidth = MAX( *shortWidth, (int)strlen( o->shortName ) ); 76 77 if(( arg = getArgName( o ))) 78 *argWidth = MAX( *argWidth, (int)strlen( arg ) ); 79 } 80 46 81 void 47 tr_getopt_usage( const char * progName,48 const char * description,82 tr_getopt_usage( const char * progName, 83 const char * description, 49 84 const struct tr_option opts[] ) 50 85 { 51 int count; 52 int longWidth = 0; 53 int shortWidth = 0; 54 int argWidth = 0; 55 struct tr_option help; 56 57 for( count=0; opts[count].description; ++count ) 58 { 59 const char * arg; 60 61 if( opts[count].longName ) 62 longWidth = MAX( longWidth, (int)strlen( opts[count].longName ) ); 63 64 if( opts[count].shortName ) 65 shortWidth = MAX( shortWidth, (int)strlen( opts[count].shortName ) ); 66 67 if(( arg = getArgName( &opts[count] ))) 68 argWidth = MAX( argWidth, (int)strlen( arg ) ); 69 } 70 71 if( !description ) 72 description = "Usage: %s [options]"; 73 printf( description, progName ); 74 printf( "\n\n" ); 75 printf( "Options:\n" ); 76 77 help.val = -1; 78 help.longName = "help"; 79 help.description = "Display this help page and exit"; 80 help.shortName = "h"; 81 help.has_arg = 0; 82 getopts_usage_line( &help, longWidth, shortWidth, argWidth ); 83 84 for( count=0; opts[count].description; ++count ) 85 getopts_usage_line( &opts[count], longWidth, shortWidth, argWidth ); 86 int longWidth = 0; 87 int shortWidth = 0; 88 int argWidth = 0; 89 struct tr_option help; 90 const struct tr_option * o; 91 92 for( o=opts; o->val; ++o ) 93 maxWidth( o, &longWidth, &shortWidth, &argWidth ); 94 95 help.val = -1; 96 help.longName = "help"; 97 help.description = "Display this help page and exit"; 98 help.shortName = "h"; 99 help.has_arg = 0; 100 maxWidth( &help, &longWidth, &shortWidth, &argWidth ); 101 102 if( description == NULL ) 103 description = "Usage: %s [options]"; 104 printf( description, progName ); 105 printf( "\n\nOptions:\n" ); 106 getopts_usage_line( &help, longWidth, shortWidth, argWidth ); 107 for( o=opts; o->val; ++o ) 108 getopts_usage_line( o, longWidth, shortWidth, argWidth ); 86 109 } 87 110 … … 123 146 return NULL; 124 147 } 125 126 static void127 showUsageAndExit( const char * appName,128 const char * description,129 const tr_option * opts )130 {131 tr_getopt_usage( appName, description, opts );132 exit( 0 );133 }134 135 148 136 149 int … … 146 159 147 160 *setme_optarg = NULL; 148 149 if( argc==1 || argc==option_index )150 return TR_OPT_DONE;151 161 152 162 /* handle the builtin 'help' option */ 153 for( i=1; i<argc; ++i ) 154 if( !strcmp(argv[i], "-h") || !strcmp(argv[i], "--help" ) ) 155 showUsageAndExit( argv[0], usage, opts ); 156 157 /* out of options */ 158 if( option_index >= argc ) 163 for( i=1; i<argc; ++i ) { 164 if( !strcmp(argv[i], "-h") || !strcmp(argv[i], "--help" ) ) { 165 tr_getopt_usage( argv[0], usage, opts ); 166 exit( 0 ); 167 } 168 } 169 170 /* out of options? */ 171 if( argc==1 || tr_optind>=argc ) 159 172 return TR_OPT_DONE; 160 173 161 o = findOption( opts, argv[ option_index], &nest );174 o = findOption( opts, argv[tr_optind], &nest ); 162 175 if( !o ) { 163 176 /* let the user know we got an unknown option... */ 164 *setme_optarg = argv[ option_index++];177 *setme_optarg = argv[tr_optind++]; 165 178 return TR_OPT_UNK; 166 179 } … … 171 184 return TR_OPT_ERR; 172 185 *setme_optarg = NULL; 173 option_index++;186 tr_optind++; 174 187 return o->val; 175 188 } … … 178 191 if( nest ) { 179 192 *setme_optarg = nest; 180 option_index++;193 tr_optind++; 181 194 return o->val; 182 195 } 183 196 184 197 /* throw an error if the option needed an argument but didn't get one */ 185 if( ++ option_index>= argc )198 if( ++tr_optind >= argc ) 186 199 return TR_OPT_ERR; 187 if( findOption( opts, argv[ option_index], NULL ))200 if( findOption( opts, argv[tr_optind], NULL )) 188 201 return TR_OPT_ERR; 189 202 190 *setme_optarg = argv[ option_index++];203 *setme_optarg = argv[tr_optind++]; 191 204 return o->val; 192 205 } -
trunk/libtransmission/tr-getopt.h
r6297 r6306 2 2 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com> 3 3 * 4 * This file is licensed by the GPL version 2. Works owned by the 5 * Transmission project are granted a special exemption to clause 2(b) 6 * so that the bulk of its code can remain under the MIT license. 7 * This exemption does not extend to derived works not owned by 8 * the Transmission project. 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 9 21 * 10 22 * $Id:$ … … 42 54 /** 43 55 * @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK, 44 * or the matching tr_option's `val ue' field56 * or the matching tr_option's `val' field 45 57 */ 46 58 int tr_getopt( const char * summary,
Note: See TracChangeset
for help on using the changeset viewer.