static int ne_auth_creds_cb(__unused void *userdata, const char *realm, int attempt, char *u, char *p) { int r = -1; pthread_mutex_lock(&credential_mutex); if (attempt) { fprintf(stderr, "Authentication failure!\n"); free((void*) username); free((void*) password); username = password = NULL; } if (!username || !password) fprintf(stderr, "Realm '%s' requires authentication.\n", realm); if (!username) username = ask_user("Username", 0); if (username && !password) password = ask_user("Password", 1); if (username && password) { snprintf(u, NE_ABUFSIZ, "%s", username); snprintf(p, NE_ABUFSIZ, "%s", password); r = 0; } pthread_mutex_unlock(&credential_mutex); return r; }
/* * Fixes some needed current_th variables. */ static int init_thread_helper(void) { char name[NAME_MAX + 1] = {0}; int num = 1, len; if (current_th->type == ARCHIVER_TH) { ask_user(_(archiving_mesg), name, NAME_MAX); if (name[0] == 27) { free(current_th); current_th = NULL; return -1; } if (!strlen(name)) { strncpy(name, strrchr(selected[0], '/') + 1, NAME_MAX); } /* avoid overwriting a compressed file in path if it has the same name of the archive being created there */ len = strlen(name); strcat(name, ".tgz"); while (access(name, F_OK) == 0) { sprintf(name + len, "%d.tgz", num); num++; } snprintf(current_th->filename, PATH_MAX, "%s/%s", current_th->full_path, name); } current_th->selected_files = selected; selected = NULL; num_selected = 0; erase_selected_highlight(); return 0; }
int main(void) { t_size dims; int **tab; dims.size = ask_user(); if (dims.size == 0) { endwin(); ft_putendl("Thanks for playing !"); return (0); } clear(); tab = make_map(dims.size); initscr(); keypad(stdscr, TRUE); curs_set(0); noecho(); if (controllers(tab, dims.size, &dims) == 1) { endwin(); ft_putendl("Error, exiting with style."); return (0); } endwin(); return (0); }
void search(void) { ask_user(_(search_insert_name), sv.searched_string, 20); if (strlen(sv.searched_string) < 5 || sv.searched_string[0] == 27) { if (strlen(sv.searched_string) > 0 && sv.searched_string[0] != 27) { print_info(searched_string_minimum, ERR_LINE); } } else { char c; sv.found_cont = 0; sv.search_archive = 0; sv.search_lazy = 0; ask_user(_(search_archives), &c, 1); if (c == 27) { return; } if (c == _(yes)[0]) { sv.search_archive = 1; } /* * Don't ask user if he wants a lazy search * if he's searching a hidden file as * lazy search won't search hidden files. */ if (sv.searched_string[0] != '.') { ask_user(_(lazy_search), &c, 1); if (c == 27) { return; } if (c == _(yes)[0]) { sv.search_lazy = 1; } } sv.searching = SEARCHING; print_info("", SEARCH_LINE); pthread_create(&search_th, NULL, search_thread, NULL); } }
int main() try { f( 1, 2, 3); f(-1, 2, 3); f( 1,-2, 3); f(-1,-2, 3); f( 1, 2,-3); f(-1, 2,-3); f( 1,-2,-3); f(-1,-2,-3); char answer = ask_user("Have you read results?"); } catch (exception& e) { cerr << "error: " << e.what() << '\n'; return 1; } catch (...) { cerr << "Oops: unknown exception!\n"; return 2; }
int main(int argc, char **argv) { struct volume *v; int ch, yes = 0, reset = 0; while ((ch = getopt(argc, argv, "yr")) != -1) { switch(ch) { case 'y': yes = 1; break; case 'r': reset = 1; break; } } if (!yes && ask_user()) return -1; /* * TODO: Currently this only checks if kernel supports OverlayFS. We * should check if there is a mount point using it with rootfs_data * as upperdir. */ if (find_filesystem("overlay")) { ULOG_ERR("overlayfs not supported by kernel\n"); return -1; } v = volume_find("rootfs_data"); if (!v) { ULOG_ERR("MTD partition 'rootfs_data' not found\n"); return -1; } volume_init(v); if (!strcmp(*argv, "jffs2mark")) return jffs2_mark(v); return jffs2_reset(v, reset); }
void piece_move (piece_info_t *obj) { int changed_loc; int speed, max_hits; int saved_moves; int need_input; long saved_loc; city_info_t *cityp; /* set func for piece if on city */ cityp = find_city (obj->loc); if (cityp != NULL) if (cityp->func[obj->type] != NOFUNC) obj->func = cityp->func[obj->type]; changed_loc = FALSE; /* not changed yet */ speed = piece_attr[obj->type].speed; max_hits = piece_attr[obj->type].max_hits; need_input = FALSE; /* don't require user input yet */ while (obj->moved < obj_moves (obj)) { saved_moves = obj->moved; /* save moves made */ saved_loc = obj->loc; /* remember starting location */ if (awake (obj) || need_input){ /* need user input? */ ask_user (obj); display_loc_u (obj->loc); /* let user see result */ need_input = FALSE; /* we got it */ } if (obj->moved == saved_moves) /* user set function? */ switch (obj->func) { /* handle preprogrammed function */ case NOFUNC: break; case RANDOM: move_random (obj); break; case SENTRY: obj->moved = speed; break; case FILL: move_fill (obj); break; case LAND: move_land (obj); break; case EXPLORE: move_explore (obj); break; case ARMYLOAD: move_armyload (obj); break; case ARMYATTACK:move_armyattack (obj); break; case TTLOAD: move_ttload (obj); break; case REPAIR: move_repair (obj); break; case WFTRANSPORT: move_transport (obj); break; case MOVE_N: case MOVE_NE: case MOVE_E: case MOVE_SE: case MOVE_S: case MOVE_SW: case MOVE_W: case MOVE_NW: move_dir (obj); break; default: move_path (obj); break; } if (obj->moved == saved_moves) need_input = TRUE; /* * handle fighters specially. If in a city or carrier, turn * is over and reset range to max. Otherwise, if * range = 0, fighter crashes and burns and turn is over. */ if (obj->type == FIGHTER && obj->hits > 0) { if ((user_map[obj->loc].contents == 'O' || user_map[obj->loc].contents == 'C') && obj->moved > 0) { obj->range = piece_attr[FIGHTER].range; obj->moved = speed; obj->func = NOFUNC; info("Landing confirmed."); } else if (obj->range == 0) { info("Fighter at %d crashed and burned.", obj->loc); kill_obj (obj, obj->loc); } } if (saved_loc != obj->loc) changed_loc = TRUE; } /* if a boat is in port, damaged, and never moved, fix some damage */ if (obj->hits > 0 /* still alive? */ && !changed_loc /* object never changed location? */ && obj->type != ARMY && obj->type != FIGHTER /* it is a boat? */ && obj->hits < max_hits /* it is damaged? */ && user_map[obj->loc].contents == 'O') /* it is in port? */ obj->hits++; /* fix some damage */ }
int main() { string q = "Why is the sky blue?"; ask_user(q); }
int main(int argc, char *argv[]) { struct btrfs_root *root; unsigned ctree_flags = OPEN_CTREE_WRITES; int success = 0; int total = 0; int seeding_flag = 0; u64 seeding_value = 0; int random_fsid = 0; char *new_fsid_str = NULL; int ret; u64 super_flags = 0; while(1) { static const struct option long_options[] = { { "help", no_argument, NULL, GETOPT_VAL_HELP}, { NULL, 0, NULL, 0 } }; int c = getopt_long(argc, argv, "S:rxfuU:n", long_options, NULL); if (c < 0) break; switch(c) { case 'S': seeding_flag = 1; seeding_value = arg_strtou64(optarg); break; case 'r': super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF; break; case 'x': super_flags |= BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA; break; case 'n': super_flags |= BTRFS_FEATURE_INCOMPAT_NO_HOLES; break; case 'f': force = 1; break; case 'U': ctree_flags |= OPEN_CTREE_IGNORE_FSID_MISMATCH; new_fsid_str = optarg; break; case 'u': ctree_flags |= OPEN_CTREE_IGNORE_FSID_MISMATCH; random_fsid = 1; break; case GETOPT_VAL_HELP: default: print_usage(); return c != GETOPT_VAL_HELP; } } set_argv0(argv); device = argv[optind]; if (check_argc_exact(argc - optind, 1)) { print_usage(); return 1; } if (random_fsid && new_fsid_str) { error("random fsid can't be used with specified fsid"); return 1; } if (!super_flags && !seeding_flag && !(random_fsid || new_fsid_str)) { error("at least one option should be specified"); print_usage(); return 1; } if (new_fsid_str) { uuid_t tmp; ret = uuid_parse(new_fsid_str, tmp); if (ret < 0) { error("could not parse UUID: %s", new_fsid_str); return 1; } if (!test_uuid_unique(new_fsid_str)) { error("fsid %s is not unique", new_fsid_str); return 1; } } ret = check_mounted(device); if (ret < 0) { error("could not check mount status of %s: %s", device, strerror(-ret)); return 1; } else if (ret) { error("%s is mounted", device); return 1; } root = open_ctree(device, 0, ctree_flags); if (!root) { error("open ctree failed"); return 1; } if (seeding_flag) { if (!seeding_value && !force) { warning( "this is dangerous, clearing the seeding flag may cause the derived device not to be mountable!"); ret = ask_user("We are going to clear the seeding flag, are you sure?"); if (!ret) { fprintf(stderr, "Clear seeding flag canceled\n"); ret = 1; goto out; } } ret = update_seeding_flag(root, seeding_value); if (!ret) success++; total++; } if (super_flags) { ret = set_super_incompat_flags(root, super_flags); if (!ret) success++; total++; } if (random_fsid || new_fsid_str) { if (!force) { warning( "it's highly recommended to run 'btrfs check' before this operation"); warning( "also canceling running UUID change progress may cause corruption"); ret = ask_user("We are going to change UUID, are your sure?"); if (!ret) { fprintf(stderr, "UUID change canceled\n"); ret = 1; goto out; } } ret = change_uuid(root->fs_info, new_fsid_str); if (!ret) success++; total++; } if (success == total) { ret = 0; } else { root->fs_info->readonly = 1; ret = 1; error("btrfstune failed"); } out: close_ctree(root); btrfs_close_all_devices(); return ret; }
/* ** ** void init_search_pop(EVOLDATA ev, MATRIX fSearchPop, MATRIX fDC, MATRIX fLC) ** ** Initializes the search population with linearly feasible values. ** Asks the user for input if feasible values cannot be generated ** after NTRIES times. ** ** EVOLDATA ev - the main EVOLDATA block ** MATRIX fSearchPop - The search population matrix to be filled in ** MATRIX fDC - the domain constraint matrix ** MATRIX fLC - the linear constraints (inequalities) matrix ** */ void init_search_pop(EVOLDATA ev, MATRIX fSearchPop, MATRIX fDC, MATRIX fLC) { int iFlag, iDCFlag; int iPcount = 0; int iTries = 1; int i, j, k, iNumCopies; char ch; /***************************************************/ /* SINGLE point initalization */ /***************************************************/ if (ev.iSearchInitType == SINGLE) { iFlag = FALSE; iTries = 1; while ((iFlag == FALSE) && (iTries <= NTRIES)) { /* generate random numbers based on the domain constraints */ for (j=1; j<=ev.iNumVars; j++) { iDCFlag = FALSE; /* check if there is a DC for the variable */ for (k=1; k<=ev.iNumDC; k++) if (j==(int)fDC[k][2]) { fSearchPop[1][j] = randgen(fDC[k][1], fDC[k][3]); iDCFlag = TRUE; } /* if no DC, generate values between limits */ if (iDCFlag == FALSE) fSearchPop[1][j] = randgen(MINNUM, MAXNUM); } /* end of j loop*/ /* now, check for feasibility wrt. linear inequalities */ iFlag = check_LC(ev, fSearchPop[1], fLC, fDC); iTries++; } /* end of while */ /* if generation failed after NTRIES times, ask user for input */ if (iTries > NTRIES) { printf("\nSearch Population : Single Point Initialization.\n"); printf("Couldn't find a feasible vector in %d tries.\n", NTRIES); iFlag = FALSE; while (iFlag == FALSE) { ask_user(fSearchPop[1], ev.iNumVars); iFlag = check_LC(ev, fSearchPop[1], fLC, fDC); }; }; /* ** now, we've got a valid vector. Copy it into the entire ** search population. */ for (i=2; i<=ev.iSearchPopSize; i++) for (j=1; j<=ev.iNumVars; j++) fSearchPop[i][j] = fSearchPop[1][j]; } /* end of if SINGLE */ else /***************************************************/ /* MULTIPLE point initalization */ /***************************************************/ { iPcount = 1; while (iPcount<=ev.iSearchPopSize) { iFlag = FALSE; iTries = 1; while ((iFlag == FALSE) && (iTries <= NTRIES)) { /* generate random numbers based on the domain constraints */ for (j=1; j<=ev.iNumVars; j++) { iDCFlag = FALSE; /* check if there is a DC for the variable */ for (k=1; k<=ev.iNumDC; k++) if (j==(int)fDC[k][2]) { fSearchPop[iPcount][j] = randgen(fDC[k][1], fDC[k][3]); iDCFlag = TRUE; } /* if no DC, generate values between limits */ if (iDCFlag == FALSE) fSearchPop[iPcount][j] = randgen(MINNUM, MAXNUM); } /* end of j loop*/ /* now, check for feasibility wrt. linear inequalities */ iFlag = check_LC(ev, fSearchPop[iPcount], fLC, fDC); iTries++; } /* end of while */ /* if we got a valid vector, fine :) otherwise, beg user :( */ if (iFlag == TRUE) iPcount++; else /* if generation failed after NTRIES times, ask user for input */ if (iTries > NTRIES) { printf("\nSearch Population : Multiple Point Initialization.\n"); printf("Couldn't find a feasible vector in %d tries.\n", NTRIES); iFlag = FALSE; while (iFlag == FALSE) { ask_user(fSearchPop[iPcount], ev.iNumVars); iFlag = check_LC(ev, fSearchPop[iPcount], fLC, fDC); }; /* ask if user wishes to duplicate */ printf("Valid vector: Duplicate? (Y/N) :"); fflush(stdin); ch = getchar(); if ((ch == 'y') || (ch == 'Y')) { iNumCopies = 0; /* make sure user inputs value */ do { printf("\nNo of copies (1 to %d) : ", ev.iSearchPopSize - iPcount+1); scanf_s("%d", &iNumCopies); } while ((iNumCopies < 1) || (iNumCopies > (ev.iSearchPopSize-iPcount+1))); /* END of while input validation */ /* now, copy vectors till iNumCopies */ for (i=1; i<iNumCopies; i++) { for (j=1; j<=ev.iNumVars; j++) { fSearchPop[iPcount+1][j] = fSearchPop[iPcount][j]; } iPcount++; } iPcount++; } /* END of block where user requests duplication */ }; /* END of if tries exhausted */ }; /* END of iPcount <= iSearchPopSize */ } /* end of MULTIPLE point initialization */ }