qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs extras.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs extras.c
Date: Wed, 14 May 2014 16:15:02 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/05/14 16:15:01

Modified files:
        .              : extras.c 

Log message:
        improve describe-buffer
        
        * fix line number for files with an imcomplete last line
        * display word count
        * align byte stats for large files

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/extras.c?cvsroot=qemacs&r1=1.27&r2=1.28

Patches:
Index: extras.c
===================================================================
RCS file: /sources/qemacs/qemacs/extras.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- extras.c    29 Apr 2014 22:25:49 -0000      1.27
+++ extras.c    14 May 2014 16:15:00 -0000      1.28
@@ -897,7 +897,7 @@
     if (!b1)
         return;
 
-    total_size = s->b->total_size;
+    total_size = b->total_size;
 
     eb_printf(b1, "Buffer Statistics\n\n");
 
@@ -911,11 +911,12 @@
         eb_get_pos(b, &line, &col, total_size);
         nb_chars = eb_get_char_offset(b, total_size);
 
-        eb_printf(b1, "       lines: %d\n", line);
+        eb_printf(b1, "       lines: %d\n", line + (col > 0));
         eb_printf(b1, "       chars: %d\n", nb_chars);
     }
     eb_printf(b1, "        mark: %d\n", b->mark);
     eb_printf(b1, "      offset: %d\n", b->offset);
+    eb_printf(b1, "   s->offset: %d\n", s->offset);
 
     eb_printf(b1, "   tab_width: %d\n", b->tab_width);
     eb_printf(b1, " fill_column: %d\n", b->fill_column);
@@ -974,15 +975,36 @@
     if (total_size > 0) {
         u8 buf[4096];
         int count[256];
-        int offset, c, i, col;
+        int offset, c, i, col, max_count, count_width;
+        int word_char, word_count;
         
         memset(count, 0, sizeof(count));
+        word_count = 0;
+        word_char = 0;
         for (offset = 0; offset < total_size;) {
             int size = eb_read(b, offset, buf, countof(buf));
-            for (i = 0; i < size; i++)
-                count[buf[i]] += 1;
+            if (size == 0)
+                break;
+            for (i = 0; i < size; i++) {
+                c = buf[i];
+                count[c] += 1;
+                if (c <= 32) {
+                    word_count += word_char;
+                    word_char = 0;
+                } else {
+                    word_char = 1;
+                }
+            }
             offset += size;
         }
+        max_count = 0;
+        for (i = 0; i < 256; i++) {
+            max_count = max(max_count, count[i]);
+        }
+        count_width = snprintf(NULL, 0, "%d", max_count);
+
+        eb_printf(b1, "       words: %d\n", word_count);
+
         eb_printf(b1, "\nByte stats:\n");
 
         for (col = i = 0; i < 256; i++) {
@@ -998,7 +1020,7 @@
             case '\'':  c = '\''; break;
             default: c = 0; break;
             }
-            col += eb_printf(b1, " %5d", count[i]);
+            col += eb_printf(b1, "   %*d", count_width, count[i]);
 
             if (c != 0)
                 col += eb_printf(b1, "  '\\%c'", c);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]