Minor update of German translation
[geany-mirror.git] / tagmanager / tcl.c
blob11e77b3edc39585f39b10dd6880c9b86371b43ce
1 /*
2 * $Id$
4 * Copyright (c) 2000-2003, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for generating tags for TCL scripts.
13 * INCLUDE FILES
15 #include "general.h" /* must always come first */
17 #include <string.h>
19 #include "parse.h"
20 #include "read.h"
21 #include "vstring.h"
24 * DATA DEFINITIONS
26 typedef enum {
27 K_CLASS, K_METHOD, K_PROCEDURE, K_MODULE
28 } tclKind;
30 static kindOption TclKinds [] = {
31 { TRUE, 'c', "class", "classes" },
32 { TRUE, 'f', "member", "methods" },
33 { TRUE, 'p', "function", "procedures" },
34 { TRUE, 'm', "namespace", "modules" }
38 * FUNCTION DEFINITIONS
41 static const unsigned char *makeTclTag (
42 const unsigned char *cp,
43 vString *const name,
44 const tclKind kind)
46 vStringClear (name);
47 while ((int) *cp != '\0' && ! isspace ((int) *cp))
49 vStringPut (name, (int) *cp);
50 ++cp;
52 vStringTerminate (name);
53 makeSimpleTag (name, TclKinds, kind);
54 return cp;
57 static boolean match (const unsigned char *line, const char *word)
59 size_t len = strlen (word);
60 boolean matched = (strncmp ((const char*) line, word, len) == 0);
62 if (matched)
64 /* check that the word is followed by a space to avoid detecting something
65 * like "proc_new ..." */
66 matched = isspace (*(line + len));
68 return matched;
71 static void findTclTags (void)
73 vString *name = vStringNew ();
74 const unsigned char *line;
76 while ((line = fileReadLine ()) != NULL)
78 const unsigned char *cp;
80 while (isspace (line [0]))
81 ++line;
83 if (line [0] == '\0' || line [0] == '#')
84 continue;
86 /* read first word */
87 for (cp = line ; *cp != '\0' && ! isspace ((int) *cp) ; ++cp)
89 if (! isspace ((int) *cp))
90 continue;
91 while (isspace ((int) *cp))
92 ++cp;
93 /* Now `line' points at first word and `cp' points at next word */
95 if (match (line, "proc"))
96 cp = makeTclTag (cp, name, K_PROCEDURE);
97 else if (match (line, "class") || match (line, "itcl::class"))
98 cp = makeTclTag (cp, name, K_CLASS);
99 else if (match (line, "public") ||
100 match (line, "protected") ||
101 match (line, "private"))
103 if (match (cp, "method"))
105 cp += 6;
106 while (isspace ((int) *cp))
107 ++cp;
108 cp = makeTclTag (cp, name, K_METHOD);
111 else if (match (line, "method"))
113 cp = makeTclTag (cp, name, K_METHOD);
115 else if (match (line, "oo::class") ) {
116 if (match (cp, "create"))
118 cp += 6;
119 while (isspace ((int) *cp))
120 ++cp;
121 cp = makeTclTag (cp, name, K_CLASS);
124 else if (match (line, "namespace") ) {
125 if (match (cp, "eval"))
127 cp += 4;
128 while (isspace ((int) *cp))
129 ++cp;
130 cp = makeTclTag (cp, name, K_MODULE);
135 vStringDelete (name);
138 extern parserDefinition* TclParser (void)
140 static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
141 parserDefinition* def = parserNew ("Tcl");
142 def->kinds = TclKinds;
143 def->kindCount = KIND_COUNT (TclKinds);
144 def->extensions = extensions;
145 def->parser = findTclTags;
146 return def;
149 /* vi:set tabstop=4 shiftwidth=4: */