int wgdos_expand_row_to_data( int ncols, float mdi, float accuracy, float base, Boolean *missing_data, Boolean *zero, int *data, float *unpacked_data, int *mdi_clashes, const function* const parent ) { int non_special_so_far; /* Number of non-special items unpacked so far */ int col; /* Number of items unpacked so far */ int off=1; function subroutine; int log_messages=(get_verbosity()>=VERBOSITY_MESSAGE); set_function_name(__func__, &subroutine, parent); double dacc, ddata, dbase, dval; *mdi_clashes = 0; non_special_so_far = 0; dacc=accuracy; dbase=base; message[0]=0; for ( col = 0; col < ncols; col ++ ) { off=1; if ( missing_data[col] ) { unpacked_data[col] = mdi; snprintf (message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), " %012g / %-12s", unpacked_data[col],"MDI"); } else if ( zero[col] ) { unpacked_data[col] = 0.0; snprintf (message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), " %012g / %-12s", unpacked_data[col],"Zero"); } else { dval=dacc*data[non_special_so_far]+dbase; unpacked_data[col] = dval; if ( unpacked_data[col] == mdi ) { (*mdi_clashes)++; } non_special_so_far++; off=1; snprintf (message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), " %012g / %-12d", unpacked_data[col],data[non_special_so_far-off]); } if (log_messages &&(col%4 == 3)) { snprintf(message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), "%3d", col); MO_syslog (VERBOSITY_MESSAGE, message, &subroutine); message[0]=0; } } if (message[0]!=0 && log_messages) { snprintf(message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), "%3d", col); MO_syslog (VERBOSITY_MESSAGE, message, &subroutine); message[0]=0; } return 0; } /* end function PP_Wgdos_Expand_Row */
int main(int argc, char * argv[]) { if(argc != 2) { puts("No file detected"); exit(0); } FILE * fp; char * snitch = NULL; time_t tiem = 0; uint8_t verbosity = 0; uint8_t NameOffset = 9+PLAYER_N; struct Planet TheirPlanet = {NULL,NULL,0,0,0}; struct Resource TheirResource = {0,0,0}; struct Fleet TheirFleet = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; struct Defense TheirDefense = {0,0,0,0,0,0,0,0,0,0}; struct Building TheirBuildings = {0,0,0,0,0,0,0,0}; struct Research TheirResearch = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; fp = fopen(argv[1],"r"); if(fp == NULL) { puts("Null or nonexistent file"); exit(0); } snitch = whosaidthat(&fp); get_tango(&fp, &TheirPlanet); puts("Calling function..."); tiem = r_time(&fp); TheirPlanet.Owner = losersname(&fp,NameOffset); booty(&fp, &TheirResource); verbosity = get_verbosity(&fp); if(verbosity == 1) { verbosity += dummies(&fp,&TheirFleet); } if(verbosity == 2) { verbosity += bunker(&fp,&TheirDefense); } if(verbosity == 3) { verbosity += shanty(&fp,&TheirBuildings); } if(verbosity == 4) { edumucation(&fp,&TheirResearch); } /* printf("Metal: %lu\nCrystal: %lu\nDeuterium: %lu\n",TheirResource.Metal,TheirResource.Crystal,TheirResource.Deuterium); */ printf("%llu\n",(long long)tiem); puts(snitch); fclose(fp); return 0; }
static gboolean window_changed(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) { if (num_monitor == 2) { // If there are more than two monitors, we need a configuration menu int cx, cy, i; struct monitorlist* current; if (monlist == NULL) { if (get_verbosity()) printf("monlist == NULL\n"); return FALSE; } i = 0; for (current = monlist; current != NULL; current = current->next) i++; if (i != 2) { // Every monitor does not support DDC/CI, or there are more monitors plugged-in //printf("i : %d\n", i); return FALSE; } cx = event->x + (event->width/2); cy = event->y + (event->height/2); i = gdk_screen_get_monitor_at_window(gdk_screen_get_default(), main_app_window->window); if (i != current_monitor) { int k = nextid; if (get_verbosity()) printf(_("Monitor changed (%d %d).\n"), i, k); k = (k == 0) ? 1 : 0; current_monitor = i; gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), k); } //g_warning(_("Could not find the current monitor in Xinerama monitors list.")); } return FALSE; }
bool mmapped_file::munmap_and_close_file(void) { reference_count--; if (reference_count > 0) { return false; } if (munmap(memory_area, size_mapped) < 0) { if (get_verbosity() > 0) { perror("munmap"); } throw mmap_allocator_exception("Error in munmap"); } if (close(fd)) { if (get_verbosity() > 0) { perror("close"); } throw mmap_allocator_exception("Error in close"); } fd = -1; return true; }
off_t filesize(int fd, std::string fname) { struct stat buf; if (fstat(fd, &buf) < 0) { if (get_verbosity() > 0) { perror("stat"); } throw mmap_allocator_exception("Cannot stat file" + fname); } return buf.st_size; }
mmap_file_identifier::mmap_file_identifier(std::string fname, enum access_mode access_mode_param) { struct stat buf; if (stat(fname.c_str(), &buf) < 0) { if (get_verbosity() > 0) { perror("stat"); } throw mmap_allocator_exception("Cannot stat file "+fname); } device = buf.st_dev; inode = buf.st_ino; access_mode = access_mode_param; }
int main (int argc, char *argv[]) { program_name = GET_NEXT_ARG; //check to see how many arguments we have... if no args, then print usage and bail if (argc == 1) { print_usage(false); exit(EXIT_FAILURE); } char *current_arg = NULL; //first, read program options... loop over args until we reach one that doesn't start with '-' for (current_arg = PEEK_ARG ; (current_arg[0] == '-') ; current_arg = PEEK_ARG) { current_arg = GET_NEXT_ARG; // print help and quit if ( CHECK_ARG( OPT_HELP ) ) { print_usage(true); exit(EXIT_SUCCESS); } //print version and quit if ( CHECK_ARG( OPT_VERSION ) ) { printf("%s-%s\n\n", PACKAGE, VERSION); exit(EXIT_SUCCESS); } //turn on verbosity if ( CHECK_ARG( OPT_VERBOSE ) ) { increment_verbosity(); v_printf(VERBOSE_NOTICE, "Verbosity level: %d", get_verbosity()); continue; } //set the color palette if ( CHECK_ARG( OPT_COLOR ) ) { printf("COLOR PALETTE NOT YET IMPLEMENTED!!\n"); continue; //go to next iteration of for() loop } //if we get here, we reached an unknown option printf("UNKNOWN OPTION: %s\n", *argv); exit(EXIT_FAILURE); } parse_line(argc, argv); //end of program return 0; }
bool language_uit::typecheck() { status("Converting"); language_files.set_message_handler(*message_handler); language_files.set_verbosity(get_verbosity()); if(language_files.typecheck(symbol_table)) { if(get_ui()==ui_message_handlert::PLAIN) std::cerr << "CONVERSION ERROR" << std::endl; return true; } return false; }
int limit_krb5_enctypes(struct rpc_gss_sec *sec, uid_t uid) { u_int maj_stat, min_stat; gss_cred_id_t credh; gss_OID_set_desc desired_mechs; krb5_enctype enctypes[] = { ENCTYPE_DES_CBC_CRC, ENCTYPE_DES_CBC_MD5, ENCTYPE_DES_CBC_MD4 }; int num_enctypes = sizeof(enctypes) / sizeof(enctypes[0]); /* We only care about getting a krb5 cred */ desired_mechs.count = 1; desired_mechs.elements = &krb5oid; maj_stat = gss_acquire_cred(&min_stat, NULL, 0, &desired_mechs, GSS_C_INITIATE, &credh, NULL, NULL); if (maj_stat != GSS_S_COMPLETE) { if (get_verbosity() > 0) pgsserr("gss_acquire_cred", maj_stat, min_stat, &krb5oid); return -1; } maj_stat = gss_set_allowable_enctypes(&min_stat, credh, &krb5oid, num_enctypes, &enctypes); if (maj_stat != GSS_S_COMPLETE) { pgsserr("gss_set_allowable_enctypes", maj_stat, min_stat, &krb5oid); gss_release_cred(&min_stat, &credh); return -1; } sec->cred = credh; return 0; }
static void combo_change(GtkWidget *widget, gpointer data) { nextid = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); if (!g_mutex_trylock(combo_change_mutex)) { if (get_verbosity()) printf("Tried to change to %d, but mutex locked.\n", gtk_combo_box_get_active(GTK_COMBO_BOX(widget))); return; } gtk_widget_set_sensitive(widget, FALSE); while (currentid != nextid) { if (get_verbosity()) printf("currentid(%d) != nextid(%d), trying...\n", currentid, nextid); currentid = nextid; int i = 0; if (monitor_manager != NULL) { delete_monitor_manager(); gtk_widget_destroy(monitor_manager); monitor_manager = NULL; } char buffer[256]; struct monitorlist* current; for (current = monlist;; current = current->next) { g_assert(current != NULL); if (i == currentid) { snprintf(buffer, 256, "%s: %s", current->filename, current->name); create_monitor_manager(current); if (monitor_manager) { gtk_widget_set_sensitive(refresh_controls_button, TRUE); } else { gtk_widget_set_sensitive(close_button, TRUE); gtk_widget_set_sensitive(choice_hbox, TRUE); } break; } i++; } if (monitor_manager) { gtk_table_attach(GTK_TABLE(table), monitor_manager, 0, 1, mainrow, mainrow+1, GTK_FILL_EXPAND, GTK_FILL_EXPAND, 5, 5); gtk_table_attach(GTK_TABLE(table), profile_manager, 0, 1, mainrow, mainrow+1, GTK_FILL_EXPAND, GTK_FILL_EXPAND, 5, 5); } while (gtk_events_pending ()) gtk_main_iteration (); } if (get_verbosity()) printf("currentid == nextid (%d)\n", currentid); gtk_widget_set_sensitive(widget, TRUE); g_mutex_unlock(combo_change_mutex); }
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; }
int wgdos_expand_broken_row_to_data( int ncols, int badnumbers, float mdi, float accuracy, float base, Boolean *missing_data, Boolean *zero, int *data, float *unpacked_data, int *mdi_clashes, const function* const parent ) { int non_special_so_far; /* Number of non-special items unpacked so far */ int col; /* Number of items unpacked so far */ int off=1; int log_messages=(get_verbosity()>=VERBOSITY_MESSAGE); function subroutine; set_function_name(__func__, &subroutine, parent); *mdi_clashes = 0; non_special_so_far = 0; message[0]=0; for ( col = 0; col < ncols; col ++ ) { off=1; if ( missing_data[col]) { unpacked_data[col] = mdi; } else if ( zero[col] ) { unpacked_data[col] = 0.0; } else { if (non_special_so_far >= badnumbers) { unpacked_data[col] = mdi; } else { unpacked_data[col] = accuracy * data[non_special_so_far] + base; if ( unpacked_data[col] == mdi ) { (*mdi_clashes)++; } non_special_so_far++; off=1; } } if (log_messages && (col%3 == 0)) { snprintf(message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), "%3d", col); MO_syslog (VERBOSITY_MESSAGE, message, &subroutine); message[0]=0; } if (log_messages) { snprintf (message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), " %.16g/%05d", unpacked_data[col],data[non_special_so_far-off]); } } if (log_messages && message[0]!=0) { snprintf(message+strlen(message), MAX_MESSAGE_SIZE-strlen(message), "%3d", col); MO_syslog (VERBOSITY_MESSAGE, message, &subroutine); message[0]=0; } return 0; } /* end function PP_Wgdos_Expand_Broken_Row */
void *mmapped_file::open_and_mmap_file(std::string filename, enum access_mode access_mode, off_t offset, size_t length, bool map_whole_file, bool allow_remap) { if (filename.c_str()[0] == '\0') { throw mmap_allocator_exception("mmap_allocator not correctly initialized: filename is empty."); } int mode; int prot; int mmap_mode = 0; off_t offset_to_map; size_t length_to_map; void *address_to_map = NULL; if (memory_area != NULL) { address_to_map = memory_area; /* do not use MAP_FIXED, since that may invalidate other memory areas in the process, such as shared libraries, which would lead to a mystic Segfault. */ } switch (access_mode) { case READ_ONLY: mode = O_RDONLY; prot = PROT_READ; mmap_mode |= MAP_SHARED; break; case READ_WRITE_SHARED: mode = O_RDWR; prot = PROT_READ | PROT_WRITE; mmap_mode |= MAP_SHARED; break; case READ_WRITE_PRIVATE: mode = O_RDONLY; prot = PROT_READ | PROT_WRITE; mmap_mode |= MAP_PRIVATE; break; default: throw mmap_allocator_exception("Internal error"); break; } if (fd == -1) { fd = open(filename.c_str(), mode); if (fd < 0) { if (get_verbosity() > 0) { perror("open"); } throw mmap_allocator_exception("Error opening file " + filename); } } if (map_whole_file) { offset_to_map = 0; length_to_map = filesize(fd, filename); } else { offset_to_map = ALIGN_TO_PAGE(offset); length_to_map = UPPER_ALIGN_TO_PAGE(length); } if (offset_to_map == offset_mapped && length_to_map == size_mapped) { reference_count++; return ((char*)memory_area)+offset-offset_mapped; } if (offset_to_map >= offset_mapped && length_to_map + offset_to_map - offset_mapped <= size_mapped) { reference_count++; return ((char*)memory_area)+offset-offset_mapped; } if (memory_area != NULL) { if (munmap(memory_area, size_mapped) < 0) { if (get_verbosity() > 0) { perror("munmap"); } throw mmap_allocator_exception("Error in munmap file "+filename); } } memory_area = mmap(address_to_map, length_to_map, prot, mmap_mode, fd, offset_to_map); if (address_to_map != NULL && !allow_remap && memory_area != MAP_FAILED && memory_area != address_to_map) { if (munmap(memory_area, length_to_map) < 0) { if (get_verbosity() > 0) { perror("munmap"); } throw mmap_allocator_exception("Error in munmap" + filename); } throw mmap_allocator_exception("Request to remap area but allow_remap is not given (remapping "+filename+")"); } if (memory_area == MAP_FAILED) { if (get_verbosity() > 0) { perror("mmap"); } throw mmap_allocator_exception("Error in mmap "+filename); } offset_mapped = offset_to_map; size_mapped = length_to_map; reference_count++; void *ret = ((char*)memory_area)+offset-offset_to_map; // assert(ret >= memory_area && ret < (char*)memory_area+size_mapped); return ret; }
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) { 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; }
bool ranking_synthesis_qbf_bitwiset::generate_functions(void) { #if 0 std::cout << "GENERATE: " << templ << std::endl; #endif qdimacs_coret::resultt res=qdimacs_coret::P_UNSATISFIABLE; unsigned state_size = get_state_size(); status("Termination: state size is " + i2string(state_size)); while (res==qdimacs_coret::P_UNSATISFIABLE && bitwise_width <= state_size) { std::auto_ptr<qdimacs_coret> solver(choose_qbf_core_extractor()); bv_pointerst converter(ns, *solver); solver->set_verbosity(get_verbosity()); solver->set_message_handler(get_message_handler()); converter.set_verbosity(get_verbosity()); converter.set_message_handler(get_message_handler()); exprt templ = instantiate(); status("Template:"); quantify_variables(converter, *solver); std::cout << std::endl << from_expr(ns, "", templ) << std::endl; status("Converting template..."); fine_timet before = current_time(); converter.set_to_true(templ); fine_timet ctime = current_time()-before; if(get_verbosity()>5) show_varmap(converter, std::cout); status("Solving..."); before = current_time(); res = solver->prop_solve(); // solver_calls++; // we don't count calls or time globally. status(std::string("TConversion time: ") + time2string(ctime) + " sec."); status(std::string("TSolver time: ") + time2string(current_time()-before) + " sec."); status(std::string("TSolver calls: 1")); if(res==qdimacs_coret::P_SATISFIABLE) { status("Found ranking functions"); if(extract_ranking_relation(converter)) return false; } else { bitwise_width++; if(bitwise_width <= state_size) status("No ranking functions found; increasing width to " + i2string(bitwise_width)); } } if(res==qdimacs_coret::P_SATISFIABLE) return true; else if(res==qdimacs_coret::P_UNSATISFIABLE) return false; else throw ("QBF SOLVER ERROR"); }
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; }
/* Initializes and fills in *sap and *qos according to Blli * code point value specified in conn_type. */ void init_conn_params(struct atm_sap *sap, struct atm_qos *qos, uint16_t conn_type) { unsigned int bllicode; int i, sdu; char qos_text[MAX_ATM_QOS_LEN + 1]; diag(COMPONENT, DIAG_DEBUG, "init_conn_params, conn_type %x\n", conn_type); memset(qos, 0, sizeof(struct atm_qos)); memset(sap, 0, sizeof(struct atm_sap)); qos->aal = ATM_AAL5; /* Set the forward and backward Max CPCS-SDU Size */ switch(conn_type) { case CONTROL_CONN: qos->rxtp.max_sdu = 1516; qos->txtp.max_sdu = 1516; break; case DATA_DIRECT_CONN: case MCAST_CONN: sdu = maxmtu2maxsdu(lec_params.c3_max_frame_size); qos->rxtp.max_sdu = sdu; qos->txtp.max_sdu = sdu; break; default: diag(COMPONENT, DIAG_ERROR, "unknown conn_type %x\n", conn_type); break; } /* ATM User Cell Rate/ATM Traffic Descriptor. */ qos->txtp.traffic_class = ATM_UBR; qos->rxtp.traffic_class = ATM_UBR; if (get_verbosity(COMPONENT) >= DIAG_DEBUG) { if (qos2text(qos_text, sizeof(qos_text), qos, 0) < 0) sprintf(qos_text, "<bad qos>"); diag(COMPONENT, DIAG_DEBUG, "init_conn_params, QoS '%s'\n", qos_text); } /* No Broadband High Layer Information in LANE. */ sap->bhli.hl_type = ATM_HL_NONE; /* Broadband Lower Layer Information. */ sap->blli[0].l3_proto = ATM_L3_TR9577; sap->blli[0].l3.tr9577.ipi = NLPID_IEEE802_1_SNAP; sap->blli[0].l3.tr9577.snap[0] = 0x00; sap->blli[0].l3.tr9577.snap[1] = 0xa0; sap->blli[0].l3.tr9577.snap[2] = 0x3e; bllicode = conn_type2codepoint(conn_type); sap->blli[0].l3.tr9577.snap[3] = (unsigned char)(0xff&(bllicode>>8)); sap->blli[0].l3.tr9577.snap[4] = (unsigned char)(0xff&bllicode); if (get_verbosity(COMPONENT) == DIAG_DEBUG) { for(i=0; i < 5; i++) { diag(COMPONENT, DIAG_DEBUG, "snap[%d] = 0x%2.2x", i, sap->blli[0].l3.tr9577.snap[i]); } } return; }
int symex_parseoptionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } register_language(new_ansi_c_language); register_language(new_cpp_language); // // command line options // optionst options; get_command_line_options(options); eval_verbosity(); goto_functionst goto_functions; if(get_goto_program(options, goto_functions)) return 6; label_properties(goto_functions); if(cmdline.isset("show-properties")) { const namespacet ns(symbol_table); show_properties(ns, get_ui(), goto_functions); return 0; } if(set_properties(goto_functions)) return 7; if(cmdline.isset("show-locs")) { const namespacet ns(symbol_table); locst locs(ns); locs.build(goto_functions); locs.output(std::cout); return 0; } // do actual Symex try { const namespacet ns(symbol_table); path_searcht path_search(ns); path_search.set_message_handler(get_message_handler()); path_search.set_verbosity(get_verbosity()); if(cmdline.isset("depth")) path_search.depth_limit=unsafe_string2unsigned(cmdline.getval("depth")); if(cmdline.isset("context-bound")) path_search.context_bound=unsafe_string2unsigned(cmdline.getval("context-bound")); if(cmdline.isset("unwind")) path_search.unwind_limit=unsafe_string2unsigned(cmdline.getval("unwind")); if(cmdline.isset("show-vcc")) { path_search.show_vcc=true; path_search(goto_functions); return 0; } // do actual symex switch(path_search(goto_functions)) { case safety_checkert::SAFE: report_properties(path_search.property_map); report_success(); return 0; case safety_checkert::UNSAFE: report_properties(path_search.property_map); report_failure(); return 10; default: return 8; } } catch(const std::string error_msg) { error() << error_msg << messaget::eom; return 8; } catch(const char *error_msg) { error() << error_msg << messaget::eom; return 8; } #if 0 // let's log some more statistics debug() << "Memory consumption:" << messaget::endl; memory_info(debug()); debug() << eom; #endif }
bool termination_baset::cegar( concrete_modelt &model, goto_tracet &goto_trace, fine_timet &modelchecker_time, fine_timet &unsafe_time, fine_timet &safe_time) { goto_trace.clear(); #if 0 std::ofstream out("model"); model.goto_functions.output(ns, out); out.close(); #endif null_message_handlert nmh; message_handlert &mh = (verbosity >= 8) ? get_message_handler() : nmh; loop_componentt::argst args(mh, model); std::auto_ptr<refinert> refiner(select_refiner(options, args)); std::auto_ptr<abstractort> abstractor(select_abstractor(options, args)); std::auto_ptr<modelcheckert> modelchecker(select_modelchecker(options, args)); std::auto_ptr<simulatort> simulator(select_simulator(options, args, shadow_context)); unsigned this_verb=get_verbosity()-2; // set their verbosity -- all the same for now refiner->set_verbosity(this_verb); abstractor->set_verbosity(this_verb); modelchecker->set_verbosity(this_verb); simulator->set_verbosity(this_verb); try { satabs_safety_checker_baset safety_checker(ns, *abstractor, *refiner, *modelchecker, *simulator); safety_checker.set_message_handler(mh); safety_checker.set_verbosity(this_verb); fine_timet before=current_time(); safety_checkert::resultt result=safety_checker(model.goto_functions); fine_timet diff=current_time()-before; modelchecker_time+=diff; switch(result) { case safety_checkert::ERROR: unsafe_time+=diff; throw "CEGAR Error"; case safety_checkert::UNSAFE: goto_trace.clear(); goto_trace.swap(safety_checker.error_trace); unsafe_time+=diff; return false; // not safe case safety_checkert::SAFE: safe_time+=diff; return true; // safe default: unsafe_time+=diff; throw std::string("CEGAR Result: ") + i2string(result); } } catch(const std::bad_alloc &s) { status(std::string("CEGAR Loop Exception: Memory exhausted")); } catch(const std::string &s) { status(std::string("CEGAR Loop Exception: ") + s); } catch(const char *s) { status(std::string("CEGAR Loop Exception: ") + s); if(std::string(s)=="refinement failure") { status("Dumping failure.o"); write_goto_binary("failure.o", ns.get_context(), model.goto_functions, mh); } } catch(unsigned u) { status(std::string("CEGAR Loop Exception: ") + i2string(u)); } catch(...) { status("UNKNOWN EXCEPTION CAUGHT"); } return false; }
int ddcci_add_controls_to_subgroup(xmlNodePtr control, xmlNodePtr mon_control, struct subgroup_db *current_group, struct vcp_entry** vcp, char* defined, char *matchedcontrols, int faulttolerance) { xmlNodePtr cur; xmlChar *mon_ctrlid; xmlChar *options_ctrlid, *options_ctrlname; enum refresh_type options_refresh; xmlChar *tmp; char *endptr; int i; struct control_db *current_control = malloc(sizeof(struct control_db)); struct control_db **last_control_ref = ¤t_group->control_list; memset(current_control, 0, sizeof(struct control_db)); /* TODO: fix it, don't break order. */ /* This might break control order, but it is no big deal... */ while (*last_control_ref) { last_control_ref = &(*last_control_ref)->next; } /* List controls in group (options.xml) */ while (control != NULL) { if (!xmlStrcmp(control->name, (const xmlChar *) "control")) { options_ctrlid = xmlGetProp(control, BAD_CAST "id"); DDCCI_DB_RETURN_IF(options_ctrlid == NULL, 0, _("Can't find id property."), control); options_ctrlname = xmlGetProp(control, BAD_CAST "name"); DDCCI_DB_RETURN_IF(options_ctrlname == NULL, 0, _("Can't find name property."), control); tmp = xmlGetProp(control, BAD_CAST "refresh"); if (tmp) { if (!xmlStrcmp(tmp, BAD_CAST "none")) { options_refresh = none; } else if (!xmlStrcmp(tmp, BAD_CAST "all")) { options_refresh = all; } else { DDCCI_DB_RETURN_IF(1, 0, _("Invalid refresh type (!= none, != all)."), control); } xmlFree(tmp); } else { options_refresh = none; } //printf("!!control id=%s group=%s name=%s\n", options_ctrlid, options_groupname, options_ctrlname); /* Find the related control in monitor specifications */ i = 0; cur = mon_control->xmlChildrenNode; while (1) { if (cur == NULL) { /* Control not found */ /* TODO: return */ break; } if (!(xmlStrcmp(cur->name, (const xmlChar *)"control"))) { mon_ctrlid = xmlGetProp(cur, BAD_CAST "id"); if (!xmlStrcmp(mon_ctrlid, options_ctrlid)) { tmp = xmlGetProp(cur, BAD_CAST "address"); DDCCI_DB_RETURN_IF(tmp == NULL, 0, _("Can't find address property."), cur); current_control->address = strtol((char*)tmp, &endptr, 0); DDCCI_DB_RETURN_IF(*endptr != 0, 0, _("Can't convert address to int."), cur); xmlFree(tmp); matchedcontrols[i] = 1; if (vcp[current_control->address] == NULL) { if (get_verbosity()) { printf(_("Control %s has been discarded by the caps string.\n"), options_ctrlid); } memset(current_control, 0, sizeof(struct control_db)); break; } if (defined[current_control->address]) { if (get_verbosity() > 1) { printf(_("Control %s (0x%02x) has already been defined.\n"), options_ctrlid, current_control->address); } memset(current_control, 0, sizeof(struct control_db)); break; } current_control->id = xmlStrdup(options_ctrlid); current_control->name = _D((char*)options_ctrlname); current_control->refresh = options_refresh; tmp = xmlGetProp(cur, BAD_CAST "delay"); if (tmp) { current_control->delay = strtol((char*)tmp, &endptr, 10); DDCCI_DB_RETURN_IF(*endptr != 0, 0, _("Can't convert delay to int."), cur); xmlFree(tmp); } else { current_control->delay = -1; } tmp = xmlGetProp(control, BAD_CAST "type"); DDCCI_DB_RETURN_IF(tmp == NULL, 0, _("Can't find type property."), control); if (!(xmlStrcmp(tmp, (const xmlChar *)"value"))) { current_control->type = value; } else if (!(xmlStrcmp(tmp, (const xmlChar *)"command"))) { current_control->type = command; if (ddcci_get_value_list(control, cur, current_control, 1, faulttolerance) < 0) { return 0; } if (current_control->value_list == NULL) { /* No value defined, use the default 0x01 value */ struct value_db *current_value = malloc(sizeof(struct value_db)); current_value->id = xmlCharStrdup("default"); current_value->name = _D((char*)options_ctrlname); current_value->value = 0x01; current_value->next = NULL; current_control->value_list = current_value; } } else if (!(xmlStrcmp(tmp, (const xmlChar *)"list"))) { current_control->type = list; if (ddcci_get_value_list(control, cur, current_control, 0, faulttolerance) < 0) { return 0; } } else { DDCCI_DB_RETURN_IF(1, 0, _("Invalid type."), control); } xmlFree(tmp); /*printf("**control id=%s group=%s name=%s address=%s\n", options_ctrlid, options_groupname, options_ctrlname, mon_address);*/ defined[current_control->address] = 1; *last_control_ref = current_control; last_control_ref = ¤t_control->next; current_control = malloc(sizeof(struct control_db)); memset(current_control, 0, sizeof(struct control_db)); xmlFree(mon_ctrlid); break; } else { xmlFree(mon_ctrlid); } } if (cur->type == XML_ELEMENT_NODE) i++; cur = cur->next; } xmlFree(options_ctrlid); xmlFree(options_ctrlname); } control = control->next; } // controls loop free(current_control); return 1; }