1 #include "Ecore_Desktop.h"
2 #include "ecore_desktop_private.h"
8 /** xmlame.c Extensively Mocked Language Approximately Mangled for Enlightenment.
10 * This is NOT a real XML parser. There were a few ways we could go when it came
11 * to parsing the freedesktop.org (fdo) XML menu files. Whatever way we went, we
12 * needed some sort of XML parser if we wanted to fully support fdo menu files.
13 * Nothing we can do about that, fdo set the standard and they choose XML to do it.
15 * After a discussion with raster, three things led to the decision to do it this
16 * way. It is likely that this will get included as a core part of the E17 window
17 * manager (E17) coz E17 needs this functionality. E17 is in a dependency freeze
18 * and there is no XML parser in it's current dependencies. The fdo XML menu files
19 * look to be simple enough to parse that this sort of fake, brain dead, XML parser
20 * may get away with it. Much testing on lots of systems is highly recommended.
22 * The final '>' of a tag is replaced with a '\0', but it's existance can be implied.
25 static char *_ecore_desktop_xmlame_parse(Ecore_Desktop_Tree * tree,
29 ecore_desktop_xmlame_new(char *buffer)
31 Ecore_Desktop_Tree *tree;
33 tree = ecore_desktop_tree_new(buffer);
38 ecore_desktop_xmlame_get(char *file)
42 Ecore_Desktop_Tree *tree = NULL;
44 size = ecore_file_size(file);
45 buffer = (char *)malloc(size + 1);
51 fd = open(file, O_RDONLY);
54 if (read(fd, buffer, size) == size)
57 tree = ecore_desktop_xmlame_new(buffer);
60 /* Have the file name as the first item on the tree, for later reference. */
61 ecore_desktop_tree_extend(tree, file);
62 _ecore_desktop_xmlame_parse(tree, buffer);
69 _ecore_desktop_xmlame_parse(Ecore_Desktop_Tree * tree, char *buffer)
71 while (*buffer != '\0')
75 /* Skip any white space at the beginning. */
76 while ((*buffer != '\0') && (isspace(*buffer)))
79 /* Find the beginning of a tag. */
80 while ((*buffer != '<') && (*buffer != '\0'))
82 /* Check for data between tags. */
89 ecore_desktop_tree_extend(tree, text);
97 /* Find the end of the tag. */
98 while ((*buffer != '>') && (*buffer != '\0'))
100 /* We have our tag, do something with it. */
105 { /* The end of an element. */
106 ecore_desktop_tree_add(tree, begin);
109 else if ((begin[1] == '!') || (begin[1] == '-')
110 || (*(buffer - 2) == '/'))
111 { /* This is a script, a comment, or a stand alone tag. */
112 ecore_desktop_tree_add(tree, begin);
115 { /* The beginning of an element. */
116 Ecore_Desktop_Tree *new_tree;
118 new_tree = ecore_desktop_xmlame_new(NULL);
121 ecore_desktop_tree_add_child(tree, new_tree);
122 ecore_desktop_tree_add(new_tree, begin);
124 _ecore_desktop_xmlame_parse(new_tree, buffer);