Enlightenment CVS committal
Author : onefang
Project : e17
Module : apps/e_utils
Dir : e17/apps/e_utils/src/bin/e17genmenu/src/bin
Modified Files:
main.c parse.c
Log Message:
Implement the ini parser.
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- main.c 1 Feb 2006 19:37:59 -0000 1.6
+++ main.c 3 Feb 2006 01:25:52 -0000 1.7
@@ -1,6 +1,7 @@
#include "global.h"
#include "config.h"
#include "menus.h"
+#include "parse.h"
#include "sort.h"
#include "fdo_paths.h"
@@ -66,7 +67,13 @@
path = fdo_paths_search_for_file(FDO_PATHS_TYPE_DESKTOP, desktop,
NULL, NULL);
if (path)
{
+ Ecore_Hash *desktop_hash;
+
printf("Path to %s is %s\n", desktop, path);
+ desktop_hash = parse_ini_file(path);
+ if (desktop_hash)
+ {
+ }
free(path);
}
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_utils/src/bin/e17genmenu/src/bin/parse.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- parse.c 3 Feb 2006 00:15:12 -0000 1.5
+++ parse.c 3 Feb 2006 01:25:52 -0000 1.6
@@ -399,6 +399,98 @@
result = ecore_hash_new(ecore_str_hash, ecore_str_compare);
if (result)
{
+ FILE *f;
+ char buffer[MAX_PATH];
+ Ecore_Hash *current = NULL;
+
+ f = fopen(file, "r");
+ if (!f)
+ {
+ fprintf(stderr, "ERROR: Cannot Open File %s\n", file);
+ ecore_hash_destroy(result);
+ return NULL;
+ }
+ ecore_hash_set_free_key(result, free);
+ ecore_hash_set_free_value(result, (Ecore_Free_Cb) ecore_hash_destroy);
+ *buffer = '\0';
+#ifdef DEBUG
+ fprintf(stdout, "PARSING INI %s\n", file);
+#endif
+ while (fgets(buffer, sizeof(buffer), f) != NULL)
+ {
+ char *c;
+ char *key;
+ char *value;
+
+ c = buffer;
+ /* Strip preceeding blanks. */
+ while ( ((*c == ' ') || (*c == '\t')) && (*c != '\n') && (*c !=
'\0'))
+ c++;
+ /* Skip blank lines and comments */
+ if ((*c == '\0') || (*c == '\n') || (*c == '#'))
+ continue;
+ if (*c == '[') /* New group. */
+ {
+ key = c + 1;
+ while ((*c != ']') && (*c != '\n') && (*c != '\0'))
+ c++;
+ *c++ = '\0';
+ current = ecore_hash_new(ecore_str_hash,
ecore_str_compare);
+ if (current)
+ {
+ ecore_hash_set_free_key(current, free);
+ ecore_hash_set_free_value(current, free);
+ if (!ecore_hash_set(result, strdup(key), current))
+ {
+ fprintf(stderr, "ERROR: Cannot add [%s] group
from %s\n", key, file);
+ ecore_hash_destroy(result);
+ return NULL;
+ }
+#ifdef DEBUG
+ fprintf(stdout, " GROUP [%s]\n", key);
+#endif
+ }
+ }
+ else if (current) /* key=value pair of current group. */
+ {
+ key = c;
+ /* Find trailing blanks or =. */
+ while ((*c != '=') && (*c != ' ') && (*c != '\t') && (*c !=
'\n') && (*c != '\0'))
+ c++;
+ if (*c != '=') /* Find equals. */
+ {
+ *c++ = '\0';
+ while ((*c != '=') && (*c != '\n') && (*c != '\0'))
+ c++;
+ }
+ if (*c == '=') /* Equals found. */
+ {
+ *c++ = '\0';
+ /* Strip preceeding blanks. */
+ while (((*c == ' ') || (*c == '\t')) && (*c != '\n')
&& (*c != '\0'))
+ c++;
+ value = c;
+ /* Find end. */
+ while ((*c != '\n') && (*c != '\0'))
+ c++;
+ *c++ = '\0';
+ /* FIXME: should strip space at end, then unescape
value. */
+ if (!ecore_hash_set(current, strdup(key),
strdup(value)))
+ {
+ fprintf(stderr, "ERROR: Cannot add %s=%s from
%s\n", key, value, file);
+ ecore_hash_destroy(result);
+ return NULL;
+ }
+#ifdef DEBUG
+ fprintf(stdout, " %s=%s\n", key, value);
+#endif
+ }
+ }
+
+ }
+ buffer[0] = (char)0;
+
+ fclose(f);
}
return result;
}
-------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs