/[emacs]/emacs/lib-src/etags.c
ViewVC logotype

Diff of /emacs/lib-src/etags.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3.5 by pot, Mon Sep 17 15:47:23 2001 UTC revision 3.6 by pot, Sat Dec 15 16:07:31 2001 UTC
# Line 32  Inc., 59 Temple Place - Suite 330, Bosto Line 32  Inc., 59 Temple Place - Suite 330, Bosto
32   *      Francesco Potort́ <pot@gnu.org> has maintained it since 1993.   *      Francesco Potort́ <pot@gnu.org> has maintained it since 1993.
33   */   */
34    
35  char pot_etags_version[] = "@(#) pot revision number is 14.21";  char pot_etags_version[] = "@(#) pot revision number is 14.26";
36    
37  #define TRUE    1  #define TRUE    1
38  #define FALSE   0  #define FALSE   0
# Line 61  char pot_etags_version[] = "@(#) pot rev Line 61  char pot_etags_version[] = "@(#) pot rev
61  #else  #else
62  # ifndef __STDC__  # ifndef __STDC__
63  #   define static               /* remove static for old compilers' sake */  #   define static               /* remove static for old compilers' sake */
64    #   define const                /* same for const */
65  # endif  # endif
66  #endif /* !HAVE_CONFIG_H */  #endif /* !HAVE_CONFIG_H */
67    
# Line 148  char pot_etags_version[] = "@(#) pot rev Line 149  char pot_etags_version[] = "@(#) pot rev
149  #endif /* LONG_OPTIONS */  #endif /* LONG_OPTIONS */
150    
151  #ifdef ETAGS_REGEXPS  #ifdef ETAGS_REGEXPS
152    # ifndef HAVE_CONFIG_H          /* this is a standalone compilation */
153    #   ifdef __CYGWIN__            /* compiling on Cygwin */
154                                 !!! NOTICE !!!
155     the regex.h distributed with Cygwin is not compatible with etags, alas!
156    If you want regular expression support, you should delete this notice and
157                  arrange to use the GNU regex.h and regex.c.
158    #   endif
159    # endif
160  # include <regex.h>  # include <regex.h>
161  #endif /* ETAGS_REGEXPS */  #endif /* ETAGS_REGEXPS */
162    
# Line 272  static void Lisp_functions P_((FILE *)); Line 281  static void Lisp_functions P_((FILE *));
281  static void Makefile_targets P_((FILE *));  static void Makefile_targets P_((FILE *));
282  static void Pascal_functions P_((FILE *));  static void Pascal_functions P_((FILE *));
283  static void Perl_functions P_((FILE *));  static void Perl_functions P_((FILE *));
284    static void PHP_functions P_((FILE *));
285  static void Postscript_functions P_((FILE *));  static void Postscript_functions P_((FILE *));
286  static void Prolog_functions P_((FILE *));  static void Prolog_functions P_((FILE *));
287  static void Python_functions P_((FILE *));  static void Python_functions P_((FILE *));
# Line 521  char *Perl_suffixes [] = Line 531  char *Perl_suffixes [] =
531  char *Perl_interpreters [] =  char *Perl_interpreters [] =
532    { "perl", "@PERL@", NULL };    { "perl", "@PERL@", NULL };
533    
534    char *PHP_suffixes [] =
535      { "php", "php3", "php4", NULL };
536    
537  char *plain_C_suffixes [] =  char *plain_C_suffixes [] =
538    { "lm",                       /* Objective lex file */    { "lm",                       /* Objective lex file */
539      "m",                        /* Objective C file */      "m",                        /* Objective C file */
# Line 571  language lang_names [] = Line 584  language lang_names [] =
584    { "makefile",   Makefile_targets,     Makefile_filenames, NULL,       NULL },    { "makefile",   Makefile_targets,     Makefile_filenames, NULL,       NULL },
585    { "pascal",     Pascal_functions,     NULL, Pascal_suffixes,          NULL },    { "pascal",     Pascal_functions,     NULL, Pascal_suffixes,          NULL },
586    { "perl",       Perl_functions,     NULL, Perl_suffixes, Perl_interpreters },    { "perl",       Perl_functions,     NULL, Perl_suffixes, Perl_interpreters },
587      { "php",        PHP_functions,        NULL, PHP_suffixes,             NULL },
588    { "postscript", Postscript_functions, NULL, Postscript_suffixes,      NULL },    { "postscript", Postscript_functions, NULL, Postscript_suffixes,      NULL },
589    { "proc",       plain_C_entries,      NULL, plain_C_suffixes,         NULL },    { "proc",       plain_C_entries,      NULL, plain_C_suffixes,         NULL },
590    { "prolog",     Prolog_functions,     NULL, Prolog_suffixes,          NULL },    { "prolog",     Prolog_functions,     NULL, Prolog_suffixes,          NULL },
# Line 3582  Yacc_entries (inf) Line 3596  Yacc_entries (inf)
3596  }  }
3597    
3598    
3599  /* A useful macro. */  /* Useful macros. */
3600  #define LOOP_ON_INPUT_LINES(file_pointer, line_buffer, char_pointer)    \  #define LOOP_ON_INPUT_LINES(file_pointer, line_buffer, char_pointer)    \
3601    for (lineno = charno = 0;     /* loop initialization */               \    for (lineno = charno = 0;     /* loop initialization */               \
3602         !feof (file_pointer)     /* loop test */                         \         !feof (file_pointer)     /* loop test */                         \
# Line 3592  Yacc_entries (inf) Line 3606  Yacc_entries (inf)
3606             char_pointer = lb.buffer,                                    \             char_pointer = lb.buffer,                                    \
3607             TRUE);                                                       \             TRUE);                                                       \
3608        )        )
3609    #define LOOKING_AT(cp, keyword) /* keyword is a constant string */      \
3610      (strneq ((cp), keyword, sizeof(keyword)-1) /* cp points at kyword */  \
3611       && iswhite((cp)[sizeof(keyword)-1])  /* followed by a blank */       \
3612       && ((cp) = skip_spaces((cp)+sizeof(keyword)-1))) /* skip blanks */
3613    
3614  /*  /*
3615   * Read a file, but do no processing.  This is used to do regexp   * Read a file, but do no processing.  This is used to do regexp
# Line 3971  Perl_functions (inf) Line 3988  Perl_functions (inf)
3988    
3989    LOOP_ON_INPUT_LINES (inf, lb, cp)    LOOP_ON_INPUT_LINES (inf, lb, cp)
3990      {      {
3991        if (*cp++ == 's'        if (LOOKING_AT (cp, "sub"))
           && *cp++ == 'u'  
           && *cp++ == 'b' && iswhite (*cp++))  
3992          {          {
           cp = skip_spaces (cp);  
3993            if (*cp != '\0')            if (*cp != '\0')
3994              {              {
3995                char *sp = cp;                char *sp = cp;
# Line 3987  Perl_functions (inf) Line 4001  Perl_functions (inf)
4001              }              }
4002          }          }
4003         else if (globals         /* only if tagging global vars is enabled */         else if (globals         /* only if tagging global vars is enabled */
4004                  && ((cp = lb.buffer,                  && ((strneq (cp, "my", 2) && (cp+=2))
4005                       *cp++ == 'm'                      || (strneq (cp, "local", 5) && (cp+=5)))
                      && *cp++ == 'y')  
                     || (cp = lb.buffer,  
                         *cp++ == 'l'  
                         && *cp++ == 'o'  
                         && *cp++ == 'c'  
                         && *cp++ == 'a'  
                         && *cp++ == 'l'))  
4006                  && (*cp == '(' || iswhite (*cp)))                  && (*cp == '(' || iswhite (*cp)))
4007          {          {
4008            /* After "my" or "local", but before any following paren or space. */            /* After "my" or "local", but before any following paren or space. */
# Line 4025  Perl_functions (inf) Line 4032  Perl_functions (inf)
4032      }      }
4033  }  }
4034    
4035    
4036  /*  /*
4037   * Python support   * Python support
4038   * Look for /^def[ \t\n]+[^ \t\n(:]+/ or /^class[ \t\n]+[^ \t\n(:]+/   * Look for /^def[ \t\n]+[^ \t\n(:]+/ or /^class[ \t\n]+[^ \t\n(:]+/
# Line 4038  Python_functions (inf) Line 4045  Python_functions (inf)
4045    register char *cp;    register char *cp;
4046    
4047    LOOP_ON_INPUT_LINES (inf, lb, cp)    LOOP_ON_INPUT_LINES (inf, lb, cp)
4048        if (LOOKING_AT (cp, "def") || LOOKING_AT (cp, "class"))
4049          {
4050            while (*cp != '\0' && !iswhite (*cp) && *cp != '(' && *cp != ':')
4051              cp++;
4052            pfnote (NULL, TRUE,
4053                    lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4054          }
4055    }
4056    
4057    
4058    /*
4059     * PHP support
4060     * Look for:
4061     *  - /^[ \t]*function[ \t\n]+[^ \t\n(]+/
4062     *  - /^[ \t]*class[ \t\n]+[^ \t\n]+/
4063     *  - /^[ \t]*define\(\"[^\"]+/
4064     * Only with --members:
4065     *  - /^[ \t]*var[ \t\n]+\$[^ \t\n=;]/
4066     * originally by Diez B. Roggisch 2001-06-06
4067     */
4068    static void
4069    PHP_functions (inf)
4070         FILE *inf;
4071    {
4072      register char *cp;
4073      bool search_identifier = FALSE;
4074    
4075      LOOP_ON_INPUT_LINES (inf, lb, cp)
4076      {      {
4077        if (*cp++ == 'd'        cp = skip_spaces (cp);
4078            && *cp++ == 'e'        if (search_identifier
4079            && *cp++ == 'f' && iswhite (*cp++))            && *cp != '\0')
4080          {          {
4081            cp = skip_spaces (cp);            while (*cp != '\0' && !iswhite (*cp) && *cp != '(')
           while (*cp != '\0' && !iswhite (*cp) && *cp != '(' && *cp != ':')  
4082              cp++;              cp++;
4083            pfnote (NULL, TRUE,            pfnote (NULL, TRUE,
4084                    lb.buffer, cp - lb.buffer + 1, lineno, linecharno);                    lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4085              search_identifier = FALSE;
4086          }          }
4087          else if (LOOKING_AT (cp, "function"))
4088        cp = lb.buffer;          {
4089        if (*cp++ == 'c'            if(*cp == '&')
4090            && *cp++ == 'l'              cp = skip_spaces (cp+1);
4091            && *cp++ == 'a'            if(*cp != '\0')
4092            && *cp++ == 's'              {
4093            && *cp++ == 's' && iswhite (*cp++))                while (*cp != '\0' && !iswhite (*cp) && *cp != '(')
4094                    cp++;
4095                  pfnote (NULL, TRUE,
4096                          lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4097                }
4098              else
4099                search_identifier = TRUE;
4100            }
4101          else if (LOOKING_AT (cp, "class"))
4102            {
4103              if (*cp != '\0')
4104                {
4105                  while (*cp != '\0' && !iswhite (*cp))
4106                    cp++;
4107                  pfnote (NULL, FALSE,
4108                          lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4109                }
4110              else
4111                search_identifier = TRUE;
4112            }
4113          else if (strneq (cp, "define", 6)
4114                   && (cp = skip_spaces (cp+6))
4115                   && *cp++ == '('
4116                   && (*cp == '"' || *cp == '\''))
4117          {          {
4118            cp = skip_spaces (cp);            char quote = *cp++;
4119            while (*cp != '\0' && !iswhite (*cp) && *cp != '(' && *cp != ':')            while (*cp != quote && *cp != '\0')
4120              cp++;              cp++;
4121            pfnote (NULL, TRUE,            pfnote (NULL, FALSE,
4122                      lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4123            }
4124          else if (members
4125                   && LOOKING_AT (cp, "var")
4126                   && *cp == '$')
4127            {
4128              while (*cp != '=' && *cp != ';' && *cp != '\0' && !iswhite(*cp))
4129                cp++;
4130              pfnote (NULL, FALSE,
4131                    lb.buffer, cp - lb.buffer + 1, lineno, linecharno);                    lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4132          }          }
4133      }      }
# Line 4461  Scheme_functions (inf) Line 4528  Scheme_functions (inf)
4528              bp++;              bp++;
4529            get_tag (bp);            get_tag (bp);
4530          }          }
4531        if (bp[0] == '('        if (LOOKING_AT (bp, "(SET!") || LOOKING_AT (bp, "(set!"))
4532            && (bp[1] == 'S' || bp[1] == 's')          get_tag (bp);
           && (bp[2] == 'E' || bp[2] == 'e')  
           && (bp[3] == 'T' || bp[3] == 't')  
           && (bp[4] == '!' || bp[4] == '!')  
           && (iswhite (bp[5])))  
         {  
           bp = skip_non_spaces (bp);  
           bp = skip_spaces (bp);  
           get_tag (bp);  
         }  
4533      }      }
4534  }  }
4535    
# Line 4666  Texinfo_nodes (inf) Line 4724  Texinfo_nodes (inf)
4724  {  {
4725    char *cp, *start;    char *cp, *start;
4726    LOOP_ON_INPUT_LINES (inf, lb, cp)    LOOP_ON_INPUT_LINES (inf, lb, cp)
4727      {      if (LOOKING_AT (cp, "@node"))
4728        if ((*cp++ == '@'        {
4729             && *cp++ == 'n'          start = cp;
4730             && *cp++ == 'o'          while (*cp != '\0' && *cp != ',')
4731             && *cp++ == 'd'            cp++;
4732             && *cp++ == 'e' && iswhite (*cp++)))          pfnote (savenstr (start, cp - start), TRUE,
4733          {                  lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
4734            start = cp = skip_spaces(cp);        }
           while (*cp != '\0' && *cp != ',')  
             cp++;  
           pfnote (savenstr (start, cp - start), TRUE,  
                   lb.buffer, cp - lb.buffer + 1, lineno, linecharno);  
         }  
     }  
4735  }  }
4736    
4737    
# Line 4689  Texinfo_nodes (inf) Line 4741  Texinfo_nodes (inf)
4741   * Assumes that the predicate starts at column 0.   * Assumes that the predicate starts at column 0.
4742   * Only the first clause of a predicate is added.   * Only the first clause of a predicate is added.
4743   */   */
4744  static int prolog_pred P_((char *, char *));  static int prolog_pr P_((char *, char *));
4745  static void prolog_skip_comment P_((linebuffer *, FILE *));  static void prolog_skip_comment P_((linebuffer *, FILE *));
4746  static int prolog_atom P_((char *, int));  static int prolog_atom P_((char *, int));
4747    
# Line 4713  Prolog_functions (inf) Line 4765  Prolog_functions (inf)
4765          continue;          continue;
4766        else if (cp[0] == '/' && cp[1] == '*')    /* comment. */        else if (cp[0] == '/' && cp[1] == '*')    /* comment. */
4767          prolog_skip_comment (&lb, inf);          prolog_skip_comment (&lb, inf);
4768        else if ((len = prolog_pred (cp, last)) > 0)        else if ((len = prolog_pr (cp, last)) > 0)
4769          {          {
4770            /* Predicate.  Store the function name so that we only            /* Predicate.  Store the function name so that we only
4771               generate a tag for the first clause.  */               generate a tag for the first clause.  */
# Line 4748  prolog_skip_comment (plb, inf) Line 4800  prolog_skip_comment (plb, inf)
4800  }  }
4801    
4802  /*  /*
4803   * A predicate definition is added if it matches:   * A predicate or rule definition is added if it matches:
4804   *     <beginning of line><Prolog Atom><whitespace>(   *     <beginning of line><Prolog Atom><whitespace>(
4805     * or  <beginning of line><Prolog Atom><whitespace>:-
4806   *   *
4807   * It is added to the tags database if it doesn't match the   * It is added to the tags database if it doesn't match the
4808   * name of the previous clause header.   * name of the previous clause header.
4809   *   *
4810   * Return the size of the name of the predicate, or 0 if no header   * Return the size of the name of the predicate or rule, or 0 if no
4811   * was found.   * header was found.
4812   */   */
4813  static int  static int
4814  prolog_pred (s, last)  prolog_pr (s, last)
4815       char *s;       char *s;
4816       char *last;                /* Name of last clause. */       char *last;                /* Name of last clause. */
4817  {  {
# Line 4772  prolog_pred (s, last) Line 4825  prolog_pred (s, last)
4825    len = pos;    len = pos;
4826    pos = skip_spaces (s + pos) - s;    pos = skip_spaces (s + pos) - s;
4827    
4828    if ((s[pos] == '(') || (s[pos] == '.'))    if ((s[pos] == '.'
4829      {         || (s[pos] == '(' && (pos += 1))
4830        if (s[pos] == '(')         || (s[pos] == ':' && s[pos + 1] == '-' && (pos += 2)))
4831          pos++;        && (last == NULL          /* save only the first clause */
4832              || len != strlen (last)
4833        /* Save only the first clause. */            || !strneq (s, last, len)))
       if (last == NULL  
           || len != (int)strlen (last)  
           || !strneq (s, last, len))  
4834          {          {
4835            pfnote (savenstr (s, len), TRUE, s, pos, lineno, linecharno);            pfnote (savenstr (s, len), TRUE, s, pos, lineno, linecharno);
4836            return len;            return len;
4837          }          }
4838      }    else
4839    return 0;      return 0;
4840  }  }
4841    
4842  /*  /*
# Line 5817  xrealloc (ptr, size) Line 5867  xrealloc (ptr, size)
5867      fatal ("virtual memory exhausted", (char *)NULL);      fatal ("virtual memory exhausted", (char *)NULL);
5868    return result;    return result;
5869  }  }
5870    
5871    /*
5872     * Local Variables:
5873     * c-indentation-style: gnu
5874     * indent-tabs-mode: t
5875     * tab-width: 8
5876     * c-font-lock-extra-types: ("FILE" "bool" "linebuffer")
5877     * End:
5878     */

Legend:
Removed from v.3.5  
changed lines
  Added in v.3.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26