doesn't seem worthwhile avoiding it.
optind = 1; /* for subsequent getopt calls */
/* accumulate command args */
while(n < argc) {
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]);
fatal(0, "unknown command '%s'", argv[n]);
if(n + commands[i].min >= argc)
fatal(0, "missing arguments to '%s'", argv[n]);
/*
* This file is part of DisOrder
/*
* 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
*
* 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
int n;
if(!(pb = (GdkPixbuf *)cache_get(&image_cache_type, 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);
/* Use the built-in copy */
if(!(pb = gdk_pixbuf_new_from_inline(-1, images[n].data, FALSE, &err))) {
error(0, "%s", err->message);
};
for(n = 0; n < nvec; ++n) {
};
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;
error(0, "%s:%d: invalid restriction '%s'",
cs->path, cs->line, vec[n]);
return -1;
static const struct conf *find(const char *key) {
int n;
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];
}
return 0;
return &conf[n];
}
return;
}
/* TODO: do something with the time */
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;
if(n < 0) return; /* probably a future command */
vec += 2;
nvec -= 2;
}
while(*vec) {
D(("key %s value %s", vec[0], vec[1]));
}
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 {
error_handler("unknown key in queue data", u);
return -1;
} else {
int find_signal(const char *s) {
int n;
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;
}
return -1;
return signals[n].signal;
}
#ifndef TABLE_H
#define TABLE_H
#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]), \
-/* 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
*/
* Returns the index N on success or -1 if not found
* The table must be lexically sorted on FIELD
*/
/* Make sure 'action' is always set */
cgi_set("action", 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);
if(actions[n].rights) {
/* Some right or other is required */
dcgi_lookup(DCGI_RIGHTS);
continue;
if(!n)
continue;
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;
}
error(0, "%s:%d: unknown option '%s'", cs.name, cs.line, vec[0]);
continue;
}
int n;
/* Look up the action */
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;
if(n < 0) {
error(0, "scheduled event %s: unrecognized action '%s'", id, action);
return -1;
sink_writes(ev_writer_sink(c->w), "500 do what?\n");
return 1;
}
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
sink_writes(ev_writer_sink(c->w), "500 unknown command\n");
else {
if(commands[n].rights