prettyness police
authorJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Sat, 2 Apr 1994 04:10:14 +0000 (20:10 -0800)
committerJan-Simon Pendry <pendry@ucbvax.Berkeley.EDU>
Sat, 2 Apr 1994 04:10:14 +0000 (20:10 -0800)
SCCS-vsn: usr.bin/ctags/yacc.c 8.2
SCCS-vsn: usr.bin/ctags/lisp.c 8.2
SCCS-vsn: usr.bin/ctags/print.c 8.2
SCCS-vsn: usr.bin/ctags/tree.c 8.2
SCCS-vsn: usr.bin/ctags/fortran.c 8.2
SCCS-vsn: usr.bin/ctags/ctags.c 8.2
SCCS-vsn: usr.bin/ctags/ctags.h 8.2
SCCS-vsn: usr.bin/ctags/C.c 8.3
SCCS-vsn: usr.bin/dirname/dirname.c 8.2
SCCS-vsn: usr.bin/env/env.c 8.2
SCCS-vsn: usr.bin/du/du.c 8.4

usr/src/usr.bin/ctags/C.c
usr/src/usr.bin/ctags/ctags.c
usr/src/usr.bin/ctags/ctags.h
usr/src/usr.bin/ctags/fortran.c
usr/src/usr.bin/ctags/lisp.c
usr/src/usr.bin/ctags/print.c
usr/src/usr.bin/ctags/tree.c
usr/src/usr.bin/ctags/yacc.c
usr/src/usr.bin/dirname/dirname.c
usr/src/usr.bin/du/du.c
usr/src/usr.bin/env/env.c

index 8261e86..66485db 100644 (file)
@@ -6,39 +6,41 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)C.c        8.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)C.c        8.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
+
 #include "ctags.h"
 
 #include "ctags.h"
 
-static int func_entry(), str_entry();
-static void hash_entry();
-static void skip_string();
+static int     func_entry __P((void));
+static void    hash_entry __P((void));
+static void    skip_string __P((int));
+static int     str_entry __P((int));
 
 /*
  * c_entries --
  *     read .c and .h files and call appropriate routines
  */
 
 /*
  * c_entries --
  *     read .c and .h files and call appropriate routines
  */
