Bunch of fixes.

This commit is contained in:
Kris Maglione 2007-07-16 16:52:35 -04:00
parent 35cdf47d04
commit 2efbe03e90
55 changed files with 223 additions and 230 deletions

View File

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

View File

@ -135,6 +135,14 @@ str_nil(char *s) {
return "<nil>";
}
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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ static IxpClient *client;
static void
usage(void) {
fprintf(stderr,
fprint(1,
"usage: %1$s [-a <address>] {create | read | ls [-ld] | remove | rm | write} <file>\n"
" %1$s [-a <address>] xwrite <file> <data>\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());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
#include <bio.h>
int
Bprint(Biobuf *bp, char *fmt, ...)
Bprint(Biobuf *bp, const char *fmt, ...)
{
int n;
va_list arg;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@
#include "fmtdef.h"
int
fprint(int fd, char *fmt, ...)
fprint(int fd, const char *fmt, ...)
{
int n;
va_list args;

View File

@ -17,7 +17,7 @@
#include "fmtdef.h"
int
print(char *fmt, ...)
print(const char *fmt, ...)
{
int n;
va_list args;

View File

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

View File

@ -18,7 +18,7 @@
#include "fmtdef.h"
Rune*
runesmprint(char *fmt, ...)
runesmprint(const char *fmt, ...)
{
va_list args;
Rune *p;

View File

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

View File

@ -18,7 +18,7 @@
#include "fmtdef.h"
int
runesprint(Rune *buf, char *fmt, ...)
runesprint(Rune *buf, const char *fmt, ...)
{
int n;
va_list args;

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@
#include "fmtdef.h"
char*
smprint(char *fmt, ...)
smprint(const char *fmt, ...)
{
va_list args;
char *p;

View File

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

View File

@ -16,7 +16,7 @@
#include "fmtdef.h"
int
sprint(char *buf, char *fmt, ...)
sprint(char *buf, const char *fmt, ...)
{
int n;
uint len;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@
#include "utf.h"
int
utflen(char *s)
utflen(const char *s)
{
int c;
long n;

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
CFLAGS += \
-std=gnu99 \
-std=c99 \
-pipe \
-Wall \
-Wno-parentheses \

View File

@ -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 <<!
!
# Status Bar Info
fn status {
echo -n `{uptime | sed 's/.*://; s/,//g'} '|' `{date}
fn status { echo -n `{uptime | sed 's/.*://; s/,//g'} '|' `{date} }
fn viewtitle { echo $* }
# Convenience Functions
fn wmiimenu {
dmenu -b -fn $WMII_FONT \
-nf $WMII_NORMCOLORS(1) -nb $WMII_NORMCOLORS(2) \
-sf $WMII_FOCUSCOLORS(1) -sb $WMII_FOCUSCOLORS(2)
}
# Functions
fn viewtitle { echo $* }
fn 9menu {
wmii9menu -font $WMII_FONT \
-^(nf nb br)^$WMII_NORMCOLORS \
-^(sf sb br)^$WMII_FOCUSCOLORS $*
}
fn proglist {
/bin/ls -lL `{echo $* | sed 'y/:/ /'} >[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 </dev/null}
# Key Bindings
fn Key-$MODKEY-Control-t {
fn key {
key=()
for(k in Key-$*) if(! 'fn?' $k) key = ($key $k)
~ $#key 0
}
key $MODKEY-Control-t || fn $key {
switch(`{wmiir read /keys | wc -l}) {
case 0 1
initkeys
@ -192,37 +193,40 @@ fn Key-$MODKEY-Control-t {
}
}
fn Key-$MODKEY-$LEFT { wmiir xwrite /tag/sel/ctl select left }
fn Key-$MODKEY-$RIGHT { wmiir xwrite /tag/sel/ctl select right }
fn Key-$MODKEY-$DOWN { wmiir xwrite /tag/sel/ctl select down }
fn Key-$MODKEY-$UP { wmiir xwrite /tag/sel/ctl select up }
key $MODKEY-$LEFT || fn $key { wmiir xwrite /tag/sel/ctl select left }
key $MODKEY-$RIGHT || fn $key { wmiir xwrite /tag/sel/ctl select right }
key $MODKEY-$DOWN || fn $key { wmiir xwrite /tag/sel/ctl select down }
key $MODKEY-$UP || fn $key { wmiir xwrite /tag/sel/ctl select up }
fn Key-$MODKEY-Shift-$LEFT { wmiir xwrite /tag/sel/ctl send sel left }
fn Key-$MODKEY-Shift-$RIGHT { wmiir xwrite /tag/sel/ctl send sel right }
fn Key-$MODKEY-Shift-$DOWN { wmiir xwrite /tag/sel/ctl send sel down }
fn Key-$MODKEY-Shift-$UP { wmiir xwrite /tag/sel/ctl send sel up }
key $MODKEY-Shift-$LEFT || fn $key { wmiir xwrite /tag/sel/ctl send sel left }
key $MODKEY-Shift-$RIGHT || fn $key { wmiir xwrite /tag/sel/ctl send sel right }
key $MODKEY-Shift-$DOWN || fn $key { wmiir xwrite /tag/sel/ctl send sel down }
key $MODKEY-Shift-$UP || fn $key { wmiir xwrite /tag/sel/ctl send sel up }
fn Key-$MODKEY-f { wmiir xwrite /client/sel/ctl Fullscreen toggle }
key $MODKEY-f || fn $key { wmiir xwrite /client/sel/ctl Fullscreen toggle }
fn Key-$MODKEY-space { wmiir xwrite /tag/sel/ctl select toggle }
fn Key-$MODKEY-Shift-space { wmiir xwrite /tag/sel/ctl send sel toggle }
key $MODKEY-space || fn $key { wmiir xwrite /tag/sel/ctl select toggle }
key $MODKEY-Shift-space || fn $key { wmiir xwrite /tag/sel/ctl send sel toggle }
key $MODKEY-d || fn $key { wmiir xwrite /tag/sel/ctl colmode sel default }
key $MODKEY-s || fn $key { wmiir xwrite /tag/sel/ctl colmode sel stack }
key $MODKEY-m || fn $key { wmiir xwrite /tag/sel/ctl colmode sel max }
fn Key-$MODKEY-d { wmiir xwrite /tag/sel/ctl colmode sel default }
fn Key-$MODKEY-s { wmiir xwrite /tag/sel/ctl colmode sel stack }
fn Key-$MODKEY-m { wmiir xwrite /tag/sel/ctl colmode sel max }
key $MODKEY-Shift-c || fn $key { wmiir xwrite /client/sel/ctl kill }
fn Key-$MODKEY-Shift-c { wmiir xwrite /client/sel/ctl kill }
key $MODKEY-a || fn $key { Action `{actionlist | wmiimenu} & }
key $MODKEY-p || fn $key { ifs=() { run_command `{wmiimenu <$progs_file} & } }
key $MODKEY-Return || fn $key { run_command $WMII_TERM & }
fn Key-$MODKEY-a { Action `{actionlist | wmiimenu} & }
fn Key-$MODKEY-p { ifs=() { run_command `{wmiimenu <$progs_file} & } }
fn Key-$MODKEY-Return { run_command $WMII_TERM & }
fn Key-$MODKEY-t { wmiir xwrite /ctl view `{read_tags | wmiimenu} & }
fn Key-$MODKEY-Shift-t {
wmiir xwrite /client/`{wmiir read /client/sel/ctl|sed 1q}^/tags `{read_tags | wmiimenu} &
key $MODKEY-t || fn $key { wmiir xwrite /ctl view `{read_tags | wmiimenu} & }
key $MODKEY-Shift-t || fn $key {
sel = `{wmiir read /client/sel/ctl | sed 1q} \
wmiir xwrite /client/$sel/tags `{read_tags | wmiimenu} &
}
fn Key-$MODKEY-^`{seq 0 9} { wmiir xwrite /ctl view `{echo $1 | sed 's/.*-//'} }
fn Key-Shift-$MODKEY-^`{seq 0 9} { wmiir xwrite /client/sel/tags `{echo $1 | sed 's/.*-//'} }
key $MODKEY-^`{seq 0 9}|| fn $key { wmiir xwrite /ctl view `{echo $1 | sed 's/.*-//'} }
key Shift-$MODKEY-^`{seq 0 9} || fn $key {
wmiir xwrite /client/sel/tags `{echo $1 | sed 's/.*-//'}
}
# WM Configuration
wmiir write /ctl <<!
@ -242,9 +246,9 @@ if not
. `{config_whatis overridekeys}
# Misc Setup
Action status
progs_file=$WMII_NS_DIR/proglist.$pid
proglist $PATH >$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 </dev/null

View File

@ -142,7 +142,7 @@ Event ClientMouseDown {
cmp := {~ $lastcmd $*}
if {$cmp Nop} {
} {$cmp Delete} { echo kill >/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} & }

View File

@ -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=$?

View File

@ -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=$?