Subject: bin/30374: "ls -q" should display space as '?'
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <apb@cequrux.com>
List: netbsd-bugs
Date: 05/30/2005 10:17:00
>Number:         30374
>Category:       bin
>Synopsis:       "ls -q" should display space as '?'
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 30 10:17:00 +0000 2005
>Originator:     Alan Barrett
>Release:        NetBSD 3.99.3
>Organization:
Not much
>Environment:
Architecture: i386
Machine: i386
>Description:
The ls(1) man page says that the "-q" flag causes non-graphic characters
to be displayed as '?'.

Whitespace characters (space, tab, newline and the like) are not
"graphic characters", according to the usual understanding of the term
and according to isgraph(3).

However, ls(1) with the "-q" flag displays spaces in file names as raw
spaces, not as '?'.

The superficial problem is confusion between graphic characters
(which do not include space) and printable characters (which include
space), and the fact that "ls -q" is documented to do special things
to non-graphic characters (but actually does special things to
non-printable characters), while "ls -b" and "ls -B" are documented
to do special things to non-printable characters (and actually do
what they are documented to do).  It might be better if "ls -q" did
special things to non-printable charafcters (keep current behaviour,
but change the documentation), and if "ls -b" and "ls -B" did special
things to non-graphic characters (change both the behaviour and the
documentation).

The real problem is that I want an easy way of telling ls(1) to make
spaces in file names visible, to help diagnose confusing situations
caused by trailing spaces in file names.  The man page told me that "ls
-q" would be that easy way, but reality was different.  As long as I get
an easy way to do what I want, I don't much care what option letter is
used.

>How-To-Repeat:

touch 'foo bar'
ls -q foo*

Expect to see "foo?bar", because space is a non-graphic character
and the ls(1) man page promised that non-graphic characters would be
displayed as '?', but actually see "foo bar".

>Fix:
Option 1: Fix the behaviour of "ls -q" to match the man page.
    This could be done by changing "if (isprint(c))" to
    "if (isgraph(c))" in the printescaped() function in
    src/bin/ls/util.c.

    Once "ls -q" is fixed to display space as "?", then many people
    will no longer want "ls -q" to be the default when output is to
    a terminal.  (File names with embedded spaces are common enough
    that people will probably want them to be displayed with raw spaces
    by default.)  So also add a new flag that works like "-q" except
    displays raw spaces, and make that new flag the default when
    output is to a terminal.

Option 2: Modify the man page to match the behaviour or "ls -q", and add
    a new flag that really does what "ls -q" is currently documented to do.

Option 3: Modify the man page to match the behaviour of "ls -q", and
    modify both the behaviour and documentation for "ls -b" and "ls -B" to
    make spaces readily apparent.  This could be done by adding VIS_WHITE
    to the flags passed to strvis(3) in the safe_print() function in
    src/bin/ls/util.c.

Option 3 is my preferred solution.