Updated Spanish translation
[anjuta-git-plugin.git] / tagmanager / vim.c
blobc6031fb861370d98774db139a1c3f2d5fd388d32
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 * Thanks are due to Jay Glanville for significant improvements.
11 * This module contains functions for generating tags for user-defined
12 * functions for the Vim editor.
16 * INCLUDE FILES
18 #include "general.h" /* must always come first */
20 #include <string.h>
22 #include "parse.h"
23 #include "read.h"
24 #include "vstring.h"
27 * DATA DEFINITIONS
29 typedef enum {
30 K_AUGROUP,
31 K_FUNCTION,
32 K_VARIABLE
33 } vimKind;
35 static kindOption VimKinds [] = {
36 { TRUE, 'a', "augroup", "autocommand groups" },
37 { TRUE, 'f', "function", "function definitions" },
38 { TRUE, 'v', "variable", "variable definitions" },
42 * FUNCTION DEFINITIONS
45 /* This function takes a char pointer, tries to find a scope separator in the
46 * string, and if it does, returns a pointer to the character after the colon,
47 * and the character defining the scope.
48 * If a colon is not found, it returns the original pointer.
50 static const unsigned char* skipPrefix (const unsigned char* name, int *scope)
52 const unsigned char* result = name;
53 if (scope != NULL)
54 *scope = '\0';
55 if (name[1] == ':')
57 if (scope != NULL)
58 *scope = *name;
59 result = name + 2;
61 else if (strncasecmp ((const char*) name, "<SID>", (size_t) 5) == 0)
63 if (scope != NULL)
64 *scope = *name;
65 result = name + 5;
67 return result;
70 static void findVimTags (void)
72 vString *name = vStringNew ();
73 const unsigned char *line;
74 boolean inFunction = FALSE;
75 int scope;
77 while ((line = fileReadLine ()) != NULL)
79 while (isspace ((int) *line))
80 ++line;
81 if ((int) *line == '"')
82 continue; /* skip comment */
83 if (strncmp ((const char*) line, "fu", (size_t) 2) == 0)
85 const unsigned char *cp = line + 1;
86 inFunction = TRUE;
88 if ((int) *++cp == 'n' && (int) *++cp == 'c' &&
89 (int) *++cp == 't' && (int) *++cp == 'i' &&
90 (int) *++cp == 'o' && (int) *++cp == 'n')
91 ++cp;
92 if ((int) *cp == '!')
93 ++cp;
94 if (isspace ((int) *cp))
96 while (isspace ((int) *cp))
97 ++cp;
98 cp = skipPrefix (cp, &scope);
99 if (isupper ((int) *cp) || scope == 's' || scope == '<')
103 vStringPut (name, (int) *cp);
104 ++cp;
105 } while (isalnum ((int) *cp) || *cp == '_');
106 vStringTerminate (name);
107 makeSimpleTag (name, VimKinds, K_FUNCTION);
108 vStringClear (name);
113 if (strncmp ((const char*) line, "aug", (size_t) 3) == 0)
115 /* Found Autocommand Group (augroup) */
116 const unsigned char *cp = line + 2;
117 if ((int) *++cp == 'r' && (int) *++cp == 'o' &&
118 (int) *++cp == 'u' && (int) *++cp == 'p')
119 ++cp;
120 if (isspace ((int) *cp))
122 while (isspace ((int) *cp))
123 ++cp;
124 if (strncasecmp ((const char*) cp, "end", (size_t) 3) != 0)
128 vStringPut (name, (int) *cp);
129 ++cp;
130 } while (isalnum ((int) *cp) || *cp == '_');
131 vStringTerminate (name);
132 makeSimpleTag (name, VimKinds, K_AUGROUP);
133 vStringClear (name);
138 if (strncmp ((const char*) line, "endf", (size_t) 4) == 0)
139 inFunction = FALSE;
141 if (!inFunction &&
142 strncmp ((const char*) line, "let", (size_t) 3) == 0)
144 /* we've found a variable declared outside of a function!! */
145 const unsigned char *cp = line + 3;
146 /* get the name */
147 if (isspace ((int) *cp))
149 /* deal with spaces, $, @ and & */
150 while (!isalnum ((int) *cp))
151 ++cp;
152 cp = skipPrefix (cp, &scope);
155 vStringPut (name, (int) *cp);
156 ++cp;
157 } while (isalnum ((int) *cp) || *cp == '_');
158 vStringTerminate (name);
159 makeSimpleTag (name, VimKinds, K_VARIABLE);
160 vStringClear (name);
164 vStringDelete (name);
167 extern parserDefinition* VimParser (void)
169 static const char *const extensions [] = { "vim", NULL };
170 parserDefinition* def = parserNew ("Vim");
171 def->kinds = VimKinds;
172 def->kindCount = KIND_COUNT (VimKinds);
173 def->extensions = extensions;
174 def->parser = findVimTags;
175 return def;
178 /* vi:set tabstop=4 shiftwidth=4: */