Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At the moment it is a bit hard to distinguish which of the functions we are using belong to ctags. To make more explicit what we need from ctags, wrap all ctags-related code and access ctags only using this layer. The interface from tm_ctags_wrappers.h can serve as a base for proper ctags interface if ctags becomes a library.
- Loading branch information
Showing
4 changed files
with
193 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* tm_ctags_wrappers.c - this file is part of Geany, a fast and lightweight IDE | ||
* | ||
* Copyright 2016 Jiri Techet <techet(at)gmail(dot)com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "tm_ctags_wrappers.h" | ||
|
||
#include "general.h" | ||
#include "entry.h" | ||
#include "parse.h" | ||
#include "read.h" | ||
|
||
|
||
typedef struct { | ||
tm_ctags_callback callback; | ||
gpointer user_data; | ||
} CallbackUserData; | ||
|
||
|
||
void tm_ctags_init() | ||
{ | ||
initializeParsing(); | ||
installLanguageMapDefaults(); | ||
} | ||
|
||
|
||
static gboolean parse_callback(const tagEntryInfo *tag, gpointer user_data) | ||
{ | ||
CallbackUserData *callback_data = user_data; | ||
|
||
return callback_data->callback(tag, FALSE, callback_data->user_data); | ||
} | ||
|
||
|
||
void tm_ctags_parse(guchar *buffer, gsize buffer_size, | ||
const gchar *file_name, TMParserType lang, tm_ctags_callback callback, | ||
gpointer user_data) | ||
{ | ||
CallbackUserData callback_data = {callback, user_data}; | ||
gboolean retry = TRUE; | ||
guint passCount = 0; | ||
|
||
g_return_if_fail(buffer || file_name); | ||
|
||
if (! LanguageTable [lang]->enabled) | ||
{ | ||
#ifdef TM_DEBUG | ||
g_warning("ignoring %s (language disabled)\n", file_name); | ||
#endif | ||
return; | ||
} | ||
|
||
setTagEntryFunction(parse_callback, &callback_data); | ||
while (retry && passCount < 3) | ||
{ | ||
callback(NULL, TRUE, user_data); | ||
if (!buffer && fileOpen (file_name, lang)) | ||
{ | ||
if (LanguageTable [lang]->parser != NULL) | ||
{ | ||
LanguageTable [lang]->parser (); | ||
fileClose (); | ||
retry = FALSE; | ||
break; | ||
} | ||
else if (LanguageTable [lang]->parser2 != NULL) | ||
retry = LanguageTable [lang]->parser2 (passCount); | ||
fileClose (); | ||
} | ||
else if (buffer && bufferOpen (buffer, buffer_size, file_name, lang)) | ||
{ | ||
if (LanguageTable [lang]->parser != NULL) | ||
{ | ||
LanguageTable [lang]->parser (); | ||
bufferClose (); | ||
retry = FALSE; | ||
break; | ||
} | ||
else if (LanguageTable [lang]->parser2 != NULL) | ||
retry = LanguageTable [lang]->parser2 (passCount); | ||
bufferClose (); | ||
} | ||
else | ||
{ | ||
g_warning("Unable to open %s", file_name); | ||
return; | ||
} | ||
++ passCount; | ||
} | ||
} | ||
|
||
|
||
const gchar *tm_ctags_get_lang_name(TMParserType lang) | ||
{ | ||
return getLanguageName(lang); | ||
} | ||
|
||
|
||
TMParserType tm_ctags_get_named_lang(const gchar *name) | ||
{ | ||
return getNamedLanguage(name); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* tm_ctags_wrappers.h - this file is part of Geany, a fast and lightweight IDE | ||
* | ||
* Copyright 2016 Jiri Techet <techet(at)gmail(dot)com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#ifndef TM_CTAGS_WRAPPERS | ||
#define TM_CTAGS_WRAPPERS | ||
|
||
#include <glib.h> | ||
|
||
#include "tm_parser.h" | ||
|
||
#include "entry.h" /* for sTagEntryInfo */ | ||
|
||
|
||
G_BEGIN_DECLS | ||
|
||
typedef gboolean (*tm_ctags_callback) (const tagEntryInfo *const tag, | ||
gboolean invalidate, void *user_data); | ||
|
||
|
||
void tm_ctags_init(); | ||
|
||
void tm_ctags_parse(guchar *buffer, gsize buffer_size, | ||
const gchar *file_name, TMParserType lang, tm_ctags_callback callback, | ||
gpointer user_data); | ||
|
||
const gchar *tm_ctags_get_lang_name(TMParserType lang); | ||
|
||
TMParserType tm_ctags_get_named_lang(const gchar *name); | ||
|
||
G_END_DECLS | ||
|
||
#endif /* TM_CTAGS_WRAPPERS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters