+/*
+ * Macros to use when declaring struct swit arrays.
+ *
+ * These macros are what known as X-Macros. In your source code you
+ * use them like this:
+ *
+ * #define FOO_SWITCHES \
+ * X("switch1", 0, SWITCHSW) \
+ * X("switch2", 0, SWITCH2SW) \
+ * X("thirdswitch", 2, SWITCH3SW) \
+ *
+ * The argument to each entry in FOO_SWITCHES are the switch name (sw),
+ * the minchars field (see above) and the return value for this switch.
+ *
+ * After you define FOO_SWITCHES, you instantiate it as follows:
+ *
+ * #define X(sw, minchars, id) id,
+ * DEFINE_SWITCH_ENUM(FOO);
+ * #undef X
+ *
+ * #define X(sw, minchars, id) { sw, minchars, id },
+ * DEFINE_SWITCH_ARRAY(FOO);
+ * #undef X
+ *
+ * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
+ * LEN_FOO.
+ */
+
+#define DEFINE_SWITCH_ENUM(name) \
+ enum { \
+ name ## _SWITCHES \
+ LEN_ ## name \
+ }
+
+#define DEFINE_SWITCH_ARRAY(name, array) \
+ static struct swit array[] = { \
+ name ## _SWITCHES \
+ { NULL, 0, 0 } \
+ }
+