sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 9bd094193d6b77282cb4cf3883147b337230ecda
parent 93cc2ecc5cb75e1353b7b5dcb1fcd03950829f7d
Author: sin <sin@2f30.org>
Date:   Wed, 18 Feb 2015 15:55:57 +0000

Simplify ls -q implementation

Diffstat:
Mls.c | 33++++++++++++---------------------
1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/ls.c b/ls.c @@ -179,8 +179,8 @@ lsdir(const char *path) Rune r; struct entry ent, *ents = NULL; struct dirent *d; - size_t i, j, k, n = 0, len; - char *cwd, *p; + size_t i, n = 0, len; + char *cwd, *p, *q, *name; cwd = agetcwd(); if (!(dp = opendir(path))) @@ -203,30 +203,21 @@ lsdir(const char *path) output(&ent); } else { ents = erealloc(ents, ++n * sizeof(*ents)); - p = estrdup(d->d_name); + name = p = estrdup(d->d_name); if (qflag) { - len = strlen(p); - for (i = 1, j = 0; j + i <= len;) { - if (!fullrune(p + j, i)) { - i++; - continue; - } - charntorune(&r, p + j, i); + q = d->d_name; + while (*p) { + len = chartorune(&r, p); if (isprintrune(r)) { - j += i; - i = 1; - continue; - } - p[j] = '?'; - for (k = j + 1; k < len - i + 2; k++) { - p[k] = p[k + i - 1]; + memcpy(p, q, len); + p += len, q += len; + } else { + *p++ = '?'; + q += len; } - len -= i - 1; - j += 1; - i = 1; } } - mkent(&ents[n - 1], p, tflag || Fflag || lflag || iflag, Lflag); + mkent(&ents[n - 1], name, tflag || Fflag || lflag || iflag, Lflag); } } closedir(dp);