Merge branch '1.37'
[geany-mirror.git] / ctags / main / ctags-api.c
blob20b6898ec53a39e4195f9a17f530163458db1c57
1 /*
2 * Copyright (c) 2016, Jiri Techet
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
7 * Defines ctags API when compiled as a library.
8 */
10 #include "general.h" /* must always come first */
12 #ifdef CTAGS_LIB
14 #include "ctags-api.h"
15 #include "types.h"
16 #include "routines.h"
17 #include "error.h"
18 #include "output.h"
19 #include "parse.h"
20 #include "options.h"
21 #include "trashbox.h"
23 #include <stdio.h>
24 #include <string.h>
25 #include <errno.h>
27 static bool nofatalErrorPrinter (const errorSelection selection,
28 const char *const format,
29 va_list ap, void *data CTAGS_ATTR_UNUSED)
31 fprintf (stderr, "%s: ", (selection & WARNING) ? "Warning: " : "Error");
32 vfprintf (stderr, format, ap);
33 if (selection & PERROR)
34 #ifdef HAVE_STRERROR
35 fprintf (stderr, " : %s", strerror (errno));
36 #else
37 perror (" ");
38 #endif
39 fputs ("\n", stderr);
41 return false;
44 extern void ctagsInit(void)
46 setErrorPrinter (nofatalErrorPrinter, NULL);
47 setTagWriter (&ctagsWriter);
49 checkRegex ();
50 initFieldDescs ();
52 initializeParsing ();
53 initOptions ();
55 initDefaultTrashBox ();
57 /* make sure all parsers are initialized */
58 initializeParser (LANG_AUTO);
63 extern void ctagsParse(unsigned char *buffer, size_t bufferSize,
64 const char *fileName, const langType language,
65 tagEntryFunction tagCallback, passStartCallback passCallback,
66 void *userData)
68 if (buffer == NULL && fileName == NULL)
70 error(FATAL, "Neither buffer nor file provided to ctagsParse()");
71 return;
74 createTagsWithFallback(buffer, bufferSize, fileName, language,
75 tagCallback, passCallback, userData);
79 extern const char *ctagsGetLangName(int lang)
81 return getLanguageName(lang);
85 extern int ctagsGetNamedLang(const char *name)
87 return getNamedLanguage(name, 0);
91 extern const char *ctagsGetLangKinds(int lang)
93 const parserDefinition *def = getParserDefinition(lang);
94 unsigned int i;
95 static char kinds[257];
97 for (i = 0; i < def->kindCount; i++)
98 kinds[i] = def->kindTable[i].letter;
99 kinds[i] = '\0';
101 return kinds;
105 extern const char *ctagsGetKindName(char kind, int lang)
107 const parserDefinition *def = getParserDefinition(lang);
108 unsigned int i;
110 for (i = 0; i < def->kindCount; i++)
112 if (def->kindTable[i].letter == kind)
113 return def->kindTable[i].name;
115 return "unknown";
119 extern char ctagsGetKindFromName(const char *name, int lang)
121 const parserDefinition *def = getParserDefinition(lang);
122 unsigned int i;
124 for (i = 0; i < def->kindCount; i++)
126 if (strcmp(def->kindTable[i].name, name) == 0)
127 return def->kindTable[i].letter;
129 return '-';
133 extern bool ctagsIsUsingRegexParser(int lang)
135 return getParserDefinition(lang)->method & METHOD_REGEX;
139 extern unsigned int ctagsGetLangCount(void)
141 return countParsers();
144 #endif /* CTAGS_LIB */