/// Sets the value of a global or local(buffer, window) option. /// /// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer /// to the window or buffer. /// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF` /// @param name The option name /// @param[out] err Details of an error that may have occurred void set_option_to(void *to, int type, String name, Object value, Error *err) { if (name.size == 0) { set_api_error("Empty option name", err); return; } int flags = get_option_value_strict(name.data, NULL, NULL, type, to); if (flags == 0) { set_api_error("invalid option name", err); return; } if (value.type == kObjectTypeNil) { if (type == SREQ_GLOBAL) { set_api_error("unable to unset option", err); return; } else if (!(flags & SOPT_GLOBAL)) { set_api_error("cannot unset option that doesn't have a global value", err); return; } else { unset_global_local_option(name.data, to); return; } } int opt_flags = (type ? OPT_LOCAL : OPT_GLOBAL); if (flags & SOPT_BOOL) { if (value.type != kObjectTypeBoolean) { set_api_error("option requires a boolean value", err); return; } bool val = value.data.boolean; set_option_value_for(name.data, val, NULL, opt_flags, type, to, err); } else if (flags & SOPT_NUM) { if (value.type != kObjectTypeInteger) { set_api_error("option requires an integer value", err); return; } if (value.data.integer > INT_MAX || value.data.integer < INT_MIN) { set_api_error("Option value outside range", err); return; } int val = (int) value.data.integer; set_option_value_for(name.data, val, NULL, opt_flags, type, to, err); } else { if (value.type != kObjectTypeString) { set_api_error("option requires a string value", err); return; } set_option_value_for(name.data, 0, value.data.string.data, opt_flags, type, to, err); } }
/// Sets the value of a global or local(buffer, window) option. /// /// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer /// to the window or buffer. /// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF` /// @param name The option name /// @param[out] err Details of an error that may have occurred void set_option_to(void *to, int type, String name, Object value, Error *err) { if (name.size == 0) { api_set_error(err, Validation, _("Empty option name")); return; } int flags = get_option_value_strict(name.data, NULL, NULL, type, to); if (flags == 0) { api_set_error(err, Validation, _("Invalid option name \"%s\""), name.data); return; } if (value.type == kObjectTypeNil) { if (type == SREQ_GLOBAL) { api_set_error(err, Exception, _("Unable to unset option \"%s\""), name.data); return; } else if (!(flags & SOPT_GLOBAL)) { api_set_error(err, Exception, _("Cannot unset option \"%s\" " "because it doesn't have a global value"), name.data); return; } else { unset_global_local_option(name.data, to); return; } } int opt_flags = (type ? OPT_LOCAL : OPT_GLOBAL); if (flags & SOPT_BOOL) { if (value.type != kObjectTypeBoolean) { api_set_error(err, Validation, _("Option \"%s\" requires a boolean value"), name.data); return; } bool val = value.data.boolean; set_option_value_for(name.data, val, NULL, opt_flags, type, to, err); } else if (flags & SOPT_NUM) { if (value.type != kObjectTypeInteger) { api_set_error(err, Validation, _("Option \"%s\" requires an integer value"), name.data); return; } if (value.data.integer > INT_MAX || value.data.integer < INT_MIN) { api_set_error(err, Validation, _("Value for option \"%s\" is outside range"), name.data); return; } int val = (int) value.data.integer; set_option_value_for(name.data, val, NULL, opt_flags, type, to, err); } else { if (value.type != kObjectTypeString) { api_set_error(err, Validation, _("Option \"%s\" requires a string value"), name.data); return; } set_option_value_for(name.data, 0, value.data.string.data, opt_flags, type, to, err); } }