void set_variants_from_options(void) { int which; const char *varname; Obj *varrest, *varset; /* Only the host of a networked game can set variants. */ if (option_game_to_join != NULL) { if (variant_settings != lispnil || option_width > 0) fprintf(stderr, "Not the host, ignoring variant settings\n"); return; } if (option_width > 0) { which = find_variant_from_name(mainmodule, keyword_name(K_WORLD_SIZE)); if (which >= 0) net_set_variant_value(which, option_width, option_height, option_circumference); else fprintf(stderr, "World size variant not available, -M ignored\n"); } /* Set the real-time variant if any times were supplied. */ if (option_total_game_time != 0 || option_per_side_time != 0 || option_per_turn_time != 0) { which = find_variant_from_name(mainmodule, keyword_name(K_REAL_TIME)); if (which >= 0) net_set_variant_value(which, option_total_game_time, option_per_side_time, option_per_turn_time); else fprintf(stderr, "Real time variants not available, ignored\n"); } for_all_list(variant_settings, varrest) { varset = car(varrest); varname = c_string(car(varset)); which = find_variant_from_name(mainmodule, varname); if (which >= 0) net_set_variant_value(which, c_number(cadr(varset)), 0, 0); else fprintf(stderr, "No variant `%s' known, ignored\n", varname); }
unsigned int parser_loose_enum_arg(struct keyword *k, const char *s, char **rest) { struct keyword_def *kd = k->keydef; int kevcount; const struct keyword_enum_value *kev; unsigned int valresult; assert(kd->type == kt_loose_enum || kd->type == kt_loose_enumarg || kd->type == kt_rsakey); assert(kd->validenum != NULL && kd->validenum->values != NULL); if(kd->deliminator != '\0') { char *nl = strchr(s, kd->deliminator); if(nl) { *nl='\0'; nl++; if(rest) *rest = nl; } } for(kevcount = kd->validenum->valuesize, kev = kd->validenum->values; kevcount > 0 && strcasecmp(s, kev->name)!=0; kev++, kevcount--); /* if we found something */ if(kevcount != 0) { assert(kev->value != 0); valresult = kev->value; k->string = NULL; return valresult; } #ifdef KEYWORD_PARSE_DEBUG { char kdtypebuf[KEYWORD_NAME_BUFLEN]; fprintf(stderr, "loose enum(%s) for %s is %d\n", s, keyword_name(&kt_values_list, kd->type, kdtypebuf), kd->loose_enum_value); } #endif /* else, it's a literal other value */ k->string = strdup(s); return kd->loose_enum_value; }