From 2efbe03e90680427dd3bcd26eb1dfddf1396646f Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 16 Jul 2007 16:52:35 -0400 Subject: [PATCH] Bunch of fixes. --- cmd/Makefile | 2 +- cmd/util.c | 8 ++ cmd/wmii/bar.c | 6 +- cmd/wmii/client.c | 11 +-- cmd/wmii/fns.h | 26 ------ cmd/wmii/fs.c | 2 +- cmd/wmii/key.c | 4 +- cmd/wmii/main.c | 2 +- cmd/wmii/message.c | 4 +- cmd/wmii/rule.c | 2 +- cmd/wmii/view.c | 7 +- cmd/wmii/x11.c | 2 +- cmd/wmiir.c | 17 ++-- config.mk | 2 +- include/bio.h | 6 +- include/fmt.h | 42 ++++----- include/utf.h | 16 ++-- include/util.h | 1 + libbio/binit.c | 2 +- libbio/bprint.c | 2 +- libbio/bvprint.c | 2 +- libfmt/dofmt.c | 4 +- libfmt/fmt.c | 4 +- libfmt/fmtdef.h | 2 +- libfmt/fmtprint.c | 2 +- libfmt/fmtvprint.c | 2 +- libfmt/fprint.c | 2 +- libfmt/print.c | 2 +- libfmt/runeseprint.c | 2 +- libfmt/runesmprint.c | 2 +- libfmt/runesnprint.c | 2 +- libfmt/runesprint.c | 2 +- libfmt/runevseprint.c | 2 +- libfmt/runevsmprint.c | 2 +- libfmt/runevsnprint.c | 2 +- libfmt/seprint.c | 2 +- libfmt/smprint.c | 2 +- libfmt/snprint.c | 2 +- libfmt/sprint.c | 2 +- libfmt/vfprint.c | 2 +- libfmt/vseprint.c | 2 +- libfmt/vsmprint.c | 2 +- libfmt/vsnprint.c | 2 +- libutf/rune.c | 4 +- libutf/utfecpy.c | 2 +- libutf/utflen.c | 2 +- libutf/utfnlen.c | 4 +- libutf/utfrrune.c | 6 +- libutf/utfrune.c | 6 +- libutf/utfutf.c | 6 +- mk/gcc.mk | 2 +- rc/rc.wmii.rc | 201 +++++++++++++++++++++--------------------- rc/sh.wmii | 4 +- util/compile | 1 + util/link | 1 + 55 files changed, 223 insertions(+), 230 deletions(-) diff --git a/cmd/Makefile b/cmd/Makefile index b4eb5a29..10ae8043 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -17,7 +17,7 @@ FILTER = sed "s|CONFPREFIX|${ETC}|g; \ s|P9PATHS|${P9PATHS}|g; \ s|AWKPATH|${AWKPATH}|g" -LDFLAGS += -lbio -lfmt -lutf +LDFLAGS += -lfmt -lutf CFLAGS += ${INCX11} -DVERSION=\"${VERSION}\" include ${ROOT}/mk/many.mk diff --git a/cmd/util.c b/cmd/util.c index 7d13b6b9..9d9c643d 100644 --- a/cmd/util.c +++ b/cmd/util.c @@ -135,6 +135,14 @@ str_nil(char *s) { return ""; } +int +utflcpy(char *to, const char *from, int l) { + char *p; + + p = utfecpy(to, to+l, from); + return p-to; +} + uint strlcat(char *dst, const char *src, uint size) { const char *s; diff --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c index 445db725..84160cf0 100644 --- a/cmd/wmii/bar.c +++ b/cmd/wmii/bar.c @@ -53,7 +53,7 @@ create_bar(Bar **bp, char *name) { b = emallocz(sizeof(Bar)); b->id = id++; - strncpy(b->name, name, sizeof(b->name)); + utflcpy(b->name, name, sizeof(b->name)); b->col = def.normcolor; for(; *bp; bp = &(*bp)->next) @@ -144,7 +144,7 @@ draw_bar(WMScreen *s) { b->r.max.x += Dx(s->brect) - width; if(tb) - b->r = rectaddpt(b->r, Pt( tb->r.max.x, 0)); + b->r = rectaddpt(b->r, Pt(tb->r.max.x, 0)); } r = rectsubpt(s->brect, s->brect.min); @@ -162,7 +162,7 @@ draw_bar(WMScreen *s) { XSync(display, False); } -Bar * +Bar* bar_of_name(Bar *bp, const char *name) { Bar *b; diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c index 83eb1389..9da301d2 100644 --- a/cmd/wmii/client.c +++ b/cmd/wmii/client.c @@ -96,9 +96,9 @@ manage_client(Client *c) { tags = gettextproperty(&c->w, "_WIN_TAGS"); if((trans = win2client(c->trans))) - strncpy(c->tags, trans->tags, sizeof(c->tags)); + utflcpy(c->tags, trans->tags, sizeof(c->tags)); else if(tags) - strncpy(c->tags, tags, sizeof(c->tags)); + utflcpy(c->tags, tags, sizeof(c->tags)); free(tags); @@ -517,7 +517,7 @@ update_class(Client *c) { strcpy(c->props, "::"); str = c->props + 1; } - utfecpy(str+1, c->props+sizeof(c->props), c->name); + utflcpy(str+1, c->name, sizeof(c->props)); } static void @@ -530,7 +530,7 @@ update_client_name(Client *c) { if(str == nil) str = gettextproperty(&c->w, "WM_NAME"); if(str) - utfecpy(c->name, c->name+sizeof(c->name), str); + utflcpy(c->name, str, sizeof(c->name)); free(str); update_class(c); @@ -558,6 +558,7 @@ updatemwm(Client *c) { if(c->sel) r = frame2client(c->sel, c->sel->r); + if(n >= 3 && (ret[Flags]&FlagDecor)) { if(ret[Decor]&All) ret[Decor] ^= ~0; @@ -863,7 +864,7 @@ apply_tags(Client *c, const char *tags) { break; if(tags[n] == '+' || tags[n] == '-') - strncpy(buf, c->tags, sizeof(c->tags)); + utflcpy(buf, c->tags, sizeof(c->tags)); strlcat(buf, &tags[n], sizeof(buf)); trim(buf, " \t/"); diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h index f7caefb7..5147324d 100644 --- a/cmd/wmii/fns.h +++ b/cmd/wmii/fns.h @@ -240,31 +240,5 @@ Rectangle gravitate(Rectangle dst, Rectangle src, Point grav); Rectangle sizehint(WinHints*, Rectangle); void sethints(Window*); -/* utf.c */ -int chartorune(Rune*, char*); -int fullrune(char*, int n); -int runelen(long); -int runenlen(Rune*, int nrune); -Rune* runestrcat(Rune*, Rune*); -Rune* runestrchr(Rune*, Rune); -int runestrcmp(Rune*, Rune*); -Rune* runestrcpy(Rune*, Rune*); -Rune* runestrdup(Rune*) ; -Rune* runestrecpy(Rune*, Rune *end, Rune*); -long runestrlen(Rune*); -Rune* runestrncat(Rune*, Rune*, long); -int runestrncmp(Rune*, Rune*, long); -Rune* runestrncpy(Rune*, Rune*, long); -Rune* runestrrchr(Rune*, Rune); -Rune* runestrstr(Rune*, Rune*); -int runetochar(char*, Rune *rune); -Rune totitlerune(Rune); -char* utfecpy(char*, char *end, char*); -int utflen(char*); -int utfnlen(char*, long); -char* utfrrune(char*, long); -char* utfrune(char*, long); -char* utfutf(char*, char*); char* toutf8n(char*, size_t); char* toutf8(char*); -int isspacerune(Rune c); diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c index b5a57118..d05af94e 100644 --- a/cmd/wmii/fs.c +++ b/cmd/wmii/fs.c @@ -901,7 +901,7 @@ fs_clunk(Ixp9Req *r) { *q-- = '\0'; q = f->p.bar->text; - utfecpy(q, q+sizeof(((Bar*)0)->text), (char*)m.pos); + utflcpy(q, (char*)m.pos, sizeof(((Bar*)0)->text)); free(p); diff --git a/cmd/wmii/key.c b/cmd/wmii/key.c index ba4e444b..3b458d56 100644 --- a/cmd/wmii/key.c +++ b/cmd/wmii/key.c @@ -97,7 +97,7 @@ get_key(const char *name) { ungrab_key(k); return k; } - strncpy(buf, name, sizeof(buf)); + utflcpy(buf, name, sizeof(buf)); toks = tokenize(seq, 8, buf, ','); for(i = 0; i < toks; i++) { if(!k) @@ -106,7 +106,7 @@ get_key(const char *name) { k->next = emallocz(sizeof(Key)); k = k->next; } - strncpy(k->name, name, sizeof(k->name)); + utflcpy(k->name, name, sizeof(k->name)); kstr = strrchr(seq[i], '-'); if(kstr) kstr++; diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c index 15ddf2c3..b6fcd65b 100644 --- a/cmd/wmii/main.c +++ b/cmd/wmii/main.c @@ -475,7 +475,7 @@ main(int argc, char *argv[]) { def.colmode = Coldefault; def.mod = Mod1Mask; - strncpy(def.grabmod, "Mod1", sizeof(def.grabmod)); + strcpy(def.grabmod, "Mod1"); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c index 4fe2cbd1..7f61be4a 100644 --- a/cmd/wmii/message.c +++ b/cmd/wmii/message.c @@ -359,7 +359,7 @@ message_root(void *p, IxpMsg *m) { if((n & (Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0) return Ebadvalue; - strncpy(def.grabmod, s, sizeof(def.grabmod)); + utflcpy(def.grabmod, s, sizeof(def.grabmod)); def.mod = n; break; default: @@ -511,7 +511,7 @@ send_client(View *v, IxpMsg *m, Bool swap) { break; } - if(!to && !swap && (f->anext || f != a->frame)) + if(!to && !swap && (f->anext || f != f->area->frame)) to = new_column(v, a, 0); if(!to) diff --git a/cmd/wmii/rule.c b/cmd/wmii/rule.c index 828ef1e1..5eff2ea3 100644 --- a/cmd/wmii/rule.c +++ b/cmd/wmii/rule.c @@ -77,7 +77,7 @@ update_rules(Rule **rule, const char *data) { trim(value, " \t/"); (*rule)->regex = regcomp(regex); if((*rule)->regex) { - strncpy((*rule)->value, value, sizeof(rul->value)); + utflcpy((*rule)->value, value, sizeof(rul->value)); rule = &(*rule)->next; } else free(*rule); diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c index 31201088..4b299638 100644 --- a/cmd/wmii/view.c +++ b/cmd/wmii/view.c @@ -64,7 +64,7 @@ create_view(const char *name) { v = emallocz(sizeof(View)); v->id = id++; - strncpy(v->name, name, sizeof(v->name)); + utflcpy(v->name, name, sizeof(v->name)); write_event("CreateTag %s\n", v->name); create_area(v, nil, 0); @@ -154,7 +154,7 @@ void select_view(const char *arg) { char buf[256]; - strncpy(buf, arg, sizeof(buf)); + utflcpy(buf, arg, sizeof(buf)); trim(buf, " \t+/"); if(strlen(buf) == 0) @@ -172,7 +172,8 @@ attach_to_view(View *v, Frame *f) { c = f->client; c->revert = nil; - if(c->trans || c->floating || c->fixedsize || c->fullscreen) + if(c->trans || c->floating || c->fixedsize + || c->titleless || c->borderless || c->fullscreen) focus_area(v->area); else if(starting && v->sel->floating) focus_area(v->area->next); diff --git a/cmd/wmii/x11.c b/cmd/wmii/x11.c index b52f3112..dd1a1664 100644 --- a/cmd/wmii/x11.c +++ b/cmd/wmii/x11.c @@ -483,7 +483,7 @@ Bool loadcolor(CTuple *c, char *str) { char buf[24]; - strncpy(buf, str, sizeof buf); + utflcpy(buf, str, sizeof(buf)); memcpy(c->colstr, str, sizeof c->colstr); buf[7] = buf[15] = buf[23] = '\0'; diff --git a/cmd/wmiir.c b/cmd/wmiir.c index 42a03c07..4973c09d 100644 --- a/cmd/wmiir.c +++ b/cmd/wmiir.c @@ -16,7 +16,7 @@ static IxpClient *client; static void usage(void) { - fprintf(stderr, + fprint(1, "usage: %1$s [-a
] {create | read | ls [-ld] | remove | rm | write} \n" " %1$s [-a
] xwrite \n" " %1$s -v\n", argv0); @@ -64,7 +64,7 @@ setrwx(long m, char *s) { } static char * -str_of_mode(uint mode) { +modestr(uint mode) { static char buf[16]; buf[0]='-'; @@ -79,7 +79,7 @@ str_of_mode(uint mode) { } static char * -str_of_time(uint val) { +timestr(uint val) { static char buf[32]; ctime_r((time_t*)&val, buf); @@ -90,13 +90,14 @@ str_of_time(uint val) { static void print_stat(Stat *s, int lflag) { if(lflag) - fprintf(stdout, "%s %s %s %5llu %s %s\n", str_of_mode(s->mode), - s->uid, s->gid, s->length, str_of_time(s->mtime), s->name); + print("%s %s %s %5llud %s %s\n", + modestr(s->mode), s->uid, s->gid, s->length, + timestr(s->mtime), s->name); else { if((s->mode&P9_DMDIR) && strcmp(s->name, "/")) - fprintf(stdout, "%s/\n", s->name); + print("%s/\n", s->name); else - fprintf(stdout, "%s\n", s->name); + print("%s\n", s->name); } } @@ -317,7 +318,7 @@ main(int argc, char *argv[]) { ARGBEGIN{ case 'v': - printf("%s-" VERSION ", ©2007 Kris Maglione\n", argv0); + print("%s-" VERSION ", ©2007 Kris Maglione\n", argv0); exit(0); case 'a': address = EARGF(usage()); diff --git a/config.mk b/config.mk index df6fc393..ffa4f5ee 100644 --- a/config.mk +++ b/config.mk @@ -14,7 +14,7 @@ LIBS = -L/usr/lib -lc -L${ROOT}/lib # Flags include ${ROOT}/mk/gcc.mk -CFLAGS += -g -O0 +CFLAGS += -g -O0 -DIXPlint LDFLAGS += -g ${LIBS} STATIC = -static MKDEP = cpp -M diff --git a/include/bio.h b/include/bio.h index ab6c0f13..e1eb8789 100644 --- a/include/bio.h +++ b/include/bio.h @@ -70,8 +70,8 @@ int Binit(Biobuf*, int, int); int Binits(Biobuf*, int, int, unsigned char*, int); int Blinelen(Biobuf*); off_t Boffset(Biobuf*); -Biobuf* Bopen(char*, int); -int Bprint(Biobuf*, char*, ...); +Biobuf* Bopen(const char*, int); +int Bprint(Biobuf*, const char*, ...); int Bputc(Biobuf*, int); int Bputrune(Biobuf*, long); void* Brdline(Biobuf*, int); @@ -82,6 +82,6 @@ int Bterm(Biobuf*); int Bungetc(Biobuf*); int Bungetrune(Biobuf*); long Bwrite(Biobuf*, void*, long); -int Bvprint(Biobuf*, char*, va_list); +int Bvprint(Biobuf*, const char*, va_list); #endif diff --git a/include/fmt.h b/include/fmt.h index a8137dae..0219a0e4 100644 --- a/include/fmt.h +++ b/include/fmt.h @@ -108,41 +108,41 @@ extern int (*fmtdoquote)(int); #endif /* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/fmt/?*.c | grep -v static |grep -v __ */ -int dofmt(Fmt *f, char *fmt); +int dofmt(Fmt *f, const char *fmt); int dorfmt(Fmt *f, const Rune *fmt); double fmtcharstod(int(*f)(void*), void *vp); int fmtfdflush(Fmt *f); int fmtfdinit(Fmt *f, int fd, char *buf, int size); int fmtinstall(int c, int (*f)(Fmt*)); -int fmtprint(Fmt *f, char *fmt, ...); +int fmtprint(Fmt *f, const char *fmt, ...); int fmtrune(Fmt *f, int r); int fmtrunestrcpy(Fmt *f, Rune *s); -int fmtstrcpy(Fmt *f, char *s); +int fmtstrcpy(Fmt *f, const char *s); char* fmtstrflush(Fmt *f); int fmtstrinit(Fmt *f); double fmtstrtod(const char *as, char **aas); -int fmtvprint(Fmt *f, char *fmt, va_list args); -int fprint(int fd, char *fmt, ...); -int print(char *fmt, ...); +int fmtvprint(Fmt *f, const char *fmt, va_list args); +int fprint(int fd, const char *fmt, ...); +int print(const char *fmt, ...); void quotefmtinstall(void); int quoterunestrfmt(Fmt *f); int quotestrfmt(Fmt *f); Rune* runefmtstrflush(Fmt *f); int runefmtstrinit(Fmt *f); -Rune* runeseprint(Rune *buf, Rune *e, char *fmt, ...); -Rune* runesmprint(char *fmt, ...); -int runesnprint(Rune *buf, int len, char *fmt, ...); -int runesprint(Rune *buf, char *fmt, ...); -Rune* runevseprint(Rune *buf, Rune *e, char *fmt, va_list args); -Rune* runevsmprint(char *fmt, va_list args); -int runevsnprint(Rune *buf, int len, char *fmt, va_list args); -char* seprint(char *buf, char *e, char *fmt, ...); -char* smprint(char *fmt, ...); -int snprint(char *buf, int len, char *fmt, ...); -int sprint(char *buf, char *fmt, ...); -int vfprint(int fd, char *fmt, va_list args); -char* vseprint(char *buf, char *e, char *fmt, va_list args); -char* vsmprint(char *fmt, va_list args); -int vsnprint(char *buf, int len, char *fmt, va_list args); +Rune* runeseprint(Rune *buf, Rune *e, const char *fmt, ...); +Rune* runesmprint(const char *fmt, ...); +int runesnprint(Rune *buf, int len, const char *fmt, ...); +int runesprint(Rune *buf, const char *fmt, ...); +Rune* runevseprint(Rune *buf, Rune *e, const char *fmt, va_list args); +Rune* runevsmprint(const char *fmt, va_list args); +int runevsnprint(Rune *buf, int len, const char *fmt, va_list args); +char* seprint(char *buf, char *e, const char *fmt, ...); +char* smprint(const char *fmt, ...); +int snprint(char *buf, int len, const char *fmt, ...); +int sprint(char *buf, const char *fmt, ...); +int vfprint(int fd, const char *fmt, va_list args); +char* vseprint(char *buf, char *e, const char *fmt, va_list args); +char* vsmprint(const char *fmt, va_list args); +int vsnprint(char *buf, int len, const char *fmt, va_list args); #endif diff --git a/include/utf.h b/include/utf.h index f63bdfe6..4779dcbc 100644 --- a/include/utf.h +++ b/include/utf.h @@ -12,8 +12,8 @@ enum }; /* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/utf/?*.c | grep -v static |grep -v __ */ -int chartorune(Rune *rune, char *str); -int fullrune(char *str, int n); +int chartorune(Rune *rune, const char *str); +int fullrune(const char *str, int n); int isalpharune(Rune c); int islowerrune(Rune c); int isspacerune(Rune c); @@ -37,11 +37,11 @@ int runetochar(char *str, Rune *rune); Rune tolowerrune(Rune c); Rune totitlerune(Rune c); Rune toupperrune(Rune c); -char* utfecpy(char *to, char *e, char *from); -int utflen(char *s); -int utfnlen(char *s, long m); -char* utfrrune(char *s, long c); -char* utfrune(char *s, long c); -char* utfutf(char *s1, char *s2); +char* utfecpy(char *to, char *e, const char *from); +int utflen(const char *s); +int utfnlen(const char *s, long m); +char* utfrrune(const char *s, long c); +char* utfrune(const char *s, long c); +char* utfutf(const char *s1, const char *s2); #endif diff --git a/include/util.h b/include/util.h index e75cd177..4181864d 100644 --- a/include/util.h +++ b/include/util.h @@ -34,6 +34,7 @@ void fatal(const char *fmt, ...); int max(int a, int b); int min(int a, int b); char *str_nil(char *s); +int utflcpy(char *to, const char *from, int l); uint strlcat(char *dst, const char *src, unsigned int siz); char *argv0; diff --git a/libbio/binit.c b/libbio/binit.c index 84739020..19dbed0c 100644 --- a/libbio/binit.c +++ b/libbio/binit.c @@ -112,7 +112,7 @@ Bfdopen(int f, int mode) } Biobuf* -Bopen(char *name, int mode) +Bopen(const char *name, int mode) { Biobuf *bp; int f; diff --git a/libbio/bprint.c b/libbio/bprint.c index 2a8eb5d4..6bdff71e 100644 --- a/libbio/bprint.c +++ b/libbio/bprint.c @@ -2,7 +2,7 @@ #include int -Bprint(Biobuf *bp, char *fmt, ...) +Bprint(Biobuf *bp, const char *fmt, ...) { int n; va_list arg; diff --git a/libbio/bvprint.c b/libbio/bvprint.c index 7da0afeb..a65da64b 100644 --- a/libbio/bvprint.c +++ b/libbio/bvprint.c @@ -17,7 +17,7 @@ fmtBflush(Fmt *f) } int -Bvprint(Biobuf *bp, char *fmt, va_list arg) +Bvprint(Biobuf *bp, const char *fmt, va_list arg) { int n; Fmt f; diff --git a/libfmt/dofmt.c b/libfmt/dofmt.c index 8f853323..a7d4d2fc 100644 --- a/libfmt/dofmt.c +++ b/libfmt/dofmt.c @@ -19,7 +19,7 @@ /* format the output into f->to and return the number of characters fmted */ int -dofmt(Fmt *f, char *fmt) +dofmt(Fmt *f, const char *fmt) { Rune rune, *rt, *rs; int r; @@ -249,7 +249,7 @@ __runefmt(Fmt *f) /* public helper routine: fmt out a null terminated string already in hand */ int -fmtstrcpy(Fmt *f, char *s) +fmtstrcpy(Fmt *f, const char *s) { int i, j; Rune r; diff --git a/libfmt/fmt.c b/libfmt/fmt.c index db5f0384..0d9639d4 100644 --- a/libfmt/fmt.c +++ b/libfmt/fmt.c @@ -137,7 +137,7 @@ fmtfmt(int c) } void* -__fmtdispatch(Fmt *f, void *fmt, int isrunes) +__fmtdispatch(Fmt *f, const void *fmt, int isrunes) { Rune rune, r; int i, n; @@ -213,6 +213,6 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes) if(n < 0) return nil; if(n == 0) - return fmt; + return (void*)fmt; } } diff --git a/libfmt/fmtdef.h b/libfmt/fmtdef.h index 5a63f9be..a33226dc 100644 --- a/libfmt/fmtdef.h +++ b/libfmt/fmtdef.h @@ -43,7 +43,7 @@ int __errfmt(Fmt *f); int __flagfmt(Fmt *f); int __fmtFdFlush(Fmt *f); int __fmtcpy(Fmt *f, const void *vm, int n, int sz); -void* __fmtdispatch(Fmt *f, void *fmt, int isrunes); +void* __fmtdispatch(Fmt *f, const void *fmt, int isrunes); void * __fmtflush(Fmt *f, void *t, int len); void __fmtlock(void); int __fmtpad(Fmt *f, int n); diff --git a/libfmt/fmtprint.c b/libfmt/fmtprint.c index 5ba59d34..5629b185 100644 --- a/libfmt/fmtprint.c +++ b/libfmt/fmtprint.c @@ -23,7 +23,7 @@ * but ignore any width flags */ int -fmtprint(Fmt *f, char *fmt, ...) +fmtprint(Fmt *f, const char *fmt, ...) { va_list va; int n; diff --git a/libfmt/fmtvprint.c b/libfmt/fmtvprint.c index cb7ffbe8..37ef1e2f 100644 --- a/libfmt/fmtvprint.c +++ b/libfmt/fmtvprint.c @@ -24,7 +24,7 @@ * but ignore any width flags */ int -fmtvprint(Fmt *f, char *fmt, va_list args) +fmtvprint(Fmt *f, const char *fmt, va_list args) { va_list va; int n; diff --git a/libfmt/fprint.c b/libfmt/fprint.c index 043202c8..b9ca15eb 100644 --- a/libfmt/fprint.c +++ b/libfmt/fprint.c @@ -17,7 +17,7 @@ #include "fmtdef.h" int -fprint(int fd, char *fmt, ...) +fprint(int fd, const char *fmt, ...) { int n; va_list args; diff --git a/libfmt/print.c b/libfmt/print.c index d038cee7..d3802622 100644 --- a/libfmt/print.c +++ b/libfmt/print.c @@ -17,7 +17,7 @@ #include "fmtdef.h" int -print(char *fmt, ...) +print(const char *fmt, ...) { int n; va_list args; diff --git a/libfmt/runeseprint.c b/libfmt/runeseprint.c index 8e01c079..1e06df0e 100644 --- a/libfmt/runeseprint.c +++ b/libfmt/runeseprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" Rune* -runeseprint(Rune *buf, Rune *e, char *fmt, ...) +runeseprint(Rune *buf, Rune *e, const char *fmt, ...) { Rune *p; va_list args; diff --git a/libfmt/runesmprint.c b/libfmt/runesmprint.c index 03143a94..fc56bdc7 100644 --- a/libfmt/runesmprint.c +++ b/libfmt/runesmprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" Rune* -runesmprint(char *fmt, ...) +runesmprint(const char *fmt, ...) { va_list args; Rune *p; diff --git a/libfmt/runesnprint.c b/libfmt/runesnprint.c index 2e6ad6c6..fad02b3f 100644 --- a/libfmt/runesnprint.c +++ b/libfmt/runesnprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" int -runesnprint(Rune *buf, int len, char *fmt, ...) +runesnprint(Rune *buf, int len, const char *fmt, ...) { int n; va_list args; diff --git a/libfmt/runesprint.c b/libfmt/runesprint.c index 1dad4df7..8924e7b2 100644 --- a/libfmt/runesprint.c +++ b/libfmt/runesprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" int -runesprint(Rune *buf, char *fmt, ...) +runesprint(Rune *buf, const char *fmt, ...) { int n; va_list args; diff --git a/libfmt/runevseprint.c b/libfmt/runevseprint.c index 2359c817..95cfa561 100644 --- a/libfmt/runevseprint.c +++ b/libfmt/runevseprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" Rune* -runevseprint(Rune *buf, Rune *e, char *fmt, va_list args) +runevseprint(Rune *buf, Rune *e, const char *fmt, va_list args) { Fmt f; diff --git a/libfmt/runevsmprint.c b/libfmt/runevsmprint.c index 3b92e05f..18717f42 100644 --- a/libfmt/runevsmprint.c +++ b/libfmt/runevsmprint.c @@ -70,7 +70,7 @@ runefmtstrinit(Fmt *f) * print into an allocated string buffer */ Rune* -runevsmprint(char *fmt, va_list args) +runevsmprint(const char *fmt, va_list args) { Fmt f; int n; diff --git a/libfmt/runevsnprint.c b/libfmt/runevsnprint.c index 431868a3..0459a9ae 100644 --- a/libfmt/runevsnprint.c +++ b/libfmt/runevsnprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" int -runevsnprint(Rune *buf, int len, char *fmt, va_list args) +runevsnprint(Rune *buf, int len, const char *fmt, va_list args) { Fmt f; diff --git a/libfmt/seprint.c b/libfmt/seprint.c index 38bdf5f5..276ba0b0 100644 --- a/libfmt/seprint.c +++ b/libfmt/seprint.c @@ -17,7 +17,7 @@ #include "fmtdef.h" char* -seprint(char *buf, char *e, char *fmt, ...) +seprint(char *buf, char *e, const char *fmt, ...) { char *p; va_list args; diff --git a/libfmt/smprint.c b/libfmt/smprint.c index f46c964d..741269ab 100644 --- a/libfmt/smprint.c +++ b/libfmt/smprint.c @@ -17,7 +17,7 @@ #include "fmtdef.h" char* -smprint(char *fmt, ...) +smprint(const char *fmt, ...) { va_list args; char *p; diff --git a/libfmt/snprint.c b/libfmt/snprint.c index 17ce0e2d..81170f2f 100644 --- a/libfmt/snprint.c +++ b/libfmt/snprint.c @@ -17,7 +17,7 @@ #include "fmtdef.h" int -snprint(char *buf, int len, char *fmt, ...) +snprint(char *buf, int len, const char *fmt, ...) { int n; va_list args; diff --git a/libfmt/sprint.c b/libfmt/sprint.c index 13e78eef..6717f6ea 100644 --- a/libfmt/sprint.c +++ b/libfmt/sprint.c @@ -16,7 +16,7 @@ #include "fmtdef.h" int -sprint(char *buf, char *fmt, ...) +sprint(char *buf, const char *fmt, ...) { int n; uint len; diff --git a/libfmt/vfprint.c b/libfmt/vfprint.c index e5a7da3a..9d936539 100644 --- a/libfmt/vfprint.c +++ b/libfmt/vfprint.c @@ -17,7 +17,7 @@ #include "fmtdef.h" int -vfprint(int fd, char *fmt, va_list args) +vfprint(int fd, const char *fmt, va_list args) { Fmt f; char buf[256]; diff --git a/libfmt/vseprint.c b/libfmt/vseprint.c index b6dfee63..a7d793a5 100644 --- a/libfmt/vseprint.c +++ b/libfmt/vseprint.c @@ -17,7 +17,7 @@ #include "fmtdef.h" char* -vseprint(char *buf, char *e, char *fmt, va_list args) +vseprint(char *buf, char *e, const char *fmt, va_list args) { Fmt f; diff --git a/libfmt/vsmprint.c b/libfmt/vsmprint.c index e015f832..def0ea26 100644 --- a/libfmt/vsmprint.c +++ b/libfmt/vsmprint.c @@ -70,7 +70,7 @@ fmtstrinit(Fmt *f) * print into an allocated string buffer */ char* -vsmprint(char *fmt, va_list args) +vsmprint(const char *fmt, va_list args) { Fmt f; int n; diff --git a/libfmt/vsnprint.c b/libfmt/vsnprint.c index ed703250..3e9c4f97 100644 --- a/libfmt/vsnprint.c +++ b/libfmt/vsnprint.c @@ -18,7 +18,7 @@ #include "fmtdef.h" int -vsnprint(char *buf, int len, char *fmt, va_list args) +vsnprint(char *buf, int len, const char *fmt, va_list args) { Fmt f; diff --git a/libutf/rune.c b/libutf/rune.c index 88484f60..a3463d5d 100644 --- a/libutf/rune.c +++ b/libutf/rune.c @@ -41,7 +41,7 @@ enum }; int -chartorune(Rune *rune, char *str) +chartorune(Rune *rune, const char *str) { int c, c1, c2; long l; @@ -161,7 +161,7 @@ runenlen(Rune *r, int nrune) } int -fullrune(char *str, int n) +fullrune(const char *str, int n) { int c; diff --git a/libutf/utfecpy.c b/libutf/utfecpy.c index f254c13a..1a76d728 100644 --- a/libutf/utfecpy.c +++ b/libutf/utfecpy.c @@ -17,7 +17,7 @@ #include "utf.h" char* -utfecpy(char *to, char *e, char *from) +utfecpy(char *to, char *e, const char *from) { char *end; diff --git a/libutf/utflen.c b/libutf/utflen.c index 769805a5..338cf6e0 100644 --- a/libutf/utflen.c +++ b/libutf/utflen.c @@ -17,7 +17,7 @@ #include "utf.h" int -utflen(char *s) +utflen(const char *s) { int c; long n; diff --git a/libutf/utfnlen.c b/libutf/utfnlen.c index 66803299..61985aaa 100644 --- a/libutf/utfnlen.c +++ b/libutf/utfnlen.c @@ -17,12 +17,12 @@ #include "utf.h" int -utfnlen(char *s, long m) +utfnlen(const char *s, long m) { int c; long n; Rune rune; - char *es; + const char *es; es = s + m; for(n = 0; s < es; n++) { diff --git a/libutf/utfrrune.c b/libutf/utfrrune.c index cff12b5e..f571c1fb 100644 --- a/libutf/utfrrune.c +++ b/libutf/utfrrune.c @@ -17,11 +17,11 @@ #include "utf.h" char* -utfrrune(char *s, long c) +utfrrune(const char *s, long c) { long c1; Rune r; - char *s1; + const char *s1; if(c < Runesync) /* not part of utf sequence */ return strrchr(s, c); @@ -31,7 +31,7 @@ utfrrune(char *s, long c) c1 = *(uchar*)s; if(c1 < Runeself) { /* one byte rune */ if(c1 == 0) - return s1; + return (char*)s1; if(c1 == c) s1 = s; s++; diff --git a/libutf/utfrune.c b/libutf/utfrune.c index 52b83599..bcbf1a4d 100644 --- a/libutf/utfrune.c +++ b/libutf/utfrune.c @@ -17,7 +17,7 @@ #include "utf.h" char* -utfrune(char *s, long c) +utfrune(const char *s, long c) { long c1; Rune r; @@ -32,13 +32,13 @@ utfrune(char *s, long c) if(c1 == 0) return 0; if(c1 == c) - return s; + return (char*)s; s++; continue; } n = chartorune(&r, s); if(r == c) - return s; + return (char*)s; s += n; } } diff --git a/libutf/utfutf.c b/libutf/utfutf.c index 13c85020..a03d5c4e 100644 --- a/libutf/utfutf.c +++ b/libutf/utfutf.c @@ -22,9 +22,9 @@ * 0 if none */ char* -utfutf(char *s1, char *s2) +utfutf(const char *s1, const char *s2) { - char *p; + const char *p; long f, n1, n2; Rune r; @@ -36,6 +36,6 @@ utfutf(char *s1, char *s2) n2 = strlen(s2); for(p=s1; p=utfrune(p, f); p+=n1) if(strncmp(p, s2, n2) == 0) - return p; + return (char*)p; return 0; } diff --git a/mk/gcc.mk b/mk/gcc.mk index 3de20054..4e79200d 100644 --- a/mk/gcc.mk +++ b/mk/gcc.mk @@ -1,5 +1,5 @@ CFLAGS += \ - -std=gnu99 \ + -std=c99 \ -pipe \ -Wall \ -Wno-parentheses \ diff --git a/rc/rc.wmii.rc b/rc/rc.wmii.rc index 60aeebdc..2958bb5a 100755 --- a/rc/rc.wmii.rc +++ b/rc/rc.wmii.rc @@ -1,45 +1,19 @@ #!/usr/bin/env wmii9rc # WMII Configuration +confpath=`{echo $WMII_CONFPATH | sed 'y/:/ /'} oldpath=$path path=($PLAN9/bin $path) -MODKEY=Mod1 -UP=k -DOWN=j -LEFT=h -RIGHT=l - -WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*' -WMII_NORMCOLORS=('#222222' '#5FBF77' '#2A7F3F') -WMII_FOCUSCOLORS=('#ffffff' '#153F1F' '#2A7F3F') -WMII_BACKGROUND='#333333' - -WMII_TERM=(xterm) - -fn wmiimenu { - dmenu -b -fn $WMII_FONT \ - -nf $WMII_NORMCOLORS(1) -nb $WMII_NORMCOLORS(2) \ - -sf $WMII_FOCUSCOLORS(1) -sb $WMII_FOCUSCOLORS(2) -} - -fn 9menu { - wmii9menu -font $WMII_FONT \ - -^(nf nb br)^$WMII_NORMCOLORS \ - -^(sf sb br)^$WMII_FOCUSCOLORS $* +# Sanity checks +if(echo $0 | grep -s '(^|/)rc\.wmii\.local$') { + echo >[1=2] Fatal: This file must not be named rc.wmii.local + exit badname } fn config_whatis { - confpath=`{echo $WMII_CONFPATH | sed 'y/:/ /'} - prog = `{{path=$confpath whatis $1} | grep -v '^fn|= '}; shift - if(~ $#prog 0) - prog = /dev/null - echo $prog $* -} - -if(echo $0 | grep -vs '/rc.wmii$') { - echo Fatal: This file should only be run as rc.wmii >[1=2] - exit badname + prog = `{@{path=$confpath whatis $1} | grep -v '^fn|= ' || echo /dev/null} + shift; echo $prog $* } if(! test -x $PLAN9/bin/read) { @@ -54,6 +28,20 @@ rc.wmii can't run: wmiirc will be run instead. ! +# Configurables +MODKEY=Mod1 +UP=k +DOWN=j +LEFT=h +RIGHT=l + +WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*' +WMII_NORMCOLORS=('#222222' '#5FBF77' '#2A7F3F') +WMII_FOCUSCOLORS=('#ffffff' '#153F1F' '#2A7F3F') +WMII_BACKGROUND='#333333' + +WMII_TERM=(xterm) + # Column Rules wmiir write /colrules < 60+40 @@ -68,12 +56,22 @@ wmiir write /tagrules <[2]/dev/null \ @@ -81,32 +79,34 @@ fn proglist { | sort | uniq } -fn getfuns { - env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p' -} - fn actionlist { { proglist $WMII_CONFPATH getfuns Action } | sort | uniq } -fn initkeys { - getfuns Key | wmiir write /keys -} - -fn read_tags { - wmiir ls /tag | sed 's,/,,; /^sel$/d' -} - -fn run_command { - @{ - rfork ns - path=$oldpath - eval exec $* & +fn run_command { @{ + rfork ns + path=$oldpath + eval exec $* & } } +fn getfuns { env | sed -n 's/^fn#'^$1^'-([^=]+).*/\1/p' } +fn initkeys { getfuns Key | wmiir write /keys } +fn read_tags { wmiir ls /tag | sed 's,/,,; /^sel$/d' } +fn 'fn?' {rc -c 'whatis '$1 >[2]/dev/null | grep -s '^fn ' } + +# Events +fn Event-Start { + switch($1) { + case wmiirc + rm -f $progs_file + exit + } +} +fn Event-Key { Key-$1 $1 } + fn Event-CreateTag { echo $WMII_NORMCOLORS `{viewtitle $*} | wmiir create /lbar/$"* } fn Event-DestroyTag { wmiir remove /lbar/$"* } fn Event-FocusTag { wmiir xwrite /lbar/$"* $WMII_FOCUSCOLORS `{viewtitle $*} } @@ -116,7 +116,6 @@ fn Event-NotUrgentTag { shift; wmiir xwrite /lbar/$"* $"* } fn Event-LeftBarClick { shift; wmiir xwrite /ctl view $* } -menulast = '' fn Event-ClientMouseDown { client = $1; button = $2 if(~ $button 3) { @@ -131,10 +130,8 @@ fn Event-ClientMouseDown { menulast = $do; } } +menulast = Nop -fn 'fn?' {rc -c 'whatis '$1 >[2]/dev/null | grep -s '^fn ' } - -# Actions fn Action { cmd=$1 action=Action-$cmd { shift if('fn?' $action) @@ -143,12 +140,20 @@ fn Action { run_command `{config_whatis $cmd} $* } & } -fn Action-rehash { proglist $PATH >$progs_file } + +# Actions +fn Action-rehash { + if(test -d /proc/$pid) + for(i in $WMII_NS_DIR/proglist.*) { + id=`{echo $i | sed 's/.*\.(.*)/\1/'} \ + if(! test -d /proc/$id) rm $i + } + proglist $PATH >$progs_file +} fn Action-quit { wmiir xwrite /ctl quit } fn Action-exec { wmiir xwrite /ctl exec $* } fn Action-status { - flag x - - flag r - + flag x -; flag r - if(wmiir remove /rbar/status >[2]/dev/null) sleep 2 echo $WMII_NORMCOLORS | wmiir create /rbar/status @@ -156,16 +161,6 @@ fn Action-status { sleep 1 } -# Events -fn Event-Start { - switch($1) { - case wmiirc - rm -f $progs_file - exit - } -} -fn Event-Key { eval Key-$1 $1 } - # Source Variables, &c local = `{config_whatis rc.wmii.local} . <{awk '//; @@ -181,7 +176,13 @@ local = `{config_whatis rc.wmii.local} }' $local $progs_file & +Action status +Action rehash # Tag Bar Setup ifs='# @@ -263,7 +267,7 @@ ifs='# initkeys if(echo Start wmiirc | ! wmiir write /event >[2]/dev/null) - exit 1 + exit write # Event Loop wmiir read /event | @@ -271,4 +275,3 @@ wmiir read /event | event = $1; shift Event-$event $* } >[2]/dev/null /client/$client/ctl - } {$cmp Fullscreen} { echo Fullscreen >/client/$client/ctl + } {$cmp Fullscreen} { echo Fullscreen toggle >/client/$client/ctl } } } @@ -198,6 +198,8 @@ Key $MODKEY-d { echo colmode sel default >/tag/sel/ctl } Key $MODKEY-s { echo colmode sel stack >/tag/sel/ctl } Key $MODKEY-m { echo colmode sel max >/tag/sel/ctl } +Key $MODKEY-f { echo Fullscreen toggle >/client/sel/ctl } + Key $MODKEY-Shift-c { echo kill >/client/sel/ctl } Key $MODKEY-a { Action `{actionlist | wmiimenu} & } diff --git a/util/compile b/util/compile index bf664de9..8dda6fb9 100755 --- a/util/compile +++ b/util/compile @@ -8,6 +8,7 @@ bin="$(echo $0 | sed 's,/[^/]*$,,')" xtmp=/tmp/cc.$$.$USER.out echo CC $($bin/cleanname ${BASE}$outfile) +[ -n "$noisycc" ] && echo $CC -o $outfile $CFLAGS $@ $CC -o $outfile $CFLAGS $@ 2>$xtmp status=$? diff --git a/util/link b/util/link index eb7e9e53..00c9719c 100755 --- a/util/link +++ b/util/link @@ -21,6 +21,7 @@ done xtmp=/tmp/ld.$$.$USER.out echo LD "$($bin/cleanname ${BASE}$outfile)" +[ -n "$noisycc" ] && echo $LD -o $outfile $ofiles $LDFLAGS $args $LD -o $outfile $ofiles $LDFLAGS $args >$xtmp 2>&1 status=$?