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"
30 TMCtagsNewTagCallback tag_callback
;
35 void tm_ctags_init(void)
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
;
58 g_return_if_fail(buffer
|| file_name
);
60 if (! LanguageTable
[lang
]->enabled
)
63 g_warning("ignoring %s (language disabled)\n", file_name
);
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 ();
81 else if (LanguageTable
[lang
]->parser2
!= NULL
)
82 retry
= LanguageTable
[lang
]->parser2 (passCount
);
85 else if (buffer
&& bufferOpen (buffer
, buffer_size
, file_name
, lang
))
87 if (LanguageTable
[lang
]->parser
!= NULL
)
89 LanguageTable
[lang
]->parser ();
94 else if (LanguageTable
[lang
]->parser2
!= NULL
)
95 retry
= LanguageTable
[lang
]->parser2 (passCount
);
100 g_warning("Unable to open %s", file_name
);
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
)
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
;
134 const gchar
*tm_ctags_get_kind_name(gchar kind
, TMParserType lang
)
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
;
148 gchar
tm_ctags_get_kind_from_name(const gchar
*name
, TMParserType lang
)
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
;
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
;