[syslinux:pathbased] dir.c32: show long directories in pages

syslinux-bot for H. Peter Anvin hpa at zytor.com
Sun Mar 14 22:03:10 PDT 2010


Commit-ID:  4121b9c7962e230f8819645ecb9d5f4eac684ed2
Gitweb:     http://syslinux.zytor.com/commit/4121b9c7962e230f8819645ecb9d5f4eac684ed2
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sun, 14 Mar 2010 22:01:19 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Sun, 14 Mar 2010 22:02:50 -0700

dir.c32: show long directories in pages

When columnizing large directories, columnize only inside of a page,
i.e. show:

a d g
b e h
c f i

j m p
k n q
l o r

This seems to have the best readability.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 com32/modules/dir.c |   46 ++++++++++++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/com32/modules/dir.c b/com32/modules/dir.c
index 10fa5c2..c9d9370 100644
--- a/com32/modules/dir.c
+++ b/com32/modules/dir.c
@@ -71,10 +71,11 @@ static int display_directory(const char *dirname)
     struct dirent *de;
     struct dirent **dex = NULL;
     size_t n_dex = 0, n_de = 0;
-    size_t i, j;
-    unsigned int nrows, ncols;
+    size_t i, j, k;
+    size_t nrows, ncols, perpage;
+    size_t endpage;
     int maxlen = 0;
-    int pos, tpos, colwidth, pagerow;
+    int pos, tpos, colwidth;
 
     dir = opendir(dirname);
     if (!dir) {
@@ -115,24 +116,29 @@ static int display_directory(const char *dirname)
     ncols = min(ncols, n_de);
     ncols = max(ncols, 1U);
     colwidth = (cols + 2)/ncols;
-    nrows = (n_de + ncols - 1) / ncols;
-
-    pagerow = 1;		/* Need one row for the cursor */
-    for (i = 0; i < nrows; i++) {
-	pos = tpos = 0;
-	for (j = i; j < n_de; j += nrows) {
-	    pos += printf("%*s%-5s %s",
-			  (tpos - pos), "",
-			  type_str(dex[j]->d_type),
-			  dex[j]->d_name);
-	    tpos += colwidth;
-	}
-	printf("\n");
-	pagerow++;
-	if (pagerow >= rows) {
-	    get_key(stdin, 0);
-	    pagerow = 1;
+    perpage = ncols * (rows - 1);
+
+    for (i = 0; i < n_de; i += perpage) {
+	/* Rows on this page */
+	endpage = min(i+perpage, n_de);
+	nrows = ((endpage-i) + ncols - 1)/ncols;
+
+	for (j = 0; j < nrows; j++) {
+	    pos = tpos = 0;
+	    for (k = i+j; k < endpage; k += nrows) {
+		pos += printf("%*s%-5s %s",
+			      (tpos - pos), "",
+			      type_str(dex[k]->d_type),
+			      dex[k]->d_name);
+		tpos += colwidth;
+	    }
+	    printf("\n");
 	}
+
+	if (endpage >= n_de)
+	    break;
+
+	get_key(stdin, 0);
     }
 
     free_dirents(dex, n_de);



More information about the Syslinux-commits mailing list