[hackers] [wmii] Fix the timestamp in events.

From: Kris Maglione <jg_AT_suckless.org>
Date: Thu Jul 19 01:46:51 2007

changeset: 2202:59b2862bc2a0
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed Jul 18 19:45:36 2007 -0400
summary: Fix the timestamp in events.

diff -r abcbb83b632b -r 59b2862bc2a0 cmd/wmii/area.c
--- a/cmd/wmii/area.c Wed Jul 18 17:56:13 2007 -0400
+++ b/cmd/wmii/area.c Wed Jul 18 19:45:36 2007 -0400
@@ -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;
-
- bx = x / divisor;
- mask = 1 << x % divisor;
+ div_t d;
+
+ d = div(x, divisor);
+ bx = d.quot;
+ mask = 1 << d.rem;
         if(set)
                 field[y*width + bx] |= mask;
         else
@@ -281,9 +283,11 @@ bit_get(uint *field, uint width, uint x,
 bit_get(uint *field, uint width, uint x, uint y) {
         enum { divisor = sizeof(uint) * 8 };
         uint bx, mask;
-
- bx = x / divisor;
- mask = 1 << x % divisor;
+ div_t d;
+
+ d = div(x, divisor);
+ bx = d.quot;
+ mask = 1 << d.rem;
 
         return (field[y*width + bx] & mask) != 0;
 }
diff -r abcbb83b632b -r 59b2862bc2a0 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Wed Jul 18 17:56:13 2007 -0400
+++ b/cmd/wmii/fns.h Wed Jul 18 19:45:36 2007 -0400
@@ -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 -r abcbb83b632b -r 59b2862bc2a0 cmd/wmii/message.c
--- a/cmd/wmii/message.c Wed Jul 18 17:56:13 2007 -0400
+++ b/cmd/wmii/message.c Wed Jul 18 19:45:36 2007 -0400
@@ -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'))
+ if(i < 2) {
+ if(r != ' ')
+ return Ebad;
+ p++;
+ }else if(!isspacerune(r) && *p != '\0')
                         return Ebad;
- if(i < 2)
- p++;
         }
 
         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 -r abcbb83b632b -r 59b2862bc2a0 cmd/wmii/printevent.c
--- a/cmd/wmii/printevent.c Wed Jul 18 17:56:13 2007 -0400
+++ b/cmd/wmii/printevent.c Wed Jul 18 19:45:36 2007 -0400
@@ -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;
-
- if (0)
- sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu",
- day, day == 1 ? "" : "(s)", hr, min, sec, msec);
-
- Bprint(b, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec);
+ msec = time/1000;
+ d = ldiv(msec, 60);
+ msec = time-msec*1000;
+
+ sec = d.rem;
+ d = ldiv(d.quot, 60);
+ min = d.rem;
+ d = ldiv(d.quot, 24);
+ hr = d.rem;
+ day = d.quot;
+
+#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 -r abcbb83b632b -r 59b2862bc2a0 cmd/wmii/view.c
--- a/cmd/wmii/view.c Wed Jul 18 17:56:13 2007 -0400
+++ b/cmd/wmii/view.c Wed Jul 18 19:45:36 2007 -0400
@@ -421,7 +421,7 @@ uint
 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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/fmtdef.h
--- a/libfmt/fmtdef.h Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/fmtdef.h Wed Jul 18 19:45:36 2007 -0400
@@ -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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/fmtprint.c
--- a/libfmt/fmtprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/fmtprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/fmtvprint.c
--- a/libfmt/fmtvprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/fmtvprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -32,16 +32,16 @@ fmtvprint(Fmt *f, const char *fmt, va_l
         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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/runevseprint.c
--- a/libfmt/runevseprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/runevseprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -31,9 +31,9 @@ runevseprint(Rune *buf, Rune *e, const c
         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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/runevsmprint.c
--- a/libfmt/runevsmprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/runevsmprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -77,9 +77,9 @@ runevsmprint(const char *fmt, va_list ar
 
         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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/runevsnprint.c
--- a/libfmt/runevsnprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/runevsnprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -31,9 +31,9 @@ runevsnprint(Rune *buf, int len, const c
         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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/vfprint.c
--- a/libfmt/vfprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/vfprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -24,9 +24,9 @@ vfprint(int fd, const char *fmt, va_list
         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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/vseprint.c
--- a/libfmt/vseprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/vseprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -30,9 +30,9 @@ vseprint(char *buf, char *e, const char
         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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/vsmprint.c
--- a/libfmt/vsmprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/vsmprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -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 -r abcbb83b632b -r 59b2862bc2a0 libfmt/vsnprint.c
--- a/libfmt/vsnprint.c Wed Jul 18 17:56:13 2007 -0400
+++ b/libfmt/vsnprint.c Wed Jul 18 19:45:36 2007 -0400
@@ -31,9 +31,9 @@ vsnprint(char *buf, int len, const char
         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;
 }
Received on Thu Jul 19 2007 - 01:46:51 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:57:39 UTC