mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Add time and a command count to control mode guards, based on code from George
Nachman.
This commit is contained in:
		
							
								
								
									
										39
									
								
								cmd-queue.c
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								cmd-queue.c
									
									
									
									
									
								
							| @@ -151,6 +151,22 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) | ||||
| 	free(msg); | ||||
| } | ||||
|  | ||||
| /* Print a guard line. */ | ||||
| void | ||||
| cmdq_guard(struct cmd_q *cmdq, const char *guard) | ||||
| { | ||||
| 	struct client	*c = cmdq->client; | ||||
|  | ||||
| 	if (c == NULL || c->session == NULL) | ||||
| 		return; | ||||
| 	if (!(c->flags & CLIENT_CONTROL)) | ||||
| 		return; | ||||
|  | ||||
| 	evbuffer_add_printf(c->stdout_data, "%%%s %ld %u\n", guard, | ||||
| 	    cmdq->time, cmdq->number); | ||||
| 	server_push_stdout(c); | ||||
| } | ||||
|  | ||||
| /* Add command list to queue and begin processing if needed. */ | ||||
| void | ||||
| cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist) | ||||
| @@ -179,16 +195,11 @@ cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist) | ||||
| int | ||||
| cmdq_continue(struct cmd_q *cmdq) | ||||
| { | ||||
| 	struct client		*c = cmdq->client; | ||||
| 	struct cmd_q_item	*next; | ||||
| 	enum cmd_retval		 retval; | ||||
| 	int			 guards, empty; | ||||
| 	int			 empty; | ||||
| 	char			 s[1024]; | ||||
|  | ||||
| 	guards = 0; | ||||
| 	if (c != NULL && c->session != NULL) | ||||
| 		guards = c->flags & CLIENT_CONTROL; | ||||
|  | ||||
| 	notify_disable(); | ||||
|  | ||||
| 	empty = TAILQ_EMPTY(&cmdq->queue); | ||||
| @@ -209,15 +220,15 @@ cmdq_continue(struct cmd_q *cmdq) | ||||
| 			log_debug("cmdq %p: %s (client %d)", cmdq, s, | ||||
| 			    cmdq->client != NULL ? cmdq->client->ibuf.fd : -1); | ||||
|  | ||||
| 			if (guards) | ||||
| 				cmdq_print(cmdq, "%%begin"); | ||||
| 			cmdq->time = time(NULL); | ||||
| 			cmdq->number++; | ||||
|  | ||||
| 			cmdq_guard(cmdq, "begin"); | ||||
| 			retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq); | ||||
| 			if (guards) { | ||||
| 				if (retval == CMD_RETURN_ERROR) | ||||
| 					cmdq_print(cmdq, "%%error"); | ||||
| 				else | ||||
| 					cmdq_print(cmdq, "%%end"); | ||||
| 			} | ||||
| 			if (retval == CMD_RETURN_ERROR) | ||||
| 				cmdq_guard(cmdq, "error"); | ||||
| 			else | ||||
| 				cmdq_guard(cmdq, "end"); | ||||
|  | ||||
| 			if (retval == CMD_RETURN_ERROR) | ||||
| 				break; | ||||
|   | ||||
| @@ -68,8 +68,13 @@ control_callback(struct client *c, int closed, unused void *data) | ||||
| 		} | ||||
|  | ||||
| 		if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) { | ||||
| 			control_write(c, "%%error in line \"%s\": %s", line, | ||||
| 			    cause); | ||||
| 			c->cmdq->time = time(NULL); | ||||
| 			c->cmdq->number++; | ||||
|  | ||||
| 			cmdq_guard(c->cmdq, "begin"); | ||||
| 			control_write(c, "parse error: %s", cause); | ||||
| 			cmdq_guard(c->cmdq, "error"); | ||||
|  | ||||
| 			free(cause); | ||||
| 		} else { | ||||
| 			cmdq_run(c->cmdq, cmdlist); | ||||
|   | ||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -1412,6 +1412,9 @@ struct cmd_q { | ||||
| 	struct cmd_q_item	*item; | ||||
| 	struct cmd		*cmd; | ||||
|  | ||||
| 	time_t			 time; | ||||
| 	u_int			 number; | ||||
|  | ||||
| 	void			 (*emptyfn)(struct cmd_q *); | ||||
| 	void			*data; | ||||
|  | ||||
| @@ -1853,6 +1856,7 @@ int		 cmdq_free(struct cmd_q *); | ||||
| void printflike2 cmdq_print(struct cmd_q *, const char *, ...); | ||||
| void printflike2 cmdq_info(struct cmd_q *, const char *, ...); | ||||
| void printflike2 cmdq_error(struct cmd_q *, const char *, ...); | ||||
| void		 cmdq_guard(struct cmd_q *, const char *); | ||||
| void		 cmdq_run(struct cmd_q *, struct cmd_list *); | ||||
| void		 cmdq_append(struct cmd_q *, struct cmd_list *); | ||||
| int		 cmdq_continue(struct cmd_q *); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Nicholas Marriott
					Nicholas Marriott