2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; version 2 of the License.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 static const char *conf_filename = "/boot/petitboot.conf";
26 static struct boot_option *cur_opt;
27 static struct device *dev;
28 static const char *devpath;
29 static int device_added;
31 static int check_and_add_device(struct device *dev)
34 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
36 return !add_device(dev);
39 static int section(char *section_name)
41 if (!device_added++ && !check_and_add_device(dev))
45 add_boot_option(cur_opt);
46 free_boot_option(cur_opt);
49 cur_opt = malloc(sizeof(*cur_opt));
50 memset(cur_opt, 0, sizeof(*cur_opt));
55 static void set_boot_option_parameter(struct boot_option *opt,
56 const char *name, const char *value)
58 if (streq(name, "name"))
59 opt->name = strdup(value);
61 else if (streq(name, "description"))
62 opt->description = strdup(value);
64 else if (streq(name, "image"))
65 opt->boot_image_file = resolve_path(value, devpath);
67 else if (streq(name, "icon"))
68 opt->icon_file = resolve_path(value, devpath);
70 else if (streq(name, "initrd"))
71 opt->initrd_file =resolve_path(value, devpath);
73 else if (streq(name, "args"))
74 opt->boot_args = strdup(value);
77 fprintf(stderr, "Unknown parameter %s\n", name);
80 static void set_device_parameter(struct device *dev,
81 const char *name, const char *value)
83 if (streq(name, "name"))
84 dev->name = strdup(value);
86 else if (streq(name, "description"))
87 dev->description = strdup(value);
89 else if (streq(name, "icon"))
90 dev->icon_file = resolve_path(value, devpath);
93 static int parameter(char *param_name, char *param_value)
96 set_boot_option_parameter(cur_opt, param_name, param_value);
98 set_device_parameter(dev, param_name, param_value);
103 static int native_parse(const char *device)
108 filepath = resolve_path(conf_filename, device);
111 dev = malloc(sizeof(*dev));
112 memset(dev, 0, sizeof(*dev));
113 dev->id = strdup(device);
115 rc = pm_process(filepath, section, parameter);
120 add_boot_option(cur_opt);
121 free_boot_option(cur_opt);
131 define_parser(native, native_parse);