// Handle FLTK events int Fl_Table::handle(int event) { PRINTEVENT; int ret = Fl_Group::handle(event); // let FLTK group handle events first if (ret) { if (Fl::event_inside(hscrollbar) || Fl::event_inside(vscrollbar)) return 1; if (Fl::focus() != this && contains(Fl::focus())) return 1; } // Which row/column are we over? int R, C; // row/column being worked on ResizeFlag resizeflag; // which resizing area are we over? (0=none) TableContext context = cursor2rowcol(R, C, resizeflag); switch ( event ) { case FL_PUSH: if (Fl::event_button() == 1 && !Fl::event_clicks()) { if (Fl::focus() != this) { take_focus(); do_callback(CONTEXT_TABLE, -1, -1); ret = 1; } damage_zone(current_row, current_col, select_row, select_col, R, C); if (context == CONTEXT_CELL) { current_row = select_row = R; current_col = select_col = C; _selecting = CONTEXT_CELL; } else { current_row = select_row = -1; current_col = select_col = -1; } } // Need this for eg. right click to pop up a menu if ( Fl_Widget::callback() && // callback defined? resizeflag == RESIZE_NONE ) // not resizing? { do_callback(context, R, C); } // do callback switch ( context ) { case CONTEXT_CELL: // FL_PUSH on a cell? ret = 1; // express interest in FL_RELEASE break; case CONTEXT_NONE: // FL_PUSH on table corner? if ( Fl::event_button() == 1 && Fl::event_x() < x() + row_header_width()) { current_col = 0; select_col = cols() - 1; current_row = 0; select_row = rows() - 1; damage_zone(current_row, current_col, select_row, select_col); ret = 1; } break; case CONTEXT_COL_HEADER: // FL_PUSH on a column header? if ( Fl::event_button() == 1) { // Resizing? Handle it if ( resizeflag ) { // Start resize if left click on column border. // "ret=1" ensures we get drag events from now on. // (C-1) is used if mouse is over the left hand side // of cell, so we resize the next column on the left. // _resizing_col = ( resizeflag & RESIZE_COL_LEFT ) ? C-1 : C; _resizing_row = -1; _dragging_x = Fl::event_x(); ret = 1; } else { // Not resizing? Select the column current_col = select_col = C; current_row = 0; select_row = rows() - 1; _selecting = CONTEXT_COL_HEADER; damage_zone(current_row, current_col, select_row, select_col); ret = 1; } } break; case CONTEXT_ROW_HEADER: // FL_PUSH on a row header? if ( Fl::event_button() == 1 ) { // Resizing? Handle it if ( resizeflag ) { // Start resize if left mouse clicked on row border. // "ret = 1" ensures we get drag events from now on. // (R-1) is used if mouse is over the top of the cell, // so that we resize the row above. // _resizing_row = ( resizeflag & RESIZE_ROW_ABOVE ) ? R-1 : R; _resizing_col = -1; _dragging_y = Fl::event_y(); ret = 1; } else { // Not resizing? Select the row current_row = select_row = R; current_col = 0; select_col = cols() - 1; _selecting = CONTEXT_ROW_HEADER; damage_zone(current_row, current_col, select_row, select_col); ret = 1; } } break; default: ret = 0; // express disinterest break; } _last_row = R; break; case FL_DRAG: if (_auto_drag == 1) { ret = 1; break; } if ( _resizing_col > -1 ) { // Dragging column? // // Let user drag even /outside/ the row/col widget. // Don't allow column width smaller than 1. // Continue to show FL_CURSOR_WE at all times during drag. // int offset = _dragging_x - Fl::event_x(); int new_w = col_width(_resizing_col) - offset; if ( new_w < _col_resize_min ) new_w = _col_resize_min; col_width(_resizing_col, new_w); _dragging_x = Fl::event_x(); table_resized(); redraw(); change_cursor(FL_CURSOR_WE); ret = 1; if ( Fl_Widget::callback() && when() & FL_WHEN_CHANGED ) { do_callback(CONTEXT_RC_RESIZE, R, C); } } else if ( _resizing_row > -1 ) { // Dragging row? // // Let user drag even /outside/ the row/col widget. // Don't allow row width smaller than 1. // Continue to show FL_CURSOR_NS at all times during drag. // int offset = _dragging_y - Fl::event_y(); int new_h = row_height(_resizing_row) - offset; if ( new_h < _row_resize_min ) new_h = _row_resize_min; row_height(_resizing_row, new_h); _dragging_y = Fl::event_y(); table_resized(); redraw(); change_cursor(FL_CURSOR_NS); ret = 1; if ( Fl_Widget::callback() && when() & FL_WHEN_CHANGED ) { do_callback(CONTEXT_RC_RESIZE, R, C); } } else { if (Fl::event_button() == 1 && _selecting == CONTEXT_CELL && context == CONTEXT_CELL) { if (select_row != R || select_col != C) damage_zone(current_row, current_col, select_row, select_col, R, C); select_row = R; select_col = C; ret = 1; } else if (Fl::event_button() == 1 && _selecting == CONTEXT_ROW_HEADER && context & (CONTEXT_ROW_HEADER|CONTEXT_COL_HEADER|CONTEXT_CELL)) { if (select_row != R) damage_zone(current_row, current_col, select_row, select_col, R, C); select_row = R; ret = 1; } else if (Fl::event_button() == 1 && _selecting == CONTEXT_COL_HEADER && context & (CONTEXT_ROW_HEADER|CONTEXT_COL_HEADER|CONTEXT_CELL)) { if (select_col != C) damage_zone(current_row, current_col, select_row, select_col, R, C); select_col = C; ret = 1; } } // Enable autodrag if not resizing, and mouse has moved off table edge if ( _resizing_row < 0 && _resizing_col < 0 && _auto_drag == 0 && ( Fl::event_x() > x() + w() - 20 || Fl::event_x() < x() + row_header_width() || Fl::event_y() > y() + h() - 20 || Fl::event_y() < y() + col_header_height() ) ) { _start_auto_drag(); } break; case FL_RELEASE: _stop_auto_drag(); switch ( context ) { case CONTEXT_ROW_HEADER: // release on row header case CONTEXT_COL_HEADER: // release on col header case CONTEXT_CELL: // release on a cell case CONTEXT_TABLE: // release on dead zone if ( _resizing_col == -1 && // not resizing a column _resizing_row == -1 && // not resizing a row Fl_Widget::callback() && // callback defined when() & FL_WHEN_RELEASE && // on button release _last_row == R ) // release on same row PUSHed? { // Need this for eg. left clicking on a cell to select it do_callback(context, R, C); } break; default: break; } if ( Fl::event_button() == 1 ) { change_cursor(FL_CURSOR_DEFAULT); _resizing_col = -1; _resizing_row = -1; ret = 1; } break; case FL_MOVE: if ( context == CONTEXT_COL_HEADER && // in column header? resizeflag ) // resize + near boundary? { change_cursor(FL_CURSOR_WE); } // show resize cursor else if ( context == CONTEXT_ROW_HEADER && // in row header? resizeflag ) // resize + near boundary? { change_cursor(FL_CURSOR_NS); } // show resize cursor else { change_cursor(FL_CURSOR_DEFAULT); } // normal cursor ret = 1; break; case FL_ENTER: // See FLTK event docs on the FL_ENTER widget if (!ret) take_focus(); ret = 1; //FALLTHROUGH case FL_LEAVE: // We want to track the mouse if resizing is allowed. if ( resizeflag ) { ret = 1; } if ( event == FL_LEAVE ) { _stop_auto_drag(); change_cursor(FL_CURSOR_DEFAULT); } break; case FL_FOCUS: Fl::focus(this); //FALLTHROUGH case FL_UNFOCUS: _stop_auto_drag(); ret = 1; break; case FL_KEYBOARD: ret = 0; switch(Fl::event_key()) { case FL_Home: ret = move_cursor(0, -1000000); break; case FL_End: ret = move_cursor(0, 1000000); break; case FL_Page_Up: ret = move_cursor(-(botrow - toprow - 1), 0); break; case FL_Page_Down: ret = move_cursor(botrow - toprow - 1 , 0); break; case FL_Left: ret = move_cursor(0, -1); break; case FL_Right: ret = move_cursor(0, 1); break; case FL_Up: ret = move_cursor(-1, 0); break; case FL_Down: ret = move_cursor(1, 0); break; } if (ret && Fl::focus() != this) { do_callback(CONTEXT_TABLE, -1, -1); take_focus(); } if (!ret && Fl_Widget::callback() && when() & FL_WHEN_NOT_CHANGED ) { do_callback(CONTEXT_CELL, select_row, select_col); //damage_zone(current_row, current_col, select_row, select_col); ret = 1; } break; default: change_cursor(FL_CURSOR_DEFAULT); break; } return(ret); }
int main( int argc, char** argv ) { int* final_result; // double mag = shell_arg_float(argc, argv, "-m", 2.0); // Configure global variables for mandelbrot size int omp_procs = shell_arg_int(argc, argv, "--procs", 1); int write_to_file = shell_arg_int(argc, argv, "-f", 0); int img_width = shell_arg_int(argc, argv, "-w", 40); int img_height = shell_arg_int(argc, argv, "-h", 40); mandelbrot_iters = shell_arg_int(argc, argv, "-i", 1000); MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nproc); MPI_Comm_rank(MPI_COMM_WORLD, &iproc); if (iproc == 0) { fprintf(stderr, "Starting parallel mandelbrot calculation...\n"); final_result = malloc(img_width * img_height * sizeof(int)); } { float start, finish; int* sizes; int* offsets; fprintf(stderr, "Node %d started...\n", iproc); start = when(); { int rem = img_width % nproc; int my_img_w = img_width / nproc + (iproc < rem ? 1 : 0); int my_img_x = img_width / nproc * iproc + (iproc < rem ? iproc : rem); float my_mdb_x = Left + (Width / img_width) * my_img_x; float my_mdb_w = (Width / img_width) * my_img_w; // Allocate space for result IntArray result = ia_alloc2(my_img_w, img_height); fprintf(stderr, "%d -- x: %d, y: 0, dim: %d x %d\n", iproc, my_img_x, my_img_w, img_height); mandelbrot_omp(my_img_x, my_img_w, // Image coords 0, img_height, my_mdb_x, my_mdb_w, // Mandelbrot coords Top, Height, result, omp_procs); // Allocate sizes array for root node if (iproc == 0) { sizes = malloc(nproc * sizeof(int)); offsets = malloc(nproc * sizeof(int)); } // Let the root node know how big each result is MPI_Gather(&result.size, 1, MPI_INT, sizes, 1, MPI_INT, 0, MPI_COMM_WORLD); if (iproc == 0) { int i; offsets[0] = 0; for (i = 0; i < nproc; i++) offsets[i + 1] = offsets[i] + sizes[i]; } MPI_Gatherv(result.ptr, result.size, MPI_INT, final_result, sizes, offsets, MPI_INT, 0, MPI_COMM_WORLD); } finish = when(); if (iproc == 0) { if (write_to_file) write_image(final_result, sizes, img_width, img_height); free(final_result); } // All nodes: fprintf(stderr, "Node %d completed in %f seconds.\n", iproc, finish - start); } MPI_Finalize(); return 0; }
int main(int argc, char* argv[]) { double start_time; double end_time; start_time = when(); /*Intialize arrays*/ for(int i=0;i<MAXROW;i++) { for(int j=0;j<MAXCOL;j++) { if(i==0 || j==0 || j==(MAXCOL-1)) { array1[i][j] = 0.0; array2[i][j] = 0.0; } else if (i==MAXROW-1) { array1[i][j] = 100.0; array2[i][j] = 100.0; } else if (i==400 && j<=330) { array1[i][j] = 100.0; array2[i][j] = 100.0; } else if (i==200 && j ==500) { array1[i][j] = 100.0; array2[i][j] = 100.0; } else { array1[i][j] = 50.0; array2[i][j] = 50.0; } } } /*Initialisation of arrays complete */ /* initialise barrier*/ mylib_init_linear_barrier(&barrier1); mylib_init_linear_barrier(&barrier2); mylib_init_linear_barrier(&barrier3); /*Initialise Threads*/ int n; int* arg; for(int i=0;i<PROCS;i++) { arg = malloc (sizeof(*arg)); *arg = i; if(pthread_create(&t[i], NULL,(void*) &check_for_convergence,arg)!=0) printf("Thread creation failed\n"); } /*Initialisation of threads complete */ /* Wait for all threads to complete */ for(int i=0;i<PROCS;i++) { pthread_join(t[i],NULL); } /*destroy barrier*/ mylib_destroy_linear_barrier(&barrier1); mylib_destroy_linear_barrier(&barrier2); mylib_destroy_linear_barrier(&barrier3); end_time=when(); printf("No of iterations = %d\n",num_of_iter); printf("Total execution time = %f\n", end_time-start_time); return 1; }
Ensure(Formatter, makes_one_letter_paragraph_from_one_character_input) { expect(reader, will_return('a')); always_expect(reader, will_return(EOF)); expect(writer, when(paragraph, is_equal_to_string("a"))); by_paragraph(&reader, NULL, &writer, NULL); }
void main(int argc, char **argv) { char *ptr; int n; debug1("DEBUG: main( %d, **argv )\n",argc); if (argc < 2 || argc > 3) { fprintf(stderr, "\nERROR: Invalid number of arguments: %d\nCommand: %s", argc-1,*argv); for (n=1; n<argc; n++) fprintf(stderr," \"%s\"",argv[n]); fprintf(stderr,"\nUsage: %s device [baudrate]\n\n",*argv); #ifndef INIT_BUG_WORKAROUND exit(3); #endif } debug("\n\n\nDEBUG: Running...\n"); fd = open(ISSUE, O_RDONLY); trace1("TRACE: /etc/issue status = %d\n",fd); if (fd < 0) { perror("ERROR"); } else { trace1("TRACE: File exists: %s\n", ISSUE); put(13); #ifdef SUPER_SMALL while ((n=read(fd,Buffer,sizeof(Buffer))) > 0) write(1,Buffer,n); #else when(); host(); *Buffer = '\0'; while (read(fd,Buffer,1) > 0) { ch = *Buffer; trace1("TRACE: Found '%c'\n", ch); if (ch == '\\' || ch == '@') { Buffer[1] = ch; read(fd,Buffer+1,1); } switch (ch) { case '\n': put(' '); put(ch); break; case '\\': ch = Buffer[1]; debug1("DEBUG: Found '\\%c'\n",ch); switch(ch) { case '0': /* NUL */ ch = 0; case '\\': case '@': put(ch); break; case 'b': /* BS Backspace */ put(8); break; case 'f': /* FF Formfeed */ put(12); break; case 'n': /* LF Linefeed */ put(10); break; case 's': /* SP Space */ put(32); break; case 't': /* HT Tab */ do { put(' '); } while (col & 7); break; case 'r': /* CR Return */ ch=13; default: /* Anything else */ put('\\'); put(ch); break; } break; case '@': ch = Buffer[1]; debug1("DEBUG: Found '@%c'\n",ch); switch(ch) { case '@': put(ch); break; case 'B': /* Baud Rate */ if (argv > 2) { state(argv[2]); state(" Baud"); } else state("Terminal"); break; case 'D': /* Date */ state(Date); break; case 'H': /* Host */ state(Host); break; case 'L': /* Line used */ if (argv > 1) { ptr = rindex(argv[1],'/'); if (ptr == NULL) ptr = argv[1]; } else ptr = NULL; if (ptr == NULL) ptr = "tty"; state(ptr); break; case 'S': /* System */ state("ELKS"); break; case 'T': /* Time */ state(Time); break; #if 0 case 'U': /* Users */ state("1 user"); break; #endif #ifdef ELKS_VERSION case 'V': /* Version */ state(ELKS_VERSION); break; #endif default: put('@'); put(ch); break; } break; default: put(ch); break; } *Buffer = '\0'; } #endif close(fd); } trace1("TRACE: Finished with %s\n", ISSUE); for (;;) { state("login: "******"DEBUG: Execv failed.\n\n"); exit(2); } } }
int main(int argc, char *argv[], char *envp[]) { register char *pl, *pr, *p, x; #ifdef AK auto FILE *f = fopen("/www/log/isdn.log", "r"); #else auto FILE *f = fopen("/var/log/isdn.log", "r"); #endif auto char s[BUFSIZ], sx[BUFSIZ]; auto int i, l, col, day, lday = UNKNOWN, month, lmonth = UNKNOWN; auto double dur; auto char *version; auto char *myname = basename(argv[0]); auto int opt, go, s0, indent; auto time_t now; auto struct tm *tm; if (f != (FILE *)NULL) { while ((opt = getopt(argc, argv, options)) != EOF) switch (opt) { case 'n' : onlynumbers++; break; case 'v' : verbose = atoi(optarg); break; case 'V' : print_version(myname); exit(0); case 'i' : showincoming++; break; case 'o' : showoutgoing++; break; case 'e' : showerrors++; break; case 'a' : showincoming = showoutgoing = showerrors = 1; break; case 'N' : strcpy(onlythis, optarg); break; case 'm' : netto++; break; case 'f' : force++; break; case 't' : onlytoday++; break; case 'I' : onlyInternal++; break; case 'E' : onlyExternal++; break; case '?' : printf(usage, argv[0], argv[0], options); return(1); } /* switch */ if (!showincoming && !showoutgoing && !showerrors) { printf("This makes no sense! You must specify -i, -o or -e\n"); printf("\t-a -> alle Verbindungen anzeigen i.e. \"-ioe\"\n"); printf("\t -> show all connections\n"); printf("\t-e -> nichtzustandegekommene Verbindungen anzeigen\n"); printf("\t -> show incomplete calls\n"); printf("\t-f -> Verbindungsentgeld _immer_ neu berechnen\n"); printf("\t -> recalculate costs _always_\n"); printf("\t-i -> reinkommende Verbindungen anzeigen\n"); printf("\t -> show incoming calls\n"); printf("\t-m -> ohne MwSt anzeigen\n"); printf("\t -> prices without VAT\n"); printf("\t-n -> _nicht_ anstelle Rufnummern Alias-Bezeichnungen anzeigen\n"); printf("\t -> do _not_ replace numbers with aliases\n"); printf("\t-o -> rausgehende Verbindungen anzeigen\n"); printf("\t -> show outgoing calls\n"); printf("\t-t -> nur die heutigen Verbindungen anzeigen\n"); printf("\t -> show only current connections\n"); printf("\t-vn -> Verbose Level\n"); printf("\t-Nnnn -> nur Verbindungen mit _dieser_ Rufnummer anzeigen\n"); printf("\t -> show only calls with the specified number\n"); printf("\t-I -> nur Verbindungen am Internen S0-Bus anzeigen\n"); printf("\t -> show only calls on the internal S0 bus\n"); printf("\t-E -> nur Verbindungen am Externen S0-Bus anzeigen\n"); printf("\t -> show only calls on the external S0 bus\n"); printf("\t-V -> Version anzeigen\n"); printf("\t -> show version\n"); return(1); } /* if */ *home = 0; interns0 = 3; set_print_fct_for_tools(print_in_modules); if (!readconfig(myname)) { initHoliday(holifile, &version); if (verbose) fprintf(stderr, "%s\n", version); initDest(destfile, &version); if (verbose) fprintf(stderr, "%s\n", version); initRate(rateconf, ratefile, zonefile, &version); if (verbose) fprintf(stderr, "%s\n", version); memset(&msnsum, 0, sizeof(msnsum)); memset(&provsum, 0, sizeof(provsum)); memset(&zonesum, 0, sizeof(zonesum)); partner[0] = (PARTNER *)calloc(knowns, sizeof(PARTNER)); partner[1] = (PARTNER *)calloc(knowns, sizeof(PARTNER)); time(&now); tm = localtime(&now); tm->tm_sec = tm->tm_min = tm->tm_hour = 0; now = mktime(tm); while (fgets(s, BUFSIZ, f)) { pl = s; col = 0; memset(&c, 0, sizeof(c)); while ((pr = strchr(pl, '|'))) { memcpy(sx, pl, (l = (pr - pl))); sx[l] = 0; pl = pr + 1; switch (col++) { case 0 : break; case 1 : deb(sx); strcpy(c.num[CALLING], sx); break; case 2 : deb(sx); strcpy(c.num[CALLED], sx); break; case 3 : dur = atoi(sx); break; case 4 : c.duration = atol(sx) / 100; break; case 5 : c.connect = atol(sx); break; case 6 : c.units = atoi(sx); break; case 7 : c.dialout = *sx == 'O'; break; case 8 : c.cause = atoi(sx); break; case 9 : c.ibytes = atoi(sx); break; case 10 : c.obytes = atoi(sx); break; case 11 : strcpy(c.version, sx); break; case 12 : c.si1 = atoi(sx); break; case 13 : c.si2 = atoi(sx); break; case 14 : c.currency_factor = atof(sx); break; case 15 : strcpy(c.currency, sx); break; case 16 : c.pay = atof(sx); break; case 17 : c.provider = atoi(sx); break; case 18 : break; } /* switch */ } /* while */ /* Repair wrong entries from older (or current?) isdnlog-versions ... */ if (abs((int)dur - (int)c.duration) > 1) { if (verbose) fprintf(stderr, "REPAIR: Duration %f -> %f\n", c.duration, dur); c.duration = dur; } /* if */ if (!memcmp(c.num[CALLED], "+4910", 5)) { p = c.num[CALLED] + 7; x = *p; *p = 0; c.provider = atoi(c.num[CALLED] + 5); *p = x; if (strlen(c.num[CALLED]) > 7) memmove(c.num[CALLED] + 3, c.num[CALLED] + 8, strlen(c.num[CALLED]) - 7); if (verbose) fprintf(stderr, "REPAIR: Provider=%d\n", c.provider); } /* if */ if (!c.provider || (c.provider == UNKNOWN)) { if (verbose) fprintf(stderr, "REPAIR: Provider %d -> %d\n", c.provider, preselect); c.provider = preselect; } /* if */ if (c.dialout && (strlen(c.num[CALLED]) > 3) && !getSpecial(c.num[CALLED])) { sprintf(s, "0%s", c.num[CALLED] + 3); if (getSpecial(s)) { if (verbose) fprintf(stderr, "REPAIR: Callee %s -> %s\n", c.num[CALLED], s); strcpy(c.num[CALLED], s); } /* if */ } /* if */ if (!c.dialout && (strlen(c.num[CALLING]) > 3) && !getSpecial(c.num[CALLING])) { sprintf(s, "0%s", c.num[CALLING] + 3); if (getSpecial(s)) { if (verbose) fprintf(stderr, "REPAIR: Caller %s -> %s\n", c.num[CALLING], s); strcpy(c.num[CALLING], s); } /* if */ } /* if */ go = 0; if (showoutgoing && c.dialout && c.duration) go++; if (showincoming && !c.dialout && c.duration) go++; if (showerrors && !c.duration) go++; if (*onlythis && strstr(c.num[CALLING], onlythis) == NULL && strstr(c.num[CALLED], onlythis) == NULL) go = 0; if (onlytoday && c.connect < now) go = 0; s0 = 0; /* Externer S0 */ if (c.dialout && (strlen(c.num[CALLING]) < interns0)) s0 = 1; /* Interner S0-Bus */ if (!c.dialout && (strlen(c.num[CALLED]) < interns0)) s0 = 1; /* Interner S0-Bus */ if (onlyInternal && !s0) go = 0; if (onlyExternal && s0) go = 0; if (go) { when(s, &day, &month); if (lmonth == UNKNOWN) lmonth = month; else if (month != lmonth) { total(SUBTOTAL); lmonth = month; } /* if */ if (lday == UNKNOWN) lday = day; else if (day != lday) { printf("\n"); lday = day; } /* else */ printf("%s%s ", s, timestr(c.duration)); if (*c.num[CALLING]) normalizeNumber(c.num[CALLING], &number[CALLING], TN_ALL); else { memset(&number[CALLING], 0, sizeof(TELNUM)); strcpy(number[CALLING].msn, "UNKNOWN"); } /* else */ if (*c.num[CALLED]) normalizeNumber(c.num[CALLED], &number[CALLED], TN_ALL); else { memset(&number[CALLED], 0, sizeof(TELNUM)); strcpy(number[CALLED].msn, "UNKNOWN"); } /* else */ findme(); indent = 11 + strlen(c.currency); if (c.dialout) { findrate(); msnsum[SUBTOTAL][c.si1][c.ihome].ncalls++; justify(number[CALLING].msn, c.num[CALLED], number[CALLED]); provsum[SUBTOTAL][c.provider].ncalls++; strcpy(s, getProvider(pnum2prefix(c.provider, c.connect))); s[PROVLEN] = 0; if (c.provider < 100) sprintf(c.sprovider, " 010%02d:%-*s", c.provider, PROVLEN, s); else if (c.provider < 200) sprintf(c.sprovider, "0100%03d:%-*s", c.provider - 100, PROVLEN, s); else sprintf(c.sprovider, "01900%02d:%-*s", c.provider - 200, PROVLEN, s); if (c.duration) { #if 0 // Berechnung, um wieviel es mit AktivPlus der DTAG billiger waere -- stimmt irgendwie eh nicht mehr ... if ((preselect == DTAG) && ((c.zone == 1) || (c.zone == 2))) { auto struct tm *tm = localtime(&c.connect); auto int takte; auto double price; takte = (c.duration + 59) / 60; if ((tm->tm_wday > 0) && (tm->tm_wday < 5)) { /* Wochentag */ if ((tm->tm_hour > 8) && (tm->tm_hour < 18)) /* Hauptzeit */ price = 0.06; else price = 0.03; } else /* Wochenende */ price = 0.03; c.aktiv = takte * price; msnsum[SUBTOTAL][c.si1][c.ihome].aktiv += c.aktiv; provsum[SUBTOTAL][c.provider].aktiv += c.aktiv; zonesum[SUBTOTAL][c.zone].aktiv += c.aktiv; } /* if */ #endif if (c.pay < 0.0) { /* impossible! */ c.pay = c.compute; c.computed++; } /* if */ if (force || fabs(c.pay - c.compute) > 1.00) { c.pay = c.compute; c.computed++; } /* if */ if (netto) c.pay = c.pay * 100.0 / 116.0; if (c.pay) printf("%12s%s ", printRate(c.pay), c.computed ? "*" : " "); else printf("%*s", indent, ""); printf("%s%s%s", c.country, c.sprovider, c.error); #if 0 if (c.aktiv) printf(" AktivPlus - %13s", printRate(c.pay - c.aktiv)); #endif msnsum[SUBTOTAL][c.si1][c.ihome].pay += c.pay; msnsum[SUBTOTAL][c.si1][c.ihome].duration += c.duration; msnsum[SUBTOTAL][c.si1][c.ihome].compute += c.compute; msnsum[SUBTOTAL][c.si1][c.ihome].ibytes += c.ibytes; msnsum[SUBTOTAL][c.si1][c.ihome].obytes += c.obytes; provsum[SUBTOTAL][c.provider].pay += c.pay; provsum[SUBTOTAL][c.provider].duration += c.duration; provsum[SUBTOTAL][c.provider].compute += c.compute; provsum[SUBTOTAL][c.provider].ibytes += c.ibytes; provsum[SUBTOTAL][c.provider].obytes += c.obytes; zonesum[SUBTOTAL][c.zone].pay += c.pay; zonesum[SUBTOTAL][c.zone].duration += c.duration; zonesum[SUBTOTAL][c.zone].compute += c.compute; zonesum[SUBTOTAL][c.zone].ibytes += c.ibytes; zonesum[SUBTOTAL][c.zone].obytes += c.obytes; } else { printf("%*s%s%s", indent, "", c.country, c.sprovider); if ((c.cause != 0x1f) && /* Normal, unspecified */ (c.cause != 0x10)) /* Normal call clearing */ printf(" %s", qmsg(TYPE_CAUSE, VERSION_EDSS1, c.cause)); if ((c.cause == 0x22) || /* No circuit/channel available */ (c.cause == 0x2a) || /* Switching equipment congestion */ (c.cause == 0x2f)) /* Resource unavailable, unspecified */ provsum[SUBTOTAL][c.provider].failed++; } /* else */ } else { /* Dialin: */ justify(number[CALLED].msn, c.num[CALLING], number[CALLING]); printf("%*s%s%s", indent, "", c.country, c.sprovider); } /* else */ if (c.known[OTHER] == UNKNOWN) { l = UNKNOWN; for (i = 0; i < nunknown[c.dialout]; i++) { if (!strcmp(unknown[c.dialout][i].num, c.num[OTHER])) { l = i; break; } /* if */ } /* for */ if (l == UNKNOWN) { l = nunknown[c.dialout]; nunknown[c.dialout]++; if (!l) unknown[c.dialout] = (PARTNER *)malloc(sizeof(PARTNER)); else unknown[c.dialout] = (PARTNER *)realloc(unknown[c.dialout], sizeof(PARTNER) * nunknown[c.dialout]); memset(&unknown[c.dialout][l], 0, sizeof(PARTNER)); } /* if */ strcpy(unknown[c.dialout][l].num, c.num[OTHER]); unknown[c.dialout][l].ihome = c.ihome; unknown[c.dialout][l].ncalls++; unknown[c.dialout][l].pay += c.pay; unknown[c.dialout][l].duration += c.duration; unknown[c.dialout][l].compute += c.compute; unknown[c.dialout][l].ibytes += c.ibytes; unknown[c.dialout][l].obytes += c.obytes; } else { strcpy(partner[c.dialout][c.known[OTHER]].num, c.num[OTHER]); partner[c.dialout][c.known[OTHER]].ncalls++; partner[c.dialout][c.known[OTHER]].pay += c.pay; partner[c.dialout][c.known[OTHER]].duration += c.duration; partner[c.dialout][c.known[OTHER]].compute += c.compute; partner[c.dialout][c.known[OTHER]].ibytes += c.ibytes; partner[c.dialout][c.known[OTHER]].obytes += c.obytes; } /* else */ printf("\n"); } /* if */ } /* while */ fclose(f); total(SUBTOTAL); if (!onlytoday) total(TOTAL); showpartner(); } else fprintf(stderr, "%s: Can't read configuration file(s)\n", myname); } else fprintf(stderr, "%s: Can't open \"isdn.log\" file\n", myname); return(0); } /* isdnbill */
ComboBrowser(int x, int y, int w, int h) : Fl_Browser(x, y, w, h, 0) { combo=0; when(FL_WHEN_RELEASE); }
int di_wrap_rcall(char* (*di_rcall)(uint64_t source, struct vfs_obj *file, const char *args)) { when(PORT_RCALL, __rcall_wrapper); _di_rcall = di_rcall; return 0; }
// This version fixes stuff and does IP int CbcHeuristicLocal::solutionFix(double & objectiveValue, double * newSolution, const int * /*keep*/) { /* If when is set to off (0), or set to root (1) and we're not at the root, return. If this heuristic discovered the current solution, don't continue. */ numCouldRun_++; // See if to do if (!when() || (when() == 1 && model_->phase() != 1)) return 0; // switched off // Don't do if it was this heuristic which found solution! if (this == model_->lastHeuristic()) return 0; /* Load up a new solver with the solution. Why continuousSolver(), as opposed to solver()? */ OsiSolverInterface * newSolver = model_->continuousSolver()->clone(); const double * colLower = newSolver->getColLower(); //const double * colUpper = newSolver->getColUpper(); int numberIntegers = model_->numberIntegers(); const int * integerVariable = model_->integerVariable(); /* The net effect here is that anything that hasn't moved from its lower bound will be fixed at lower bound. See comments in solution() w.r.t. asymmetric treatment of upper and lower bounds. */ int i; int nFix = 0; for (i = 0; i < numberIntegers; i++) { int iColumn = integerVariable[i]; const OsiObject * object = model_->object(i); // get original bounds double originalLower; double originalUpper; getIntegerInformation( object, originalLower, originalUpper); newSolver->setColLower(iColumn, CoinMax(colLower[iColumn], originalLower)); if (!used_[iColumn]) { newSolver->setColUpper(iColumn, colLower[iColumn]); nFix++; } } /* Try a `small' branch-and-bound search. The notion here is that we've fixed a lot of variables and reduced the amount of `free' problem to a point where a small BaB search will suffice to fully explore the remaining problem. This routine will execute integer presolve, then call branchAndBound to do the actual search. */ int returnCode = 0; #ifdef CLP_INVESTIGATE2 printf("Fixing %d out of %d (%d continuous)\n", nFix, numberIntegers, newSolver->getNumCols() - numberIntegers); #endif if (nFix*10 <= numberIntegers) { // see if we can fix more int * which = new int [2*(numberIntegers-nFix)]; int * sort = which + (numberIntegers - nFix); int n = 0; for (i = 0; i < numberIntegers; i++) { int iColumn = integerVariable[i]; if (used_[iColumn]) { which[n] = iColumn; sort[n++] = used_[iColumn]; } } CoinSort_2(sort, sort + n, which); // only half fixed in total n = CoinMin(n, numberIntegers / 2 - nFix); int allow = CoinMax(numberSolutions_ - 2, sort[0]); int nFix2 = 0; for (i = 0; i < n; i++) { int iColumn = integerVariable[i]; if (used_[iColumn] <= allow) { newSolver->setColUpper(iColumn, colLower[iColumn]); nFix2++; } else { break; } } delete [] which; nFix += nFix2; #ifdef CLP_INVESTIGATE2 printf("Number fixed increased from %d to %d\n", nFix - nFix2, nFix); #endif } if (nFix*10 > numberIntegers) { returnCode = smallBranchAndBound(newSolver, numberNodes_, newSolution, objectiveValue, objectiveValue, "CbcHeuristicLocal"); /* -2 is return due to user event, and -1 is overloaded with what look to be two contradictory meanings. */ if (returnCode < 0) { returnCode = 0; // returned on size int numberColumns = newSolver->getNumCols(); int numberContinuous = numberColumns - numberIntegers; if (numberContinuous > 2*numberIntegers && nFix*10 < numberColumns) { #define LOCAL_FIX_CONTINUOUS #ifdef LOCAL_FIX_CONTINUOUS //const double * colUpper = newSolver->getColUpper(); const double * colLower = newSolver->getColLower(); int nAtLb = 0; //double sumDj=0.0; const double * dj = newSolver->getReducedCost(); double direction = newSolver->getObjSense(); for (int iColumn = 0; iColumn < numberColumns; iColumn++) { if (!newSolver->isInteger(iColumn)) { if (!used_[iColumn]) { //double djValue = dj[iColumn]*direction; nAtLb++; //sumDj += djValue; } } } if (nAtLb) { // fix some continuous double * sort = new double[nAtLb]; int * which = new int [nAtLb]; //double threshold = CoinMax((0.01*sumDj)/static_cast<double>(nAtLb),1.0e-6); int nFix2 = 0; for (int iColumn = 0; iColumn < numberColumns; iColumn++) { if (!newSolver->isInteger(iColumn)) { if (!used_[iColumn]) { double djValue = dj[iColumn] * direction; if (djValue > 1.0e-6) { sort[nFix2] = -djValue; which[nFix2++] = iColumn; } } } } CoinSort_2(sort, sort + nFix2, which); int divisor = 2; nFix2 = CoinMin(nFix2, (numberColumns - nFix) / divisor); for (int i = 0; i < nFix2; i++) { int iColumn = which[i]; newSolver->setColUpper(iColumn, colLower[iColumn]); } delete [] sort; delete [] which; #ifdef CLP_INVESTIGATE2 printf("%d integers have zero value, and %d continuous fixed at lb\n", nFix, nFix2); #endif returnCode = smallBranchAndBound(newSolver, numberNodes_, newSolution, objectiveValue, objectiveValue, "CbcHeuristicLocal"); if (returnCode < 0) returnCode = 0; // returned on size } #endif } } } /* If the result is complete exploration with a solution (3) or proven infeasibility (2), we could generate a cut (the AI folks would call it a nogood) to prevent us from going down this route in the future. */ if ((returnCode&2) != 0) { // could add cut returnCode &= ~2; } delete newSolver; return returnCode; }
int di_wrap_sync(int (*di_sync)(uint64_t source, struct vfs_obj *file)) { when(PORT_SYNC, __sync_wrapper); _di_sync = di_sync; return 0; }
int di_wrap_share(int (*di_share)(uint64_t source, struct vfs_obj *file, uint8_t *buffer, size_t size, uint64_t off)) { when(PORT_SHARE, __share_wrapper); _di_share = di_share; return 0; }
int di_wrap_reset(int (*di_reset)(uint64_t source, struct vfs_obj *file)) { when(PORT_RESET, __reset_wrapper); _di_reset = di_reset; return 0; }
int di_wrap_write(size_t (*di_write)(uint64_t source, struct vfs_obj *file, uint8_t *buffer, size_t size, uint64_t off)) { when(PORT_WRITE, __write_wrapper); _di_write = di_write; return 0; }
int di_wrap_read(size_t (*di_read)(uint64_t source, struct vfs_obj *file, uint8_t *buffer, size_t size, uint64_t off)) { when(PORT_READ, __read_wrapper); _di_read = di_read; return 0; }
int Panner::handle ( int m ) { int r = Fl_Widget::handle( m ); switch ( m ) { case FL_ENTER: case FL_LEAVE: redraw(); return 1; case FL_PUSH: if ( Fl::event_button2() ) { _bypassed = ! _bypassed; redraw(); return 1; } else if ( Fl::event_button1() && ( drag = event_point() ) ) return 1; else return 0; case FL_RELEASE: if ( Fl::event_button1() && drag ) { drag = NULL; do_callback(); redraw(); return 1; } else return 0; case FL_MOUSEWHEEL: { /* TODO: place point on opposite face of sphere */ } case FL_DRAG: { if ( ! drag ) return 0; float X = Fl::event_x() - x(); float Y = Fl::event_y() - y(); int tx, ty, tw, th; bbox( tx, ty, tw, th ); /* if ( _outs < 3 ) */ /* drag->angle( (float)(X / (tw / 2)) - 1.0f, 0.0f ); */ /* else */ drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f ); if ( when() & FL_WHEN_CHANGED ) do_callback(); redraw(); return 1; } } return r; // return 0; }
int CbcHeuristicNaive::solution(double & solutionValue, double * betterSolution) { numCouldRun_++; // See if to do bool atRoot = model_->getNodeCount() == 0; int passNumber = model_->getCurrentPassNumber(); if (!when() || (when() == 1 && model_->phase() != 1) || !atRoot || passNumber != 1) return 0; // switched off // Don't do if it was this heuristic which found solution! if (this == model_->lastHeuristic()) return 0; numRuns_++; double cutoff; model_->solver()->getDblParam(OsiDualObjectiveLimit, cutoff); double direction = model_->solver()->getObjSense(); cutoff *= direction; cutoff = CoinMin(cutoff, solutionValue); OsiSolverInterface * solver = model_->continuousSolver(); if (!solver) solver = model_->solver(); const double * colLower = solver->getColLower(); const double * colUpper = solver->getColUpper(); const double * objective = solver->getObjCoefficients(); int numberColumns = model_->getNumCols(); int numberIntegers = model_->numberIntegers(); const int * integerVariable = model_->integerVariable(); int i; bool solutionFound = false; CoinWarmStartBasis saveBasis; CoinWarmStartBasis * basis = dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ; if (basis) { saveBasis = * basis; delete basis; } // First just fix all integers as close to zero as possible OsiSolverInterface * newSolver = cloneBut(7); // wassolver->clone(); for (i = 0; i < numberIntegers; i++) { int iColumn = integerVariable[i]; double lower = colLower[iColumn]; double upper = colUpper[iColumn]; double value; if (lower > 0.0) value = lower; else if (upper < 0.0) value = upper; else value = 0.0; newSolver->setColLower(iColumn, value); newSolver->setColUpper(iColumn, value); } newSolver->initialSolve(); if (newSolver->isProvenOptimal()) { double solValue = newSolver->getObjValue() * direction ; if (solValue < cutoff) { // we have a solution solutionFound = true; solutionValue = solValue; memcpy(betterSolution, newSolver->getColSolution(), numberColumns*sizeof(double)); COIN_DETAIL_PRINT(printf("Naive fixing close to zero gave solution of %g\n", solutionValue)); cutoff = solValue - model_->getCutoffIncrement(); } } // Now fix all integers as close to zero if zero or large cost int nFix = 0; for (i = 0; i < numberIntegers; i++) { int iColumn = integerVariable[i]; double lower = colLower[iColumn]; double upper = colUpper[iColumn]; double value; if (fabs(objective[i]) > 0.0 && fabs(objective[i]) < large_) { nFix++; if (lower > 0.0) value = lower; else if (upper < 0.0) value = upper; else value = 0.0; newSolver->setColLower(iColumn, value); newSolver->setColUpper(iColumn, value); } else { // set back to original newSolver->setColLower(iColumn, lower); newSolver->setColUpper(iColumn, upper); } } const double * solution = solver->getColSolution(); if (nFix) { newSolver->setWarmStart(&saveBasis); newSolver->setColSolution(solution); newSolver->initialSolve(); if (newSolver->isProvenOptimal()) { double solValue = newSolver->getObjValue() * direction ; if (solValue < cutoff) { // try branch and bound double * newSolution = new double [numberColumns]; COIN_DETAIL_PRINT(printf("%d fixed after fixing costs\n", nFix)); int returnCode = smallBranchAndBound(newSolver, numberNodes_, newSolution, solutionValue, solutionValue, "CbcHeuristicNaive1"); if (returnCode < 0) returnCode = 0; // returned on size if ((returnCode&2) != 0) { // could add cut returnCode &= ~2; } if (returnCode == 1) { // solution solutionFound = true; memcpy(betterSolution, newSolution, numberColumns*sizeof(double)); COIN_DETAIL_PRINT(printf("Naive fixing zeros gave solution of %g\n", solutionValue)); cutoff = solutionValue - model_->getCutoffIncrement(); } delete [] newSolution; } } } #if 1 newSolver->setObjSense(-direction); // maximize newSolver->setWarmStart(&saveBasis); newSolver->setColSolution(solution); for (int iColumn = 0; iColumn < numberColumns; iColumn++) { double value = solution[iColumn]; double lower = colLower[iColumn]; double upper = colUpper[iColumn]; double newLower; double newUpper; if (newSolver->isInteger(iColumn)) { newLower = CoinMax(lower, floor(value) - 2.0); newUpper = CoinMin(upper, ceil(value) + 2.0); } else { newLower = CoinMax(lower, value - 1.0e5); newUpper = CoinMin(upper, value + 1.0e-5); } newSolver->setColLower(iColumn, newLower); newSolver->setColUpper(iColumn, newUpper); } newSolver->initialSolve(); if (newSolver->isProvenOptimal()) { double solValue = newSolver->getObjValue() * direction ; if (solValue < cutoff) { nFix = 0; newSolver->setObjSense(direction); // correct direction //const double * thisSolution = newSolver->getColSolution(); for (int iColumn = 0; iColumn < numberColumns; iColumn++) { double value = solution[iColumn]; double lower = colLower[iColumn]; double upper = colUpper[iColumn]; double newLower = lower; double newUpper = upper; if (newSolver->isInteger(iColumn)) { if (value < lower + 1.0e-6) { nFix++; newUpper = lower; } else if (value > upper - 1.0e-6) { nFix++; newLower = upper; } else { newLower = CoinMax(lower, floor(value) - 2.0); newUpper = CoinMin(upper, ceil(value) + 2.0); } } newSolver->setColLower(iColumn, newLower); newSolver->setColUpper(iColumn, newUpper); } // try branch and bound double * newSolution = new double [numberColumns]; COIN_DETAIL_PRINT(printf("%d fixed after maximizing\n", nFix)); int returnCode = smallBranchAndBound(newSolver, numberNodes_, newSolution, solutionValue, solutionValue, "CbcHeuristicNaive1"); if (returnCode < 0) returnCode = 0; // returned on size if ((returnCode&2) != 0) { // could add cut returnCode &= ~2; } if (returnCode == 1) { // solution solutionFound = true; memcpy(betterSolution, newSolution, numberColumns*sizeof(double)); COIN_DETAIL_PRINT(printf("Naive maximizing gave solution of %g\n", solutionValue)); cutoff = solutionValue - model_->getCutoffIncrement(); } delete [] newSolution; } } #endif delete newSolver; return solutionFound ? 1 : 0; }
// Handle FLTK events int Fl_Table_Copy::handle(int event) { PRINTEVENT; int ret = Fl_Group::handle(event); // let FLTK group handle events first // Which row/column are we over? int R, C; // row/column being worked on ResizeFlag resizeflag; // which resizing area are we over? (0=none) TableContext context = cursor2rowcol(R, C, resizeflag); if (ret) { if (Fl::event_inside(hscrollbar) || Fl::event_inside(vscrollbar)) return 1; if ( context != CONTEXT_ROW_HEADER && // mouse not in row header (STR#2742) context != CONTEXT_COL_HEADER && // mouse not in col header (STR#2742) Fl::focus() != this && // we don't have focus? contains(Fl::focus())) { // focus is a child? return 1; } } // Make snapshots of realtime event states *before* we service user's cb, // which may do things like post popup menus that return with unexpected button states. int _event_button = Fl::event_button(); int _event_clicks = Fl::event_clicks(); int _event_x = Fl::event_x(); int _event_y = Fl::event_y(); int _event_key = Fl::event_key(); #if FLTK_ABI_VERSION >= 10303 int _event_state = Fl::event_state(); #endif Fl_Widget *_focus = Fl::focus(); switch ( event ) { case FL_PUSH: // Single left-click on table? do user's callback with CONTEXT_TABLE if (_event_button == 1 && !_event_clicks) { if (_focus == this) { take_focus(); do_callback(CONTEXT_TABLE, -1, -1); ret = 1; } damage_zone(current_row, current_col, select_row, select_col, R, C); if (context == CONTEXT_CELL) { current_row = select_row = R; current_col = select_col = C; _selecting = CONTEXT_CELL; } else { // Clear selection if not resizing row/col if ( !resizeflag ) { current_row = select_row = -1; current_col = select_col = -1; } } } // A click on table with user's callback defined? // Need this for eg. right click to pop up a menu // if ( Fl_Widget::callback() && // callback defined? resizeflag == RESIZE_NONE ) { // not resizing? do_callback(context, R, C); // do callback with context (cell, header, etc) } // Handle selection if handling a left-click // Use snapshot of _event_button we made before servicing user's cb's // to avoid checking realtime state of buttons which may have changed // during the user's callbacks. // switch ( context ) { case CONTEXT_CELL: // FL_PUSH on a cell? ret = 1; // express interest in FL_RELEASE break; case CONTEXT_NONE: // FL_PUSH on table corner? if ( _event_button == 1 && _event_x < x() + row_header_width()) { current_col = 0; select_col = cols() - 1; current_row = 0; select_row = rows() - 1; damage_zone(current_row, current_col, select_row, select_col); ret = 1; } break; case CONTEXT_COL_HEADER: // FL_PUSH on a column header? if ( _event_button == 1) { // Resizing? Handle it if ( resizeflag ) { // Start resize if left click on column border. // "ret=1" ensures we get drag events from now on. // (C-1) is used if mouse is over the left hand side // of cell, so we resize the next column on the left. // _resizing_col = ( resizeflag & RESIZE_COL_LEFT ) ? C-1 : C; _resizing_row = -1; _dragging_x = _event_x; ret = 1; } else { // Not resizing? Select the column if ( Fl::focus() != this && contains(Fl::focus()) ) return 0; // STR #3018 - item 1 current_col = select_col = C; current_row = 0; select_row = rows() - 1; _selecting = CONTEXT_COL_HEADER; damage_zone(current_row, current_col, select_row, select_col); ret = 1; } } break; case CONTEXT_ROW_HEADER: // FL_PUSH on a row header? if ( _event_button == 1 ) { // Resizing? Handle it if ( resizeflag ) { // Start resize if left mouse clicked on row border. // "ret = 1" ensures we get drag events from now on. // (R-1) is used if mouse is over the top of the cell, // so that we resize the row above. // _resizing_row = ( resizeflag & RESIZE_ROW_ABOVE ) ? R-1 : R; _resizing_col = -1; _dragging_y = _event_y; ret = 1; } else { // Not resizing? Select the row if ( Fl::focus() != this && contains(Fl::focus()) ) return 0; // STR #3018 - item 1 current_row = select_row = R; current_col = 0; select_col = cols() - 1; _selecting = CONTEXT_ROW_HEADER; damage_zone(current_row, current_col, select_row, select_col); ret = 1; } } break; default: ret = 0; // express disinterest break; } _last_row = R; break; case FL_DRAG: if (_auto_drag == 1) { ret = 1; break; } if ( _resizing_col > -1 ) { // Dragging column? // // Let user drag even /outside/ the row/col widget. // Don't allow column width smaller than 1. // Continue to show FL_CURSOR_WE at all times during drag. // int offset = _dragging_x - _event_x; int new_w = col_width(_resizing_col) - offset; if ( new_w < _col_resize_min ) new_w = _col_resize_min; col_width(_resizing_col, new_w); _dragging_x = _event_x; table_resized(); redraw(); change_cursor(FL_CURSOR_WE); ret = 1; if ( Fl_Widget::callback() && when() & FL_WHEN_CHANGED ) { do_callback(CONTEXT_RC_RESIZE, R, C); } } else if ( _resizing_row > -1 ) { // Dragging row? // // Let user drag even /outside/ the row/col widget. // Don't allow row width smaller than 1. // Continue to show FL_CURSOR_NS at all times during drag. // int offset = _dragging_y - _event_y; int new_h = row_height(_resizing_row) - offset; if ( new_h < _row_resize_min ) new_h = _row_resize_min; row_height(_resizing_row, new_h); _dragging_y = _event_y; table_resized(); redraw(); change_cursor(FL_CURSOR_NS); ret = 1; if ( Fl_Widget::callback() && when() & FL_WHEN_CHANGED ) { do_callback(CONTEXT_RC_RESIZE, R, C); } } else { if (_event_button == 1 && _selecting == CONTEXT_CELL && context == CONTEXT_CELL) { // Dragging a cell selection? if ( _event_clicks ) break; // STR #3018 - item 2 if (select_row != R || select_col != C) { damage_zone(current_row, current_col, select_row, select_col, R, C); } select_row = R; select_col = C; ret = 1; } else if (_event_button == 1 && _selecting == CONTEXT_ROW_HEADER && context & (CONTEXT_ROW_HEADER|CONTEXT_COL_HEADER|CONTEXT_CELL)) { if (select_row != R) { damage_zone(current_row, current_col, select_row, select_col, R, C); } select_row = R; ret = 1; } else if (_event_button == 1 && _selecting == CONTEXT_COL_HEADER && context & (CONTEXT_ROW_HEADER|CONTEXT_COL_HEADER|CONTEXT_CELL)) { if (select_col != C) { damage_zone(current_row, current_col, select_row, select_col, R, C); } select_col = C; ret = 1; } } // Enable autodrag if not resizing, and mouse has moved off table edge if ( _resizing_row < 0 && _resizing_col < 0 && _auto_drag == 0 && ( _event_x > x() + w() - 20 || _event_x < x() + row_header_width() || _event_y > y() + h() - 20 || _event_y < y() + col_header_height() ) ) { _start_auto_drag(); } break; case FL_RELEASE: _stop_auto_drag(); switch ( context ) { case CONTEXT_ROW_HEADER: // release on row header case CONTEXT_COL_HEADER: // release on col header case CONTEXT_CELL: // release on a cell case CONTEXT_TABLE: // release on dead zone if ( _resizing_col == -1 && // not resizing a column _resizing_row == -1 && // not resizing a row Fl_Widget::callback() && // callback defined when() & FL_WHEN_RELEASE && // on button release _last_row == R ) { // release on same row PUSHed? // Need this for eg. left clicking on a cell to select it do_callback(context, R, C); } break; default: break; } if ( _event_button == 1 ) { change_cursor(FL_CURSOR_DEFAULT); _resizing_col = -1; _resizing_row = -1; ret = 1; } break; case FL_MOVE: if ( context == CONTEXT_COL_HEADER && // in column header? resizeflag ) { // resize + near boundary? change_cursor(FL_CURSOR_WE); // show resize cursor } else if ( context == CONTEXT_ROW_HEADER && // in row header? resizeflag ) { // resize + near boundary? change_cursor(FL_CURSOR_NS); // show resize cursor } else { change_cursor(FL_CURSOR_DEFAULT); // normal cursor } ret = 1; break; case FL_ENTER: // See FLTK event docs on the FL_ENTER widget if (!ret) take_focus(); ret = 1; //FALLTHROUGH case FL_LEAVE: // We want to track the mouse if resizing is allowed. if ( resizeflag ) { ret = 1; } if ( event == FL_LEAVE ) { _stop_auto_drag(); change_cursor(FL_CURSOR_DEFAULT); } break; case FL_FOCUS: Fl::focus(this); //FALLTHROUGH case FL_UNFOCUS: _stop_auto_drag(); ret = 1; break; case FL_KEYBOARD: { ret = 0; int is_row = select_row; int is_col = select_col; switch(_event_key) { case FL_Home: ret = move_cursor(0, -1000000); break; case FL_End: ret = move_cursor(0, 1000000); break; case FL_Page_Up: ret = move_cursor(-(botrow - toprow - 1), 0); break; case FL_Page_Down: ret = move_cursor(botrow - toprow - 1 , 0); break; case FL_Left: ret = move_cursor(0, -1); break; case FL_Right: ret = move_cursor(0, 1); break; case FL_Up: ret = move_cursor(-1, 0); break; case FL_Down: ret = move_cursor(1, 0); break; case FL_Tab: #if FLTK_ABI_VERSION >= 10303 if ( !tab_cell_nav() ) break; // not navigating cells? let fltk handle it (STR#2862) if ( _event_state & FL_SHIFT ) { ret = move_cursor(0, -1, 0); // shift-tab -> left } else { ret = move_cursor(0, 1, 0); // tab -> right } break; #else break; // without tab_cell_nav(), Fl_Table_Copy should default to navigating widgets, not cells #endif } if (ret && Fl::focus() != this) { do_callback(CONTEXT_TABLE, -1, -1); take_focus(); } //if (!ret && Fl_Widget::callback() && when() & FL_WHEN_NOT_CHANGED ) if ( Fl_Widget::callback() && ( ( !ret && when() & FL_WHEN_NOT_CHANGED ) || ( is_row!= select_row || is_col!= select_col ) ) ) { do_callback(CONTEXT_CELL, select_row, select_col); //damage_zone(current_row, current_col, select_row, select_col); ret = 1; } break; } default: change_cursor(FL_CURSOR_DEFAULT); break; } return(ret); }
score_t search_ab(boost::shared_ptr<search_info> proc_info) { if(proc_info->get_abort()) return bad_min_score; // Unmarshall the info struct node_t board = proc_info->board; const int depth = proc_info->depth; if(depth != board.depth) { std::cout << "depth=" << depth << "board.depth=" << board.depth << std::endl; } assert(depth == board.depth); score_t alpha = proc_info->alpha; score_t beta = proc_info->beta; assert(depth >= 0); std::ostringstream strB; print_board(board, strB, true); std::string strBoard = strB.str(); // if we are a leaf node, return the value from the eval() function if (depth == 0) { evaluator ev; DECL_SCORE(s,ev.eval(board, chosen_evaluator),board.hash); return s; } /* if this isn't the root of the search tree (where we have to pick a chess_move and can't simply return 0) then check to see if the position is a repeat. if so, we can assume that this line is a draw and return 0. */ if (board.ply && reps(board)==3) { DECL_SCORE(z,0,board.hash); proc_info->draw = true; return z; } // fifty chess_move draw rule if (board.fifty >= 100) { DECL_SCORE(z,0,board.hash); proc_info->draw = true; return z; } score_t max_val = bad_min_score; score_t p_board = board.p_board; score_t zlo = bad_min_score,zhi = bad_max_score; bool white =board.side == LIGHT; bool entry_found = false; int excess =0; bool exact = false; if (white && board.root_side == LIGHT && db_on && board.ply > 0 && !proc_info->quiescent){ entry_found = dbase.get_transposition_value (board, zlo, zhi, white,p_board,excess,exact,board.depth); int pe = proc_info->excess; if (excess > proc_info->excess){ proc_info->excess = excess; //if (!board.follow_capt && search_method == MTDF) board.follow_capt = true; } else{ //board.follow_depth = 0; } if(entry_found && excess > 0) { assert(depth == board.depth); std::cout << "excess = " << (excess+depth) << std::endl; zhi = bad_max_score; verify(strBoard,board.side,depth+excess,board.castle,board.ep,zlo,bad_max_score); } } if (entry_found){ return zlo; } if(!entry_found) { entry_found = get_transposition_value (board, zlo, zhi); if(!entry_found && db_on && board.side == LIGHT){ entry_found = dbase.get_transposition_value(board,zlo,zhi,white,p_board,excess,true,depth); verify(strBoard,board.side,depth,board.castle,board.ep,zlo,zhi); } } if (entry_found) { if(zlo >= beta) { return zlo; } if(alpha >= zhi) { return zhi; } alpha = max(zlo,alpha); beta = min(zhi,beta); } if(alpha >= beta) { //proc_info->stop=false; //deeper= false; return alpha; } const score_t alpha0 = alpha; std::vector<chess_move> workq; std::vector<chess_move> max_move; gen(workq, board); // Generate the moves #ifdef PV_ON if(!proc_info->use_srand) proc_info->incr = rand(); proc_info->use_srand = false; srand(proc_info->incr); sort_pv(workq, board.depth); // Part of iterative deepening #endif const int worksq = workq.size(); std::vector<boost::shared_ptr<task> > tasks; int j=0; score_t val; bool aborted = false; bool children_aborted = false; // loop through the moves //for (; j < worksq; j++) while(j < worksq) { while(j < worksq) { chess_move g = workq[j++]; boost::shared_ptr<search_info> child_info{new search_info(board)}; bool parallel; if (!aborted && !proc_info->get_abort() && makemove(child_info->board, g)) { parallel = j > 0 && !capture(board,g); boost::shared_ptr<task> t = parallel_task(depth, ¶llel); t->info = child_info; int d = depth - 1; if(!test_alphabeta && d == 0 && capture(board,g)) { d = 1; /* if(!proc_info->quiescent) { t->info->alpha = bad_min_score; t->info->beta = bad_max_score; } */ t->info->quiescent = true; } else if(proc_info->quiescent) { t->info->quiescent = true; } t->info->board.depth = child_info->depth = d; assert(depth >= 0); t->info->alpha = -beta; t->info->beta = -alpha; t->info->mv = g; t->pfunc = search_ab_f; t->start(); tasks.push_back(t); // Control branching if (!parallel) break; /* else if (beta >= max_score*.9) continue; */ else if (tasks.size() < 5) continue; else break; } } When when(tasks); size_t const count = tasks.size(); for(size_t n_=0;n_<count;n_++) { int n = when.any(); boost::shared_ptr<task> child_task = tasks[n]; //assert(child_task.valid()); child_task->join(); boost::shared_ptr<search_info> child_info = child_task->info; tasks.erase(tasks.begin()+n); if(!children_aborted && (aborted || child_info->get_abort())) { for(unsigned int m = 0;m < tasks.size();m++) { tasks[m]->info->set_abort(true); } children_aborted = true; } //child_task->join(); if(child_info->get_abort()) continue; if(child_info->draw) proc_info->draw = true; val = -child_info->result; proc_info->log << " " << child_info->mv << "=" << val; bool found = false; if (child_info->excess > proc_info->excess){ proc_info->excess = child_info->excess; found = true; if (!board.follow_capt){ board.follow_capt = true; } } if (val > max_val || found ) { max_move.clear(); max_move.push_back(child_info->mv); if (val > max_val) max_val = val; if (val > alpha) { alpha = val; #ifdef PV_ON if(!child_info->get_abort()) ;//pv[board.search_depth - 1].set(child_info->mv); #endif if(alpha >= beta) { //aborted = true; j += worksq; continue; } } } else if(val == max_val && proc_info->excess == 0) { max_move.push_back(child_info->mv); } } if(alpha >= beta) { j += worksq; break; } } // no legal moves? then we're in checkmate or stalemate if (max_move.size()==0) { if (in_check(board, board.side)) { DECL_SCORE(s,max_score,board.hash); return s; } else { DECL_SCORE(z,0,board.hash); return z; } } if(db_on) { if (board.ply == 0 || board.depth>0) { assert(max_move.size() != 0); ScopedLock s(cmutex); move_to_make = max_move.at(rand() % max_move.size()); } } bool store = true; if(proc_info->draw) { store = false; } if(proc_info->quiescent) store = false; score_t lo, hi; if(proc_info->excess) { lo = max_val; hi = max_score; //std::cout<<"Max depth: "<<proc_info->excess+depth<<std::endl; store = false; } else if(alpha0 < max_val && max_val < beta) { lo = max_val-1; hi = max_val; } else if(max_val <= alpha0) { hi = max_val; lo = zlo; if(lo == zlo) store = false; } else if (max_val >= beta){ lo = max_val; hi = zhi; if(hi == zhi) store = false; } else { store = false; lo = hi = 0; } if(store && lo > hi) { std::cout << "lo=" << lo << " hi=" << hi << std::endl; abort(); } if(store && db_on) { verify(strBoard,board.side,depth,board.castle,board.ep,lo,hi); } if(store) { //if(board.depth > 1) dbase.add_data(board,lo,hi,white,proc_info->excess); set_transposition_value(board,lo,hi); } return max_val; }
int Fl_Button::handle(int event) { static bool oldval; static bool already_pushed=false; bool newval; switch (event) { case FL_LEAVE: case FL_ENTER: if (highlight_color() && takesevents()) redraw(FL_DAMAGE_HIGHLIGHT); case FL_MOVE: return 1; case FL_PUSH: if(!already_pushed) oldval = value(); already_pushed = true; case FL_DRAG: if (Fl::event_inside(0,0,w(),h())) { held_down = this; if (type() == RADIO) newval = true; else newval = !oldval; } else { held_down = 0; newval = oldval; } if (value(newval) && when()&FL_WHEN_CHANGED) do_callback((void*)value()); return 1; case FL_RELEASE: redraw(FL_DAMAGE_VALUE); held_down = 0; already_pushed = false; if (value() == oldval) return 1; if (type() == RADIO) setonly(); else if (type()) // TOGGLE ; // leave it as set else { value(oldval); if (when() & FL_WHEN_CHANGED) do_callback((void*)value()); } if (when() & FL_WHEN_RELEASE) do_callback((void*)value()); else set_changed(); return 1; case FL_UNFOCUS: case FL_FOCUS: redraw(FL_DAMAGE_HIGHLIGHT); // grab initial focus if we are an Fl_Return_Button: return shortcut()=='\r' ? 2 : 1; case FL_SHORTCUT: case FL_KEY: if(event==FL_SHORTCUT && !test_shortcut()) return 0; if(event==FL_KEY && Fl::event_key() != ' ' && Fl::event_key() != FL_Enter ) return 0; if (type() == RADIO/* && !value()*/) { setonly(); if (when() & FL_WHEN_CHANGED) do_callback((void*)value()); } // TOGGLE else if (type()) { value(!value()); if (when() & FL_WHEN_CHANGED) do_callback((void*)value()); } if (when() & FL_WHEN_RELEASE) do_callback((void*)value()); else set_changed(); return 1; default: break; } return Fl_Widget::handle(event); }
int tDateTime3( void ) { { DateTime when( "6/28/95 18:30" ); DateTime dt( "6/28/95 18:30" ); dt.setTimeZone(); if( dt.getOffset() != -18000 ) ERROR; if( dt.getTimeT() + 18000 != when.getTimeT() ) ERROR; if( ! dt.isLocal() ) ERROR; if( ! dt.isDST() ) ERROR; dt.setTimeT( when.getTimeT() ); if( dt.getTimeT() != when.getTimeT() ) ERROR; if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; } { DateTime when( "2/28/95 18:30" ); DateTime dt( "2/28/95 18:30" ); dt.setTimeZone(); if( dt.getOffset() != -21600 ) ERROR; if( dt.getTimeT() + 21600 != when.getTimeT() ) ERROR; if( ! dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; dt.set( when.getTimeT() ); if( dt.getTimeT() != when.getTimeT() ) ERROR; if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; dt.set( when.getTimeT(), TRUE ); if( dt.getOffset() != -21600 ) ERROR; if( dt.getTimeT() + 21600 != when.getTimeT() ) ERROR; if( ! dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; dt.set( when.getTimeT(), FALSE ); if( dt.getTimeT() != when.getTimeT() ) ERROR; if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; } { const char * dateString = "3/1/92 3:30:00"; DateTime when( dateString ); DateTime dt( "6/28/95 18:30" ); dt.setTimeZone(); dt.set( dateString ); if( dt.getTimeT() != when.getTimeT() ) ERROR; if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; if( dt.getTimeT() != 699420600 ) ERROR; if( dt.getSecOfDay() != 12600 ) ERROR; if( dt.getHour() != 3 ) ERROR; if( dt.getMinute() != 30 ) ERROR; if( dt.getSecond() != 0 ) ERROR; if( dt.getDayOfYear() != 61 ) ERROR; if( dt.getDayOfMonth() != 1 ) ERROR; if( dt.getMonth() != 3 ) ERROR; if( dt.getYearOfCentury() != 92 ) ERROR; if( dt.getYear() != 1992 ) ERROR; dt.set( "01-Mar-92 03:30:00", "%d-%b-%y %H:%M:%S" ); if( dt.getTimeT() != 699420600 ) ERROR; if( dt.getSecOfDay() != 12600 ) ERROR; if( dt.getHour() != 3 ) ERROR; if( dt.getMinute() != 30 ) ERROR; if( dt.getSecond() != 0 ) ERROR; if( dt.getDayOfYear() != 61 ) ERROR; if( dt.getDayOfMonth() != 1 ) ERROR; if( dt.getMonth() != 3 ) ERROR; if( dt.getYearOfCentury() != 92 ) ERROR; if( dt.getYear() != 1992 ) ERROR; } { int year = 1992; int month = 3; int day = 1; int hour = 18; int min = 15; int sec = 30; DateTime dt( "6/28/95 18:30" ); dt.setTimeZone(); dt.set( year, month, day ); if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; if( dt.getYear() != year ) ERROR; if( dt.getMonth() != month ) ERROR; if( dt.getDayOfMonth() != day ) ERROR; if( dt.getHour() != 0 ) ERROR; if( dt.getMinute() != 0 ) ERROR; if( dt.getSecond() != 0 ) ERROR; year = 10; dt.set( year, month, day, hour, min, sec ); if( dt.getYear() != 2010 ) ERROR; if( dt.getMonth() != month ) ERROR; if( dt.getDayOfMonth() != day ) ERROR; if( dt.getHour() != hour ) ERROR; if( dt.getMinute() != min ) ERROR; if( dt.getSecond() != sec ) ERROR; } { int year = 92; int month = 3; int day = 1; int hour = 18; int min = 15; int sec = 30; struct tm tm; tm.tm_year = year; tm.tm_mon = month - 1; tm.tm_mday = day; tm.tm_hour = hour; tm.tm_min = min; tm.tm_sec = sec; DateTime dt( "6/28/95 18:30" ); dt.setTimeZone(); dt.set( tm ); if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; if( dt.getYear() != 1900 + year ) ERROR; if( dt.getMonth() != month ) ERROR; if( dt.getDayOfMonth() != day ) ERROR; if( dt.getHour() != hour ) ERROR; if( dt.getMinute() != min ) ERROR; if( dt.getSecond() != sec ) ERROR; } { int year = 1992; int month = 3; int day = 1; int hour = 18; int min = 15; int sec = 30; DateTime dt( "6/28/95 18:30" ); dt.setTimeZone(); dt.setValid( year, month, day ); if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; if( dt.getYear() != year ) ERROR; if( dt.getMonth() != month ) ERROR; if( dt.getDayOfMonth() != day ) ERROR; if( dt.getHour() != 0 ) ERROR; if( dt.getMinute() != 0 ) ERROR; if( dt.getSecond() != 0 ) ERROR; dt.set( year, month, day, hour, min, sec ); if( dt.getYear() != year ) ERROR; if( dt.getMonth() != month ) ERROR; if( dt.getDayOfMonth() != day ) ERROR; if( dt.getHour() != hour ) ERROR; if( dt.getMinute() != min ) ERROR; if( dt.getSecond() != sec ) ERROR; dt.setValid( 65, month, day ); if( dt.good() ) ERROR; dt.setValid( year, month, day ); if( ! dt.good() ) ERROR; dt.setValid( -1, month, day); if( dt.good() ) ERROR; dt.setValid( 2055, month, day ); if( dt.good() ) ERROR; dt.setValid( 1969, month, day ); if( dt.good() ) ERROR; dt.setValid( year, 0, day ); if( dt.good() ) ERROR; dt.setValid( year, 13, day ); if( dt.good() ) ERROR; dt.setValid( year, -1, day ); if( dt.good() ) ERROR; dt.setValid( year, month, -1 ); if( dt.good() ) ERROR; dt.setValid( year, month, 0 ); if( dt.good() ) ERROR; dt.setValid( 0, 0, 0 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 0 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 1, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 2, 28 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 2, 29 ); if( ! dt.good() ) ERROR; dt.setValid( 93, 2, 29 ); if( dt.good() ) ERROR; dt.setValid( 92, 3, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 3, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 4, 31 ); if( dt.good() ) ERROR; dt.setValid( 92, 4, 30 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 5, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 5, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 6, 31 ); if( dt.good() ) ERROR; dt.setValid( 92, 6, 30 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 7, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 7, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 8, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 8, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 9, 31 ); if( dt.good() ) ERROR; dt.setValid( 92, 9, 30 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 10, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 10, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 11, 31 ); if( dt.good() ) ERROR; dt.setValid( 92, 11, 30 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 12, 32 ); if( dt.good() ) ERROR; dt.setValid( 92, 12, 31 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 1, 1, -1 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 1, 24 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0, -1 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0, 60 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0, 0 ); if( ! dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0, 0, -1 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0, 0, 60 ); if( dt.good() ) ERROR; dt.setValid( 92, 1, 1, 0, 0, 0 ); if( ! dt.good() ) ERROR; } { DateTime dt( "6/28/95 18:30" ); dt.setTimeZone(); dt.setValid( "2/1/95 06:30:15" ); if( dt.getOffset() != 0 ) ERROR; if( dt.isLocal() ) ERROR; if( dt.isDST() ) ERROR; if( dt.getYear() != 1995 ) ERROR; if( dt.getMonth() != 2 ) ERROR; if( dt.getDayOfMonth() != 1 ) ERROR; if( dt.getHour() != 6 ) ERROR; if( dt.getMinute() != 30 ) ERROR; if( dt.getSecond() != 15 ) ERROR; if( ! dt.good() ) ERROR; dt.setValid( "95 01 01 15 30 15", "%y %m %d %H %M %S" ); if( dt.getYear() != 1995 ) ERROR; if( dt.getMonth() != 1 ) ERROR; if( dt.getDayOfMonth() != 1 ) ERROR; if( dt.getHour() != 15 ) ERROR; if( dt.getMinute() != 30 ) ERROR; if( dt.getSecond() != 15 ) ERROR; if( ! dt.good() ) ERROR; dt.setValid( "0/1/95" ); if( dt.good() ) ERROR; dt.setValid( "13/1/95" ); if( dt.good() ) ERROR; dt.setValid( "1/1/95" ); if( ! dt.good() ) ERROR; // This test fails. The strptime routine // converts the '0' to 0 which is january! // dt.setValid( "95 0 1", "%y %m %d" ); // if( dt.good() ) ERROR; dt.setValid( "13/1/95", "%m/%d/%y" ); if( dt.good() ) ERROR; dt.setValid( "1/1/95", "%m/%d/%y" ); if( ! dt.good() ) ERROR; dt.setValid( "2/29/92" ); if( ! dt.good() ) ERROR; dt.setValid( "2/29/95" ); if( dt.good() ) ERROR; dt.setValid( "92 2 29", "%y %m %d" ); if( ! dt.good() ) ERROR; dt.setValid( "93 2 29", "%y %m %d" ); if( dt.good() ) ERROR; dt.setValid( "1/1/65" ); if( dt.good() ) ERROR; dt.setValid( "1/1/95 24:0:0" ); if( dt.good() ) ERROR; dt.setValid( "1 1 95 24 0 0", "%m %d %y %h %m %s" ); if( dt.good() ) ERROR; dt.setValid( "1/1/95 23:60:0" ); if( dt.good() ) ERROR; dt.setValid( "1/1/95 23:59:60" ); if( dt.good() ) ERROR; dt.setValid( "1/1/95 23:59:59" ); if( ! dt.good() ) ERROR; } return( 0 ); }
void _init() { extern int main(int argc, char **argv); extern void _on_event(void); char **argv, *pack; size_t length; int argc; _when((uintptr_t) _on_event); /* unpack environment variables */ __loadenv(); /* setup standard streams */ stdin = fdopen(fdload(0), "r"); stdout = fdopen(fdload(1), "w"); stderr = fdopen(fdload(2), "w"); fs_root = fdload(3); /* set up signals */ __sig_init(); when(PORT_CHILD, NULL); /* set up I/O handlers */ when(PORT_REPLY, NULL); when(PORT_READ, reject); when(PORT_WRITE, reject); when(PORT_SYNC, reject); when(PORT_RESET, reject); when(PORT_SHARE, reject); when(PORT_RCALL, reject); when(PORT_EVENT, ignore); when(PORT_FIND, reject); when(PORT_CONS, reject); when(PORT_MOVE, reject); when(PORT_REMV, reject); when(PORT_LINK, reject); when(PORT_LIST, reject); when(PORT_SIZE, reject); when(PORT_TYPE, reject); when(PORT_PERM, reject); when(PORT_AUTH, reject); /* unpack argument list */ pack = __pack_load(PACK_KEY_ARG, &length); if (pack) { argv = loadarg(pack); for (argc = 0; argv[argc]; argc++); setenv("NAME", argv[0]); } else { argv = NULL; argc = 0; setenv("NAME", "unknown"); } __pack_reset(); /* execute main program */ exit(main(argc, argv)); }
tactic * mk_qfbv_tactic(ast_manager & m, params_ref const & p) { params_ref main_p; main_p.set_bool("elim_and", true); main_p.set_bool("push_ite_bv", true); main_p.set_bool("blast_distinct", true); params_ref simp2_p = p; simp2_p.set_bool("som", true); simp2_p.set_bool("pull_cheap_ite", true); simp2_p.set_bool("push_ite_bv", false); simp2_p.set_bool("local_ctx", true); simp2_p.set_uint("local_ctx_limit", 10000000); simp2_p.set_bool("flat", true); // required by som simp2_p.set_bool("hoist_mul", false); // required by som params_ref local_ctx_p = p; local_ctx_p.set_bool("local_ctx", true); params_ref solver_p; solver_p.set_bool("preprocess", false); // preprocessor of smt::context is not needed. params_ref no_flat_p; no_flat_p.set_bool("flat", false); params_ref ctx_simp_p; ctx_simp_p.set_uint("max_depth", 32); ctx_simp_p.set_uint("max_steps", 50000000); params_ref hoist_p; hoist_p.set_bool("hoist_mul", true); hoist_p.set_bool("som", false); params_ref solve_eq_p; // conservative guassian elimination. solve_eq_p.set_uint("solve_eqs_max_occs", 2); params_ref big_aig_p; big_aig_p.set_bool("aig_per_assertion", false); tactic * preamble_st = and_then(and_then(mk_simplify_tactic(m), mk_propagate_values_tactic(m), using_params(mk_solve_eqs_tactic(m), solve_eq_p), mk_elim_uncnstr_tactic(m), if_no_proofs(if_no_unsat_cores(mk_bv_size_reduction_tactic(m))), using_params(mk_simplify_tactic(m), simp2_p)), // Z3 can solve a couple of extra benchmarks by using hoist_mul // but the timeout in SMT-COMP is too small. // Moreover, it impacted negatively some easy benchmarks. // We should decide later, if we keep it or not. using_params(mk_simplify_tactic(m), hoist_p), mk_max_bv_sharing_tactic(m)); #ifdef USE_OLD_SAT_SOLVER tactic * new_sat = and_then(mk_simplify_tactic(m), mk_smt_tactic()); #else tactic * new_sat = cond(mk_or(mk_produce_proofs_probe(), mk_produce_unsat_cores_probe()), and_then(mk_simplify_tactic(m), mk_smt_tactic()), mk_sat_tactic(m)); #endif tactic * st = using_params(and_then(preamble_st, // If the user sets HI_DIV0=false, then the formula may contain uninterpreted function // symbols. In this case, we should not use cond(mk_is_qfbv_probe(), cond(mk_is_qfbv_eq_probe(), and_then(mk_bv1_blaster_tactic(m), using_params(mk_smt_tactic(), solver_p)), and_then(mk_bit_blaster_tactic(m), when(mk_lt(mk_memory_probe(), mk_const_probe(MEMLIMIT)), and_then(using_params(and_then(mk_simplify_tactic(m), mk_solve_eqs_tactic(m)), local_ctx_p), if_no_proofs(cond(mk_produce_unsat_cores_probe(), mk_aig_tactic(), using_params(mk_aig_tactic(), big_aig_p))))), new_sat)), mk_smt_tactic())), main_p); st->updt_params(p); return st; }
Ensure(Formatter, pairs_the_functions_with_the_resources) { expect(reader, when(stream, is_equal_to(1)), will_return('a')); always_expect(reader, when(stream, is_equal_to(1)), will_return(EOF)); expect(writer, when(stream, is_equal_to(2))); by_paragraph(&reader, (void *)1, &writer, (void *)2); }
Ensure(Words, invokes_callback_once_for_single_word_sentence) { expect(mocked_callback, when(word, is_equal_to_string("Word")), when(memo, is_null)); words("Word", &mocked_callback, NULL); }
int Flu_Spinner::handle(int event) { int W = w()*15/100; if( W < h()/2 ) W = h()/2; int X = x()+w()-W, Y = y(); if( (align() & FL_ALIGN_INSIDE) || !_editable ) { _input.readonly( true ); _input.cursor_color( FL_WHITE ); } else { _input.readonly( false ); _input.cursor_color( FL_BLACK ); } switch( event ) { case FL_PUSH: _dragging = true; if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this); _lastValue = value(); _lastY = Fl::event_y(); Fl::remove_timeout( repeat_callback, this ); if( Fl::event_inside( X, Y, W, h()/2 ) ) // up button { _pushed = true; _valbox[0] = FL_DOWN_BOX; _up = true; } if( Fl::event_inside( X, Y+h()/2, W, h()/2 ) ) // down button { _pushed = true; _valbox[1] = FL_DOWN_BOX; _up = false; } if( _pushed ) { increment_cb(); _totalTime = _initialDelay; if( _doRepeat ) Fl::add_timeout( _initialDelay, repeat_callback, this); handle_push(); take_focus(); redraw(); return 1; } break; case FL_DRAG: { // only do the dragging if the last Y differs from the current Y by more than 3 pixels if( ABS(_lastY-Fl::event_y()) < 3 ) break; _dragging = true; _pushed = false; Fl::remove_timeout( repeat_callback, this ); int oldWhen = when(); _setvalue(increment(_lastValue,(_lastY-Fl::event_y())*(Fl::event_state(FL_SHIFT|FL_CTRL|FL_ALT)?10:1))); _valbox[0] = _valbox[1] = FL_DOWN_BOX; when( oldWhen ); fl_cursor((Fl_Cursor)22); _input.redraw(); redraw(); } break; case FL_RELEASE: { bool doCB = ( ( when() & FL_WHEN_RELEASE ) || ( when() & FL_WHEN_RELEASE_ALWAYS ) ) && ( _pushed || ( _valbox[0] == FL_DOWN_BOX ^ _valbox[1] == FL_DOWN_BOX ) ); _pushed = false; _dragging = false; Fl::remove_timeout( repeat_callback, this ); _valbox[0] = _valbox[1] = FL_UP_BOX; fl_cursor(FL_CURSOR_DEFAULT); redraw(); handle_release(); if( doCB ) do_callback(); _input.take_focus(); } break; case FL_FOCUS: case FL_UNFOCUS: redraw(); _input.take_focus(); return 0; case FL_ENTER: if( Fl::event_inside( &_input ) ) return _input.handle(event); else if( active_r() ) { fl_cursor(FL_CURSOR_DEFAULT); return 1; } break; case FL_LEAVE: if( Fl::event_inside( &_input ) ) return _input.handle(event); else if( active_r() ) { fl_cursor(FL_CURSOR_DEFAULT); return 1; } break; case FL_KEYBOARD: switch( Fl::event_key() ) { case FL_Down: { int oldWhen = when(); when( FL_WHEN_CHANGED ); _setvalue(increment(value(),-1*(Fl::event_state(FL_SHIFT|FL_CTRL|FL_ALT)?10:1))); when( oldWhen ); redraw(); return 1; } case FL_Up: { int oldWhen = when(); when( FL_WHEN_CHANGED ); _setvalue(increment(value(),1*(Fl::event_state(FL_SHIFT|FL_CTRL|FL_ALT)?10:1))); when( oldWhen ); redraw(); return 1; } } break; } return _input.handle(event); }
int Panner::handle ( int m ) { int r = Fl_Group::handle( m ); switch ( m ) { case FL_ENTER: case FL_LEAVE: _projection_choice->value(_projection_mode); _range_choice->value(_range_mode); redraw(); return 1; case FL_PUSH: { if ( Fl::event_button1() || Fl::event_button3() ) drag = event_point(); if ( Fl::event_button2() ) { /* if ( _projection == POLAR ) */ /* _projection = ORTHO; */ /* else */ /* _projection = POLAR; */ } return 1; } case FL_RELEASE: if ( drag ) { do_callback(); drag = NULL; redraw(); return 1; } else return 0; case FL_MOUSEWHEEL: { /* Point *p = event_point(); */ /* if ( p ) */ /* drag = p; */ /* if ( drag ) */ /* { */ /* // drag->elevation( drag->elevation() + Fl::event_dy()); */ /* drag->elevation( 0 - drag->elevation() ); */ /* do_callback(); */ /* redraw(); */ /* return 1; */ /* } */ return 1; } case FL_DRAG: { if ( ! drag ) return 0; int tx, ty, tw, th; bbox( tx, ty, tw, th ); float X = (float(Fl::event_x() - tx) / tw ) - 0.5f; float Y = (float(Fl::event_y() - ty) / th) - 0.5f; if ( Fl::event_button1() ) { if ( POLAR == projection() ) set_polar( drag,X,Y ); else { if ( fabsf( X ) < 0.5f && fabsf( Y ) < 0.5f ) set_ortho( drag, X,Y ); } } else set_polar_radius( drag,X,Y ); if ( when() & FL_WHEN_CHANGED ) do_callback(); damage(FL_DAMAGE_EXPOSE); return 1; } } return r; // return 0; }