From ad970838dc28b52fb1a0d33864b3685a162bd1b1 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 18 Jul 2007 19:45:36 -0400 Subject: [PATCH] Fix the timestamp in events. --- cmd/wmii/area.c | 14 +++++++++----- cmd/wmii/fns.h | 4 +++- cmd/wmii/message.c | 16 +++++++++------ cmd/wmii/printevent.c | 45 ++++++++++++++++++++++--------------------- cmd/wmii/view.c | 4 ++-- libfmt/fmtdef.h | 8 ++------ libfmt/fmtprint.c | 8 ++++---- libfmt/fmtvprint.c | 12 ++++++------ libfmt/runevseprint.c | 4 ++-- libfmt/runevsmprint.c | 4 ++-- libfmt/runevsnprint.c | 4 ++-- libfmt/vfprint.c | 4 ++-- libfmt/vseprint.c | 4 ++-- libfmt/vsmprint.c | 4 ++-- libfmt/vsnprint.c | 4 ++-- 15 files changed, 73 insertions(+), 66 deletions(-) diff --git a/cmd/wmii/area.c b/cmd/wmii/area.c index bce003fe..d74b583f 100644 --- a/cmd/wmii/area.c +++ b/cmd/wmii/area.c @@ -265,12 +265,14 @@ detach_from_area(Frame *f) { } static void -bit_set(uint *field, uint width, uint x, uint y, Bool set) { +bit_set(uint *field, uint width, uint x, uint y, int set) { enum { divisor = sizeof(uint) * 8 }; uint bx, mask; + div_t d; - bx = x / divisor; - mask = 1 << x % divisor; + d = div(x, divisor); + bx = d.quot; + mask = 1 << d.rem; if(set) field[y*width + bx] |= mask; else @@ -281,9 +283,11 @@ static Bool bit_get(uint *field, uint width, uint x, uint y) { enum { divisor = sizeof(uint) * 8 }; uint bx, mask; + div_t d; - bx = x / divisor; - mask = 1 << x % divisor; + d = div(x, divisor); + bx = d.quot; + mask = 1 << d.rem; return (field[y*width + bx] & mask) != 0; } diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h index 5147324d..c96175c2 100644 --- a/cmd/wmii/fns.h +++ b/cmd/wmii/fns.h @@ -4,7 +4,7 @@ #ifdef VARARGCK # pragma varargck argpos write_event 1 - +# # pragma varargck type "C" Client* # pragma varargck type "W" Window* # pragma varargck type "P" Point @@ -134,6 +134,8 @@ void* hashrm(Map*, char*); /* message.c */ char *getword(IxpMsg*); +int getulong(char*, ulong*); +int getlong(char*, long*); Area *strarea(View*, char*); char *message_view(View*, IxpMsg*); char *parse_colors(IxpMsg*, CTuple*); diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c index f46b67b5..263581ea 100644 --- a/cmd/wmii/message.c +++ b/cmd/wmii/message.c @@ -172,7 +172,7 @@ getbase(char **s) { return 10; } -static int +int getlong(char *s, long *ret) { char *end, *rend; int base; @@ -184,7 +184,7 @@ getlong(char *s, long *ret) { return (end == rend); } -static int +int getulong(char *s, ulong *ret) { char *end, *rend; int base; @@ -288,11 +288,14 @@ parse_colors(IxpMsg *m, CTuple *col) { for(j = 0; j < 6 && p < (char*)m->end; j++) if(!isxdigit(*p++)) return Ebad; + chartorune(&r, p); - if(i < 2 && r != ' ' || !(isspacerune(r) || *p == '\0')) - return Ebad; - if(i < 2) + if(i < 2) { + if(r != ' ') + return Ebad; p++; + }else if(!isspacerune(r) && *p != '\0') + return Ebad; } c = *p; @@ -345,12 +348,13 @@ message_root(void *p, IxpMsg *m) { resize_bar(screen); }else ret = "can't load font"; + focus_view(screen, screen->sel); break; case LBORDER: if(!getulong(getword(m), &n)) return Ebadvalue; def.border = n; - /* XXX: Apply the change */ + focus_view(screen, screen->sel); break; case LGRABMOD: s = getword(m); diff --git a/cmd/wmii/printevent.c b/cmd/wmii/printevent.c index 5de47752..4868f229 100644 --- a/cmd/wmii/printevent.c +++ b/cmd/wmii/printevent.c @@ -75,23 +75,21 @@ unmask(Pair * list, uint val) { Pair *p; char *s, *end; - Boolean first = True; + int n; buffer[0] = '\0'; end = buffer + sizeof buffer; s = buffer; - s += strlcat(s, "(", end - s); - + n = 0; + s = utfecpy(s, end, "("); for (p = list; p->val; p++) if (val & p->key) { - if (!first) - s += strlcat(s, "|", end - s); - first = False; - s += strlcat(s, p->val, end - s); + if(n++) + s = utfecpy(s, end, "|"); + s = utfecpy(s, end, p->val); } - - strlcat(s, ")", end - s); + utfecpy(s, end, ")"); return buffer; } @@ -150,6 +148,7 @@ TData(Biobuf *b, va_list *ap) { /* Returns the string equivalent of a timestamp */ static void TTime(Biobuf *b, va_list *ap) { + ldiv_t d; ulong msec; ulong sec; ulong min; @@ -159,21 +158,23 @@ TTime(Biobuf *b, va_list *ap) { time = va_arg(*ap, Time); - msec = time % 1000; - time /= 1000; - sec = time % 60; - time /= 60; - min = time % 60; - time /= 60; - hr = time % 24; - time /= 24; - day = time; + msec = time/1000; + d = ldiv(msec, 60); + msec = time-msec*1000; - if (0) - sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu", - day, day == 1 ? "" : "(s)", hr, min, sec, msec); + sec = d.rem; + d = ldiv(d.quot, 60); + min = d.rem; + d = ldiv(d.quot, 24); + hr = d.rem; + day = d.quot; - Bprint(b, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec); +#ifdef notdef + sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu", + day, day == 1 ? "" : "(s)", hr, min, sec, msec); +#endif + + Bprint(b, "%ludd_%ludh_%ludm_%lud.%03luds", day, hr, min, sec, msec); } /* Returns the string equivalent of a boolean parameter */ diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c index 379e3842..fbe1606a 100644 --- a/cmd/wmii/view.c +++ b/cmd/wmii/view.c @@ -421,7 +421,7 @@ update_views(void) { uint newcolw(View *v, int num) { Rule *r; - uint n; + ulong n; for(r=def.colrules.rule; r; r=r->next) if(regexec(r->regex, v->name, nil, 0)) { @@ -432,7 +432,7 @@ newcolw(View *v, int num) { n = tokenize(toks, 16, buf, '+'); if(num < n) - if(sscanf(toks[num], "%u", &n) == 1) + if(getulong(toks[num], &n)) return Dx(screen->r) * (n / 100.0); break; } diff --git a/libfmt/fmtdef.h b/libfmt/fmtdef.h index a33226dc..d3678312 100644 --- a/libfmt/fmtdef.h +++ b/libfmt/fmtdef.h @@ -106,11 +106,7 @@ int __strfmt(Fmt *f); }\ }while(0) -#ifdef va_copy -# define VA_COPY(a,b) va_copy(a,b) -# define VA_END(a) va_end(a) -#else -# define VA_COPY(a,b) (a) = (b) -# define VA_END(a) +#ifndef va_copy +# define va_copy(a,b) (a) = (b) #endif diff --git a/libfmt/fmtprint.c b/libfmt/fmtprint.c index 5629b185..3367125f 100644 --- a/libfmt/fmtprint.c +++ b/libfmt/fmtprint.c @@ -31,16 +31,16 @@ fmtprint(Fmt *f, const char *fmt, ...) f->flags = 0; f->width = 0; f->prec = 0; - VA_COPY(va, f->args); - VA_END(f->args); + va_copy(va, f->args); + va_end(f->args); va_start(f->args, fmt); n = dofmt(f, fmt); va_end(f->args); f->flags = 0; f->width = 0; f->prec = 0; - VA_COPY(f->args,va); - VA_END(va); + va_copy(f->args,va); + va_end(va); if(n >= 0) return 0; return n; diff --git a/libfmt/fmtvprint.c b/libfmt/fmtvprint.c index 37ef1e2f..db5115bc 100644 --- a/libfmt/fmtvprint.c +++ b/libfmt/fmtvprint.c @@ -32,16 +32,16 @@ fmtvprint(Fmt *f, const char *fmt, va_list args) f->flags = 0; f->width = 0; f->prec = 0; - VA_COPY(va,f->args); - VA_END(f->args); - VA_COPY(f->args,args); + va_copy(va,f->args); + va_end(f->args); + va_copy(f->args,args); n = dofmt(f, fmt); f->flags = 0; f->width = 0; f->prec = 0; - VA_END(f->args); - VA_COPY(f->args,va); - VA_END(va); + va_end(f->args); + va_copy(f->args,va); + va_end(va); if(n >= 0) return 0; return n; diff --git a/libfmt/runevseprint.c b/libfmt/runevseprint.c index 95cfa561..ee9d9c5e 100644 --- a/libfmt/runevseprint.c +++ b/libfmt/runevseprint.c @@ -31,9 +31,9 @@ runevseprint(Rune *buf, Rune *e, const char *fmt, va_list args) f.flush = nil; f.farg = nil; f.nfmt = 0; - VA_COPY(f.args,args); + va_copy(f.args,args); dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); *(Rune*)f.to = '\0'; return (Rune*)f.to; } diff --git a/libfmt/runevsmprint.c b/libfmt/runevsmprint.c index 18717f42..f39cab75 100644 --- a/libfmt/runevsmprint.c +++ b/libfmt/runevsmprint.c @@ -77,9 +77,9 @@ runevsmprint(const char *fmt, va_list args) if(runefmtstrinit(&f) < 0) return nil; - VA_COPY(f.args,args); + va_copy(f.args,args); n = dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); if(f.start == nil) return nil; if(n < 0){ diff --git a/libfmt/runevsnprint.c b/libfmt/runevsnprint.c index 0459a9ae..e602be0a 100644 --- a/libfmt/runevsnprint.c +++ b/libfmt/runevsnprint.c @@ -31,9 +31,9 @@ runevsnprint(Rune *buf, int len, const char *fmt, va_list args) f.flush = nil; f.farg = nil; f.nfmt = 0; - VA_COPY(f.args,args); + va_copy(f.args,args); dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); *(Rune*)f.to = '\0'; return (Rune*)f.to - buf; } diff --git a/libfmt/vfprint.c b/libfmt/vfprint.c index 9d936539..8e35c330 100644 --- a/libfmt/vfprint.c +++ b/libfmt/vfprint.c @@ -24,9 +24,9 @@ vfprint(int fd, const char *fmt, va_list args) int n; fmtfdinit(&f, fd, buf, sizeof(buf)); - VA_COPY(f.args,args); + va_copy(f.args,args); n = dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); if(n > 0 && __fmtFdFlush(&f) == 0) return -1; return n; diff --git a/libfmt/vseprint.c b/libfmt/vseprint.c index a7d793a5..c55dc328 100644 --- a/libfmt/vseprint.c +++ b/libfmt/vseprint.c @@ -30,9 +30,9 @@ vseprint(char *buf, char *e, const char *fmt, va_list args) f.flush = 0; f.farg = nil; f.nfmt = 0; - VA_COPY(f.args,args); + va_copy(f.args,args); dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); *(char*)f.to = '\0'; return (char*)f.to; } diff --git a/libfmt/vsmprint.c b/libfmt/vsmprint.c index def0ea26..72d74352 100644 --- a/libfmt/vsmprint.c +++ b/libfmt/vsmprint.c @@ -77,9 +77,9 @@ vsmprint(const char *fmt, va_list args) if(fmtstrinit(&f) < 0) return nil; - VA_COPY(f.args,args); + va_copy(f.args,args); n = dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); if(n < 0){ free(f.start); return nil; diff --git a/libfmt/vsnprint.c b/libfmt/vsnprint.c index 3e9c4f97..7c79b9c2 100644 --- a/libfmt/vsnprint.c +++ b/libfmt/vsnprint.c @@ -31,9 +31,9 @@ vsnprint(char *buf, int len, const char *fmt, va_list args) f.flush = 0; f.farg = nil; f.nfmt = 0; - VA_COPY(f.args,args); + va_copy(f.args,args); dofmt(&f, fmt); - VA_END(f.args); + va_end(f.args); *(char*)f.to = '\0'; return (char*)f.to - buf; }