]> git.ozlabs.org Git - petitboot/blobdiff - discover/parser.c
Fix params.c build warnings
[petitboot] / discover / parser.c
index 5b1a7abdab600656bc803721bef66f07bdcc9b88..8f2735ccc6553b3d00bdc575b5debdd7b7203a3a 100644 (file)
@@ -2,29 +2,45 @@
 #include <stdlib.h>
 
 #include "pb-protocol/pb-protocol.h"
 #include <stdlib.h>
 
 #include "pb-protocol/pb-protocol.h"
+#include <log/log.h>
 
 #include "device-handler.h"
 
 #include "device-handler.h"
-#include "log.h"
 #include "parser.h"
 #include "parser.h"
-extern struct parser kboot_parser;
+#include "parser-utils.h"
 
 
-/* array of parsers, ordered by priority */
-static struct parser *parsers[] = {
-       &kboot_parser,
-       NULL
-};
+extern struct parser __start_parsers[], __stop_parsers[];
 
 void iterate_parsers(struct discover_context *ctx)
 {
 
 void iterate_parsers(struct discover_context *ctx)
 {
-       int i;
+       struct parser *parser;
+       unsigned int count = 0;
 
        pb_log("trying parsers for %s\n", ctx->device_path);
 
 
        pb_log("trying parsers for %s\n", ctx->device_path);
 
-       for (i = 0; parsers[i]; i++) {
-               pb_log("\ttrying parser '%s'\n", parsers[i]->name);
-               /* just use a dummy device path for now */
-               if (parsers[i]->parse(ctx))
-                       return;
+       for (parser = __start_parsers; parser < __stop_parsers; parser++) {
+               pb_log("\ttrying parser '%s'\n", parser->name);
+               count += parser->parse(ctx);
        }
        }
-       pb_log("\tno boot_options found\n");
+       if (!count)
+               pb_log("\tno boot_options found\n");
+}
+
+static int compare_parsers(const void *a, const void *b)
+{
+       const struct parser *parser_a = a, *parser_b = b;
+
+       if (parser_a->priority > parser_b->priority)
+               return -1;
+
+       if (parser_a->priority < parser_b->priority)
+               return 1;
+
+       return 0;
+}
+
+void parser_init(void)
+{
+       /* sort our parsers into descending priority order */
+       qsort(__start_parsers, __stop_parsers - __start_parsers,
+                       sizeof(struct parser), compare_parsers);
 }
 }