Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/src


Modified Files:
      Tag: branch-exp
        Makefile.am econfig.c E.h 


Log Message:
Use flat ASCII for configuration.
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/Makefile.am,v
retrieving revision 1.43.2.22
retrieving revision 1.43.2.23
diff -u -3 -r1.43.2.22 -r1.43.2.23
--- Makefile.am 17 Oct 2004 12:24:50 -0000      1.43.2.22
+++ Makefile.am 21 Oct 2004 17:52:44 -0000      1.43.2.23
@@ -104,7 +104,6 @@
 
 LDADD = \
        @LIBINTL@               \
-       @edb_libs@              \
        @ecore_libs@            \
        $(FNLIB_LIBS)           \
        $(TTF_LIBS)             \
@@ -117,7 +116,7 @@
        $(E_X_LIBS)             \
        -lX11 -lm
 
-INCLUDES = -I$(top_builddir) -I$(top_srcdir)/intl @edb_cflags@ @ecore_cflags@ 
$(ESD_CFLAGS) $(IMLIB_CFLAGS) $(X_CFLAGS)
+INCLUDES = -I$(top_builddir) -I$(top_srcdir)/intl @ecore_cflags@ $(ESD_CFLAGS) 
$(IMLIB_CFLAGS) $(X_CFLAGS)
 
 install-data-local:
        $(top_srcdir)/mkinstalldirs $(DESTDIR)$(ENLIGHTENMENT_ROOT)/themes
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/Attic/econfig.c,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -3 -r1.1.2.8 -r1.1.2.9
--- econfig.c   5 Sep 2004 11:46:44 -0000       1.1.2.8
+++ econfig.c   21 Oct 2004 17:52:44 -0000      1.1.2.9
@@ -22,10 +22,193 @@
  */
 #include "E.h"
 #include "econfig.h"
+#include <ctype.h>
 
