Thread (60 messages) flat view 60 messages, 3 authors, 2007-08-24

Re: [PATCH 17/20] bootwrapper: Add PlanetCore firmware support.

From: Scott Wood <hidden>
Date: 2007-08-21 16:29:15

David Gibson wrote:
quoted
+void planetcore_prepare_table(char *table)
+{
+	int last_was_newline = 0;
+
+	while (*table != 10 || !last_was_newline) {
+		if (*table == 10) {
+			*table = 0;
+			last_was_newline = 1;
+		} else {
+			last_was_newline = 0;
+		}
+
+		table++;
+	}

Hrm.. this loop makes my brain hurt.  It's correct as far as I can
determine what it's supposed to be doing, but I think there's got to
be a way to make what it's doing a little more obvious.
How about something like this:

char last = 0;

while (1) {
	if (*table == '\n') {
		*table = 0;

		if (last == *table)
			return;
	}

	last = *table++;
}

-Scott
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help