int usermove(void) { int n; const char *const *p; char buf[256]; (void)printf("\nYour hand is:"); printhand(userhand); for (;;) { (void)printf("You ask me for: "); (void)fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) exit(0); if (buf[0] == '\0') continue; if (buf[0] == '\n') { (void)printf("%d cards in my hand, %d in the pool.\n", countcards(comphand), curcard); (void)printf("My books:"); (void)countbooks(comphand); continue; } buf[strlen(buf) - 1] = '\0'; if (!strcasecmp(buf, "p") && !promode) { promode = 1; (void)printf("Entering pro mode.\n"); continue; } if (!strcasecmp(buf, "quit")) exit(0); for (p = cards; *p; ++p) if (!strcasecmp(*p, buf)) break; if (!*p) { (void)printf("I don't understand!\n"); continue; } n = p - cards; if (userhand[n]) { userasked[n] = 1; return(n); } if (nrandom(3) == 1) (void)printf("You don't have any of those!\n"); else (void)printf("You don't have any %s's!\n", cards[n]); if (nrandom(4) == 1) (void)printf("No cheating!\n"); (void)printf("Guess again.\n"); } /* NOTREACHED */ }
int changedrivers(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE]; int configtype; int rc; int c; int needcards, sofarallocated, nictocheck, countofcards, toallocate; char *green = "GREEN"; char *orange = "ORANGE"; char *purple = "PURPLE"; char *red = "RED"; char *sections[6]; int choice; char nexteth[STRING_SIZE]; int abort; char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE]; char displaydriver[STRING_SIZE]; char cardinfo[STRING_SIZE]; char mac[STRING_SIZE]; int driverc = 0; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); runcommandwithstatus("/etc/rc.d/rc.netaddress.down", ctr[TR_PUSHING_NETWORK_DOWN]); /* Blank them so the rc.netaddress.up dosnt get confused. */ replacekeyvalue(kv, "GREEN_DEV", ""); replacekeyvalue(kv, "ORANGE_DEV", ""); replacekeyvalue(kv, "PURPLE_DEV", ""); replacekeyvalue(kv, "RED_DEV", ""); if (configtype == 0) needcards = 1; else if (configtype == 1 || configtype == 2 || configtype == 4) needcards = 2; else if (configtype == 3 || configtype == 5 || configtype == 6) needcards = 3; else needcards = 4; /* This is the green card. */ sofarallocated = 0; nictocheck = 0; countofcards = countcards(); strcpy(displaydriver, ""); strcpy(currentdriver, ""); abort = 0; driverc = 0; /* Keep going till all cards are got, or they give up. */ while (sofarallocated < needcards && !abort) { /* This is how many cards were added by the last module. */ toallocate = countofcards - nictocheck; while (!abort && toallocate > 0 && nictocheck < countofcards && sofarallocated < needcards) { findnicdescription(displaydriver, temp); /* Get device name, eth%d is hard coded. */ sprintf(nexteth, "eth%d", nictocheck); /* Get MAC address. */ if (getnicmac(mac, STRING_SIZE, nexteth)) /* If MAC found put at the end of NIC description. */ snprintf(cardinfo, STRING_SIZE, "%s [%s]", temp, mac); else /* MAC lookup failed so just display NIC description. */ snprintf(cardinfo, STRING_SIZE, "%s", temp); sprintf(message, ctr[TR_UNCLAIMED_DRIVER], cardinfo); c = 0; choice = 0; strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); if (CONFIG_TYPE_GREEN(configtype) &&!strlen(temp)) sections[c++] = green; strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); if (CONFIG_TYPE_ORANGE(configtype) && !strlen(temp)) sections[c++] = orange; strcpy(temp, ""); findkey(kv, "PURPLE_DEV", temp); if (CONFIG_TYPE_PURPLE(configtype) && !strlen(temp)) sections[c++] = purple; strcpy(temp, ""); findkey(kv, "RED_DEV", temp); if (CONFIG_TYPE_RED(configtype) && !strlen(temp)) sections[c++] = red; sections[c] = NULL; rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT], message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_SKIP], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { /* Now we see which iface needs its settings changed. */ if (strcmp(sections[choice], green) == 0) { replacekeyvalue(kv, "GREEN_DEV", nexteth); replacekeyvalue(kv, "GREEN_DRIVER", currentdriver); replacekeyvalue(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "GREEN_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], orange) == 0) { replacekeyvalue(kv, "ORANGE_DEV", nexteth); replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver); replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], purple) == 0) { replacekeyvalue(kv, "PURPLE_DEV", nexteth); replacekeyvalue(kv, "PURPLE_DRIVER", currentdriver); replacekeyvalue(kv, "PURPLE_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "PURPLE_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], red) == 0) { replacekeyvalue(kv, "RED_DEV", nexteth); replacekeyvalue(kv, "RED_DRIVER", currentdriver); replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } } else if (rc == 2) { nictocheck++; } else if (rc == 3) { // Cancelled? Then abort abort = 1; } // Reached the end of the cards? Abort if (nictocheck >= countofcards) abort=1; // Run out of cards to allocate? Abort if (toallocate == 0) abort=1; // Got enough cards? Break and finish if (sofarallocated == needcards) break; } } if (sofarallocated >= needcards) { newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK], ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]); } else errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); freekeyvalues(kv); netaddresschange = 1; return 1; }