Fix the timestamp in events.

This commit is contained in:
Kris Maglione 2007-07-18 19:45:36 -04:00
parent 90c44aefac
commit ad970838dc
15 changed files with 73 additions and 66 deletions

View File

@ -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;
}

View File

@ -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*);

View File

@ -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);

View File

@ -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 */

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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){

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}