diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-04-11 18:55:23 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-04-11 18:55:23 -0400 |
commit | 8beeead5fdc891138f5a6c476bd56a277b31e71f (patch) | |
tree | eac1618091baae6dd98c134dc39e34610a128827 /ls.c | |
parent | 707184fe4e9e5ffa99def9c868027c61f41249fc (diff) |
implement -q
Diffstat (limited to 'ls.c')
-rw-r--r-- | ls.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -23,6 +23,7 @@ */ #define _XOPEN_SOURCE 700 +#include <ctype.h> #include <errno.h> #include <fcntl.h> /* included because GNU only defines AT_FDCWD here */ #include <grp.h> @@ -65,6 +66,7 @@ static enum { OWNER_NAME, OWNER_ID, OWNER_NONE } ls_owner = OWNER_NAME; static enum { MARK_NONE, MARK_DIRS, MARK_ALL } ls_mark = MARK_NONE; static enum { BLOCKS_NONE, BLOCKS_POSIX, BLOCKS_KIBI } ls_blocks = BLOCKS_NONE; static int ls_print_inodes = 0; +static int ls_questionable = 0; static int recurse = 0; static int reverse = 0; @@ -102,6 +104,14 @@ static char * ls_filename(struct file_info *f) { static char name[PATH_MAX + 2]; snprintf(name, sizeof(name), "%s%s", f->path, ls_getmark(f->st.st_mode)); + + if (ls_questionable) { + for (size_t i = 0; i < strlen(name); i++) { + if (name[i] == '\t' || !isprint(name[i])) { + name[i] = '?'; + } + } + } return name; } @@ -523,12 +533,13 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); ls_print = isatty(STDOUT_FILENO) ? ls_print_columns : ls_print_single; + ls_questionable = isatty(STDOUT_FILENO) ? 1 : 0; enum { NONE, OPERANDS, ALL } links = NONE; int list_dirs_separately = 1; int c; - while ((c = getopt(argc, argv, ":ACFRSacdgfiklmnoprstux1HL")) != -1) { + while ((c = getopt(argc, argv, "ACFRSacdgfiklmnopqrstux1HL")) != -1) { switch (c) { case 'A': /** all but . and .. **/ ls_hidden = HIDE_SOME; @@ -627,7 +638,7 @@ int main(int argc, char *argv[]) break; case 'q': /** replace non-printable characters with ? **/ - //format |= QUOTE; // FIXME + ls_questionable = 1; break; case 'r': /** reverse sort order **/ |