<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">[PATCH] Re-factor console list formatting

diff -urN b/common/console.c head/common/console.c
--- b/common/console.c	2004-08-11 22:36:27.000000000 +0930
+++ head/common/console.c	2005-12-11 22:28:36.000000000 +1030
@@ -696,3 +696,50 @@
     Con_Printf("%s", msg);
     scr_disabled_for_loading = temp;
 }
+
+void
+Con_ShowList(const char **list, int cnt)
+{
+    const char *s;
+    unsigned i, j, max_len, len, cols, rows;
+    char *line;
+
+    /* Lay them out in columns */
+    max_len = 0;
+    for (i = 0; i &lt; cnt; ++i) {
+	len = strlen(list[i]);
+	if (len &gt; max_len)
+	    max_len = len;
+    }
+
+    line = Z_Malloc(Con_GetWidth() + 1);
+    cols = Con_GetWidth() / (max_len + 2);
+    rows = cnt / cols + 1;
+
+    /* Looks better if we have a few rows before spreading out */
+    if (rows &lt; 5) {
+	cols = cnt / 5 + 1;
+	rows = cnt / cols + 1;
+    }
+
+    for (i = 0; i &lt; rows; ++i) {
+	line[0] = '\0';
+	for (j = 0; j &lt; cols; ++j) {
+	    if (j * rows + i &gt;= cnt)
+		break;
+	    s = list[j * rows + i];
+	    len = strlen(s);
+
+	    strcat(line, s);
+	    if (j &lt; cols - 1) {
+		while (len &lt; max_len) {
+		    strcat(line, " ");
+		    len++;
+		}
+		strcat(line, "  ");
+	    }
+	}
+	Con_Printf("%s\n", line);
+    }
+    Z_Free(line);
+}
diff -urN b/common/keys.c head/common/keys.c
--- b/common/keys.c	2004-07-25 15:59:59.000000000 +0930
+++ head/common/keys.c	2005-12-11 22:40:04.000000000 +1030
@@ -208,11 +208,11 @@
     }
 }
 
-void ShowCompletions(void)
+static void
+ShowCompletions(void)
 {
     const char *s;
-    unsigned cnt, i, j, max_len, len, cols, rows;
-    char *line;
+    unsigned cnt;
 
     s = key_lines[edit_line] + 1;
     if (*s == '\\' || *s == '/')
@@ -221,45 +221,7 @@
     cnt = find_completions(s);
     if (cnt) {
 	Con_Printf("%u possible completions:\n", cnt);
-
-	/* Lay them out in columns */
-	max_len = 0;
-	for (i = 0; i &lt; cnt; ++i) {
-	    len = strlen(completions_list[i]);
-	    if (len &gt; max_len)
-		max_len = len;
-	}
-
-	line = Z_Malloc(Con_GetWidth() + 1);
-	cols = Con_GetWidth() / (max_len + 2);
-	rows = cnt / cols + 1;
-
-	/* Looks better if we have a few rows before spreading out */
-	if (rows &lt; 5) {
-	    cols = cnt / 5 + 1;
-	    rows = cnt / cols + 1;
-	}
-
-	for (i = 0; i &lt; rows; ++i) {
-	    line[0] = '\0';
-	    for (j = 0; j &lt; cols; ++j) {
-		if (j * rows + i &gt;= cnt)
-		    break;
-		s = completions_list[j * rows + i];
-		len = strlen(s);
-
-		strcat(line, s);
-		if (j &lt; cols - 1) {
-		    while (len &lt; max_len) {
-			strcat(line, " ");
-			len++;
-		    }
-		    strcat(line, "  ");
-		}
-	    }
-	    Con_Printf("%s\n", line);
-	}
-	Z_Free(line);
+	Con_ShowList(completions_list, cnt);
     }
 }
 
</pre></body></html>