Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/ctags/C.c
Show All 33 Lines | |||||
static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94"; | static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94"; | ||||
#endif | #endif | ||||
#endif | #endif | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <stddef.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "ctags.h" | #include "ctags.h" | ||||
static int func_entry(void); | static int func_entry(void); | ||||
static void hash_entry(void); | static void hash_entry(void); | ||||
static void skip_string(int); | static void skip_string(int); | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | |||||
* func_entry -- | * func_entry -- | ||||
* handle a function reference | * handle a function reference | ||||
*/ | */ | ||||
static int | static int | ||||
func_entry(void) | func_entry(void) | ||||
{ | { | ||||
int c; /* current character */ | int c; /* current character */ | ||||
int level = 0; /* for matching '()' */ | int level = 0; /* for matching '()' */ | ||||
static char attribute[] = "__attribute__"; | |||||
char maybe_attribute[sizeof attribute + 1], | |||||
kevans: Why `+ 1`? `sizeof attribute` should already account for the nul byte and the arithmetic below… | |||||
Done Inline ActionsI know but that's how it is upstream. I'm probably going to refactor it soon anyway. des: I know but that's how it is upstream. I'm probably going to refactor it soon anyway. | |||||
*anext; | |||||
/* | /* | ||||
* Find the end of the assumed function declaration. | * Find the end of the assumed function declaration. | ||||
* Note that ANSI C functions can have type definitions so keep | * Note that ANSI C functions can have type definitions so keep | ||||
* track of the parentheses nesting level. | * track of the parentheses nesting level. | ||||
*/ | */ | ||||
while (GETC(!=, EOF)) { | while (GETC(!=, EOF)) { | ||||
switch (c) { | switch (c) { | ||||
Show All 21 Lines | func_entry(void) | ||||
} | } | ||||
return (NO); | return (NO); | ||||
fnd: | fnd: | ||||
/* | /* | ||||
* we assume that the character after a function's right paren | * we assume that the character after a function's right paren | ||||
* is a token character if it's a function and a non-token | * is a token character if it's a function and a non-token | ||||
* character if it's a declaration. Comments don't count... | * character if it's a declaration. Comments don't count... | ||||
*/ | */ | ||||
for (;;) { | for (anext = maybe_attribute;;) { | ||||
while (GETC(!=, EOF) && iswhite(c)) | while (GETC(!=, EOF) && iswhite(c)) | ||||
if (c == '\n') | if (c == '\n') | ||||
SETLINE; | SETLINE; | ||||
if (c == EOF) | |||||
return NO; | |||||
/* | |||||
* Recognize the gnu __attribute__ extension, which would | |||||
* otherwise make the heuristic test DTWT | |||||
*/ | |||||
if (anext == maybe_attribute) { | |||||
if (intoken(c)) { | |||||
*anext++ = c; | |||||
continue; | |||||
} | |||||
} else { | |||||
if (intoken(c)) { | |||||
if (anext - maybe_attribute | |||||
< (ptrdiff_t)(sizeof attribute - 1)) | |||||
*anext++ = c; | |||||
else break; | |||||
continue; | |||||
} else { | |||||
*anext++ = '\0'; | |||||
if (strcmp(maybe_attribute, attribute) == 0) { | |||||
(void)ungetc(c, inf); | |||||
return NO; | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
if (intoken(c) || c == '{') | if (intoken(c) || c == '{') | ||||
break; | break; | ||||
if (c == '/' && (GETC(==, '*') || c == '/')) | if (c == '/' && (GETC(==, '*') || c == '/')) | ||||
skip_comment(c); | skip_comment(c); | ||||
else { /* don't ever "read" '/' */ | else { /* don't ever "read" '/' */ | ||||
(void)ungetc(c, inf); | (void)ungetc(c, inf); | ||||
return (NO); | return (NO); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |
Why + 1? sizeof attribute should already account for the nul byte and the arithmetic below seems to acknowledge that