-#if ENABLE_EDB                 /* */
+/*
+ * Braindead flat ASCII config file implementation
+ */
+
+typedef struct
+{
+   char               *key;
+   char               *value;
+} ECfgFileItem;
+
+typedef struct
+{
+   FILE               *fs;
+   int                 nitms;
+   ECfgFileItem       *pitms;
+} ECfgFile;
+
+#define E_DB_File ECfgFile
+
+static ECfgFile    *
+e_db_open(const char *name)
+{
+   ECfgFile           *ecf;
+   FILE               *fs;
+
+   fs = fopen(name, "w");
+   if (!fs)
+      return NULL;
+
+   ecf = Ecalloc(1, sizeof(ECfgFile));
+   if (!ecf)
+      goto done;
+
+   ecf->fs = fs;
+
+ done:
+   if (!ecf)
+      fclose(fs);
+   return ecf;
+}
+
+static ECfgFile    *
+e_db_open_read(const char *name)
+{
+   ECfgFile           *ecf;
+   FILE               *fs;
+   char                buf[4096], key[128], *s;
+   int                 i, len;
+
+   fs = fopen(name, "r");
+   if (!fs)
+      return NULL;
+
+   ecf = Ecalloc(1, sizeof(ECfgFile));
+   if (!ecf)
+      goto done;
+
+   for (;;)
+     {
+       s = fgets(buf, sizeof(buf), fs);
+       if (!s)
+          break;
+
+       /* Strip comment and trailing whitespace */
+       i = strcspn(s, "#\r\n");
+       for (; i > 0; i--)
+          if (!isspace(s[i - 1]))
+             break;
+       s[i] = '\0';
+
+       len = 0;
+       i = sscanf(s, "%100s = %n", key, &len);
+       if (i <= 0 || len <= 0)
+          continue;            /* Ignore bad format */
+
+       i = ecf->nitms++;
+       ecf->pitms = Erealloc(ecf->pitms, ecf->nitms * sizeof(ECfgFileItem));
+       ecf->pitms[i].key = Estrdup(key);
+       ecf->pitms[i].value = Estrdup(s + len);
+     }
+
+ done:
+   fclose(fs);
+   return ecf;
+}
+
+static void
+e_db_close(ECfgFile * ecf)
+{
+   int                 i;
+
+   if (ecf->pitms)
+     {
+       for (i = 0; i < ecf->nitms; i++)
+         {
+            Efree(ecf->pitms[i].key);
+            Efree(ecf->pitms[i].value);
+         }
+       Efree(ecf->pitms);
+     }
+   if (ecf->fs)
+      fclose(ecf->fs);
+   Efree(ecf);
+}
+
+static void
+e_db_flush(void)
+{
+}
+
+static const char  *
+ECfgFileFindValue(ECfgFile * ecf, const char *key)
+{
+   int                 i;
+
+   for (i = 0; i < ecf->nitms; i++)
+      if (!strcmp(key, ecf->pitms[i].key))
+        return ecf->pitms[i].value;
+
+   return NULL;
+}
+
+static int
+e_db_int_get(ECfgFile * ecf, const char *key, int *pint)
+{
+   const char         *value;
+
+   value = ECfgFileFindValue(ecf, key);
+   if (!value)
+      return 0;
 
-#include <Edb.h>
+   if (sscanf(value, "%i", pint) < 1)
+      return 0;
+
+   return 1;
+}
+
+static int
+e_db_float_get(ECfgFile * ecf, const char *key, float *pflt)
+{
+   const char         *value;
+
+   value = ECfgFileFindValue(ecf, key);
+   if (!value)
+      return 0;
+
+   if (sscanf(value, "%f", pflt) < 1)
+      return 0;
+
+   return 1;
+}
+
+static char        *
+e_db_str_get(ECfgFile * ecf, const char *key)
+{
+   const char         *value;
+
+   value = ECfgFileFindValue(ecf, key);
+   if (!value)
+      return NULL;
+
+   return Estrdup(value);
+}
+
+static void
+e_db_int_set(ECfgFile * ecf, const char *key, int value)
+{
+   fprintf(ecf->fs, "%s = %d\n", key, value);
+}
+
+static void
+e_db_float_set(ECfgFile * ecf, const char *key, float value)
+{
+   fprintf(ecf->fs, "%s = %f\n", key, value);
+}
+
+static void
+e_db_str_set(ECfgFile * ecf, const char *key, const char *value)
+{
+   fprintf(ecf->fs, "%s = %s\n", key, value);
+}
+
+/*
+ * Configuration handling.
+ */
 
 static void
 CfgItemLoad(E_DB_File * edf, const char *prefix, const CfgItem * ci)
@@ -112,7 +295,7 @@
 static const char  *
 ConfigurationGetFile(char *buf, int len)
 {
-   Esnprintf(buf, len, "%s.db", EGetSavePrefix());
+   Esnprintf(buf, len, "%s.cfg", EGetSavePrefix());
    return buf;
 }
 
@@ -340,5 +523,3 @@
    sscanf(p, "%s", item);
    ModuleConfigShow(name, item);
 }
-
-#endif
===================================================================
RCS file: /cvsroot/enlightenment/e16/e/src/E.h,v
retrieving revision 1.314.2.55
retrieving revision 1.314.2.56
diff -u -3 -r1.314.2.55 -r1.314.2.56
--- E.h 20 Oct 2004 21:03:58 -0000      1.314.2.55
+++ E.h 21 Oct 2004 17:52:44 -0000      1.314.2.56
@@ -1395,12 +1395,6 @@
 void                SaveUserControlConfig(const char *file);
 void                RecoverUserConfig(void);
 
-/* config-edb.c */
-void                ConfigurationLoad(void);
-void                ConfigurationSave(void);
-void                ConfigurationSet(const char *params);
-void                ConfigurationShow(const char *params);
-
 /* coords.c */
 void                CoordsShow(EWin * ewin);
 void                CoordsHide(void);
@@ -1574,6 +1568,12 @@
                                  int h, char firstlast);
 void                PropagateShapes(Window win);
 
+/* econfig.c */
+void                ConfigurationLoad(void);
+void                ConfigurationSave(void);
+void                ConfigurationSet(const char *params);
+void                ConfigurationShow(const char *params);
+
 /* edge.c */
 void                EdgeWindowsShow(void);
 void                EdgeWindowsHide(void);




-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to