optreserr_t win_add_resolution_parameter(HWND control, option_resolution *resolution) { const option_guide *guide; char buf[256]; optreserr_t err; const char *text; const char *old_text; int i; if (!win_get_window_text_utf8(control, buf, ARRAY_LENGTH(buf))) { err = OPTIONRESOLTUION_ERROR_INTERNAL; return err; } text = buf; guide = (const option_guide *) GetProp(control, guide_prop); if (!guide) { err = OPTIONRESOLTUION_ERROR_INTERNAL; return err; } if (guide->option_type == OPTIONTYPE_ENUM_BEGIN) { /* need to convert display name to identifier */ old_text = text; text = NULL; for (i = 1; guide[i].option_type == OPTIONTYPE_ENUM_VALUE; i++) { if (!strcmp(guide[i].display_name, old_text)) { text = guide[i].identifier; break; } } } if (text) { err = option_resolution_add_param(resolution, guide->identifier, text); if (err) return err; } err = OPTIONRESOLUTION_ERROR_SUCCESS; return err; }
static void node_createimage(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; xml_data_node *child_node; xml_attribute_node *attr_node; option_resolution *opts = NULL; const imgtool_module *module; const char *driver; const char *param_name; const char *param_value; attr_node = xml_get_attribute(node, "driver"); if (!attr_node) { error_missingattribute("driver"); return; } driver = attr_node->value; /* does image creation support options? */ module = imgtool_find_module(attr_node->value); if (module && module->createimage_optguide && module->createimage_optspec) opts = option_resolution_create(module->createimage_optguide, module->createimage_optspec); report_message(MSG_INFO, "Creating image (module '%s')", driver); for (child_node = xml_get_sibling(node->child, "param"); child_node; child_node = xml_get_sibling(child_node->next, "param")) { if (!opts) { report_message(MSG_FAILURE, "Cannot specify creation options with this module"); return; } attr_node = xml_get_attribute(child_node, "name"); if (!attr_node) { error_missingattribute("name"); return; } param_name = attr_node->value; attr_node = xml_get_attribute(child_node, "value"); if (!attr_node) { error_missingattribute("value"); return; } param_value = attr_node->value; option_resolution_add_param(opts, param_name, param_value); } err = imgtool_image_create_byname(driver, tempfile_name(), opts, &state->m_image); if (opts) { option_resolution_close(opts); opts = NULL; } if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } err = imgtool_partition_open(state->m_image, 0, &state->m_partition); if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } }
static int parse_options(int argc, char *argv[], int minunnamed, int maxunnamed, option_resolution *resolution, filter_getinfoproc *filter, const char **fork) { int i; int lastunnamed = 0; char *s; char *name = NULL; char *value = NULL; optreserr_t oerr; static char buf[256]; if (filter) *filter = NULL; if (fork) *fork = NULL; for (i = 0; i < argc; i++) { /* Named or unamed arg */ if ((argv[i][0] != '-') || (argv[i][1] != '-')) { /* Unnamed */ if (i >= maxunnamed) goto error; /* Too many unnamed */ lastunnamed = i + 1; } else { /* Named */ name = argv[i] + 2; s = strchr(name, '='); if (!s) goto error; *s = 0; value = s + 1; if (!strcmp(name, "filter")) { /* filter option */ if (!filter) goto error; /* this command doesn't use filters */ if (*filter) goto optionalreadyspecified; *filter = filter_lookup(value); if (!(*filter)) goto filternotfound; } else if (!strcmp(name, "fork")) { /* fork option */ if (!fork) goto error; /* this command doesn't use filters */ if (*fork) goto optionalreadyspecified; snprintf(buf, ARRAY_LENGTH(buf), "%s", value); *fork = buf; } else { /* Other named option */ if (i < minunnamed) goto error; /* Too few unnamed */ oerr = option_resolution_add_param(resolution, name, value); if (oerr) goto opterror; } } } return lastunnamed; filternotfound: fprintf(stderr, "%s: Unknown filter type\n", value); return -1; optionalreadyspecified: fprintf(stderr, "Cannot specify multiple %ss\n", name); return -1; opterror: fprintf(stderr, "%s: %s\n", name, option_resolution_error_string(oerr)); return -1; error: fprintf(stderr, "%s: Unrecognized option\n", argv[i]); return -1; }