From ba937f0119d6102d2af9cc777cce495e65544952 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 25 May 2008 14:52:24 +0100 Subject: [PATCH] TABLE_FIND() now uses typeof. We're committed to GCC anyway so it doesn't seem worthwhile avoiding it. Organization: Straylight/Edgeware From: Richard Kettlewell --- clients/disorder.c | 2 +- disobedience/misc.c | 4 ++-- lib/configuration.c | 4 ++-- lib/eclient.c | 2 +- lib/queue.c | 2 +- lib/signame.c | 2 +- lib/table.h | 12 ++++++------ server/actions.c | 2 +- server/options.c | 2 +- server/schedule.c | 2 +- server/server.c | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clients/disorder.c b/clients/disorder.c index 0dd71c7..1bac10b 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -755,7 +755,7 @@ int main(int argc, char **argv) { optind = 1; /* for subsequent getopt calls */ /* accumulate command args */ while(n < argc) { - if((i = TABLE_FIND(commands, struct command, name, argv[n])) < 0) + if((i = TABLE_FIND(commands, name, argv[n])) < 0) fatal(0, "unknown command '%s'", argv[n]); if(n + commands[i].min >= argc) fatal(0, "missing arguments to '%s'", argv[n]); diff --git a/disobedience/misc.c b/disobedience/misc.c index 1e5ee22..da0db60 100644 --- a/disobedience/misc.c +++ b/disobedience/misc.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder - * Copyright (C) 2006, 2007 Richard Kettlewell + * Copyright (C) 2006-2008 Richard Kettlewell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -109,7 +109,7 @@ GdkPixbuf *find_image(const char *name) { int n; if(!(pb = (GdkPixbuf *)cache_get(&image_cache_type, name))) { - if((n = TABLE_FIND(images, struct image, name, name)) >= 0) { + if((n = TABLE_FIND(images, name, name)) >= 0) { /* Use the built-in copy */ if(!(pb = gdk_pixbuf_new_from_inline(-1, images[n].data, FALSE, &err))) { error(0, "%s", err->message); diff --git a/lib/configuration.c b/lib/configuration.c index 5c1d4ce..ca7d86e 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -311,7 +311,7 @@ static int set_restrict(const struct config_state *cs, }; for(n = 0; n < nvec; ++n) { - if((i = TABLE_FIND(restrictions, struct restriction, name, vec[n])) < 0) { + if((i = TABLE_FIND(restrictions, name, vec[n])) < 0) { error(0, "%s:%d: invalid restriction '%s'", cs->path, cs->line, vec[n]); return -1; @@ -986,7 +986,7 @@ static const struct conf conf[] = { static const struct conf *find(const char *key) { int n; - if((n = TABLE_FIND(conf, struct conf, name, key)) < 0) + if((n = TABLE_FIND(conf, name, key)) < 0) return 0; return &conf[n]; } diff --git a/lib/eclient.c b/lib/eclient.c index a8ca322..941849c 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -1404,7 +1404,7 @@ static void logline(disorder_eclient *c, const char *line) { return; } /* TODO: do something with the time */ - n = TABLE_FIND(logentry_handlers, struct logentry_handler, name, vec[1]); + n = TABLE_FIND(logentry_handlers, name, vec[1]); if(n < 0) return; /* probably a future command */ vec += 2; nvec -= 2; diff --git a/lib/queue.c b/lib/queue.c index 2b10f7a..a98bec1 100644 --- a/lib/queue.c +++ b/lib/queue.c @@ -177,7 +177,7 @@ int queue_unmarshall_vec(struct queue_entry *q, int nvec, char **vec, } while(*vec) { D(("key %s value %s", vec[0], vec[1])); - if((n = TABLE_FIND(fields, struct field, name, *vec)) < 0) { + if((n = TABLE_FIND(fields, name, *vec)) < 0) { error_handler("unknown key in queue data", u); return -1; } else { diff --git a/lib/signame.c b/lib/signame.c index 85e79c2..cc1b339 100644 --- a/lib/signame.c +++ b/lib/signame.c @@ -138,7 +138,7 @@ static const struct sigtable { int find_signal(const char *s) { int n; - if((n = TABLE_FIND(signals, struct sigtable, name, s)) < 0) + if((n = TABLE_FIND(signals, name, s)) < 0) return -1; return signals[n].signal; } diff --git a/lib/table.h b/lib/table.h index 11215bb..8cdfcfd 100644 --- a/lib/table.h +++ b/lib/table.h @@ -21,13 +21,13 @@ #ifndef TABLE_H #define TABLE_H -#define TABLE_FIND(TABLE, TYPE, FIELD, NAME) \ - table_find((void *)TABLE, \ - offsetof(TYPE, FIELD), \ - sizeof (TYPE), \ - sizeof TABLE / sizeof (TYPE), \ +#define TABLE_FIND(TABLE, FIELD, NAME) \ + table_find((void *)TABLE, \ + offsetof(typeof((TABLE)[0]), FIELD), \ + sizeof ((TABLE)[0]), \ + sizeof TABLE / sizeof ((TABLE)[0]), \ NAME) -/* Search TYPE TABLE[] for an element where TABLE[N].FIELD matches NAME +/* Search TABLE[] for an element where TABLE[N].FIELD matches NAME * Returns the index N on success or -1 if not found * The table must be lexically sorted on FIELD */ diff --git a/server/actions.c b/server/actions.c index 2468b77..e9995b9 100644 --- a/server/actions.c +++ b/server/actions.c @@ -775,7 +775,7 @@ void dcgi_action(const char *action) { /* Make sure 'action' is always set */ cgi_set("action", action); } - if((n = TABLE_FIND(actions, struct action, name, action)) >= 0) { + if((n = TABLE_FIND(actions, name, action)) >= 0) { if(actions[n].rights) { /* Some right or other is required */ dcgi_lookup(DCGI_RIGHTS); diff --git a/server/options.c b/server/options.c index 68f8271..0e4a1d5 100644 --- a/server/options.c +++ b/server/options.c @@ -95,7 +95,7 @@ static void option__readfile(const char *name) { continue; if(!n) continue; - if((i = TABLE_FIND(options, struct option, name, vec[0])) == -1) { + if((i = TABLE_FIND(options, name, vec[0])) == -1) { error(0, "%s:%d: unknown option '%s'", cs.name, cs.line, vec[0]); continue; } diff --git a/server/schedule.c b/server/schedule.c index a932f2d..4f0b34e 100644 --- a/server/schedule.c +++ b/server/schedule.c @@ -454,7 +454,7 @@ static int schedule_lookup(const char *id, int n; /* Look up the action */ - n = TABLE_FIND(schedule_actions, typeof(schedule_actions[0]), name, action); + n = TABLE_FIND(schedule_actions, name, action); if(n < 0) { error(0, "scheduled event %s: unrecognized action '%s'", id, action); return -1; diff --git a/server/server.c b/server/server.c index 5df2d33..527255e 100644 --- a/server/server.c +++ b/server/server.c @@ -1711,7 +1711,7 @@ static int command(struct conn *c, char *line) { sink_writes(ev_writer_sink(c->w), "500 do what?\n"); return 1; } - if((n = TABLE_FIND(commands, struct command, name, vec[0])) < 0) + if((n = TABLE_FIND(commands, name, vec[0])) < 0) sink_writes(ev_writer_sink(c->w), "500 unknown command\n"); else { if(commands[n].rights -- [mdw]