Update info.c to use size_trun_len() & Co.
David Martin
dmartina at excite.com
Sun Aug 26 18:36:38 UTC 2001
I've been messing with the info panel and I've got some patches:
- Use the new size_trunc_len() in util.c instead of print_bytesize()
in win.c. I think the change of adding an extra parameter is harmless
for the file list panels. In the way group some strings to ease
translation.
- Changes to sizes when using tiny widths. We're now printing senseless
things. The alternative is to print nothing when len < 3+1.
- Move a comment in info.c so that it appears in translator's files.
It would be nice to do some cleaning in this kind of messages to avoid
useless stuff confusing translators.
As they're quite small I'm usign the same message for all three.
*8-) David
------------------------
diff -1 -upr mc-4.5.55.orig/src/ChangeLog mc-4.5.55/src/ChangeLog
--- mc-4.5.55.orig/src/ChangeLog Fri Aug 24 06:51:11 2001
+++ mc-4.5.55/src/ChangeLog Sun Aug 26 00:40:27 2001
@@ -1 +1,18 @@
+2001-08-26 David Martin <dmartina at excite.es>
+
+ * info.c (info_show_info): Use size_trunc_len() instead of
+ print_bytesize(). Group strings ("don't assume English
+ word ordering"). Add singular message when single block.
+
+ * win.c (print_bytesize): Remove.
+ (sprint_bytesize): Remove.
+ * win.h: Remove print_bytesize() and sprint_bytesize().
+
+ * util.c (size_trunc_len): Update to support 1K blocks in
+ filesystem sizes. Add units parameter.
+ * util.h: Add units parameter in size_trunc_len.
+
+ * screen.c (string_file_size): Add units (0=byte) to
+ size_trunc_len() call.
+
2001-08-24 Pavel Roskin <proski at gnu.org>
diff -1 -upr mc-4.5.55.orig/src/info.c mc-4.5.55/src/info.c
--- mc-4.5.55.orig/src/info.c Tue Jun 19 00:24:04 2001
+++ mc-4.5.55/src/info.c Sun Aug 26 00:04:32 2001
@@ -32,3 +32,3 @@
#include "main.h" /* opanel, cpanel definitions */
-#include "win.h" /* print_bytesize */
+#include "util.h" /* size_trunc_len */
#include "layout.h"
@@ -123,7 +123,7 @@ info_show_info (WInfo *info)
if (myfs_stats.avail > 0 || myfs_stats.total > 0){
- addstr (_("Free space "));
- print_bytesize (myfs_stats.avail, 1);
- printw (_(" (%d%%) of "), myfs_stats.total
- ? 100 * myfs_stats.avail / myfs_stats.total : 0);
- print_bytesize (myfs_stats.total, 1);
+ char buffer1 [6], buffer2[6];
+ size_trunc_len (buffer1, 5, myfs_stats.avail,1);
+ size_trunc_len (buffer2, 5, myfs_stats.total,1);
+ printw (_("Free space %sb (%d%%) of %sb"), buffer1, myfs_stats.total ?
+ 100 * myfs_stats.avail / myfs_stats.total : 0, buffer2);
} else
@@ -169,6 +169,8 @@ info_show_info (WInfo *info)
{
- printw (_("Size: "));
- print_bytesize (buf.st_size, 0);
+ char buffer[10];
+ size_trunc_len(buffer, 9, buf.st_size, 0);
+ printw (_("Size: %sb"), buffer);
#ifdef HAVE_ST_BLOCKS
- printw (_(" (%d blocks)"), buf.st_blocks);
+ printw ((buf.st_blocks==1) ?
+ _(" (%d block)") : _(" (%d blocks)"), buf.st_blocks);
#endif
diff -1 -upr mc-4.5.55.orig/src/screen.c mc-4.5.55/src/screen.c
--- mc-4.5.55.orig/src/screen.c Sun Aug 19 19:33:26 2001
+++ mc-4.5.55/src/screen.c Sun Aug 26 00:04:32 2001
@@ -208,3 +208,3 @@ string_file_size (file_entry *fe, int le
{
- size_trunc_len (buffer, len, fe->buf.st_size);
+ size_trunc_len (buffer, len, fe->buf.st_size,0);
}
diff -1 -upr mc-4.5.55.orig/src/util.c mc-4.5.55/src/util.c
--- mc-4.5.55.orig/src/util.c Thu Aug 16 05:52:51 2001
+++ mc-4.5.55/src/util.c Sun Aug 26 00:17:22 2001
@@ -313,5 +313,8 @@ char *size_trunc_sep (double size)
* floating point by any means.
+ *
+ * Units: size units (filesystem sizes are 1K blocks)
+ * 0=bytes, 1=Kbytes, 2=Mbytes, etc.
*/
void
-size_trunc_len (char *buffer, int len, off_t size)
+size_trunc_len (char *buffer, int len, off_t size, unsigned units)
{
@@ -329,3 +332,3 @@ size_trunc_len (char *buffer, int len, o
- for (j = 0; suffix [j] != NULL; j++) {
+ for (j = units; suffix [j] != NULL; j++) {
if (size < power10 [len - (j > 0)]) {
diff -1 -upr mc-4.5.55.orig/src/util.h mc-4.5.55/src/util.h
--- mc-4.5.55.orig/src/util.h Thu Jun 28 06:17:28 2001
+++ mc-4.5.55/src/util.h Sun Aug 26 00:04:32 2001
@@ -20,3 +20,3 @@ char *size_trunc (double size);
char *size_trunc_sep (double size);
-void size_trunc_len (char *buffer, int len, off_t size);
+void size_trunc_len (char *buffer, int len, off_t size, unsigned units);
int is_exe (mode_t mode);
diff -1 -upr mc-4.5.55.orig/src/win.c mc-4.5.55/src/win.c
--- mc-4.5.55.orig/src/win.c Wed Jun 6 23:41:44 2001
+++ mc-4.5.55/src/win.c Sun Aug 26 00:04:32 2001
@@ -46,27 +46,2 @@ static Fkey_Table_List *fkey_table_list
-/* Width of output is always seven characters */
-void sprint_bytesize (char *buffer, int size, int scale)
-{
- char scales[] = " kMGT";
-
- if (size > 0){
- while (size > 9999 && scale < sizeof (scales)){
- size = (size + 512) / 1024;
- scale ++;
- }
- }
- if (scale > 0)
- g_snprintf (buffer, 10, "%4d %cb", size, scales[scale]);
- else
- g_snprintf (buffer, 10, "%4d b ", size);
-}
-
-void print_bytesize (int size, int scale)
-{
- char buffer [10];
-
- sprint_bytesize (buffer, size, scale);
- printw (buffer);
-}
-
/* Return values: 0 = not a fkey, other = was a fkey */
diff -1 -upr mc-4.5.55.orig/src/win.h mc-4.5.55/src/win.h
--- mc-4.5.55.orig/src/win.h Fri Feb 27 05:54:43 1998
+++ mc-4.5.55/src/win.h Sun Aug 26 00:04:32 2001
@@ -6,5 +6,2 @@
-void print_bytesize (int size, int scale);
-void sprint_bytesize (char *buffer, int size, int scale);
-
-------------------------------------------------------
diff -1 -upr mc-4.5.99a/src/ChangeLog mc-4.5.99a.patched/src/ChangeLog
--- mc-4.5.99a/src/ChangeLog Fri Aug 24 20:49:00 2001
+++ mc-4.5.99a.patched/src/ChangeLog Sun Aug 26 18:22:40 2001
@@ -1 +1,6 @@
+2001-08-26 David Martin <dmartina at excite.es>
+
+ * util.c (size_trunc_len): Print size values with some (little)
+ sense for tiny and even wee lengths (i.e. squeezed X terminals).
+
2001-08-24 Pavel Roskin <proski at gnu.org>
diff -1 -upr mc-4.5.99a/src/util.c mc-4.5.99a.patched/src/util.c
--- mc-4.5.99a/src/util.c Thu Aug 16 05:52:51 2001
+++ mc-4.5.99a.patched/src/util.c Sun Aug 26 17:58:37 2001
@@ -331,3 +331,8 @@ size_trunc_len (char *buffer, int len, o
if (size < power10 [len - (j > 0)]) {
- g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size,
suffix[j]);
+ if (len > 1 || !size)
+ /* Empty files will print "0" even with minimal width */
+ g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, suffix[j]);
+ else
+ /* Sort of "~1", "~K", etc. (see below) with one single character */
+ g_snprintf (buffer, len + 1, "%s", (j) ? suffix[j] : "1");
break;
@@ -335,4 +340,17 @@ size_trunc_len (char *buffer, int len, o
- /* Powers of 1024, no rounding. */
- size = size >> 10;
+ /*
+ * Powers of 1024, with rounding.
+ * 1000 should do 1K, not 0K.
+ */
+ size = ( size + 512 ) >> 10;
+ if ( size == 0 ) {
+ /*
+ * These would lead to non-zero values represented like "0X" (for
example: "0M").
+ * Let's break now with "~K" or just "K" if there's no room.
+ * "~1" or just "1" if dealign with units
(bytes).
+ */
+ g_snprintf (buffer, len + 1, (len == 1) ? "%s" : "~%s",
+ (j) ? suffix[j] : "1");
+ break;
+ }
}
------------------------------------------
diff -1 -upr mc-4.5.99a/src/ChangeLog mc-4.5.99a-patched/src/ChangeLog
--- mc-4.5.99a/src/ChangeLog Sun Aug 26 18:43:06 2001
+++ mc-4.5.99a-patched/src/ChangeLog Fri Aug 24 20:49:00 2001
@@ -1,8 +1 @@
-2001-08-26 David Martin <dmartina at excite.es>
-
- * info.c (info_show_info): Move comment line just before translatable
- message so it's shown in .po files to alert translators; the message
- (translated) is used to know the start column (so the available width)
- for some "truncatable" strings.
-
2001-08-24 Pavel Roskin <proski at gnu.org>
diff -1 -upr mc-4.5.99a/src/info.c mc-4.5.99a-patched/src/info.c
--- mc-4.5.99a/src/info.c Tue Jun 19 00:24:04 2001
+++ mc-4.5.99a-patched/src/info.c Sun Aug 26 18:33:32 2001
@@ -99,2 +99,3 @@ info_show_info (WInfo *info)
if(!i18n_adjust) {
+ /*This printf pattern string will be used as a reference for size*/
file_label=_("File: %s");
@@ -102,3 +103,2 @@ info_show_info (WInfo *info)
}
- /*The printf pattern string is used as a reference for size*/
_______________________________________________________
Send a cool gift with your E-Card
http://www.bluemountain.com/giftcenter/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: info.diff.gz
Type: application/x-gzip-compressed
Size: 1691 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20010826/e0175919/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wee.diff.gz
Type: application/x-gzip-compressed
Size: 846 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20010826/e0175919/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: info_i18n.diff.gz
Type: application/x-gzip-compressed
Size: 548 bytes
Desc: not available
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20010826/e0175919/attachment-0002.bin>
More information about the mc-devel
mailing list