29
33
static kindOption MakeKinds [] = {
30
{ TRUE, 'm', "macro", "macros"}
34
{ TRUE, 'm', "macro", "macros"},
35
{ TRUE, 't', "function", "targets"}
34
39
* FUNCTION DEFINITIONS
42
static int nextChar (void)
54
static void skipLine (void)
59
while (c != EOF && c != '\n');
64
static int skipToNonWhite (void)
69
while (c != '\n' && isspace (c));
37
73
static boolean isIdentifier (int c)
39
return (boolean)(isalnum (c) || c == '_');
75
return (boolean)(c != '\0' && (isalnum (c) || strchr (".-_/", c) != NULL));
78
static boolean isSpecialTarget (vString *const name)
81
/* All special targets begin with '.'. */
82
if (vStringChar (name, i++) != '.') {
85
while (i < vStringLength (name)) {
86
char ch = vStringChar (name, i++);
87
if (ch != '_' && !isupper (ch))
95
static void newTarget (vString *const name)
97
/* Ignore GNU Make's "special targets". */
98
if (isSpecialTarget (name))
102
makeSimpleTag (name, MakeKinds, K_TARGET);
105
static void newMacro (vString *const name)
107
makeSimpleTag (name, MakeKinds, K_MACRO);
110
static void newMacroFromDefine (vString *const name)
112
/* name is something like "define JAVAHPP_RULE", find the space and jump to the next char */
113
vStringCopyS (name, strchr (vStringValue (name), ' ') + 1);
114
makeSimpleTag (name, MakeKinds, K_MACRO);
117
static void readIdentifier (const int first, vString *const id)
123
while (isIdentifier (c) || c == ' ')
125
c_next = nextChar ();
127
/* add the space character only if the previous and
128
* next character are valid identifiers */
129
if (isIdentifier (c_prev) && isIdentifier (c_next))
139
vStringTerminate (id);
142
static void skipToMatch (const char *const pair)
144
const int begin = pair [0], end = pair [1];
145
const unsigned long inputLineNumber = getInputLineNumber ();
149
while (matchLevel > 0)
160
verbose ("%s: failed to find match for '%c' at line %lu\n",
161
getInputFileName (), begin, inputLineNumber);
42
164
static void findMakeTags (void)
44
vString *name = vStringNew ();
45
const unsigned char *line;
47
while ((line = fileReadLine ()) != NULL)
49
const unsigned char* cp = line;
50
boolean possible = TRUE;
52
while (isspace ((int) *cp))
166
vString *name = vStringNew ();
167
boolean newline = TRUE;
168
boolean in_define = FALSE;
169
boolean in_rule = FALSE;
170
boolean variable_possible = TRUE;
173
while ((c = nextChar ()) != EOF)
59
/* We look for any sequence of identifier characters following
60
* either a white space or a colon and followed by either = or :=
62
if (possible && isIdentifier ((int) *cp))
64
while (isIdentifier ((int) *cp))
66
vStringPut (name, (int) *cp);
69
vStringTerminate (name);
70
while (isspace ((int) *cp))
75
makeSimpleTag (name, MakeKinds, K_MACRO);
78
else if (isspace ((int) *cp) || *cp == ':')
181
skipLine (); /* skip rule */
187
variable_possible = (boolean)(!in_rule);
192
else if (isspace (c))
202
variable_possible = TRUE;
205
else if (variable_possible && isIdentifier (c))
207
readIdentifier (c, name);
208
if (strncmp (vStringValue (name), "endef", 5) == 0)
212
else if (strncmp (vStringValue (name), "define", 6) == 0 &&
216
c = skipToNonWhite ();
217
newMacroFromDefine (name);
221
c = skipToNonWhite ();
222
if (strchr (":?+", c) != NULL)
224
boolean append = (boolean)(c == '+');
225
boolean was_colon = (c == ':');
264
variable_possible = FALSE;
266
vStringDelete (name);
89
269
extern parserDefinition* MakefileParser (void)
91
static const char *const patterns [] = { "[Mm]akefile", NULL };
92
static const char *const extensions [] = { "mak", "mk", NULL };
93
parserDefinition* const def = parserNew ("Make");
94
def->kinds = MakeKinds;
95
def->kindCount = KIND_COUNT (MakeKinds);
96
def->patterns = patterns;
97
def->extensions = extensions;
98
def->parser = findMakeTags;
271
static const char *const patterns [] = { "[Mm]akefile", NULL };
272
static const char *const extensions [] = { "mak", "mk", NULL };
273
parserDefinition* const def = parserNew ("Make");
274
def->kinds = MakeKinds;
275
def->kindCount = KIND_COUNT (MakeKinds);
276
def->patterns = patterns;
277
def->extensions = extensions;
278
def->parser = findMakeTags;
102
/* vi:set tabstop=8 shiftwidth=4: */
282
/* vi:set tabstop=4 shiftwidth=4: */