forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptag.c
242 lines (208 loc) · 5.94 KB
/
ptag.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
*
* Copyright (c) 1996-2002, Darren Hiebert
* Copyright (c) 2016, Red Hat, Inc.
* Copyright (c) 2016, Masatake YAMATO
*
* Author: Masatake YAMATO <[email protected]>
*
* 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.
*
*/
#include "general.h" /* must always come first */
#include "colprint_p.h"
#include "ctags.h"
#include "debug.h"
#include "entry_p.h"
#include "options_p.h"
#include "parse_p.h"
#include "ptag_p.h"
#include "writer_p.h"
#include <string.h>
static bool ptagMakeFormat (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
char format [11];
const char *formatComment = "unknown format";
sprintf (format, "%u", Option.tagFileFormat);
if (Option.tagFileFormat == 1)
formatComment = "original ctags format";
else if (Option.tagFileFormat == 2)
formatComment =
"extended format; --format=1 will not append ;\" to lines";
return writePseudoTag (desc, format, formatComment, NULL);
}
static bool ptagMakeHowSorted (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
Option.sorted == SO_FOLDSORTED ? "2" :
(Option.sorted == SO_SORTED ? "1" : "0"),
"0=unsorted, 1=sorted, 2=foldcase",
NULL);
}
static bool ptagMakeAuthor (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
AUTHOR_NAME, "", NULL);
}
static bool ptagMakeProgName (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
PROGRAM_NAME, "Derived from Exuberant Ctags", NULL);
}
static bool ptagMakeProgURL (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
return writePseudoTag (desc,
PROGRAM_URL, "official site", NULL);
}
static bool ptagMakeProgVersion (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
const char* repoinfo = ctags_repoinfo? ctags_repoinfo: "";
return writePseudoTag (desc, PROGRAM_VERSION, repoinfo, NULL);
}
#ifdef HAVE_ICONV
static bool ptagMakeFileEncoding (ptagDesc *desc, const void *data CTAGS_ATTR_UNUSED)
{
if (! Option.outputEncoding)
return false;
return writePseudoTag (desc, Option.outputEncoding, "", NULL);
}
#endif
static bool ptagMakeKindSeparators (ptagDesc *desc, const void *data)
{
const langType *language = data;
return makeKindSeparatorsPseudoTags (*language, desc);
}
static bool ptagMakeKindDescriptions (ptagDesc *desc, const void *data)
{
const langType *language = data;
return makeKindDescriptionsPseudoTags (*language, desc);
}
static ptagDesc ptagDescs [] = {
{
/* The prefix is not "TAG_".
Only --output-format=json use this ptag. */
false, "JSON_OUTPUT_VERSION",
"the version of json output stream format",
ptagMakeJsonOutputVersion,
true },
{ true, "TAG_FILE_FORMAT",
"the version of tags file format",
ptagMakeFormat,
true },
{ true, "TAG_FILE_SORTED",
"how tags are sorted",
ptagMakeHowSorted,
true },
{ true, "TAG_PROGRAM_AUTHOR",
"the author of this ctags implementation",
ptagMakeAuthor,
true },
{ true, "TAG_PROGRAM_NAME",
"the name of this ctags implementation",
ptagMakeProgName,
true },
{ true, "TAG_PROGRAM_URL",
"the official site URL of this ctags implementation",
ptagMakeProgURL,
true },
{ true, "TAG_PROGRAM_VERSION",
"the version of this ctags implementation",
ptagMakeProgVersion,
true },
#ifdef HAVE_ICONV
{ true, "TAG_FILE_ENCODING",
"the encoding used in output tags file",
ptagMakeFileEncoding,
true },
#endif
{ false, "TAG_KIND_SEPARATOR",
"the separators used in kinds",
ptagMakeKindSeparators,
false },
{ false, "TAG_KIND_DESCRIPTION",
"the letters, names and descriptions of kinds in a parser",
ptagMakeKindDescriptions,
false },
{ true, "TAG_OUTPUT_MODE",
"the output mode: u-ctags or e-ctags",
ptagMakeCtagsOutputMode,
true },
{ true, "TAG_OUTPUT_FILESEP",
"the separator used in file name (slash or backslash)",
ptagMakeCtagsOutputFilesep,
true },
};
extern bool makePtagIfEnabled (ptagType type, const void *data)
{
ptagDesc *desc;
Assert (0 <= type && type < PTAG_COUNT);
desc = ptagDescs + type;
if (desc->enabled)
return desc->makeTag (desc, data);
else
return false;
}
extern bool isPtagEnabled (ptagType type)
{
ptagDesc *desc;
Assert (0 <= type && type < PTAG_COUNT);
desc = ptagDescs + type;
return desc->enabled;
}
extern bool enablePtag (ptagType type, bool state)
{
bool oldstate;
ptagDesc *desc;
Assert (0 <= type && type < PTAG_COUNT);
desc = ptagDescs + type;
oldstate = desc->enabled;
desc->enabled = state;
return oldstate;
}
extern ptagDesc* getPtagDesc (ptagType type)
{
if (type == PTAG_UNKNOWN
|| type >= PTAG_COUNT)
return NULL;
return ptagDescs + type;
}
extern ptagType getPtagTypeForName (const char *name)
{
int i;
Assert (name);
for (i = 0; i < PTAG_COUNT; i++)
if (strcmp (ptagDescs [i].name, name) == 0)
return i;
return PTAG_UNKNOWN;
}
extern bool isPtagCommonInParsers (ptagType type)
{
ptagDesc* pdesc = getPtagDesc (type);
return pdesc->commonInParsers;
}
static int ptagCompare (struct colprintLine *a, struct colprintLine *b)
{
const char *a_name = colprintLineGetColumn (a, 0);
const char *b_name = colprintLineGetColumn (b, 0);
return strcmp(a_name, b_name);
}
extern void printPtags (bool withListHeader, bool machinable, FILE *fp)
{
struct colprintTable *table = colprintTableNew ("L:NAME",
"L:ENABLED",
"L:DESCRIPTION",
NULL);
for (unsigned int i = 0; i < PTAG_COUNT; i++)
{
struct colprintLine *line = colprintTableGetNewLine (table);
colprintLineAppendColumnCString (line, ptagDescs[i].name);
colprintLineAppendColumnCString (line, ptagDescs[i].enabled
? "on"
: "off");
colprintLineAppendColumnCString (line, ptagDescs[i].description);
}
colprintTableSort (table, ptagCompare);
colprintTablePrint (table, 0, withListHeader, machinable, fp);
colprintTableDelete (table);
}