[Cook] Generating tags?

gaulanm mike.gauland at tait.co.nz
Tue Jul 22 06:46:17 EST 2003


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];
}




More information about the Cook-users mailing list