[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils "ls -m" outputs unnecessary spaces
From: |
Paul Eggert |
Subject: |
coreutils "ls -m" outputs unnecessary spaces |
Date: |
23 Dec 2003 14:22:27 -0800 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
While reviewing my earlier patch about "ls" and output columns,
I noticed that coreutils 5.1.0 "ls -m" outputs unnecessary spaces
between comma and newline, and also before the inode number and the
size (if specified). Here's a patch.
2003-12-23 Paul Eggert <address@hidden>
* src/ls.c (length_of_file_names_and_frills):
Remove forward decl; not needed.
(print_file_name_and_frills, length_of_file_name_and_frills):
With -m, don't output spaces before inum or size.
(print_with_commas): Don't output space just before newline.
--- ../../coreutils-5.1.0-orig/src/ls.c Wed Dec 10 23:47:18 2003
+++ ls.c Tue Dec 23 14:09:59 2003
@@ -236,7 +236,6 @@ static uintmax_t gobble_file (const char
static void print_color_indicator (const char *name, mode_t mode, int linkok);
static void put_indicator (const struct bin_str *ind);
static int put_indicator_direct (const struct bin_str *ind);
-static size_t length_of_file_name_and_frills (const struct fileinfo *f);
static void add_ignore_pattern (const char *pattern);
static void attach (char *dest, const char *dirname, const char *name);
static void clear_files (void);
@@ -3453,10 +3452,11 @@ print_file_name_and_frills (const struct
char buf[MAX (LONGEST_HUMAN_READABLE + 1, INT_BUFSIZE_BOUND (uintmax_t))];
if (print_inode)
- printf ("%*s ", inode_number_width, umaxtostr (f->stat.st_ino, buf));
+ printf ("%*s ", format == with_commas ? 0 : inode_number_width,
+ umaxtostr (f->stat.st_ino, buf));
if (print_block_size)
- printf ("%*s ", block_size_width,
+ printf ("%*s ", format == with_commas ? 0 : block_size_width,
human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
ST_NBLOCKSIZE, output_block_size));
@@ -3588,12 +3588,19 @@ length_of_file_name_and_frills (const st
{
register size_t len = 0;
size_t name_width;
+ char buf[MAX (LONGEST_HUMAN_READABLE + 1, INT_BUFSIZE_BOUND (uintmax_t))];
if (print_inode)
- len += inode_number_width + 1;
+ len += 1 + (format == with_commas
+ ? strlen (umaxtostr (f->stat.st_ino, buf))
+ : inode_number_width);
if (print_block_size)
- len += block_size_width + 1;
+ len += 1 + (format == with_commas
+ ? strlen (human_readable (ST_NBLOCKS (f->stat), buf,
+ human_output_opts, ST_NBLOCKSIZE,
+ output_block_size))
+ : block_size_width);
quote_name (NULL, f->name, filename_quoting_options, &name_width);
len += name_width;
@@ -3696,31 +3703,33 @@ static void
print_with_commas (void)
{
size_t filesno;
- size_t pos;
- size_t old_pos;
-
- pos = 0;
+ size_t pos = 0;
for (filesno = 0; filesno < files_index; filesno++)
{
- old_pos = pos;
-
- pos += length_of_file_name_and_frills (files + filesno);
- if (filesno + 1 < files_index)
- pos += 2; /* For the comma and space */
+ size_t len = length_of_file_name_and_frills (files + filesno);
- if (old_pos != 0 && pos >= line_length)
+ if (filesno != 0)
{
- putchar ('\n');
- pos -= old_pos;
- }
+ char separator;
+
+ if (pos + len + 2 < line_length)
+ {
+ pos += 2;
+ separator = ' ';
+ }
+ else
+ {
+ pos = 0;
+ separator = '\n';
+ }
- print_file_name_and_frills (files + filesno);
- if (filesno + 1 < files_index)
- {
putchar (',');
- putchar (' ');
+ putchar (separator);
}
+
+ print_file_name_and_frills (files + filesno);
+ pos += len;
}
putchar ('\n');
}
- coreutils "ls -m" outputs unnecessary spaces,
Paul Eggert <=