From 23f176cae633cc795a8d7a0becb56ba1481f32ba Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 17 Aug 2006 15:46:56 +0000 Subject: [PATCH] ls -CF would misalign columns in some cases. * src/ls.c (get_type_indicator): New function. extracted from... (print_type_indicator): ...here. Use it. (length_of_file_name_and_frills): Use it here, too, rather than assuming stat.st_mode is valid. Reported by Andreas Schwab, here: FIXME: add a test for this: FYI, I did ls -CF /proc and visually inspected the result. --- ChangeLog | 10 ++++++++++ src/ls.c | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0230753..416f7a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2006-08-17 Jim Meyering + ls -CF would misalign columns in some cases. + * src/ls.c (get_type_indicator): New function. extracted from... + (print_type_indicator): ...here. Use it. + (length_of_file_name_and_frills): Use it here, too, rather than + assuming stat.st_mode is valid. + Reported by Andreas Schwab, here: + + FIXME: add a test for this: FYI, I did ls -CF /proc and visually + inspected the result. + * src/copy.c (copy_internal, same_file_ok): Adjust comments not to mention the now-removed cp_options.xstat member. diff --git a/src/ls.c b/src/ls.c index 40de927..29cc253 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3797,8 +3797,10 @@ print_file_name_and_frills (const struct fileinfo *f) print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype); } -static void -print_type_indicator (bool stat_ok, mode_t mode, enum filetype type) +/* Given these arguments describing a file, return the single-byte + type indicator, or 0. */ +static char +get_type_indicator (bool stat_ok, mode_t mode, enum filetype type) { char c; @@ -3826,7 +3828,13 @@ print_type_indicator (bool stat_ok, mode_t mode, enum filetype type) else c = 0; } + return c; +} +static void +print_type_indicator (bool stat_ok, mode_t mode, enum filetype type) +{ + char c = get_type_indicator (stat_ok, mode, type); if (c) DIRED_PUTCHAR (c); } @@ -3950,16 +3958,8 @@ length_of_file_name_and_frills (const struct fileinfo *f) if (indicator_style != none) { - mode_t mode = f->stat.st_mode; - - len += (S_ISREG (mode) - ? (indicator_style == classify && (mode & S_IXUGO)) - : (S_ISDIR (mode) - || (indicator_style != slash - && (S_ISLNK (mode) - || S_ISFIFO (mode) - || S_ISSOCK (mode) - || S_ISDOOR (mode))))); + char c = get_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype); + len += (c != 0); } return len; -- 2.7.4