[fusion-commits] compiz mirror: Changes to 'master' (c668335066254a4edf4f826b1344c1ca55186b4f)
compiz at server.beryl-project.org
compiz at server.beryl-project.org
Fri Jul 6 04:05:05 CEST 2007
New commits:
commit c668335066254a4edf4f826b1344c1ca55186b4f
Author: Dennis Kasprzyk <onestone at opencompositing.org>
Date: Fri Jul 6 04:04:17 2007 +0200
Added string formating to fragment functions.
include/compiz.h | 8 +++--
src/fragment.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 87 insertions(+), 9 deletions(-)
Modified: compiz/include/compiz.h
===================================================================
--- compiz/include/compiz.h
+++ compiz/include/compiz.h
@@ -26,7 +26,7 @@
#ifndef _COMPIZ_H
#define _COMPIZ_H
-#define ABIVERSION 20070606
+#define ABIVERSION 20070706
#include <stdio.h>
#include <sys/time.h>
@@ -3008,11 +3008,13 @@ addColorOpToFunctionData (CompFunctionData *data,
Bool
addDataOpToFunctionData (CompFunctionData *data,
- char *str);
+ char *str,
+ ...);
Bool
addBlendOpToFunctionData (CompFunctionData *data,
- char *str);
+ char *str,
+ ...);
int
createFragmentFunction (CompScreen *s,
Modified: compiz/src/fragment.c
===================================================================
--- compiz/src/fragment.c
+++ compiz/src/fragment.c
@@ -34,6 +34,8 @@
#define COMP_FUNCTION_ARB_MASK (1 << 0)
#define COMP_FUNCTION_MASK (COMP_FUNCTION_ARB_MASK)
+#define BUFFER_SIZE 1024
+
struct _CompProgram {
struct _CompProgram *next;
@@ -1031,30 +1033,104 @@ addColorOpToFunctionData (CompFunctionData *data,
Bool
addDataOpToFunctionData (CompFunctionData *data,
- char *str)
+ char *str,
+ ...)
{
- int ===================================================================
+ int ===================================================================
+ int size = BUFFER_SIZE;
+ int n;
+ char *fStr;
+ char *tmp;
+ va_list ap;
if (!allocBodyOpInFunctionData (data))
return FALSE;
+ if ((fStr = malloc (size)) == NULL)
+ return FALSE;
+
+ while (1)
+ {
+ /* Try to print in the allocated space. */
+ va_start(ap, str);
+ n = vsnprintf (fStr, size, str, ap);
+ va_end(ap);
+
+ /* If that worked, leave the loop. */
+ if (n > -1 && n < size)
+ break;
+
+ /* Else try again with more space. */
+ if (n > -1) /* glibc 2.1 */
+ size = n+1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ size *= 2; /* twice the old size */
+
+ if ((tmp = realloc (fStr, size)) == NULL)
+ {
+ free(fStr);
+ return FALSE;
+ } else {
+ fStr = tmp;
+ }
+ }
+
data->body[index].type = CompOpTypeData;
- data->body[index].data.data = strdup (str);
+ data->body[index].data.data = strdup (fStr);
+
+ free (fStr);
return TRUE;
}
Bool
addBlendOpToFunctionData (CompFunctionData *data,
- char *str)
+ char *str,
+ ...)
{
- int ===================================================================
+ int ===================================================================
+ int size = BUFFER_SIZE;
+ int n;
+ char *fStr;
+ char *tmp;
+ va_list ap;
if (!allocBodyOpInFunctionData (data))
return FALSE;
+ if ((fStr = malloc (size)) == NULL)
+ return FALSE;
+
+ while (1)
+ {
+ /* Try to print in the allocated space. */
+ va_start(ap, str);
+ n = vsnprintf (fStr, size, str, ap);
+ va_end(ap);
+
+ /* If that worked, leave the loop. */
+ if (n > -1 && n < size)
+ break;
+
+ /* Else try again with more space. */
+ if (n > -1) /* glibc 2.1 */
+ size = n+1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ size *= 2; /* twice the old size */
+
+ if ((tmp = realloc (fStr, size)) == NULL)
+ {
+ free(fStr);
+ return FALSE;
+ } else {
+ fStr = tmp;
+ }
+ }
+
data->body[index].type = CompOpTypeDataBlend;
- data->body[index].data.data = strdup (str);
+ data->body[index].data.data = strdup (fStr);
+
+ free (fStr);
return TRUE;
}
More information about the commits
mailing list