+void
 c_entries()
 {
 c_entries()
 {
-       extern int      tflag;          /* -t: create tags for typedefs */
-       register int    c,              /* current character */
-                       level;          /* brace level */
-       register char   *sp;            /* buffer pointer */
-       int     token,                  /* if reading a token */
-               t_def,                  /* if reading a typedef */
-               t_level;                /* typedef's brace level */
+       int     c;                      /* current character */
+       int     level;                  /* brace level */
+       int     token;                  /* if reading a token */
+       int     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;
        char    tok[MAXTOKEN];          /* token buffer */
 
        lineftell = ftell(inf);
        sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
-       while (GETC(!=,EOF)) {
-
-       switch ((char)c) {
+       while (GETC(!=, EOF)) {
+               switch (c) {
                /*
                /*
-                * Here's where it DOESN'T handle:
+                * Here's where it DOESN'T handle: {
                 *      foo(a)
                 *      {
                 *      #ifdef notdef
                 *      foo(a)
                 *      {
                 *      #ifdef notdef
@@ -66,7 +68,7 @@ c_entries()
                         * the above 3 cases are similar in that they
                         * are special characters that also end tokens.
                         */
                         * the above 3 cases are similar in that they
                         * are special characters that also end tokens.
                         */
-endtok:                        if (sp > tok) {
+       endtok:                 if (sp > tok) {
                                *sp = EOS;
                                token = YES;
                                sp = tok;
                                *sp = EOS;
                                token = YES;
                                sp = tok;
@@ -90,11 +92,11 @@ endtok:                     if (sp > tok) {
                 *      "foo() XX comment XX { int bar; }"
                 */
                case '/':
                 *      "foo() XX comment XX { int bar; }"
                 */
                case '/':
-                       if (GETC(==,'*')) {
+                       if (GETC(==, '*')) {
                                skip_comment();
                                continue;
                        }
                                skip_comment();
                                continue;
                        }
-                       (void)ungetc(c,inf);
+                       (void)ungetc(c, inf);
                        c = '/';
                        goto storec;
 
                        c = '/';
                        goto storec;
 
@@ -107,7 +109,7 @@ endtok:                     if (sp > tok) {
                        goto storec;
 
                /*
                        goto storec;
 
                /*
-                * if we have a current token, parenthesis on
+                * if we have a current token, parenthesis on
                 * level zero indicates a function.
                 */
                case '(':
                 * level zero indicates a function.
                 */
                case '(':
@@ -126,7 +128,7 @@ endtok:                     if (sp > tok) {
                                curline = lineno;
                                if (func_entry()) {
                                        ++level;
                                curline = lineno;
                                if (func_entry()) {
                                        ++level;
-                                       pfnote(tok,curline);
+                                       pfnote(tok, curline);
                                }
                                break;
                        }
                                }
                                break;
                        }
@@ -154,7 +156,7 @@ endtok:                     if (sp > tok) {
                                getline();
                                if (sp != tok)
                                        *sp = EOS;
                                getline();
                                if (sp != tok)
                                        *sp = EOS;
-                               pfnote(tok,lineno);
+                               pfnote(tok, lineno);
                                break;
                        }
                        goto storec;
                                break;
                        }
                        goto storec;
@@ -165,22 +167,23 @@ endtok:                   if (sp > tok) {
                 * reserved words.
                 */
                default:
                 * reserved words.
                 */
                default:
-storec:                        if (!intoken(c)) {
+       storec:         if (!intoken(c)) {
                                if (sp == tok)
                                        break;
                                *sp = EOS;
                                if (tflag) {
                                        /* no typedefs inside typedefs */
                                if (sp == tok)
                                        break;
                                *sp = EOS;
                                if (tflag) {
                                        /* no typedefs inside typedefs */
-                                       if (!t_def && !bcmp(tok,"typedef",8)) {
+                                       if (!t_def &&
+                                                  !memcmp(tok, "typedef",8)) {
                                                t_def = YES;
                                                t_level = level;
                                                break;
                                        }
                                        /* catch "typedef struct" */
                                        if ((!t_def || t_level < level)
                                                t_def = YES;
                                                t_level = level;
                                                break;
                                        }
                                        /* catch "typedef struct" */
                                        if ((!t_def || t_level < level)
-                                           && (!bcmp(tok,"struct",7)
-                                           || !bcmp(tok,"union",6)
-                                           || !bcmp(tok,"enum",5))) {
+                                           && (!memcmp(tok, "struct", 7)
+                                           || !memcmp(tok, "union", 6)
+                                           || !memcmp(tok, "enum", 5))) {
                                                /*
                                                 * get line immediately;
                                                 * may change before '{'
                                                /*
                                                 * get line immediately;
                                                 * may change before '{'
@@ -189,6 +192,7 @@ storec:                     if (!intoken(c)) {
                                                if (str_entry(c))
                                                        ++level;
                                                break;
                                                if (str_entry(c))
                                                        ++level;
                                                break;
+                                               /* } */
                                        }
                                }
                                sp = tok;
                                        }
                                }
                                sp = tok;
@@ -199,6 +203,7 @@ storec:                     if (!intoken(c)) {
                        }
                        continue;
                }
                        }
                        continue;
                }
+
                sp = tok;
                token = NO;
        }
                sp = tok;
                token = NO;
        }
@@ -211,16 +216,16 @@ storec:                   if (!intoken(c)) {
 static int
 func_entry()
 {
 static int
 func_entry()
 {
-       register int    c;              /* current character */
-       int             level = 0;      /* for matching '()' */
+       int     c;                      /* current character */
+       int     level = 0;              /* for matching '()' */
 
        /*
         * Find the end of the assumed function declaration.
         * Note that ANSI C functions can have type definitions so keep
         * track of the parentheses nesting level.
         */
 
        /*
         * Find the end of the assumed function declaration.
         * Note that ANSI C functions can have type definitions so keep
         * track of the parentheses nesting level.
         */
-       while (GETC(!=,EOF)) {
-               switch ((char)c) {
+       while (GETC(!=, EOF)) {
+               switch (c) {
                case '\'':
                case '"':
                        /* skip strings and character constants */
                case '\'':
                case '"':
                        /* skip strings and character constants */
@@ -228,7 +233,7 @@ func_entry()
                        break;
                case '/':
                        /* skip comments */
                        break;
                case '/':
                        /* skip comments */
-                       if (GETC(==,'*'))
+                       if (GETC(==, '*'))
                                skip_comment();
                        break;
                case '(':
                                skip_comment();
                        break;
                case '(':
@@ -243,7 +248,7 @@ func_entry()
                        SETLINE;
                }
        }
                        SETLINE;
                }
        }
-       return(NO);
+       return (NO);
 fnd:
        /*
         * we assume that the character after a function's right paren
 fnd:
        /*
         * we assume that the character after a function's right paren
@@ -251,21 +256,21 @@ fnd:
         * character if it's a declaration.  Comments don't count...
         */
        for (;;) {
         * character if it's a declaration.  Comments don't count...
         */
        for (;;) {
-               while (GETC(!=,EOF) && iswhite(c))
-                       if (c == (int)'\n')
+               while (GETC(!=, EOF) && iswhite(c))
+                       if (c == '\n')
                                SETLINE;
                                SETLINE;
-               if (intoken(c) || c == (int)'{')
+               if (intoken(c) || c == '{')
                        break;
                        break;
-               if (c == (int)'/' && GETC(==,'*'))
+               if (c == '/' && GETC(==, '*'))
                        skip_comment();
                else {                          /* don't ever "read" '/' */
                        skip_comment();
                else {                          /* don't ever "read" '/' */
-                       (void)ungetc(c,inf);
-                       return(NO);
+                       (void)ungetc(c, inf);
+                       return (NO);
                }
        }
                }
        }
-       if (c != (int)'{')
-               (void)skip_key((int)'{');
-       return(YES);
+       if (c != '{')
+               (void)skip_key('{');
+       return (YES);
 }
 
 /*
 }
 
 /*
@@ -275,32 +280,31 @@ fnd:
 static void
 hash_entry()
 {
 static void
 hash_entry()
 {
-       extern int      dflag;          /* -d: non-macro defines */
-       register int    c,              /* character read */
-                       curline;        /* line started on */
-       register char   *sp;            /* buffer pointer */
+       int     c;                      /* character read */
+       int     curline;                /* line started on */
+       char    *sp;                    /* buffer pointer */
        char    tok[MAXTOKEN];          /* storage buffer */
 
        curline = lineno;
        for (sp = tok;;) {              /* get next token */
        char    tok[MAXTOKEN];          /* storage buffer */
 
        curline = lineno;
        for (sp = tok;;) {              /* get next token */
-               if (GETC(==,EOF))
+               if (GETC(==, EOF))
                        return;
                if (iswhite(c))
                        break;
                *sp++ = c;
        }
        *sp = EOS;
                        return;
                if (iswhite(c))
                        break;
                *sp++ = c;
        }
        *sp = EOS;
-       if (bcmp(tok,"define",6))       /* only interested in #define's */
+       if (memcmp(tok, "define", 6))   /* only interested in #define's */
                goto skip;
        for (;;) {                      /* this doesn't handle "#define \n" */
                goto skip;
        for (;;) {                      /* this doesn't handle "#define \n" */
-               if (GETC(==,EOF))
+               if (GETC(==, EOF))
                        return;
                if (!iswhite(c))
                        break;
        }
        for (sp = tok;;) {              /* get next token */
                *sp++ = c;
                        return;
                if (!iswhite(c))
                        break;
        }
        for (sp = tok;;) {              /* get next token */
                *sp++ = c;
-               if (GETC(==,EOF))
+               if (GETC(==, EOF))
                        return;
                /*
                 * this is where it DOESN'T handle
                        return;
                /*
                 * this is where it DOESN'T handle
@@ -310,44 +314,44 @@ hash_entry()
                        break;
        }
        *sp = EOS;
                        break;
        }
        *sp = EOS;
-       if (dflag || c == (int)'(') {   /* only want macros */
+       if (dflag || c == '(') {        /* only want macros */
                getline();
                getline();
-               pfnote(tok,curline);
+               pfnote(tok, curline);
        }
        }
-skip:  if (c == (int)'\n') {           /* get rid of rest of define */
+skip:  if (c == '\n') {                /* get rid of rest of define */
                SETLINE
                if (*(sp - 1) != '\\')
                        return;
        }
                SETLINE
                if (*(sp - 1) != '\\')
                        return;
        }
-       (void)skip_key((int)'\n');
+       (void)skip_key('\n');
 }
 
 /*
  * str_entry --
  *     handle a struct, union or enum entry
  */
 }
 
 /*
  * str_entry --
  *     handle a struct, union or enum entry
  */
-static
+static int
 str_entry(c)
 str_entry(c)
-       register int    c;              /* current character */
+       int     c;                      /* current character */
 {
 {
-       register char   *sp;            /* buffer pointer */
        int     curline;                /* line started on */
        int     curline;                /* line started on */
-       char    tok[BUFSIZ];            /* storage buffer */
+       char    *sp;                    /* buffer pointer */
+       char    tok[LINE_MAX];          /* storage buffer */
 
        curline = lineno;
        while (iswhite(c))
 
        curline = lineno;
        while (iswhite(c))
-               if (GETC(==,EOF))
-                       return(NO);
-       if (c == (int)'{')              /* it was "struct {" */
-               return(YES);
+               if (GETC(==, EOF))
+                       return (NO);
+       if (c == '{')           /* it was "struct {" */
+               return (YES);
        for (sp = tok;;) {              /* get next token */
                *sp++ = c;
        for (sp = tok;;) {              /* get next token */
                *sp++ = c;
-               if (GETC(==,EOF))
-                       return(NO);
+               if (GETC(==, EOF))
+                       return (NO);
                if (!intoken(c))
                        break;
        }
                if (!intoken(c))
                        break;
        }
-       switch ((char)c) {
+       switch (c) {
                case '{':               /* it was "struct foo{" */
                        --sp;
                        break;
                case '{':               /* it was "struct foo{" */
                        --sp;
                        break;
@@ -355,43 +359,45 @@ str_entry(c)
                        SETLINE;
                        /*FALLTHROUGH*/
                default:                /* probably "struct foo " */
                        SETLINE;
                        /*FALLTHROUGH*/
                default:                /* probably "struct foo " */
-                       while (GETC(!=,EOF))
+                       while (GETC(!=, EOF))
                                if (!iswhite(c))
                                        break;
                                if (!iswhite(c))
                                        break;
-                       if (c != (int)'{') {
+                       if (c != '{') {
                                (void)ungetc(c, inf);
                                (void)ungetc(c, inf);
-                               return(NO);
+                               return (NO);
                        }
        }
        *sp = EOS;
                        }
        }
        *sp = EOS;
-       pfnote(tok,curline);
-       return(YES);
+       pfnote(tok, curline);
+       return (YES);
 }
 
 /*
  * skip_comment --
  *     skip over comment
  */
 }
 
 /*
  * skip_comment --
  *     skip over comment
  */
+void
 skip_comment()
 {
 skip_comment()
 {
-       register int    c,              /* character read */
-                       star;           /* '*' flag */
+       int     c;                      /* character read */
+       int     star;                   /* '*' flag */
 
 
-       for (star = 0;GETC(!=,EOF);)
-               switch((char)c) {
-                       /* comments don't nest, nor can they be escaped. */
-                       case '*':
-                               star = YES;
-                               break;
-                       case '/':
-                               if (star)
-                                       return;
-                               break;
-                       case '\n':
-                               SETLINE;
-                               /*FALLTHROUGH*/
-                       default:
-                               star = NO;
+       for (star = 0; GETC(!=, EOF);)
+               switch(c) {
+               /* comments don't nest, nor can they be escaped. */
+               case '*':
+                       star = YES;
+                       break;
+               case '/':
+                       if (star)
+                               return;
+                       break;
+               case '\n':
+                       SETLINE;
+                       /*FALLTHROUGH*/
+               default:
+                       star = NO;
+                       break;
                }
 }
 
                }
 }
 
@@ -401,13 +407,13 @@ skip_comment()
  */
 void
 skip_string(key)
  */
 void
 skip_string(key)
-       register int    key;
+       int     key;
 {
 {
-       register int    c,
-                       skip;
+       int     c,
+               skip;
 
 
-       for (skip = NO; GETC(!=,EOF); )
-               switch ((char)c) {
+       for (skip = NO; GETC(!=, EOF); )
+               switch (c) {
                case '\\':              /* a backslash escapes anything */
                        skip = !skip;   /* we toggle in case it's "\\" */
                        break;
                case '\\':              /* a backslash escapes anything */
                        skip = !skip;   /* we toggle in case it's "\\" */
                        break;
@@ -427,14 +433,14 @@ skip_string(key)
  */
 int
 skip_key(key)
  */
 int
 skip_key(key)
-       register int    key;
+       int     key;
 {
 {
-       register int    c,
-                       skip,
-                       retval;
+       int     c,
+               skip,
+               retval;
 
 
-       for (skip = retval = NO;GETC(!=,EOF);)
-               switch((char)c) {
+       for (skip = retval = NO; GETC(!=, EOF);)
+               switch(c) {
                case '\\':              /* a backslash escapes anything */
                        skip = !skip;   /* we toggle in case it's "\\" */
                        break;
                case '\\':              /* a backslash escapes anything */
                        skip = !skip;   /* we toggle in case it's "\\" */
                        break;
@@ -449,11 +455,11 @@ skip_key(key)
                        break;
                case '/':
                        /* skip comments */
                        break;
                case '/':
                        /* skip comments */
-                       if (GETC(==,'*')) {
+                       if (GETC(==, '*')) {
                                skip_comment();
                                break;
                        }
                                skip_comment();
                                break;
                        }
-                       (void)ungetc(c,inf);
+                       (void)ungetc(c, inf);
                        c = '/';
                        goto norm;
                case '\n':
                        c = '/';
                        goto norm;
                case '\n':
@@ -462,8 +468,8 @@ skip_key(key)
                default:
                norm:
                        if (c == key && !skip)
                default:
                norm:
                        if (c == key && !skip)
-                               return(retval);
+                               return (retval);
                        skip = NO;
                }
                        skip = NO;
                }
-       return(retval);
+       return (retval);
 }
 }
index a61612a..98433cc 100644 (file)
@@ -12,12 +12,16 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ctags.c    8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)ctags.c    8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <err.h>
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
+
 #include "ctags.h"
 
 /*
 #include "ctags.h"
 
 /*
@@ -27,86 +31,89 @@ static char sccsid[] = "@(#)ctags.c 8.1 (Berkeley) %G%";
 NODE   *head;                  /* head of the sorted binary tree */
 
                                /* boolean "func" (see init()) */
 NODE   *head;                  /* head of the sorted binary tree */
 
                                /* boolean "func" (see init()) */
-bool   _wht[0177],_etk[0177],_itk[0177],_btk[0177],_gd[0177];
+bool   _wht[256], _etk[256], _itk[256], _btk[256], _gd[256];
 
 
-FILE   *inf,                   /* ioptr for current input file */
-       *outf;                  /* ioptr for tags file */
+FILE   *inf;                   /* ioptr for current input file */
+FILE   *outf;                  /* ioptr for tags file */
 
 long   lineftell;              /* ftell after getc( inf ) == '\n' */
 
 
 long   lineftell;              /* ftell after getc( inf ) == '\n' */
 
-int    lineno,                 /* line number of current line */
-       dflag,                  /* -d: non-macro defines */
-       tflag,                  /* -t: create tags for typedefs */
-       wflag,                  /* -w: suppress warnings */
-       vflag,                  /* -v: vgrind style index output */
-       xflag;                  /* -x: cxref style output */
+int    lineno;                 /* line number of current line */
+int    dflag;                  /* -d: non-macro defines */
+int    tflag;                  /* -t: create tags for typedefs */
+int    vflag;                  /* -v: vgrind style index output */
+int    wflag;                  /* -w: suppress warnings */
+int    xflag;                  /* -x: cxref style output */
+
+char   *curfile;               /* current input file name */
+char   searchar = '/';         /* use /.../ searches by default */
+char   lbuf[LINE_MAX];
 
 
-char   *curfile,               /* current input file name */
-       searchar = '/',         /* use /.../ searches by default */
-       lbuf[BUFSIZ];
+void   init __P((void));
+void   find_entries __P((char *));
 
 
-main(argc,argv)
+int
+main(argc, argv)
        int     argc;
        char    **argv;
 {
        int     argc;
        char    **argv;
 {
-       extern char     *optarg;                /* getopt arguments */
-       extern int      optind;
        static char     *outfile = "tags";      /* output file */
        static char     *outfile = "tags";      /* output file */
-       int     aflag,                          /* -a: append to tags */
-               uflag,                          /* -u: update tags */
-               exit_val,                       /* exit value */
-               step,                           /* step through args */
-               ch;                             /* getopts char */
+       int     aflag;                          /* -a: append to tags */
+       int     uflag;                          /* -u: update tags */
+       int     exit_val;                       /* exit value */
+       int     step;                           /* step through args */
+       int     ch;                             /* getopts char */
        char    cmd[100];                       /* too ugly to explain */
 
        aflag = uflag = NO;
        char    cmd[100];                       /* too ugly to explain */
 
        aflag = uflag = NO;
-       while ((ch = getopt(argc,argv,"BFadf:tuwvx")) != EOF)
-               switch((char)ch) {
-                       case 'B':
-                               searchar = '?';
-                               break;
-                       case 'F':
-                               searchar = '/';
-                               break;
-                       case 'a':
-                               aflag++;
-                               break;
-                       case 'd':
-                               dflag++;
-                               break;
-                       case 'f':
-                               outfile = optarg;
-                               break;
-                       case 't':
-                               tflag++;
-                               break;
-                       case 'u':
-                               uflag++;
-                               break;
-                       case 'w':
-                               wflag++;
-                               break;
-                       case 'v':
-                               vflag++;
-                       case 'x':
-                               xflag++;
-                               break;
-                       case '?':
-                       default:
-                               goto usage;
+       while ((ch = getopt(argc, argv, "BFadf:tuwvx")) != EOF)
+               switch(ch) {
+               case 'B':
+                       searchar = '?';
+                       break;
+               case 'F':
+                       searchar = '/';
+                       break;
+               case 'a':
+                       aflag++;
+                       break;
+               case 'd':
+                       dflag++;
+                       break;
+               case 'f':
+                       outfile = optarg;
+                       break;
+               case 't':
+                       tflag++;
+                       break;
+               case 'u':
+                       uflag++;
+                       break;
+               case 'w':
+                       wflag++;
+                       break;
+               case 'v':
+                       vflag++;
+               case 'x':
+                       xflag++;
+                       break;
+               case '?':
+               default:
+                       goto usage;
                }
        argv += optind;
        argc -= optind;
        if (!argc) {
                }
        argv += optind;
        argc -= optind;
        if (!argc) {
-usage:         puts("Usage: ctags [-BFadtuwvx] [-f tagsfile] file ...");
+usage:         (void)fprintf(stderr,
+                       "usage: ctags [-BFadtuwvx] [-f tagsfile] file ...");
                exit(1);
        }
 
        init();
 
                exit(1);
        }
 
        init();
 
-       for (exit_val = step = 0;step < argc;++step)
-               if (!(inf = fopen(argv[step],"r"))) {
-                       perror(argv[step]);
+       for (exit_val = step = 0; step < argc; ++step)
+               if (!(inf = fopen(argv[step], "r"))) {
+                       warn("%s", argv[step]);
                        exit_val = 1;
                }
                else {
                        exit_val = 1;
                }
                else {
@@ -120,20 +127,22 @@ usage:            puts("Usage: ctags [-BFadtuwvx] [-f tagsfile] file ...");
                        put_entries(head);
                else {
                        if (uflag) {
                        put_entries(head);
                else {
                        if (uflag) {
-                               for (step = 0;step < argc;step++) {
-                                       (void)sprintf(cmd,"mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS",outfile,argv[step],outfile);
+                               for (step = 0; step < argc; step++) {
+                                       (void)sprintf(cmd,
+                                               "mv %s OTAGS; fgrep -v '\t%s\t' OTAGS >%s; rm OTAGS",
+                                                       outfile, argv[step],
+                                                       outfile);
                                        system(cmd);
                                }
                                ++aflag;
                        }
                                        system(cmd);
                                }
                                ++aflag;
                        }
-                       if (!(outf = fopen(outfile, aflag ? "a" : "w"))) {
-                               perror(outfile);
-                               exit(exit_val);
-                       }
+                       if (!(outf = fopen(outfile, aflag ? "a" : "w")))
+                               err(exit_val, "%s", outfile);
                        put_entries(head);
                        (void)fclose(outf);
                        if (uflag) {
                        put_entries(head);
                        (void)fclose(outf);
                        if (uflag) {
-                               (void)sprintf(cmd,"sort %s -o %s",outfile,outfile);
+                               (void)sprintf(cmd, "sort -o %s %s",
+                                               outfile, outfile);
                                system(cmd);
                        }
                }
                                system(cmd);
                        }
                }
@@ -150,12 +159,13 @@ usage:            puts("Usage: ctags [-BFadtuwvx] [-f tagsfile] file ...");
  *     CWHITE are set to YES.  Thus, "_wht" of a char is YES if it is in
  *     the string CWHITE, else NO.
  */
  *     CWHITE are set to YES.  Thus, "_wht" of a char is YES if it is in
  *     the string CWHITE, else NO.
  */
+void
 init()
 {
 init()
 {
-       register int    i;
-       register char   *sp;
+       int             i;
+       unsigned char   *sp;
 
 
-       for (i = 0; i < 0177; i++) {
+       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] = NO;
                _gd[i] = YES;
        }
@@ -181,18 +191,19 @@ init()
  *     this routine opens the specified file and calls the function
  *     which searches the file.
  */
  *     this routine opens the specified file and calls the function
  *     which searches the file.
  */
+void
 find_entries(file)
        char    *file;
 {
 find_entries(file)
        char    *file;
 {
-       register char   *cp;
+       char    *cp;
 
        lineno = 0;                             /* should be 1 ?? KB */
 
        lineno = 0;                             /* should be 1 ?? KB */
-       if (cp = rindex(file, '.')) {
+       if (cp = strrchr(file, '.')) {
                if (cp[1] == 'l' && !cp[2]) {
                if (cp[1] == 'l' && !cp[2]) {
-                       register int    c;
+                       int     c;
 
                        for (;;) {
 
                        for (;;) {
-                               if (GETC(==,EOF))
+                               if (GETC(==, EOF))
                                        return;
                                if (!iswhite(c)) {
                                        rewind(inf);
                                        return;
                                if (!iswhite(c)) {
                                        rewind(inf);
@@ -200,7 +211,7 @@ find_entries(file)
                                }
                        }
 #define        LISPCHR ";(["
                                }
                        }
 #define        LISPCHR ";(["
-/* lisp */             if (index(LISPCHR,(char)c)) {
+/* lisp */             if (strchr(LISPCHR, c)) {
                                l_entries();
                                return;
                        }
                                l_entries();
                                return;
                        }
@@ -210,8 +221,8 @@ find_entries(file)
                                 * for C references.  This may be wrong.
                                 */
                                toss_yysec();
                                 * for C references.  This may be wrong.
                                 */
                                toss_yysec();
-                               (void)strcpy(lbuf,"%%$");
-                               pfnote("yylex",lineno);
+                               (void)strcpy(lbuf, "%%$");
+                               pfnote("yylex", lineno);
                                rewind(inf);
                        }
                }
                                rewind(inf);
                        }
                }
@@ -221,8 +232,8 @@ find_entries(file)
                         * for C references.  This may be wrong.
                         */
                        toss_yysec();
                         * for C references.  This may be wrong.
                         */
                        toss_yysec();
-                       (void)strcpy(lbuf,"%%$");
-                       pfnote("yyparse",lineno);
+                       (void)strcpy(lbuf, "%%$");
+                       pfnote("yyparse", lineno);
                        y_entries();
                }
 /* fortran */  else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) {
                        y_entries();
                }
 /* fortran */  else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) {
index 1f4216c..f6387ae 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ctags.h     8.1 (Berkeley) %G%
+ *     @(#)ctags.h     8.2 (Berkeley) %G%
  */
 
 #define        bool    char
  */
 
 #define        bool    char
 #define        SETLINE         {++lineno;lineftell = ftell(inf);}
 #define        GETC(op,exp)    ((c = getc(inf)) op (int)exp)
 
 #define        SETLINE         {++lineno;lineftell = ftell(inf);}
 #define        GETC(op,exp)    ((c = getc(inf)) op (int)exp)
 
-#define        iswhite(arg)    (_wht[arg])     /* T if char is white */
-#define        begtoken(arg)   (_btk[arg])     /* T if char can start token */
-#define        intoken(arg)    (_itk[arg])     /* T if char can be in token */
-#define        endtoken(arg)   (_etk[arg])     /* T if char ends tokens */
-#define        isgood(arg)     (_gd[arg])      /* T if char can be after ')' */
+#define        iswhite(arg)    (_wht[(unsigned)arg])   /* T if char is white */
+#define        begtoken(arg)   (_btk[(unsigned)arg])   /* T if char can start token */
+#define        intoken(arg)    (_itk[(unsigned)arg])   /* T if char can be in token */
+#define        endtoken(arg)   (_etk[(unsigned)arg])   /* T if char ends tokens */
+#define        isgood(arg)     (_gd[(unsigned)arg])    /* T if char can be after ')' */
 
 typedef struct nd_st {                 /* sorting structure */
        struct nd_st    *left,
 
 typedef struct nd_st {                 /* sorting structure */
        struct nd_st    *left,
@@ -35,9 +35,30 @@ typedef struct nd_st {                       /* sorting structure */
        bool    been_warned;            /* set if noticed dup */
 } NODE;
 
        bool    been_warned;            /* set if noticed dup */
 } NODE;
 
-extern FILE    *inf;                   /* ioptr for current input file */
+extern char    *curfile;               /* current input file name */
+extern NODE    *head;                  /* head of the sorted binary tree */
+extern FILE    *inf;                   /* ioptr for current input file */
+extern FILE    *outf;                  /* ioptr for current output file */
 extern long    lineftell;              /* ftell after getc( inf ) == '\n' */
 extern long    lineftell;              /* ftell after getc( inf ) == '\n' */
-extern int     lineno,                 /* line number of current line */
-               xflag;                  /* -x: cxref style output */
-extern bool    _wht[0177],_etk[0177],_itk[0177],_btk[0177],_gd[0177];
-extern char    lbuf[BUFSIZ];
+extern int     lineno;                 /* line number of current line */
+extern int     dflag;                  /* -d: non-macro defines */
+extern int     tflag;                  /* -t: create tags for typedefs */
+extern int     vflag;                  /* -v: vgrind style index output */
+extern int     wflag;                  /* -w: suppress warnings */
+extern int     xflag;                  /* -x: cxref style output */
+extern bool    _wht[], _etk[], _itk[], _btk[], _gd[];
+extern char    lbuf[LINE_MAX];
+extern char    *lbp;
+extern char    searchar;               /* ex search character */
+
+extern int     cicmp __P((char *));
+extern void    getline __P((void));
+extern void    pfnote __P((char *, int));
+extern int     skip_key __P((int));
+extern void    put_entries __P((NODE *));
+extern void    toss_yysec __P((void));
+extern void    l_entries __P((void));
+extern void    y_entries __P((void));
+extern int     PF_funcs __P((void));
+extern void    c_entries __P((void));
+extern void    skip_comment __P((void));
index 586d919..eb838dd 100644 (file)
@@ -6,33 +6,37 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)fortran.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)fortran.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <ctype.h>
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
+
 #include "ctags.h"
 
 #include "ctags.h"
 
-static void takeprec();
+static void takeprec __P((void));
 
 char *lbp;                             /* line buffer pointer */
 
 
 char *lbp;                             /* line buffer pointer */
 
+int
 PF_funcs()
 {
 PF_funcs()
 {
-       register bool   pfcnt;          /* pascal/fortran functions found */
-       register char   *cp;
-       char    tok[MAXTOKEN],
-               *gettoken();
+       bool    pfcnt;                  /* pascal/fortran functions found */
+       char    *cp;
+       char    tok[MAXTOKEN];
 
        for (pfcnt = NO;;) {
                lineftell = ftell(inf);
 
        for (pfcnt = NO;;) {
                lineftell = ftell(inf);
-               if (!fgets(lbuf,sizeof(lbuf),inf))
-                       return(pfcnt);
+               if (!fgets(lbuf, sizeof(lbuf), inf))
+                       return (pfcnt);
                ++lineno;
                lbp = lbuf;
                if (*lbp == '%')        /* Ratfor escape to fortran */
                        ++lbp;
                ++lineno;
                lbp = lbuf;
                if (*lbp == '%')        /* Ratfor escape to fortran */
                        ++lbp;
-               for (;isspace(*lbp);++lbp);
+               for (; isspace(*lbp); ++lbp)
+                       continue;
                if (!*lbp)
                        continue;
                switch (*lbp | ' ') {   /* convert to lower-case */
                if (!*lbp)
                        continue;
                switch (*lbp | ' ') {   /* convert to lower-case */
@@ -42,7 +46,8 @@ PF_funcs()
                        break;
                case 'd':
                        if (cicmp("double")) {
                        break;
                case 'd':
                        if (cicmp("double")) {
-                               for (;isspace(*lbp);++lbp);
+                               for (; isspace(*lbp); ++lbp)
+                                       continue;
                                if (!*lbp)
                                        continue;
                                if (cicmp("precision"))
                                if (!*lbp)
                                        continue;
                                if (cicmp("precision"))
@@ -63,7 +68,8 @@ PF_funcs()
                                takeprec();
                        break;
                }
                                takeprec();
                        break;
                }
-               for (;isspace(*lbp);++lbp);
+               for (; isspace(*lbp); ++lbp)
+                       continue;
                if (!*lbp)
                        continue;
                switch (*lbp | ' ') {
                if (!*lbp)
                        continue;
                switch (*lbp | ' ') {
@@ -81,16 +87,18 @@ PF_funcs()
                default:
                        continue;
                }
                default:
                        continue;
                }
-               for (;isspace(*lbp);++lbp);
+               for (; isspace(*lbp); ++lbp)
+                       continue;
                if (!*lbp)
                        continue;
                if (!*lbp)
                        continue;
-               for (cp = lbp + 1;*cp && intoken(*cp);++cp);
+               for (cp = lbp + 1; *cp && intoken(*cp); ++cp)
+                       continue;
                if (cp = lbp + 1)
                        continue;
                *cp = EOS;
                if (cp = lbp + 1)
                        continue;
                *cp = EOS;
-               (void)strcpy(tok,lbp);
+               (void)strcpy(tok, lbp);
                getline();                      /* process line for ex(1) */
                getline();                      /* process line for ex(1) */
-               pfnote(tok,lineno);
+               pfnote(tok, lineno);
                pfcnt = YES;
        }
        /*NOTREACHED*/
                pfcnt = YES;
        }
        /*NOTREACHED*/
@@ -100,30 +108,35 @@ PF_funcs()
  * cicmp --
  *     do case-independent strcmp
  */
  * cicmp --
  *     do case-independent strcmp
  */
+int
 cicmp(cp)
 cicmp(cp)
-       register char   *cp;
+       char    *cp;
 {
 {
-       register int    len;
-       register char   *bp;
+       int     len;
+       char    *bp;
 
 
-       for (len = 0,bp = lbp;*cp && (*cp &~ ' ') == (*bp++ &~ ' ');
-           ++cp,++len);
+       for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' ');
+           ++cp, ++len)
+               continue;
        if (!*cp) {
                lbp += len;
        if (!*cp) {
                lbp += len;
-               return(YES);
+               return (YES);
        }
        }
-       return(NO);
+       return (NO);
 }
 
 static void
 takeprec()
 {
 }
 
 static void
 takeprec()
 {
-       for (;isspace(*lbp);++lbp);
+       for (; isspace(*lbp); ++lbp)
+               continue;
        if (*lbp == '*') {
        if (*lbp == '*') {
-               for (++lbp;isspace(*lbp);++lbp);
+               for (++lbp; isspace(*lbp); ++lbp)
+                       continue;
                if (!isdigit(*lbp))
                        --lbp;                  /* force failure */
                else
                if (!isdigit(*lbp))
                        --lbp;                  /* force failure */
                else
-                       while (isdigit(*++lbp));
+                       while (isdigit(*++lbp))
+                               continue;
        }
 }
        }
 }
index 3f101ba..51e6889 100644 (file)
@@ -6,29 +6,31 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lisp.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)lisp.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <ctype.h>
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
-#include "ctags.h"
 
 
-extern char    *lbp;                   /* pointer shared with fortran */
+#include "ctags.h"
 
 /*
  * lisp tag functions
  * just look for (def or (DEF
  */
 
 /*
  * lisp tag functions
  * just look for (def or (DEF
  */
+void
 l_entries()
 {
 l_entries()
 {
-       register int    special;
-       register char   *cp,
-                       savedc;
+       int     special;
+       char    *cp;
+       char    savedc;
        char    tok[MAXTOKEN];
 
        for (;;) {
                lineftell = ftell(inf);
        char    tok[MAXTOKEN];
 
        for (;;) {
                lineftell = ftell(inf);
-               if (!fgets(lbuf,sizeof(lbuf),inf))
+               if (!fgets(lbuf, sizeof(lbuf), inf))
                        return;
                ++lineno;
                lbp = lbuf;
                        return;
                ++lineno;
                lbp = lbuf;
@@ -44,28 +46,34 @@ l_entries()
                        if (cicmp("wrapper") || cicmp("whopper"))
                                special = YES;
                }
                        if (cicmp("wrapper") || cicmp("whopper"))
                                special = YES;
                }
-               for (;!isspace(*lbp);++lbp);
-               for (;isspace(*lbp);++lbp);
-               for (cp = lbp;*cp && *cp != '\n';++cp);
+               for (; !isspace(*lbp); ++lbp)
+                       continue;
+               for (; isspace(*lbp); ++lbp)
+                       continue;
+               for (cp = lbp; *cp && *cp != '\n'; ++cp)
+                       continue;
                *cp = EOS;
                if (special) {
                *cp = EOS;
                if (special) {
-                       if (!(cp = index(lbp,')')))
+                       if (!(cp = strchr(lbp, ')')))
+                               continue;
+                       for (; cp >= lbp && *cp != ':'; --cp)
                                continue;
                                continue;
-                       for (;cp >= lbp && *cp != ':';--cp);
                        if (cp < lbp)
                                continue;
                        lbp = cp;
                        if (cp < lbp)
                                continue;
                        lbp = cp;
-                       for (;*cp && *cp != ')' && *cp != ' ';++cp);
+                       for (; *cp && *cp != ')' && *cp != ' '; ++cp)
+                               continue;
                }
                else
                        for (cp = lbp + 1;
                }
                else
                        for (cp = lbp + 1;
-                           *cp && *cp != '(' && *cp != ' ';++cp);
+                           *cp && *cp != '(' && *cp != ' '; ++cp)
+                               continue;
                savedc = *cp;
                *cp = EOS;
                savedc = *cp;
                *cp = EOS;
-               (void)strcpy(tok,lbp);
+               (void)strcpy(tok, lbp);
                *cp = savedc;
                getline();
                *cp = savedc;
                getline();
-               pfnote(tok,lineno);
+               pfnote(tok, lineno);
        }
        /*NOTREACHED*/
 }
        }
        /*NOTREACHED*/
 }
index 5d5b211..40047a1 100644 (file)
@@ -6,40 +6,42 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include <unistd.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "ctags.h"
+#include <unistd.h>
 
 
-extern char    searchar;               /* ex search character */
+#include "ctags.h"
 
 /*
  * getline --
  *     get the line the token of interest occurred on,
  *     prepare it for printing.
  */
 
 /*
  * getline --
  *     get the line the token of interest occurred on,
  *     prepare it for printing.
  */
+void
 getline()
 {
 getline()
 {
-       register long   saveftell;
-       register int    c,
-                       cnt;
-       register char   *cp;
+       long    saveftell;
+       int     c;
+       int     cnt;
+       char    *cp;
 
        saveftell = ftell(inf);
 
        saveftell = ftell(inf);
-       (void)fseek(inf,lineftell,L_SET);
+       (void)fseek(inf, lineftell, L_SET);
        if (xflag)
        if (xflag)
-               for (cp = lbuf;GETC(!=,'\n');*cp++ = c);
+               for (cp = lbuf; GETC(!=, '\n'); *cp++ = c)
+                       continue;
        /*
         * do all processing here, so we don't step through the
         * line more than once; means you don't call this routine
         * unless you're sure you've got a keeper.
         */
        /*
         * do all processing here, so we don't step through the
         * line more than once; means you don't call this routine
         * unless you're sure you've got a keeper.
         */
-       else for (cnt = 0,cp = lbuf;GETC(!=,EOF) && cnt < ENDLINE;++cnt) {
-               if (c == (int)'\\') {           /* backslashes */
+       else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) {
+               if (c == '\\') {                /* backslashes */
                        if (cnt > ENDLINE - 2)
                                break;
                        *cp++ = '\\'; *cp++ = '\\';
                        if (cnt > ENDLINE - 2)
                                break;
                        *cp++ = '\\'; *cp++ = '\\';
@@ -51,7 +53,7 @@ getline()
                        *cp++ = '\\'; *cp++ = c;
                        ++cnt;
                }
                        *cp++ = '\\'; *cp++ = c;
                        ++cnt;
                }
-               else if (c == (int)'\n') {      /* end of keep */
+               else if (c == '\n') {   /* end of keep */
                        *cp++ = '$';            /* can find whole line */
                        break;
                }
                        *cp++ = '$';            /* can find whole line */
                        break;
                }
@@ -59,30 +61,29 @@ getline()
                        *cp++ = c;
        }
        *cp = EOS;
                        *cp++ = c;
        }
        *cp = EOS;
-       (void)fseek(inf,saveftell,L_SET);
+       (void)fseek(inf, saveftell, L_SET);
 }
 
 /*
  * put_entries --
  *     write out the tags
  */
 }
 
 /*
  * put_entries --
  *     write out the tags
  */
+void
 put_entries(node)
 put_entries(node)
-       register NODE   *node;
+       NODE    *node;
 {
 {
-       extern FILE     *outf;          /* ioptr for tags file */
-       extern int      vflag;          /* -v: vgrind style output */
 
        if (node->left)
                put_entries(node->left);
        if (vflag)
                printf("%s %s %d\n",
 
        if (node->left)
                put_entries(node->left);
        if (vflag)
                printf("%s %s %d\n",
-                   node->entry,node->file,(node->lno + 63) / 64);
+                   node->entry, node->file, (node->lno + 63) / 64);
        else if (xflag)
                printf("%-16s%4d %-16s %s\n",
        else if (xflag)
                printf("%-16s%4d %-16s %s\n",
-                   node->entry,node->lno,node->file,node->pat);
+                   node->entry, node->lno, node->file, node->pat);
        else
        else
-               fprintf(outf,"%s\t%s\t%c^%s%c\n",
-                   node->entry,node->file,searchar,node->pat,searchar);
+               fprintf(outf, "%s\t%s\t%c^%s%c\n",
+                   node->entry, node->file, searchar, node->pat, searchar);
        if (node->right)
                put_entries(node->right);
 }
        if (node->right)
                put_entries(node->right);
 }
index bc5292b..d8110da 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tree.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)tree.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include <errno.h>
+#include <err.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "ctags.h"
 
 #include "ctags.h"
 
+static void    add_node __P((NODE *, NODE *));
+static void    free_tree __P((NODE *));
+
 /*
  * pfnote --
  *     enter a new node in the tree
  */
 /*
  * pfnote --
  *     enter a new node in the tree
  */
-pfnote(name,ln)
+void
+pfnote(name, ln)
        char    *name;
        int     ln;
 {
        char    *name;
        int     ln;
 {
-       extern NODE     *head;          /* head of the sorted binary tree */
-       extern char     *curfile;       /* current input file name */
-       register NODE   *np;
-       register char   *fp;
+       NODE    *np;
+       char    *fp;
        char    nbuf[MAXTOKEN];
 
        /*NOSTRICT*/
        if (!(np = (NODE *)malloc(sizeof(NODE)))) {
        char    nbuf[MAXTOKEN];
 
        /*NOSTRICT*/
        if (!(np = (NODE *)malloc(sizeof(NODE)))) {
-               fputs("ctags: too many entries to sort\n",stderr);
+               warnx("too many entries to sort");
                put_entries(head);
                free_tree(head);
                /*NOSTRICT*/
                put_entries(head);
                free_tree(head);
                /*NOSTRICT*/
-               if (!(head = np = (NODE *)malloc(sizeof(NODE)))) {
-                       fputs("ctags: out of space.\n",stderr);
-                       exit(1);
-               }
+               if (!(head = np = (NODE *)malloc(sizeof(NODE))))
+                       err(1, "out of space");
        }
        }
-       if (!xflag && !strcmp(name,"main")) {
-               if (!(fp = rindex(curfile,'/')))
+       if (!xflag && !strcmp(name, "main")) {
+               if (!(fp = strrchr(curfile, '/')))
                        fp = curfile;
                else
                        ++fp;
                        fp = curfile;
                else
                        ++fp;
-               (void)sprintf(nbuf,"M%s",fp);
-               fp = rindex(nbuf,'.');
+               (void)sprintf(nbuf, "M%s", fp);
+               fp = strrchr(nbuf, '.');
                if (fp && !fp[2])
                        *fp = EOS;
                name = nbuf;
        }
                if (fp && !fp[2])
                        *fp = EOS;
                name = nbuf;
        }
-       if (!(np->entry = strdup(name))) {
-               (void)fprintf(stderr, "ctags: %s\n", strerror(errno));
-               exit(1);
-       }
+       if (!(np->entry = strdup(name)))
+               err(1, NULL);
        np->file = curfile;
        np->lno = ln;
        np->left = np->right = 0;
        np->file = curfile;
        np->lno = ln;
        np->left = np->right = 0;
-       if (!(np->pat = strdup(lbuf))) {
-               (void)fprintf(stderr, "ctags: %s\n", strerror(errno));
-               exit(1);
-       }
+       if (!(np->pat = strdup(lbuf)))
+               err(1, NULL);
        if (!head)
                head = np;
        else
        if (!head)
                head = np;
        else
-               add_node(np,head);
+               add_node(np, head);
 }
 
 }
 
-add_node(node,cur_node)
-       register NODE   *node,
-                       *cur_node;
+static void
+add_node(node, cur_node)
+       NODE    *node,
+               *cur_node;
 {
 {
-       extern int      wflag;                  /* -w: suppress warnings */
-       register int    dif;
+       int     dif;
 
 
-       dif = strcmp(node->entry,cur_node->entry);
+       dif = strcmp(node->entry, cur_node->entry);
        if (!dif) {
                if (node->file == cur_node->file) {
                        if (!wflag)
        if (!dif) {
                if (node->file == cur_node->file) {
                        if (!wflag)
-                               fprintf(stderr,"Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n",node->file,lineno,node->entry);
+                               fprintf(stderr, "Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n", node->file, lineno, node->entry);
                        return;
                }
                if (!cur_node->been_warned)
                        if (!wflag)
                        return;
                }
                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);
+                               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;
        }
        else if (dif < 0)
                if (cur_node->left)
                cur_node->been_warned = YES;
        }
        else if (dif < 0)
                if (cur_node->left)
-                       add_node(node,cur_node->left);
+                       add_node(node, cur_node->left);
                else
                        cur_node->left = node;
        else if (cur_node->right)
                else
                        cur_node->left = node;
        else if (cur_node->right)
-               add_node(node,cur_node->right);
+               add_node(node, cur_node->right);
        else
                cur_node->right = node;
 }
 
        else
                cur_node->right = node;
 }
 
+static void
 free_tree(node)
 free_tree(node)
-       register NODE   *node;
+       NODE    *node;
 {
        while (node) {
                if (node->right)
 {
        while (node) {
                if (node->right)
index c8910ba..b7d73e4 100644 (file)
@@ -6,26 +6,32 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)yacc.c     8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)yacc.c     8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <ctype.h>
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
+
 #include "ctags.h"
 
 /*
  * y_entries:
  *     find the yacc tags and put them in.
  */
 #include "ctags.h"
 
 /*
  * y_entries:
  *     find the yacc tags and put them in.
  */
+void
 y_entries()
 {
 y_entries()
 {
-       register int    c;
-       register char   *sp;
-       register bool   in_rule;
+       int     c;
+       char    *sp;
+       bool    in_rule;
        char    tok[MAXTOKEN];
 
        char    tok[MAXTOKEN];
 
-       while (GETC(!=,EOF))
-               switch ((char)c) {
+       in_rule = NO;
+
+       while (GETC(!=, EOF))
+               switch (c) {
                case '\n':
                        SETLINE;
                        /* FALLTHROUGH */
                case '\n':
                        SETLINE;
                        /* FALLTHROUGH */
@@ -35,7 +41,7 @@ y_entries()
                case '\t':
                        break;
                case '{':
                case '\t':
                        break;
                case '{':
-                       if (skip_key((int)'}'))
+                       if (skip_key('}'))
                                in_rule = NO;
                        break;
                case '\'':
                                in_rule = NO;
                        break;
                case '\'':
@@ -44,42 +50,41 @@ y_entries()
                                in_rule = NO;
                        break;
                case '%':
                                in_rule = NO;
                        break;
                case '%':
-                       if (GETC(==,'%'))
+                       if (GETC(==, '%'))
                                return;
                                return;
-                       (void)ungetc(c,inf);
+                       (void)ungetc(c, inf);
                        break;
                case '/':
                        break;
                case '/':
-                       if (GETC(==,'*'))
+                       if (GETC(==, '*'))
                                skip_comment();
                        else
                                skip_comment();
                        else
-                               (void)ungetc(c,inf);
+                               (void)ungetc(c, inf);
                        break;
                case '|':
                case ';':
                        in_rule = NO;
                        break;
                default:
                        break;
                case '|':
                case ';':
                        in_rule = NO;
                        break;
                default:
-                       if (in_rule || !isalpha(c) && c != (int)'.'
-                           && c != (int)'_')
+                       if (in_rule || !isalpha(c) && c != '.' && c != '_')
                                break;
                        sp = tok;
                        *sp++ = c;
                                break;
                        sp = tok;
                        *sp++ = c;
-                       while (GETC(!=,EOF) && (intoken(c) || c == (int)'.'))
+                       while (GETC(!=, EOF) && (intoken(c) || c == '.'))
                                *sp++ = c;
                        *sp = EOS;
                        getline();              /* may change before ':' */
                        while (iswhite(c)) {
                                *sp++ = c;
                        *sp = EOS;
                        getline();              /* may change before ':' */
                        while (iswhite(c)) {
-                               if (c == (int)'\n')
+                               if (c == '\n')
                                        SETLINE;
                                        SETLINE;
-                               if (GETC(==,EOF))
+                               if (GETC(==, EOF))
                                        return;
                        }
                                        return;
                        }
-                       if (c == (int)':') {
-                               pfnote(tok,lineno);
+                       if (c == ':') {
+                               pfnote(tok, lineno);
                                in_rule = YES;
                        }
                        else
                                in_rule = YES;
                        }
                        else
-                               (void)ungetc(c,inf);
+                               (void)ungetc(c, inf);
                }
 }
 
                }
 }
 
@@ -87,10 +92,11 @@ y_entries()
  * toss_yysec --
  *     throw away lines up to the next "\n%%\n"
  */
  * toss_yysec --
  *     throw away lines up to the next "\n%%\n"
  */
+void
 toss_yysec()
 {
 toss_yysec()
 {
-       register int    c,                      /* read character */
-                       state;
+       int     c;                      /* read character */
+       int     state;
 
        /*
         * state == 0 : waiting
 
        /*
         * state == 0 : waiting
@@ -99,20 +105,21 @@ toss_yysec()
         * state == 3 : recieved second %
         */
        lineftell = ftell(inf);
         * state == 3 : recieved second %
         */
        lineftell = ftell(inf);
-       for (state = 0;GETC(!=,EOF);)
-               switch ((char)c) {
-                       case '\n':
-                               ++lineno;
-                               lineftell = ftell(inf);
-                               if (state == 3)         /* done! */
-                                       return;
-                               state = 1;              /* start over */
-                               break;
-                       case '%':
-                               if (state)              /* if 1 or 2 */
-                                       ++state;        /* goto 3 */
-                               break;
-                       default:
-                               state = 0;              /* reset */
+       for (state = 0; GETC(!=, EOF);)
+               switch (c) {
+               case '\n':
+                       ++lineno;
+                       lineftell = ftell(inf);
+                       if (state == 3)         /* done! */
+                               return;
+                       state = 1;              /* start over */
+                       break;
+               case '%':
+                       if (state)              /* if 1 or 2 */
+                               ++state;        /* goto 3 */
+                       break;
+               default:
+                       state = 0;              /* reset */
+                       break;
                }
 }
                }
 }
index d361fdb..c32828c 100644 (file)
@@ -12,18 +12,20 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)dirname.c  8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)dirname.c  8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdlib.h>
 
+void usage __P((void));
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern int optind;
-       register char *p;
+       char *p;
        int ch;
 
        while ((ch = getopt(argc, argv, "")) != EOF)
        int ch;
 
        while ((ch = getopt(argc, argv, "")) != EOF)
@@ -61,7 +63,8 @@ main(argc, argv)
         *     shall be removed.
         */
        for (; *p; ++p);
         *     shall be removed.
         */
        for (; *p; ++p);
-       while (*--p == '/');
+       while (*--p == '/')
+               continue;
        *++p = '\0';
 
        /*
        *++p = '\0';
 
        /*
@@ -106,8 +109,10 @@ main(argc, argv)
        exit(0);
 }
 
        exit(0);
 }
 
+void
 usage()
 {
 usage()
 {
+
        (void)fprintf(stderr, "usage: dirname path\n");
        exit(1);
 }
        (void)fprintf(stderr, "usage: dirname path\n");
        exit(1);
 }
index 511047c..ee259d0 100644 (file)
@@ -15,7 +15,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)du.c       8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)du.c       8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -169,20 +169,20 @@ typedef struct _ID {
 
 int
 linkchk(p)
 
 int
 linkchk(p)
-       register FTSENT *p;
+       FTSENT *p;
 {
        static ID *files;
        static int maxfiles, nfiles;
 {
        static ID *files;
        static int maxfiles, nfiles;
-       register ID *fp, *start;
-       register ino_t ino;
-       register dev_t dev;
+       ID *fp, *start;
+       ino_t ino;
+       dev_t dev;
 
        ino = p->fts_statp->st_ino;
        dev = p->fts_statp->st_dev;
        if ((start = files) != NULL)
                for (fp = start + nfiles - 1; fp >= start; --fp)
                        if (ino == fp->inode && dev == fp->dev)
 
        ino = p->fts_statp->st_ino;
        dev = p->fts_statp->st_dev;
        if ((start = files) != NULL)
                for (fp = start + nfiles - 1; fp >= start; --fp)
                        if (ino == fp->inode && dev == fp->dev)
-                               return(1);
+                               return (1);
 
        if (nfiles == maxfiles && (files = realloc((char *)files,
            (u_int)(sizeof(ID) * (maxfiles += 128)))) == NULL)
 
        if (nfiles == maxfiles && (files = realloc((char *)files,
            (u_int)(sizeof(ID) * (maxfiles += 128)))) == NULL)
@@ -190,13 +190,14 @@ linkchk(p)
        files[nfiles].inode = ino;
        files[nfiles].dev = dev;
        ++nfiles;
        files[nfiles].inode = ino;
        files[nfiles].dev = dev;
        ++nfiles;
-       return(0);
+       return (0);
 }
 
 void
 usage()
 {
 }
 
 void
 usage()
 {
+
        (void)fprintf(stderr,
        (void)fprintf(stderr,
-"usage: du [-H | -L | -P] [-a | -s] [-x] [file ...]\n");
+               "usage: du [-H | -L | -P] [-a | -s] [-x] [file ...]\n");
        exit(1);
 }
        exit(1);
 }
index 4efe139..37cacc4 100644 (file)
@@ -12,24 +12,28 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)env.c      8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)env.c      8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <err.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 
+extern char **environ;
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 {
 main(argc, argv)
        int argc;
        char **argv;
 {
-       extern char **environ;
-       extern int errno, optind;
-       register char **ep, *p;
+       char **ep, *p;
        char *cleanenv[1];
        int ch;
 
        while ((ch = getopt(argc, argv, "-")) != EOF)
        char *cleanenv[1];
        int ch;
 
        while ((ch = getopt(argc, argv, "-")) != EOF)
-               switch((char)ch) {
+               switch(ch) {
                case '-':
                        environ = cleanenv;
                        cleanenv[0] = NULL;
                case '-':
                        environ = cleanenv;
                        cleanenv[0] = NULL;
@@ -40,13 +44,11 @@ main(argc, argv)
                            "usage: env [-] [name=value ...] [command]\n");
                        exit(1);
                }
                            "usage: env [-] [name=value ...] [command]\n");
                        exit(1);
                }
-       for (argv += optind; *argv && (p = index(*argv, '=')); ++argv)
+       for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
                (void)setenv(*argv, ++p, 1);
        if (*argv) {
                execvp(*argv, argv);
                (void)setenv(*argv, ++p, 1);
        if (*argv) {
                execvp(*argv, argv);
-               (void)fprintf(stderr, "env: %s: %s\n", *argv,
-                   strerror(errno));
-               exit(1);
+               err(1, "%s", *argv);
        }
        for (ep = environ; *ep; ep++)
                (void)printf("%s\n", *ep);
        }
        for (ep = environ; *ep; ep++)
                (void)printf("%s\n", *ep);