2006-05-16 19:04:04 +00:00
|
|
|
/*
|
2008-03-21 16:47:17 +00:00
|
|
|
* $Id$
|
2006-05-16 19:04:04 +00:00
|
|
|
*
|
2008-03-21 16:47:17 +00:00
|
|
|
* Copyright (c) 2000-2003, Darren Hiebert
|
2006-05-16 19:04:04 +00:00
|
|
|
*
|
|
|
|
* This source code is released for free distribution under the terms of the
|
|
|
|
* GNU General Public License.
|
|
|
|
*
|
|
|
|
* This module contains functions for generating tags for TCL scripts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INCLUDE FILES
|
|
|
|
*/
|
2008-03-21 16:47:17 +00:00
|
|
|
#include "general.h" /* must always come first */
|
2006-05-16 19:04:04 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "parse.h"
|
|
|
|
#include "read.h"
|
|
|
|
#include "vstring.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DATA DEFINITIONS
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2008-03-21 16:47:17 +00:00
|
|
|
K_CLASS, K_METHOD, K_PROCEDURE
|
2006-05-16 19:04:04 +00:00
|
|
|
} tclKind;
|
|
|
|
|
|
|
|
static kindOption TclKinds [] = {
|
2008-03-21 16:47:17 +00:00
|
|
|
{ TRUE, 'c', "class", "classes" },
|
|
|
|
{ TRUE, 'm', "member", "methods" },
|
|
|
|
{ TRUE, 'p', "function", "procedures" }
|
2006-05-16 19:04:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION DEFINITIONS
|
|
|
|
*/
|
|
|
|
|
2008-03-21 16:47:17 +00:00
|
|
|
static const unsigned char *makeTclTag (
|
|
|
|
const unsigned char *cp,
|
|
|
|
vString *const name,
|
|
|
|
const tclKind kind)
|
|
|
|
{
|
|
|
|
vStringClear (name);
|
|
|
|
while ((int) *cp != '\0' && ! isspace ((int) *cp))
|
|
|
|
{
|
|
|
|
vStringPut (name, (int) *cp);
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
vStringTerminate (name);
|
|
|
|
makeSimpleTag (name, TclKinds, kind);
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean match (const unsigned char *line, const char *word)
|
|
|
|
{
|
2008-08-05 08:54:02 +00:00
|
|
|
size_t len = strlen (word);
|
|
|
|
boolean matched = (strncmp ((const char*) line, word, len) == 0);
|
|
|
|
|
|
|
|
if (matched)
|
|
|
|
{
|
|
|
|
/* check that the word is followed by a space to avoid detecting something
|
|
|
|
* like "proc_new ..." */
|
|
|
|
matched = isspace (*(line + len));
|
|
|
|
}
|
|
|
|
return matched;
|
2008-03-21 16:47:17 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 19:04:04 +00:00
|
|
|
static void findTclTags (void)
|
|
|
|
{
|
2008-03-21 16:47:17 +00:00
|
|
|
vString *name = vStringNew ();
|
|
|
|
const unsigned char *line;
|
2006-05-16 19:04:04 +00:00
|
|
|
|
2008-03-21 16:47:17 +00:00
|
|
|
while ((line = fileReadLine ()) != NULL)
|
|
|
|
{
|
|
|
|
const unsigned char *cp;
|
2006-05-16 19:04:04 +00:00
|
|
|
|
2008-03-21 16:47:17 +00:00
|
|
|
while (isspace (line [0]))
|
|
|
|
++line;
|
2006-05-16 19:04:04 +00:00
|
|
|
|
2008-03-21 16:47:17 +00:00
|
|
|
if (line [0] == '\0' || line [0] == '#')
|
|
|
|
continue;
|
2006-05-16 19:04:04 +00:00
|
|
|
|
2008-03-21 16:47:17 +00:00
|
|
|
/* read first word */
|
|
|
|
for (cp = line ; *cp != '\0' && ! isspace ((int) *cp) ; ++cp)
|
|
|
|
;
|
|
|
|
if (! isspace ((int) *cp))
|
|
|
|
continue;
|
|
|
|
while (isspace ((int) *cp))
|
|
|
|
++cp;
|
|
|
|
/* Now `line' points at first word and `cp' points at next word */
|
|
|
|
|
|
|
|
if (match (line, "proc"))
|
|
|
|
cp = makeTclTag (cp, name, K_PROCEDURE);
|
|
|
|
else if (match (line, "class") || match (line, "itcl::class"))
|
|
|
|
cp = makeTclTag (cp, name, K_CLASS);
|
|
|
|
else if (match (line, "public") ||
|
|
|
|
match (line, "protected") ||
|
|
|
|
match (line, "private"))
|
|
|
|
{
|
|
|
|
if (match (cp, "method"))
|
|
|
|
{
|
|
|
|
cp += 6;
|
|
|
|
while (isspace ((int) *cp))
|
|
|
|
++cp;
|
|
|
|
cp = makeTclTag (cp, name, K_METHOD);
|
|
|
|
}
|
|
|
|
}
|
2006-05-16 19:04:04 +00:00
|
|
|
}
|
2008-03-21 16:47:17 +00:00
|
|
|
vStringDelete (name);
|
2006-05-16 19:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern parserDefinition* TclParser (void)
|
|
|
|
{
|
2008-03-21 16:47:17 +00:00
|
|
|
static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
|
|
|
|
parserDefinition* def = parserNew ("Tcl");
|
|
|
|
def->kinds = TclKinds;
|
|
|
|
def->kindCount = KIND_COUNT (TclKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser = findTclTags;
|
|
|
|
return def;
|
2006-05-16 19:04:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:47:17 +00:00
|
|
|
/* vi:set tabstop=4 shiftwidth=4: */
|