SF.net SVN: geany: [2497] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Thu Apr 17 18:06:33 UTC 2008


Revision: 2497
          http://geany.svn.sourceforge.net/geany/?rev=2497&view=rev
Author:   eht16
Date:     2008-04-17 11:06:31 -0700 (Thu, 17 Apr 2008)

Log Message:
-----------
Improve Makefile parser for better parsing of targets (from CTags' patches tracker, for reference this is patch v3).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tagmanager/make.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-04-17 17:48:12 UTC (rev 2496)
+++ trunk/ChangeLog	2008-04-17 18:06:31 UTC (rev 2497)
@@ -7,6 +7,9 @@
    tagmanager filename (patch by Yura Siamashka, thanks).
    This makes it also possible to add navigation history items for files
    without a tagmanager filename.
+ * tagmanager/make.c:
+   Improve Makefile parser for better parsing of targets
+   (from CTags' patches tracker, for reference this is patch v3).
 
 
 2008-04-16  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>

Modified: trunk/tagmanager/make.c
===================================================================
--- trunk/tagmanager/make.c	2008-04-17 17:48:12 UTC (rev 2496)
+++ trunk/tagmanager/make.c	2008-04-17 18:06:31 UTC (rev 2497)
@@ -31,8 +31,8 @@
 } shKind;
 
 static kindOption MakeKinds [] = {
-	{ TRUE, 'm', "macro", "macros"},
-	{ TRUE, 'f', "function", "targets"}
+	{ TRUE, 'm', "macro",  "macros"},
+	{ TRUE, 't', "function", "targets"}
 };
 
 /*
@@ -72,17 +72,68 @@
 
 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)
+{
+	size_t i = 0;
+	/* All special targets begin with '.'. */
+	if (vStringChar (name, i++) != '.') {
+		return FALSE;
+	}
+	while (i < vStringLength (name)) {
+		char ch = vStringChar (name, i++);
+		if (ch != '_' && !isupper (ch))
+		{
+			return FALSE;
+		}
+	}
+	return TRUE;
+}
+
+static void newTarget (vString *const name)
+{
+	/* Ignore GNU Make's "special targets". */
+	if  (isSpecialTarget (name))
+	{
+		return;
+	}
+	makeSimpleTag (name, MakeKinds, K_TARGET);
+}
+
+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 */
+	vStringCopyS (name, strchr (vStringValue (name), ' ') + 1);
+	makeSimpleTag (name, MakeKinds, K_MACRO);
+}
+
 static void readIdentifier (const int first, vString *const id)
 {
 	int c = first;
+	int c_prev = first;
+	int c_next = first;
 	vStringClear (id);
-	while (isIdentifier (c))
+	while (isIdentifier (c) || c == ' ')
 	{
-		vStringPut (id, c);
-		c = nextChar ();
+		c_next = nextChar ();
+		if (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;
 	}
 	fileUngetc (c);
 	vStringTerminate (id);
@@ -133,7 +184,6 @@
 				else
 					in_rule = FALSE;
 			}
-
 			variable_possible = (boolean)(!in_rule);
 			newline = FALSE;
 		}
@@ -155,18 +205,16 @@
 		else if (variable_possible && isIdentifier (c))
 		{
 			readIdentifier (c, name);
-
-			if (strcmp (vStringValue (name), "endef") == 0)
+			if (strncmp (vStringValue (name), "endef", 5) == 0)
 				in_define = FALSE;
 			else if (in_define)
 				skipLine ();
-			else if (strcmp (vStringValue (name), "define") == 0  &&
+			else if (strncmp (vStringValue (name), "define", 6) == 0  &&
 				isIdentifier (c))
 			{
 				in_define = TRUE;
 				c = skipToNonWhite ();
-				readIdentifier (c, name);
-				makeSimpleTag (name, MakeKinds, K_MACRO);
+				newMacroFromDefine (name);
 				skipLine ();
 			}
 			else {
@@ -174,26 +222,42 @@
 				if (strchr (":?+", c) != NULL)
 				{
 					boolean append = (boolean)(c == '+');
-					if (c == ':')
+					boolean was_colon = (c == ':');
+					c = nextChar ();
+					if (was_colon)
 					{
-						in_rule = TRUE;
-						makeSimpleTag (name, MakeKinds, K_TARGET);
+						if (c == '=')
+						{
+							newMacro (name);
+							in_rule = FALSE;
+							skipLine ();
+						}
+						else
+						{
+							in_rule = TRUE;
+							newTarget (name);
+						}
 					}
-					c = nextChar ();
-					if (c != '=')
-						fileUngetc (c);
 					else if (append)
 					{
 						skipLine ();
 						continue;
 					}
+					else
+					{
+						fileUngetc (c);
+					}
 				}
-				if (c == '=')
+				else if (c == '=')
 				{
-					makeSimpleTag (name, MakeKinds, K_MACRO);
+					newMacro (name);
 					in_rule = FALSE;
 					skipLine ();
 				}
+				else
+				{
+					fileUngetc (c);
+				}
 			}
 		}
 		else


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list