git: ebc5b3b08560 - stable/14 - ctags: Use C99 bool instead of defining our own
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 08 May 2024 13:07:42 UTC
The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ebc5b3b08560d900f5013038d0fd1bb484a4f187 commit ebc5b3b08560d900f5013038d0fd1bb484a4f187 Author: Collin Funk <collin.funk1@gmail.com> AuthorDate: 2024-02-07 00:34:50 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-05-08 13:06:15 +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 (cherry picked from commit 87b0195ace1a71a1a07244890be3aaef72e1ffcd) --- 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 25c5db5d405b..725336d33e01 100644 --- a/usr.bin/ctags/C.c +++ b/usr.bin/ctags/C.c @@ -43,10 +43,10 @@ static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94"; #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 -- @@ -58,13 +58,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) { /* @@ -98,11 +98,11 @@ c_entries(void) */ endtok: if (sp > tok) { *sp = EOS; - token = YES; + token = true; sp = tok; } else - token = NO; + token = false; continue; /* @@ -180,7 +180,7 @@ c_entries(void) */ case ';': if (t_def && level == t_level) { - t_def = NO; + t_def = false; get_line(); if (sp != tok) *sp = EOS; @@ -213,7 +213,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; } @@ -239,15 +239,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; } } @@ -255,7 +255,7 @@ c_entries(void) * func_entry -- * handle a function reference */ -static int +static bool func_entry(void) { int c; /* current character */ @@ -293,7 +293,7 @@ func_entry(void) SETLINE; } } - return (NO); + return (false); fnd: /* * we assume that the character after a function's right paren @@ -305,7 +305,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 @@ -317,7 +317,7 @@ fnd: } } else { if (intoken(c)) { - if (anext - maybe_attribute + if (anext - maybe_attribute < (ptrdiff_t)(sizeof attribute - 1)) *anext++ = c; else break; @@ -326,7 +326,7 @@ fnd: *anext++ = '\0'; if (strcmp(maybe_attribute, attribute) == 0) { (void)ungetc(c, inf); - return NO; + return false; } break; } @@ -337,12 +337,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); } /* @@ -371,7 +371,7 @@ hash_entry(void) if (sp == tok + sizeof tok - 1) /* Too long -- truncate it */ *sp = EOS; - else + else *sp++ = c; } *sp = EOS; @@ -387,7 +387,7 @@ hash_entry(void) if (sp == tok + sizeof tok - 1) /* Too long -- truncate it */ *sp = EOS; - else + else *sp++ = c; if (GETC(==, EOF)) return; @@ -415,7 +415,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 */ @@ -425,17 +425,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; } @@ -452,12 +452,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); } /* @@ -474,7 +474,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 == '*') @@ -486,7 +486,7 @@ skip_comment(int t) /* t is comment character */ return; /*FALLTHROUGH*/ default: - star = NO; + star = false; break; } } @@ -501,7 +501,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 "\\" */ @@ -512,7 +512,7 @@ skip_string(int key) default: if (c == key && !skip) return; - skip = NO; + skip = false; } } @@ -520,21 +520,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 '"': @@ -557,7 +557,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 6053a52f32da..686acd0f9cdf 100644 --- a/usr.bin/ctags/ctags.c +++ b/usr.bin/ctags/ctags.c @@ -99,8 +99,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': @@ -110,7 +110,7 @@ main(int argc, char **argv) searchar = '/'; break; case 'T': - tflag = NO; + tflag = false; break; case 'a': aflag++; @@ -122,7 +122,7 @@ main(int argc, char **argv) outfile = optarg; break; case 't': - tflag = YES; + tflag = true; break; case 'u': uflag++; @@ -264,24 +264,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 8892733d650f..5079353a8136 100644 --- a/usr.bin/ctags/ctags.h +++ b/usr.bin/ctags/ctags.h @@ -32,10 +32,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 */ @@ -83,14 +82,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 7fa6ec3823d9..56ae3b66458b 100644 --- a/usr.bin/ctags/fortran.c +++ b/usr.bin/ctags/fortran.c @@ -47,14 +47,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); @@ -126,7 +126,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*/ } @@ -135,7 +135,7 @@ PF_funcs(void) * cicmp -- * do case-independent strcmp */ -int +bool cicmp(const char *cp) { int len; @@ -146,9 +146,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 d167c82e7c69..bd6100709299 100644 --- a/usr.bin/ctags/lisp.c +++ b/usr.bin/ctags/lisp.c @@ -50,7 +50,7 @@ static char sccsid[] = "@(#)lisp.c 8.3 (Berkeley) 4/2/94"; void l_entries(void) { - int special; + bool special; char *cp; char savedc; char tok[MAXTOKEN]; @@ -63,15 +63,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 15291f4a5e80..c3cfabc6e25f 100644 --- a/usr.bin/ctags/tree.c +++ b/usr.bin/ctags/tree.c @@ -106,7 +106,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 0fd8537fb74f..e30ea0eacad0 100644 --- a/usr.bin/ctags/yacc.c +++ b/usr.bin/ctags/yacc.c @@ -54,7 +54,7 @@ y_entries(void) bool in_rule; char tok[MAXTOKEN]; - in_rule = NO; + in_rule = false; while (GETC(!=, EOF)) switch (c) { @@ -68,12 +68,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(==, '%')) @@ -88,7 +88,7 @@ y_entries(void) break; case '|': case ';': - in_rule = NO; + in_rule = false; break; default: if (in_rule || (!isalpha(c) && c != '.' && c != '_')) @@ -107,7 +107,7 @@ y_entries(void) } if (c == ':') { pfnote(tok, lineno); - in_rule = YES; + in_rule = true; } else (void)ungetc(c, inf);