geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

geany_tcl.c
Go to the documentation of this file.
1/*
2* Copyright (c) 2000-2003, Darren Hiebert
3*
4* This source code is released for free distribution under the terms of the
5* GNU General Public License version 2 or (at your option) any later version.
6*
7* This module contains functions for generating tags for TCL scripts.
8*/
9
10/*
11* INCLUDE FILES
12*/
13#include "general.h" /* must always come first */
14
15#include <string.h>
16
17#include "parse.h"
18#include "read.h"
19#include "routines.h"
20#include "vstring.h"
21
22/*
23* DATA DEFINITIONS
24*/
25typedef enum {
28
30 { true, 'c', "class", "classes" },
31 { true, 'm', "method", "methods" },
32 { true, 'p', "procedure", "procedures" },
33 { true, 'n', "module", "modules" }
34};
35
36/*
37* FUNCTION DEFINITIONS
38*/
39
40static const unsigned char *makeTclTag (
41 const unsigned char *cp,
42 vString *const name,
43 const tclKind kind)
44{
46 while ((int) *cp != '\0' && ! isspace ((int) *cp))
47 {
48 vStringPut (name, (int) *cp);
49 ++cp;
50 }
51 makeSimpleTag (name, kind);
52 return cp;
53}
54
55static bool match (const unsigned char *line, const char *word)
56{
57 size_t len = strlen (word);
58 bool matched = (strncmp ((const char*) line, word, len) == 0);
59
60 if (matched)
61 {
62 /* check that the word is followed by a space to avoid detecting something
63 * like "proc_new ..." */
64 matched = isspace (*(line + len));
65 }
66 return matched;
67}
68
69static void findTclTags (void)
70{
72 const unsigned char *line;
73
74 while ((line = readLineFromInputFile ()) != NULL)
75 {
76 const unsigned char *cp;
77
78 while (isspace (line [0]))
79 ++line;
80
81 if (line [0] == '\0' || line [0] == '#')
82 continue;
83
84 /* read first word */
85 for (cp = line ; *cp != '\0' && ! isspace ((int) *cp) ; ++cp)
86 ;
87 if (! isspace ((int) *cp))
88 continue;
89 while (isspace ((int) *cp))
90 ++cp;
91 /* Now `line' points at first word and `cp' points at next word */
92
93 if (match (line, "proc"))
94 cp = makeTclTag (cp, name, K_PROCEDURE);
95 else if (match (line, "class") || match (line, "itcl::class"))
96 cp = makeTclTag (cp, name, K_CLASS);
97 else if (match (line, "public") ||
98 match (line, "protected") ||
99 match (line, "private"))
100 {
101 if (match (cp, "method"))
102 {
103 cp += 6;
104 while (isspace ((int) *cp))
105 ++cp;
106 cp = makeTclTag (cp, name, K_METHOD);
107 }
108 }
109 else if (match (line, "method"))
110 {
111 cp = makeTclTag (cp, name, K_METHOD);
112 }
113 else if (match (line, "oo::class") ) {
114 if (match (cp, "create"))
115 {
116 cp += 6;
117 while (isspace ((int) *cp))
118 ++cp;
119 cp = makeTclTag (cp, name, K_CLASS);
120 }
121 }
122 else if (match (line, "namespace") ) {
123 if (match (cp, "eval"))
124 {
125 cp += 4;
126 while (isspace ((int) *cp))
127 ++cp;
128 cp = makeTclTag (cp, name, K_MODULE);
129 }
130 }
131
132 }
134}
135
137{
138 static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
139 parserDefinition* def = parserNew ("Tcl");
140 def->kindTable = TclKinds;
142 def->extensions = extensions;
143 def->parser = findTclTags;
144 return def;
145}
const gchar * name
Definition: document.c:3219
vString * line
Definition: geany_cobol.c:133
static bool match(const unsigned char *line, const char *word)
Definition: geany_tcl.c:55
static const unsigned char * makeTclTag(const unsigned char *cp, vString *const name, const tclKind kind)
Definition: geany_tcl.c:40
tclKind
Definition: geany_tcl.c:25
@ K_MODULE
Definition: geany_tcl.c:26
@ K_METHOD
Definition: geany_tcl.c:26
@ K_PROCEDURE
Definition: geany_tcl.c:26
@ K_CLASS
Definition: geany_tcl.c:26
parserDefinition * TclParser(void)
Definition: geany_tcl.c:136
static kindDefinition TclKinds[]
Definition: geany_tcl.c:29
static void findTclTags(void)
Definition: geany_tcl.c:69
parserDefinition * parserNew(const char *name)
Definition: parse.c:237
int makeSimpleTag(const vString *const name, const int kindIndex)
Definition: parse.c:182
#define NULL
Definition: rbtree.h:150
const unsigned char * readLineFromInputFile(void)
Definition: read.c:1000
#define ARRAY_SIZE(X)
Definition: routines.h:27
const char *const * extensions
Definition: parse.h:78
simpleParser parser
Definition: parse.h:83
kindDefinition * kindTable
Definition: parse.h:76
unsigned int kindCount
Definition: parse.h:77
vString * vStringNew(void)
Definition: vstring.c:70
void vStringDelete(vString *const string)
Definition: vstring.c:60
#define vStringClear(string)
Definition: vstring.h:36
static void vStringPut(vString *const string, const int c)
Definition: vstring.h:101