]> git.ozlabs.org Git - petitboot/blobdiff - devices/parser-test.c
Make kboot_parser global options array static
[petitboot] / devices / parser-test.c
index 9622d4d31463e0268207483507f1b990fddaa42c..8c94d3f899d4c2f43ea4945ae006ccd619a05065 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 
 #include "parser.h"
+#include "paths.h"
 
 void pb_log(const char *fmt, ...)
 {
@@ -17,82 +18,68 @@ void pb_log(const char *fmt, ...)
        va_end(ap);
 }
 
-
 int mount_device(const char *dev_path)
 {
-       pb_log("attempt to mount device (%s) not supported\n", dev_path);
+       printf("[mount] %s\n", dev_path);
        return 0;
 }
 
+static int device_idx;
+static int option_idx;
+
 int add_device(const struct device *dev)
 {
-       printf("device added:\n");
-       printf("\tid: %s\n", dev->id);
-       printf("\tname: %s\n", dev->name);
-       printf("\tdescription: %s\n", dev->description);
-       printf("\tboot_image: %s\n", dev->icon_file);
+       printf("[dev %2d] id: %s\n", device_idx, dev->id);
+       printf("[dev %2d] name: %s\n", device_idx, dev->name);
+       printf("[dev %2d] description: %s\n", device_idx, dev->description);
+       printf("[dev %2d] boot_image: %s\n", device_idx, dev->icon_file);
+
+       device_idx++;
+       option_idx = 0;
        return 0;
 }
 
+
 int add_boot_option(const struct boot_option *opt)
 {
-       printf("option added:\n");
-       printf("\tname: %s\n", opt->name);
-       printf("\tdescription: %s\n", opt->description);
-       printf("\tboot_image: %s\n", opt->boot_image_file);
-       printf("\tinitrd: %s\n", opt->initrd_file);
-       printf("\tboot_args: %s\n", opt->boot_args);
-       return 0;
-}
+       if (!device_idx) {
+               fprintf(stderr, "Option (%s) added before device\n",
+                               opt->name);
+               exit(EXIT_FAILURE);
+       }
 
-enum generic_icon_type guess_device_type(void)
-{
-       return ICON_TYPE_UNKNOWN;
-}
+       printf("[opt %2d] name: %s\n", option_idx, opt->name);
+       printf("[opt %2d] description: %s\n", option_idx, opt->description);
+       printf("[opt %2d] boot_image: %s\n", option_idx, opt->boot_image_file);
+       printf("[opt %2d] initrd: %s\n", option_idx, opt->initrd_file);
+       printf("[opt %2d] boot_args: %s\n", option_idx, opt->boot_args);
 
-static char *mountpoint;
+       option_idx++;
 
-const char *mountpoint_for_device(const char *dev_path)
-{
-       char *tmp, *dev;
-       dev = strrchr(dev_path, '/');
-       if (dev)
-               dev_path = dev + 1;
-       asprintf(&tmp, "%s/%s", mountpoint, dev_path);
-       return tmp;
+       return 0;
 }
 
-char *resolve_path(const char *path, const char *default_mountpoint)
+enum generic_icon_type guess_device_type(void)
 {
-       char *sep, *ret;
-       const char *devpath;
-
-       sep = strchr(path, ':');
-       if (!sep) {
-               devpath = default_mountpoint;
-               asprintf(&ret, "%s/%s", devpath, path);
-       } else {
-               char *tmp = strndup(path, sep - path);
-               devpath = mountpoint_for_device(path);
-               asprintf(&ret, "%s/%s", devpath, sep + 1);
-               free(tmp);
-       }
-
-       return ret;
+       return ICON_TYPE_UNKNOWN;
 }
 
 int main(int argc, char **argv)
 {
-       const char *dev = "sda1";
+       char *mountpoint, *dev;
 
-       if (argc != 2) {
-               fprintf(stderr, "usage: %s <fake-mountpoint>\n", argv[0]);
+       if (argc != 3) {
+               fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
                return EXIT_FAILURE;
        }
 
        mountpoint = argv[1];
+       dev = argv[2];
+
+       set_mount_base(mountpoint);
 
        iterate_parsers(dev, mountpoint);
 
+
        return EXIT_SUCCESS;
 }