f8560c
From 2e9f9f1f5d0fb223b109429b9c904504b7f638e2 Mon Sep 17 00:00:00 2001
f8560c
From: Petr Machata <pmachata@redhat.com>
f8560c
Date: Fri, 8 Aug 2014 16:53:41 +0200
f8560c
Subject: [PATCH] In config files, allow whitespace between identifier and
f8560c
 opening paren
f8560c
f8560c
---
f8560c
 read_config_file.c                    |   61 ++++++--------------------------
f8560c
 testsuite/ltrace.main/parameters2.exp |   14 +++++++-
f8560c
 2 files changed, 25 insertions(+), 50 deletions(-)
f8560c
f8560c
diff --git a/read_config_file.c b/read_config_file.c
f8560c
index ea3ab88..05ff283 100644
f8560c
--- a/read_config_file.c
f8560c
+++ b/read_config_file.c
f8560c
@@ -1,6 +1,6 @@
f8560c
 /*
f8560c
  * This file is part of ltrace.
f8560c
- * Copyright (C) 2011,2012,2013 Petr Machata, Red Hat Inc.
f8560c
+ * Copyright (C) 2011,2012,2013,2014 Petr Machata, Red Hat Inc.
f8560c
  * Copyright (C) 1998,1999,2003,2007,2008,2009 Juan Cespedes
f8560c
  * Copyright (C) 2006 Ian Wienand
f8560c
  * Copyright (C) 2006 Steve Fink
f8560c
@@ -168,38 +168,6 @@ parse_ident(struct locus *loc, char **str)
f8560c
 	return xstrndup(ident, *str - ident);
f8560c
 }
f8560c
 
f8560c
-/*
f8560c
-  Returns position in string at the left parenthesis which starts the
f8560c
-  function's argument signature. Returns NULL on error.
f8560c
-*/
f8560c
-static char *
f8560c
-start_of_arg_sig(char *str) {
f8560c
-	char *pos;
f8560c
-	int stacked = 0;
f8560c
-
f8560c
-	if (!strlen(str))
f8560c
-		return NULL;
f8560c
-
f8560c
-	pos = &str[strlen(str)];
f8560c
-	do {
f8560c
-		pos--;
f8560c
-		if (pos < str)
f8560c
-			return NULL;
f8560c
-		while ((pos > str) && (*pos != ')') && (*pos != '('))
f8560c
-			pos--;
f8560c
-
f8560c
-		if (*pos == ')')
f8560c
-			stacked++;
f8560c
-		else if (*pos == '(')
f8560c
-			stacked--;
f8560c
-		else
f8560c
-			return NULL;
f8560c
-
f8560c
-	} while (stacked > 0);
f8560c
-
f8560c
-	return (stacked == 0) ? pos : NULL;
f8560c
-}
f8560c
-
f8560c
 static int
f8560c
 parse_int(struct locus *loc, char **str, long *ret)
f8560c
 {
f8560c
@@ -1110,7 +1078,6 @@ static int
f8560c
 process_line(struct protolib *plib, struct locus *loc, char *buf)
f8560c
 {
f8560c
 	char *str = buf;
f8560c
-	char *tmp;
f8560c
 
f8560c
 	debug(3, "Reading line %d of `%s'", loc->line_no, loc->filename);
f8560c
 	eat_spaces(&str);
f8560c
@@ -1148,22 +1115,13 @@ process_line(struct protolib *plib, struct locus *loc, char *buf)
f8560c
 	debug(4, " return_type = %d", fun.return_info->type);
f8560c
 
f8560c
 	eat_spaces(&str);
f8560c
-	tmp = start_of_arg_sig(str);
f8560c
-	if (tmp == NULL) {
f8560c
-		report_error(loc->filename, loc->line_no, "syntax error");
f8560c
+	proto_name = parse_ident(loc, &str);
f8560c
+	if (proto_name == NULL)
f8560c
 		goto err;
f8560c
-	}
f8560c
-	*tmp = '\0';
f8560c
 
f8560c
-	proto_name = strdup(str);
f8560c
-	if (proto_name == NULL) {
f8560c
-	oom:
f8560c
-		report_error(loc->filename, loc->line_no,
f8560c
-			     "%s", strerror(errno));
f8560c
+	eat_spaces(&str);
f8560c
+	if (parse_char(loc, &str, '(') < 0)
f8560c
 		goto err;
f8560c
-	}
f8560c
-
f8560c
-	str = tmp + 1;
f8560c
 	debug(3, " name = %s", proto_name);
f8560c
 
f8560c
 	struct param *extra_param = NULL;
f8560c
@@ -1177,8 +1135,13 @@ process_line(struct protolib *plib, struct locus *loc, char *buf)
f8560c
 			if (have_stop == 0) {
f8560c
 				struct param param;
f8560c
 				param_init_stop(¶m;;
f8560c
-				if (prototype_push_param(&fun, &param) < 0)
f8560c
-					goto oom;
f8560c
+				if (prototype_push_param(&fun, &param) < 0) {
f8560c
+				oom:
f8560c
+					report_error(loc->filename,
f8560c
+						     loc->line_no,
f8560c
+						     "%s", strerror(errno));
f8560c
+					goto err;
f8560c
+				}
f8560c
 				have_stop = 1;
f8560c
 			}
f8560c
 			str++;
f8560c
diff --git a/testsuite/ltrace.main/parameters2.exp b/testsuite/ltrace.main/parameters2.exp
f8560c
index 6318fc5..9850079 100644
f8560c
--- a/testsuite/ltrace.main/parameters2.exp
f8560c
+++ b/testsuite/ltrace.main/parameters2.exp
f8560c
@@ -1,5 +1,5 @@
f8560c
 # This file is part of ltrace.
f8560c
-# Copyright (C) 2012, 2013 Petr Machata, Red Hat Inc.
f8560c
+# Copyright (C) 2012, 2013, 2014 Petr Machata, Red Hat Inc.
f8560c
 #
f8560c
 # This program is free software; you can redistribute it and/or
f8560c
 # modify it under the terms of the GNU General Public License as
f8560c
@@ -259,4 +259,16 @@ ltraceMatch1 [ltraceLibTest {
f8560c
     somefunc();
f8560c
 }] {somefunc\(\) *= nil} == 1
f8560c
 
f8560c
+# Test that spaces in function name make no difference.
f8560c
+
f8560c
+ltraceMatch1 [ltraceLibTest {
f8560c
+    void somefunc ();
f8560c
+} {
f8560c
+    void somefunc(void);
f8560c
+} {
f8560c
+    void somefunc(void) {}
f8560c
+} {
f8560c
+    somefunc();
f8560c
+}] {somefunc\(\)} == 1
f8560c
+
f8560c
 ltraceDone
f8560c
-- 
f8560c
1.7.6.5
f8560c