From fc642f1752caa156d41f5245e5f05b583bb8b886 Mon Sep 17 00:00:00 2001
From: Guillaume Seguin <guillaume@segu.in>
Date: Thu, 16 Aug 2007 02:14:17 +0200
Subject: [PATCH] * Add fragment program pretty printer

---
 src/fragment.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/fragment.c b/src/fragment.c
index a1c9e6e..04ae571 100644
--- a/src/fragment.c
+++ b/src/fragment.c
@@ -154,6 +154,53 @@ static CompFunction initialLoadFunction = {
     COMP_FUNCTION_MASK
 };
 
+/*
+ * Print nicely formatted fragment program
+ */
+static void
+printPrettyFragment (char *source)
+{
+    char *result, *current;
+    int feeds = 1, length;
+
+    current = source;
+    while (*current != '\0')
+    {
+	if (strstr (current, ";") == current) break;
+	feeds++;
+	current = strstr (current, ";");
+	if (!current) break;
+	else current++;
+    }
+
+    result = malloc (sizeof (char) * (strlen (source) + feeds + 1));
+    if (!result)
+	result = source;
+    else
+    {
+	current = source;
+	strcpy (result, "!!ARBfp1.0\n");
+	current += 10;
+	while (*current != '\0')
+	{
+	    if (strstr (current, ";"))
+		length = strstr (current, ";") + 1 - current;
+	    else
+		length = strlen (current);
+	    strncat (result, current, length);
+	    strcat (result, "\n");
+	    current = strstr (current, ";");
+	    if (!current) break;
+	    else current++;
+	}
+	result[strlen (source) + feeds] = '\0';
+    }
+    compLogMessage (NULL, "core", CompLogLevelInfo,
+		    "Using fragment program :");
+    printf ("%s", result);
+    free (result);
+}
+
 static CompFunction *
 findFragmentFunction (CompScreen *s,
 		      int	 id)
@@ -630,6 +677,8 @@ buildFragmentProgram (CompScreen     *s,
 
     glGetError ();
 
+    printPrettyFragment (info.data);
+
     (*s->genPrograms) (1, &program->name);
     (*s->bindProgram) (GL_FRAGMENT_PROGRAM_ARB, program->name);
     (*s->programString) (GL_FRAGMENT_PROGRAM_ARB,
-- 
1.5.2.4

