int main(void) { bool win = FALSE; int move, max_moves; int player; print_instructions(); max_moves = DIM * DIM; /* Maximum number of moves in a game */ while (TRUE) { initialize_board(); for (move = 1; move <= max_moves; move++) { player = move % 2 == 0 ? 2 : 1; win = do_move(player); print_board(); if (win) { printf("Player %d, you WON!\n\n", player); break; /* out of for loop */ } } /* * If we got here by falling through the loop, then it is a * tie game. */ if (!win) printf("Tie Game!\n\n"); if (!ask_yesno("Do you wish to play again?")) break; /* out of while loop */ } return 0; }
static void exec_cmd_ask(const char *iaskstr, const char *iactstr, const char *icmdstr, ...) { char *askstr, *actstr, *cmdstr; va_list ap; va_start(ap, icmdstr); if (vasprintf(&askstr, iaskstr, ap) < 0) { endwin(); err(EXIT_FAILURE, "asprintf"); } va_end(ap); va_start(ap, icmdstr); if (vasprintf(&actstr, iactstr, ap) < 0) { endwin(); err(EXIT_FAILURE, "asprintf"); } va_end(ap); va_start(ap, icmdstr); if (vasprintf(&cmdstr, icmdstr, ap) < 0) { endwin(); err(EXIT_FAILURE, "asprintf"); } va_end(ap); if (ask_yesno(askstr)) exec_cmd_noask(actstr, cmdstr); free(askstr); free(actstr); free(cmdstr); return; }
/* * any additional partition validation */ int md_check_partitions(void) { /* X68k partitions must be in order of the range. */ int part, last = PART_A-1; uint32_t start = 0; for (part = PART_A; part < 8; part++) { if (part == PART_C) continue; if (last >= PART_A && pm->bsdlabel[part].pi_size > 0) { msg_display(MSG_emptypart, part+'a'); process_menu(MENU_ok, NULL); return 0; } if (pm->bsdlabel[part].pi_size == 0) { if (last < PART_A) last = part; } else { if (start >= pm->bsdlabel[part].pi_offset) { msg_display(MSG_ordering, part+'a'); if (ask_yesno(NULL)) return 0; } start = pm->bsdlabel[part].pi_offset; } } return 1; }
int md_check_mbr(mbr_info_t *mbri) { mbr_info_t *ext; struct mbr_partition *part; int i, hasboot=0; if (boardtype == BOARD_TYPE_NORMAL) return 2; /* raspi code */ if (boardtype == BOARD_TYPE_RPI) { for (ext = mbri; ext; ext = ext->extended) { part = ext->mbr.mbr_parts; for (i=0, hasboot=0; i < MBR_PART_COUNT; part++, i++) { if (part->mbrp_type != MBR_PTYPE_FAT16L && part->mbrp_type != MBR_PTYPE_FAT32L) continue; hasboot = 1; break; } } if (!hasboot) { msg_display(MSG_nomsdospart); msg_display_add(MSG_reeditpart, 0); if (!ask_yesno(NULL)) return 0; return 1; } } return 2; }
static void ask_exit(void) { if (ask_yesno("Exit pkgui?")) { attroff(COLOR_PAIR(1)); endwin(); exit(0); } return; }
/* * Check a disklabel. * If there are overlapping active partitions, * Ask the user if they want to edit the partition or give up. */ int edit_and_check_label(partinfo *lp, int nparts, int rawpart, int bsdpart) { static struct menu_ent *menu; static int menu_no = -1; static struct ptn_menu_info pi; int maxpart = getmaxpartitions(); if (menu == NULL) { menu = malloc((maxpart + 1) * sizeof *menu); if (!menu) return 1; } if (menu_no == -1) { menu_no = new_menu(NULL, menu, maxpart + 1, 0, -1, maxpart + 2, 74, MC_ALWAYS_SCROLL | MC_NOBOX | MC_DFLTEXIT, set_label_texts, fmt_fspart, NULL, NULL, MSG_partition_sizes_ok); } if (menu_no < 0) return 1; pi.flags = 0; pm->current_cylsize = pm->dlcylsize; for (;;) { /* first give the user the option to edit the label... */ process_menu(menu_no, &pi); /* User thinks the label is OK. */ /* check we have a single root fs */ if (check_one_root(lp, nparts) == 0 && partman_go == 0) msg_display(MSG_must_be_one_root); else /* Check for overlaps */ if (checkoverlap(lp, nparts, rawpart, bsdpart) == 0) return 1; /*XXX ???*/ msg_display_add(MSG_edit_partitions_again); if (!ask_yesno(NULL)) return(0); } /*NOTREACHED*/ }
void CommandConversationConference::execute_s() { CConversation::Ref conversation = skype->get_current_conversation(); if (conversation) { List_String participants; bool temp = true; while (temp) { participants.push_back(ask("Add participant:")); temp = (ask_yesno("Add another?") == 0); } Conversation::Ref conference; conversation->SpawnConference(participants, conference); if (conference) skype->set_current_conversation(conference); } }
static void goonordie(mmv_t *mmv) { if ((mmv->paterr || mmv->badreps) && mmv->nreps > 0) { eprint("Not everything specified can be done."); if (mmv->badstyle == ABORTBAD) { eprint(" Aborting.\n"); exit(1); } else if (mmv->badstyle == SKIPBAD) { eprint(" Proceeding with the rest.\n"); } else if (!ask_yesno(" Proceed with the rest? ", -1)) { exit(1); } } }
void CommandConversationConference::execute_p() { Conversation::Ref conversation = skype->get_current_conversation(); if (conversation) { Conversation::TYPE ctype; conversation->GetPropType(ctype); if (ctype == Conversation::DIALOG) { printf("Conversation is not a conference, choose 'ms - spawn a conf' instead\n"); return; } List_String participants; bool temp = true; while (temp) { participants.push_back(ask("Add participant:")); temp = (ask_yesno("Add another?") == 0); } conversation->AddConsumers(participants); } }
int config_dhcp(char *inter) { int dhcpautoconf; /* * Don't bother checking for an existing instance of dhcpcd, just * ask it to renew the lease. It will fork and daemonize if there * wasn't already an instance. */ if (!file_mode_match(DHCPCD, S_IFREG)) return 0; if (ask_yesno(MSG_Perform_autoconfiguration)) { /* spawn off dhcpcd and wait for parent to exit */ dhcpautoconf = run_program(RUN_DISPLAY | RUN_PROGRESS, "%s -d -n %s", DHCPCD, inter); return dhcpautoconf ? 0 : 1; } return 0; }
static int skipdel(mmv_t *mmv, REP *p) { if (p->r_flags & R_DELOK) { return (0); } eprintf("%s%s -> %s%s : ", p->r_hfrom->h_name, p->r_ffrom->fi_name, p->r_hto->h_name, p->r_nto); if (!fwritable(mmv, p->r_hto->h_name, p->r_fdel)) { eprintf("old %s%s lacks write permission. delete it", p->r_hto->h_name, p->r_nto); } else { eprintf("%s old %s%s", (mmv->op & OVERWRITE) ? "overwrite" : "delete", p->r_hto->h_name, p->r_nto); } return (!ask_yesno("? ", -1)); }
static int snap(mmv_t *mmv, REP *first, REP *p) { char fname[PATH_MAX]; int redirected = 0; if (mmv->noex) { exit(1); } mmv->failed = 1; signal(SIGINT, breakstat); if (mmv->badstyle == ASKBAD && isatty(fileno(stdout)) && ask_yesno("Redirect standard output to file? ", 0)) { redirected = 1; umask(mmv->oldumask); while (true) { int err; mmv->outfile = ask_filename("File name> ", fname, sizeof (fname)); if (mmv->outfile != NULL) { break; } err = errno; eprint("open('"); eprint_filename(fname); eprint("') failed.\n"); eexplain_err(err); } } if (redirected || !mmv->verbose) { show_done_all(mmv, p); } fprintf(mmv->outfile, "The following left undone:\n"); mmv->noex = 1; return (first != p); }
static int handle_license(const char *dev) { static struct { const char *dev; const char *lic; } licdev[] = { { "iwi", "/libdata/firmware/if_iwi/LICENSE.ipw2200-fw" }, { "ipw", "/libdata/firmware/if_ipw/LICENSE" }, }; size_t i; for (i = 0; i < __arraycount(licdev); i++) if (strncmp(dev, licdev[i].dev, 3) == 0) { char buf[64]; int val; size_t len = sizeof(int); (void)snprintf(buf, sizeof(buf), "hw.%s.accept_eula", licdev[i].dev); if (sysctlbyname(buf, &val, &len, NULL, 0) != -1 && val != 0) return 1; msg_display(MSG_license, dev, licdev[i].lic); if (ask_yesno(NULL)) { val = 1; if (sysctlbyname(buf, NULL, NULL, &val, 0) == -1) return 0; add_sysctl_conf("%s=1", buf); return 1; } else return 0; } return 1; }
/* * Get the information to configure the network, configure it and * make sure both the gateway and the name server are up. */ int config_network(void) { char *textbuf; int octet0; int dhcp_config; int nfs_root = 0; int slip = 0; int pid, status; char **ap, *slcmd[10], *in_buf; char buffer[STRSIZE]; struct statvfs sb; struct net_desc net_devs[MAX_NETS]; menu_ent net_menu[5]; int menu_no; int num_devs; int selected_net; int i; #ifdef INET6 int v6config = 1, rv; #endif FILE *f; time_t now; if (network_up) return (1); num_devs = get_ifconfig_info(net_devs); if (num_devs < 1) { /* No network interfaces found! */ msg_display(MSG_nonet); process_menu(MENU_ok, NULL); return (-1); } for (i = 0; i < num_devs; i++) { net_menu[i].opt_name = net_devs[i].if_dev; net_menu[i].opt_menu = OPT_NOMENU; net_menu[i].opt_flags = OPT_EXIT; net_menu[i].opt_action = set_menu_select; } again: selected_net = -1; menu_no = new_menu(MSG_netdevs, net_menu, num_devs, -1, 4, 0, 0, MC_SCROLL, NULL, NULL, NULL, NULL, NULL); msg_display(MSG_asknetdev, ""); process_menu(menu_no, &selected_net); free_menu(menu_no); if (selected_net == -1) return 0; network_up = 1; dhcp_config = 0; strncpy(net_dev, net_devs[selected_net].if_dev, STRSIZE); if (!handle_license(net_dev)) goto done; slip = net_dev[0] == 's' && net_dev[1] == 'l' && isdigit((unsigned char)net_dev[2]); /* If root is on NFS do not reconfigure the interface. */ if (statvfs("/", &sb) == 0 && strcmp(sb.f_fstypename, "nfs") == 0) { nfs_root = 1; get_ifinterface_info(); get_if6interface_info(); get_host_info(); } else if (!slip) { /* Preload any defaults we can find */ get_ifinterface_info(); get_if6interface_info(); get_host_info(); /* domain and host */ msg_display(MSG_netinfo); /* ethernet medium */ for (;;) { msg_prompt_add(MSG_net_media, net_media, net_media, sizeof net_media); /* * ifconfig does not allow media specifiers on * IFM_MANUAL interfaces. Our UI gives no way * to set an option back * to null-string if it gets accidentally set. * Check for plausible alternatives. */ if (strcmp(net_media, "<default>") == 0 || strcmp(net_media, "default") == 0 || strcmp(net_media, "<manual>") == 0 || strcmp(net_media, "manual") == 0 || strcmp(net_media, "<none>") == 0 || strcmp(net_media, "none") == 0 || strcmp(net_media, " ") == 0) { *net_media = '\0'; } if (*net_media == '\0') break; /* * We must set the media type here - to give dhcp * a chance */ if (run_program(0, "/sbin/ifconfig %s media %s", net_dev, net_media) == 0) break; /* Failed to set - output the supported values */ if (collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -m %s |" "while IFS=; read line;" " do [ \"$line\" = \"${line#*media}\" ] || " "echo $line;" " done", net_dev ) > 0) msg_display(textbuf); free(textbuf); } net_dhcpconf = 0; /* try a dhcp configuration */ dhcp_config = config_dhcp(net_dev); if (dhcp_config) { char *nline; /* Get newly configured data off interface. */ get_ifinterface_info(); get_if6interface_info(); get_host_info(); net_dhcpconf |= DHCPCONF_IPADDR; /* * Extract default route from output of * 'route -n show' */ if (collect(T_OUTPUT, &textbuf, "/sbin/route -n show | " "while read dest gateway flags;" " do [ \"$dest\" = default ] && {" " echo \"$gateway\"; break; };" " done" ) > 0) strlcpy(net_defroute, textbuf, sizeof net_defroute); free(textbuf); if ((nline = strchr(net_defroute, '\n'))) *nline = '\0'; /* pull nameserver info out of /etc/resolv.conf */ if (collect(T_OUTPUT, &textbuf, "cat /etc/resolv.conf 2>/dev/null |" " while read keyword address rest;" " do [ \"$keyword\" = nameserver ] &&" " { echo \"$address\"; break; };" " done" ) > 0) strlcpy(net_namesvr, textbuf, sizeof net_namesvr); free(textbuf); if ((nline = strchr(net_namesvr, '\n'))) *nline = '\0'; if (net_namesvr[0] != '\0') net_dhcpconf |= DHCPCONF_NAMESVR; /* pull domain info out of /etc/resolv.conf */ if (collect(T_OUTPUT, &textbuf, "cat /etc/resolv.conf 2>/dev/null |" " while read keyword domain rest;" " do [ \"$keyword\" = domain ] &&" " { echo \"$domain\"; break; };" " done" ) > 0) strlcpy(net_domain, textbuf, sizeof net_domain); free(textbuf); if (net_domain[0] == '\0') { /* pull domain info out of /etc/resolv.conf */ if (collect(T_OUTPUT, &textbuf, "cat /etc/resolv.conf 2>/dev/null |" " while read keyword search rest;" " do [ \"$keyword\" = search ] &&" " { echo \"$search\"; break; };" " done" ) > 0) strlcpy(net_domain, textbuf, sizeof net_domain); free(textbuf); } if ((nline = strchr(net_domain, '\n'))) *nline = '\0'; if (net_domain[0] != '\0') net_dhcpconf |= DHCPCONF_DOMAIN; if (gethostname(net_host, sizeof(net_host)) == 0 && net_host[0] != 0) net_dhcpconf |= DHCPCONF_HOST; } } if (!(net_dhcpconf & DHCPCONF_HOST)) msg_prompt_add(MSG_net_host, net_host, net_host, sizeof net_host); if (!(net_dhcpconf & DHCPCONF_DOMAIN)) msg_prompt_add(MSG_net_domain, net_domain, net_domain, sizeof net_domain); if (!dhcp_config) { /* Manually configure IPv4 */ if (!nfs_root) msg_prompt_add(MSG_net_ip, net_ip, net_ip, sizeof net_ip); if (slip) msg_prompt_add(MSG_net_srv_ip, net_srv_ip, net_srv_ip, sizeof net_srv_ip); else if (!nfs_root) { /* We don't want netmasks for SLIP */ octet0 = atoi(net_ip); if (!net_mask[0]) { if (0 <= octet0 && octet0 <= 127) strlcpy(net_mask, "0xff000000", sizeof(net_mask)); else if (128 <= octet0 && octet0 <= 191) strlcpy(net_mask, "0xffff0000", sizeof(net_mask)); else if (192 <= octet0 && octet0 <= 223) strlcpy(net_mask, "0xffffff00", sizeof(net_mask)); } msg_prompt_add(MSG_net_mask, net_mask, net_mask, sizeof net_mask); } msg_prompt_add(MSG_net_defroute, net_defroute, net_defroute, sizeof net_defroute); } if (!(net_dhcpconf & DHCPCONF_NAMESVR)) { #ifdef INET6 if (v6config) { rv = 0; process_menu(MENU_namesrv6, &rv); if (!rv) msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr, sizeof net_namesvr); } else #endif msg_prompt_add(MSG_net_namesrv, net_namesvr, net_namesvr, sizeof net_namesvr); } /* confirm the setting */ if (slip) msg_display(MSG_netok_slip, net_domain, net_host, *net_namesvr == '\0' ? "<none>" : net_namesvr, net_dev, *net_media == '\0' ? "<default>" : net_media, *net_ip == '\0' ? "<none>" : net_ip, *net_srv_ip == '\0' ? "<none>" : net_srv_ip, *net_mask == '\0' ? "<none>" : net_mask, *net_defroute == '\0' ? "<none>" : net_defroute); else msg_display(MSG_netok, net_domain, net_host, *net_namesvr == '\0' ? "<none>" : net_namesvr, net_dev, *net_media == '\0' ? "<default>" : net_media, *net_ip == '\0' ? "<none>" : net_ip, *net_mask == '\0' ? "<none>" : net_mask, *net_defroute == '\0' ? "<none>" : net_defroute); #ifdef INET6 msg_display_add(MSG_netokv6, !is_v6kernel() ? "<not supported>" : net_ip6); #endif done: if (!ask_yesno(MSG_netok_ok)) goto again; run_program(0, "/sbin/ifconfig lo0 127.0.0.1"); /* dhcpcd will have configured it all for us */ if (dhcp_config) { fflush(NULL); network_up = 1; return network_up; } /* * we may want to perform checks against inconsistent configuration, * like IPv4 DNS server without IPv4 configuration. */ /* Create /etc/resolv.conf if a nameserver was given */ if (net_namesvr[0] != '\0') { f = fopen("/etc/resolv.conf", "w"); if (f == NULL) { if (logfp) (void)fprintf(logfp, "%s", msg_string(MSG_resolv)); (void)fprintf(stderr, "%s", msg_string(MSG_resolv)); exit(1); } scripting_fprintf(NULL, "cat <<EOF >/etc/resolv.conf\n"); time(&now); scripting_fprintf(f, ";\n; BIND data file\n; %s %s;\n", "Created by NetBSD sysinst on", safectime(&now)); if (net_domain[0] != '\0') scripting_fprintf(f, "search %s\n", net_domain); if (net_namesvr[0] != '\0') scripting_fprintf(f, "nameserver %s\n", net_namesvr); scripting_fprintf(NULL, "EOF\n"); fflush(NULL); fclose(f); } if (net_ip[0] != '\0') { if (slip) { /* XXX: needs 'ifconfig sl0 create' much earlier */ /* Set SLIP interface UP */ run_program(0, "/sbin/ifconfig %s inet %s %s up", net_dev, net_ip, net_srv_ip); strcpy(sl_flags, "-s 115200 -l /dev/tty00"); msg_prompt_win(MSG_slattach, -1, 12, 70, 0, sl_flags, sl_flags, 255); /* XXX: wtf isn't run_program() used here? */ pid = fork(); if (pid == 0) { strcpy(buffer, "/sbin/slattach "); strcat(buffer, sl_flags); in_buf = buffer; for (ap = slcmd; (*ap = strsep(&in_buf, " ")) != NULL;) if (**ap != '\0') ++ap; execvp(slcmd[0], slcmd); } else wait4(pid, &status, WNOHANG, 0); } else if (!nfs_root) { if (net_mask[0] != '\0') { run_program(0, "/sbin/ifconfig %s inet %s netmask %s", net_dev, net_ip, net_mask); } else { run_program(0, "/sbin/ifconfig %s inet %s", net_dev, net_ip); } } } /* Set host name */ if (net_host[0] != '\0') sethostname(net_host, strlen(net_host)); /* Set a default route if one was given */ if (!nfs_root && net_defroute[0] != '\0') { run_program(RUN_DISPLAY | RUN_PROGRESS, "/sbin/route -n flush -inet"); run_program(RUN_DISPLAY | RUN_PROGRESS, "/sbin/route -n add default %s", net_defroute); } /* * wait a couple of seconds for the interface to go live. */ if (!nfs_root) { msg_display_add(MSG_wait_network); sleep(5); } /* * ping should be verbose, so users can see the cause * of a network failure. */ if (net_defroute[0] != '\0' && network_up) network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS, "/sbin/ping -v -c 5 -w 5 -o -n %s", net_defroute); if (net_namesvr[0] != '\0' && network_up) { #ifdef INET6 if (strchr(net_namesvr, ':')) network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS, "/sbin/ping6 -v -c 3 -n %s", net_namesvr); else #endif network_up = !run_program(RUN_DISPLAY | RUN_PROGRESS, "/sbin/ping -v -c 5 -w 5 -o -n %s", net_namesvr); } fflush(NULL); return network_up; }
/* * Write the network config info the user entered via menus into the * config files in the target disk. Be careful not to lose any * information we don't immediately add back, in case the install * target is the currently-active root. */ void mnt_net_config(void) { char ifconfig_fn[STRSIZE]; FILE *ifconf = NULL; if (!network_up) return; if (!ask_yesno(MSG_mntnetconfig)) return; /* Write hostname to /etc/rc.conf */ if ((net_dhcpconf & DHCPCONF_HOST) == 0) if (del_rc_conf("hostname") == 0) add_rc_conf("hostname=%s\n", recombine_host_domain()); /* Copy resolv.conf to target. If DHCP was used to create it, * it will be replaced on next boot anyway. */ if (net_namesvr[0] != '\0') dup_file_into_target("/etc/resolv.conf"); /* * bring the interface up, it will be necessary for IPv6, and * it won't make trouble with IPv4 case either */ snprintf(ifconfig_fn, sizeof ifconfig_fn, "/etc/ifconfig.%s", net_dev); ifconf = target_fopen(ifconfig_fn, "w"); if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); scripting_fprintf(ifconf, "up\n"); if (*net_media != '\0') scripting_fprintf(ifconf, "media %s\n", net_media); scripting_fprintf(NULL, "EOF\n"); } if ((net_dhcpconf & DHCPCONF_IPADDR) == 0) { FILE *hosts; /* Write IPaddr and netmask to /etc/ifconfig.if[0-9] */ if (ifconf != NULL) { scripting_fprintf(NULL, "cat <<EOF >>%s%s\n", target_prefix(), ifconfig_fn); if (*net_media != '\0') scripting_fprintf(ifconf, "%s netmask %s media %s\n", net_ip, net_mask, net_media); else scripting_fprintf(ifconf, "%s netmask %s\n", net_ip, net_mask); scripting_fprintf(NULL, "EOF\n"); } /* * Add IPaddr/hostname to /etc/hosts. * Be careful not to clobber any existing contents. * Relies on ordered search of /etc/hosts. XXX YP? */ hosts = target_fopen("/etc/hosts", "a"); if (hosts != 0) { scripting_fprintf(NULL, "cat <<EOF >>%s/etc/hosts\n", target_prefix()); write_etc_hosts(hosts); (void)fclose(hosts); scripting_fprintf(NULL, "EOF\n"); } if (del_rc_conf("defaultroute") == 0) add_rc_conf("defaultroute=\"%s\"\n", net_defroute); } else { /* * Start dhcpcd quietly and in master mode, but restrict * it to our interface */ add_rc_conf("dhcpcd=YES\n"); add_rc_conf("dhcpcd_flags=\"-qM %s\"\n", net_dev); } if (ifconf) fclose(ifconf); fflush(NULL); }