mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Merge branch 'obsd-master'
This commit is contained in:
		@@ -160,11 +160,17 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
			cmdq_error(item, "not an array: %s", args->argv[0]);
 | 
								cmdq_error(item, "not an array: %s", args->argv[0]);
 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
								return (CMD_RETURN_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else if (*name != '@' && options_array_size(parent, NULL) != -1) {
 | 
				
			||||||
		if (*name != '@' && options_array_size(parent, NULL) != -1) {
 | 
							if (value == NULL) {
 | 
				
			||||||
			cmdq_error(item, "is an array: %s", args->argv[0]);
 | 
								cmdq_error(item, "empty value");
 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
								return (-1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (o == NULL)
 | 
				
			||||||
 | 
								o = options_empty(oo, options_table_entry(parent));
 | 
				
			||||||
 | 
							if (!args_has(args, 'a'))
 | 
				
			||||||
 | 
								options_array_clear(o);
 | 
				
			||||||
 | 
							options_array_assign(o, value);
 | 
				
			||||||
 | 
							return (CMD_RETURN_NORMAL);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* With -o, check this option is not already set. */
 | 
						/* With -o, check this option is not already set. */
 | 
				
			||||||
@@ -197,7 +203,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
			else
 | 
								else
 | 
				
			||||||
				options_remove(o);
 | 
									options_remove(o);
 | 
				
			||||||
		} else
 | 
							} else
 | 
				
			||||||
			options_array_set(o, idx, NULL);
 | 
								options_array_set(o, idx, NULL, 0);
 | 
				
			||||||
	} else if (*name == '@')
 | 
						} else if (*name == '@')
 | 
				
			||||||
		options_set_string(oo, name, args_has(args, 'a'), "%s", value);
 | 
							options_set_string(oo, name, args_has(args, 'a'), "%s", value);
 | 
				
			||||||
	else if (idx == -1) {
 | 
						else if (idx == -1) {
 | 
				
			||||||
@@ -207,7 +213,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if (o == NULL)
 | 
							if (o == NULL)
 | 
				
			||||||
			o = options_empty(oo, options_table_entry(parent));
 | 
								o = options_empty(oo, options_table_entry(parent));
 | 
				
			||||||
		if (options_array_set(o, idx, value) != 0) {
 | 
							if (options_array_set(o, idx, value, 1) != 0) {
 | 
				
			||||||
			cmdq_error(item, "invalid index: %s", args->argv[0]);
 | 
								cmdq_error(item, "invalid index: %s", args->argv[0]);
 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
								return (CMD_RETURN_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,11 +91,20 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
 | 
				
			|||||||
	const char	*name;
 | 
						const char	*name;
 | 
				
			||||||
	const char	*value;
 | 
						const char	*value;
 | 
				
			||||||
	char		*tmp, *escaped;
 | 
						char		*tmp, *escaped;
 | 
				
			||||||
 | 
						u_int		 size, i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (idx != -1) {
 | 
						if (idx != -1) {
 | 
				
			||||||
		xasprintf(&tmp, "%s[%d]", options_name(o), idx);
 | 
							xasprintf(&tmp, "%s[%d]", options_name(o), idx);
 | 
				
			||||||
		name = tmp;
 | 
							name = tmp;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
							if (options_array_size(o, &size) != -1) {
 | 
				
			||||||
 | 
								for (i = 0; i < size; i++) {
 | 
				
			||||||
 | 
									if (options_array_get(o, i) == NULL)
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									cmd_show_options_print(self, item, o, i);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		tmp = NULL;
 | 
							tmp = NULL;
 | 
				
			||||||
		name = options_name(o);
 | 
							name = options_name(o);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										85
									
								
								options.c
									
									
									
									
									
								
							
							
						
						
									
										85
									
								
								options.c
									
									
									
									
									
								
							@@ -170,22 +170,11 @@ struct options_entry *
 | 
				
			|||||||
options_default(struct options *oo, const struct options_table_entry *oe)
 | 
					options_default(struct options *oo, const struct options_table_entry *oe)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct options_entry	*o;
 | 
						struct options_entry	*o;
 | 
				
			||||||
	char			*cp, *copy, *next;
 | 
					 | 
				
			||||||
	u_int			 idx = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	o = options_empty(oo, oe);
 | 
						o = options_empty(oo, oe);
 | 
				
			||||||
 | 
						if (oe->type == OPTIONS_TABLE_ARRAY)
 | 
				
			||||||
	if (oe->type == OPTIONS_TABLE_ARRAY) {
 | 
							options_array_assign(o, oe->default_str);
 | 
				
			||||||
		copy = cp = xstrdup(oe->default_str);
 | 
						else if (oe->type == OPTIONS_TABLE_STRING)
 | 
				
			||||||
		while ((next = strsep(&cp, ",")) != NULL) {
 | 
					 | 
				
			||||||
			options_array_set(o, idx, next);
 | 
					 | 
				
			||||||
			idx++;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		free(copy);
 | 
					 | 
				
			||||||
		return (o);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (oe->type == OPTIONS_TABLE_STRING)
 | 
					 | 
				
			||||||
		o->string = xstrdup(oe->default_str);
 | 
							o->string = xstrdup(oe->default_str);
 | 
				
			||||||
	else if (oe->type == OPTIONS_TABLE_STYLE) {
 | 
						else if (oe->type == OPTIONS_TABLE_STYLE) {
 | 
				
			||||||
		memcpy(&o->style, &grid_default_cell, sizeof o->style);
 | 
							memcpy(&o->style, &grid_default_cell, sizeof o->style);
 | 
				
			||||||
@@ -242,6 +231,13 @@ options_table_entry(struct options_entry *o)
 | 
				
			|||||||
	return (o->tableentry);
 | 
						return (o->tableentry);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					options_array_clear(struct options_entry *o)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (OPTIONS_IS_ARRAY(o))
 | 
				
			||||||
 | 
							o->arraysize = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char *
 | 
					const char *
 | 
				
			||||||
options_array_get(struct options_entry *o, u_int idx)
 | 
					options_array_get(struct options_entry *o, u_int idx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -253,9 +249,11 @@ options_array_get(struct options_entry *o, u_int idx)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
options_array_set(struct options_entry *o, u_int idx, const char *value)
 | 
					options_array_set(struct options_entry *o, u_int idx, const char *value,
 | 
				
			||||||
 | 
					    int append)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u_int	i;
 | 
						char	*new;
 | 
				
			||||||
 | 
						u_int	 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!OPTIONS_IS_ARRAY(o))
 | 
						if (!OPTIONS_IS_ARRAY(o))
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
@@ -268,12 +266,17 @@ options_array_set(struct options_entry *o, u_int idx, const char *value)
 | 
				
			|||||||
			o->array[i] = NULL;
 | 
								o->array[i] = NULL;
 | 
				
			||||||
		o->arraysize = idx + 1;
 | 
							o->arraysize = idx + 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (o->array[idx] != NULL)
 | 
					
 | 
				
			||||||
		free((void *)o->array[idx]);
 | 
						new = NULL;
 | 
				
			||||||
	if (value != NULL)
 | 
						if (value != NULL) {
 | 
				
			||||||
		o->array[idx] = xstrdup(value);
 | 
							if (o->array[idx] != NULL && append)
 | 
				
			||||||
	else
 | 
								xasprintf(&new, "%s%s", o->array[idx], value);
 | 
				
			||||||
		o->array[idx] = NULL;
 | 
							else
 | 
				
			||||||
 | 
								new = xstrdup(value);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						free((void *)o->array[idx]);
 | 
				
			||||||
 | 
						o->array[idx] = new;
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -287,6 +290,32 @@ options_array_size(struct options_entry *o, u_int *size)
 | 
				
			|||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					options_array_assign(struct options_entry *o, const char *s)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const char	*separator;
 | 
				
			||||||
 | 
						char		*copy, *next, *string;
 | 
				
			||||||
 | 
						u_int		 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						separator = o->tableentry->separator;
 | 
				
			||||||
 | 
						if (separator == NULL)
 | 
				
			||||||
 | 
							separator = " ,";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						copy = string = xstrdup(s);
 | 
				
			||||||
 | 
						while ((next = strsep(&string, separator)) != NULL) {
 | 
				
			||||||
 | 
							if (*next == '\0')
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							for (i = 0; i < OPTIONS_ARRAY_LIMIT; i++) {
 | 
				
			||||||
 | 
								if (i >= o->arraysize || o->array[i] == NULL)
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (i == OPTIONS_ARRAY_LIMIT)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							options_array_set(o, i, next, 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						free(copy);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
options_isstring(struct options_entry *o)
 | 
					options_isstring(struct options_entry *o)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -384,12 +413,6 @@ options_parse_get(struct options *oo, const char *s, int *idx, int only)
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
		o = options_get(oo, name);
 | 
							o = options_get(oo, name);
 | 
				
			||||||
	free(name);
 | 
						free(name);
 | 
				
			||||||
	if (o != NULL) {
 | 
					 | 
				
			||||||
		if (OPTIONS_IS_ARRAY(o) && *idx == -1)
 | 
					 | 
				
			||||||
			return (NULL);
 | 
					 | 
				
			||||||
		if (!OPTIONS_IS_ARRAY(o) && *idx != -1)
 | 
					 | 
				
			||||||
			return (NULL);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return (o);
 | 
						return (o);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -447,12 +470,6 @@ options_match_get(struct options *oo, const char *s, int *idx, int only,
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
		o = options_get(oo, name);
 | 
							o = options_get(oo, name);
 | 
				
			||||||
	free(name);
 | 
						free(name);
 | 
				
			||||||
	if (o != NULL) {
 | 
					 | 
				
			||||||
		if (OPTIONS_IS_ARRAY(o) && *idx == -1)
 | 
					 | 
				
			||||||
			return (NULL);
 | 
					 | 
				
			||||||
		if (!OPTIONS_IS_ARRAY(o) && *idx != -1)
 | 
					 | 
				
			||||||
			return (NULL);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return (o);
 | 
						return (o);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1481,6 +1481,7 @@ struct options_table_entry {
 | 
				
			|||||||
	const char		 *default_str;
 | 
						const char		 *default_str;
 | 
				
			||||||
	long long		  default_num;
 | 
						long long		  default_num;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const char		 *separator;
 | 
				
			||||||
	const char		 *style;
 | 
						const char		 *style;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1618,17 +1619,20 @@ const struct options_table_entry *options_table_entry(struct options_entry *);
 | 
				
			|||||||
struct options_entry *options_get_only(struct options *, const char *);
 | 
					struct options_entry *options_get_only(struct options *, const char *);
 | 
				
			||||||
struct options_entry *options_get(struct options *, const char *);
 | 
					struct options_entry *options_get(struct options *, const char *);
 | 
				
			||||||
void		 options_remove(struct options_entry *);
 | 
					void		 options_remove(struct options_entry *);
 | 
				
			||||||
 | 
					void		 options_array_clear(struct options_entry *);
 | 
				
			||||||
const char	*options_array_get(struct options_entry *, u_int);
 | 
					const char	*options_array_get(struct options_entry *, u_int);
 | 
				
			||||||
int		 options_array_set(struct options_entry *, u_int, const char *);
 | 
					int		 options_array_set(struct options_entry *, u_int, const char *,
 | 
				
			||||||
 | 
							     int);
 | 
				
			||||||
int		 options_array_size(struct options_entry *, u_int *);
 | 
					int		 options_array_size(struct options_entry *, u_int *);
 | 
				
			||||||
 | 
					void		 options_array_assign(struct options_entry *, const char *);
 | 
				
			||||||
int		 options_isstring(struct options_entry *);
 | 
					int		 options_isstring(struct options_entry *);
 | 
				
			||||||
const char	*options_tostring(struct options_entry *, int);
 | 
					const char	*options_tostring(struct options_entry *, int);
 | 
				
			||||||
char		*options_parse(const char *, int *);
 | 
					char		*options_parse(const char *, int *);
 | 
				
			||||||
struct options_entry *options_parse_get(struct options *, const char *, int *,
 | 
					struct options_entry *options_parse_get(struct options *, const char *, int *,
 | 
				
			||||||
		    int);
 | 
							     int);
 | 
				
			||||||
char		*options_match(const char *, int *, int *);
 | 
					char		*options_match(const char *, int *, int *);
 | 
				
			||||||
struct options_entry *options_match_get(struct options *, const char *, int *,
 | 
					struct options_entry *options_match_get(struct options *, const char *, int *,
 | 
				
			||||||
		    int, int *);
 | 
							     int, int *);
 | 
				
			||||||
const char	*options_get_string(struct options *, const char *);
 | 
					const char	*options_get_string(struct options *, const char *);
 | 
				
			||||||
long long	 options_get_number(struct options *, const char *);
 | 
					long long	 options_get_number(struct options *, const char *);
 | 
				
			||||||
const struct grid_cell *options_get_style(struct options *, const char *);
 | 
					const struct grid_cell *options_get_style(struct options *, const char *);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user