Use gnu-case-range and gnu-conditional-omitted-operand extensions
I'm sad to do this but I just can't stand writing (foo ? foo : bar) anymore.
This commit is contained in:
		
							parent
							
								
									6574f012c9
								
							
						
					
					
						commit
						75a6aa9258
					
				
							
								
								
									
										3
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								Makefile
									
									
									
									
									
								
							| @ -1,7 +1,8 @@ | |||||||
| PREFIX = /usr/local | PREFIX = /usr/local | ||||||
| MANDIR = ${PREFIX}/share/man | MANDIR = ${PREFIX}/share/man | ||||||
| 
 | 
 | ||||||
| CFLAGS += -std=c11 -Wall -Wextra -Wpedantic | CEXTS = gnu-case-range gnu-conditional-omitted-operand | ||||||
|  | CFLAGS += -std=c11 -Wall -Wextra -Wpedantic ${CEXTS:%=-Wno-%} | ||||||
| LDLIBS = -lcrypto -ltls -lncursesw | LDLIBS = -lcrypto -ltls -lncursesw | ||||||
| 
 | 
 | ||||||
| -include config.mk | -include config.mk | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								command.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								command.c
									
									
									
									
									
								
							| @ -58,8 +58,8 @@ static void splitMessage(char *cmd, uint id, char *params) { | |||||||
| 	int overhead = snprintf( | 	int overhead = snprintf( | ||||||
| 		NULL, 0, ":%s!%*s@%*s %s %s :\r\n", | 		NULL, 0, ":%s!%*s@%*s %s %s :\r\n", | ||||||
| 		self.nick, | 		self.nick, | ||||||
| 		(self.user ? 0 : network.userLen), (self.user ? self.user : "*"), | 		(self.user ? 0 : network.userLen), (self.user ?: "*"), | ||||||
| 		(self.host ? 0 : network.hostLen), (self.host ? self.host : "*"), | 		(self.host ? 0 : network.hostLen), (self.host ?: "*"), | ||||||
| 		cmd, idNames[id] | 		cmd, idNames[id] | ||||||
| 	); | 	); | ||||||
| 	assert(overhead > 0 && overhead < 512); | 	assert(overhead > 0 && overhead < 512); | ||||||
| @ -98,7 +98,7 @@ static void commandNotice(uint id, char *params) { | |||||||
| 
 | 
 | ||||||
| static void commandMe(uint id, char *params) { | static void commandMe(uint id, char *params) { | ||||||
| 	char buf[512]; | 	char buf[512]; | ||||||
| 	snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ? params : "")); | 	snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ?: "")); | ||||||
| 	echoMessage("PRIVMSG", id, buf); | 	echoMessage("PRIVMSG", id, buf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -129,7 +129,7 @@ static void commandPart(uint id, char *params) { | |||||||
| 
 | 
 | ||||||
| static void commandQuit(uint id, char *params) { | static void commandQuit(uint id, char *params) { | ||||||
| 	(void)id; | 	(void)id; | ||||||
| 	set(&self.quit, (params ? params : "nyaa~")); | 	set(&self.quit, (params ?: "nyaa~")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void commandNick(uint id, char *params) { | static void commandNick(uint id, char *params) { | ||||||
| @ -384,12 +384,11 @@ static void commandExec(uint id, char *params) { | |||||||
| 	if (pid < 0) err(EX_OSERR, "fork"); | 	if (pid < 0) err(EX_OSERR, "fork"); | ||||||
| 	if (pid) return; | 	if (pid) return; | ||||||
| 
 | 
 | ||||||
| 	const char *shell = getenv("SHELL"); |  | ||||||
| 	if (!shell) shell = "/bin/sh"; |  | ||||||
| 
 |  | ||||||
| 	close(STDIN_FILENO); | 	close(STDIN_FILENO); | ||||||
| 	dup2(execPipe[1], STDOUT_FILENO); | 	dup2(execPipe[1], STDOUT_FILENO); | ||||||
| 	dup2(utilPipe[1], STDERR_FILENO); | 	dup2(utilPipe[1], STDERR_FILENO); | ||||||
|  | 
 | ||||||
|  | 	const char *shell = getenv("SHELL") ?: "/bin/sh"; | ||||||
| 	execlp(shell, shell, "-c", params, NULL); | 	execlp(shell, shell, "-c", params, NULL); | ||||||
| 	warn("%s", shell); | 	warn("%s", shell); | ||||||
| 	_exit(EX_UNAVAILABLE); | 	_exit(EX_UNAVAILABLE); | ||||||
| @ -404,7 +403,7 @@ static void commandHelp(uint id, char *params) { | |||||||
| 	if (pid) return; | 	if (pid) return; | ||||||
| 
 | 
 | ||||||
| 	char buf[256]; | 	char buf[256]; | ||||||
| 	snprintf(buf, sizeof(buf), "ip%s$", (params ? params : "COMMANDS")); | 	snprintf(buf, sizeof(buf), "ip%s$", (params ?: "COMMANDS")); | ||||||
| 	setenv("LESS", buf, 1); | 	setenv("LESS", buf, 1); | ||||||
| 	execlp("man", "man", "1", "catgirl", NULL); | 	execlp("man", "man", "1", "catgirl", NULL); | ||||||
| 	dup2(utilPipe[1], STDERR_FILENO); | 	dup2(utilPipe[1], STDERR_FILENO); | ||||||
|  | |||||||
| @ -60,7 +60,7 @@ static struct Node *prepend(struct Node *node) { | |||||||
| 	node->next = head; | 	node->next = head; | ||||||
| 	if (head) head->prev = node; | 	if (head) head->prev = node; | ||||||
| 	head = node; | 	head = node; | ||||||
| 	if (!tail) tail = node; | 	tail = (tail ?: node); | ||||||
| 	return node; | 	return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -69,7 +69,7 @@ static struct Node *append(struct Node *node) { | |||||||
| 	node->prev = tail; | 	node->prev = tail; | ||||||
| 	if (tail) tail->next = node; | 	if (tail) tail->next = node; | ||||||
| 	tail = node; | 	tail = node; | ||||||
| 	if (!head) head = node; | 	head = (head ?: node); | ||||||
| 	return node; | 	return node; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										45
									
								
								handle.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								handle.c
									
									
									
									
									
								
							| @ -260,9 +260,9 @@ static void handleReplyISupport(struct Message *msg) { | |||||||
| 			set(&network.setParamModes, strsep(&msg->params[i], ",")); | 			set(&network.setParamModes, strsep(&msg->params[i], ",")); | ||||||
| 			set(&network.channelModes, strsep(&msg->params[i], ",")); | 			set(&network.channelModes, strsep(&msg->params[i], ",")); | ||||||
| 		} else if (!strcmp(key, "EXCEPTS")) { | 		} else if (!strcmp(key, "EXCEPTS")) { | ||||||
| 			network.excepts = (msg->params[i] ? msg->params[i][0] : 'e'); | 			network.excepts = (msg->params[i] ?: "e")[0]; | ||||||
| 		} else if (!strcmp(key, "INVEX")) { | 		} else if (!strcmp(key, "INVEX")) { | ||||||
| 			network.invex = (msg->params[i] ? msg->params[i][0] : 'I'); | 			network.invex = (msg->params[i] ?: "I")[0]; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -309,7 +309,7 @@ static void handleJoin(struct Message *msg) { | |||||||
| 		"\3%02d%s\3\t%s%s%sarrives in \3%02d%s\3", | 		"\3%02d%s\3\t%s%s%sarrives in \3%02d%s\3", | ||||||
| 		hash(msg->user), msg->nick, | 		hash(msg->user), msg->nick, | ||||||
| 		(msg->params[2] ? "(" : ""), | 		(msg->params[2] ? "(" : ""), | ||||||
| 		(msg->params[2] ? msg->params[2] : ""), | 		(msg->params[2] ?: ""), | ||||||
| 		(msg->params[2] ? ") " : ""), | 		(msg->params[2] ? ") " : ""), | ||||||
| 		hash(msg->params[0]), msg->params[0] | 		hash(msg->params[0]), msg->params[0] | ||||||
| 	); | 	); | ||||||
| @ -340,14 +340,12 @@ static void handlePart(struct Message *msg) { | |||||||
| 		id, ignoreCheck(Cold, msg), tagTime(msg), | 		id, ignoreCheck(Cold, msg), tagTime(msg), | ||||||
| 		"\3%02d%s\3\tleaves \3%02d%s\3%s%s", | 		"\3%02d%s\3\tleaves \3%02d%s\3%s%s", | ||||||
| 		hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0], | 		hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0], | ||||||
| 		(msg->params[1] ? ": " : ""), | 		(msg->params[1] ? ": " : ""), (msg->params[1] ?: "") | ||||||
| 		(msg->params[1] ? msg->params[1] : "") |  | ||||||
| 	); | 	); | ||||||
| 	logFormat( | 	logFormat( | ||||||
| 		id, tagTime(msg), "%s leaves %s%s%s", | 		id, tagTime(msg), "%s leaves %s%s%s", | ||||||
| 		msg->nick, msg->params[0], | 		msg->nick, msg->params[0], | ||||||
| 		(msg->params[1] ? ": " : ""), | 		(msg->params[1] ? ": " : ""), (msg->params[1] ?: "") | ||||||
| 		(msg->params[1] ? msg->params[1] : "") |  | ||||||
| 	); | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -364,14 +362,12 @@ static void handleKick(struct Message *msg) { | |||||||
| 		hash(msg->user), msg->nick, | 		hash(msg->user), msg->nick, | ||||||
| 		completeColor(id, msg->params[1]), msg->params[1], | 		completeColor(id, msg->params[1]), msg->params[1], | ||||||
| 		hash(msg->params[0]), msg->params[0], | 		hash(msg->params[0]), msg->params[0], | ||||||
| 		(msg->params[2] ? ": " : ""), | 		(msg->params[2] ? ": " : ""), (msg->params[2] ?: "") | ||||||
| 		(msg->params[2] ? msg->params[2] : "") |  | ||||||
| 	); | 	); | ||||||
| 	logFormat( | 	logFormat( | ||||||
| 		id, tagTime(msg), "%s kicks %s out of %s%s%s", | 		id, tagTime(msg), "%s kicks %s out of %s%s%s", | ||||||
| 		msg->nick, msg->params[1], msg->params[0], | 		msg->nick, msg->params[1], msg->params[0], | ||||||
| 		(msg->params[2] ? ": " : ""), | 		(msg->params[2] ? ": " : ""), (msg->params[2] ?: "") | ||||||
| 		(msg->params[2] ? msg->params[2] : "") |  | ||||||
| 	); | 	); | ||||||
| 	completeRemove(id, msg->params[1]); | 	completeRemove(id, msg->params[1]); | ||||||
| 	if (kicked) completeClear(id); | 	if (kicked) completeClear(id); | ||||||
| @ -409,15 +405,13 @@ static void handleQuit(struct Message *msg) { | |||||||
| 			id, ignoreCheck(Cold, msg), tagTime(msg), | 			id, ignoreCheck(Cold, msg), tagTime(msg), | ||||||
| 			"\3%02d%s\3\tleaves%s%s", | 			"\3%02d%s\3\tleaves%s%s", | ||||||
| 			hash(msg->user), msg->nick, | 			hash(msg->user), msg->nick, | ||||||
| 			(msg->params[0] ? ": " : ""), | 			(msg->params[0] ? ": " : ""), (msg->params[0] ?: "") | ||||||
| 			(msg->params[0] ? msg->params[0] : "") |  | ||||||
| 		); | 		); | ||||||
| 		if (id == Network) continue; | 		if (id == Network) continue; | ||||||
| 		logFormat( | 		logFormat( | ||||||
| 			id, tagTime(msg), "%s leaves%s%s", | 			id, tagTime(msg), "%s leaves%s%s", | ||||||
| 			msg->nick, | 			msg->nick, | ||||||
| 			(msg->params[0] ? ": " : ""), | 			(msg->params[0] ? ": " : ""), (msg->params[0] ?: "") | ||||||
| 			(msg->params[0] ? msg->params[0] : "") |  | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| 	completeRemove(None, msg->nick); | 	completeRemove(None, msg->nick); | ||||||
| @ -576,7 +570,7 @@ static void handleReplyUserModeIs(struct Message *msg) { | |||||||
| 		const char *name = UserModes[(byte)*ch]; | 		const char *name = UserModes[(byte)*ch]; | ||||||
| 		catf( | 		catf( | ||||||
| 			buf, sizeof(buf), ", +%c%s%s", | 			buf, sizeof(buf), ", +%c%s%s", | ||||||
| 			*ch, (name ? " " : ""), (name ? name : "") | 			*ch, (name ? " " : ""), (name ?: "") | ||||||
| 		); | 		); | ||||||
| 	} | 	} | ||||||
| 	uiFormat( | 	uiFormat( | ||||||
| @ -618,13 +612,13 @@ static void handleReplyChannelModeIs(struct Message *msg) { | |||||||
| 			assert(param < ParamCap); | 			assert(param < ParamCap); | ||||||
| 			catf( | 			catf( | ||||||
| 				buf, sizeof(buf), ", +%c%s%s %s", | 				buf, sizeof(buf), ", +%c%s%s %s", | ||||||
| 				*ch, (name ? " " : ""), (name ? name : ""), | 				*ch, (name ? " " : ""), (name ?: ""), | ||||||
| 				msg->params[param++] | 				msg->params[param++] | ||||||
| 			); | 			); | ||||||
| 		} else { | 		} else { | ||||||
| 			catf( | 			catf( | ||||||
| 				buf, sizeof(buf), ", +%c%s%s", | 				buf, sizeof(buf), ", +%c%s%s", | ||||||
| 				*ch, (name ? " " : ""), (name ? name : "") | 				*ch, (name ? " " : ""), (name ?: "") | ||||||
| 			); | 			); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -651,7 +645,7 @@ static void handleMode(struct Message *msg) { | |||||||
| 				hash(msg->user), msg->nick, | 				hash(msg->user), msg->nick, | ||||||
| 				(set ? "" : "un"), | 				(set ? "" : "un"), | ||||||
| 				self.color, msg->params[0], | 				self.color, msg->params[0], | ||||||
| 				set["-+"], *ch, (name ? " " : ""), (name ? name : "") | 				set["-+"], *ch, (name ? " " : ""), (name ?: "") | ||||||
| 			); | 			); | ||||||
| 		} | 		} | ||||||
| 		return; | 		return; | ||||||
| @ -800,7 +794,7 @@ static void handleErrorBanListFull(struct Message *msg) { | |||||||
| 	require(msg, false, 4); | 	require(msg, false, 4); | ||||||
| 	uiFormat( | 	uiFormat( | ||||||
| 		idFor(msg->params[1]), Cold, tagTime(msg), | 		idFor(msg->params[1]), Cold, tagTime(msg), | ||||||
| 		"%s", (msg->params[4] ? msg->params[4] : msg->params[3]) | 		"%s", (msg->params[4] ?: msg->params[3]) | ||||||
| 	); | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -933,15 +927,14 @@ static void handleReplyWhoisIdle(struct Message *msg) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	char signon[sizeof("0000-00-00 00:00:00")]; | 	char signon[sizeof("0000-00-00 00:00:00")]; | ||||||
| 	time_t time = (msg->params[3] ? strtol(msg->params[3], NULL, 10) : 0); | 	time_t time = strtol((msg->params[3] ?: ""), NULL, 10); | ||||||
| 	strftime(signon, sizeof(signon), "%F %T", localtime(&time)); | 	strftime(signon, sizeof(signon), "%F %T", localtime(&time)); | ||||||
| 	uiFormat( | 	uiFormat( | ||||||
| 		Network, Warm, tagTime(msg), | 		Network, Warm, tagTime(msg), | ||||||
| 		"\3%02d%s\3\tis idle for %lu %s%s%s%s", | 		"\3%02d%s\3\tis idle for %lu %s%s%s%s", | ||||||
| 		completeColor(Network, msg->params[1]), msg->params[1], | 		completeColor(Network, msg->params[1]), msg->params[1], | ||||||
| 		idle, unit, (idle != 1 ? "s" : ""), | 		idle, unit, (idle != 1 ? "s" : ""), | ||||||
| 		(msg->params[3] ? ", signed on " : ""), | 		(msg->params[3] ? ", signed on " : ""), (msg->params[3] ? signon : "") | ||||||
| 		(msg->params[3] ? signon : "") |  | ||||||
| 	); | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -976,9 +969,7 @@ static void handleReplyWhoisGeneric(struct Message *msg) { | |||||||
| 		Network, Warm, tagTime(msg), | 		Network, Warm, tagTime(msg), | ||||||
| 		"\3%02d%s\3\t%s%s%s", | 		"\3%02d%s\3\t%s%s%s", | ||||||
| 		completeColor(Network, msg->params[1]), msg->params[1], | 		completeColor(Network, msg->params[1]), msg->params[1], | ||||||
| 		msg->params[2], | 		msg->params[2], (msg->params[3] ? " " : ""), (msg->params[3] ?: "") | ||||||
| 		(msg->params[3] ? " " : ""), |  | ||||||
| 		(msg->params[3] ? msg->params[3] : "") |  | ||||||
| 	); | 	); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -1031,7 +1022,7 @@ static bool isMention(const struct Message *msg) { | |||||||
| 	const char *match = msg->params[1]; | 	const char *match = msg->params[1]; | ||||||
| 	while (NULL != (match = strcasestr(match, self.nick))) { | 	while (NULL != (match = strcasestr(match, self.nick))) { | ||||||
| 		char a = (match > msg->params[1] ? match[-1] : ' '); | 		char a = (match > msg->params[1] ? match[-1] : ' '); | ||||||
| 		char b = (match[len] ? match[len] : ' '); | 		char b = (match[len] ?: ' '); | ||||||
| 		if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) { | 		if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) { | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								ignore.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								ignore.c
									
									
									
									
									
								
							| @ -62,8 +62,7 @@ enum Heat ignoreCheck(enum Heat heat, const struct Message *msg) { | |||||||
| 	char match[512]; | 	char match[512]; | ||||||
| 	snprintf( | 	snprintf( | ||||||
| 		match, sizeof(match), "%s!%s@%s %s %s", | 		match, sizeof(match), "%s!%s@%s %s %s", | ||||||
| 		msg->nick, msg->user, msg->host, msg->cmd, | 		msg->nick, msg->user, msg->host, msg->cmd, (msg->params[0] ?: "") | ||||||
| 		(msg->params[0] ? msg->params[0] : "") |  | ||||||
| 	); | 	); | ||||||
| 	for (size_t i = 0; i < ignore.len; ++i) { | 	for (size_t i = 0; i < ignore.len; ++i) { | ||||||
| 		if (fnmatch(ignore.patterns[i], match, FNM_CASEFOLD)) continue; | 		if (fnmatch(ignore.patterns[i], match, FNM_CASEFOLD)) continue; | ||||||
|  | |||||||
							
								
								
									
										7
									
								
								ui.c
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								ui.c
									
									
									
									
									
								
							| @ -891,6 +891,7 @@ static void keyCode(int code) { | |||||||
| 		break; case KeyMetaMinus: window->ignore ^= true; reflow(window); | 		break; case KeyMetaMinus: window->ignore ^= true; reflow(window); | ||||||
| 		break; case KeyMetaSlash: windowShow(windows.swap); | 		break; case KeyMetaSlash: windowShow(windows.swap); | ||||||
| 
 | 
 | ||||||
|  | 		break; case KeyMeta0 ... KeyMeta9: uiShowNum(code - KeyMeta0); | ||||||
| 		break; case KeyMetaA: showAuto(); | 		break; case KeyMetaA: showAuto(); | ||||||
| 		break; case KeyMetaB: edit(id, EditPrevWord, 0); | 		break; case KeyMetaB: edit(id, EditPrevWord, 0); | ||||||
| 		break; case KeyMetaD: edit(id, EditDeleteNextWord, 0); | 		break; case KeyMetaD: edit(id, EditDeleteNextWord, 0); | ||||||
| @ -911,12 +912,6 @@ static void keyCode(int code) { | |||||||
| 		break; case KEY_PPAGE: windowScroll(window, +(PAGE_LINES - 2)); | 		break; case KEY_PPAGE: windowScroll(window, +(PAGE_LINES - 2)); | ||||||
| 		break; case KEY_RIGHT: edit(id, EditNext, 0); | 		break; case KEY_RIGHT: edit(id, EditNext, 0); | ||||||
| 		break; case KEY_UP: windowScroll(window, +1); | 		break; case KEY_UP: windowScroll(window, +1); | ||||||
| 		 |  | ||||||
| 		break; default: { |  | ||||||
| 			if (code >= KeyMeta0 && code <= KeyMeta9) { |  | ||||||
| 				uiShowNum(code - KeyMeta0); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user