int main(int argc, const char **argv) { wi_pool_t *pool; wi_string_t *homepath, *wirepath, *path, *component; wi_file_t *file; int ch; /* init libwired */ wi_initialize(); wi_load(argc, argv); pool = wi_pool_init(wi_pool_alloc()); wi_log_callback = wr_wi_log_callback; /* init core systems */ wr_version_init(); wr_start_date = wi_date_init(wi_date_alloc()); /* set defaults */ wr_nick = wi_retain(wi_user_name()); homepath = wi_user_home(); wr_timestamp_format = wi_retain(WI_STR("%H:%M")); /* parse command line switches */ while((ch = getopt(argc, (char * const *) argv, "DhVv")) != -1) { switch(ch) { case 'D': wr_debug = true; wi_log_level = WI_LOG_DEBUG; wi_log_file = true; wi_log_path = WI_STR("wire.out"); wi_log_callback = NULL; break; case 'V': case 'v': wr_version(); break; case '?': case 'h': default: wr_usage(); break; } } argc -= optind; argv += optind; /* open log */ wi_log_open(); /* create ~/.wire */ wirepath = wi_string_by_appending_path_component(homepath, WI_STR(WR_WIRE_PATH)); wi_file_create_directory(wirepath, 0700); /* init subsystems */ wr_signals_init(); wr_terminal_init(); wr_readline_init(); wr_chats_init(); wr_windows_init(); wr_client_init(); wr_runloop_init(); wr_users_init(); wr_ignores_init(); wr_files_init(); wr_transfers_init(); wr_servers_init(); /* open default settings */ path = wi_string_by_appending_path_component(homepath, WI_STR(WR_WIRE_CONFIG_PATH)); file = wi_file_for_reading(path); if(file) wr_parse_file(file); else wr_printf_prefix(WI_STR("%@: %m"), path); /* read specified bookmark */ if(*argv) { component = wi_string_with_cstring(*argv); path = wi_string_by_appending_path_component(wirepath, component); file = wi_file_for_reading(path); if(file) wr_parse_file(file); else wr_printf_prefix(WI_STR("%@: %m"), path); } /* clean up pool after startup */ wi_pool_drain(pool); /* enter event loop */ wr_runloop_run(); /* clean up */ wr_cleanup(); wi_release(pool); return 0; }
int main(int argc, char *argv[]) { affinity_set(0); final_data_kvs_len_t wr_val; int nprocs = 0, map_tasks = 0, ndisp = 5, reduce_tasks = 0, quiet = 0, fast = 0; uint64_t inputsize = 0x80000000; int c; while ((c = getopt(argc, argv, "p:l:m:r:qs:f")) != -1) { switch (c) { case 'p': nprocs = atoi(optarg); break; case 'l': ndisp = atoi(optarg); break; case 'm': map_tasks = atoi(optarg); break; case 'r': reduce_tasks = atoi(optarg); break; case 's': inputsize = atol(optarg) * 1024 * 1024; break; case 'q': quiet = 1; break; case 'f': fast = 1; break; default: wr_usage(argv[0]); exit(EXIT_FAILURE); break; } } enum { wordlength = 3 }; uint32_t seed = 0; char *fdata = (char *) mmap(NULL, inputsize + 1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); assert(fdata != MAP_FAILED); uint64_t pos = 0; for (uint64_t i = 0; i < inputsize / (wordlength + 1); i++) { for (uint32_t j = 0; j < wordlength; j++) fdata[pos++] = rnd(&seed) % 26 + 'A'; fdata[pos++] = ' '; } memset(&fdata[pos], 0, inputsize - pos); if (fast) return 0; printf("Starting mapreduce\n"); fflush(stdout); do_mapreduce(nprocs, map_tasks, reduce_tasks, fdata, inputsize, &wr_val); printf("Finished mapreduce\n"); fflush(stdout); mr_print_stats(); if (!quiet) print_top(&wr_val, ndisp); mr_finalize(); return 0; }
int wirouterkeyrec(int argc, char *argv[]) { int debug = 0, verbose = 0, option = 0, optidx = 0, update = 0; struct option long_options[] = { {"ssid", 1, 0, 's'}, {"ssid_file", 1, 0, 'f'}, {"config", 1, 0, 'c'}, {"agpfurl", 1, 0, 'a'}, {"updateagpf", 0, 0, 'u'}, {"debug", 0, 0, 'd'}, {"help", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {NULL, 0, 0, 0} }; unsigned char *temp = NULL, *agpf_host = NULL, *agpf_url = NULL, *agpf_web_page = (unsigned char *) AGPF_DEFAULT_WEB_PAGE, wr_config_file[255]; /* Config File Name */ Essid_list *net_list = NULL; /* Networks list */ /* Print the usage */ if(argc < 2) wr_usage(argv[0]); memset(wr_config_file, 0, sizeof(wr_config_file)); while((option = getopt_long(argc, argv, "s:f:c:a:dhvu", long_options, &optidx)) > 0) { switch(option) { case 's': /* Multiple networks */ if(strstr(optarg, ",")) { /* Parsing List */ for(temp = (unsigned char *) strtok(optarg, ","); temp; temp = (unsigned char *) strtok(NULL, ",")) net_list = wr_essid_add(net_list, temp); } /* Just one network */ else { net_list = wr_essid_add(net_list, (unsigned char *)optarg); } if(!net_list) PRINT_FATAL_ERROR("Unable to get a valid SSID list [Errno: %s].", strerror(errno)); break; case 'f': /* Load networks from file */ net_list = wr_load_essid_from_file(net_list, (unsigned char *)optarg); if(!net_list) PRINT_FATAL_ERROR("Unable to get a valid SSID list [Errno: %s].", strerror(errno)); break; case 'c': /* Set a new configuration file */ if(strlen(optarg) < 255) strncpy((char *)wr_config_file, optarg, sizeof(wr_config_file)-1); else PRINT_ERROR("File name too long. Will be used the default config file (%s)", AGPF_DEFAULT_CONFIG_FILE); if(wr_check_file_exist(wr_config_file) < 0) PRINT_FATAL_ERROR("Unable to open the configuration file [Errno: %s].", strerror(errno)); break; case 'u': /* Update the configuration file */ update = 1; break; case 'a': /* Set the URL from where downloading the AGPF configuration file */ agpf_web_page = (unsigned char *)optarg; wr_parsing_web_page(agpf_web_page, &agpf_host, &agpf_url); if(!agpf_host || !agpf_url) PRINT_ERROR("Invalid URL. Will be used the default URL (%s)", AGPF_DEFAULT_WEB_PAGE); break; case 'd': debug = 1; break; case 'h': wr_usage(argv[0]); break; case 'v': verbose = 1; break; default: wr_usage(argv[0]); break; } } if(update) { PRINT_HEADER if(!agpf_host || !agpf_url) { agpf_web_page = (unsigned char *)AGPF_DEFAULT_WEB_PAGE; wr_parsing_web_page(agpf_web_page, &agpf_host, &agpf_url); if(!agpf_host || !agpf_url) PRINT_FATAL_ERROR("Unable to use the default URL (%s)", AGPF_DEFAULT_WEB_PAGE); } if(!wr_check_file_exist((unsigned char *) AGPF_DEFAULT_CONFIG_FILE_DIR)) agpf_update_config_file((unsigned char *)AGPF_DEFAULT_CONFIG_FILE_DIR, agpf_host, 80, agpf_url, NULL, NULL, debug); else agpf_update_config_file((unsigned char *)AGPF_DEFAULT_CONFIG_FILE, agpf_host, 80, agpf_url, NULL, NULL, debug); return 0; } if(!net_list) return -1; PRINT_HEADER net_list = wr_get_keys(net_list, wr_config_file, debug); /* Print the result */ if(net_list) { wr_print_essid(net_list, verbose); net_list = wr_essid_free(net_list); } else { printf("\nThere are no WPA keys found.\n\n"); return -1; } return 0; }