3 * libpnd - tools for the Open Pandora device
4 * This code to be released under the terms of the GPLv2
15 * Since we're sticking configs in homedirs and /etc, it seems inappropriate to use XML; further
16 * of course, XML means a heavy duty parser (expat or something at least) when people really just
17 * use grep on these guys. Still, XML would afford us unicode which would be nice..
18 * Anyway, the very basic format of the config file supported herein is derived from .ini really
24 * Comments and leading/trailing space is removed; embedded space is left.
26 * Thats it; internally, 'section' is prepended to all keys, so it looks something like this.
27 * Section can be [] to mean 'back to the top level.' I had
28 * considered having no decorations around [section] (which is to say, a key with no value) but
29 * I could see cases where folks want to have a valueless key, without something goofy like value
30 * 'present' 'on' '0', when they just want a key 'use-foo' and don't want 'use foo' value 'no'
31 * that feals yes/no-ey.
33 * NOTE: If a key is present in a config twice.. well, too bad. No warning is made.
36 * path /mnt/sd1/my/path
40 * autodiscovery.path -> /mnt/sd1/my/path
44 /* certain paths must be 'givens'; ideally as few assumptions as possible, but to
45 * find further config files we need to look _somewhere_; note that searchpaths
46 * are searched in order, so the most-canonicle should be listed last.
48 * NOTE: This search path is used to find the basic config files, which in turn
49 * can specify a replacement config path .. it may be required to first locate the
50 * 'conf' config, and then use its suggested searchpath!
53 #define PND_CONF_SEARCHPATH "/media/mmcblk0p1/pandora/conf:/media/mmcblk1p1/pandora/conf:/etc/pandora/conf:./testdata/conf"
55 /* within the base conf file 'conf', the key for the searchpath is 'conf.searchpath' */
56 #define PND_CONF_FILE "conf" /* a config file for config settings! */
57 #define PND_CONF_KEY "conf.searchpath" /* if not found, use PND_CONF_SEARCHPATH */
59 /* we would like to open config files based on enums, so as to minimize specifying
60 * filenames; ie: It makes it easier to rename them later or display them in a native
61 * language, etc. It is optional as our API will allow direct open by filename as
66 pnd_conf_conf, // provides settings for the config system
67 pnd_conf_apps, // provides application search-path, pxml override location, etc.
68 pnd_conf_startup, // provides list of startup applications, basic shell application, etc.
69 pnd_conf_desktop, // provides settings for the launchers
70 pnd_conf_categories, // provides mapping from PXML category to dot-desktop category
71 pnd_conf_evmap, // provides mapping from event to sh-script
72 } pnd_conf_filename_e;
75 pnd_conf_filename_e id;
77 } pnd_conf_filename_t;
79 extern pnd_conf_filename_t pnd_conf_filenames[];
81 /* config file blackbox type
83 typedef void* pnd_conf_handle;
86 * config FILE reading public API
89 /* fetch_searchpath() - since near every app may wish to use this piece of code,
90 * it is encapsulated here.
91 * Returns a search-path to be used hereafter; free it when done with it!
93 char *pnd_conf_query_searchpath ( void );
95 /* fetch_by_id() will try to locate the config file as referred to by the enum'd 'id'. If it
96 * can be found and parsed a handle will be returned, otherwise a handle of 0 (NULL).
97 * Returns a 0 handle on fail, otherwise a useful handle.
99 pnd_conf_handle pnd_conf_fetch_by_id ( pnd_conf_filename_e id, char *searchpath );
101 /* if you don't wish to use an 'id', you can fetch by filename. Essentially the fetch_by_id()
102 * function simply uses this to do the work, but you could use it to load up alternate config-format
104 * Returns a 0 handle on fail, otherwise a useful handle.
106 pnd_conf_handle pnd_conf_fetch_by_name ( char *filename, char *searchpath );
108 /* fetch_by_path() will operate on a specific full filename; this essentially does the
109 * dirty work for the above functions, but can be used to pull in a specific path for
111 * Returns a 0 handle on fail, otherwise a useful handle.
113 pnd_conf_handle pnd_conf_fetch_by_path ( char *fullpath );
116 * config file accessor functions public API
119 /* get_as_char() will attempt to locate the specified key string (of format section.key) in the
120 * provided config handle. Do not free up this value, it is considered read only.
121 * Returns NULL on error, otherwise a READ ONLY char* reference to the value.
123 char *pnd_conf_get_as_char ( pnd_conf_handle c, char *key );
124 #define PND_CONF_BADNUM (-31337) /* really lame hack, I know */
125 int pnd_conf_get_as_int ( pnd_conf_handle c, char *key );