Enlightenment CVS committal Author : onefang Project : e17 Module : apps/e_utils
Dir : e17/apps/e_utils/src/bin/e17genmenu/src/bin Modified Files: dumb_list.c dumb_list.h main.c xmlame.c xmlame.h Log Message: David 'onefang' Seikel is proud to present - "The World's Lamest XML Parser!" Enjoy. =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/dumb_list.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- dumb_list.c 8 Feb 2006 04:35:56 -0000 1.2 +++ dumb_list.c 8 Feb 2006 23:13:29 -0000 1.3 @@ -148,14 +148,12 @@ { int i; - E_FREE(list->elements); - for (i = 0; i < list->size; i++) { int j; for (j = 0; j < level; j++) - printf(" "); + printf("."); switch (list->elements[i].type) { case DUMB_LIST_ELEMENT_TYPE_STRING : @@ -166,6 +164,7 @@ case DUMB_LIST_ELEMENT_TYPE_LIST : { + printf("LIST ELEMENT TYPE\n"); dumb_list_dump((Dumb_List *) list->elements[i].element, level + 1); } break; @@ -184,7 +183,6 @@ { int i; - for (i = list->size - 1; i >= 0; i--) { if (list->elements[i].type == DUMB_LIST_ELEMENT_TYPE_LIST) =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/dumb_list.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- dumb_list.h 8 Feb 2006 04:35:56 -0000 1.2 +++ dumb_list.h 8 Feb 2006 23:13:30 -0000 1.3 @@ -41,6 +41,7 @@ Dumb_List *dumb_list_new(char *buffer); Dumb_List *dumb_list_add(Dumb_List *list, char *element); Dumb_List *dumb_list_extend(Dumb_List *list, char *element); + Dumb_List *dumb_list_add_child(Dumb_List *list, Dumb_List *element); int dumb_list_exist(Dumb_List *list, char *element); void dumb_list_dump(Dumb_List *list, int level); void dumb_list_del(Dumb_List *list); =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/main.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- main.c 8 Feb 2006 04:35:56 -0000 1.14 +++ main.c 8 Feb 2006 23:13:30 -0000 1.15 @@ -53,15 +53,16 @@ char *directory = "Applications.directory"; char *desktop = "xterm.desktop"; char *icon = "tux.png"; - Dumb_List *menus = NULL; + Dumb_List *menu_xml = NULL; printf("Path to %s is %s\n", menu, path); - menus = xmlame_new(NULL); - if (menus) + menu_xml = xmlame_get(path);; + if (menu_xml) { - xmlame_fill(path); - dumb_list_dump(menus, 0); + dumb_list_dump(menu_xml, 0); printf("\n\n"); + /* convert the xml into a menu */ + /* create the .eap and order files from the menu */ } free(path); =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/xmlame.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- xmlame.c 8 Feb 2006 04:35:56 -0000 1.2 +++ xmlame.c 8 Feb 2006 23:13:30 -0000 1.3 @@ -1,3 +1,13 @@ +#include <fcntl.h> +#include <ctype.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <Ecore_File.h> + #include "xmlame.h" /** xmlame.c Extensively Mocked Language Approximately Mangled for Enlightenment. @@ -13,8 +23,13 @@ * and there is no XML parser in it's current dependencies. The fdo XML menu files * look to be simple enough to parse that this sort of fake, brain dead, XML parser * may get away with it. Much testing on lots of systems is highly recommended. + * + * The final '>' of a tag is replaced with a '\0', but it's existance can be implied. */ +static char *_xmlame_parse(Dumb_List *list, char *buffer); + + Dumb_List * xmlame_new(char *buffer) { @@ -24,7 +39,93 @@ return list; } -void -xmlame_fill(char *file) +Dumb_List * +xmlame_get(char *file) { + int size; + char *buffer; + Dumb_List *list = NULL; + + size = ecore_file_size(file); + buffer = (char *) malloc(size + 1); + if (buffer) + { + int fd; + + buffer[0] = '\0'; + fd = open(file, O_RDONLY); + if (fd != -1) + { + if (read(fd, buffer, size) == size) + buffer[size] = '\0'; + } + list = xmlame_new(buffer); + if (list) + _xmlame_parse(list, buffer); + } + return list; +} + +static char * +_xmlame_parse(Dumb_List *list, char *buffer) +{ + do + { + char *text; + + /* Skip any white space at the beginning. */ + while ((*buffer != '\0') && (isspace(*buffer))) + buffer++; + text = buffer; + /* Find the beginning of a tag. */ + while ((*buffer != '<') && (*buffer != '\0')) + buffer++; + /* Check for data between tags. */ + if (buffer != text) + { + char t; + + t = *buffer; + *buffer = '\0'; + dumb_list_extend(list, strdup(text)); + *buffer = t; + } + if (*buffer != '\0') + { + char *begin; + + begin = buffer++; + /* Find the end of the tag. */ + while ((*buffer != '>') && (*buffer != '\0')) + buffer++; + /* We have our tag, do something with it. */ + if (*buffer != '\0') + { + *buffer++ = '\0'; + if (begin[1] == '/') + { /* The end of an element. */ + dumb_list_add(list, begin); + break; + } + else if ((begin[1] == '!') || (begin[1] == '-') || (*(buffer - 2) == '/')) + { /* This is a script, a comment, or a stand alone tag. */ + dumb_list_add(list, begin); + } + else + { /* The beginning of an element. */ + Dumb_List *new_list; + + new_list = xmlame_new(NULL); + if (new_list) + { + dumb_list_add_child(list, new_list); + dumb_list_add(new_list, begin); + buffer = _xmlame_parse(new_list, buffer); + } + } + } + } + } while (*buffer != '\0'); + + return buffer; } =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/xmlame.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- xmlame.h 8 Feb 2006 04:35:56 -0000 1.2 +++ xmlame.h 8 Feb 2006 23:13:30 -0000 1.3 @@ -4,6 +4,6 @@ #include "dumb_list.h" Dumb_List *xmlame_new(char *buffer); -void xmlame_fill(char *file); +Dumb_List *xmlame_get(char *file); #endif ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs