git: 87b0195ace1a - main - ctags: Use C99 bool instead of defining our own

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 19 Apr 2024 18:48:55 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=87b0195ace1a71a1a07244890be3aaef72e1ffcd

commit 87b0195ace1a71a1a07244890be3aaef72e1ffcd
Author:     Collin Funk <collin.funk1@gmail.com>
AuthorDate: 2024-02-07 00:34:50 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-04-19 18:48:37 +0000

    ctags: Use C99 bool instead of defining our own
    
    Use stdbool.h definitions instead of defining non-standard ones.
    
    Signed-off-by: Collin Funk <collin.funk1@gmail.com>
    
    Reviewed by:    markj
    MFC after:      2 weeks
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1107
---
 usr.bin/ctags/C.c       | 76 ++++++++++++++++++++++++-------------------------
 usr.bin/ctags/ctags.c   | 22 +++++++-------
 usr.bin/ctags/ctags.h   | 11 ++++---
 usr.bin/ctags/fortran.c | 12 ++++----
 usr.bin/ctags/lisp.c    |  8 +++---
 usr.bin/ctags/tree.c    |  2 +-
 usr.bin/ctags/yacc.c    | 10 +++----
 7 files changed, 70 insertions(+), 71 deletions(-)

diff --git a/usr.bin/ctags/C.c b/usr.bin/ctags/C.c
index 283a08ec555d..20a2cf072aa9 100644
--- a/usr.bin/ctags/C.c
+++ b/usr.bin/ctags/C.c
@@ -37,10 +37,10 @@
 
 #include "ctags.h"
 
-static int	func_entry(void);
+static bool	func_entry(void);
 static void	hash_entry(void);
 static void	skip_string(int);
-static int	str_entry(int);
+static bool	str_entry(int);
 
 /*
  * c_entries --
@@ -52,13 +52,13 @@ c_entries(void)
 	int	c;			/* current character */
 	int	level;			/* brace level */
 	int	token;			/* if reading a token */
-	int	t_def;			/* if reading a typedef */
+	bool	t_def;			/* if reading a typedef */
 	int	t_level;		/* typedef's brace level */
 	char	*sp;			/* buffer pointer */
 	char	tok[MAXTOKEN];		/* token buffer */
 
 	lineftell = ftell(inf);
-	sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
+	sp = tok; token = t_def = false; t_level = -1; level = 0; lineno = 1;
 	while (GETC(!=, EOF)) {
 		switch (c) {
 		/*
@@ -92,11 +92,11 @@ c_entries(void)
 			 */
 	endtok:			if (sp > tok) {
 				*sp = EOS;
-				token = YES;
+				token = true;
 				sp = tok;
 			}
 			else
-				token = NO;
+				token = false;
 			continue;
 
 		/*
@@ -174,7 +174,7 @@ c_entries(void)
 		 */
 		case ';':
 			if (t_def && level == t_level) {
-				t_def = NO;
+				t_def = false;
 				get_line();
 				if (sp != tok)
 					*sp = EOS;
@@ -207,7 +207,7 @@ c_entries(void)
 					/* no typedefs inside typedefs */
 					if (!t_def &&
 						   !memcmp(tok, "typedef",8)) {
-						t_def = YES;
+						t_def = true;
 						t_level = level;
 						break;
 					}
@@ -233,15 +233,15 @@ c_entries(void)
 				if (sp == tok + sizeof tok - 1)
 					/* Too long -- truncate it */
 					*sp = EOS;
-				else 
+				else
 					*sp++ = c;
-				token = YES;
+				token = true;
 			}
 			continue;
 		}
 
 		sp = tok;
-		token = NO;
+		token = false;
 	}
 }
 
@@ -249,7 +249,7 @@ c_entries(void)
  * func_entry --
  *	handle a function reference
  */
-static int
+static bool
 func_entry(void)
 {
 	int	c;			/* current character */
@@ -287,7 +287,7 @@ func_entry(void)
 			SETLINE;
 		}
 	}
-	return (NO);
+	return (false);
 fnd:
 	/*
 	 * we assume that the character after a function's right paren
@@ -299,7 +299,7 @@ fnd:
 			if (c == '\n')
 				SETLINE;
 		if (c == EOF)
-			return NO;
+			return false;
 		/*
 		 * Recognize the gnu __attribute__ extension, which would
 		 * otherwise make the heuristic test DTWT
@@ -311,7 +311,7 @@ fnd:
 			}
 		} else {
 			if (intoken(c)) {
-				if (anext - maybe_attribute 
+				if (anext - maybe_attribute
 				 < (ptrdiff_t)(sizeof attribute - 1))
 					*anext++ = c;
 				else	break;
@@ -320,7 +320,7 @@ fnd:
 				*anext++ = '\0';
 				if (strcmp(maybe_attribute, attribute) == 0) {
 					(void)ungetc(c, inf);
-					return NO;
+					return false;
 				}
 				break;
 			}
@@ -331,12 +331,12 @@ fnd:
 			skip_comment(c);
 		else {				/* don't ever "read" '/' */
 			(void)ungetc(c, inf);
-			return (NO);
+			return (false);
 		}
 	}
 	if (c != '{')
 		(void)skip_key('{');
-	return (YES);
+	return (true);
 }
 
 /*
@@ -365,7 +365,7 @@ hash_entry(void)
 		if (sp == tok + sizeof tok - 1)
 			/* Too long -- truncate it */
 			*sp = EOS;
-		else 
+		else
 			*sp++ = c;
 	}
 	*sp = EOS;
@@ -381,7 +381,7 @@ hash_entry(void)
 		if (sp == tok + sizeof tok - 1)
 			/* Too long -- truncate it */
 			*sp = EOS;
-		else 
+		else
 			*sp++ = c;
 		if (GETC(==, EOF))
 			return;
@@ -409,7 +409,7 @@ skip:	if (c == '\n') {		/* get rid of rest of define */
  * str_entry --
  *	handle a struct, union or enum entry
  */
-static int
+static bool
 str_entry(int c) /* c is current character */
 {
 	int	curline;		/* line started on */
@@ -419,17 +419,17 @@ str_entry(int c) /* c is current character */
 	curline = lineno;
 	while (iswhite(c))
 		if (GETC(==, EOF))
-			return (NO);
+			return (false);
 	if (c == '{')		/* it was "struct {" */
-		return (YES);
+		return (true);
 	for (sp = tok;;) {		/* get next token */
 		if (sp == tok + sizeof tok - 1)
 			/* Too long -- truncate it */
 			*sp = EOS;
-		else 
+		else
 			*sp++ = c;
 		if (GETC(==, EOF))
-			return (NO);
+			return (false);
 		if (!intoken(c))
 			break;
 	}
@@ -446,12 +446,12 @@ str_entry(int c) /* c is current character */
 					break;
 			if (c != '{') {
 				(void)ungetc(c, inf);
-				return (NO);
+				return (false);
 			}
 	}
 	*sp = EOS;
 	pfnote(tok, curline);
-	return (YES);
+	return (true);
 }
 
 /*
@@ -468,7 +468,7 @@ skip_comment(int t) /* t is comment character */
 		switch(c) {
 		/* comments don't nest, nor can they be escaped. */
 		case '*':
-			star = YES;
+			star = true;
 			break;
 		case '/':
 			if (star && t == '*')
@@ -480,7 +480,7 @@ skip_comment(int t) /* t is comment character */
 				return;
 			/*FALLTHROUGH*/
 		default:
-			star = NO;
+			star = false;
 			break;
 		}
 }
@@ -495,7 +495,7 @@ skip_string(int key)
 	int	c,
 		skip;
 
-	for (skip = NO; GETC(!=, EOF); )
+	for (skip = false; GETC(!=, EOF); )
 		switch (c) {
 		case '\\':		/* a backslash escapes anything */
 			skip = !skip;	/* we toggle in case it's "\\" */
@@ -506,7 +506,7 @@ skip_string(int key)
 		default:
 			if (c == key && !skip)
 				return;
-			skip = NO;
+			skip = false;
 		}
 }
 
@@ -514,21 +514,21 @@ skip_string(int key)
  * skip_key --
  *	skip to next char "key"
  */
-int
+bool
 skip_key(int key)
 {
-	int	c,
-		skip,
-		retval;
+	int	c;
+	bool	skip;
+	bool	retval;
 
-	for (skip = retval = NO; GETC(!=, EOF);)
+	for (skip = retval = false; GETC(!=, EOF);)
 		switch(c) {
 		case '\\':		/* a backslash escapes anything */
 			skip = !skip;	/* we toggle in case it's "\\" */
 			break;
 		case ';':		/* special case for yacc; if one */
 		case '|':		/* of these chars occurs, we may */
-			retval = YES;	/* have moved out of the rule */
+			retval = true;	/* have moved out of the rule */
 			break;		/* not used by C */
 		case '\'':
 		case '"':
@@ -551,7 +551,7 @@ skip_key(int key)
 		norm:
 			if (c == key && !skip)
 				return (retval);
-			skip = NO;
+			skip = false;
 		}
 	return (retval);
 }
diff --git a/usr.bin/ctags/ctags.c b/usr.bin/ctags/ctags.c
index 1f8966a409db..b8d642520466 100644
--- a/usr.bin/ctags/ctags.c
+++ b/usr.bin/ctags/ctags.c
@@ -86,8 +86,8 @@ main(int argc, char **argv)
 
 	setlocale(LC_ALL, "");
 
-	aflag = uflag = NO;
-	tflag = YES;
+	aflag = uflag = false;
+	tflag = true;
 	while ((ch = getopt(argc, argv, "BFTadf:tuwvx")) != -1)
 		switch(ch) {
 		case 'B':
@@ -97,7 +97,7 @@ main(int argc, char **argv)
 			searchar = '/';
 			break;
 		case 'T':
-			tflag = NO;
+			tflag = false;
 			break;
 		case 'a':
 			aflag++;
@@ -109,7 +109,7 @@ main(int argc, char **argv)
 			outfile = optarg;
 			break;
 		case 't':
-			tflag = YES;
+			tflag = true;
 			break;
 		case 'u':
 			uflag++;
@@ -251,24 +251,24 @@ init(void)
 	const unsigned char	*sp;
 
 	for (i = 0; i < 256; i++) {
-		_wht[i] = _etk[i] = _itk[i] = _btk[i] = NO;
-		_gd[i] = YES;
+		_wht[i] = _etk[i] = _itk[i] = _btk[i] = false;
+		_gd[i] = true;
 	}
 #define	CWHITE	" \f\t\n"
 	for (sp = CWHITE; *sp; sp++)	/* white space chars */
-		_wht[*sp] = YES;
+		_wht[*sp] = true;
 #define	CTOKEN	" \t\n\"'#()[]{}=-+%*/&|^~!<>;,.:?"
 	for (sp = CTOKEN; *sp; sp++)	/* token ending chars */
-		_etk[*sp] = YES;
+		_etk[*sp] = true;
 #define	CINTOK	"ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789"
 	for (sp = CINTOK; *sp; sp++)	/* valid in-token chars */
-		_itk[*sp] = YES;
+		_itk[*sp] = true;
 #define	CBEGIN	"ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
 	for (sp = CBEGIN; *sp; sp++)	/* token starting chars */
-		_btk[*sp] = YES;
+		_btk[*sp] = true;
 #define	CNOTGD	",;"
 	for (sp = CNOTGD; *sp; sp++)	/* invalid after-function chars */
-		_gd[*sp] = NO;
+		_gd[*sp] = false;
 }
 
 /*
diff --git a/usr.bin/ctags/ctags.h b/usr.bin/ctags/ctags.h
index c9a7539b277a..b74bf7ea7602 100644
--- a/usr.bin/ctags/ctags.h
+++ b/usr.bin/ctags/ctags.h
@@ -30,10 +30,9 @@
  *
  */
 
-#define	bool	char
+/* This header requires bool for some externed symbols. */
+#include <stdbool.h>
 
-#define	YES		1
-#define	NO		0
 #define	EOS		'\0'
 
 #define	ENDLINE		50		/* max length of pattern */
@@ -81,14 +80,14 @@ extern char	lbuf[LINE_MAX];
 extern char    *lbp;
 extern char	searchar;		/* ex search character */
 
-extern int	cicmp(const char *);
+extern bool	cicmp(const char *);
 extern void	get_line(void);
 extern void	pfnote(const char *, int);
-extern int	skip_key(int);
+extern bool	skip_key(int);
 extern void	put_entries(NODE *);
 extern void	toss_yysec(void);
 extern void	l_entries(void);
 extern void	y_entries(void);
-extern int	PF_funcs(void);
+extern bool	PF_funcs(void);
 extern void	c_entries(void);
 extern void	skip_comment(int);
diff --git a/usr.bin/ctags/fortran.c b/usr.bin/ctags/fortran.c
index 55d8d824f568..4375076f5914 100644
--- a/usr.bin/ctags/fortran.c
+++ b/usr.bin/ctags/fortran.c
@@ -41,14 +41,14 @@ static void takeprec(void);
 
 char *lbp;				/* line buffer pointer */
 
-int
+bool
 PF_funcs(void)
 {
 	bool	pfcnt;			/* pascal/fortran functions found */
 	char	*cp;
 	char	tok[MAXTOKEN];
 
-	for (pfcnt = NO;;) {
+	for (pfcnt = false;;) {
 		lineftell = ftell(inf);
 		if (!fgets(lbuf, sizeof(lbuf), inf))
 			return (pfcnt);
@@ -120,7 +120,7 @@ PF_funcs(void)
 		(void)strlcpy(tok, lbp, sizeof(tok));	/* possible trunc */
 		get_line();			/* process line for ex(1) */
 		pfnote(tok, lineno);
-		pfcnt = YES;
+		pfcnt = true;
 	}
 	/*NOTREACHED*/
 }
@@ -129,7 +129,7 @@ PF_funcs(void)
  * cicmp --
  *	do case-independent strcmp
  */
-int
+bool
 cicmp(const char *cp)
 {
 	int	len;
@@ -140,9 +140,9 @@ cicmp(const char *cp)
 		continue;
 	if (!*cp) {
 		lbp += len;
-		return (YES);
+		return (true);
 	}
-	return (NO);
+	return (false);
 }
 
 static void
diff --git a/usr.bin/ctags/lisp.c b/usr.bin/ctags/lisp.c
index e219fcee4634..e721bf8f757d 100644
--- a/usr.bin/ctags/lisp.c
+++ b/usr.bin/ctags/lisp.c
@@ -44,7 +44,7 @@
 void
 l_entries(void)
 {
-	int	special;
+	bool	special;
 	char	*cp;
 	char	savedc;
 	char	tok[MAXTOKEN];
@@ -57,15 +57,15 @@ l_entries(void)
 		lbp = lbuf;
 		if (!cicmp("(def"))
 			continue;
-		special = NO;
+		special = false;
 		switch(*lbp | ' ') {
 		case 'm':
 			if (cicmp("method"))
-				special = YES;
+				special = true;
 			break;
 		case 'w':
 			if (cicmp("wrapper") || cicmp("whopper"))
-				special = YES;
+				special = true;
 		}
 		for (; !isspace(*lbp); ++lbp)
 			continue;
diff --git a/usr.bin/ctags/tree.c b/usr.bin/ctags/tree.c
index e8250bcbcf67..7643d1895b93 100644
--- a/usr.bin/ctags/tree.c
+++ b/usr.bin/ctags/tree.c
@@ -100,7 +100,7 @@ add_node(NODE *node, NODE *cur_node)
 		if (!cur_node->been_warned)
 			if (!wflag)
 				fprintf(stderr, "Duplicate entry in files %s and %s: %s (Warning only)\n", node->file, cur_node->file, node->entry);
-		cur_node->been_warned = YES;
+		cur_node->been_warned = true;
 	}
 	else if (dif < 0)
 		if (cur_node->left)
diff --git a/usr.bin/ctags/yacc.c b/usr.bin/ctags/yacc.c
index 502fbc98b714..71dddaa36f67 100644
--- a/usr.bin/ctags/yacc.c
+++ b/usr.bin/ctags/yacc.c
@@ -48,7 +48,7 @@ y_entries(void)
 	bool	in_rule;
 	char	tok[MAXTOKEN];
 
-	in_rule = NO;
+	in_rule = false;
 
 	while (GETC(!=, EOF))
 		switch (c) {
@@ -62,12 +62,12 @@ y_entries(void)
 			break;
 		case '{':
 			if (skip_key('}'))
-				in_rule = NO;
+				in_rule = false;
 			break;
 		case '\'':
 		case '"':
 			if (skip_key(c))
-				in_rule = NO;
+				in_rule = false;
 			break;
 		case '%':
 			if (GETC(==, '%'))
@@ -82,7 +82,7 @@ y_entries(void)
 			break;
 		case '|':
 		case ';':
-			in_rule = NO;
+			in_rule = false;
 			break;
 		default:
 			if (in_rule || (!isalpha(c) && c != '.' && c != '_'))
@@ -101,7 +101,7 @@ y_entries(void)
 			}
 			if (c == ':') {
 				pfnote(tok, lineno);
-				in_rule = YES;
+				in_rule = true;
 			}
 			else
 				(void)ungetc(c, inf);