mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Fix ordering of source-file with multiple files and add flags to load_cfg.
This commit is contained in:
		
							
								
								
									
										25
									
								
								cfg.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								cfg.c
									
									
									
									
									
								
							@@ -82,7 +82,7 @@ void
 | 
				
			|||||||
start_cfg(void)
 | 
					start_cfg(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const char	*home;
 | 
						const char	*home;
 | 
				
			||||||
	int		 quiet = 0;
 | 
						int		 flags = 0;
 | 
				
			||||||
	struct client	*c;
 | 
						struct client	*c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
@@ -103,14 +103,14 @@ start_cfg(void)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (cfg_file == NULL)
 | 
						if (cfg_file == NULL)
 | 
				
			||||||
		load_cfg(TMUX_CONF, NULL, NULL, 1);
 | 
							load_cfg(TMUX_CONF, NULL, NULL, CFG_QUIET, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (cfg_file == NULL && (home = find_home()) != NULL) {
 | 
						if (cfg_file == NULL && (home = find_home()) != NULL) {
 | 
				
			||||||
		xasprintf(&cfg_file, "%s/.tmux.conf", home);
 | 
							xasprintf(&cfg_file, "%s/.tmux.conf", home);
 | 
				
			||||||
		quiet = 1;
 | 
							flags = CFG_QUIET;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (cfg_file != NULL)
 | 
						if (cfg_file != NULL)
 | 
				
			||||||
		load_cfg(cfg_file, NULL, NULL, quiet);
 | 
							load_cfg(cfg_file, NULL, NULL, flags, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
 | 
						cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -239,7 +239,8 @@ cfg_handle_directive(const char *p, const char *path, size_t line,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
 | 
					load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
 | 
				
			||||||
 | 
					    struct cmdq_item **new_item)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	FILE			*f;
 | 
						FILE			*f;
 | 
				
			||||||
	const char		 delim[3] = { '\\', '\\', '\0' };
 | 
						const char		 delim[3] = { '\\', '\\', '\0' };
 | 
				
			||||||
@@ -247,7 +248,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
 | 
				
			|||||||
	size_t			 line = 0;
 | 
						size_t			 line = 0;
 | 
				
			||||||
	char			*buf, *cause1, *p, *q;
 | 
						char			*buf, *cause1, *p, *q;
 | 
				
			||||||
	struct cmd_list		*cmdlist;
 | 
						struct cmd_list		*cmdlist;
 | 
				
			||||||
	struct cmdq_item	*new_item;
 | 
						struct cmdq_item	*new_item0;
 | 
				
			||||||
	struct cfg_cond		*cond, *cond1;
 | 
						struct cfg_cond		*cond, *cond1;
 | 
				
			||||||
	struct cfg_conds	 conds;
 | 
						struct cfg_conds	 conds;
 | 
				
			||||||
	struct cmd_find_state	*fs = NULL;
 | 
						struct cmd_find_state	*fs = NULL;
 | 
				
			||||||
@@ -262,7 +263,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	log_debug("loading %s", path);
 | 
						log_debug("loading %s", path);
 | 
				
			||||||
	if ((f = fopen(path, "rb")) == NULL) {
 | 
						if ((f = fopen(path, "rb")) == NULL) {
 | 
				
			||||||
		if (errno == ENOENT && quiet)
 | 
							if (errno == ENOENT && (flags & CFG_QUIET))
 | 
				
			||||||
			return (0);
 | 
								return (0);
 | 
				
			||||||
		cfg_add_cause("%s: %s", path, strerror(errno));
 | 
							cfg_add_cause("%s: %s", path, strerror(errno));
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
@@ -301,12 +302,12 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		free(buf);
 | 
							free(buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
 | 
							new_item0 = cmdq_get_command(cmdlist, NULL, NULL, 0);
 | 
				
			||||||
		if (item != NULL) {
 | 
							if (item != NULL) {
 | 
				
			||||||
			cmdq_insert_after(item, new_item);
 | 
								cmdq_insert_after(item, new_item0);
 | 
				
			||||||
			item = new_item;
 | 
								item = new_item0;
 | 
				
			||||||
		} else
 | 
							} else
 | 
				
			||||||
			cmdq_append(c, new_item);
 | 
								cmdq_append(c, new_item0);
 | 
				
			||||||
		cmd_list_free(cmdlist);
 | 
							cmd_list_free(cmdlist);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		found++;
 | 
							found++;
 | 
				
			||||||
@@ -319,6 +320,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
 | 
				
			|||||||
		free(cond);
 | 
							free(cond);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (new_item != NULL)
 | 
				
			||||||
 | 
							*new_item = item;
 | 
				
			||||||
	return (found);
 | 
						return (found);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,15 +49,18 @@ static enum cmd_retval
 | 
				
			|||||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
 | 
					cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct args		*args = self->args;
 | 
						struct args		*args = self->args;
 | 
				
			||||||
	int			 quiet = args_has(args, 'q');
 | 
						int			 flags = 0;
 | 
				
			||||||
	struct client		*c = item->client;
 | 
						struct client		*c = item->client;
 | 
				
			||||||
	struct cmdq_item	*new_item;
 | 
						struct cmdq_item	*new_item, *after;
 | 
				
			||||||
	enum cmd_retval		 retval;
 | 
						enum cmd_retval		 retval;
 | 
				
			||||||
	char			*pattern, *tmp;
 | 
						char			*pattern, *tmp;
 | 
				
			||||||
	const char		*path = args->argv[0];
 | 
						const char		*path = args->argv[0];
 | 
				
			||||||
	glob_t			 g;
 | 
						glob_t			 g;
 | 
				
			||||||
	u_int			 i;
 | 
						u_int			 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (args_has(args, 'q'))
 | 
				
			||||||
 | 
							flags |= CFG_QUIET;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (*path == '/')
 | 
						if (*path == '/')
 | 
				
			||||||
		pattern = xstrdup(path);
 | 
							pattern = xstrdup(path);
 | 
				
			||||||
	else {
 | 
						else {
 | 
				
			||||||
@@ -69,7 +72,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	retval = CMD_RETURN_NORMAL;
 | 
						retval = CMD_RETURN_NORMAL;
 | 
				
			||||||
	if (glob(pattern, 0, NULL, &g) != 0) {
 | 
						if (glob(pattern, 0, NULL, &g) != 0) {
 | 
				
			||||||
		if (!quiet || errno != ENOENT) {
 | 
							if (errno != ENOENT || (~flags & CFG_QUIET)) {
 | 
				
			||||||
			cmdq_error(item, "%s: %s", path, strerror(errno));
 | 
								cmdq_error(item, "%s: %s", path, strerror(errno));
 | 
				
			||||||
			retval = CMD_RETURN_ERROR;
 | 
								retval = CMD_RETURN_ERROR;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -78,9 +81,12 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	free(pattern);
 | 
						free(pattern);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						after = item;
 | 
				
			||||||
	for (i = 0; i < (u_int)g.gl_pathc; i++) {
 | 
						for (i = 0; i < (u_int)g.gl_pathc; i++) {
 | 
				
			||||||
		if (load_cfg(g.gl_pathv[i], c, item, quiet) < 0)
 | 
							if (load_cfg(g.gl_pathv[i], c, after, flags, &new_item) < 0)
 | 
				
			||||||
			retval = CMD_RETURN_ERROR;
 | 
								retval = CMD_RETURN_ERROR;
 | 
				
			||||||
 | 
							else if (new_item != NULL)
 | 
				
			||||||
 | 
								after = new_item;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (cfg_finished) {
 | 
						if (cfg_finished) {
 | 
				
			||||||
		new_item = cmdq_get_callback(cmd_source_file_done, NULL);
 | 
							new_item = cmdq_get_callback(cmd_source_file_done, NULL);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1671,8 +1671,10 @@ void	proc_toggle_log(struct tmuxproc *);
 | 
				
			|||||||
/* cfg.c */
 | 
					/* cfg.c */
 | 
				
			||||||
extern int cfg_finished;
 | 
					extern int cfg_finished;
 | 
				
			||||||
extern struct client *cfg_client;
 | 
					extern struct client *cfg_client;
 | 
				
			||||||
 | 
					#define CFG_QUIET 0x1
 | 
				
			||||||
void	start_cfg(void);
 | 
					void	start_cfg(void);
 | 
				
			||||||
int	load_cfg(const char *, struct client *, struct cmdq_item *, int);
 | 
					int	load_cfg(const char *, struct client *, struct cmdq_item *, int,
 | 
				
			||||||
 | 
						    struct cmdq_item **);
 | 
				
			||||||
void	set_cfg_file(const char *);
 | 
					void	set_cfg_file(const char *);
 | 
				
			||||||
void printflike(1, 2) cfg_add_cause(const char *, ...);
 | 
					void printflike(1, 2) cfg_add_cause(const char *, ...);
 | 
				
			||||||
void	cfg_print_causes(struct cmdq_item *);
 | 
					void	cfg_print_causes(struct cmdq_item *);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user