int main(int argc, char **argv) { int ret; parse_loglevel(argc, argv, options); av_register_all(); avformat_network_init(); init_opts(); #if CONFIG_AVDEVICE avdevice_register_all(); #endif show_banner(); parse_options(NULL, argc, argv, options, opt_input_file); if (!input_filename) { show_usage(); fprintf(stderr, "You have to specify one input file.\n"); fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'.\n", program_name); exit(1); } ret = probe_file(input_filename); uninit_opts(); av_dict_free(&fmt_entries_to_show); avformat_network_deinit(); return ret; }
int main(int argc, char **argv) { int ret; av_register_all(); init_opts(); #if CONFIG_AVDEVICE avdevice_register_all(); #endif show_banner(); parse_options(argc, argv, options, opt_input_file); if (!input_filename) { show_usage(); fprintf(stderr, "You have to specify one input file.\n"); fprintf(stderr, "Use -h to get full help or, even better, run 'man ffprobe'.\n"); exit(1); } ret = probe_file(input_filename); av_free(avformat_opts); return ret; }
static void usage(u8* argv0) { show_banner(); SAYF("\n%s [ options ] -- /path/to/target_app [ ... ]\n\n" "Required parameters:\n\n" " -o file - file to write the trace data to\n\n" "Execution control settings:\n\n" " -t msec - timeout for each run (none)\n" " -m megs - memory limit for child process (%u MB)\n" " -Q - use binary-only instrumentation (QEMU mode)\n\n" "Other settings:\n\n" " -q - sink program's output and don't show messages\n" " -e - show edge coverage only, ignore hit counts\n\n" "This tool displays raw tuple data captured by AFL instrumentation.\n" "For additional help, consult %s/README.\n\n" cRST, argv0, MEM_LIMIT, doc_path); exit(1); }
/** *************************************************************************** * Show brief usage info and exit. * */ static void show_help() { show_banner(); printf("%% dupd operation options\n"); printf("\n"); opt_show_help(); }
/** *************************************************************************** * Show built-in documentation and exit. * Content is compiled into the binary from the manpage. * */ static void show_usage() { show_banner(); for (unsigned int c = 0; c < man_dupd_len; c++) { putchar((char)man_dupd[c]); } }
static void parse_args(int argc, char **argv) { prog_name = strdup(argv[0]); current_dir = get_current_dir_name (); show_banner(); if (argc < 2 || !strcmp (argv[1], "--help") || !strcmp (argv[1], "-h")) show_usage(); }
int main(int argc, char **argv) { int ret; uint8_t *buffer = av_malloc(AVP_BUFFSIZE); if (!buffer) exit(1); register_exit(avprobe_cleanup); options = real_options; parse_loglevel(argc, argv, options); av_register_all(); avformat_network_init(); init_opts(); #if CONFIG_AVDEVICE avdevice_register_all(); #endif show_banner(); octx.print_header = ini_print_header; octx.print_footer = ini_print_footer; octx.print_array_header = ini_print_array_header; octx.print_array_footer = ini_print_array_footer; octx.print_object_header = ini_print_object_header; octx.print_integer = ini_print_integer; octx.print_string = ini_print_string; parse_options(NULL, argc, argv, options, opt_input_file); if (!input_filename) { show_usage(); fprintf(stderr, "You have to specify one input file.\n"); fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'.\n", program_name); exit_program(1); } probe_out = avio_alloc_context(buffer, AVP_BUFFSIZE, 1, NULL, NULL, probe_buf_write, NULL); if (!probe_out) exit_program(1); probe_header(); ret = probe_file(input_filename); probe_footer(); avio_flush(probe_out); av_freep(&probe_out); av_freep(&buffer); uninit_opts(); avformat_network_deinit(); return ret; }
void shell_run(tree_t e, struct tree_rd_ctx *ctx) { const int ndecls = tree_decls(e); hash_t *decl_hash = hash_new(ndecls * 2, true); for (int i = 0; i < ndecls; i++) { tree_t d = tree_decl(e, i); hash_put(decl_hash, tree_ident(d), d); } Tcl_Interp *interp = Tcl_CreateInterp(); bool have_quit = false; Tcl_CreateExitHandler(shell_exit_handler, &have_quit); shell_cmd_t shell_cmds[] = { CMD(quit, &have_quit, "Exit simulation"), CMD(run, ctx, "Start or resume simulation"), CMD(restart, NULL, "Restart simulation"), CMD(show, decl_hash, "Display simulation objects"), CMD(help, shell_cmds, "Display this message"), CMD(copyright, NULL, "Display copyright information"), CMD(signals, e, "Find signal objects in the design"), CMD(now, NULL, "Display current simulation time"), CMD(watch, decl_hash, "Trace changes to a signal"), CMD(unwatch, decl_hash, "Stop tracing signals"), { NULL, NULL, NULL, NULL} }; qsort(shell_cmds, ARRAY_LEN(shell_cmds) - 1, sizeof(shell_cmd_t), compare_shell_cmd); for (shell_cmd_t *c = shell_cmds; c->name != NULL; c++) Tcl_CreateObjCommand(interp, c->name, c->fn, c->cd, NULL); show_banner(); slave_post_msg(SLAVE_RESTART, NULL, 0); char *line; while (!have_quit && (line = shell_get_line())) { switch (Tcl_Eval(interp, line)) { case TCL_OK: break; case TCL_ERROR: errorf("%s", Tcl_GetStringResult(interp)); break; default: assert(false); } free(line); } Tcl_Exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { show_banner(); std::cout << "VERSION " << VERSION << std::endl; std::cout << "started at " << timestamp_sql() << std::endl; std::cout << "reading config file from " << argv[1] << std::endl; read_config_file(argv[1],service_config); show_config(); try { if (argc <= 1) { std::cerr << "Usage: tcp_service <config_file>\n"; return EXIT_FAILURE; } db_ptr->set_hostname(service_config.dbhost_address.c_str()); db_ptr->set_username(service_config.dbuser.c_str()); db_ptr->set_password(service_config.dbpassword.c_str()); db_ptr->set_database(service_config.dbdatabase.c_str()); // for schema if(db_ptr->connect()) { std::cout << "connected to database " << db_ptr->get_database() << std::endl; }else { std::cout << "problems openning database " << db_ptr->get_database() << std::endl; exit(EXIT_FAILURE); } boost::asio::io_service io_service; server s(io_service, std::stoi(service_config.service_port,0,10)); s.set_query_begin(service_config.query_begin); s.set_query_end(service_config.query_end); /*boost::thread([](){ create_main_window(); });*/ io_service.run(); }catch (std::exception& e) { std::cerr << std::endl << "Exception: " << e.what() << "\n"; } return EXIT_SUCCESS; }
void run_B (int use_hw, int num_load_threads, thread_arg_t * arg) { unsigned int i=0; hthread_t measure_tidA, measure_tidB; hthread_t tids[num_load_threads]; hthread_mutexattr_t block_attr; hthread_mutexattr_t data_attr; // Print banner show_banner(num_load_threads); // Initialize thread argument fields // * Setup mutexes // * Initialize counter block_attr.num = 0; block_attr.type = HTHREAD_MUTEX_DEFAULT; data_attr.num = 1; data_attr.type = HTHREAD_MUTEX_DEFAULT; hthread_mutex_init(&arg->block_mutex, &block_attr); hthread_mutex_init(&arg->data_mutex, &data_attr); arg->counter = 0; // Create measurement thread A hthread_create(&measure_tidA, NULL, measureThread, (void*)arg); // Create measurement thread B hthread_create(&measure_tidB, NULL, testThreadWithMeasurement, (void*)arg); // Create all of the load threads dbg_printf("Creating load threads...\n"); for (i = 0; i < num_load_threads; i++) { // Create load thread hthread_create(&tids[i], NULL, testThread, (void*)arg); } // Make sure that measurement thread A runs hthread_join(measure_tidA,NULL); // Make sure that measurement thread B runs hthread_join(measure_tidB,NULL); // Wait for all load threads to complete for (i = 0; i < num_load_threads; i++) { // Join on load thread hthread_join(tids[i],NULL); } // Extract turn-around results // Turn-around = unlock_start to measure_lock_stop arg->measure_lock_check = calc_timediff_us(arg->unlock_start, arg->measure_lock_stop); return; }
/* * Returns true if the game has been won, else false. */ bool won() { for (int i = 0; i < DIM; i++) for (int j = 0; j < DIM; j++) if (g.board[j][i] == 0) return false; show_banner("You won! Congratulations!"); return true; }
/* * Returns true iff number ch represents a valid move, else false. */ bool validate(int ch) { ch -= '0'; char message[100]; hide_banner(); // check all numbers in the same row for (int i = 0; i < DIM; i++) if (g.board[g.y][i] == ch && i != g.x) { sprintf(message, "Illegal move: there is another %i in this row.", ch); show_banner(message); show_cursor(); return false; } // check all numbers in the same column for (int j = 0; j < DIM; j++) if (g.board[j][g.x] == ch && j != g.y) { sprintf(message, "Illegal move: there is another %i in this column.", ch); show_banner(message); show_cursor(); return false; } // check all numbers in the same 3x3 square for (int y = (g.y/3)*3; y < (g.y/3)*3 + 3; y++) for (int x = (g.x/3)*3; x < (g.x/3)*3 + 3; x++) if (g.board[y][x] == ch && g.x != x && g.y != y) { sprintf(message, "Illegal move: there is another %i in this square.", ch); show_banner(message); show_cursor(); return false; } return true; }
/* Show program help. */ static void show_help (poptContext ctx) { size_t ix; show_banner (); poptSetOtherOptionHelp (ctx, mocp_summary); poptPrintHelp (ctx, stdout, 0); printf ("\nEnvironment variables:\n\n"); for (ix = 0; ix < ARRAY_SIZE(environment_variables); ix += 1) printf (" %-34s%s\n", environment_variables[ix].name, environment_variables[ix].desc); printf ("\n"); }
bool check_row(int y) { //check one row for duplicates, y = y axis int row[9]; for(int i = 0; i < 9; i++) { row[i] = g.board[y][i]; for(int k = 0; k < i; k++) { if(row[k] != 0 && row[k] == row[i]) { hide_banner(); show_banner("You've got a row issue"); return false; } } } return true; }
bool check_col(int x) { //check one column for duplicates, x = x axis int col[9]; for(int i = 0; i < 9; i++) { col[i] = g.board[i][x]; for(int k = 0; k < i; k++) { if(col[k] != 0 && col[k] == col[i]) { hide_banner(); show_banner("You've got a column problem"); return false; } } } return true; }
static int no_results(ms_bitfield_info * output) { int elements = -1; int i = 0; int j = 0; int valid_elements = 0; if (output == NULL) { return -1; } elements = ms_get_size(output); for (i = 0; i < elements; ++i) { if (ms_get_status(output, i) == 0) { break; } } for (j = 0; j < elements; ++j) { if (ms_get_status(output, j) == 0) { ++valid_elements; } } if ((i < elements) || (flag_fb_showerrors == 1)) { /* at least one valid entry */ show_banner(0, valid_elements, elements); return 0; } else { printf("No results\n"); return -1; } }
void warn(void) { if (!check_cols(1)) show_banner("You have a column problem"); if (!check_rows(1)) show_banner("You have a row issue"); if (!check_squares(1)) show_banner("You have a square snare"); if (!check_cols(1) && !check_rows(1)) show_banner("You have a column problem and a row issue"); if (!check_cols(1) && !check_squares(1)) show_banner("You have a column problem and a square snare"); if (!check_rows(1) && !check_squares(1)) show_banner("You have a row issue and a square snare"); if (!check_rows(1) && !check_cols(1) && !check_squares(1)) show_banner("You have a column problem, a row issue and a square snare"); show_cursor(); }
bool game_won(void) { if(check_cols(0) && check_rows(0) && check_squares(0)) { show_banner("You won, have a sandwich!"); for (int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) { g.init_board[j][i] = 9; } } return true; } else return false; }
int main(int argc, char *argv[]) { enum COMMAND cmd; show_banner(); switch (parse_commandline(argc, argv)) { case COMMAND_INSTALL: return run_install(param0, param1); case COMMAND_REMOVE: return run_remove(param0); case COMMAND_CREATE: return run_create(param0, param2, param1); case COMMAND_UNPACK: return run_unpack(param0, param1); case COMMAND_UNDEFINED: default: show_usage(); return 1; } return EXIT_SUCCESS; }
int main(int argc, char **argv) { Images images; flif_options options = FLIF_DEFAULT_OPTIONS; #ifdef HAS_ENCODER int mode = -1; // 0 = encode, 1 = decode, 2 = transcode #else int mode = 1; #endif bool showhelp = false; if (strcmp(argv[0],"cflif") == 0) mode = 0; if (strcmp(argv[0],"dflif") == 0) mode = 1; if (strcmp(argv[0],"deflif") == 0) mode = 1; if (strcmp(argv[0],"decflif") == 0) mode = 1; static struct option optlist[] = { {"help", 0, NULL, 'h'}, {"decode", 0, NULL, 'd'}, {"verbose", 0, NULL, 'v'}, {"no-crc", 0, NULL, 'c'}, {"no-metadata", 0, NULL, 'm'}, {"no-color-profile", 0, NULL, 'p'}, {"quality", 1, NULL, 'q'}, {"scale", 1, NULL, 's'}, {"resize", 1, NULL, 'r'}, {"fit", 1, NULL, 'f'}, {"identify", 0, NULL, 'i'}, {"version", 0, NULL, 'V'}, {"overwrite", 0, NULL, 'o'}, {"breakpoints", 0, NULL, 'b'}, {"keep-palette", 0, NULL, 'k'}, #ifdef HAS_ENCODER {"encode", 0, NULL, 'e'}, {"transcode", 0, NULL, 't'}, {"interlace", 0, NULL, 'I'}, {"no-interlace", 0, NULL, 'N'}, {"frame-delay", 1, NULL, 'F'}, {"keep-invisible-rgb", 0, NULL, 'K'}, {"max-palette-size", 1, NULL, 'P'}, {"force-color-buckets", 0, NULL, 'A'}, {"no-color-buckets", 0, NULL, 'B'}, {"no-ycocg", 0, NULL, 'Y'}, {"no-channel-compact", 0, NULL, 'C'}, {"max-frame-lookback", 1, NULL, 'L'}, {"no-frame-shape", 0, NULL, 'S'}, {"maniac-repeats", 1, NULL, 'R'}, {"maniac-divisor", 1, NULL, 'D'}, {"maniac-min-size", 1, NULL, 'M'}, {"maniac-threshold", 1, NULL, 'T'}, {"chance-cutoff", 1, NULL, 'X'}, {"chance-alpha", 1, NULL, 'Z'}, {"lossy", 1, NULL, 'Q'}, {"adaptive", 0, NULL, 'U'}, {"guess", 1, NULL, 'G'}, {"invisible-guess", 1, NULL, 'H'}, {"effort", 1, NULL, 'E'}, {"chroma-subsample", 0, NULL, 'J'}, {"no-subtract-green", 0, NULL, 'W'}, #endif {0, 0, 0, 0} }; int i,c; #ifdef HAS_ENCODER while ((c = getopt_long (argc, argv, "hdvcmiVq:s:r:f:obketINnF:KP:ABYWCL:SR:D:M:T:X:Z:Q:UG:H:E:J", optlist, &i)) != -1) { #else while ((c = getopt_long (argc, argv, "hdvcmiVq:s:r:f:obk", optlist, &i)) != -1) { #endif switch (c) { case 'd': mode=1; break; case 'v': increase_verbosity(); break; case 'V': increase_verbosity(3); break; case 'c': options.crc_check = 0; break; case 'm': options.metadata = 0; break; case 'p': options.color_profile = 0; break; case 'o': options.overwrite = 1; break; case 'q': options.quality=atoi(optarg); if (options.quality < 0 || options.quality > 100) {e_printf("Not a sensible number for option -q\n"); return 1; } break; case 's': options.scale=atoi(optarg); if (options.scale < 1 || options.scale > 128) {e_printf("Not a sensible number for option -s\n"); return 1; } break; case 'r': if (sscanf(optarg,"%ix%i", &options.resize_width, &options.resize_height) < 1) { if (sscanf(optarg,"x%i", &options.resize_height) < 1) {e_printf("Not a sensible value for option -r (expected WxH)\n"); return 1; } } if (!options.resize_height) options.resize_height = options.resize_width; break; case 'f': if (sscanf(optarg,"%ix%i", &options.resize_width, &options.resize_height) < 1) { if (sscanf(optarg,"x%i", &options.resize_height) < 1) {e_printf("Not a sensible value for option -f (expected WxH)\n"); return 1; } } options.fit=1; break; case 'i': options.scale = -1; break; case 'b': options.show_breakpoints = 8; mode=1; break; case 'k': options.keep_palette = true; break; #ifdef HAS_ENCODER case 'e': mode=0; break; case 't': mode=2; break; case 'I': options.method.encoding=flifEncoding::interlaced; break; case 'n': // undocumented: lower case -n still works case 'N': options.method.encoding=flifEncoding::nonInterlaced; break; case 'A': options.acb=1; break; case 'B': options.acb=0; break; case 'P': options.palette_size=atoi(optarg); if (options.palette_size < -32000 || options.palette_size > 32000) {e_printf("Not a sensible number for option -P\n"); return 1; } if (options.palette_size > 512) {v_printf(1,"Warning: palette size above 512 implies that simple FLIF decoders (8-bit only) cannot decode this file.\n"); } if (options.palette_size == 0) {v_printf(5,"Palette disabled\n"); } break; case 'R': options.learn_repeats=atoi(optarg); if (options.learn_repeats < 0 || options.learn_repeats > 20) {e_printf("Not a sensible number for option -R\n"); return 1; } break; case 'F': options.frame_delay.clear(); while(optarg != 0) { int d=strtol(optarg,&optarg,10); if (d==0) break; if (*optarg == ',' || *optarg == '+' || *optarg == ' ') optarg++; options.frame_delay.push_back(d); if (d < 0 || d > 60000) {e_printf("Not a sensible number for option -F: %i\n",d); return 1; } } if (options.frame_delay.size() < 1) options.frame_delay.push_back(100); break; case 'L': options.lookback=atoi(optarg); if (options.lookback < -1 || options.lookback > 256) {e_printf("Not a sensible number for option -L\n"); return 1; } break; case 'D': options.divisor=atoi(optarg); if (options.divisor <= 0 || options.divisor > 0xFFFFFFF) {e_printf("Not a sensible number for option -D\n"); return 1; } break; case 'M': options.min_size=atoi(optarg); if (options.min_size < 0) {e_printf("Not a sensible number for option -M\n"); return 1; } break; case 'T': options.split_threshold=atoi(optarg); if (options.split_threshold <= 3 || options.split_threshold > 100000) {e_printf("Not a sensible number for option -T\n"); return 1; } options.split_threshold *= 5461; break; case 'Y': options.ycocg=0; break; case 'W': options.ycocg=0; options.subtract_green=0; break; case 'C': options.plc=0; break; case 'S': options.frs=0; break; case 'K': options.alpha_zero_special=0; break; case 'X': options.cutoff=atoi(optarg); if (options.cutoff < 1 || options.cutoff > 128) {e_printf("Not a sensible number for option -X (try something between 1 and 128)\n"); return 1; } break; case 'Z': options.alpha=atoi(optarg); if (options.alpha < 2 || options.alpha > 128) {e_printf("Not a sensible number for option -Z (try something between 2 and 128)\n"); return 1; } break; case 'Q': options.loss=100-atoi(optarg); // can't go above quality 100 = lossless // can go way below 0 if you want if (options.loss < 0) {e_printf("Not a sensible number for option -Q (try something between 0 and 100)\n"); return 1; } break; case 'U': options.adaptive=1; break; case 'G': { int p=0; while(*optarg != 0) { int d=0; switch (*optarg) { case '?': case 'G': case 'g': case 'H': case 'h': // guess/heuristically choose d = -2; break; case '0': case 'A': case 'a': // average d = 0; break; case '1': case 'M': case 'm': // median of 3 values (avg, grad1, grad2) d = 1; break; case '2': case 'N': case 'n': // median of 3 neighbors d = 2; break; case '3': case 'X': case 'x': // auto/mixed, usually a bad idea d = -1; break; case ' ': case ',': case '+': optarg++; continue; default: e_printf("Not a sensible value for option -G\nValid values are: 0 (avg), 1 (median avg/gradients), 2 (median neighbors), X (auto/mixed), ? (heuristically pick 0-2)\n"); return 1; } if (p>4) {e_printf("Error while parsing option -G: too many planes specified\n"); return 1; } options.predictor[p] = d; p++; optarg++; } for (; p<5; p++) options.predictor[p]=options.predictor[0]; } break; case 'H': options.invisible_predictor=atoi(optarg); if (options.invisible_predictor < 0 || options.invisible_predictor > 2) {e_printf("Not a sensible value for option -H\nValid values are: 0 (avg), 1 (median avg/gradients), 2 (median neighbors)\n"); return 1; } break; case 'J': options.chroma_subsampling = 1; break; case 'E': { int effort=atoi(optarg); if (effort < 0 || effort > 100) {e_printf("Not a sensible number for option -E (try something between 0 and 100)\n"); return 1; } // set some parameters automatically if (effort < 10) options.learn_repeats=0; else if (effort <= 50) {options.learn_repeats=1; options.split_threshold=5461*8*5;} else if (effort <= 70) {options.learn_repeats=2; options.split_threshold=5461*8*8;} else if (effort <= 90) {options.learn_repeats=3; options.split_threshold=5461*8*10;} else if (effort <= 100) {options.learn_repeats=4; options.split_threshold=5461*8*12;} if (effort < 15) { for (int i=0; i<5; i++) options.predictor[i]=0; } else if (effort < 30) { options.predictor[1]=0; options.predictor[2]=0; } if (effort < 5) options.acb=0; if (effort < 8) options.palette_size=0; if (effort < 25) options.plc=0; if (effort < 30) options.lookback=0; if (effort < 5) options.frs=0; v_printf(3,"Encode effort: %i, corresponds to parameters -R%i -T%i%s%s%s%s\n", effort, options.learn_repeats, options.split_threshold/5461, (effort<15?" -G0":(effort<30?" -G?00":"")), (effort<5?" -B":""), (effort<8?" -P0":""), (effort<25?" -C":"")); // not mentioning animation options since they're usually irrelevant } break; #endif case 'h': showhelp=true; break; default: show_help(mode); return 0; } } argc -= optind; argv += optind; bool last_is_output = (options.scale != -1); if (options.show_breakpoints && argc == 1) { last_is_output = false; options.no_full_decode = 1; options.scale = 2; } if (!strcmp(argv[argc-1],"-")) { // writing output to stdout, so redirecting verbose output to stderr to avoid contaminating the output stream redirect_stdout_to_stderr(); } show_banner(); if (argc == 0 || showhelp) { if (get_verbosity() == 1 || showhelp) show_help(mode); return 0; } if (argc == 1 && last_is_output) { show_help(mode); e_printf("\nOutput file missing.\n"); return 1; } if (options.scale == -1) mode = 1; if (mode < 0) mode = 0; if (file_exists(argv[0])) { char *f = strrchr(argv[0],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.'); #ifdef HAS_ENCODER if (mode == 0 && file_is_flif(argv[0])) { char *f = strrchr(argv[1],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[1],'.'); if ((ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { v_printf(3,"Input and output file are both FLIF file, adding implicit -t\n"); mode = 2; } else { v_printf(3,"Input file is a FLIF file, adding implicit -d\n"); mode = 1; } } if (mode == 0) { char *f = strrchr(argv[argc-1],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[argc-1],'.'); if (ext && !options.loss && strcasecmp(ext,".flif") && strcasecmp(ext,".flf") ) { e_printf("Warning: expected file name extension \".flif\" for output file.\n"); } else if (options.loss && check_compatible_extension(ext)) { v_printf(2,"Not doing actual lossy encoding to FLIF, just applying loss.\n"); options.just_add_loss = 1; } } if (mode != 0) { #endif if (!(ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { e_printf("Warning: expected file name extension \".flif\" for input file, trying anyway...\n"); } #ifdef HAS_ENCODER } else { if (!check_compatible_extension(ext)) { e_printf("Warning: expected \".png\", \".pnm\" or \".pam\" file name extension for input file, trying anyway...\n"); } } #endif } else if (argc>0) { if (!strcmp(argv[0],"-")) { v_printf(4,"Taking input from standard input. Mode: %s\n", (mode==0?"encode": (mode==1?"decode":"transcode"))); } else if (!strchr(argv[0],'%')) { e_printf("Error: input file does not exist: %s\n",argv[0]); return 1; } } if (last_is_output && file_exists(argv[argc-1]) && !options.overwrite) { e_printf("Error: output file already exists: %s\nUse --overwrite to force overwrite.\n",argv[argc-1]); return 1; } if (mode > 0 && argc > 2 && options.scale != -1) { e_printf("Too many arguments.\n"); return 1; } #ifdef HAS_ENCODER if (options.chroma_subsampling) v_printf(1,"Warning: chroma subsampling produces a truncated FLIF file. Image will not be lossless!\n"); if (options.loss > 0) options.keep_palette = false; // not going to add loss to indexed colors if (options.adaptive) options.loss = -options.loss; // use negative loss to indicate we want to do adaptive lossy encoding if (mode == 0) { if (!handle_encode(argc, argv, images, options)) return 2; } else if (mode == 1) { #endif return handle_decode(argc, argv, images, options); #ifdef HAS_ENCODER } else if (mode == 2) { // if (scale > 1) {e_printf("Not yet supported: transcoding downscaled image; use decode + encode!\n");} if (!decode_flif(argv, images, options)) return 2; argc--; argv++; if (!encode_flif(argc, argv, images, options)) return 2; } #endif return 0; }
int main(int argc, char *argv[]) { // define usage const char *usage = "Usage: sudoku n00b|l33t [#]\n"; // ensure that number of arguments is as expected if (argc != 2 && argc != 3) { fprintf(stderr, usage); return 1; } // ensure that level is valid if (strcmp(argv[1], "debug") == 0) g.level = "debug"; else if (strcmp(argv[1], "n00b") == 0) g.level = "n00b"; else if (strcmp(argv[1], "l33t") == 0) g.level = "l33t"; else { fprintf(stderr, usage); return 2; } // n00b and l33t levels have 1024 boards; debug level has 9 int max = (strcmp(g.level, "debug") == 0) ? 9 : 1024; // ensure that #, if provided, is in [1, max] if (argc == 3) { // ensure n is integral char c; if (sscanf(argv[2], " %d %c", &g.number, &c) != 1) { fprintf(stderr, usage); return 3; } // ensure n is in [1, max] if (g.number < 1 || g.number > max) { fprintf(stderr, "That board # does not exist!\n"); return 4; } // seed PRNG with # so that we get same sequence of boards srand(g.number); } else { // seed PRNG with current time so that we get any sequence of boards srand(time(NULL)); // choose a random n in [1, max] g.number = rand() % max + 1; } // start up ncurses if (!startup()) { fprintf(stderr, "Error starting up ncurses!\n"); return 5; } // register handler for SIGWINCH (SIGnal WINdow CHanged) signal(SIGWINCH, (void (*)(int)) handle_signal); // start the first game if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } redraw_all(); // initialize legal variable g.legal = true; // initialize won variable g.won = false; // let the user play! int ch; do { // refresh the screen refresh(); // get user's input ch = getch(); // capitalize input to simplify cases ch = toupper(ch); // process user's input switch (ch) { // start a new game case 'N': g.number = rand() % max + 1; if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // restart current game case 'R': if (!restart_game()) { shutdown(); fprintf(stderr, "Could not load board from disk!\n"); return 6; } break; // let user manually redraw screen with ctrl-L case CTRL('l'): redraw_all(); break; // move cursor on the board case KEY_DOWN: case KEY_UP: case KEY_LEFT: case KEY_RIGHT: move_cursor(ch); break; case KEY_BACKSPACE: case KEY_DC: case 46: // . case 48: // 0 case 49: // 1 case 50: // 2 case 51: // 3 case 52: // 4 case 53: // 5 case 54: // 6 case 55: // 7 case 56: // 8 case 57: // 9 change_number(ch); if(!legal(ch)) { show_banner("Illegal Move..."); show_cursor(); g.legal = false; } else { hide_banner(); show_cursor(); g.legal = true; } if(won(ch)) { show_banner("You Won The Game!!!"); g.won = true; } break; } // log input (and board's state) if any was received this iteration if (ch != ERR) log_move(ch); } while (ch != 'Q'); // shut down ncurses shutdown(); // tidy up the screen (using ANSI escape sequences) printf("\033[2J"); printf("\033[%d;%dH", 0, 0); // that's all folks printf("\nkthxbai!\n\n"); return 0; }
/* Show program usage. */ static void show_usage (poptContext ctx) { show_banner (); poptSetOtherOptionHelp (ctx, mocp_summary); poptPrintUsage (ctx, stdout, 0); }
int main(int argc, char** argv) { s32 opt; u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0; u32 tcnt; char** use_argv; doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH; while ((opt = getopt(argc,argv,"+o:m:t:A:eqZQ")) > 0) switch (opt) { case 'o': if (out_file) FATAL("Multiple -o options not supported"); out_file = optarg; break; case 'm': { u8 suffix = 'M'; if (mem_limit_given) FATAL("Multiple -m options not supported"); mem_limit_given = 1; if (!strcmp(optarg, "none")) { mem_limit = 0; break; } if (sscanf(optarg, "%llu%c", &mem_limit, &suffix) < 1 || optarg[0] == '-') FATAL("Bad syntax used for -m"); switch (suffix) { case 'T': mem_limit *= 1024 * 1024; break; case 'G': mem_limit *= 1024; break; case 'k': mem_limit /= 1024; break; case 'M': break; default: FATAL("Unsupported suffix or bad syntax for -m"); } if (mem_limit < 5) FATAL("Dangerously low value of -m"); if (sizeof(rlim_t) == 4 && mem_limit > 2000) FATAL("Value of -m out of range on 32-bit systems"); } break; case 't': if (timeout_given) FATAL("Multiple -t options not supported"); timeout_given = 1; if (strcmp(optarg, "none")) { exec_tmout = atoi(optarg); if (exec_tmout < 20 || optarg[0] == '-') FATAL("Dangerously low value of -t"); } break; case 'e': if (edges_only) FATAL("Multiple -e options not supported"); edges_only = 1; break; case 'q': if (quiet_mode) FATAL("Multiple -q options not supported"); quiet_mode = 1; break; case 'Z': /* This is an undocumented option to write data in the syntax expected by afl-cmin. Nobody else should have any use for this. */ cmin_mode = 1; quiet_mode = 1; break; case 'A': /* Another afl-cmin specific feature. */ at_file = optarg; break; case 'Q': if (qemu_mode) FATAL("Multiple -Q options not supported"); if (!mem_limit_given) mem_limit = MEM_LIMIT_QEMU; qemu_mode = 1; break; default: usage(argv[0]); } if (optind == argc || !out_file) usage(argv[0]); setup_shm(); setup_signal_handlers(); set_up_environment(); find_binary(argv[optind]); if (!quiet_mode) { show_banner(); ACTF("Executing '%s'...\n", target_path); } detect_file_args(argv + optind); if (qemu_mode) use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind); else use_argv = argv + optind; run_target(use_argv); tcnt = write_results(); if (!quiet_mode) { if (!tcnt) FATAL("No instrumentation detected" cRST); OKF("Captured %u tuples in '%s'." cRST, tcnt, out_file); } exit(child_crashed * 2 + child_timed_out); }
int main(int argc, char **argv) { Images images; #ifdef HAS_ENCODER int mode = 0; // 0 = encode, 1 = decode, 2 = transcode flifEncodingOptional method; int learn_repeats = -1; int acb = -1; // try auto color buckets int frame_delay = 100; int palette_size = -1; int lookback = 1; int divisor=CONTEXT_TREE_COUNT_DIV; int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE; int split_threshold=CONTEXT_TREE_SPLIT_THRESHOLD; int yiq = 1; int plc = 1; bool alpha_zero_special = true; #else int mode = 1; #endif int quality = 100; // 100 = everything, positive value: partial decode, negative value: only rough data int scale = 1; bool showhelp = false; if (strcmp(argv[0],"flif") == 0) mode = 0; if (strcmp(argv[0],"dflif") == 0) mode = 1; if (strcmp(argv[0],"deflif") == 0) mode = 1; if (strcmp(argv[0],"decflif") == 0) mode = 1; static struct option optlist[] = { {"help", 0, NULL, 'h'}, {"decode", 0, NULL, 'd'}, {"verbose", 0, NULL, 'v'}, {"quality", 1, NULL, 'q'}, {"scale", 1, NULL, 's'}, {"identify", 1, NULL, 'I'}, #ifdef HAS_ENCODER {"encode", 0, NULL, 'e'}, {"transcode", 0, NULL, 't'}, {"interlace", 0, NULL, 'i'}, {"no-interlace", 0, NULL, 'n'}, {"acb", 0, NULL, 'a'}, {"no-acb", 0, NULL, 'b'}, {"palette", 1, NULL, 'p'}, {"repeats", 1, NULL, 'r'}, {"frame-delay", 1, NULL, 'f'}, {"lookback", 1, NULL, 'l'}, {"divisor", 1, NULL, 'D'}, {"min-size", 1, NULL, 'M'}, {"split-threshold", 1, NULL, 'S'}, {"rgb", 0, NULL, 'R'}, {"no-plc", 0, NULL, 'C'}, {"keep-alpha-zero", 0, NULL, 'A'}, #endif {0, 0, 0, 0} }; int i,c; #ifdef HAS_ENCODER while ((c = getopt_long (argc, argv, "hedtvIinabq:s:p:r:f:l:D:M:S:RCA", optlist, &i)) != -1) { #else while ((c = getopt_long (argc, argv, "hdvIq:s:", optlist, &i)) != -1) { #endif switch (c) { case 'd': mode=1; break; case 'v': increase_verbosity(); break; case 'q': quality=atoi(optarg); if (quality < 0 || quality > 100) {e_printf("Not a sensible number for option -q\n"); return 1; } break; case 's': scale=atoi(optarg); if (scale < 1 || scale > 128) {e_printf("Not a sensible number for option -s\n"); return 1; } break; case 'I': scale = -1; break; #ifdef HAS_ENCODER case 'e': mode=0; break; case 't': mode=2; break; case 'i': method.encoding=flifEncoding::interlaced; break; case 'n': method.encoding=flifEncoding::nonInterlaced; break; case 'a': acb=1; break; case 'b': acb=0; break; case 'p': palette_size=atoi(optarg); if (palette_size < 0 || palette_size > 30000) {e_printf("Not a sensible number for option -p\n"); return 1; } if (palette_size == 0) {v_printf(2,"Palette disabled\n"); } break; case 'r': learn_repeats=atoi(optarg); if (learn_repeats < 0 || learn_repeats > 20) {e_printf("Not a sensible number for option -r\n"); return 1; } break; case 'f': frame_delay=atoi(optarg); if (frame_delay < 0 || frame_delay > 60000) {e_printf("Not a sensible number for option -f\n"); return 1; } break; case 'l': lookback=atoi(optarg); if (lookback < -1 || lookback > 256) {e_printf("Not a sensible number for option -l\n"); return 1; } break; case 'D': divisor=atoi(optarg); if (divisor <= 0 || divisor > 0xFFFFFFF) {e_printf("Not a sensible number for option -D\n"); return 1; } break; case 'M': min_size=atoi(optarg); if (min_size < 0 || min_size > CONTEXT_TREE_MAX_COUNT) {e_printf("Not a sensible number for option -M\n"); return 1; } break; case 'S': split_threshold=atoi(optarg); if (split_threshold <= 0 || split_threshold > 100000) {e_printf("Not a sensible number for option -S\n"); return 1; } split_threshold *= 5461; break; case 'R': yiq=0; break; case 'C': plc=0; break; case 'A': alpha_zero_special=false; break; #endif case 'h': showhelp=true; break; default: show_help(); return 0; } } argc -= optind; argv += optind; show_banner(); if (argc == 0 || showhelp) { //e_printf("Input file missing.\n"); if (get_verbosity() == 1 || showhelp) show_help(); return 1; } if (argc == 1 && scale != -1) { show_help(); e_printf("\nOutput file missing.\n"); return 1; } if (scale == -1) mode = 1; if (file_exists(argv[0])) { char *f = strrchr(argv[0],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.'); #ifdef HAS_ENCODER if (mode == 0 && file_is_flif(argv[0])) { char *f = strrchr(argv[1],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[1],'.'); if (check_compatible_extension(ext)) { v_printf(3,"Input file is a FLIF file, adding implicit -d\n"); mode = 1; } else if ((ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { v_printf(3,"Input and output file are both FLIF file, adding implicit -t\n"); mode = 2; } } if (mode != 0) { #endif if (!(ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { e_printf("Warning: expected file name extension \".flif\" for input file, trying anyway...\n"); } #ifdef HAS_ENCODER } else { if (!check_compatible_extension(ext)) { e_printf("Warning: expected \".png\", \".pnm\" or \".pam\" file name extension for input file, trying anyway...\n"); } } #endif } else if (argc>0) { e_printf("Input file does not exist: %s\n",argv[0]); return 1; } if (mode > 0 && argc > 2 && scale != -1) { e_printf("Too many arguments.\n"); return 1; } #ifdef HAS_ENCODER if (mode == 0) { if (!handle_encode(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay, divisor, min_size, split_threshold, yiq, plc, alpha_zero_special)) return 2; } else if (mode == 1) { #endif return handle_decode(argc, argv, images, quality, scale); #ifdef HAS_ENCODER } else if (mode == 2) { if (scale > 1) {e_printf("Not yet supported: transcoding downscaled image; use decode + encode!\n");} if (!decode_flif(argv, images, quality, scale)) return 2; argc--; argv++; if (!encode_flif(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay, divisor, min_size, split_threshold, yiq, plc)) return 2; } #endif return 0; }
int main(int argc, char *const argv[]) { int error = 0; log_debug("Parsing options"); Options *opts = parse_opt(argc, argv); if (!opts) { show_banner(); show_help(); return -1; } log_set_level(opts->loglevel); if (opts->logfile) { log_set_logfile(opts->logfile); log_set_logfile_level(LOG_LEVEL_MAX); } #ifdef HAVE_VSYSLOG if (opts->syslog) { log_set_syslog("daliserver"); } #endif if (opts->background) { daemonize(opts->pidfile); } else { show_banner(); } log_info("Starting daliserver"); log_debug("Initializing dispatch queue"); DispatchPtr dispatch = dispatch_new(); if (!dispatch) { error = -1; } else { //dispatch_set_timeout(dispatch, 100); UsbDaliPtr usb = NULL; if (!opts->dryrun) { log_debug("Initializing USB connection"); usb = usbdali_open(NULL, dispatch, opts->usbbus, opts->usbdev); if (!usb) { error = -1; } } if (opts->dryrun || usb) { log_debug("Initializing server"); ServerPtr server = server_open(dispatch, opts->address, opts->port, DEFAULT_NET_FRAMESIZE, net_frame_handler, usb); if (!server) { error = -1; } else { server_set_connection_destroy_callback(server, net_dequeue_connection, usb); if (usb) { usbdali_set_outband_callback(usb, dali_outband_handler, server); usbdali_set_inband_callback(usb, dali_inband_handler); } log_debug("Creating shutdown notifier"); killsocket = ipc_new(); if (!killsocket) { error = -1; } else { ipc_register(killsocket, dispatch); log_info("Server ready, waiting for events"); running = 1; signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); while (running && dispatch_run(dispatch, usbdali_get_timeout(usb))); log_info("Shutting daliserver down"); ipc_free(killsocket); } server_close(server); } if (usb) { usbdali_close(usb); } } dispatch_free(dispatch); } free_opt(opts); log_info("Exiting"); return error; }
bool check_valid(int n) { int newx=0, newy=0; for (int i=0; i<9; i++) { if ((g.board[i][g.x])==movenumber) { show_banner("You have made an invalid move!"); g.badMoves[i][g.x]=99; show_cursor(); return false; } if ((g.board[g.y][i])==movenumber) { show_banner("You have made an invalid move!"); g.badMoves[i][g.x]=99; show_cursor(); return false; } } if (g.y%3==2) ///find origin of little box newy=g.y-2; else if (g.y%3==1) newy=g.y-1; if (g.x%3==2) newx=g.x-2; else if (g.x%3==1) newx=g.x-1; for (int j=0; j<3; j++) { for (int k=0; k<3; k++) { if (((tempBoard[newy+j][newx+k])==movenumber)&& ((g.board[k][g.x])!=movenumber)) { show_banner("You have made an invalid move!"); g.badMoves[newy+j][newx+k]=99; show_cursor(); return false; } } } return true; }
int main(int argc, char **argv) { Images images; #ifdef HAS_ENCODER int mode = 0; // 0 = encode, 1 = decode, 2 = transcode flifEncodingOptional method; int learn_repeats = -1; int acb = -1; // try auto color buckets std::vector<int> frame_delay; frame_delay.push_back(100); int palette_size = -1; int lookback = 1; int divisor=CONTEXT_TREE_COUNT_DIV; int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE; int split_threshold=CONTEXT_TREE_SPLIT_THRESHOLD; int yiq = 1; int plc = 1; int frs = 1; bool alpha_zero_special = true; int alpha=19; int cutoff=2; #else int mode = 1; #endif int quality = 100; // 100 = everything, positive value: partial decode, negative value: only rough data int scale = 1; int resize_width = 0, resize_height = 0; bool showhelp = false; if (strcmp(argv[0],"flif") == 0) mode = 0; if (strcmp(argv[0],"dflif") == 0) mode = 1; if (strcmp(argv[0],"deflif") == 0) mode = 1; if (strcmp(argv[0],"decflif") == 0) mode = 1; static struct option optlist[] = { {"help", 0, NULL, 'h'}, {"decode", 0, NULL, 'd'}, {"verbose", 0, NULL, 'v'}, {"quality", 1, NULL, 'q'}, {"scale", 1, NULL, 's'}, {"resize", 1, NULL, 'r'}, {"identify", 0, NULL, 'i'}, {"version", 0, NULL, 'V'}, #ifdef HAS_ENCODER {"encode", 0, NULL, 'e'}, {"transcode", 0, NULL, 't'}, {"interlace", 0, NULL, 'I'}, {"no-interlace", 0, NULL, 'N'}, {"frame-delay", 1, NULL, 'F'}, {"keep-invisible-rgb", 0, NULL, 'K'}, {"max-palette-size", 1, NULL, 'P'}, {"force-color-buckets", 0, NULL, 'A'}, {"no-color-buckets", 0, NULL, 'B'}, {"no-ycocg", 0, NULL, 'Y'}, {"no-channel-compact", 0, NULL, 'C'}, {"max-frame-lookback", 1, NULL, 'L'}, {"no-frame-shape", 0, NULL, 'S'}, {"maniac-repeats", 1, NULL, 'R'}, {"maniac-divisor", 1, NULL, 'D'}, {"maniac-min-size", 1, NULL, 'M'}, {"maniac-threshold", 1, NULL, 'T'}, {"chance-cutoff", 1, NULL, 'X'}, {"chance-alpha", 1, NULL, 'Z'}, #endif {0, 0, 0, 0} }; int i,c; #ifdef HAS_ENCODER while ((c = getopt_long (argc, argv, "hdviVq:s:r:etINnF:KP:ABYCL:SR:D:M:T:X:Z:", optlist, &i)) != -1) { #else while ((c = getopt_long (argc, argv, "hdviVq:s:r:", optlist, &i)) != -1) { #endif switch (c) { case 'd': mode=1; break; case 'v': increase_verbosity(); break; case 'V': increase_verbosity(3); break; case 'q': quality=atoi(optarg); if (quality < 0 || quality > 100) {e_printf("Not a sensible number for option -q\n"); return 1; } break; case 's': scale=atoi(optarg); if (scale < 1 || scale > 128) {e_printf("Not a sensible number for option -s\n"); return 1; } break; case 'r': if (sscanf(optarg,"%ix%i", &resize_width, &resize_height) < 1) {e_printf("Not a sensible value for option -r (expected WxH)\n"); return 1; } if (!resize_height) resize_height = resize_width; break; case 'i': scale = -1; break; #ifdef HAS_ENCODER case 'e': mode=0; break; case 't': mode=2; break; case 'I': method.encoding=flifEncoding::interlaced; break; case 'n': // undocumented: lower case -n still works case 'N': method.encoding=flifEncoding::nonInterlaced; break; case 'A': acb=1; break; case 'B': acb=0; break; case 'P': palette_size=atoi(optarg); if (palette_size < -32000 || palette_size > 32000) {e_printf("Not a sensible number for option -P\n"); return 1; } if (palette_size == 0) {v_printf(5,"Palette disabled\n"); } break; case 'R': learn_repeats=atoi(optarg); if (learn_repeats < 0 || learn_repeats > 20) {e_printf("Not a sensible number for option -R\n"); return 1; } break; case 'F': frame_delay.clear(); while(optarg != 0) { int d=strtol(optarg,&optarg,10); if (d==0) break; if (*optarg == ',' || *optarg == '+') optarg++; frame_delay.push_back(d); if (d < 0 || d > 60000) {e_printf("Not a sensible number for option -F: %i\n",d); return 1; } } if (frame_delay.size() < 1) frame_delay.push_back(100); break; case 'L': lookback=atoi(optarg); if (lookback < -1 || lookback > 256) {e_printf("Not a sensible number for option -L\n"); return 1; } break; case 'D': divisor=atoi(optarg); if (divisor <= 0 || divisor > 0xFFFFFFF) {e_printf("Not a sensible number for option -D\n"); return 1; } break; case 'M': min_size=atoi(optarg); if (min_size < 0) {e_printf("Not a sensible number for option -M\n"); return 1; } break; case 'T': split_threshold=atoi(optarg); if (split_threshold <= 3 || split_threshold > 100000) {e_printf("Not a sensible number for option -T\n"); return 1; } split_threshold *= 5461; break; case 'Y': yiq=0; break; case 'C': plc=0; break; case 'S': frs=0; break; case 'K': alpha_zero_special=false; break; case 'X': cutoff=atoi(optarg); if (cutoff < 1 || cutoff > 128) {e_printf("Not a sensible number for option -X (try something between 1 and 128)\n"); return 1; } break; case 'Z': alpha=atoi(optarg); if (alpha < 2 || alpha > 128) {e_printf("Not a sensible number for option -Z (try something between 2 and 128)\n"); return 1; } break; #endif case 'h': showhelp=true; break; default: show_help(); return 0; } } argc -= optind; argv += optind; show_banner(); if (argc == 0 || showhelp) { if (get_verbosity() == 1 || showhelp) show_help(); return 0; } if (argc == 1 && scale != -1) { show_help(); e_printf("\nOutput file missing.\n"); return 1; } if (scale == -1) mode = 1; if (file_exists(argv[0])) { char *f = strrchr(argv[0],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.'); #ifdef HAS_ENCODER if (mode == 0 && file_is_flif(argv[0])) { char *f = strrchr(argv[1],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[1],'.'); if ((ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { v_printf(3,"Input and output file are both FLIF file, adding implicit -t\n"); mode = 2; } else { v_printf(3,"Input file is a FLIF file, adding implicit -d\n"); mode = 1; } } if (mode != 0) { #endif if (!(ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { e_printf("Warning: expected file name extension \".flif\" for input file, trying anyway...\n"); } #ifdef HAS_ENCODER } else { if (!check_compatible_extension(ext)) { e_printf("Warning: expected \".png\", \".pnm\" or \".pam\" file name extension for input file, trying anyway...\n"); } } #endif } else if (argc>0) { e_printf("Input file does not exist: %s\n",argv[0]); return 1; } if (mode > 0 && argc > 2 && scale != -1) { e_printf("Too many arguments.\n"); return 1; } #ifdef HAS_ENCODER if (mode == 0) { if (!handle_encode(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay, divisor, min_size, split_threshold, yiq, plc, alpha_zero_special, frs, cutoff, alpha)) return 2; } else if (mode == 1) { #endif return handle_decode(argc, argv, images, quality, scale, resize_width, resize_height); #ifdef HAS_ENCODER } else if (mode == 2) { // if (scale > 1) {e_printf("Not yet supported: transcoding downscaled image; use decode + encode!\n");} if (!decode_flif(argv, images, quality, scale, resize_width, resize_height)) return 2; argc--; argv++; if (!encode_flif(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay, divisor, min_size, split_threshold, yiq, plc, frs, cutoff, alpha)) return 2; } #endif return 0; }
/** *************************************************************************** * Process command line arguments and set corresponding globals. * Shows usage and exits if errors are detected in argument usage. * */ static int process_args(int argc, char * argv[]) { char * options[COUNT_OPTIONS]; uint64_t user_ram_limit = 0; #ifdef USE_FIEMAP using_fiemap = 1; #endif int rv = optgen_parse(argc, argv, &operation, options); if (options[OPT_help]) { show_help(); return 1; } if (rv == OPTGEN_NONE) { show_banner(); printf("\n"); printf("Run 'dupd help' for a summary of available options.\n"); printf("Run 'dupd usage' for more documentation.\n"); return 1; } if (rv != OPTGEN_OK) { // LCOV_EXCL_START printf("error parsing command line arguments\n"); return 2; } // LCOV_EXCL_STOP if (options[OPT_x_small_buffers]) { x_small_buffers = 1; } if (options[OPT_x_testing]) { only_testing = 1; } if (options[OPT_quiet]) { log_level = -99; } log_level = opt_int(options[OPT_verbose_level], log_level); log_level += opt_count(options[OPT_verbose]); if (log_level > L_MAX_LOG_LEVEL) { log_level = L_MAX_LOG_LEVEL; } if (options[OPT_log_only]) { log_only = 1; } if (start_path_state == START_PATH_NULL) { start_path[0] = (char *)malloc(DUPD_PATH_MAX); getcwd(start_path[0], DUPD_PATH_MAX); start_path_count = 1; LOG(L_INFO, "Defaulting --path to [%s]\n", start_path[0]); } if (options[OPT_file] != NULL) { file_path = options[OPT_file]; // file path can be relative, normalize in that case if (file_path[0] != '/') { file_path = (char *)malloc(DUPD_PATH_MAX); free_file_path = 1; getcwd(file_path, DUPD_PATH_MAX); strcat(file_path, "/"); strcat(file_path, options[OPT_file]); } } db_path = options[OPT_db]; if (db_path == NULL) { db_path = (char *)malloc(DUPD_PATH_MAX); free_db_path = 1; snprintf(db_path, DUPD_PATH_MAX, "%s/.dupd_sqlite", getenv("HOME")); } cache_db_path = options[OPT_cache]; if (cache_db_path == NULL) { cache_db_path = (char *)malloc(DUPD_PATH_MAX); free_cache_db_path = 1; snprintf(cache_db_path, DUPD_PATH_MAX, "%s/.dupd_cache", getenv("HOME")); } if (options[OPT_link]) { rmsh_link = RMSH_LINK_SOFT; } if (options[OPT_hardlink]) { rmsh_link = RMSH_LINK_HARD; } if (options[OPT_hidden]) { scan_hidden = 1; } if (options[OPT_no_thread_scan]) { threaded_sizetree = 0; } if (options[OPT_hardlink_is_unique]) { hardlink_is_unique = 1; } if (options[OPT_one_file_system]) { one_file_system = 1; } if (options[OPT_x_no_cache]) { use_hash_cache = 0; } cache_min_size = (uint64_t)opt_int(options[OPT_x_cache_min_size], cache_min_size); hash_one_block_size = opt_int(options[OPT_firstblocksize], hash_one_block_size); hash_block_size = opt_int(options[OPT_blocksize], hash_block_size); filecmp_block_size = opt_int(options[OPT_fileblocksize], filecmp_block_size); hash_one_max_blocks = opt_int(options[OPT_firstblocks], hash_one_max_blocks); cut_path = options[OPT_cut]; exclude_path = options[OPT_exclude_path]; if (exclude_path != NULL && exclude_path[0] != '/') { printf("error: --exclude-path must be absolute\n"); return 2; } stats_file = options[OPT_stats_file]; minimum_file_size = opt_int(options[OPT_minsize], minimum_file_size); if (minimum_file_size < 1) { minimum_file_size = 1; } path_sep_string = (char *)malloc(2); path_sep_string[0] = (char)path_separator; path_sep_string[1] = 0; char * hash_name = opt_string(options[OPT_hash], "xxhash"); if (!strcmp("md5", hash_name)) { hash_function = HASH_FN_MD5; } else if (!strcmp("sha1", hash_name)) { hash_function = HASH_FN_SHA1; } else if (!strcmp("sha512", hash_name)) { hash_function = HASH_FN_SHA512; } else if (!strcmp("xxhash", hash_name)) { hash_function = HASH_FN_XXHASH; } else { printf("error: unknown hash %s\n", hash_name); return 2; } hash_bufsize = hash_get_bufsize(hash_function); char * report_format_name = opt_string(options[OPT_format], "text"); if (!strcmp("text", report_format_name)) { report_format = REPORT_FORMAT_TEXT; } else if (!strcmp("csv", report_format_name)) { report_format = REPORT_FORMAT_CSV; } else if (!strcmp("json", report_format_name)) { report_format = REPORT_FORMAT_JSON; } else { printf("error: unknown report format %s\n", report_format_name); return 2; } char * buflimstr = opt_string(options[OPT_buflimit], "0"); if (strcmp("0", buflimstr)) { int len = strlen(buflimstr); if (buflimstr[len-1] == 'M') { user_ram_limit = MB1; buflimstr[len-1] = 0; } else if (buflimstr[len-1] == 'G') { user_ram_limit = GB1; buflimstr[len-1] = 0; } else { user_ram_limit = 1; } long c = atol(buflimstr); user_ram_limit *= c; if (user_ram_limit < MB8) { user_ram_limit = MB8; } } if (options[OPT_cmp_two]) { opt_compare_two = 1; } if (hash_one_block_size == 0) { hash_one_block_size = DEF_HDD_hash_one_block_size; } round1_max_bytes = hash_one_block_size * hash_one_max_blocks; // If user hasn't provided a cache_min_size, do something reasonable if (cache_min_size == 0) { if (round1_max_bytes < K512) { cache_min_size = K512; } else { cache_min_size = round1_max_bytes; } } char * sortby = opt_string(options[OPT_sort_by], "def"); if (!strcmp("inode", sortby)) { sort_bypass = SORT_BY_INODE; } else if (!strcmp("block", sortby)) { sort_bypass = SORT_BY_BLOCK; } else if (!strcmp("none", sortby)) { sort_bypass = SORT_BY_NONE; } if (sort_bypass != 0) { LOG(L_INFO, "Sort bypass set to %s\n", sortby); if (hardlink_is_unique) { printf("Don't do that..\n"); return 2; } } if (sort_bypass != 0 && sort_bypass != SORT_BY_BLOCK) { using_fiemap = 0; } if (options[OPT_x_nofie]) { using_fiemap = 0; } LOG(L_INFO, "Will be using_fiemap (if available): %d\n", using_fiemap); uint64_t ram = total_ram(); if (user_ram_limit > 0) { if (user_ram_limit > ram) { buffer_limit = 0.9 * ram; } else { buffer_limit = user_ram_limit; } } if (buffer_limit == 0) { buffer_limit = 0.5 * ram; if (x_small_buffers) { buffer_limit = MB1; } } int ramm = ram / (1024 * 1024); int blim = buffer_limit / (1024 * 1024); LOG(L_INFO, "Reported RAM: %dMB buffer limit: %dMB\n", ramm, blim); return 0; }
int main(int argc, char ** argv) { int c; int result = -1; int i = 0; char arg_arch[MAX_ARCH_BUFFER]; char arg_impl[MAX_IMPL_BUFFER]; char arg_calc[MAX_CALC_BUFFER]; ms_bitfield_info * output = NULL; ms_bitfield_info * toshow = NULL; int arg_core = -1; int option_index = 0; int ppl = 0; int m = 0; if (argc == 1) { show_banner(1, 0, 0); } while ((c = getopt_long(argc, argv, "t:a:i:c:v:", long_options, &option_index)) != -1) { switch(c) { case 0: break; case 'a': strncpy(arg_arch, optarg, MAX_ARCH_BUFFER - 1); break; case 'i': strncpy(arg_impl, optarg, MAX_ARCH_BUFFER - 1); break; case 'c': arg_core = atoi(optarg); break; case 'v': strncpy(arg_calc, optarg, MAX_CALC_BUFFER - 1); flag_fb_calc = 1; break; case '?': case 'h': print_usage(); break; default: show_banner(1, 0, 0); return -1; } } if (flag_fb_show_info) { switch(flag_fb_show_info) { case FLAG_SHOW_GROUPS: ms_get_groups(&toshow); no_results(toshow); for (i = 0; i < ms_get_size(toshow); ++i) { printf("%s\n", ms_get_group_string(toshow, i)); } ms_free_result(&toshow); break; case FLAG_SHOW_BITFIELDS: ms_get_bitfields(&toshow); no_results(toshow); for (i = 0; i < ms_get_size(toshow); ++i) { printf("0x%08x (%s.%s.%s)\n", ms_get_uid(toshow, i), ms_get_decode_string(toshow, i), ms_get_register_string(toshow, i), ms_get_bitfield_string(toshow, i)); } ms_free_result(&toshow); break; case FLAG_SHOW_REGISTERS: ms_get_registers(&toshow); no_results(toshow); for (i = 0; i < ms_get_size(toshow); ++i) { printf("%s\n", ms_get_register_string(toshow, i)); } ms_free_result(&toshow); break; default: break; } goto done; } ppl = get_ppl_from_flag(flag_fb_el0, flag_fb_el1); if (flag_fb_bitfield) { if (optind < argc) { if (ms_find_by_bitfield(arg_arch, arg_impl, strtol(argv[optind], NULL, 16), arg_core, ppl, flag_fb_noparse, &output) != 0) { goto done; } } } else if (flag_fb_group) { if (optind < argc) { if (ms_find_by_group(arg_arch, arg_impl, argv[optind], arg_core, ppl, flag_fb_noparse, &output) != 0) { goto done; } } } else if (flag_fb_register) { if (optind < argc) { if (flag_fb_calc) { if (ms_find_by_register(arg_arch, arg_impl, argv[optind], arg_core, ppl, flag_fb_noparse, arg_calc, &output) != 0) { goto done; } } else { if (ms_find_by_register(arg_arch, arg_impl, argv[optind], arg_core, ppl, flag_fb_noparse, NULL, &output) != 0) { goto done; } } } } else if (flag_fb_all) { ms_get_groups(&toshow); for (i = 0; i < ms_get_size(toshow); ++i) { if (ms_find_by_group(arg_arch, arg_impl, ms_get_group_string(toshow, i), arg_core, ppl, flag_fb_noparse, &output) != 0) { goto done; } show_results(output); ms_free_result(&output); } } else { goto done; } show_results(output); result = 0; done: ms_free_result(&toshow); ms_free_result(&output); printf("\n# Leaving the kernel module installed compromises the security of your system.\n# Use 'rmmod maplesyrup_mod' to unload the module.\n"); return result; }
int main(int argc, char **argv) { Images images; #ifdef HAS_ENCODER int mode = 0; // 0 = encode, 1 = decode, 2 = transcode flifEncodingOptional method; int learn_repeats = -1; int acb = -1; // try auto color buckets int frame_delay = 100; int palette_size = 512; int lookback = 1; #else int mode = 1; #endif int quality = 100; // 100 = everything, positive value: partial decode, negative value: only rough data int scale = 1; if (strcmp(argv[0],"flif") == 0) mode = 0; if (strcmp(argv[0],"dflif") == 0) mode = 1; if (strcmp(argv[0],"deflif") == 0) mode = 1; if (strcmp(argv[0],"decflif") == 0) mode = 1; static struct option optlist[] = { {"help", 0, NULL, 'h'}, {"decode", 0, NULL, 'd'}, {"verbose", 0, NULL, 'v'}, {"quality", 1, NULL, 'q'}, {"scale", 1, NULL, 's'}, #ifdef HAS_ENCODER {"encode", 0, NULL, 'e'}, {"transcode", 0, NULL, 't'}, {"interlace", 0, NULL, 'i'}, {"no-interlace", 0, NULL, 'n'}, {"acb", 0, NULL, 'a'}, {"no-acb", 0, NULL, 'b'}, {"palette", 1, NULL, 'p'}, {"repeats", 1, NULL, 'r'}, {"frame-delay", 1, NULL, 'f'}, {"lookback", 1, NULL, 'l'}, #endif {0, 0, 0, 0} }; int i,c; #ifdef HAS_ENCODER while ((c = getopt_long (argc, argv, "hedtvinabq:s:p:r:f:l:", optlist, &i)) != -1) { #else while ((c = getopt_long (argc, argv, "hdvq:s:", optlist, &i)) != -1) { #endif switch (c) { case 'd': mode=1; break; case 'v': increase_verbosity(); break; case 'q': quality=atoi(optarg); if (quality < 0 || quality > 100) {e_printf("Not a sensible number for option -q\n"); return 1; } break; case 's': scale=atoi(optarg); if (scale < 1 || scale > 128) {e_printf("Not a sensible number for option -s\n"); return 1; } break; #ifdef HAS_ENCODER case 'e': mode=0; break; case 't': mode=2; break; case 'i': method.encoding=flifEncoding::interlaced; break; case 'n': method.encoding=flifEncoding::nonInterlaced; break; case 'a': acb=1; break; case 'b': acb=0; break; case 'p': palette_size=atoi(optarg); if (palette_size < -1 || palette_size > 30000) {e_printf("Not a sensible number for option -p\n"); return 1; } if (palette_size == 0) {v_printf(2,"Palette disabled\n"); } break; case 'r': learn_repeats=atoi(optarg); if (learn_repeats < 0 || learn_repeats > 1000) {e_printf("Not a sensible number for option -r\n"); return 1; } break; case 'f': frame_delay=atoi(optarg); if (frame_delay < 0 || frame_delay > 60000) {e_printf("Not a sensible number for option -f\n"); return 1; } break; case 'l': lookback=atoi(optarg); if (lookback < -1 || lookback > 256) {e_printf("Not a sensible number for option -l\n"); return 1; } break; #endif case 'h': default: show_help(); return 0; } } argc -= optind; argv += optind; show_banner(); if (argc == 0) { //e_printf("Input file missing.\n"); if (get_verbosity() == 1) show_help(); return 1; } if (argc == 1) { show_help(); e_printf("\nOutput file missing.\n"); return 1; } if (file_exists(argv[0])) { #ifdef HAS_ENCODER if (mode == 0 && file_is_flif(argv[0])) { char *f = strrchr(argv[1],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[1],'.'); if (check_compatible_extension(ext)) { v_printf(2,"Input file is a FLIF file, adding implicit -d\n"); mode = 1; } else if ((ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { v_printf(2,"Input and output file are both FLIF file, adding implicit -t\n"); mode = 2; } } #endif char *f = strrchr(argv[0],'/'); char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.'); if (mode == 0) { if (!check_compatible_extension(ext)) { e_printf("Warning: expected \".png\" or \".pnm\" file name extension for input file, trying anyway...\n"); } } else { if (!(ext && ( !strcasecmp(ext,".flif") || ( !strcasecmp(ext,".flf") )))) { e_printf("Warning: expected file name extension \".flif\" for input file, trying anyway...\n"); } } } else if (argc>0) { e_printf("Input file does not exist: %s\n",argv[0]); return 1; } if (mode > 0 && argc > 2) { e_printf("Too many arguments.\n"); return 1; } #ifdef HAS_ENCODER if (mode == 0) { if (!handle_encode(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay)) return 2; } else if (mode == 1) { #endif if (!handle_decode(argv, images, quality, scale)) return 2; #ifdef HAS_ENCODER } else if (mode == 2) { if (scale > 1) {e_printf("Not yet supported: transcoding downscaled image; use decode + encode!\n");} if (!decode_flif(argv, images, quality, scale)) return 2; argc--; argv++; if (!encode_flif(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay)) return 2; } #endif return 0; }