Typedef bt_intern_str
[babeltrace.git] / formats / registry.c
index a6fd74b2bc5d3432ba0dae10eb0784753607e411..829ede9da77bf12dce5da544e3ea0bb3538a8049 100644 (file)
@@ -3,7 +3,9 @@
  *
  * Format Registry
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
 #include <glib.h>
 #include <errno.h>
 #include <stdio.h>
+#include <assert.h>
+
+struct walk_data {
+       FILE *fp;
+       int iter;
+};
 
 static int init_done;
 void __attribute__((constructor)) format_init(void);
@@ -32,29 +40,37 @@ void __attribute__((destructor)) format_finalize(void);
  */
 GHashTable *format_registry;
 
-struct format *bt_lookup_format(GQuark qname)
+struct format *bt_lookup_format(bt_intern_str name)
 {
        if (!init_done)
                return NULL;
        return g_hash_table_lookup(format_registry,
-                                  (gconstpointer) (unsigned long) qname);
+                                  (gconstpointer) (unsigned long) name);
 }
 
 static void show_format(gpointer key, gpointer value, gpointer user_data)
 {
-       FILE *fp = user_data;
+       struct walk_data *data = user_data;
 
-       fprintf(fp, "format: %s\n",
+       fprintf(data->fp, "%s%s", data->iter ? ", " : "",
                g_quark_to_string((GQuark) (unsigned long) key));
+       data->iter++;
 }
 
 void bt_fprintf_format_list(FILE *fp)
 {
-       fprintf(fp, "Formats available:\n");
+       struct walk_data data;
+
+       data.fp = fp;
+       data.iter = 0;
+
+       fprintf(fp, "Formats available: ");
        if (!init_done)
                return;
-       g_hash_table_foreach(format_registry, show_format, fp);
-       fprintf(fp, "End of formats available.\n");
+       g_hash_table_foreach(format_registry, show_format, &data);
+       if (data.iter == 0)
+               fprintf(fp, "<none>");
+       fprintf(fp, ".\n");
 }
 
 int bt_register_format(struct format *format)
This page took 0.025284 seconds and 4 git commands to generate.