mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add m: for fnmatch(3) format matching.
This commit is contained in:
		
							
								
								
									
										9
									
								
								format.c
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								format.c
									
									
									
									
									
								
							@@ -21,6 +21,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <ctype.h>
 | 
					#include <ctype.h>
 | 
				
			||||||
#include <errno.h>
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#include <fnmatch.h>
 | 
				
			||||||
#include <libgen.h>
 | 
					#include <libgen.h>
 | 
				
			||||||
#include <netdb.h>
 | 
					#include <netdb.h>
 | 
				
			||||||
#include <stdarg.h>
 | 
					#include <stdarg.h>
 | 
				
			||||||
@@ -868,6 +869,12 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* Is there a length limit or whatnot? */
 | 
						/* Is there a length limit or whatnot? */
 | 
				
			||||||
	switch (copy[0]) {
 | 
						switch (copy[0]) {
 | 
				
			||||||
 | 
						case 'm':
 | 
				
			||||||
 | 
							if (copy[1] != ':')
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							compare = -2;
 | 
				
			||||||
 | 
							copy += 2;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	case '!':
 | 
						case '!':
 | 
				
			||||||
		if (copy[1] == '=' && copy[2] == ':') {
 | 
							if (copy[1] == '=' && copy[2] == ':') {
 | 
				
			||||||
			compare = -1;
 | 
								compare = -1;
 | 
				
			||||||
@@ -943,6 +950,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
 | 
				
			|||||||
			value = xstrdup("1");
 | 
								value = xstrdup("1");
 | 
				
			||||||
		else if (compare == -1 && strcmp(left, right) != 0)
 | 
							else if (compare == -1 && strcmp(left, right) != 0)
 | 
				
			||||||
			value = xstrdup("1");
 | 
								value = xstrdup("1");
 | 
				
			||||||
 | 
							else if (compare == -2 && fnmatch(left, right, 0) == 0)
 | 
				
			||||||
 | 
								value = xstrdup("1");
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			value = xstrdup("0");
 | 
								value = xstrdup("0");
 | 
				
			||||||
		free(right);
 | 
							free(right);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							@@ -3444,6 +3444,13 @@ if running on
 | 
				
			|||||||
.Ql myhost ,
 | 
					.Ql myhost ,
 | 
				
			||||||
otherwise by
 | 
					otherwise by
 | 
				
			||||||
.Ql 0.
 | 
					.Ql 0.
 | 
				
			||||||
 | 
					An
 | 
				
			||||||
 | 
					.Ql m
 | 
				
			||||||
 | 
					specifies a
 | 
				
			||||||
 | 
					.Xr fnmatch 3
 | 
				
			||||||
 | 
					comparison - the first argument is the pattern and the second the string to
 | 
				
			||||||
 | 
					compare. For example,
 | 
				
			||||||
 | 
					.Ql #{m:*foo*,#{host}} .
 | 
				
			||||||
.Pp
 | 
					.Pp
 | 
				
			||||||
A limit may be placed on the length of the resultant string by prefixing it
 | 
					A limit may be placed on the length of the resultant string by prefixing it
 | 
				
			||||||
by an
 | 
					by an
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user