Skip to content

Commit

Permalink
Create geany.c/h and put isIgnoreToken()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
techee committed Oct 8, 2016
1 parent f1dbf2c commit 0a0ed51
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 68 deletions.
2 changes: 2 additions & 0 deletions ctags/Makefile.am
Expand Up @@ -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 \
Expand Down
80 changes: 80 additions & 0 deletions 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 <string.h>
#include <glib.h>

/* 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;
}
14 changes: 14 additions & 0 deletions 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 */
66 changes: 0 additions & 66 deletions ctags/main/options.c
Expand Up @@ -23,8 +23,6 @@
#include "options.h"
#include "parse.h"

#include <glib.h>

#define CTAGS_ENVIRONMENT "CTAGS"

#define CTAGS_FILE "tags"
Expand Down Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion ctags/main/options.h
Expand Up @@ -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 */
1 change: 1 addition & 0 deletions ctags/parsers/c.c
Expand Up @@ -26,6 +26,7 @@
#include "read.h"
#include "routines.h"
#include "xtag.h"
#include "geany.h"

/*
* MACROS
Expand Down
2 changes: 1 addition & 1 deletion src/symbols.c
Expand Up @@ -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.
Expand Down

0 comments on commit 0a0ed51

Please sign in to comment.