[hackers] [sbase] Simplify ls -q implementation || sin

From: <git_AT_suckless.org>
Date: Wed, 18 Feb 2015 17:49:13 +0100 (CET)

commit 03afb2fb1809981065f310c63fcf984c9fa37c25
Author: sin <sin_AT_2f30.org>
Date: Wed Feb 18 15:55:57 2015 +0000

    Simplify ls -q implementation

diff --git a/ls.c b/ls.c
index be5a9cd..ab9d4c3 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -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)))
_AT_@ -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);
Received on Wed Feb 18 2015 - 17:49:13 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 18 2015 - 18:00:15 CET