From 0a0ed51792b9af2693b9ec632c1456e62ace0af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Fri, 7 Oct 2016 16:00:49 +0200 Subject: [PATCH] Create geany.c/h and put isIgnoreToken() This is a (hopefully) temporary file where we put geany-specific code that for some reason has to be still in ctags. Put isIgnoreToken() in this file. --- ctags/Makefile.am | 2 ++ ctags/main/geany.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ ctags/main/geany.h | 14 ++++++++ ctags/main/options.c | 66 ------------------------------------ ctags/main/options.h | 1 - ctags/parsers/c.c | 1 + src/symbols.c | 2 +- 7 files changed, 98 insertions(+), 68 deletions(-) create mode 100644 ctags/main/geany.c create mode 100644 ctags/main/geany.h diff --git a/ctags/Makefile.am b/ctags/Makefile.am index 53325b34..483f3b98 100644 --- a/ctags/Makefile.am +++ b/ctags/Makefile.am @@ -64,6 +64,8 @@ libctags_la_SOURCES = \ main/error.c \ main/error.h \ main/gcc-attr.h \ + main/geany.c \ + main/geany.h \ main/general.h \ main/keyword.c \ main/keyword.h \ diff --git a/ctags/main/geany.c b/ctags/main/geany.c new file mode 100644 index 00000000..ddeb7b5e --- /dev/null +++ b/ctags/main/geany.c @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2016, Jiri Techet +* +* This source code is released for free distribution under the terms of the +* GNU General Public License version 2 or (at your option) any later version. +* +* Defines external interface to option processing. +*/ + +#include "general.h" /* must always come first */ + +#include "geany.h" +#include "vstring.h" + +#include +#include + +/* tags_ignore is a NULL-terminated array of strings, read from ~/.config/geany/ignore.tags. + * This file contains a space or newline separated list of symbols which should be ignored + * by the C/C++ parser, see -I command line option of ctags for details. */ +gchar **c_tags_ignore = NULL; + +/* Determines whether or not "name" should be ignored, per the ignore list. + */ +extern bool isIgnoreToken (const char *const name, + bool *const pIgnoreParens, + const char **const replacement) +{ + bool result = false; + + if (c_tags_ignore != NULL) + { + const size_t nameLen = strlen (name); + unsigned int i; + guint len = g_strv_length (c_tags_ignore); + vString *token = vStringNew(); + + if (pIgnoreParens != NULL) + *pIgnoreParens = false; + + for (i = 0 ; i < len ; ++i) + { + size_t tokenLen; + + vStringCopyS (token, c_tags_ignore[i]); + tokenLen = vStringLength (token); + + if (tokenLen >= 2 && vStringChar (token, tokenLen - 1) == '*' && + strncmp (vStringValue (token), name, tokenLen - 1) == 0) + { + result = true; + break; + } + if (strncmp (vStringValue (token), name, nameLen) == 0) + { + if (nameLen == tokenLen) + { + result = true; + break; + } + else if (tokenLen == nameLen + 1 && + vStringChar (token, tokenLen - 1) == '+') + { + result = true; + if (pIgnoreParens != NULL) + *pIgnoreParens = true; + break; + } + else if (vStringChar (token, nameLen) == '=') + { + if (replacement != NULL) + *replacement = vStringValue (token) + nameLen + 1; + break; + } + } + } + vStringDelete (token); + } + return result; +} diff --git a/ctags/main/geany.h b/ctags/main/geany.h new file mode 100644 index 00000000..9d51aef4 --- /dev/null +++ b/ctags/main/geany.h @@ -0,0 +1,14 @@ +/* +* Copyright (c) 2016, Jiri Techet +* +* This source code is released for free distribution under the terms of the +* GNU General Public License version 2 or (at your option) any later version. +* +* Defines external interface to option processing. +*/ +#ifndef CTAGS_GEANY_H +#define CTAGS_GEANY_H + +extern bool isIgnoreToken (const char *const name, bool *const pIgnoreParens, const char **const replacement); + +#endif /* CTAGS_GEANY_H */ diff --git a/ctags/main/options.c b/ctags/main/options.c index 6343cb3d..888e994f 100644 --- a/ctags/main/options.c +++ b/ctags/main/options.c @@ -23,8 +23,6 @@ #include "options.h" #include "parse.h" -#include - #define CTAGS_ENVIRONMENT "CTAGS" #define CTAGS_FILE "tags" @@ -133,67 +131,3 @@ extern bool isIncludeFile (const char *const fileName) { return false; } - -/* tags_ignore is a NULL-terminated array of strings, read from ~/.config/geany/ignore.tags. - * This file contains a space or newline separated list of symbols which should be ignored - * by the C/C++ parser, see -I command line option of ctags for details. */ -gchar **c_tags_ignore = NULL; - -/* Determines whether or not "name" should be ignored, per the ignore list. - */ -extern bool isIgnoreToken (const char *const name, - bool *const pIgnoreParens, - const char **const replacement) -{ - bool result = false; - - if (c_tags_ignore != NULL) - { - const size_t nameLen = strlen (name); - unsigned int i; - guint len = g_strv_length (c_tags_ignore); - vString *token = vStringNew(); - - if (pIgnoreParens != NULL) - *pIgnoreParens = false; - - for (i = 0 ; i < len ; ++i) - { - size_t tokenLen; - - vStringCopyS (token, c_tags_ignore[i]); - tokenLen = vStringLength (token); - - if (tokenLen >= 2 && vStringChar (token, tokenLen - 1) == '*' && - strncmp (vStringValue (token), name, tokenLen - 1) == 0) - { - result = true; - break; - } - if (strncmp (vStringValue (token), name, nameLen) == 0) - { - if (nameLen == tokenLen) - { - result = true; - break; - } - else if (tokenLen == nameLen + 1 && - vStringChar (token, tokenLen - 1) == '+') - { - result = true; - if (pIgnoreParens != NULL) - *pIgnoreParens = true; - break; - } - else if (vStringChar (token, nameLen) == '=') - { - if (replacement != NULL) - *replacement = vStringValue (token) + nameLen + 1; - break; - } - } - } - vStringDelete (token); - } - return result; -} diff --git a/ctags/main/options.h b/ctags/main/options.h index 54044d40..515f91b2 100644 --- a/ctags/main/options.h +++ b/ctags/main/options.h @@ -103,6 +103,5 @@ extern void freeList (stringList** const pString); extern void setDefaultTagFileName (void); extern bool isIncludeFile (const char *const fileName); -extern bool isIgnoreToken (const char *const name, bool *const pIgnoreParens, const char **const replacement); #endif /* CTAGS_MAIN_OPTIONS_H */ diff --git a/ctags/parsers/c.c b/ctags/parsers/c.c index 7035cc1b..1432515e 100644 --- a/ctags/parsers/c.c +++ b/ctags/parsers/c.c @@ -26,6 +26,7 @@ #include "read.h" #include "routines.h" #include "xtag.h" +#include "geany.h" /* * MACROS diff --git a/src/symbols.c b/src/symbols.c index 971b3f72..384162ba 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -118,7 +118,7 @@ symbol_menu; static void load_user_tags(GeanyFiletypeID ft_id); -/* get the tags_ignore list, exported by tagmanager's options.c */ +/* get the tags_ignore list, exported by tagmanager's geany.c */ extern gchar **c_tags_ignore; /* ignore certain tokens when parsing C-like syntax.