void Game::update_hud() { print_messages(); // Draw minimap cuss::element* minimap = i_hud.find_by_name("draw_minimap"); if (minimap) { int cornerx = map->posx - minimap->sizex / 2 + MAP_SIZE / 2; int cornery = map->posy - minimap->sizey / 2 + MAP_SIZE / 2; worldmap->draw_minimap(minimap, cornerx, cornery); } if (player->weapon.is_real()) { i_hud.set_data("text_weapon", player->weapon.get_name_full()); } else { i_hud.set_data("text_weapon", "None"); } i_hud.set_data("hp_head", player->hp_text(BODYPART_HEAD ) ); i_hud.set_data("hp_torso", player->hp_text(BODYPART_TORSO ) ); i_hud.set_data("hp_l_arm", player->hp_text(BODYPART_LEFT_ARM ) ); i_hud.set_data("hp_r_arm", player->hp_text(BODYPART_RIGHT_ARM) ); i_hud.set_data("hp_l_leg", player->hp_text(BODYPART_LEFT_LEG ) ); i_hud.set_data("hp_r_leg", player->hp_text(BODYPART_RIGHT_LEG) ); i_hud.draw(w_hud); w_hud->refresh(); }
int gui_messages_log_proc(int msg, DIALOG *d, int c __attribute__((unused))) { switch (msg) { case MSG_START: init_messages(d); break; case MSG_END: uninit_messages(); break; case MSG_NEW_LOG_TEXT: /* * Message indicating that there is a new message to be processed * and displayed. */ print_messages(d); break; case MSG_CLEAR_LOG_TEXT: clear_messages(d); break; } return D_O_K; }
void CLI::show_options() { cout << "-----------------------------------\n"; cout << " 1. Human vs Computer\n"; cout << " 2. Computer vs Human\n"; cout << " 3. Human vs Human\n"; cout << " 4. Computer vs Computer\n"; cout << " 5. Load game\n"; cout << " 6. Help (Moves/Commands)\n"; cout << " 7. Run Benchmark\n"; cout << " 8. Win At Chess Test\n"; cout << " 9. Settings\n"; cout << "-----------------------------------\n"; cout << " 0. Quit\n"; cout << "-----------------------------------\n"; print_messages(); }
board_struct *attempt_to_move(board_struct *parent_board, board_struct *current_board, success_failure *success_index, int row_coordinate, int col_coordinate, full_empty hashing_array[VERY_LARGE_NUMBER], int row, int col, int row_incr, int col_incr) { board_struct *new_board; //The two is as the space two away from the peg in the direction we wish to move must be empty in order to put a peg in. if(parent_board->board_array[row + row_incr][col + col_incr] == peg && parent_board->board_array[row + 2 * row_incr][col + 2 * col_incr] == space){ new_board = create_new_board_struct(); copy_in_parent_board(new_board, parent_board); generate_board(new_board, parent_board, current_board, row, col, row_incr, col_incr); check_for_success(new_board, row_coordinate, col_coordinate, success_index); count_board_pegs(new_board); generate_hash_string(new_board); if( check_modulus_hash_number(new_board, hashing_array) == seen_before){ if( check_unique_hash_number(new_board, current_board, new_board->number_pegs) == seen_before){ free(new_board); return(current_board); } } print_messages(new_board->number_pegs, success_index); return(new_board); } return(current_board); }
/* * main process: * axel_new() * axel_open() * axel_start() : setup_thread() * signal SIGINT/SIGTERM * while{ axel_do()} */ int main( int argc, char *argv[] ) { char fn[MAX_STRING] = ""; int do_search = 0; search_t *search; conf_t conf[1]; axel_t *axel; int i, j, cur_head = 0; char *s; #ifdef I18N setlocale( LC_ALL, "" ); bindtextdomain( PACKAGE, LOCALE ); textdomain( PACKAGE ); #endif if( !conf_init( conf ) ) { return( 1 ); } opterr = 0; j = -1; while( 1 ) { int option; option = getopt_long( argc, argv, "s:n:o:S::NqvhVam:H:U:", axel_options, NULL ); if( option == -1 ) break; switch( option ) { case 'U': strncpy( conf->user_agent, optarg, MAX_STRING); break; case 'H': strncpy( conf->add_header[cur_head++], optarg, MAX_STRING ); break; case 'm': // add by liuyan if( !sscanf( optarg, "%i", &conf->max_time ) ) { print_help(); return( 1 ); } break; case 's': if( !sscanf( optarg, "%i", &conf->max_speed ) ) { print_help(); return( 1 ); } break; case 'n': if( !sscanf( optarg, "%i", &conf->num_connections ) ) { print_help(); return( 1 ); } break; case 'o': strncpy( fn, optarg, MAX_STRING ); break; case 'S': do_search = 1; if( optarg != NULL ) if( !sscanf( optarg, "%i", &conf->search_top ) ) { print_help(); return( 1 ); } break; case 'a': conf->alternate_output = 1; break; case 'N': *conf->http_proxy = 0; break; case 'h': print_help(); return( 0 ); case 'v': if( j == -1 ) j = 1; else j ++; break; case 'V': print_version(); return( 0 ); case 'q': close( 1 ); conf->verbose = -1; if( open( "/dev/null", O_WRONLY ) != 1 ) { fprintf( stderr, _("Can't redirect stdout to /dev/null.\n") ); return( 1 ); } break; default: print_help(); return( 1 ); } } conf->add_header_count = cur_head; if( j > -1 ) conf->verbose = j; if( argc - optind == 0 ) { print_help(); return( 1 ); } else if( strcmp( argv[optind], "-" ) == 0 ) { s = malloc( MAX_STRING ); if (scanf( "%1024[^\n]s", s) != 1) { fprintf( stderr, _("Error when trying to read URL (Too long?).\n") ); return( 1 ); } } else { s = argv[optind]; if( strlen( s ) > MAX_STRING ) { fprintf( stderr, _("Can't handle URLs of length over %d\n" ), MAX_STRING ); return( 1 ); } } // 下载准备 printf( _("Initializing download: %s\n"), s ); if( do_search ) { search = malloc( sizeof( search_t ) * ( conf->search_amount + 1 ) ); memset( search, 0, sizeof( search_t ) * ( conf->search_amount + 1 ) ); search[0].conf = conf; if( conf->verbose ) printf( _("Doing search...\n") ); // 查询filesearching.com,获取多个url i = search_makelist( search, s ); if( i < 0 ) { fprintf( stderr, _("File not found\n" ) ); return( 1 ); } if( conf->verbose ) printf( _("Testing speeds, this can take a while...\n") ); // 测速 j = search_getspeeds( search, i ); search_sortlist( search, i ); if( conf->verbose ) { printf( _("%i usable servers found, will use these URLs:\n"), j ); j = min( j, conf->search_top ); printf( "%-60s %15s\n", "URL", "Speed" ); for( i = 0; i < j; i ++ ) printf( "%-70.70s %5i\n", search[i].url, search[i].speed ); printf( "\n" ); } // 搜索下载模式 axel = axel_new( conf, j, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } else if( argc - optind == 1 ) { // 单源直接下载 axel = axel_new( conf, 0, s ); //s is url_t( i.e. char* ) if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } else { // 多源直接下载 search = malloc( sizeof( search_t ) * ( argc - optind ) ); memset( search, 0, sizeof( search_t ) * ( argc - optind ) ); for( i = 0; i < ( argc - optind ); i ++ ) strncpy( search[i].url, argv[optind+i], MAX_STRING ); axel = axel_new( conf, argc - optind, search ); // search is search_t free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } print_messages( axel ); if( s != argv[optind] ) { free( s ); } if( *fn ) { struct stat buf; if( stat( fn, &buf ) == 0 ) { if( S_ISDIR( buf.st_mode ) ) { size_t fnlen = strlen(fn); size_t axelfnlen = strlen(axel->filename); if (fnlen + 1 + axelfnlen + 1 > MAX_STRING) { fprintf( stderr, _("Filename too long!\n")); return ( 1 ); } fn[fnlen] = '/'; memcpy(fn+fnlen+1, axel->filename, axelfnlen); fn[fnlen + 1 + axelfnlen] = '\0'; } } sprintf( string, "%s.st", fn ); if( access( fn, F_OK ) == 0 ) if( access( string, F_OK ) != 0 ) { fprintf( stderr, _("No state file, cannot resume!\n") ); return( 1 ); } if( access( string, F_OK ) == 0 ) if( access( fn, F_OK ) != 0 ) { printf( _("State file found, but no downloaded data. Starting from scratch.\n" ) ); unlink( string ); } strcpy( axel->filename, fn ); } else { /* Local file existence check */ i = 0; s = axel->filename + strlen( axel->filename ); while( 1 ) { sprintf( string, "%s.st", axel->filename ); if( access( axel->filename, F_OK ) == 0 ) { if( axel->conn[0].supported ) { if( access( string, F_OK ) == 0 ) break; } } else { if( access( string, F_OK ) ) break; } sprintf( s, ".%i", i ); i ++; } } // 打开文件(状态文件、数据文件) if( !axel_open( axel ) ) { print_messages( axel ); return( 1 ); } print_messages( axel ); axel_start( axel );// print_messages( axel ); if( conf->alternate_output ) { putchar('\n'); } axel->start_byte = axel->bytes_done; /* Install save_state signal handler for resuming support */ signal( SIGINT, stop ); signal( SIGTERM, stop ); while( !axel->ready && run ) { // 判断超时 if( gettime() - axel->start_time > conf->max_time ) { printf(_("\nTime's up (max_time=%ds) ! Download Incomplete!\n"), conf->max_time); axel->ready = 0; run = 0; break; } long long int prev; prev = axel->bytes_done; axel_do( axel ); // 真正下载数据的地方 if( conf->alternate_output ) { if( !axel->message && prev != axel->bytes_done ) print_alternate_output( axel ); } if( axel->message ) { if(conf->alternate_output==1) { putchar( '\r' ); for( i = 0; i < 79; i++ ) putchar( ' ' ); putchar( '\r' ); } else { putchar( '\n' ); } print_messages( axel ); } else if( axel->ready ) { putchar( '\n' ); } } strcpy( string + MAX_STRING / 2, size_human( axel->bytes_done - axel->start_byte ) ); if( axel->ready && run ) { printf( _("\nSuccessfully Downloaded %s in %s. (%.2f KB/s)\n"), string + MAX_STRING / 2, time_human( gettime() - axel->start_time ), (double) axel->bytes_per_second / 1024 ); } else { printf(_("\nDownload Failed.\n")); } i = axel->ready ? 0 : 2; axel_close( axel ); return( i ); }
int main( int argc, char *argv[] ) { char fn[MAX_STRING] = ""; int do_search = 0; search_t *search; conf_t conf[1]; axel_t *axel; int i, j, cur_head = 0; char *s; #ifdef I18N setlocale( LC_ALL, "" ); bindtextdomain( PACKAGE, LOCALE ); textdomain( PACKAGE ); #endif if( !conf_init( conf ) ) { return( 1 ); } opterr = 0; j = -1; while( 1 ) { int option; option = getopt_long( argc, argv, "s:n:o:S::NqvhVaH:U:", axel_options, NULL ); if( option == -1 ) break; switch( option ) { case 'U': strncpy( conf->user_agent, optarg, MAX_STRING); break; case 'H': strncpy( conf->add_header[cur_head++], optarg, MAX_STRING ); break; case 's': if( !sscanf( optarg, "%i", &conf->max_speed ) ) { print_help(); return( 1 ); } break; case 'n': if( !sscanf( optarg, "%i", &conf->num_connections ) ) { print_help(); return( 1 ); } break; case 'o': strncpy( fn, optarg, MAX_STRING ); break; case 'S': do_search = 1; if( optarg != NULL ) if( !sscanf( optarg, "%i", &conf->search_top ) ) { print_help(); return( 1 ); } break; case 'a': conf->alternate_output = 1; break; case 'N': *conf->http_proxy = 0; break; case 'h': print_help(); return( 0 ); case 'v': if( j == -1 ) j = 1; else j ++; break; case 'V': print_version(); return( 0 ); case 'q': close( 1 ); conf->verbose = -1; if( open( "/dev/null", O_WRONLY ) != 1 ) { fprintf( stderr, _("Can't redirect stdout to /dev/null.\n") ); return( 1 ); } break; default: print_help(); return( 1 ); } } conf->add_header_count = cur_head; if( j > -1 ) conf->verbose = j; if( argc - optind == 0 ) { print_help(); return( 1 ); } else if( strcmp( argv[optind], "-" ) == 0 ) { s = malloc( MAX_STRING ); if (scanf( "%1024[^\n]s", s) != 1) { fprintf( stderr, _("Error when trying to read URL (Too long?).\n") ); return( 1 ); } } else { s = argv[optind]; if( strlen( s ) > MAX_STRING ) { fprintf( stderr, _("Can't handle URLs of length over %d\n" ), MAX_STRING ); return( 1 ); } } printf( _("Initializing download: %s\n"), s ); if( do_search ) { search = malloc( sizeof( search_t ) * ( conf->search_amount + 1 ) ); memset( search, 0, sizeof( search_t ) * ( conf->search_amount + 1 ) ); search[0].conf = conf; if( conf->verbose ) printf( _("Doing search...\n") ); i = search_makelist( search, s ); if( i < 0 ) { fprintf( stderr, _("File not found\n" ) ); return( 1 ); } if( conf->verbose ) printf( _("Testing speeds, this can take a while...\n") ); j = search_getspeeds( search, i ); search_sortlist( search, i ); if( conf->verbose ) { printf( _("%i usable servers found, will use these URLs:\n"), j ); j = min( j, conf->search_top ); printf( "%-60s %15s\n", "URL", "Speed" ); for( i = 0; i < j; i ++ ) printf( "%-70.70s %5i\n", search[i].url, search[i].speed ); printf( "\n" ); } axel = axel_new( conf, j, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } else if( argc - optind == 1 ) { axel = axel_new( conf, 0, s ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } else { search = malloc( sizeof( search_t ) * ( argc - optind ) ); memset( search, 0, sizeof( search_t ) * ( argc - optind ) ); for( i = 0; i < ( argc - optind ); i ++ ) strncpy( search[i].url, argv[optind+i], MAX_STRING ); axel = axel_new( conf, argc - optind, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return( 1 ); } } print_messages( axel ); if( s != argv[optind] ) { free( s ); } if( *fn ) { struct stat buf; if( stat( fn, &buf ) == 0 ) { if( S_ISDIR( buf.st_mode ) ) { size_t fnlen = strlen(fn); size_t axelfnlen = strlen(axel->filename); if (fnlen + 1 + axelfnlen + 1 > MAX_STRING) { fprintf( stderr, _("Filename too long!\n")); return ( 1 ); } fn[fnlen] = '/'; memcpy(fn+fnlen+1, axel->filename, axelfnlen); fn[fnlen + 1 + axelfnlen] = '\0'; } } sprintf( string, "%s.st", fn ); if( access( fn, F_OK ) == 0 && access( string, F_OK ) != 0 ) { fprintf( stderr, _("No state file, cannot resume!\n") ); return( 1 ); } if( access( string, F_OK ) == 0 && access( fn, F_OK ) != 0 ) { printf( _("State file found, but no downloaded data. Starting from scratch.\n" ) ); unlink( string ); } strcpy( axel->filename, fn ); } else { /* Local file existence check */ i = 0; s = axel->filename + strlen( axel->filename ); while( 1 ) { sprintf( string, "%s.st", axel->filename ); if( access( axel->filename, F_OK ) == 0 ) { if( axel->conn[0].supported ) { if( access( string, F_OK ) == 0 ) break; } } else { if( access( string, F_OK ) ) break; } sprintf( s, ".%i", i ); i ++; } } if( !axel_open( axel ) ) { print_messages( axel ); return( 1 ); } print_messages( axel ); axel_start( axel ); print_messages( axel ); if( conf->alternate_output ) { putchar('\n'); } else { if( axel->bytes_done > 0 ) /* Print first dots if resuming */ { putchar( '\n' ); print_commas( axel->bytes_done ); } } axel->start_byte = axel->bytes_done; /* Install save_state signal handler for resuming support */ signal( SIGINT, stop ); signal( SIGTERM, stop ); while( !axel->ready && run ) { long long int prev, done; prev = axel->bytes_done; axel_do( axel ); if( conf->alternate_output ) { if( !axel->message && prev != axel->bytes_done ) print_alternate_output( axel ); } else { /* The infamous wget-like 'interface'.. ;) */ done = ( axel->bytes_done / 1024 ) - ( prev / 1024 ); if( done && conf->verbose > -1 ) { for( i = 0; i < done; i ++ ) { i += ( prev / 1024 ); if( ( i % 50 ) == 0 ) { if( prev >= 1024 ) printf( " [%6.1fKB/s]", (double) axel->bytes_per_second / 1024 ); if( axel->size < 10240000 ) printf( "\n[%3lld%%] ", min( 100, 102400 * i / axel->size ) ); else printf( "\n[%3lld%%] ", min( 100, i / ( axel->size / 102400 ) ) ); } else if( ( i % 10 ) == 0 ) { putchar( ' ' ); } putchar( '.' ); i -= ( prev / 1024 ); } fflush( stdout ); } } if( axel->message ) { if(conf->alternate_output==1) { /* clreol-simulation */ putchar( '\r' ); for( i = 0; i < 79; i++ ) /* linewidth known? */ putchar( ' ' ); putchar( '\r' ); } else { putchar( '\n' ); } print_messages( axel ); if( !axel->ready ) { if(conf->alternate_output!=1) print_commas( axel->bytes_done ); else print_alternate_output(axel); } } else if( axel->ready ) { putchar( '\n' ); } } strcpy( string + MAX_STRING / 2, size_human( axel->bytes_done - axel->start_byte ) ); printf( _("\nDownloaded %s in %s. (%.2f KB/s)\n"), string + MAX_STRING / 2, time_human( gettime() - axel->start_time ), (double) axel->bytes_per_second / 1024 ); i = axel->ready ? 0 : 2; axel_close( axel ); return( i ); }
/** * @brief: c UART0 IRQ Handler */ void uart_iprocess(void) { uint8_t IIR_IntId; // Interrupt ID from IIR LPC_UART_TypeDef *pUart = (LPC_UART_TypeDef *)LPC_UART0; __disable_irq(); #ifdef DEBUG_0 //uart1_put_string("Entering c_UART0_IRQHandler\n\r"); #endif // DEBUG_0 /* Reading IIR automatically acknowledges the interrupt */ IIR_IntId = (pUart->IIR) >> 1 ; // skip pending bit in IIR if (IIR_IntId & IIR_RDA) { // Receive Data Avaialbe /* read UART. Read RBR will clear the interrupt */ // Perform a 'context switch' PCB *old_proc = gp_current_process; gp_current_process = k_get_process(PID_UART_IPROC); g_char_in = pUart->RBR; #ifdef DEBUG_0 uart1_put_string("Reading a char = "); uart1_put_char(g_char_in); uart1_put_string("\n\r"); #endif // DEBUG_0 // process the character. If it is a hotkey, call the corresponding function // If we are reading, fall through to default and add to the command buffer switch (g_char_in) { case '\r': case '\n': if (g_is_reading) { // We've finished reading a command, send it to the KCD process MSG_BUF *message; g_is_reading = 0; strcpy("\n\r", (char *)(g_in_buffer + g_in_index)); if (is_memory_available()) { message = k_request_memory_block(); message->mtype = DEFAULT; strcpy((char *)g_in_buffer, message->mtext); k_send_message(PID_KCD, message); } g_in_index = 0; } break; case '%': if (!g_is_reading) { // Start reading a command g_is_reading = 1; g_in_index = 1; g_in_buffer[0] = '%'; break; } #if defined(DEBUG_0) && defined(_DEBUG_HOTKEYS) case READY_Q_COMMAND: if (!g_is_reading) { print_ready(); break; } case MEMORY_Q_COMMAND: if (!g_is_reading) { print_mem_blocked(); break; } case RECEIVE_Q_COMMAND: if (!g_is_reading) { print_receive_blocked(); break; } case MESSAGE_COMMAND: if (!g_is_reading) { print_messages(); break; } #endif /* DEBUG HOTKEYS */ default: if (g_is_reading) { // TODO: check bounds g_in_buffer[g_in_index++] = g_char_in; } } gp_current_process = old_proc; } else if (IIR_IntId & IIR_THRE) { /* THRE Interrupt, transmit holding register becomes empty */ // Check for messages and load the buffer // Perform a 'context switch' to the i-process MSG_BUF *message; PCB *old_proc = gp_current_process; gp_current_process = k_get_process(PID_UART_IPROC); // Don't block waiting for a message while (is_message(PID_UART_IPROC)) { int sender = PID_CRT; char *c; // Receive message and copy it to the buffer message = k_receive_message(&sender); c = message->mtext; //dprintf("Copying message to buffer: %s\n\r", message->mtext); if (*c != '\0') { do { g_out_buffer[g_out_end] = *c; g_out_end = (g_out_end + 1) % OUTPUT_BUFF_SIZE; c++; } while (g_out_end != g_out_start && *c != '\0'); } k_release_memory_block(message); } // Check if there is something in the circular buffer if (g_out_start != g_out_end) { g_char_out = g_out_buffer[g_out_start]; pUart->THR = g_char_out; g_out_start = (g_out_start + 1) % OUTPUT_BUFF_SIZE; } else { // nothing to print, disable the THRE interrupt pUart->IER ^= IER_THRE; // toggle (disable) the IER_THRE bit } gp_current_process = old_proc; } else { /* not implemented yet */ #ifdef DEBUG_0 //uart1_put_string("Should not get here!\n\r"); #endif // DEBUG_0 __enable_irq(); return; } __enable_irq(); }
void start_download(const char* url, const char* saving_path, int max_count, int max_speed, int taskId) { DebugMsg("start_download: %s %s", url, saving_path); char fn[MAX_STRING] = ""; int do_search = 0; search_t *search; conf_t conf[1]; axel_t *axel; int i, j, cur_head = 0; char *s; if( !conf_init( conf ) ) { return; } // strncpy( conf->user_agent, optarg, MAX_STRING); case 'U': // strncpy( conf->add_header[cur_head++], optarg, MAX_STRING ); case 'H': if (max_speed > 0) { conf->max_speed = max_speed; // 限速,指定每秒下载最大byte } // conf->num_connections = 10; // 指定同时打开的线程数 // strncpy( fn, optarg, MAX_STRING ); // 指定本地输出文件 // do_search = 1; // 查找镜像 // if( optarg != NULL ) { // if( !sscanf( optarg, "%i", &conf->search_top ) ) // { // print_help(); // return( 1 ); // } // } // conf->alternate_output = 1; // 交替输出进度信息 // *conf->http_proxy = 0; // 不使用代理服务器 print_help(); // 打印帮助 print_version(); // 打印版本号 conf->verbose = 1; // 打印更多状态信息 conf->task_id = taskId; s = (char*)url; strncpy(conf->saving_path, saving_path, sizeof(conf->saving_path) - 1); conf->add_header_count = cur_head; printf( _("Initializing download: %s\n"), s ); if( do_search == 1) { search = (search_t*)malloc( sizeof( search_t ) * ( conf->search_amount + 1 ) ); memset( search, 0, sizeof( search_t ) * ( conf->search_amount + 1 ) ); search[0].conf = conf; if( conf->verbose ) printf( _("Doing search...\n") ); i = search_makelist( search, s ); if( i < 0 ) { fprintf( stderr, _("File not found\n" ) ); return; } if( conf->verbose ) printf( _("Testing speeds, this can take a while...\n") ); j = search_getspeeds( search, i ); search_sortlist( search, i ); if( conf->verbose ) { printf( _("%i usable servers found, will use these URLs:\n"), j ); j = __min( j, conf->search_top ); printf( "%-60s %15s\n", "URL", "Speed" ); for( i = 0; i < j; i ++ ) printf( "%-70.70s %5i\n", search[i].url, search[i].speed ); printf( "\n" ); } axel = axel_new( conf, j, search ); free( search ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return; } } else if (do_search == 0) { axel = axel_new( conf, 0, s ); if( axel->ready == -1 ) { print_messages( axel ); axel_close( axel ); return; } } else { // 多个url地址进行搜寻 // search = (search_t*)malloc( sizeof( search_t ) * ( argc - optind ) ); // memset( search, 0, sizeof( search_t ) * ( argc - optind ) ); // for( i = 0; i < ( argc - optind ); i ++ ) // strncpy( search[i].url, argv[optind+i], MAX_STRING ); // axel = axel_new( conf, argc - optind, search ); // free( search ); // if( axel->ready == -1 ) // { // print_messages( axel ); // axel_close( axel ); // return( 1 ); // } } print_messages( axel ); // 指定输出文件 if( *fn ) { struct stat buf; if( stat( fn, &buf ) == 0 ) { if( S_ISDIR( buf.st_mode ) ) { size_t fnlen = strlen(fn); size_t axelfnlen = strlen(axel->filename); if (fnlen + 1 + axelfnlen + 1 > MAX_STRING) { fprintf( stderr, _("Filename too long!\n")); return; } fn[fnlen] = '/'; memcpy(fn+fnlen+1, axel->filename, axelfnlen); fn[fnlen + 1 + axelfnlen] = '\0'; } } sprintf( string, "%s.st", fn ); if( access( fn, F_OK ) == 0 ) if( access( string, F_OK ) != 0 ) { fprintf( stderr, _("No state file, cannot resume!\n") ); return; } if( access( string, F_OK ) == 0 ) if( access( fn, F_OK ) != 0 ) { printf( _("State file found, but no downloaded data. Starting from scratch.\n" ) ); unlink( string ); } strcpy( axel->filename, fn ); } else { /* Local file existence check */ i = 0; s = axel->filename + strlen( axel->filename ); while( 1 ) { char szTempPath[512] = {0}; char szFilePath[512] = {0}; snprintf(szTempPath, sizeof(szTempPath) - 1, "%s/%s.st", axel->conf[0].saving_path, axel->filename); snprintf(szFilePath, sizeof(szFilePath) - 1, "%s/%s", axel->conf[0].saving_path, axel->filename); if( access(szFilePath, F_OK ) == 0 ) { if( axel->conn[0].supported ) { if( access(szTempPath, F_OK ) == 0 ) break; } } else { if( access( szTempPath, F_OK ) ) break; } sprintf( s, ".%i", i ); i ++; } } if( !axel_open( axel ) ) { print_messages( axel ); return; } print_messages( axel ); axel_start( axel ); print_messages( axel ); if( conf->alternate_output ) { putchar('\n'); } else { if( axel->bytes_done > 0 ) /* Print first dots if resuming */ { putchar( '\n' ); print_commas( axel->bytes_done ); } } axel->start_byte = axel->bytes_done; /* Install save_state signal handler for resuming support */ signal( SIGINT, stop ); signal( SIGTERM, stop ); while( !axel->ready && run ) { long long int prev, done; prev = axel->bytes_done; axel_do( axel ); update_percent(axel->conf[0].task_id, axel->size, axel->bytes_done, 1.0 * axel->bytes_done / __max(axel->size, 1), axel->bytes_per_second); if (g_verbose) { if( conf->alternate_output ) { if( !axel->message && prev != axel->bytes_done ) { print_alternate_output( axel ); } } else { /* The infamous wget-like 'interface'.. ;) */ done = ( axel->bytes_done / 1024 ) - ( prev / 1024 ); if( done && conf->verbose > -1 ) { for( i = 0; i < done; i ++ ) { i += ( prev / 1024 ); if( ( i % 50 ) == 0 ) { if( prev >= 1024 ) printf( " [%6.1fKB/s]", (double) axel->bytes_per_second / 1024 ); if( axel->size < 10240000 ) printf( "\n[%3lld%%] ", __min( 100, 102400 * i / axel->size ) ); else printf( "\n[%3lld%%] ", __min( 100, i / ( axel->size / 102400 ) ) ); } else if( ( i % 10 ) == 0 ) { putchar( ' ' ); } putchar( '.' ); i -= ( prev / 1024 ); } fflush( stdout ); } } if( axel->message ) { if(conf->alternate_output==1) { /* clreol-simulation */ putchar( '\r' ); for( i = 0; i < 79; i++ ) /* linewidth known? */ putchar( ' ' ); putchar( '\r' ); } else { putchar( '\n' ); } print_messages( axel ); if( !axel->ready ) { if(conf->alternate_output!=1) print_commas( axel->bytes_done ); else print_alternate_output(axel); } } else if( axel->ready ) { putchar( '\n' ); } } } strcpy( string + MAX_STRING / 2, size_human( axel->bytes_done - axel->start_byte ) ); printf( _("\nDownloaded %s in %s. (%.2f KB/s)\n"), string + MAX_STRING / 2, time_human( gettime() - axel->start_time ), (double) axel->bytes_per_second / 1024 ); i = axel->ready ? 0 : 2; axel_close( axel ); return; }