Skip to content

Commit

Permalink
make: Support for variable expansions in target names
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Apr 20, 2015
1 parent 0d60359 commit 5bed3b5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
37 changes: 8 additions & 29 deletions tagmanager/ctags/make.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int skipToNonWhite (void)

static boolean isIdentifier (int c)
{
return (boolean)(c != '\0' && (isalnum (c) || strchr (".-_/", c) != NULL));
return (boolean)(c != '\0' && (isalnum (c) || strchr (".-_/$(){}", c) != NULL));
}

static boolean isSpecialTarget (vString *const name)
Expand Down Expand Up @@ -118,14 +118,19 @@ static void newMacroFromDefine (vString *const name)

static void readIdentifier (const int first, vString *const id)
{
int depth = 0;
int c = first;
int c_prev = first;
int c_next = first;
vStringClear (id);
while (isIdentifier (c) || c == ' ')
while (isIdentifier (c) || c == ' ' || (depth > 0 && c != EOF && c != '\n'))
{
c_next = nextChar ();
if (c == ' ') {
if (c == '(' || c == '}')
depth++;
else if (depth > 0 && (c == ')' || c == '}'))
depth--;
if (depth < 1 && c == ' ') {
/* add the space character only if the previous and
* next character are valid identifiers */
if (isIdentifier (c_prev) && isIdentifier (c_next))
Expand All @@ -141,28 +146,6 @@ static void readIdentifier (const int first, vString *const id)
vStringTerminate (id);
}

static void skipToMatch (const char *const pair)
{
const int begin = pair [0], end = pair [1];
const unsigned long inputLineNumber = getInputLineNumber ();
int matchLevel = 1;
int c = '\0';

while (matchLevel > 0)
{
c = nextChar ();
if (c == begin)
++matchLevel;
else if (c == end)
--matchLevel;
else if (c == '\n' || c == EOF)
break;
}
if (c == EOF)
verbose ("%s: failed to find match for '%c' at line %lu\n",
getInputFileName (), begin, inputLineNumber);
}

static void findMakeTags (void)
{
vString *name = vStringNew ();
Expand Down Expand Up @@ -195,10 +178,6 @@ static void findMakeTags (void)
continue;
else if (c == '#')
skipLine ();
else if (c == '(')
skipToMatch ("()");
else if (c == '{')
skipToMatch ("{}");
else if (c == ':')
{
variable_possible = TRUE;
Expand Down
1 change: 1 addition & 0 deletions tests/ctags/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ test_sources = \
line_directives.c \
local.c \
macros.c \
make-target-with-parentheses.mak \
make-variable-on-cmdline.mak \
masm.asm \
matlab_backtracking.m \
Expand Down
1 change: 1 addition & 0 deletions tests/ctags/make-target-with-parentheses.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(obj)/raid6int1.c: F := 6
3 changes: 3 additions & 0 deletions tests/ctags/make-target-with-parentheses.mak.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# format=tagmanager
$(obj)/raid6int1.c�16�0
F�65536�0
1 change: 1 addition & 0 deletions tests/ctags/simple.mak.tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# format=tagmanager
$(obj)/raid6int1.c�16�0
A�65536�0
B�65536�0
C�65536�0
Expand Down

0 comments on commit 5bed3b5

Please sign in to comment.