[Cook] Generating tags?

Jerry Pendergraft jerry at endocardial.com
Tue Jul 22 07:26:16 EST 2003


Sorry for that previous useless blurb - fat fingers....

There are a couple things to help with generating tags files.
One might be to get and install
Exuberant Ctags 5.4, Copyright (C) 1996-2002 Darren Hiebert
http://ctags.sourceforge.net

That gives you a way to generate both (lots) of kinds of tags using a
single program. With --filter=yes allows you to feed the path names of the
files to stdin and output on stdout for redirection.

The recipes I use are below, I provide separate recipes for each kind of
tag file and control what I actually build by adjusting my target list.
So my default might be:
misc = TAGS tags;
all : [programs] [misc];
but one can always modify the list on the command line or on the fly as
you have.

TAGS : [prog_sources] [prog_includes]
{
    function print [wheredo [__FILE__] [__LINE__] "Generating:"] [target];

    cat | tags -e --filter\=yes > [target] ;data
[unsplit "\n" [resolve [prog_includes]]]
[unsplit "\n" [resolve [prog_sources]]]
dataend
}

/* the extra perl/sort here makes a tags file that works for
 * both vi and vim
 */
tags : [prog_sources] [prog_includes]
{
    function print [wheredo [__FILE__] [__LINE__] "Generating:"] [target];

    cat | ctags --filter\=yes --sort\=no |
      perl -ne "\'s/^\\w+::\\s*//;print;\'" | 
      sort > [target];data
[unsplit "\n" [resolve [prog_includes]]]
[unsplit "\n" [resolve [prog_sources]]]
dataend
}

-- 
Jerry Pendergraft                        jerry.pendergraft at endocardial.com
Endocardial Solutions                    voice: 651-523-6935
1350 Energy Lane, Suite 110                fax: 651-644-7897
St Paul, MN 55108-5254                  mobile: 651-491-0163

On Tue, 22 Jul 2003, gaulanm wrote:

> I'd like to use cook to build a 'tags' file for our project.  Below is 
> what I've come up with--can anyone suggest a cleaner way?  I have three 
> separate targets:
>     'cook etags' builds a TAGS file, using the 'etags' program;
>     'cook ctags' builds a tags file, using the 'ctags' program;
>     'cook tags' builds TAGS or tags, based on the user's EDITOR 
> environment variable.
> Thanks for any suggestions,
> Mike
> 
> /*
>  * Build a 'tags' (vi) or 'TAGS') file.  The 'makeTags' function expects
>  * a single argument, either 'tags' or 'TAGS', then makes the appropriate
>  * file, using the 'ctags' or 'etags' program.
>  */
> function makeTags =
> {
>     if [matches "tags" [@1]] then {
>         TagsCommand = "ctags";
>     } else if [matches "TAGS" [@1]] then{
>         TagsCommand = "etags";
>     } else {
>         fail [catenate "Unknown tag file: " [@1]];
>     };
> 
>     /* Remove the old tags file: */
>     rm -f [@1];
> 
>     /*
>      * 'files' is the list of files to extract tags from.  Note that
>      * this may change when switching between the 'leon' and 'synth'
>      * platforms.
>      */
>     files = [src] [header_files];
> 
>     /*
>      * For each file of interest, invoke the tag-generating fuction,
>      * and append the tags to the list.
>      */
>     loop {
>         nextFile = [head [files]];
>     if [not [nextFile]] then loopstop;
>         files = [tail [files]];
>     
>         [shell [TagsCommand] --append [nextFile]];
>     }
> };
> 
> /*
>  * Use 'cook tags' to remake your tags file based on your EDITOR
>  * environment variable (make 'TAGS' using 'etags' if you're using Emacs;
>  * otherwise we assume vi and use 'ctags' to generate 'tags').
>  *
>  * 'set forced' forces the file to be rebuilt, even if the file 'tags' 
> exists.
>  */
> tags: [src] [header_files] set forced
> {
>    if [matches %macs [getenv EDITOR]] then {
>        [makeTags TAGS];
>    } else {
>        [makeTags tags];
>    }
> }
> 
> /*
>  * 'cook ctags' will make a 'tags' file, even if you're using Emacs.
>  */
> ctags:
> {
>     [makeTags tags];
> }
> 
> /*
>  * 'cook etags' will make a 'TAGS' file, even if you're no using Emacs.
>  */
> etags:
> {
>     [makeTags TAGS];
> }
> 
> _______________________________________________
> Cook-users mailing list
> Cook-users at auug.org.au
> http://www.auug.org.au/mailman/listinfo/cook-users
> 




More information about the Cook-users mailing list