wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 5967819d63943bd64e4b3879cd3398786a54842f
parent 6aa50a0d2b8d2d699f48eecec30508298e6aae6d
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Wed,  8 Feb 2006 01:05:19 +0100

implemented better xls formatting in wmiir


Diffstat:
cmd/wmiifs.c | 31+++++++++++++++----------------
cmd/wmiir.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 74 insertions(+), 34 deletions(-)

diff --git a/cmd/wmiifs.c b/cmd/wmiifs.c @@ -297,7 +297,7 @@ static void mntrespond(IXPConn *c, Fcall *fcall) { Bind *b = rx_to_bind(c); - fprintf(stderr, "mntrespond, welcome: fcall->id=%d\n", fcall->id); + /*fprintf(stderr, "mntrespond, welcome: fcall->id=%d\n", fcall->id);*/ memcpy(&b->fcall, fcall, sizeof(Fcall)); ixp_server_respond_fcall(b->tx, &b->fcall); } @@ -317,7 +317,7 @@ mntwalk(IXPConn *c, Fcall *fcall) } if(mkqid(&dir, b->fcall.wname[0], &b->fcall.wqid[0], True) == -1) { - fprintf(stderr, "%s", "wmiifs: mntwalk cannot make qid\n"); + /*fprintf(stderr, "%s", "wmiifs: mntwalk cannot make qid\n");*/ ixp_server_respond_error(b->tx, &b->fcall, Enofile); xunbind(b); return; @@ -328,14 +328,14 @@ mntwalk(IXPConn *c, Fcall *fcall) nwqid++; if(!nwqid) { - fprintf(stderr, "%s", "wmiifs: mntwalk nwqid wrong \n"); + /*fprintf(stderr, "%s", "wmiifs: mntwalk nwqid wrong \n");*/ ixp_server_respond_error(b->tx, &b->fcall, Enofile); xunbind(b); return; } /* a fid will only be valid, if the walk was complete */ - fprintf(stderr, "nwqid=%d b->fcall.nwname=%d", nwqid, b->fcall.nwname); + /*fprintf(stderr, "nwqid=%d b->fcall.nwname=%d", nwqid, b->fcall.nwname);*/ if(nwqid == b->fcall.nwname) { if(b->fcall.fid != b->fcall.newfid) { m = cext_emallocz(sizeof(IXPMap)); @@ -344,10 +344,10 @@ mntwalk(IXPConn *c, Fcall *fcall) } m->qid = dir; /* mount point, even if not */ m->fid = b->fcall.newfid; - fprintf(stderr, "%s", "wmiifs: fffaoooo\n"); + /*fprintf(stderr, "%s", "wmiifs: fffaoooo\n");*/ } - fprintf(stderr, "wmiifs: success mntwalk b-tx=%x m->fid = %d (b->fcall.newfid=%d)\n", - b->tx, m->fid, b->fcall.newfid); + /*fprintf(stderr, "wmiifs: success mntwalk b-tx=%x m->fid = %d (b->fcall.newfid=%d)\n", + b->tx, m->fid, b->fcall.newfid);*/ b->fid = m->fid; b->fcall.id = RWALK; b->fcall.nwqid = nwqid; @@ -358,7 +358,7 @@ static char * mntrequest(Bind *b, Fcall *tx) { unsigned int msize; - fprintf(stderr, "mntrequest: welcome, tx=%x tx->id=%d fid=%d\n", b->tx, tx->id, tx->fid); + /*fprintf(stderr, "mntrequest: welcome, tx=%x tx->id=%d fid=%d\n", b->tx, tx->id, tx->fid);*/ memcpy(&b->client.fcall, tx, sizeof(Fcall)); memcpy(&b->fcall, tx, sizeof(Fcall)); msize = ixp_fcall_to_msg(&b->client.fcall, msg, IXP_MAX_MSG); @@ -378,12 +378,12 @@ xwalk(IXPConn *c, Fcall *fcall) IXPMap *m; Mount *mnt; - fprintf(stderr, "xwalk: welcome fcall->wname[0]=%s fcall->fid=%d\n", fcall->wname[0], fcall->fid); + /*fprintf(stderr, "xwalk: welcome fcall->wname[0]=%s fcall->fid=%d\n", fcall->wname[0], fcall->fid);*/ if(!(m = ixp_server_fid2map(c, fcall->fid))) return Enofid; if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid))) return Enofid; - fprintf(stderr, "xwalk: fcall->nwname=%d\n", fcall->nwname); + /*fprintf(stderr, "xwalk: fcall->nwname=%d\n", fcall->nwname);*/ if(fcall->nwname) { dir = m->qid; if((mnt = name_to_mount(fcall->wname[0]))) { @@ -395,7 +395,7 @@ xwalk(IXPConn *c, Fcall *fcall) memcpy(&b->client.fcall, fcall, sizeof(Fcall)); memcpy(&b->fcall, fcall, sizeof(Fcall)); - fprintf(stderr, "xwalk: sending fid=%d (newfid=%d)\n", b->client.fcall.fid, b->client.fcall.newfid); + /*fprintf(stderr, "xwalk: sending fid=%d (newfid=%d)\n", b->client.fcall.fid, b->client.fcall.newfid);*/ b->client.fcall.nwname = fcall->nwname - 1; for(i = 1; i < fcall->nwname; i++) @@ -576,10 +576,10 @@ xstat(IXPConn *c, Fcall *fcall) IXPMap *m = ixp_server_fid2map(c, fcall->fid); Bind *b; char *name; - fprintf(stderr, "xstat: welcome, c=%x fcall->fid=%d\n", c, fcall->fid); + /*fprintf(stderr, "xstat: welcome, c=%x fcall->fid=%d\n", c, fcall->fid);*/ if(!m) return Enofid; - fprintf(stderr, "xstat: now fetching bind, fcall->fid=%d\n", fcall->fid); + /*fprintf(stderr, "xstat: now fetching bind, fcall->fid=%d\n", fcall->fid);*/ if((b = fid_to_bind(m->fid))) return mntrequest(b, fcall); name = qid_to_name(&m->qid); @@ -666,7 +666,7 @@ do_mnt_fcall(IXPConn *c) unsigned int msize; if((msize = ixp_server_receive_fcall(c, &fcall))) { - fprintf(stderr, "mntfcall=%d\n", fcall.id); + /*fprintf(stderr, "mntfcall=%d\n", fcall.id);*/ switch(fcall.id) { case RWALK: mntwalk(c, &fcall); break; case RREMOVE: @@ -679,7 +679,6 @@ do_mnt_fcall(IXPConn *c) case RERROR: mntrespond(c, &fcall); break; } } - fprintf(stderr, "foooo mntfcall=%d\n", fcall.id); } static void @@ -690,7 +689,7 @@ do_fcall(IXPConn *c) char *errstr; if((msize = ixp_server_receive_fcall(c, &fcall))) { - fprintf(stderr, "locfcall=%d\n", fcall.id); + /*fprintf(stderr, "locfcall=%d\n", fcall.id);*/ switch(fcall.id) { case TVERSION: errstr = wmii_ixp_version(c, &fcall); break; case TATTACH: errstr = wmii_ixp_attach(c, &fcall); break; diff --git a/cmd/wmiir.c b/cmd/wmiir.c @@ -8,6 +8,7 @@ #include <string.h> #include <unistd.h> #include <dirent.h> +#include <time.h> #include <ixp.h> #include <cext.h> @@ -80,40 +81,80 @@ xwrite(char *file) } static int -comp(const void *s1, const void *s2) +comp_stat(const void *s1, const void *s2) { - return strcmp(*(char **)s1, *(char **)s2); + Stat *st1 = (Stat *)s1; + Stat *st2 = (Stat *)s2; + return strcmp(st1->name, st2->name); +} + +static void +setrwx(long m, char *s) +{ + static char *modes[] = + { + "---", + "--x", + "-w-", + "-wx", + "r--", + "r-x", + "rw-", + "rwx", + }; + strncpy(s, modes[m], 3); +} + +static char * +mode_to_str(unsigned int mode) +{ + static char buf[16]; + + if(mode & DMDIR) + buf[0]='d'; + else + buf[0]='-'; + + buf[1]='-'; + setrwx((mode >> 6) & 7, &buf[2]); + setrwx((mode >> 3) & 7, &buf[5]); + setrwx((mode >> 0) & 7, &buf[8]); + buf[11] = 0; + return buf; +} + +static char * +time_to_str(unsigned int t) +{ + static char buf[32]; + cext_strlcpy(buf, ctime((time_t *)&t), sizeof(buf)); + buf[strlen(buf) - 1] = 0; + return buf; } static void xls(void *result, unsigned int msize) { - size_t n = 0, j = 0; - char buf[IXP_MAX_FLEN]; + size_t n = 0, i = 0; void *p = result; - char **dir; - static Stat stat, zerostat = { 0 }; + Stat *dir; + static Stat stat; do { p = ixp_dec_stat(p, &stat); n++; } while(p - result < msize); - dir = (char **)cext_emallocz(sizeof(char *) * n); + dir = (Stat *)cext_emallocz(sizeof(Stat) * n); p = result; do { - p = ixp_dec_stat(p, &stat); - if(stat.qid.type == IXP_QTDIR) - snprintf(buf, sizeof(buf), "%s/", stat.name); - else - snprintf(buf, sizeof(buf), "%s", stat.name); - dir[j++] = cext_estrdup(buf); - stat = zerostat; + p = ixp_dec_stat(p, &dir[i++]); } while(p - result < msize); - qsort(dir, n, sizeof(char *), comp); - for(j = 0; j < n; j++) { - fprintf(stdout, "%s\n", dir[j]); - free(dir[j]); + qsort(dir, n, sizeof(Stat), comp_stat); + for(i = 0; i < n; i++) { + fprintf(stdout, "%s %s %s %5lld %s %s\n", mode_to_str(dir[i].mode), + dir[i].uid, dir[i].gid, dir[i].length, + time_to_str(dir[i].mtime), dir[i].name); } free(dir); }