commit ede385c313709d3dd018babd7381b52be6c18cf6
parent 230491250a1447df219efb3f069a5c3fe524fc74
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Mon, 3 Apr 2006 13:40:34 +0200
made the style more concise, s/evector_t/Vector/g, evector.c -> vector.c, s/foo_vec_t/FooVector/g, etc
Diffstat:
11 files changed, 97 insertions(+), 114 deletions(-)
diff --git a/cmd/wm/area.c b/cmd/wm/area.c
@@ -8,12 +8,10 @@
#include "wm.h"
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-area_to_evector(area_vec_t *view)
+static Vector *
+area2vector(AreaVector *av)
{
- return (evector_t *) view;
+ return (Vector *) av;
}
Area *
@@ -25,7 +23,7 @@ alloc_area(View *v)
a->id = id++;
a->rect = rect;
a->rect.height = rect.height - brect.height;
- cext_evector_attach(area_to_evector(&v->area), a);
+ cext_vattach(area2vector(&v->area), a);
v->sel = v->area.size -1;
return a;
}
@@ -44,7 +42,7 @@ destroy_area(Area *a)
for(i = 0; i < client.size; i++)
if(client.data[i]->revert == a)
client.data[i]->revert = 0;
- cext_evector_detach(area_to_evector(&v->area), a);
+ cext_vdetach(area2vector(&v->area), a);
if(v->sel > 1)
v->sel--;
free(a);
@@ -133,12 +131,10 @@ send2area(Area *to, Area *from, Client *c)
focus_client(c);
}
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-frame_to_evector(frame_vec_t *view)
+static Vector *
+frame2vector(FrameVector *fv)
{
- return (evector_t *) view;
+ return (Vector *) fv;
}
void
@@ -157,9 +153,9 @@ attach_toarea(Area *a, Client *c)
f->rect = c->rect;
f->rect.width += 2 * def.border;
f->rect.height += def.border + bar_height();
- cext_evector_attach(frame_to_evector(&c->frame), f);
+ cext_vattach(frame2vector(&c->frame), f);
c->sel = c->frame.size - 1;
- cext_evector_attach(frame_to_evector(&a->frame),f);
+ cext_vattach(frame2vector(&a->frame),f);
a->sel = a->frame.size - 1;
if(area2index(a)) /* column */
arrange_column(a);
@@ -180,8 +176,8 @@ detach_fromarea(Area *a, Client *c)
break;
}
- cext_evector_detach(frame_to_evector(&c->frame), f);
- cext_evector_detach(frame_to_evector(&a->frame), f);
+ cext_vdetach(frame2vector(&c->frame), f);
+ cext_vdetach(frame2vector(&a->frame), f);
free(f);
if(c->sel > 0)
c->sel--;
diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c
@@ -42,12 +42,10 @@ comp_label_name(const void *l1, const void *l2)
return strcmp(ll1->name, ll2->name);
}
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-label_to_evector(label_vec_t *view)
+static Vector *
+label2vector(LabelVector *lv)
{
- return (evector_t *) view;
+ return (Vector *) lv;
}
Label *
@@ -64,7 +62,7 @@ get_label(char *name, Bool intern)
cext_strlcpy(l->name, name, sizeof(l->name));
cext_strlcpy(l->colstr, def.selcolor, sizeof(l->colstr));
l->color = def.sel;
- cext_evector_attach(label_to_evector(&label), l);
+ cext_vattach(label2vector(&label), l);
qsort(label.data, label.size, sizeof(Label *), comp_label_name);
qsort(label.data, label.size, sizeof(Label *), comp_label_intern);
@@ -74,7 +72,7 @@ get_label(char *name, Bool intern)
void
destroy_label(Label *l)
{
- cext_evector_detach(label_to_evector(&label), l);
+ cext_vdetach(label2vector(&label), l);
}
unsigned int
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -12,12 +12,10 @@
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask)
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-client_to_evector(client_vec_t *view)
+static Vector *
+client2vector(ClientVector *cv)
{
- return (evector_t *) view;
+ return (Vector *) cv;
}
Client *
@@ -67,7 +65,7 @@ alloc_client(Window w, XWindowAttributes *wa)
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
c->gc = XCreateGC(dpy, c->framewin, 0, 0);
XSync(dpy, False);
- cext_evector_attach(client_to_evector(&client), c);
+ cext_vattach(client2vector(&client), c);
return c;
}
@@ -393,7 +391,7 @@ destroy_client(Client *c)
reparent_client(c, root, c->rect.x, c->rect.y);
XFreeGC(dpy, c->gc);
XDestroyWindow(dpy, c->framewin);
- cext_evector_detach(client_to_evector(&client), c);
+ cext_vdetach(client2vector(&client), c);
update_tags();
free(c);
diff --git a/cmd/wm/kb.c b/cmd/wm/kb.c
@@ -92,12 +92,10 @@ name2key(const char *name)
return nil;
}
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-key_to_evector(key_vec_t *view)
+static Vector *
+key2vector(KeyVector *kv)
{
- return (evector_t *) view;
+ return (Vector *) kv;
}
static Key *
@@ -136,7 +134,7 @@ get_key(const char *name)
}
if(r) {
r->id = id++;
- cext_evector_attach(key_to_evector(&key), r);
+ cext_vattach(key2vector(&key), r);
}
return r;
@@ -146,7 +144,7 @@ void
destroy_key(Key *k)
{
Key *n;
- cext_evector_detach(key_to_evector(&key), k);
+ cext_vdetach(key2vector(&key), k);
while(k) {
n = k->next;
free(k);
diff --git a/cmd/wm/tag.c b/cmd/wm/tag.c
@@ -44,20 +44,17 @@ organize_client(View *v, Client *c)
}
}
-
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-tag_to_evector(tag_vec_t *view)
+static Vector *
+tag2vector(TagVector *tv)
{
- return (evector_t *) view;
+ return (Vector *) tv;
}
void
ensure_tag(char *arg)
{
if(!istag(arg)) {
- cext_evector_attach(tag_to_evector(&tag), strdup(arg));
+ cext_vattach(tag2vector(&tag), strdup(arg));
}
}
diff --git a/cmd/wm/view.c b/cmd/wm/view.c
@@ -8,12 +8,10 @@
#include "wm.h"
-/* We expect the optimiser to remove this function, It is included to ensure type safeness.
- */
-static evector_t *
-view_to_evector(view_vec_t *view)
+static Vector *
+view2vector(ViewVector *vv)
{
- return (evector_t *) view;
+ return (Vector *) vv;
}
View *
@@ -27,7 +25,7 @@ alloc_view(char *name)
alloc_area(v);
alloc_area(v);
sel = view.size;
- cext_evector_attach(view_to_evector(&view), v);
+ cext_vattach(view2vector(&view), v);
return v;
}
@@ -37,7 +35,7 @@ destroy_view(View *v)
while(v->area.size)
destroy_area(v->area.data[0]);
- cext_evector_detach(view_to_evector(&view), v);
+ cext_vdetach(view2vector(&view), v);
if(sel >= view.size)
sel = 0;
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -73,22 +73,22 @@ typedef struct Area Area;
typedef struct Frame Frame;
typedef struct Client Client;
-EVECTOR(area_vec_t, Area*);
+EVECTOR(AreaVector, Area*);
struct View {
char tag[MAX_TAGS][MAX_TAGLEN];
unsigned int ntag;
unsigned short id;
- area_vec_t area;
+ AreaVector area;
unsigned int sel;
unsigned int revert;
};
-EVECTOR(frame_vec_t, Frame*);
+EVECTOR(FrameVector, Frame*);
struct Area {
unsigned short id;
- frame_vec_t frame;
+ FrameVector frame;
View *view;
unsigned int sel;
int mode;
@@ -117,7 +117,7 @@ struct Client {
XSizeHints size;
Window framewin;
GC gc;
- frame_vec_t frame;
+ FrameVector frame;
unsigned int sel;
Area *revert;
};
@@ -158,24 +158,21 @@ typedef struct {
} Default;
/* global variables */
-EVECTOR(view_vec_t, View*);
-view_vec_t view;
+EVECTOR(ViewVector, View*);
+ViewVector view;
unsigned int sel;
-EVECTOR(client_vec_t, Client*);
-client_vec_t client;
+EVECTOR(ClientVector, Client*);
+ClientVector client;
-EVECTOR(key_vec_t, Key*);
-key_vec_t key;
+EVECTOR(KeyVector, Key*);
+KeyVector key;
-EVECTOR(label_vec_t, Label*);
-label_vec_t label;
+EVECTOR(LabelVector, Label*);
+LabelVector label;
-EVECTOR(tag_vec_t, char *);
-tag_vec_t tag;
-//char **tag;
-//unsigned int ntag;
-//unsigned int tagsz;
+EVECTOR(TagVector, char *);
+TagVector tag;
Display *dpy;
IXPServer *ixps;
diff --git a/libcext/Makefile b/libcext/Makefile
@@ -3,7 +3,7 @@
include ../config.mk
-SRC = array.c emallocz.c estrdup.c evector.c strlcat.c strlcpy.c strtonum.c tokenize.c
+SRC = array.c emallocz.c estrdup.c strlcat.c strlcpy.c strtonum.c tokenize.c vector.c
OBJ = ${SRC:.c=.o}
diff --git a/libcext/cext.h b/libcext/cext.h
@@ -16,18 +16,6 @@ void cext_array_detach(void **array, void *p, unsigned int *size);
/* emallocz.c */
void *cext_emallocz(unsigned int size);
-/* evector.c */
-#define EVECTOR(name, type) \
-typedef struct { \
- unsigned int size; \
- type * data; \
-} name
-
-EVECTOR(evector_t, void*);
-
-void cext_evector_attach(evector_t *v, void *p);
-void cext_evector_detach(evector_t *v, void *p);
-
/* estrdup.c */
char *cext_estrdup(const char *s);
@@ -43,3 +31,16 @@ long long cext_strtonum(const char *numstr, long long minval,
/* tokenize.c */
unsigned int cext_tokenize(char **result, unsigned int reslen, char *str, char delim);
+
+/* vector.c */
+#define EVECTOR(name, type) \
+typedef struct { \
+ unsigned int size; \
+ type * data; \
+} name
+
+EVECTOR(Vector, void*);
+
+void cext_vattach(Vector *v, void *p);
+void cext_vdetach(Vector *v, void *p);
+
diff --git a/libcext/evector.c b/libcext/evector.c
@@ -1,32 +0,0 @@
-/* extendible vectors. Icarus Sparry 2006. Public domain. */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "cext.h"
-
-void
-cext_evector_attach(evector_t *v, void *p)
-{
- ++v->size;
- if (!(v->data = realloc(v->data, v->size * sizeof(void *)))) {
- fprintf(stderr, "%s\n", "Out of memory in cext_evector_attach\n");
- exit(1);
- }
- v->data[v->size - 1]=p;
-}
-
-void
-cext_evector_detach(evector_t *v, void *data)
-{
- void **p = v->data, **end;
- if (!p) return;
- for(end = p + v->size - 1; p <= end; p++)
- if (*p == data) {
- memmove(p, p + 1, end - (p + 1));
- *end = nil;
- --v->size;
- return;
- }
-}
diff --git a/libcext/vector.c b/libcext/vector.c
@@ -0,0 +1,32 @@
+/* extendible vectors. Icarus Sparry 2006. Public domain. */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "cext.h"
+
+void
+cext_vattach(Vector *v, void *p)
+{
+ ++v->size;
+ if (!(v->data = realloc(v->data, v->size * sizeof(void *)))) {
+ fprintf(stderr, "%s\n", "Out of memory in cext_evector_attach\n");
+ exit(1);
+ }
+ v->data[v->size - 1]=p;
+}
+
+void
+cext_vdetach(Vector *v, void *data)
+{
+ void **p = v->data, **end;
+ if (!p) return;
+ for(end = p + v->size - 1; p <= end; p++)
+ if (*p == data) {
+ memmove(p, p + 1, end - (p + 1));
+ *end = nil;
+ --v->size;
+ return;
+ }
+}