]> git.ozlabs.org Git - petitboot/blob - devices/parser.c
Include COPYING and TODO in dist target
[petitboot] / devices / parser.c
1
2 #include <petitboot-paths.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "parser.h"
7
8 extern struct parser native_parser;
9 extern struct parser yaboot_parser;
10 extern struct parser kboot_parser;
11
12 /* array of parsers, ordered by priority */
13 static struct parser *parsers[] = {
14         &native_parser,
15         &yaboot_parser,
16         &kboot_parser,
17         NULL
18 };
19
20 void iterate_parsers(const char *devpath, const char *mountpoint)
21 {
22         int i;
23
24         pb_log("trying parsers for %s@%s\n", devpath, mountpoint);
25
26         for (i = 0; parsers[i]; i++) {
27                 pb_log("\ttrying parser '%s'\n", parsers[i]->name);
28                 /* just use a dummy device path for now */
29                 if (parsers[i]->parse(devpath, mountpoint))
30                         return;
31         }
32         pb_log("\tno boot_options found\n");
33 }
34
35 /* convenience functions for parsers */
36 void free_device(struct device *dev)
37 {
38         if (!dev)
39                 return;
40         if (dev->id)
41                 free(dev->id);
42         if (dev->name)
43                 free(dev->name);
44         if (dev->description)
45                 free(dev->description);
46         if (dev->icon_file)
47                 free(dev->icon_file);
48         free(dev);
49 }
50
51 void free_boot_option(struct boot_option *opt)
52 {
53         if (!opt)
54                 return;
55         if (opt->name)
56                 free(opt->name);
57         if (opt->description)
58                 free(opt->description);
59         if (opt->icon_file)
60                 free(opt->icon_file);
61         if (opt->boot_image_file)
62                 free(opt->boot_image_file);
63         if (opt->initrd_file)
64                 free(opt->initrd_file);
65         if (opt->boot_args)
66                 free(opt->boot_args);
67         free(opt);
68 }
69
70 char *join_paths(const char *a, const char *b)
71 {
72         char *full_path;
73
74         full_path = malloc(strlen(a) + strlen(b) + 2);
75
76         strcpy(full_path, a);
77         if (b[0] != '/')
78                 strcat(full_path, "/");
79         strcat(full_path, b);
80
81         return full_path;
82 }
83
84 const char *generic_icon_file(enum generic_icon_type type)
85 {
86         switch (type) {
87         case ICON_TYPE_DISK:
88                 return artwork_pathname("hdd.png");
89         case ICON_TYPE_USB:
90                 return artwork_pathname("usbpen.png");
91         case ICON_TYPE_OPTICAL:
92                 return artwork_pathname("cdrom.png");
93         case ICON_TYPE_NETWORK:
94         case ICON_TYPE_UNKNOWN:
95                 break;
96         }
97         return artwork_pathname("hdd.png");
98 }
99