forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags.c
78 lines (66 loc) · 1.66 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
/*
*
* Copyright (c) 2000-2003, Darren Hiebert
*
* This source code is released for free distribution under the terms of the
* GNU General Public License.
*
* 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 "flags.h"
#include "vstring.h"
#include "routines.h"
#define LONG_FLAG_OPEN '{'
#define LONG_FLAG_CLOSE '}'
void flagsEval (const char* flags, flagDefinition* defs, unsigned int ndefs, void* data)
{
unsigned int i, j;
if (!flags)
return;
if (!defs)
return;
for (i = 0 ; flags [i] != '\0' ; ++i)
{
if (flags [i] == LONG_FLAG_OPEN)
{
const char* aflag = flags + i + 1;
char* needle_close_paren = strchr(aflag, LONG_FLAG_CLOSE);
const char* param;
char* needle_eqaul;
if (needle_close_paren == NULL)
{
error (WARNING, "long flags specifier opened with `%c' is not closed `%c'",
LONG_FLAG_OPEN, LONG_FLAG_CLOSE);
break;
}
*needle_close_paren = '\0';
needle_eqaul = strchr(aflag, '=');
if ((needle_eqaul == NULL || (needle_eqaul >= needle_close_paren)))
{
needle_eqaul = NULL;
param = NULL;
}
else
{
param = needle_eqaul + 1;
*needle_eqaul = '\0';
}
for ( j = 0 ; j < ndefs ; ++j )
if (defs[j].long_str && (strcmp(aflag, defs[j].long_str) == 0))
defs[j].long_proc(aflag, param, data);
if (needle_eqaul)
*needle_eqaul = '=';
*needle_close_paren = LONG_FLAG_CLOSE;
i = needle_close_paren - flags;
}
else for (j = 0 ; j < ndefs ; ++j)
if (flags[i] == defs[j].short_char)
defs[j].short_proc(flags[i], data);
}
}