diff mbox

[edid-decode] Read extension blocks in xrandr EDID property

Message ID 1385465149-4331-1-git-send-email-simon.farnsworth@onelan.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Simon Farnsworth Nov. 26, 2013, 11:25 a.m. UTC
Extend the parsing of the xrandr EDID property block to read extension
blocks, not just the basic block.

Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>
---
 edid-decode.c | 45 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)

Comments

Lespiau, Damien Dec. 17, 2013, 11:37 p.m. UTC | #1
On Tue, Nov 26, 2013 at 11:25:49AM +0000, Simon Farnsworth wrote:
> Extend the parsing of the xrandr EDID property block to read extension
> blocks, not just the basic block.
> 
> Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>

Hi,

That patch seems to work as intended, so pushed it with my r-b tag.
Sorry it took so long.
diff mbox

Patch

diff --git a/edid-decode.c b/edid-decode.c
index 4265843..e26ad3e 100644
--- a/edid-decode.c
+++ b/edid-decode.c
@@ -1126,38 +1126,56 @@  extract_edid(int fd)
     start = strstr(ret, "EDID_DATA:");
     if (start == NULL)
     	start = strstr(ret, "EDID:");
-    /* Look for xrandr --verbose output (8 lines of 16 hex bytes) */
+    /* Look for xrandr --verbose output (lines of 16 hex bytes) */
     if (start != NULL) {
 	const char indentation1[] = "                ";
 	const char indentation2[] = "\t\t";
+	/* Used to detect that we've gone past the EDID property */
+	const char half_indentation1[] = "        ";
+	const char half_indentation2[] = "\t";
 	const char *indentation;
 	char *s;
 
-	out = malloc(128);
-	if (out == NULL) {
-	    free(ret);
-	    return NULL;
-	}
-
-	for (i = 0; i < 8; i++) {
+	lines = 0;
+	for (i = 0;; i++) {
 	    int j;
 
-	    /* Get the next start of the line of EDID hex. */
+	    /* Get the next start of the line of EDID hex, assuming spaces for indentation */
 	    s = strstr(start, indentation = indentation1);
-	    if (!s)
+	    /* Did we skip the start of another property? */
+	    if (s && s > strstr(start, half_indentation1))
+		break;
+
+	    /* If we failed, retry assuming tabs for indentation */
+	    if (!s) {
 		s = strstr(start, indentation = indentation2);
-	    if (s == NULL) {
+                /* Did we skip the start of another property? */
+                if (s && s > strstr(start, half_indentation2))
+                    break;
+            }
+
+	    if (!s)
+		break;
+
+	    lines++;
+	    start = s + strlen(indentation);
+
+	    s = realloc(out, lines * 16);
+	    if (!s) {
 		free(ret);
 		free(out);
 		return NULL;
 	    }
-	    start = s + strlen(indentation);
-
+	    out = (unsigned char *)s;
 	    c = start;
 	    for (j = 0; j < 16; j++) {
 		char buf[3];
 		/* Read a %02x from the log */
 		if (!isxdigit(c[0]) || !isxdigit(c[1])) {
+                    if (j != 0) {
+                        lines--;
+                        break;
+                    }
 		    free(ret);
 		    free(out);
 		    return NULL;
@@ -1171,6 +1189,7 @@  extract_edid(int fd)
 	}
 
 	free(ret);
+	edid_lines = lines;
 	return out;
     }