void oops_do(void f(oop*)) { if (is_filled()) { outer.oops_do(f); if(is_inner()) inner.oops_do(f); } }
/* * is_unique: return 1 if grid (r, c) not empty and * grid (r, c)'s number is unique among line r, col c and * the corresponding box. 0 if not. */ int is_unique(int r, int c, int puzzle[][9]) { int i, flag[9]; // make sure (r,c) not empty! if (!is_filled(puzzle, r, c)) return 0; for (i=0; i<9; i++) flag[i] = 0; i = puzzle[r-1][c-1]; puzzle[r-1][c-1] = 0; getbox(puzzle, r, c); getrow(puzzle, r, c); getcol(puzzle, r, c); puzzle[r-1][c-1] = i; flag[puzzle[r-1][c-1] - 1] = 1; for (i=0; i<9; i++) { if (box[i] >= 1 && box[i] <= 9) flag[box[i]-1]++; if (row[i] >= 1 && row[i] <= 9) flag[row[i]-1]++; if (col[i] >= 1 && col[i] <= 9) flag[col[i]-1]++; } for (i=0; i<9; i++) if (flag[i] > 1) return 0; return 1; }
/* * is_finished: return 1 if no empty grid exist in * puzzle[][9] and all grid is unique. return 0 if not. */ int is_finished(int puzzle[][9]) { int r, c; for (r=0; r<9; r++) for (c=0; c<9; c++) if (!(is_filled(puzzle, r+1, c+1) || is_unique(r+1, c+1, puzzle))) return 0; return 1; }
/* * exist_error: return 1 if the sudoku puzzle[][9] exist a * empty grid with no condidates. 0 if not. */ int exist_error(int puzzle[][9]) { int cond[9][9][9+1]; int r, c; get_condidates(cond, puzzle); for (r=0; r<9; r++) for (c=0; c<9; c++) if (!is_filled(puzzle, r+1, c+1) && (cond[r][c][0] < 1 || cond[r][c][0] > 9)) return 1; return 0; }
// If this function does not return segsize, it will signal an error // condition to the library. This will cause the transfer to get aborted // and the libcurl function used will return CURLE_WRITE_ERROR. static size_t write_data ( void *buffer, size_t size, size_t nmemb, void *userp ) { // The size (in bytes) of the received buffer. const int segsize = size * nmemb; // In this function, userp refers to a Buffer structure. Buffer *const userbuf = userp; if ( is_filled ( userbuf ) ) { return 0; } // Get truncated_segsize. int truncated_segsize = segsize; if ( userbuf->index + segsize >= userbuf->capa ) { truncated_segsize = userbuf->capa - 1 - userbuf->index; } if ( truncated_segsize > 0 ) { memcpy ( &( userbuf->wr_buf )[userbuf->index], buffer, truncated_segsize ); userbuf->index += truncated_segsize; // After each change, userbuf->wr_buf must be a valid string. ( userbuf->wr_buf )[userbuf->index] = '\0'; return truncated_segsize; } else { userbuf->index = userbuf->capa - 1; return 0; } }
static void add_filled_point(int x, int y, carmen_map_p true_map, carmen_map_p modify_map) { int num_points; grid_cell_p cell_list; double value; if (!is_in_map(x, y, modify_map)) return; value = true_map->map[x][y]; if (is_filled(value)) return; /* if (point_exists(x, y, FILLED)) */ /* return; */ num_points = scan_size[current_data_set]; if (num_points == max_scan_size[current_data_set]) { max_scan_size[current_data_set] *= 2; laser_scan[current_data_set] = realloc(laser_scan[current_data_set], max_scan_size[current_data_set]*sizeof(grid_cell_t)); carmen_test_alloc(laser_scan[current_data_set]); } cell_list = laser_scan[current_data_set]; value = FILLED; /* carmen_warn("Filling point %d (%d) %d %d\n", num_points, */ /* current_data_set, x, y); */ cell_list[num_points].x = x; cell_list[num_points].y = y; cell_list[num_points].value = value; scan_size[current_data_set]++; modify_map->map[x][y] = 2.0; }
const Key_file::Entry* Key_file::get_latest () const { return is_filled() ? get(latest()) : 0; }
int main ( int argc, char *argv[] ) { if ( argc < 4 ) { fprintf ( stderr, "Sorry, bad syntax. You must apply at least 3 arguments.\n" ); fprintf ( stderr, "%s <timeout> <url> <args>...\n", argv[0] ); return UNKNOWN; } if ( !is_positive_integer ( argv[1] ) ) { fprintf ( stderr, "Sorry, bad syntax. The first argument must be a positive" ); fprintf ( stderr, " integer (it is a timeout in seconds).\n" ); return UNKNOWN; } const int timeout = atoi ( argv[1] ); const char *const url = argv[2]; // First step, init curl. CURL *curl; curl = curl_easy_init ( ); if ( !curl ) { fprintf ( stderr, "Sorry, could not init curl.\n" ); return UNKNOWN; } // Construction of the post variable, a string with this form: // token1=<urlencoded data1>&token2=<urlencoded data2>&... char post[MAX_POST_IN_BYTES]; post[0] = '\0'; int token_num = 1; char *urlencoded_str = NULL; int i = 0; for ( i = 3; i < argc; i++ ) { if ( token_num > 999 ) { fprintf ( stderr, "Sorry, the limit number (999) of POST variables is exceeded.\n" ); curl_easy_cleanup ( curl ); return UNKNOWN; } //printf("token%d: [%s]\n", token_num, argv[i]); urlencoded_str = curl_easy_escape ( curl, argv[i], 0 ); // 10 is the max length of the string "token<num>=&". // The maximum is reached with "token999=&". int temp_size = 10 + strlen ( urlencoded_str ) + 1; char temp[temp_size]; sprintf ( temp, "token%d=%s&", token_num, urlencoded_str ); if ( strlen ( post ) + strlen ( temp ) + 1 < MAX_POST_IN_BYTES ) { strcat ( post, temp ); } else { fprintf ( stderr, "Sorry, the max POST size is exceeded.\n" ); curl_free ( urlencoded_str ); curl_easy_cleanup ( curl ); return UNKNOWN; } curl_free ( urlencoded_str ); token_num++; } // Remove the last character "&". post[strlen ( post ) - 1] = '\0'; //printf("POST [%s]\n", post); curl_easy_setopt ( curl, CURLOPT_URL, url ); curl_easy_setopt ( curl, CURLOPT_TIMEOUT, timeout ); curl_easy_setopt ( curl, CURLOPT_POSTFIELDS, post ); // Tell curl that we will receive data to the function write_data // which will write the data in "buf". Buffer buf; init_buffer ( &buf ); curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, write_data ); curl_easy_setopt ( curl, CURLOPT_WRITEDATA, &buf ); // Allow curl to perform the action. CURLcode ret; ret = curl_easy_perform ( curl ); if ( ret ) { if ( ret != CURLE_WRITE_ERROR || !is_filled ( &buf ) ) { curl_easy_cleanup ( curl ); fprintf ( stderr, "Sorry, exit value of curl_easy_perform is %d.", ret ); switch ( ret ) { case CURLE_COULDNT_RESOLVE_HOST: fprintf ( stderr, " Could not resolve the host address.\n" ); break; case CURLE_OPERATION_TIMEDOUT: fprintf ( stderr, " Operation timeout.\n" ); break; default: fprintf ( stderr, "\n" ); break; } return UNKNOWN; } } curl_easy_cleanup ( curl ); /* printf("----------------------------------\n"); printf("%s", buf.wr_buf); printf("----------------------------------\n"); */ int return_value; if ( !strncmp ( buf.wr_buf, "0\n", 2 ) ) { return_value = OK; } else if ( !strncmp ( buf.wr_buf, "1\n", 2 ) ) { return_value = WARNING; } else if ( !strncmp ( buf.wr_buf, "2\n", 2 ) ) { return_value = CRITICAL; } else if ( !strncmp ( buf.wr_buf, "3\n", 2 ) ) { return_value = UNKNOWN; } else { fprintf ( stderr, "Unexpected output of the plugin, return value not" ); fprintf ( stderr, " displayed or not in {0, 1, 2, 3}.\n" ); return UNKNOWN; } char *output = buf.wr_buf + 2; size_t len = strlen ( output ); if ( len > 0 && output[len - 1] == '\n' ) { printf ( "%s", output ); } else { printf ( "%s\n", output ); } return return_value; }
const double Contribution::guess_amount_of_profit() { if(is_filled()) return (((float)period)/365.25 * interest * summ / 100); return 0; }