chiark / gitweb /
TABLE_FIND() now uses typeof. We're committed to GCC anyway so it
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 25 May 2008 13:52:24 +0000 (14:52 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 25 May 2008 13:52:24 +0000 (14:52 +0100)
doesn't seem worthwhile avoiding it.

clients/disorder.c
disobedience/misc.c
lib/configuration.c
lib/eclient.c
lib/queue.c
lib/signame.c
lib/table.h
server/actions.c
server/options.c
server/schedule.c
server/server.c

index 0dd71c74eb3cfa700f7b420dfc1087175dd5a7e9..1bac10b125dac329fa7e377d956ba4549361303b 100644 (file)
@@ -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]);
index 1e5ee22c3c720ed965ef50105e5f2ebe707c05b4..da0db603e3f9769c9cef65b23cfea8050ef0b29b 100644 (file)
@@ -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);
index 5c1d4cef429720f80472dc07bf944929fda9d9f0..ca7d86e7dd4cc22d2d7b6e993616f61ac4d72096 100644 (file)
@@ -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];
 }
index a8ca322e071bed886259f8d26d74e5f663713516..941849c7502f1ec51b96f40644fee5943e158831 100644 (file)
@@ -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;
index 2b10f7a2264636a21461b6ab86f7ba6ea4060207..a98bec135bb0ca2b8bea9fb1795bb3fb3543e310 100644 (file)
@@ -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 {
index 85e79c232454cbd7738a8de7e1dc210fd83219bd..cc1b339fe548c2f0811992b24b92ec567d9b279a 100644 (file)
@@ -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;
 }
index 11215bb0bd0efd6f215fa4592cf68edce5d971a1..8cdfcfd985707602cfae7c7cc292dcebef9e5042 100644 (file)
 #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
  */
index 2468b77ad1837dd7895bb523737d551b7851021d..e9995b9665ad7a9be6fde4def2d4264aeecfb7f1 100644 (file)
@@ -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);
index 68f827157726d74d2c3229764a2a15bc8cd9048d..0e4a1d585e0e08b0326499d14a8577434e3989eb 100644 (file)
@@ -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;
     }
index a932f2d4139db9529e38ec8b02a7ac2bd31f8814..4f0b34e7de8a18e271b3e2e7fd64d47f77e4ff2f 100644 (file)
@@ -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;
index 5df2d330a611c1b42e8f2c756177cad9fd10624a..527255e571de8a85fc5b72c8479a45cfabf63295 100644 (file)
@@ -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