geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xtag.c
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) 2015, Red Hat, Inc.
4 * Copyright (c) 2015, Masatake YAMATO
5 *
6 * Author: Masatake YAMATO <yamato@redhat.com>
7 *
8 * This source code is released for free distribution under the terms of the
9 * GNU General Public License version 2 or (at your option) any later version.
10 *
11 */
12
13#include "general.h" /* must always come first */
14#include "ctags.h"
15#include "debug.h"
16#include "options.h"
17#include "options_p.h"
18#include "parse_p.h"
19#include "routines.h"
20#include "trashbox.h"
21#include "writer_p.h"
22#include "xtag.h"
23#include "xtag_p.h"
24
25#include <string.h>
26#include <ctype.h>
27
28typedef struct sXtagObject {
33
35{
36 if (!writerCanPrintPtag())
37 return false;
39 return false;
40
41 return ! isDestinationStdout ();
42}
43
45{
46 if (!writerCanPrintPtag())
47 return true;
48 else
49 return false;
50}
51
52static void enableFileKind (xtagDefinition *pdef, bool state)
53{
55 pdef->enabled = state;
56}
57
59 { true, 'F', "fileScope",
60 "Include tags of file scope" },
61 { false, 'f', "inputFile",
62 "Include an entry for the base file name of every input file",
63 NULL,
64 NULL,
66 { false, 'p', "pseudo",
67 "Include pseudo tags",
70 { false, 'q', "qualified",
71 "Include an extra class-qualified tag entry for each tag"},
72 { false, 'r', "reference",
73 "Include reference tags"},
74 { false, 'g', "guest",
75 "Include tags generated by guest parsers"},
76 { true, 's', "subparser",
77 "Include tags generated by subparsers"},
78 { true, '\0', "anonymous",
79 "Include tags for non-named objects like lambda"},
80};
81
82static unsigned int xtagObjectUsed;
83static unsigned int xtagObjectAllocated;
85
87{
88 Assert ((0 <= type) && ((unsigned int)type < xtagObjectUsed));
89 return (xtagObjects + type);
90}
91
93{
94 Assert ((0 <= type) && ((unsigned int)type < xtagObjectUsed));
95
96 return getXtagObject (type)->def;
97}
98
99typedef bool (* xtagPredicate) (xtagObject *pobj, langType language, const void *user_data);
100static xtagType getXtagTypeGeneric (xtagPredicate predicate, langType language, const void *user_data)
101{
102 static bool initialized = false;
103 unsigned int i;
104
105 if (language == LANG_AUTO && (initialized == false))
106 {
107 initialized = true;
109 }
110 else if (language != LANG_IGNORE && (initialized == false))
111 initializeParser (language);
112
113 for (i = 0; i < xtagObjectUsed; i++)
114 {
115 if (predicate (xtagObjects + i, language, user_data))
116 return i;
117 }
118 return XTAG_UNKNOWN;
119}
120
122 const void *user_data)
123{
124 return (pobj->def->letter == *((char *)user_data))? true: false;
125}
126
127extern xtagType getXtagTypeForLetter (char letter)
128{
130}
131
132static bool xtagEqualByNameAndLanguage (xtagObject *pobj, langType language, const void *user_data)
133{
134 const char* name = user_data;
135
136 if ((language == LANG_AUTO || pobj->language == language)
137 && (strcmp (pobj->def->name, name) == 0))
138 return true;
139 else
140 return false;
141}
142
144{
146}
147
149{
150 return colprintTableNew ("L:LETTER", "L:NAME", "L:ENABLED",
151 "L:LANGUAGE", "L:FIXED", "L:DESCRIPTION", NULL);
152}
153
154static void xtagColprintAddLine (struct colprintTable *table, int xtype)
155{
156 xtagObject* xobj = getXtagObject (xtype);
157 xtagDefinition *xdef = xobj->def;
158
159 struct colprintLine *line = colprintTableGetNewLine(table);
160
162 (xdef->letter == NUL_XTAG_LETTER)
163 ? '-'
164 : xdef->letter);
168 xobj->language == LANG_IGNORE
169 ? RSV_NONE
170 : getLanguageName (xobj->language));
173}
174
175extern void xtagColprintAddCommonLines (struct colprintTable *table)
176{
177 for (int i = 0; i < XTAG_COUNT; i++)
178 xtagColprintAddLine (table, i);
179}
180
181extern void xtagColprintAddLanguageLines (struct colprintTable *table, langType language)
182{
183 for (unsigned int i = XTAG_COUNT; i < xtagObjectUsed; i++)
184 {
185 xtagObject* xobj = getXtagObject (i);
186
187 if (xobj->language == language)
188 xtagColprintAddLine (table, i);
189 }
190}
191
192static int xtagColprintCompareLines (struct colprintLine *a , struct colprintLine *b)
193{
194 const char *a_parser = colprintLineGetColumn (a, 3);
195 const char *b_parser = colprintLineGetColumn (b, 3);
196
197 if (strcmp (a_parser, RSV_NONE) == 0
198 && strcmp (b_parser, RSV_NONE) != 0)
199 return -1;
200 else if (strcmp (a_parser, RSV_NONE) != 0
201 && strcmp (b_parser, RSV_NONE) == 0)
202 return 1;
203 else if (strcmp (a_parser, RSV_NONE) != 0
204 && strcmp (b_parser, RSV_NONE) != 0)
205 {
206 int r;
207 r = strcmp (a_parser, b_parser);
208 if (r != 0)
209 return r;
210 }
211 else
212 {
213 int r;
214
215 const char *a_letter = colprintLineGetColumn (a, 0);
216 const char *b_letter = colprintLineGetColumn (b, 0);
217 r = strcmp(a_letter, b_letter);
218 if (r != 0)
219 return r;
220 }
221
222 const char *a_name = colprintLineGetColumn (a, 1);
223 const char *b_name = colprintLineGetColumn (b, 1);
224
225 return strcmp(a_name, b_name);
226}
227
228extern void xtagColprintTablePrint (struct colprintTable *table,
229 bool withListHeader, bool machinable, FILE *fp)
230{
232 colprintTablePrint (table, 0, withListHeader, machinable, fp);
233}
234
235extern bool isXtagEnabled (xtagType type)
236{
237 xtagDefinition* def = getXtagDefinition (type);
238
239 Assert (def);
240
241 if (def->isEnabled)
242 return def->isEnabled (def);
243 else
244 return def->enabled;
245}
246
247extern bool isXtagFixed (xtagType type)
248{
249 xtagDefinition* def = getXtagDefinition (type);
250
251 Assert (def);
252
253 if (def->isFixed)
254 return def->isFixed (def);
255
256 return false;
257}
258
259extern bool enableXtag (xtagType type, bool state)
260{
261 bool old;
262 xtagDefinition* def = getXtagDefinition (type);
263
264 Assert (def);
265
266 old = isXtagEnabled (type);
267
268 if (isXtagFixed(type))
269 def->enabled = old;
270 else if (def->enable)
271 def->enable (def, state);
272 else
273 def->enabled = state;
274
275 def->isEnabled = NULL;
276
277 return old;
278}
279
280extern bool isCommonXtag (xtagType type)
281{
282 return (type < XTAG_COUNT)? true: false;
283}
284
285extern int getXtagOwner (xtagType type)
286{
287 return getXtagObject (type)->language;
288}
289
290const char* getXtagName (xtagType type)
291{
292 xtagDefinition* def = getXtagDefinition (type);
293 if (def)
294 return def->name;
295 else
296 return NULL;
297}
298
299const char* getXtagDescription (xtagType type)
300{
301 xtagDefinition* def = getXtagDefinition (type);
302 if (def)
303 return def->description;
304 else
305 return NULL;
306}
307
308extern void initXtagObjects (void)
309{
310 xtagObject *xobj;
311
315
316 for (unsigned int i = 0; i < ARRAY_SIZE (xtagDefinitions); i++)
317 {
318 xobj = xtagObjects + i;
319 xobj->def = xtagDefinitions + i;
320 xobj->def->xtype = i;
321 xobj->language = LANG_IGNORE;
322 xobj->sibling = XTAG_UNKNOWN;
324 }
325}
326
327extern int countXtags (void)
328{
329 return xtagObjectUsed;
330}
331
332static void updateSiblingXtag (xtagType type, const char* name)
333{
334 int i;
335 xtagObject *xobj;
336
337 for (i = type; i > 0; i--)
338 {
339 xobj = xtagObjects + i - 1;
340 if (xobj->def->name && (strcmp (xobj->def->name, name) == 0))
341 {
342 Assert (xobj->sibling == XTAG_UNKNOWN);
343 xobj->sibling = type;
344 break;
345 }
346 }
347}
348
349extern int defineXtag (xtagDefinition *def, langType language)
350{
351 xtagObject *xobj;
352 size_t i;
353
354 Assert (def);
355 Assert (def->name);
356 for (i = 0; i < strlen (def->name); i++)
357 {
358 Assert ( isalnum (def->name [i]) );
359 }
360 def->letter = NUL_XTAG_LETTER;
361
363 {
366 }
367 xobj = xtagObjects + (xtagObjectUsed);
368 def->xtype = xtagObjectUsed++;
369 xobj->def = def;
370 xobj->language = language;
371 xobj->sibling = XTAG_UNKNOWN;
372
373 updateSiblingXtag (def->xtype, def->name);
374
375 verbose ("Add extra[%d]: %s,%s in %s\n",
376 def->xtype,
377 def->name, def->description,
378 getLanguageName (language));
379
380 return def->xtype;
381}
382
384{
385 xtagObject *xobj;
386
387 xobj = xtagObjects + type;
388 return xobj->sibling;
389}
void colprintLineAppendColumnCString(struct colprintLine *line, const char *column)
Definition: colprint.c:254
void colprintTableSort(struct colprintTable *table, int(*compareFn)(struct colprintLine *, struct colprintLine *))
Definition: colprint.c:235
void colprintLineAppendColumnBool(struct colprintLine *line, bool column)
Definition: colprint.c:280
struct colprintLine * colprintTableGetNewLine(struct colprintTable *table)
Definition: colprint.c:240
struct colprintTable * colprintTableNew(const char *columnHeader,...)
Definition: colprint.c:73
void colprintLineAppendColumnChar(struct colprintLine *line, char column)
Definition: colprint.c:265
void colprintTablePrint(struct colprintTable *table, unsigned int startFrom, bool withHeader, bool machinable, FILE *fp)
Definition: colprint.c:227
const char * colprintLineGetColumn(struct colprintLine *line, unsigned int column)
Definition: colprint.c:285
#define RSV_NONE
Definition: ctags.h:39
#define Assert(c)
Definition: debug.h:47
const gchar * name
Definition: document.c:3219
#define CTAGS_ATTR_UNUSED
Definition: gcc-attr.h:22
vString * line
Definition: geany_cobol.c:133
void verbose(const char *const format,...)
Definition: options.c:655
bool isDestinationStdout(void)
Definition: options.c:3918
const char * getLanguageName(const langType language)
Definition: parse.c:284
void initializeParser(langType lang)
Definition: parse.c:1850
void enableDefaultFileKind(bool state)
Definition: parse.c:2023
#define LANG_IGNORE
Definition: parse.h:27
#define LANG_AUTO
Definition: parse.h:26
#define NULL
Definition: rbtree.h:150
void eFreeIndirect(void **ptr)
Definition: routines.c:263
#define xMalloc(n, Type)
Definition: routines.h:23
#define ARRAY_SIZE(X)
Definition: routines.h:27
#define xRealloc(p, n, Type)
Definition: routines.h:25
bool enabled
Definition: xtag.h:42
bool(* isEnabled)(struct sXtagDefinition *def)
Definition: xtag.h:58
const char * description
Definition: xtag.h:48
void(* enable)(struct sXtagDefinition *def, bool state)
Definition: xtag.h:60
unsigned int xtype
Definition: xtag.h:62
unsigned char letter
Definition: xtag.h:46
const char * name
Definition: xtag.h:47
bool(* isFixed)(struct sXtagDefinition *def)
Definition: xtag.h:59
xtagType sibling
Definition: xtag.c:31
xtagDefinition * def
Definition: xtag.c:29
langType language
Definition: xtag.c:30
#define DEFAULT_TRASH_BOX(PTR, PROC)
Definition: trashbox.h:34
int langType
Definition: types.h:13
bool writerPrintPtagByDefault(void)
Definition: writer.c:186
bool writerCanPrintPtag(void)
Definition: writer.c:115
void xtagColprintTablePrint(struct colprintTable *table, bool withListHeader, bool machinable, FILE *fp)
Definition: xtag.c:228
xtagDefinition * getXtagDefinition(xtagType type)
Definition: xtag.c:92
xtagType getXtagTypeForLetter(char letter)
Definition: xtag.c:127
static xtagType getXtagTypeGeneric(xtagPredicate predicate, langType language, const void *user_data)
Definition: xtag.c:100
bool enableXtag(xtagType type, bool state)
Definition: xtag.c:259
struct sXtagObject xtagObject
static bool isPseudoTagsFixed(xtagDefinition *pdef)
Definition: xtag.c:44
const char * getXtagDescription(xtagType type)
Definition: xtag.c:299
bool(* xtagPredicate)(xtagObject *pobj, langType language, const void *user_data)
Definition: xtag.c:99
xtagType nextSiblingXtag(xtagType type)
Definition: xtag.c:383
static unsigned int xtagObjectUsed
Definition: xtag.c:82
static bool xtagEqualByLetter(xtagObject *pobj, langType language, const void *user_data)
Definition: xtag.c:121
static xtagDefinition xtagDefinitions[]
Definition: xtag.c:58
const char * getXtagName(xtagType type)
Definition: xtag.c:290
struct colprintTable * xtagColprintTableNew(void)
Definition: xtag.c:148
int countXtags(void)
Definition: xtag.c:327
static bool xtagEqualByNameAndLanguage(xtagObject *pobj, langType language, const void *user_data)
Definition: xtag.c:132
bool isXtagFixed(xtagType type)
Definition: xtag.c:247
static void xtagColprintAddLine(struct colprintTable *table, int xtype)
Definition: xtag.c:154
static void updateSiblingXtag(xtagType type, const char *name)
Definition: xtag.c:332
static bool isPseudoTagsEnabled(xtagDefinition *pdef)
Definition: xtag.c:34
static int xtagColprintCompareLines(struct colprintLine *a, struct colprintLine *b)
Definition: xtag.c:192
void initXtagObjects(void)
Definition: xtag.c:308
static void enableFileKind(xtagDefinition *pdef, bool state)
Definition: xtag.c:52
bool isCommonXtag(xtagType type)
Definition: xtag.c:280
static unsigned int xtagObjectAllocated
Definition: xtag.c:83
bool isXtagEnabled(xtagType type)
Definition: xtag.c:235
void xtagColprintAddLanguageLines(struct colprintTable *table, langType language)
Definition: xtag.c:181
xtagType getXtagTypeForNameAndLanguage(const char *name, langType language)
Definition: xtag.c:143
int getXtagOwner(xtagType type)
Definition: xtag.c:285
static xtagObject * xtagObjects
Definition: xtag.c:84
void xtagColprintAddCommonLines(struct colprintTable *table)
Definition: xtag.c:175
static xtagObject * getXtagObject(xtagType type)
Definition: xtag.c:86
int defineXtag(xtagDefinition *def, langType language)
Definition: xtag.c:349
@ XTAG_UNKNOWN
Definition: xtag.h:26
@ XTAG_COUNT
Definition: xtag.h:38
enum eXtagType xtagType
#define NUL_XTAG_LETTER
Definition: xtag.h:45