Fix file names of generated tags files for C, PHP and Python
[geany-mirror.git] / src / tagmanager / tm_ctags_wrappers.c
blob378033da848f7b4fe19bddb357b1507198085649
1 /*
2 * tm_ctags_wrappers.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2016 Jiri Techet <techet(at)gmail(dot)com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "tm_ctags_wrappers.h"
23 #include "general.h"
24 #include "entry.h"
25 #include "parse.h"
26 #include "read.h"
29 typedef struct {
30 TMCtagsNewTagCallback tag_callback;
31 gpointer user_data;
32 } CallbackUserData;
35 void tm_ctags_init(void)
37 initializeParsing();
38 installLanguageMapDefaults();
42 static gboolean parse_callback(const tagEntryInfo *tag, gpointer user_data)
44 CallbackUserData *callback_data = user_data;
46 return callback_data->tag_callback(tag, callback_data->user_data);
50 void tm_ctags_parse(guchar *buffer, gsize buffer_size,
51 const gchar *file_name, TMParserType lang, TMCtagsNewTagCallback tag_callback,
52 TMCtagsPassStartCallback pass_callback, gpointer user_data)
54 CallbackUserData callback_data = {tag_callback, user_data};
55 gboolean retry = TRUE;
56 guint passCount = 0;
58 g_return_if_fail(buffer || file_name);
60 if (! LanguageTable [lang]->enabled)
62 #ifdef TM_DEBUG
63 g_warning("ignoring %s (language disabled)\n", file_name);
64 #endif
65 return;
68 setTagEntryFunction(parse_callback, &callback_data);
69 while (retry && passCount < 3)
71 pass_callback(user_data);
72 if (!buffer && fileOpen (file_name, lang))
74 if (LanguageTable [lang]->parser != NULL)
76 LanguageTable [lang]->parser ();
77 fileClose ();
78 retry = FALSE;
79 break;
81 else if (LanguageTable [lang]->parser2 != NULL)
82 retry = LanguageTable [lang]->parser2 (passCount);
83 fileClose ();
85 else if (buffer && bufferOpen (buffer, buffer_size, file_name, lang))
87 if (LanguageTable [lang]->parser != NULL)
89 LanguageTable [lang]->parser ();
90 bufferClose ();
91 retry = FALSE;
92 break;
94 else if (LanguageTable [lang]->parser2 != NULL)
95 retry = LanguageTable [lang]->parser2 (passCount);
96 bufferClose ();
98 else
100 g_warning("Unable to open %s", file_name);
101 return;
103 ++ passCount;
108 const gchar *tm_ctags_get_lang_name(TMParserType lang)
110 return getLanguageName(lang);
114 TMParserType tm_ctags_get_named_lang(const gchar *name)
116 return getNamedLanguage(name);
120 const gchar *tm_ctags_get_lang_kinds(TMParserType lang)
122 guint i;
123 parserDefinition *def = LanguageTable[lang];
124 static gchar kinds[257];
126 for (i = 0; i < def->kindCount; i++)
127 kinds[i] = def->kinds[i].letter;
128 kinds[i] = '\0';
130 return kinds;
134 const gchar *tm_ctags_get_kind_name(gchar kind, TMParserType lang)
136 guint i;
137 parserDefinition *def = LanguageTable[lang];
139 for (i = 0; i < def->kindCount; i++)
141 if (def->kinds[i].letter == kind)
142 return def->kinds[i].name;
144 return "unknown";
148 gchar tm_ctags_get_kind_from_name(const gchar *name, TMParserType lang)
150 guint i;
151 parserDefinition *def = LanguageTable[lang];
153 for (i = 0; i < def->kindCount; i++)
155 if (g_strcmp0(def->kinds[i].name, name) == 0)
156 return def->kinds[i].letter;
158 return '-';
162 gboolean tm_ctags_is_using_regex_parser(TMParserType lang)
164 return LanguageTable[lang]->method & METHOD_REGEX;
168 guint tm_ctags_get_lang_count(void)
170 return LanguageCount;