Hi,

ok I hope this patches are now ok for you to commit.

Regards,
Patrick Niklaus
From 3a8292a556cbed2ce05a878e842b7590263e4944 Mon Sep 17 00:00:00 2001
From: marex <[EMAIL PROTECTED]>
Date: Thu, 12 Apr 2007 19:21:14 +0200
Subject: [PATCH] Fixed list parsing (plugged a memory leak)

---
 plugins/ini.c |   70 +++++++++++++++++++++++---------------------------------
 1 files changed, 29 insertions(+), 41 deletions(-)

diff --git a/plugins/ini.c b/plugins/ini.c
index c55d897..c7659c7 100644
--- a/plugins/ini.c
+++ b/plugins/ini.c
@@ -397,53 +397,47 @@ iniParseLine (char *line, char **optionName, char **optionValue)
 static Bool
 csvToList (char *csv, CompListValue *list, CompOptionType type)
 {
-    char *csvtmp, *split, *item = NULL;
-    int  count = 1, i, itemLength;
+    char *split_start = NULL;
+    char *split_end = NULL;
+    char *item = NULL;
+    int itemLength;
+    int count;
+    int i;
 
     if (csv[0] == '\0')
     {
 	list->nValue = 0;
 	return FALSE;
     }
+ 
+    count = 0;
+    for (i = 0; csv[i] != '\0'; i++)
+	if (csv[i] == ',')
+	    count++;
 
-    csvtmp = strdup (csv);
-    csvtmp = strchr (csv, ',');
-
-    while (csvtmp)
-    {
-	csvtmp++;  /* avoid the comma */
-	count++;
-	csvtmp = strchr (csvtmp, ',');
-    }
-
+    split_start = csv;
     list->value = malloc (sizeof (CompOptionValue) * count);
     if (list->value)
     {
-	for (i=0; i<count; i++)
+	for (i = 0; i < count; i++)
 	{
-	    split = strchr (csv, ',');
-	    if (split)
+	    split_end = strchr(split_start, ',');
+
+	    if (split_end)
 	    {
-		/* > 1 value */
-		itemLength = strlen(csv) - strlen(split);
-		item = realloc (item, sizeof (char) * (itemLength+1));
-		strncpy (item, csv, itemLength);
-		item[itemLength] = '\0';
-		csv += itemLength + 1;
+		itemLength = strlen(split_start) - strlen(split_end);
+		item = strndup(split_start, itemLength);
 	    }
-	    else
+	    else // last value
 	    {
-		/* 1 value only */
-		itemLength = strlen(csv);
-		item = realloc (item, sizeof (char) * (itemLength+1));
-		strncpy (item, csv, itemLength);
-		item[itemLength] = '\0';
+		item = strdup(split_start);
 	    }
 
 	    switch (type)
 	    {
 		case CompOptionTypeString:
-		    list->value[i].s = strdup (item);
+		    if (item[0] != '\0')
+			list->value[i].s = strdup (item);
 		    break;
 		case CompOptionTypeBool:
 		    if (item[0] != '\0')
@@ -464,13 +458,14 @@ csvToList (char *csv, CompListValue *list, CompOptionType type)
 		default:
 		    break;
 	    }
+
+	    split_start = ++split_end;
+	    if (item)
+		free(item);
 	}
 	list->nValue = count;
     }
 
-    if (item)
-	free (item);
-
     return TRUE;
 }

-- 
1.5.0

From a64c0092b4d3735b9d526524f1ba0e64dd676c09 Mon Sep 17 00:00:00 2001
From: marex <[EMAIL PROTECTED]>
Date: Thu, 12 Apr 2007 19:51:22 +0200
Subject: [PATCH] Cleaned up iniParseLine

---
 plugins/ini.c |   46 +++++++++-------------------------------------
 1 files changed, 9 insertions(+), 37 deletions(-)

