=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ctags/C.c,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/ctags/C.c 2002/02/16 21:27:45 1.7 --- src/usr.bin/ctags/C.c 2003/05/12 20:41:39 1.8 *************** *** 1,4 **** ! /* $OpenBSD: C.c,v 1.7 2002/02/16 21:27:45 millert Exp $ */ /* $NetBSD: C.c,v 1.3 1995/03/26 20:14:02 glass Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: C.c,v 1.8 2003/05/12 20:41:39 pjanzen Exp $ */ /* $NetBSD: C.c,v 1.3 1995/03/26 20:14:02 glass Exp $ */ /* *************** *** 38,44 **** #if 0 static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94"; #else ! static char rcsid[] = "$OpenBSD: C.c,v 1.7 2002/02/16 21:27:45 millert Exp $"; #endif #endif /* not lint */ --- 38,44 ---- #if 0 static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94"; #else ! static char rcsid[] = "$OpenBSD: C.c,v 1.8 2003/05/12 20:41:39 pjanzen Exp $"; #endif #endif /* not lint */ *************** *** 126,133 **** */ case '/': if (GETC(==, '*')) { ! skip_comment(); continue; } (void)ungetc(c, inf); c = '/'; --- 126,136 ---- */ case '/': if (GETC(==, '*')) { ! skip_comment(c); continue; + } else if (c == '/') { + skip_comment(c); + continue; } (void)ungetc(c, inf); c = '/'; *************** *** 146,151 **** --- 149,161 ---- * level zero indicates a function. */ case '(': + do { + c = getc(inf); + } while (iswhite(c)); + if (c == '*') + break; + else + ungetc(c, inf); if (!level && token) { int curline; *************** *** 270,275 **** --- 280,288 ---- { int c; /* current character */ int level = 0; /* for matching '()' */ + static char attribute[] = "__attribute__"; + char maybe_attribute[sizeof attribute + 1]; + char *anext; /* * Find the end of the assumed function declaration. *************** *** 286,292 **** case '/': /* skip comments */ if (GETC(==, '*')) ! skip_comment(); break; case '(': level++; --- 299,307 ---- case '/': /* skip comments */ if (GETC(==, '*')) ! skip_comment(c); ! else if (c == '/') ! skip_comment(c); break; case '(': level++; *************** *** 307,320 **** * is a token character if it's a function and a non-token * character if it's a declaration. Comments don't count... */ ! for (;;) { while (GETC(!=, EOF) && iswhite(c)) if (c == '\n') SETLINE; if (intoken(c) || c == '{') break; if (c == '/' && GETC(==, '*')) ! skip_comment(); else { /* don't ever "read" '/' */ (void)ungetc(c, inf); return (NO); --- 322,364 ---- * is a token character if it's a function and a non-token * character if it's a declaration. Comments don't count... */ ! for (anext = maybe_attribute;;) { while (GETC(!=, EOF) && iswhite(c)) if (c == '\n') 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 < (int)(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 == '{') break; if (c == '/' && GETC(==, '*')) ! skip_comment(c); ! else if (c == '/') ! skip_comment(c); else { /* don't ever "read" '/' */ (void)ungetc(c, inf); return (NO); *************** *** 449,455 **** * skip over comment */ void ! skip_comment() { int c; /* character read */ int star; /* '*' flag */ --- 493,499 ---- * skip over comment */ void ! skip_comment(int commenttype) { int c; /* character read */ int star; /* '*' flag */ *************** *** 461,470 **** star = YES; break; case '/': ! if (star) return; break; case '\n': SETLINE; /*FALLTHROUGH*/ default: --- 505,521 ---- star = YES; break; case '/': ! if (commenttype == '*' && star) return; break; case '\n': + if (commenttype == '/') { + /* We don't really parse C, so sometimes it + * is necessary to see the newline + */ + ungetc(c, inf); + return; + } SETLINE; /*FALLTHROUGH*/ default: *************** *** 528,534 **** case '/': /* skip comments */ if (GETC(==, '*')) { ! skip_comment(); break; } (void)ungetc(c, inf); --- 579,588 ---- case '/': /* skip comments */ if (GETC(==, '*')) { ! skip_comment(c); ! break; ! } else if (c == '/') { ! skip_comment(c); break; } (void)ungetc(c, inf);