~ubuntu-branches/ubuntu/utopic/exuberant-ctags/utopic

« back to all changes in this revision

Viewing changes to tcl.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2006-07-31 09:09:12 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20060731090912-rxe2jt8nz6g2k2zx
Tags: 1:5.6-1
* New upstream release (closes: #374097).
* Fix accidentally-unrendered line in ctags(1) (closes: #271323).
* Policy version 3.7.2: no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
*   $Id: tcl.c,v 1.7 2003/04/01 04:55:28 darren Exp $
 
2
*   $Id: tcl.c,v 1.8 2006/05/30 04:37:13 darren Exp $
3
3
*
4
4
*   Copyright (c) 2000-2003, Darren Hiebert
5
5
*
12
12
/*
13
13
*   INCLUDE FILES
14
14
*/
15
 
#include "general.h"    /* must always come first */
 
15
#include "general.h"  /* must always come first */
16
16
 
17
17
#include <string.h>
18
18
 
24
24
*   DATA DEFINITIONS
25
25
*/
26
26
typedef enum {
27
 
    K_CLASS, K_METHOD, K_PROCEDURE
 
27
        K_CLASS, K_METHOD, K_PROCEDURE
28
28
} tclKind;
29
29
 
30
30
static kindOption TclKinds [] = {
31
 
    { TRUE, 'c', "class",     "classes" },
32
 
    { TRUE, 'm', "method",    "methods" },
33
 
    { TRUE, 'p', "procedure", "procedures" }
 
31
        { TRUE, 'c', "class",     "classes" },
 
32
        { TRUE, 'm', "method",    "methods" },
 
33
        { TRUE, 'p', "procedure", "procedures" }
34
34
};
35
35
 
36
36
/*
38
38
*/
39
39
 
40
40
static const unsigned char *makeTclTag (
41
 
        const unsigned char *cp,
42
 
        vString *const name,
43
 
        const tclKind kind)
 
41
                const unsigned char *cp,
 
42
                vString *const name,
 
43
                const tclKind kind)
44
44
{
45
 
    vStringClear (name);
46
 
    while ((int) *cp != '\0'  &&  ! isspace ((int) *cp))
47
 
    {
48
 
        vStringPut (name, (int) *cp);
49
 
        ++cp;
50
 
    }
51
 
    vStringTerminate (name);
52
 
    makeSimpleTag (name, TclKinds, kind);
53
 
    return cp;
 
45
        vStringClear (name);
 
46
        while ((int) *cp != '\0'  &&  ! isspace ((int) *cp))
 
47
        {
 
48
                vStringPut (name, (int) *cp);
 
49
                ++cp;
 
50
        }
 
51
        vStringTerminate (name);
 
52
        makeSimpleTag (name, TclKinds, kind);
 
53
        return cp;
54
54
}
55
55
 
56
56
static boolean match (const unsigned char *line, const char *word)
57
57
{
58
 
    return (boolean) (strncmp ((const char*) line, word, strlen (word)) == 0);
 
58
        return (boolean) (strncmp ((const char*) line, word, strlen (word)) == 0);
59
59
}
60
60
 
61
61
static void findTclTags (void)
62
62
{
63
 
    vString *name = vStringNew ();
64
 
    const unsigned char *line;
65
 
 
66
 
    while ((line = fileReadLine ()) != NULL)
67
 
    {
68
 
        const unsigned char *cp;
69
 
 
70
 
        while (isspace (line [0])) 
71
 
            ++line;
72
 
        
73
 
        if (line [0] == '\0'  ||  line [0] == '#')
74
 
            continue;
75
 
 
76
 
        /* read first word */
77
 
        for (cp = line ; *cp != '\0'  &&  ! isspace ((int) *cp) ; ++cp)
78
 
            ;
79
 
        if (! isspace ((int) *cp))
80
 
            continue;
81
 
        while (isspace ((int) *cp))
82
 
            ++cp;
83
 
        /* Now `line' points at first word and `cp' points at next word */
84
 
 
85
 
        if (match (line, "proc"))
86
 
            cp = makeTclTag (cp, name, K_PROCEDURE);
87
 
        else if (match (line, "class") || match (line, "itcl::class"))
88
 
            cp = makeTclTag (cp, name, K_CLASS);
89
 
        else if (match (line, "public") ||
90
 
                match (line, "protected") ||
91
 
                match (line, "private"))
 
63
        vString *name = vStringNew ();
 
64
        const unsigned char *line;
 
65
 
 
66
        while ((line = fileReadLine ()) != NULL)
92
67
        {
93
 
            if (match (cp, "method"))
94
 
            {
95
 
                cp += 6;
 
68
                const unsigned char *cp;
 
69
 
 
70
                while (isspace (line [0])) 
 
71
                        ++line;
 
72
                
 
73
                if (line [0] == '\0'  ||  line [0] == '#')
 
74
                        continue;
 
75
 
 
76
                /* read first word */
 
77
                for (cp = line ; *cp != '\0'  &&  ! isspace ((int) *cp) ; ++cp)
 
78
                        ;
 
79
                if (! isspace ((int) *cp))
 
80
                        continue;
96
81
                while (isspace ((int) *cp))
97
 
                    ++cp;
98
 
                cp = makeTclTag (cp, name, K_METHOD);
99
 
            }
 
82
                        ++cp;
 
83
                /* Now `line' points at first word and `cp' points at next word */
 
84
 
 
85
                if (match (line, "proc"))
 
86
                        cp = makeTclTag (cp, name, K_PROCEDURE);
 
87
                else if (match (line, "class") || match (line, "itcl::class"))
 
88
                        cp = makeTclTag (cp, name, K_CLASS);
 
89
                else if (match (line, "public") ||
 
90
                                match (line, "protected") ||
 
91
                                match (line, "private"))
 
92
                {
 
93
                        if (match (cp, "method"))
 
94
                        {
 
95
                                cp += 6;
 
96
                                while (isspace ((int) *cp))
 
97
                                        ++cp;
 
98
                                cp = makeTclTag (cp, name, K_METHOD);
 
99
                        }
 
100
                }
100
101
        }
101
 
    }
102
 
    vStringDelete (name);
 
102
        vStringDelete (name);
103
103
}
104
104
 
105
105
extern parserDefinition* TclParser (void)
106
106
{
107
 
    static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
108
 
    parserDefinition* def = parserNew ("Tcl");
109
 
    def->kinds      = TclKinds;
110
 
    def->kindCount  = KIND_COUNT (TclKinds);
111
 
    def->extensions = extensions;
112
 
    def->parser     = findTclTags;
113
 
    return def;
 
107
        static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
 
108
        parserDefinition* def = parserNew ("Tcl");
 
109
        def->kinds      = TclKinds;
 
110
        def->kindCount  = KIND_COUNT (TclKinds);
 
111
        def->extensions = extensions;
 
112
        def->parser     = findTclTags;
 
113
        return def;
114
114
}
115
115
 
116
 
/* vi:set tabstop=8 shiftwidth=4: */
 
116
/* vi:set tabstop=4 shiftwidth=4: */