*/
#include "obt/ddparse.h"
+#include "obt/link.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
typedef struct _ObtDDParse ObtDDParse;
/* Parses the value and adds it to the group's key_hash, with the given
- key */
-typedef void (*ObtDDParseValueFunc)(gchar *key, const gchar *val,
- ObtDDParse *parse, gboolean *error);
+ key
+ Return TRUE if it is added to the hash table, and FALSE if not.
+*/
+typedef gboolean (*ObtDDParseValueFunc)(gchar *key, const gchar *val,
+ ObtDDParse *parse, gboolean *error);
struct _ObtDDParse {
v->value.strings.n = 0;
break;
case OBT_DDPARSE_BOOLEAN:
- break;
case OBT_DDPARSE_NUMERIC:
+ case OBT_DDPARSE_ENUM_APPLICATION:
+ case OBT_DDPARSE_ENVIRONMENTS:
break;
default:
g_assert_not_reached();
return o;
}
+static guint parse_value_environments(const gchar *in,
+ const ObtDDParse *const parse,
+ gboolean *error)
+{
+ const gchar *s;
+ int i;
+ guint mask = 0;
+
+ s = in;
+ while (*s) {
+ switch (*(s++)) {
+ case 'G':
+ if (strcmp(s, "NOME") == 0) {
+ mask |= OBT_LINK_ENV_GNOME;
+ s += 4;
+ }
+ break;
+ case 'K':
+ if (strcmp(s, "DE") == 0) {
+ mask |= OBT_LINK_ENV_KDE;
+ s += 2;
+ }
+ break;
+ case 'L':
+ if (strcmp(s, "XDE") == 0) {
+ mask |= OBT_LINK_ENV_LXDE;
+ s += 3;
+ }
+ break;
+ case 'R':
+ if (strcmp(s, "OX") == 0) {
+ mask |= OBT_LINK_ENV_ROX;
+ s += 2;
+ }
+ break;
+ case 'X':
+ if (strcmp(s, "FCE") == 0) {
+ mask |= OBT_LINK_ENV_XFCE;
+ s += 3;
+ }
+ break;
+ case 'O':
+ switch (*(s++)) {
+ case 'l':
+ if (strcmp(s, "d") == 0) {
+ mask |= OBT_LINK_ENV_OLD;
+ s += 1;
+ }
+ break;
+ case 'P':
+ if (strcmp(s, "ENBOX") == 0) {
+ mask |= OBT_LINK_ENV_OPENBOX;
+ s += 5;
+ }
+ break;
+ }
+ }
+ /* find the next string, or the end of the sequence */
+ while (*s && *s != ';') ++s;
+ }
+ return mask;
+}
+
static gboolean parse_value_boolean(const gchar *in,
const ObtDDParse *const parse,
gboolean *error)
}
g_print("Found key/value %s=%s.\n", key, buf+valstart);
if (parse->group->value_func)
- parse->group->value_func(key, buf+valstart, parse, error);
+ if (!parse->group->value_func(key, buf+valstart, parse, error)) {
+ parse_error("Unknown key", parse, error);
+ g_free(key);
+ }
}
static gboolean parse_file(FILE *f, ObtDDParse *parse)
return !error;
}
-static void parse_desktop_entry_value(gchar *key, const gchar *val,
- ObtDDParse *parse, gboolean *error)
+static gboolean parse_desktop_entry_value(gchar *key, const gchar *val,
+ ObtDDParse *parse, gboolean *error)
{
ObtDDParseValue v, *pv;
- /* figure out value type */
- v.type = OBT_DDPARSE_NUM_VALUE_TYPES;
- /* XXX do this part */
+ switch (key[0]) {
+ case 'C':
+ switch (key[1]) {
+ case 'a': /* Categories */
+ if (strcmp(key+2, "tegories")) return FALSE;
+ v.type = OBT_DDPARSE_STRINGS; break;
+ case 'o': /* Comment */
+ if (strcmp(key+2, "mment")) return FALSE;
+ v.type = OBT_DDPARSE_LOCALESTRING; break;
+ default:
+ return FALSE;
+ }
+ break;
+ case 'E': /* Exec */
+ if (strcmp(key+1, "xec")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ case 'G': /* GenericName */
+ if (strcmp(key+1, "enericName")) return FALSE;
+ v.type = OBT_DDPARSE_LOCALESTRING; break;
+ case 'I': /* Icon */
+ if (strcmp(key+1, "con")) return FALSE;
+ v.type = OBT_DDPARSE_LOCALESTRING; break;
+ case 'H': /* Hidden */
+ if (strcmp(key+1, "idden")) return FALSE;
+ v.type = OBT_DDPARSE_BOOLEAN; break;
+ case 'M': /* MimeType */
+ if (strcmp(key+1, "imeType")) return FALSE;
+ v.type = OBT_DDPARSE_STRINGS; break;
+ case 'N':
+ switch (key[1]) {
+ case 'a': /* Name */
+ if (strcmp(key+2, "me")) return FALSE;
+ v.type = OBT_DDPARSE_LOCALESTRING; break;
+ case 'o':
+ switch (key[2]) {
+ case 'D': /* NoDisplay */
+ if (strcmp(key+3, "isplay")) return FALSE;
+ v.type = OBT_DDPARSE_BOOLEAN; break;
+ case 't': /* NotShowIn */
+ if (strcmp(key+3, "ShowIn")) return FALSE;
+ v.type = OBT_DDPARSE_STRINGS; break;
+ default:
+ return FALSE;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+ break;
+ case 'P': /* Path */
+ if (strcmp(key+1, "ath")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ case 'S': /* Path */
+ if (key[1] == 't' && key[2] == 'a' && key[3] == 'r' &&
+ key[4] == 't' && key[5] == 'u' && key[6] == 'p')
+ switch (key[7]) {
+ case 'N': /* StartupNotify */
+ if (strcmp(key+8, "otify")) return FALSE;
+ v.type = OBT_DDPARSE_BOOLEAN; break;
+ case 'W': /* StartupWMClass */
+ if (strcmp(key+8, "MClass")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ default:
+ return FALSE;
+ }
+ else
+ return FALSE;
+ break;
+ case 'T':
+ switch (key[1]) {
+ case 'e': /* Terminal */
+ if (strcmp(key+2, "rminal")) return FALSE;
+ v.type = OBT_DDPARSE_BOOLEAN; break;
+ case 'r': /* TryExec */
+ if (strcmp(key+2, "yExec")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ case 'y': /* Type */
+ if (strcmp(key+2, "pe")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ default:
+ return FALSE;
+ }
+ break;
+ case 'U': /* URL */
+ if (strcmp(key+1, "RL")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ case 'V': /* MimeType */
+ if (strcmp(key+1, "ersion")) return FALSE;
+ v.type = OBT_DDPARSE_STRING; break;
+ default:
+ return FALSE;
+ }
/* parse the value */
switch (v.type) {
case OBT_DDPARSE_NUMERIC:
v.value.numeric = parse_value_numeric(val, parse, error);
break;
+ case OBT_DDPARSE_ENUM_APPLICATION:
+ if (val[0] == 'A' && strcmp(val+1, "pplication") == 0)
+ v.value.enumerable = OBT_LINK_TYPE_APPLICATION;
+ else if (val[0] == 'L' && strcmp(val+1, "ink") == 0)
+ v.value.enumerable = OBT_LINK_TYPE_URL;
+ else if (val[0] == 'D' && strcmp(val+1, "irectory") == 0)
+ v.value.enumerable = OBT_LINK_TYPE_DIRECTORY;
+ else {
+ parse_error("Unknown Type", parse, error);
+ return FALSE;
+ }
+ break;
+ case OBT_DDPARSE_ENVIRONMENTS:
+ v.value.environments = parse_value_environments(val, parse, error);
+ break;
default:
g_assert_not_reached();
}
pv = g_slice_new(ObtDDParseValue);
*pv = v;
g_hash_table_insert(parse->group->key_hash, key, pv);
+ return TRUE;
}
GHashTable* obt_ddparse_file(const gchar *name, GSList *paths)