static int get_option_count(const option_guide *guide, const char *optspec) { struct OptionRange ranges[128]; int count = 0, i; option_resolution_listranges(optspec, guide->parameter, ranges, ARRAY_LENGTH(ranges)); for (i = 0; ranges[i].min >= 0; i++) count += ranges[i].max - ranges[i].min + 1; return count; }
optreserr_t option_resolution_isvalidvalue(const char *specification, int option_char, int val) { optreserr_t err; struct OptionRange ranges[256]; int i; err = option_resolution_listranges(specification, option_char, ranges, ARRAY_LENGTH(ranges)); if (err) return err; for (i = 0; (ranges[i].min >= 0) && (ranges[i].max >= 0); i++) { if ((ranges[i].min <= val) && (ranges[i].max >= val)) return OPTIONRESOLUTION_ERROR_SUCCESS; } return OPTIONRESOLUTION_ERROR_PARAMOUTOFRANGE; }
BOOL win_adjust_option_control(HWND control, int delta) { const option_guide *guide; const char *optspec; struct OptionRange ranges[128]; char buf[64]; int val, original_val, i; BOOL changed = FALSE; guide = (const option_guide *) GetProp(control, guide_prop); optspec = (const char *) GetProp(control, spec_prop); assert(guide->option_type == OPTIONTYPE_INT); if (delta == 0) return TRUE; option_resolution_listranges(optspec, guide->parameter, ranges, ARRAY_LENGTH(ranges)); win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf)); original_val = atoi(buf); val = original_val + delta; for (i = 0; ranges[i].min >= 0; i++) { if (ranges[i].min > val) { if ((delta < 0) && (i > 0)) val = ranges[i-1].max; else val = ranges[i].min; changed = TRUE; break; } } if (!changed && (i > 0) && (ranges[i-1].max < val)) val = ranges[i-1].max; if (val != original_val) { _snprintf(buf, ARRAY_LENGTH(buf), "%d", val); win_set_window_text_utf8(control, buf); } return TRUE; }
static void listoptions(const option_guide *opt_guide, const char *opt_spec) { char opt_name[32]; const char *opt_desc; struct OptionRange range[32]; char range_buffer[512]; char buf[32]; int i; assert(opt_guide); fprintf(stdout, "Option Allowed values Description\n"); fprintf(stdout, "---------------- ------------------------------ -----------\n"); while(opt_guide->option_type != OPTIONTYPE_END) { range_buffer[0] = 0; snprintf(opt_name, ARRAY_LENGTH(opt_name), "--%s", opt_guide->identifier); opt_desc = opt_guide->display_name; /* is this option relevant? */ if (!strchr(opt_spec, opt_guide->parameter)) { opt_guide++; continue; } switch(opt_guide->option_type) { case OPTIONTYPE_INT: option_resolution_listranges(opt_spec, opt_guide->parameter, range, ARRAY_LENGTH(range)); for (i = 0; range[i].max >= 0; i++) { if (range[i].min == range[i].max) snprintf(buf, ARRAY_LENGTH(buf), "%i", range[i].min); else snprintf(buf, ARRAY_LENGTH(buf), "%i-%i", range[i].min, range[i].max); if (i > 0) strncatz(range_buffer, "/", sizeof(range_buffer)); strncatz(range_buffer, buf, sizeof(range_buffer)); } break; case OPTIONTYPE_ENUM_BEGIN: i = 0; while(opt_guide[1].option_type == OPTIONTYPE_ENUM_VALUE) { if (i > 0) strncatz(range_buffer, "/", sizeof(range_buffer)); strncatz(range_buffer, opt_guide[1].identifier, sizeof(range_buffer)); opt_guide++; i++; } break; case OPTIONTYPE_STRING: snprintf(range_buffer, sizeof(range_buffer), "(string)"); break; default: assert(0); break; } fprintf(stdout, "%16s %-30s %s\n", opt_name, range_buffer, opt_desc); opt_guide++; } }
static BOOL prepare_combobox(HWND control, const option_guide *guide, const char *optspec) { struct OptionRange ranges[128]; int default_value, default_index, current_index, option_count; int i, j, k; BOOL has_option; TCHAR buf1[256]; TCHAR buf2[256]; LPTSTR tempstr; SendMessage(control, CB_GETLBTEXT, SendMessage(control, CB_GETCURSEL, 0, 0), (LPARAM) buf1); SendMessage(control, CB_RESETCONTENT, 0, 0); has_option = guide && optspec; if (has_option) { if ((guide->option_type != OPTIONTYPE_INT) && (guide->option_type != OPTIONTYPE_ENUM_BEGIN)) goto unexpected; option_resolution_listranges(optspec, guide->parameter, ranges, ARRAY_LENGTH(ranges)); option_resolution_getdefault(optspec, guide->parameter, &default_value); option_count = 0; default_index = -1; current_index = -1; for (i = 0; ranges[i].min >= 0; i++) { for (j = ranges[i].min; j <= ranges[i].max; j++) { if (guide->option_type == OPTIONTYPE_INT) { _sntprintf(buf2, ARRAY_LENGTH(buf2), TEXT("%d"), j); SendMessage(control, CB_ADDSTRING, 0, (LPARAM) buf2); } else if (guide->option_type == OPTIONTYPE_ENUM_BEGIN) { for (k = 1; guide[k].option_type == OPTIONTYPE_ENUM_VALUE; k++) { if (guide[k].parameter == j) break; } if (guide[k].option_type != OPTIONTYPE_ENUM_VALUE) goto unexpected; tempstr = tstring_from_utf8(guide[k].display_name); SendMessage(control, CB_ADDSTRING, 0, (LPARAM) tempstr); osd_free(tempstr); } else goto unexpected; SendMessage(control, CB_SETITEMDATA, option_count, j); if (j == default_value) default_index = option_count; if (!_tcscmp(buf1, buf2)) current_index = option_count; option_count++; } } // if there is only one option, it is effectively disabled if (option_count <= 1) has_option = FALSE; if (current_index >= 0) SendMessage(control, CB_SETCURSEL, current_index, 0); else if (default_index >= 0) SendMessage(control, CB_SETCURSEL, default_index, 0); } else { // this item is non applicable SendMessage(control, CB_ADDSTRING, 0, (LPARAM) TEXT("N/A")); SendMessage(control, CB_SETCURSEL, 0, 0); } EnableWindow(control, has_option); return TRUE; unexpected: assert(FALSE); return FALSE; }