mirror of
https://github.com/0intro/wmii
synced 2024-12-26 21:29:45 +03:00
drastic reduction of ugly #define's
This commit is contained in:
parent
bcec7933d8
commit
83834ba9b3
42
cmd/wm/fs.c
42
cmd/wm/fs.c
@ -27,7 +27,7 @@ static char Enofunc[] = "function not supported";
|
||||
static char Enocommand[] = "command not supported";
|
||||
static char Ebadvalue[] = "bad value";
|
||||
|
||||
#define WMII_IOUNIT 2048
|
||||
enum { WMII_IOUNIT = 2048 };
|
||||
|
||||
/*
|
||||
* filesystem specification
|
||||
@ -464,20 +464,20 @@ type2stat(Stat *stat, char *wname, Qid *dir)
|
||||
case FsDclients:
|
||||
case FsDlabel:
|
||||
case FsDroot:
|
||||
return mkstat(stat, dir, wname, 0, DMDIR | DMREAD | DMEXEC);
|
||||
return mkstat(stat, dir, wname, 0, IXP_DMDIR | IXP_DMREAD | IXP_DMEXEC);
|
||||
break;
|
||||
case FsDbar:
|
||||
return mkstat(stat, dir, wname, 0, DMDIR | DMREAD | DMWRITE | DMEXEC);
|
||||
return mkstat(stat, dir, wname, 0, IXP_DMDIR | IXP_DMREAD | IXP_DMWRITE | IXP_DMEXEC);
|
||||
break;
|
||||
case FsFctl:
|
||||
return mkstat(stat, dir, wname, 0, DMWRITE);
|
||||
return mkstat(stat, dir, wname, 0, IXP_DMWRITE);
|
||||
break;
|
||||
case FsFevent:
|
||||
return mkstat(stat, dir, wname, 0, DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, 0, IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFborder:
|
||||
snprintf(buf, sizeof(buf), "%d", def.border);
|
||||
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFgeom:
|
||||
if(dir_type == FsDclient) {
|
||||
@ -490,68 +490,68 @@ type2stat(Stat *stat, char *wname, Qid *dir)
|
||||
snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y,
|
||||
c->rect.width, c->rect.height);
|
||||
}
|
||||
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFclass:
|
||||
if(dir_type == FsDclient) {
|
||||
f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3];
|
||||
return mkstat(stat, dir, wname, strlen(f->client->classinst), DMREAD);
|
||||
return mkstat(stat, dir, wname, strlen(f->client->classinst), IXP_DMREAD);
|
||||
}
|
||||
else
|
||||
return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->classinst), DMREAD);
|
||||
return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->classinst), IXP_DMREAD);
|
||||
break;
|
||||
case FsFname:
|
||||
if(dir_type == FsDclient) {
|
||||
f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3];
|
||||
return mkstat(stat, dir, wname, strlen(f->client->name), DMREAD);
|
||||
return mkstat(stat, dir, wname, strlen(f->client->name), IXP_DMREAD);
|
||||
}
|
||||
else
|
||||
return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->name), DMREAD);
|
||||
return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->name), IXP_DMREAD);
|
||||
break;
|
||||
case FsFtags:
|
||||
switch(dir_type) {
|
||||
case FsDclient:
|
||||
f = view.data[dir_i1]->area.data[dir_i2]->frame.data[dir_i3];
|
||||
tags2str(buf, sizeof(buf), f->client->tag, f->client->ntag);
|
||||
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsDGclient:
|
||||
tags2str(buf, sizeof(buf), client.data[dir_i1]->tag, client.data[dir_i1]->ntag);
|
||||
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unsigned int i, len = 0;
|
||||
for(i = 0; i < tag.size; i++)
|
||||
len += strlen(tag.data[i]) + 1;
|
||||
return mkstat(stat, dir, wname, len, DMREAD);
|
||||
return mkstat(stat, dir, wname, len, IXP_DMREAD);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case FsFtag:
|
||||
if(dir_type == FsDview)
|
||||
return mkstat(stat, dir, wname, strlen(def.tag), DMREAD);
|
||||
return mkstat(stat, dir, wname, strlen(def.tag), IXP_DMREAD);
|
||||
break;
|
||||
case FsFdata:
|
||||
return mkstat(stat, dir, wname, (dir_i1 == label.size) ? 0 : strlen(label.data[dir_i1]->data), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, (dir_i1 == label.size) ? 0 : strlen(label.data[dir_i1]->data), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFmode:
|
||||
return mkstat(stat, dir, wname, strlen(mode2str(view.data[dir_i1]->area.data[dir_i2]->mode)), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(mode2str(view.data[dir_i1]->area.data[dir_i2]->mode)), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFcolors:
|
||||
case FsFselcolors:
|
||||
case FsFnormcolors:
|
||||
return mkstat(stat, dir, wname, 23, DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, 23, IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFkeys:
|
||||
return mkstat(stat, dir, wname, def.keys ? strlen(def.keys) : 0, DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, def.keys ? strlen(def.keys) : 0, IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFrules:
|
||||
return mkstat(stat, dir, wname, def.rules ? strlen(def.rules) : 0, DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, def.rules ? strlen(def.rules) : 0, IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
case FsFfont:
|
||||
return mkstat(stat, dir, wname, strlen(def.font), DMREAD | DMWRITE);
|
||||
return mkstat(stat, dir, wname, strlen(def.font), IXP_DMREAD | IXP_DMWRITE);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
45
cmd/wm/wm.h
45
cmd/wm/wm.h
@ -63,17 +63,21 @@ enum {
|
||||
FsFmode
|
||||
};
|
||||
|
||||
#define MAX_TAGS 8
|
||||
#define MAX_TAGLEN 32
|
||||
#define WM_PROTOCOL_DELWIN 1
|
||||
#define MIN_COLWIDTH 64
|
||||
enum { MAX_TAGS = 8 };
|
||||
enum { MAX_TAGLEN = 32 };
|
||||
enum { MIN_COLWIDTH = 64 };
|
||||
enum { WM_PROTOCOL_DELWIN = 1 };
|
||||
|
||||
typedef struct View View;
|
||||
typedef struct Area Area;
|
||||
typedef struct Frame Frame;
|
||||
typedef struct Client Client;
|
||||
|
||||
VECTOR(AreaVector, Area *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
Area **data;
|
||||
} AreaVector;
|
||||
|
||||
struct View {
|
||||
char name[MAX_TAGLEN];
|
||||
unsigned short id;
|
||||
@ -82,7 +86,11 @@ struct View {
|
||||
unsigned int revert;
|
||||
};
|
||||
|
||||
VECTOR(FrameVector, Frame *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
Frame **data;
|
||||
} FrameVector;
|
||||
|
||||
struct Area {
|
||||
unsigned short id;
|
||||
FrameVector frame;
|
||||
@ -155,20 +163,35 @@ typedef struct {
|
||||
} Default;
|
||||
|
||||
/* global variables */
|
||||
VECTOR(ViewVector, View *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
View **data;
|
||||
} ViewVector;
|
||||
ViewVector view;
|
||||
unsigned int sel;
|
||||
|
||||
VECTOR(ClientVector, Client *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
Client **data;
|
||||
} ClientVector;
|
||||
ClientVector client;
|
||||
|
||||
VECTOR(KeyVector, Key *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
Key **data;
|
||||
} KeyVector;
|
||||
KeyVector key;
|
||||
|
||||
VECTOR(LabelVector, Label *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
Label **data;
|
||||
} LabelVector;
|
||||
LabelVector label;
|
||||
|
||||
VECTOR(TagVector, char *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
char **data;
|
||||
} TagVector;
|
||||
TagVector tag;
|
||||
|
||||
Display *dpy;
|
||||
|
@ -31,7 +31,11 @@ static Window win;
|
||||
static XRectangle mrect;
|
||||
static int screen;
|
||||
|
||||
VECTOR(ItemVector, char *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
char **data;
|
||||
} ItemVector;
|
||||
|
||||
static ItemVector allitem = {0};
|
||||
static ItemVector item = {0};
|
||||
|
||||
|
@ -57,7 +57,7 @@ xcreate(char *file)
|
||||
return -1;
|
||||
}
|
||||
p++;
|
||||
if(ixp_client_create(&c, fid, p, DMWRITE, IXP_OWRITE) == -1) {
|
||||
if(ixp_client_create(&c, fid, p, IXP_DMWRITE, IXP_OWRITE) == -1) {
|
||||
fprintf(stderr, "wmiir: cannot create file '%s': %s\n", p, c.errstr);
|
||||
return -1;
|
||||
}
|
||||
@ -107,7 +107,7 @@ mode2str(unsigned int mode)
|
||||
{
|
||||
static char buf[16];
|
||||
|
||||
if(mode & DMDIR)
|
||||
if(mode & IXP_DMDIR)
|
||||
buf[0]='d';
|
||||
else
|
||||
buf[0]='-';
|
||||
|
@ -29,13 +29,10 @@ long long cext_strtonum(const char *numstr, long long minval,
|
||||
unsigned int cext_tokenize(char **result, unsigned int reslen, char *str, char delim);
|
||||
|
||||
/* vector.c */
|
||||
#define VECTOR(name, type) \
|
||||
typedef struct { \
|
||||
unsigned int size; \
|
||||
type *data; \
|
||||
} name
|
||||
|
||||
VECTOR(Vector, void*);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
void **data;
|
||||
} Vector;
|
||||
|
||||
void cext_vattach(Vector *v, void *p);
|
||||
void cext_vdetach(Vector *v, void *p);
|
||||
|
@ -19,9 +19,11 @@
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define INVALID 1
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
enum {
|
||||
INVALID = 1,
|
||||
TOOSMALL = 2,
|
||||
TOOLARGE = 3
|
||||
};
|
||||
|
||||
long long
|
||||
cext_strtonum(const char *numstr, long long minval, long long maxval,
|
||||
|
57
libixp/ixp.h
57
libixp/ixp.h
@ -6,18 +6,17 @@
|
||||
#include <sys/types.h>
|
||||
#include <cext.h>
|
||||
|
||||
#define IXP_VERSION "9P2000"
|
||||
#define IXP_MAX_VERSION 32
|
||||
#define IXP_MAX_ERROR 128
|
||||
#define IXP_MAX_CACHE 32
|
||||
#define IXP_MAX_MSG 8192
|
||||
#define IXP_MAX_FLEN 128
|
||||
#define IXP_MAX_ULEN 32
|
||||
#define IXP_MAX_STAT 64
|
||||
#define IXP_MAX_WELEM 16 /* MAXWELEM */
|
||||
#define IXP_MAX_TFUNCS 14
|
||||
#define IXP_VERSION "9P2000"
|
||||
#define IXP_NOTAG (unsigned short)~0U /*Dummy tag */
|
||||
#define IXP_NOFID (unsigned int)~0 /*No auth */
|
||||
|
||||
#define IXP_PORT 5640
|
||||
enum { IXP_MAX_VERSION = 32 };
|
||||
enum { IXP_MAX_ERROR = 128 };
|
||||
enum { IXP_MAX_CACHE = 32 };
|
||||
enum { IXP_MAX_MSG = 8192 };
|
||||
enum { IXP_MAX_FLEN = 128 };
|
||||
enum { IXP_MAX_ULEN = 32 };
|
||||
enum { IXP_MAX_WELEM = 16 };
|
||||
|
||||
/* 9P message types */
|
||||
enum {
|
||||
@ -52,16 +51,17 @@ enum {
|
||||
};
|
||||
|
||||
/* borrowed from libc.h of Plan 9 */
|
||||
#define DMDIR 0x80000000 /*mode bit for directories */
|
||||
#define DMAPPEND 0x40000000 /*mode bit for append only files */
|
||||
#define DMEXCL 0x20000000 /*mode bit for exclusive use files */
|
||||
#define DMMOUNT 0x10000000 /*mode bit for mounted channel */
|
||||
#define DMAUTH 0x08000000 /*mode bit for authentication file */
|
||||
#define DMTMP 0x04000000 /*mode bit for non-backed-up file */
|
||||
|
||||
#define DMREAD 0x4<<6 /*mode bit for read permission */
|
||||
#define DMWRITE 0x2<<6 /*mode bit for write permission */
|
||||
#define DMEXEC 0x1<<6 /*mode bit for execute permission */
|
||||
enum {
|
||||
IXP_DMDIR = 0x80000000, /* mode bit for directories */
|
||||
IXP_DMAPPEND = 0x40000000, /* mode bit for append only files */
|
||||
IXP_DMEXCL = 0x20000000, /* mode bit for exclusive use files */
|
||||
IXP_DMMOUNT = 0x10000000, /* mode bit for mounted channel */
|
||||
IXP_DMAUTH = 0x08000000, /* mode bit for authentication file */
|
||||
IXP_DMTMP = 0x04000000, /* mode bit for non-backed-up file */
|
||||
IXP_DMREAD = 0x4<<6, /* mode bit for read permission */
|
||||
IXP_DMWRITE = 0x2<<6, /* mode bit for write permission */
|
||||
IXP_DMEXEC = 0x1<<6 /* mode bit for execute permission */
|
||||
};
|
||||
|
||||
/* modes */
|
||||
enum {
|
||||
@ -89,9 +89,6 @@ enum {
|
||||
IXP_QTFILE = 0x00,
|
||||
};
|
||||
|
||||
#define IXP_NOTAG (unsigned short)~0U /*Dummy tag */
|
||||
#define IXP_NOFID (unsigned int)~0 /*No auth */
|
||||
|
||||
typedef struct Qid Qid;
|
||||
struct Qid {
|
||||
unsigned char type;
|
||||
@ -155,7 +152,11 @@ struct IXPMap {
|
||||
};
|
||||
|
||||
|
||||
VECTOR(MapVector, IXPMap *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
IXPMap **data;
|
||||
} MapVector;
|
||||
|
||||
struct IXPConn {
|
||||
int fd;
|
||||
IXPServer *srv;
|
||||
@ -166,7 +167,11 @@ struct IXPConn {
|
||||
int is_pending;
|
||||
};
|
||||
|
||||
VECTOR(ConnVector, IXPConn *);
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
IXPConn **data;
|
||||
} ConnVector;
|
||||
|
||||
struct IXPServer {
|
||||
int running;
|
||||
ConnVector conn;
|
||||
|
@ -49,12 +49,10 @@ connect_inet_sock(char *host)
|
||||
unsigned int prt;
|
||||
|
||||
if(!port)
|
||||
prt = IXP_PORT;
|
||||
else {
|
||||
*port = 0;
|
||||
port++;
|
||||
prt = cext_strtonum(port, 0, 65535, &errstr);
|
||||
}
|
||||
return -1;
|
||||
*port = 0;
|
||||
port++;
|
||||
prt = cext_strtonum(port, 0, 65535, &errstr);
|
||||
|
||||
if(errstr)
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user