git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/7] Change parse_attr() to take a pointer to struct attr_state

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Aug 12, 2011, 21:43 UTC
Message-ID
<1313185390-19724-5-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1313185390-19724-1-git-send-email-mhagger@alum.mit.edu>

parse_attr() only needs access to the attr_state to which it should store its results, not to the whole match_attr structure. This change also removes the need for it to know num_attr. Change its signature accordingly and add a comment.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 attr.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/attr.c b/attr.c
index cac550d..f23f62a 100644
--- a/attr.c
+++ b/attr.c
@@ -139,8 +139,15 @@ struct match_attr {
 
 static const char blank[] = " \t\r\n";
 
+/*
+ * Parse a whitespace-delimited attribute state (i.e., "attr",
+ * "-attr", "!attr", or "attr=value") from the string starting at src.
+ * If e is not NULL, write the results to *e.  Return a pointer to the
+ * remainder of the string (with leading whitespace removed), or NULL
+ * if there was an error.
+ */
 static const char *parse_attr(const char *src, int lineno, const char *cp,
-			      int num_attr, struct match_attr *res)
+			      struct attr_state *e)
 {
 	const char *ep, *equals;
 	int len;
@@ -153,7 +160,7 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
 		len = equals - cp;
 	else
 		len = ep - cp;
-	if (!res) {
+	if (!e) {
 		if (*cp == '-' || *cp == '!') {
 			cp++;
 			len--;
@@ -165,9 +172,6 @@ static const char *parse_attr(const char *src, int lineno, const char *cp,
 			return NULL;
 		}
 	} else {
-		struct attr_state *e;
-
-		e = &(res->state[num_attr]);
 		if (*cp == '-' || *cp == '!') {
 			e->setto = (*cp == '-') ? ATTR__FALSE : ATTR__UNSET;
 			cp++;
@@ -225,7 +229,8 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
 		cp = name + namelen;
 		cp = cp + strspn(cp, blank);
 		while (*cp) {
-			cp = parse_attr(src, lineno, cp, num_attr, res);
+			cp = parse_attr(src, lineno, cp,
+				pass ? &(res->state[num_attr]) : NULL);
 			if (!cp)
 				return NULL;
 			num_attr++;
-- 
1.7.6.8.gd2879
Previous: Michael HaggertyNext: Michael Haggerty
Message 5 of 8 in “Comments and refactoring in attr.c”
  1. 0/7 Comments and refactoring in attr.cMichael Haggerty, Aug 12, 2011
  2. 1/7 Add a file commentMichael Haggerty, Aug 12, 2011
  3. 2/7 Document struct match_attrMichael Haggerty, Aug 12, 2011
  4. 3/7 Increment num_attr in parse_attr_line(), not parse_attr()Michael Haggerty, Aug 12, 2011
  5. 4/7 Change parse_attr() to take a pointer to struct attr_stateMichael Haggerty, Aug 12, 2011
  6. 5/7 Determine the start of the states outside of the pass loopMichael Haggerty, Aug 12, 2011
  7. 6/7 Change while loop into for loopMichael Haggerty, Aug 12, 2011
  8. 7/7 Unroll the loop over passesMichael Haggerty, Aug 12, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.