10 const char *conf_filename = "/boot/petitboot.conf";
12 static struct boot_option *cur_opt;
13 static struct device *dev;
14 static const char *devpath;
17 int check_and_add_device(struct device *dev)
20 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
22 return !add_device(dev);
25 static int section(char *section_name)
27 if (!device_added++ && !check_and_add_device(dev))
31 add_boot_option(cur_opt);
32 free_boot_option(cur_opt);
35 cur_opt = malloc(sizeof(*cur_opt));
36 memset(cur_opt, 0, sizeof(*cur_opt));
41 static void set_boot_option_parameter(struct boot_option *opt,
42 const char *name, const char *value)
44 if (streq(name, "name"))
45 opt->name = strdup(value);
47 else if (streq(name, "description"))
48 opt->description = strdup(value);
50 else if (streq(name, "image"))
51 opt->boot_image_file = resolve_path(value, devpath);
53 else if (streq(name, "icon"))
54 opt->icon_file = resolve_path(value, devpath);
56 else if (streq(name, "initrd"))
57 opt->initrd_file =resolve_path(value, devpath);
59 else if (streq(name, "args"))
60 opt->boot_args = strdup(value);
63 fprintf(stderr, "Unknown parameter %s\n", name);
66 static void set_device_parameter(struct device *dev,
67 const char *name, const char *value)
69 if (streq(name, "name"))
70 dev->name = strdup(value);
72 else if (streq(name, "description"))
73 dev->description = strdup(value);
75 else if (streq(name, "icon"))
76 dev->icon_file = resolve_path(value, devpath);
79 static int parameter(char *param_name, char *param_value)
82 set_boot_option_parameter(cur_opt, param_name, param_value);
84 set_device_parameter(dev, param_name, param_value);
89 int parse(const char *device)
94 filepath = resolve_path(conf_filename, device);
97 dev = malloc(sizeof(*dev));
98 memset(dev, 0, sizeof(*dev));
99 dev->id = strdup(device);
101 rc = pm_process(filepath, section, parameter);
106 add_boot_option(cur_opt);
107 free_boot_option(cur_opt);
117 struct parser native_parser = {
118 .name = "native petitboot parser",