forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.c
157 lines (130 loc) · 3.86 KB
/
flags.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
/*
*
* Copyright (c) 2000-2003, Darren Hiebert
*
* 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.
*
* This module contains functions to process command line options.
*/
/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */
#include <string.h>
#include <stdio.h>
#include "ctags.h"
#include "flags_p.h"
#include "vstring.h"
#include "routines.h"
extern const char *flagsEval (const char* flags_original, flagDefinition* defs, unsigned int ndefs, void* data)
{
unsigned int i, j;
char *flags;
const char *optscript = NULL;
if (!flags_original)
return NULL;
flags = eStrdup (flags_original);
for (i = 0 ; flags [i] != '\0' ; ++i)
{
if (flags [i] == LONG_FLAGS_OPEN && flags [i + 1] == LONG_FLAGS_OPEN)
{
optscript = flags_original + i;
break;
}
else if (flags [i] == LONG_FLAGS_OPEN)
{
const char* aflag = flags + i + 1;
char* needle_close_paren = strchr(aflag, LONG_FLAGS_CLOSE);
const char* param;
char* needle_equal;
if (needle_close_paren == NULL)
{
error (WARNING, "long flags specifier opened with `%c' is not closed `%c': \"%s\"",
LONG_FLAGS_OPEN, LONG_FLAGS_CLOSE, flags_original);
break;
}
*needle_close_paren = '\0';
needle_equal = strchr(aflag, '=');
if ((needle_equal == NULL || (needle_equal >= needle_close_paren)))
{
needle_equal = NULL;
param = NULL;
}
else
{
param = needle_equal + 1;
*needle_equal = '\0';
}
for ( j = 0 ; j < ndefs ; ++j )
if (defs[j].longStr && (strcmp(aflag, defs[j].longStr) == 0))
defs[j].longProc(aflag, param, data);
if (needle_equal)
*needle_equal = '=';
*needle_close_paren = LONG_FLAGS_CLOSE;
i = needle_close_paren - flags;
}
else for (j = 0 ; j < ndefs ; ++j)
if (flags[i] == defs[j].shortChar)
defs[j].shortProc(flags[i], data);
}
eFree (flags);
return optscript;
}
extern struct colprintTable * flagsColprintTableNew (void)
{
return colprintTableNew ("L:LETTER", "L:NAME", "L:DESCRIPTION", NULL);
}
extern void flagsColprintAddDefinitions (struct colprintTable *table, flagDefinition* def,
unsigned int ndefs)
{
vString *longName = vStringNew ();
for (unsigned int i = 0; i < ndefs; i++)
{
struct colprintLine * line;
char shortChar;
const char *paramName;
const char *description;
line = colprintTableGetNewLine(table);
shortChar = def[i].shortChar;
if (shortChar == '\0')
shortChar = '-';
colprintLineAppendColumnChar (line, shortChar);
vStringCopyS (longName, def[i].longStr? def[i].longStr: RSV_NONE);
paramName = def[i].paramName;
if (paramName)
{
vStringPut (longName, '=');
vStringCatS (longName, paramName);
}
colprintLineAppendColumnVString (line, longName);
vStringClear(longName);
description = def[i].description? def[i].description: "";
colprintLineAppendColumnCString (line, description);
}
vStringDelete(longName);
}
static int flagsColprintCompareLines(struct colprintLine *a , struct colprintLine *b)
{
const char *a_letter = colprintLineGetColumn (a, 0);
const char *b_letter = colprintLineGetColumn (b, 0);
if (a_letter[0] != '-' && b_letter[0] == '-')
return -1;
else if (a_letter[0] == '-' && b_letter[0] != '-')
return 1;
else if (a_letter[0] != '-' && b_letter[0] != '-')
return strcmp(a_letter, b_letter);
const char *a_name = colprintLineGetColumn (a, 1);
const char *b_name = colprintLineGetColumn (b, 1);
if (a_name[0] != '_' && b_name[0] == '_')
return -1;
else if (a_name[0] == '_' && b_name[0] != '_')
return 1;
return strcmp(a_name, b_name);
}
extern void flagsColprintTablePrint (struct colprintTable *table,
bool withListHeader, bool machinable, FILE *fp)
{
colprintTableSort (table, flagsColprintCompareLines);
colprintTablePrint (table, 0, withListHeader, machinable, fp);
}