diff --git a/tagmanager/ctags/make.c b/tagmanager/ctags/make.c index bc8a1488..37ad5882 100644 --- a/tagmanager/ctags/make.c +++ b/tagmanager/ctags/make.c @@ -105,42 +105,19 @@ static void newMacro (vString *const name) makeSimpleTag (name, MakeKinds, K_MACRO); } -static void newMacroFromDefine (vString *const name) -{ - /* name is something like "define JAVAHPP_RULE", find the space and jump to the next char */ - char *name_val = strchr (vStringValue (name), ' '); - - if (name_val != NULL) { - vStringCopyS (name, name_val + 1); - makeSimpleTag (name, MakeKinds, K_MACRO); - } -} - 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 == ' ' || (depth > 0 && c != EOF && c != '\n')) + while (isIdentifier (c) || (depth > 0 && c != EOF && c != '\n')) { - c_next = nextChar (); 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)) - vStringPut (id, c); - } - else { - vStringPut (id, c); - } - c_prev = c; - c = c_next; + vStringPut (id, c); + c = nextChar (); } fileUngetc (c); vStringTerminate (id); @@ -148,7 +125,7 @@ static void readIdentifier (const int first, vString *const id) static void findMakeTags (void) { - vString *name = vStringNew (); + stringList *identifiers = stringListNew (); boolean newline = TRUE; boolean in_define = FALSE; boolean in_rule = FALSE; @@ -169,6 +146,7 @@ static void findMakeTags (void) else in_rule = FALSE; } + stringListClear (identifiers); variable_possible = (boolean)(!in_rule); newline = FALSE; } @@ -178,74 +156,70 @@ static void findMakeTags (void) continue; else if (c == '#') skipLine (); - else if (c == ':') + else if (variable_possible && c == '?') { - variable_possible = TRUE; - in_rule = TRUE; + c = nextChar (); + fileUngetc (c); + variable_possible = (c == '='); + } + else if (variable_possible && c == ':' && + stringListCount (identifiers) > 0) + { + c = nextChar (); + fileUngetc (c); + if (c != '=') + { + unsigned int i; + for (i = 0; i < stringListCount (identifiers); i++) + newTarget (stringListItem (identifiers, i)); + stringListClear (identifiers); + in_rule = TRUE; + } + } + else if (variable_possible && c == '=' && + stringListCount (identifiers) == 1) + { + newMacro (stringListItem (identifiers, 0)); + skipLine (); + in_rule = FALSE; } else if (variable_possible && isIdentifier (c)) { + vString *name = vStringNew (); readIdentifier (c, name); - if (strncmp (vStringValue (name), "endef", 5) == 0) - in_define = FALSE; - else if (in_define) - skipLine (); - else if (strncmp (vStringValue (name), "define", 6) == 0 && - isIdentifier (c)) + stringListAdd (identifiers, name); + + if (stringListCount (identifiers) == 1) { - in_define = TRUE; - c = skipToNonWhite (); - newMacroFromDefine (name); - skipLine (); - } - else { - c = skipToNonWhite (); - if (strchr (":?+", c) != NULL) - { - boolean append = (boolean)(c == '+'); - boolean was_colon = (c == ':'); - c = nextChar (); - if (was_colon) - { - if (c == '=') - { - newMacro (name); - in_rule = FALSE; - skipLine (); - } - else - { - fileUngetc (c); - in_rule = TRUE; - newTarget (name); - } - } - else if (append) - { - skipLine (); - continue; - } - else - { - fileUngetc (c); - } - } - else if (c == '=') - { - newMacro (name); - in_rule = FALSE; + if (in_define && ! strcmp (vStringValue (name), "endef")) + in_define = FALSE; + else if (in_define) skipLine (); - } - else + else if (! strcmp (vStringValue (name), "define")) { - fileUngetc (c); + in_define = TRUE; + c = skipToNonWhite (); + vStringClear (name); + /* all remaining characters on the line are the name -- even spaces */ + while (c != EOF && c != '\n') + { + vStringPut (name, c); + c = nextChar (); + } + if (c == '\n') + fileUngetc (c); + vStringTerminate (name); + vStringStripTrailing (name); + newMacro (name); } + else if (! strcmp (vStringValue (name), "export")) + stringListClear (identifiers); } } else variable_possible = FALSE; } - vStringDelete (name); + stringListDelete (identifiers); } extern parserDefinition* MakefileParser (void) diff --git a/tests/ctags/Makefile.am b/tests/ctags/Makefile.am index c0854414..bd4d4042 100644 --- a/tests/ctags/Makefile.am +++ b/tests/ctags/Makefile.am @@ -200,6 +200,7 @@ test_sources = \ line_directives.c \ local.c \ macros.c \ + make-multi-target.mak \ make-target-with-parentheses.mak \ make-variable-on-cmdline.mak \ masm.asm \ diff --git a/tests/ctags/make-multi-target.mak b/tests/ctags/make-multi-target.mak new file mode 100644 index 00000000..e4a30837 --- /dev/null +++ b/tests/ctags/make-multi-target.mak @@ -0,0 +1,8 @@ + +all: foo bar + +foo bar: baz + echo $@ + +baz: + echo $@ diff --git a/tests/ctags/make-multi-target.mak.tags b/tests/ctags/make-multi-target.mak.tags new file mode 100644 index 00000000..c2fd9409 --- /dev/null +++ b/tests/ctags/make-multi-target.mak.tags @@ -0,0 +1,5 @@ +# format=tagmanager +allÌ16Ö0 +barÌ16Ö0 +bazÌ16Ö0 +fooÌ16Ö0 diff --git a/tests/ctags/simple.mak.tags b/tests/ctags/simple.mak.tags index fe05578c..e6879130 100644 --- a/tests/ctags/simple.mak.tags +++ b/tests/ctags/simple.mak.tags @@ -8,7 +8,7 @@ E FÌ65536Ö0 GÌ65536Ö0 HÌ65536Ö0 +IÌ65536Ö0 a.oÌ16Ö0 b.oÌ16Ö0 defaultÌ16Ö0 -export IÌ65536Ö0