+#define MAX_CLASSES 16
+static bool all_enabled;
+static const char *enabled_classes[MAX_CLASSES];
+static size_t enabled_cnt;
+
+/* Enables the debug message classes specified in CLASSES. The
+ string CLASSES is modified by and becomes owned by this
+ function. */
+void
+debug_enable (char *classes)
+{
+ char *class, *save;
+
+ for (class = strtok_r (classes, ",", &save); class != NULL;
+ class = strtok_r (NULL, ",", &save))
+ {
+ if (strcmp (class, "all") && enabled_cnt < MAX_CLASSES)
+ enabled_classes[enabled_cnt++] = class;
+ else
+ all_enabled = true;
+ }
+}
+
+/* Checks whether CLASS is enabled. */
+static bool
+class_is_enabled (const char *class)
+{
+ size_t i;
+
+ if (all_enabled)
+ return true;
+
+ for (i = 0; i < enabled_cnt; i++)
+ if (!strcmp (enabled_classes[i], class))
+ return true;
+
+ return false;
+}
+
+/* Prints a debug message along with the source file name, line
+ number, and function name of where it was emitted. CLASS is
+ used to filter out unwanted messages. */