diff --git a/plugins/ini.c b/plugins/ini.c
index c7659c7..3e197cd 100644
--- a/plugins/ini.c
+++ b/plugins/ini.c
@@ -348,48 +348,20 @@ iniGetFilename (CompDisplay *d,
 static Bool
 iniParseLine (char *line, char **optionName, char **optionValue)
 {
-    int  pos = 0;
-    int  splitPos = 0;
-    int  endPos = 0;
-    char tmpName[MAX_OPTION_LENGTH];
-    char tmpValue[MAX_OPTION_LENGTH];
+    char *split_pos;
+    int lenght;
 
     if (line[0] == '\0' || line[0] == '\n')
 	return FALSE;
 
-    while (pos < strlen(line))
-    {
-	if (!splitPos && line[pos] == '=')
-	    splitPos = pos;
-	if (line[pos] == '\n')
-	{
-	    endPos = pos;
-	    break;
-	}
-	pos++;
-    }
-
-    if (splitPos && endPos)
-    {
-	tmpName[0] = '\0';
-	tmpValue[0] = '\0';
-
-	int i;
-	for (i=0; i < splitPos; i++)
-	    tmpName[i] = line[i];
-	tmpName[splitPos] = '\0';
-
-	for (i=splitPos+1; i<endPos; i++)
-	    tmpValue[i - (splitPos+1)] = line[i];
-	tmpValue[endPos - (splitPos+1)] = '\0';
-
-	*optionName = strdup (tmpName);
-	*optionValue = strdup (tmpValue);
-    }
-    else
-    {
+    split_pos = strchr(line, '=');
+    if (!split_pos)
 	return FALSE;
-    }
+
+    lenght = strlen(line) - strlen(split_pos);
+    *optionName = strndup(line, lenght);
+    split_pos++;
+    *optionValue = strndup(split_pos, strlen(split_pos)-1);
 
     return TRUE;
 }
-- 
1.5.0

From 165d8567a530dd34429deb3389adea5325bcab14 Mon Sep 17 00:00:00 2001
From: marex <[EMAIL PROTECTED]>
Date: Thu, 12 Apr 2007 20:45:14 +0200
Subject: [PATCH] Some minor cleanup in iniLoadOptionsFromFile and iniGetFileDataFromFilename

---
 plugins/ini.c |   85 +++++++++++++++++++++++++--------------------------------
 1 files changed, 37 insertions(+), 48 deletions(-)

diff --git a/plugins/ini.c b/plugins/ini.c
index 3e197cd..d1263df 100644
--- a/plugins/ini.c
+++ b/plugins/ini.c
@@ -143,9 +143,11 @@ static IniFileData *
 iniGetFileDataFromFilename (CompDisplay *d,
 			    const char *filename)
 {
-    int len, i;
-    int pluginSep = 0, screenSep = 0;
-    char *pluginStr, *screenStr;
+    int fnLen, lenght;
+    char *pluginSep;
+    char *screenSep;
+    char *pluginStr;
+    char *screenStr;
     IniFileData *fd;
 
     INI_DISPLAY (d);
@@ -153,35 +155,27 @@ iniGetFileDataFromFilename (CompDisplay *d,
     if (!filename)
 	return NULL;
 
-    len = strlen (filename);
+    fnLen = strlen(filename);
 
-    if (len < (strlen(FILE_SUFFIX) + 2))
+    if (fnLen < (strlen(FILE_SUFFIX) + 2))
 	return NULL;
 
-    if ((filename[0]=='.') || (filename[len-1]=='~'))
+    if ((filename[0] == '.') || (filename[fnLen-1] == '~'))
 	return NULL;
 
     for (fd = id->fileData; fd; fd = fd->next)
 	if (strcmp (fd->filename, filename) == 0)
 	    return fd;
 
-    for (i=0; i<len; i++)
-    {
-	if (filename[i] == '-')
-	{
-	    if (!pluginSep)
-		pluginSep = i-1;
-	    else
-		return NULL; /*found a second dash */
-	}
-	else if (filename[i] == '.')
-	{
-	    if (!screenSep)
-		screenSep = i-1;
-	    else
-		return NULL; /*found a second dot */
-	}
-    }
+    /* the split point for the plugin name */
+    pluginSep = strrchr(filename, '-');
+    if (!pluginSep)
+	return NULL;
+
+    /* the split point for the screen name */
+    screenSep = strrchr(filename, '.');
+    if (!screenSep)
+	return NULL;
 
     if (!pluginSep || !screenSep)
 	return NULL;
@@ -202,17 +196,12 @@ iniGetFileDataFromFilename (CompDisplay *d,
 
     newFd->filename = strdup (filename);
 
-    pluginStr = malloc (sizeof (char) * pluginSep + 1);
-    screenStr = malloc (sizeof (char) * (screenSep - pluginSep) + 1);
-
-    if (!pluginStr || !screenStr)
-	return NULL;
-
-    strncpy (pluginStr, filename, pluginSep + 1);
-    pluginStr[pluginSep + 1] = '\0';
-
-    strncpy (screenStr, &filename[pluginSep+2], (screenSep - pluginSep) + 1);
-    screenStr[(screenSep - pluginSep) -1] = '\0';
+    /* get plugin and screen name */
+    lenght = strlen(filename) - strlen(pluginSep);
+    pluginStr = strndup(filename, lenght);
+    pluginSep++; /* skip the '-' */
+    lenght = strlen(pluginSep) - strlen(screenSep);
+    screenStr = strndup(pluginSep, lenght);
 
     if (strcmp (pluginStr, CORE_NAME) == 0)
 	newFd->plugin = NULL;
@@ -330,7 +319,7 @@ iniGetFilename (CompDisplay *d,
     if (fn)
     {
 	sprintf (fn, "%s-%s%s",
-		 plugin?plugin:CORE_NAME, screenStr, FILE_SUFFIX);
+		 plugin ? plugin : CORE_NAME, screenStr, FILE_SUFFIX);
 
 	*filename = strdup (fn);
 
@@ -606,7 +595,7 @@ iniLoadOptionsFromFile (CompDisplay *d,
     CompScreen *s = NULL;
     CompPlugin *p = NULL;
     Bool status = FALSE;
-    Bool hv = FALSE;
+    Bool has_value = FALSE;
     CompOptionValue value;
 
     if (plugin)
@@ -655,12 +644,13 @@ iniLoadOptionsFromFile (CompDisplay *d,
 
     IniAction action;
     action.realOptionName = NULL;
-    Bool continueReading = FALSE;
-    while (fgets (&tmp[0], MAX_OPTION_LENGTH, optionFile) != NULL)
+    Bool continueReading;
+    while (fgets (tmp, MAX_OPTION_LENGTH, optionFile) != NULL)
     {
 	status = FALSE;
+	continueReading = FALSE;
 
-	if (!iniParseLine (&tmp[0], &optionName, &optionValue))
+	if (!iniParseLine (tmp, &optionName, &optionValue))
 	{
 	    fprintf(stderr,
 		    "Ignoring line '%s' in %s %i\n", tmp, plugin, screen);
@@ -677,29 +667,29 @@ iniLoadOptionsFromFile (CompDisplay *d,
 		switch (o->type)
 		{
 		case CompOptionTypeBool:
-		    hv = TRUE;
+		    has_value = TRUE;
 		    value.b = (Bool) atoi (optionValue);
 			break;
 		case CompOptionTypeInt:
-		    hv = TRUE;
+		    has_value = TRUE;
 		    value.i = atoi (optionValue);
 			break;
 		case CompOptionTypeFloat:
-		    hv = TRUE;
+		    has_value = TRUE;
 		    value.f = atof (optionValue);
 			break;
 		case CompOptionTypeString:
-		    hv = TRUE;
+		    has_value = TRUE;
 		    value.s = strdup (optionValue);
 			break;
 		case CompOptionTypeColor:
-		    hv = stringToColor (optionValue, value.c);
+		    has_value = stringToColor (optionValue, value.c);
 			break;
 		case CompOptionTypeList:
-		    hv = csvToList (optionValue, &value.list, value.list.type);
+		    has_value = csvToList (optionValue, &value.list, value.list.type);
 			break;
 		case CompOptionTypeMatch:
-		    hv = TRUE;
+		    has_value = TRUE;
 		    matchInit (&value.match);
 		    matchAddFromString (&value.match, optionValue);
 			break;
@@ -707,7 +697,7 @@ iniLoadOptionsFromFile (CompDisplay *d,
 			break;
 		}
 
-		if (hv)
+		if (has_value)
 		{
 		    if (plugin && p)
 		    {
@@ -797,7 +787,6 @@ iniLoadOptionsFromFile (CompDisplay *d,
 	    free (optionName);
 	if (optionValue)
 	    free (optionValue);
-	continueReading = FALSE;
     } 
 
     return TRUE;
-- 
1.5.0

From 9564111862735968d1f1deb1bf1f8d1cc7dd688b Mon Sep 17 00:00:00 2001
From: marex <[EMAIL PROTECTED]>
Date: Thu, 12 Apr 2007 22:45:06 +0200
Subject: [PATCH] Fixed list parsing

---
 plugins/ini.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugins/ini.c b/plugins/ini.c
index d1263df..c79f2ec 100644
--- a/plugins/ini.c
+++ b/plugins/ini.c
@@ -371,9 +371,10 @@ csvToList (char *csv, CompListValue *list, CompOptionType type)
 	return FALSE;
     }
  
-    count = 0;
+    int lenght = strlen(csv);
+    count = 1;
     for (i = 0; csv[i] != '\0'; i++)
-	if (csv[i] == ',')
+	if (csv[i] == ',' && i != lenght-1)
 	    count++;
 
     split_start = csv;
-- 
1.5.0

From 63e8157bc7c780ff1da6e15e8e38083526f3ae4d Mon Sep 17 00:00:00 2001
From: marex <[EMAIL PROTECTED]>
Date: Fri, 13 Apr 2007 12:35:33 +0200
Subject: [PATCH] Some further minor fixes to ini.c

---
 plugins/ini.c |   68 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/plugins/ini.c b/plugins/ini.c
index c79f2ec..0aee893 100644
--- a/plugins/ini.c
+++ b/plugins/ini.c
@@ -143,7 +143,7 @@ static IniFileData *
 iniGetFileDataFromFilename (CompDisplay *d,
 			    const char *filename)
 {
-    int fnLen, lenght;
+    int fnLen, length;
     char *pluginSep;
     char *screenSep;
     char *pluginStr;
@@ -197,11 +197,11 @@ iniGetFileDataFromFilename (CompDisplay *d,
     newFd->filename = strdup (filename);
 
     /* get plugin and screen name */
-    lenght = strlen(filename) - strlen(pluginSep);
-    pluginStr = strndup(filename, lenght);
+    length = strlen(filename) - strlen(pluginSep);
+    pluginStr = strndup(filename, length);
     pluginSep++; /* skip the '-' */
-    lenght = strlen(pluginSep) - strlen(screenSep);
-    screenStr = strndup(pluginSep, lenght);
+    length = strlen(pluginSep) - strlen(screenSep);
+    screenStr = strndup(pluginSep, length);
 
     if (strcmp (pluginStr, CORE_NAME) == 0)
 	newFd->plugin = NULL;
@@ -337,20 +337,20 @@ iniGetFilename (CompDisplay *d,
 static Bool
 iniParseLine (char *line, char **optionName, char **optionValue)
 {
-    char *split_pos;
-    int lenght;
+    char *splitPos;
+    int length;
 
     if (line[0] == '\0' || line[0] == '\n')
 	return FALSE;
 
-    split_pos = strchr(line, '=');
-    if (!split_pos)
+    splitPos = strchr(line, '=');
+    if (!splitPos)
 	return FALSE;
 
-    lenght = strlen(line) - strlen(split_pos);
-    *optionName = strndup(line, lenght);
-    split_pos++;
-    *optionValue = strndup(split_pos, strlen(split_pos)-1);
+    length = strlen(line) - strlen(splitPos);
+    *optionName = strndup(line, length);
+    splitPos++;
+    *optionValue = strndup(splitPos, strlen(splitPos)-1);
 
     return TRUE;
 }
@@ -358,8 +358,8 @@ iniParseLine (char *line, char **optionName, char **optionValue)
 static Bool
 csvToList (char *csv, CompListValue *list, CompOptionType type)
 {
-    char *split_start = NULL;
-    char *split_end = NULL;
+    char *splitStart = NULL;
+    char *splitEnd = NULL;
     char *item = NULL;
     int itemLength;
     int count;
@@ -371,28 +371,28 @@ csvToList (char *csv, CompListValue *list, CompOptionType type)
 	return FALSE;
     }
  
-    int lenght = strlen(csv);
+    int length = strlen(csv);
     count = 1;
-    for (i = 0; csv[i] != '\0'; i++)
-	if (csv[i] == ',' && i != lenght-1)
+    for (i = 0; i < length; i++)
+	if (csv[i] == ',' && i != length-1)
 	    count++;
 
-    split_start = csv;
+    splitStart = csv;
     list->value = malloc (sizeof (CompOptionValue) * count);
     if (list->value)
     {
 	for (i = 0; i < count; i++)
 	{
-	    split_end = strchr(split_start, ',');
+	    splitEnd = strchr(splitStart, ',');
 
-	    if (split_end)
+	    if (splitEnd)
 	    {
-		itemLength = strlen(split_start) - strlen(split_end);
-		item = strndup(split_start, itemLength);
+		itemLength = strlen(splitStart) - strlen(splitEnd);
+		item = strndup(splitStart, itemLength);
 	    }
 	    else // last value
 	    {
-		item = strdup(split_start);
+		item = strdup(splitStart);
 	    }
 
 	    switch (type)
@@ -421,7 +421,7 @@ csvToList (char *csv, CompListValue *list, CompOptionType type)
 		    break;
 	    }
 
-	    split_start = ++split_end;
+	    splitStart = ++splitEnd;
 	    if (item)
 		free(item);
 	}
@@ -596,7 +596,7 @@ iniLoadOptionsFromFile (CompDisplay *d,
     CompScreen *s = NULL;
     CompPlugin *p = NULL;
     Bool status = FALSE;
-    Bool has_value = FALSE;
+    Bool hasValue = FALSE;
     CompOptionValue value;
 
     if (plugin)
@@ -668,29 +668,29 @@ iniLoadOptionsFromFile (CompDisplay *d,
 		switch (o->type)
 		{
 		case CompOptionTypeBool:
-		    has_value = TRUE;
+		    hasValue = TRUE;
 		    value.b = (Bool) atoi (optionValue);
 			break;
 		case CompOptionTypeInt:
-		    has_value = TRUE;
+		    hasValue = TRUE;
 		    value.i = atoi (optionValue);
 			break;
 		case CompOptionTypeFloat:
-		    has_value = TRUE;
+		    hasValue = TRUE;
 		    value.f = atof (optionValue);
 			break;
 		case CompOptionTypeString:
-		    has_value = TRUE;
+		    hasValue = TRUE;
 		    value.s = strdup (optionValue);
 			break;
 		case CompOptionTypeColor:
-		    has_value = stringToColor (optionValue, value.c);
+		    hasValue = stringToColor (optionValue, value.c);
 			break;
 		case CompOptionTypeList:
-		    has_value = csvToList (optionValue, &value.list, value.list.type);
+		    hasValue = csvToList (optionValue, &value.list, value.list.type);
 			break;
 		case CompOptionTypeMatch:
-		    has_value = TRUE;
+		    hasValue = TRUE;
 		    matchInit (&value.match);
 		    matchAddFromString (&value.match, optionValue);
 			break;
@@ -698,7 +698,7 @@ iniLoadOptionsFromFile (CompDisplay *d,
 			break;
 		}
 
-		if (has_value)
+		if (hasValue)
 		{
 		    if (plugin && p)
 		    {
-- 
1.5.0

_______________________________________________
compiz mailing list
[EMAIL PROTECTED]
http://lists.freedesktop.org/mailman/listinfo/compiz

Reply via email to