Enlightenment CVS committal

Author  : andreas99
Project : e16
Module  : tools

Dir     : e16/tools/e16menuedit2/src


Modified Files:
        Makefile.am e16menu.c e16menuedit2.c e16menuedit2.h file.c 
        file.h 
Added Files:
        regex_func.c regex_func.h 


Log Message:
- added new _experimental_ routine to read menus with regex
  - <FIXED> Bug with "------" NULL entries
  

===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- Makefile.am 28 Aug 2004 12:27:57 -0000      1.7
+++ Makefile.am 9 Jan 2005 20:53:51 -0000       1.8
@@ -20,7 +20,8 @@
         treeview.c\
         treeview.h\
         libglade_support.c\
-        libglade_support.h
-
-e16menuedit2_LDADD = @PACKAGE_LIBS@ $(INTLLIBS) 
+        libglade_support.h\
+       regex_func.c\
+       regex_func.h
 
+e16menuedit2_LDADD = @PACKAGE_LIBS@ $(INTLLIBS)
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menu.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- e16menu.c   29 Dec 2004 11:25:42 -0000      1.8
+++ e16menu.c   9 Jan 2005 20:53:51 -0000       1.9
@@ -88,77 +88,49 @@
     {
       if (first)
       {
-        gchar *text[3];
-        char *txt = NULL;
-        char *txt2 = NULL;
-        char *txt3 = NULL;
-
-        txt = field (s, 0);
-        text[0] = g_locale_to_utf8 (txt, -1, NULL, NULL, NULL);
-        txt2 = g_strdup ("");
-        text[1] = g_locale_to_utf8 (txt2, -1, NULL, NULL, NULL);
-        txt3 = g_strdup (buf);
-        text[2] = g_locale_to_utf8 (txt3, -1, NULL, NULL, NULL);
+        gchar **data;
 
+       menu_regex (s, &data);
+
+       data[3] = strdup (to_utf8 (buf));
+      
         gtk_tree_store_append (store, &iter, NULL);
         gtk_tree_store_set (store, &iter,
-                            COL_DESCRIPTION, text[0],
-                            COL_ICON, gdk_pixbuf_new_from_file (text[1], NULL),
-                            COL_ICONNAME, text[1],
-                            COL_PARAMS, text[2],
+                            COL_DESCRIPTION, data[0],
+                            COL_ICON, gdk_pixbuf_new_from_file (data[1], NULL),
+                            COL_ICONNAME, data[1],
+                            COL_PARAMS, data[3],
                             -1);
 
-        //printf("mainitem: %s, %s, %s\n",txt,txt2,txt3);
-
-        if (txt)
-          g_free (txt);
-        if (txt2)
-          g_free (txt2);
-        if (txt3)
-          g_free (txt3);
-
+       g_free (data[0]);
+       g_free (data[1]);
+       g_free (data[2]);
+       g_free (data[3]);
+       g_free (data);
         first = 0;
       }
       else
       {
-        char *txt = NULL, *icon = NULL, *act = NULL, *params = NULL;
-        gchar *text[3];
-
-        txt = field (s, 0);
-        icon = field (s, 1);
-        act = field (s, 2);
-        params = field (s, 3);
-
-        text[0] = g_locale_to_utf8 (txt, -1, NULL, NULL, NULL);
-        if (!icon)
-          icon = g_strdup ("");
-        text[1] = g_locale_to_utf8 (icon, -1, NULL, NULL, NULL);
-        if (!params)
-          params = g_strdup ("");
-        text[2] = g_locale_to_utf8 (params, -1, NULL, NULL, NULL);
-
-        //printf("subitem: %s, %s, %s, %s\n",txt,icon,act,params);
+        gchar **data;
+      
+       menu_regex (s, &data);
 
         gtk_tree_store_append (store, &sub_iter, &iter);
         gtk_tree_store_set (store, &sub_iter,
-                            COL_DESCRIPTION, text[0],
-                            COL_ICON, gdk_pixbuf_new_from_file (icon, NULL),
-                            COL_ICONNAME, text[1],
-                            COL_PARAMS, text[2],
+                            COL_DESCRIPTION, data[0],
+                            COL_ICON, gdk_pixbuf_new_from_file (data[1], NULL),
+                            COL_ICONNAME, data[1],
+                            COL_PARAMS, data[3],
                             -1);
 
-        if (!strcasecmp (act, "menu"))
-          load_sub_menu_from_disk (params, store, &sub_iter);
-
-        if (txt)
-          g_free (txt);
-        if (icon)
-          g_free (icon);
-        if (act)
-          g_free (act);
-        if (params)
-          g_free (params);
+        if (!strcasecmp (data[2], "menu"))
+          load_sub_menu_from_disk (data[3], store, &sub_iter);
 
+       g_free (data[0]);
+       g_free (data[1]);
+       g_free (data[2]);
+       g_free (data[3]);
+       g_free (data);
       }
     }
   }
@@ -202,45 +174,28 @@
       if (first)
         first = 0;
       else
-      {
-        char *txt = NULL, *icon = NULL, *act = NULL, *params = NULL;
-        gchar *text[3];
-
-        txt = field (s, 0);
-        icon = field (s, 1);
-        act = field (s, 2);
-        params = field (s, 3);
-
-        text[0] = g_locale_to_utf8 (txt, -1, NULL, NULL, NULL);
-        if (!icon)
-          icon = g_strdup ("");
-        text[1] = g_locale_to_utf8 (icon, -1, NULL, NULL, NULL);
-        if (!params)
-          params = g_strdup ("");
-        text[2] = g_locale_to_utf8 (params, -1, NULL, NULL, NULL);
-
-        /* printf("subitem: %s, %s, %s, %s\n",txt,icon,act,params); */
+      {        
+        gchar **data;
+      
+       menu_regex (s, &data);
 
         gtk_tree_store_append (store, &sub_iter, iter);
         gtk_tree_store_set (store, &sub_iter,
-                            COL_DESCRIPTION, text[0],
-                            COL_ICON, gdk_pixbuf_new_from_file (icon, NULL),
-                            COL_ICONNAME, text[1],
-                            COL_PARAMS, text[2],
+                            COL_DESCRIPTION, data[0],
+                            COL_ICON, gdk_pixbuf_new_from_file (data[1], NULL),
+                            COL_ICONNAME, data[1],
+                            COL_PARAMS, data[3],
                             -1);
 
 
-        if (!strcasecmp (act, "menu"))
-          load_sub_menu_from_disk (params, store, &sub_iter);
+        if (!strcasecmp (data[2], "menu"))
+          load_sub_menu_from_disk (data[3], store, &sub_iter);
 
-        if (txt)
-          g_free (txt);
-        if (icon)
-          g_free (icon);
-        if (act)
-          g_free (act);
-        if (params)
-          g_free (params);
+       g_free (data[0]);
+       g_free (data[1]);
+       g_free (data[2]);
+       g_free (data[3]);
+       g_free (data);
       }
     }
   }
@@ -321,8 +276,7 @@
 
       sprintf (buffer, "\"%s\"\n", description);
 #ifdef WRITE_FILE    
-      fprintf (menu_ptr2, "%s", g_locale_from_utf8 (buffer,
-               -1, NULL, NULL, NULL));
+      fprintf (menu_ptr2, "%s", from_utf8 (buffer));
       fclose (menu_ptr2);
 #else
       g_print ("write header to: \"%s\"\n", menu_file[depth]);
@@ -333,8 +287,7 @@
                icon[0] == '\0' ? "NULL" : icon,
                params[0] == '\0' ? "" : params);
 #ifdef WRITE_FILE      
-      fprintf (menu_ptr, "%s", g_locale_from_utf8 (buffer,
-               -1, NULL, NULL, NULL));
+      fprintf (menu_ptr, "%s", from_utf8 (buffer));
 #else
       g_print ("write menu to: \"%s\"\n", menu_file[depth-1]);
 #endif /* WRITE_FILE */     
@@ -346,8 +299,7 @@
                icon[0] == '\0' ? "NULL" : icon,
                params[0] == '\0' ? "" : params);
 #ifdef WRITE_FILE
-      fprintf (menu_ptr, "%s", g_locale_from_utf8 (buffer,
-               -1, NULL, NULL, NULL));
+      fprintf (menu_ptr, "%s", from_utf8 (buffer));
 #else
       g_print ("write exec to: \"%s\"\n", menu_file[depth-1]);
 #endif /*WRITE_FILE */    
@@ -368,8 +320,7 @@
 
     sprintf (buffer, "\"%s\"\n", description);
 #ifdef WRITE_FILE  
-    fprintf (menu_ptr2, "%s", g_locale_from_utf8 (buffer,
-             -1, NULL, NULL, NULL));
+    fprintf (menu_ptr2, "%s", from_utf8 (buffer));
     fclose (menu_ptr2);
 #else
     g_print ("write first header to: \"%s\"\n", menu_file[depth]);
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menuedit2.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- e16menuedit2.c      29 Dec 2004 11:25:42 -0000      1.20
+++ e16menuedit2.c      9 Jan 2005 20:53:51 -0000       1.21
@@ -59,6 +59,9 @@
   textdomain (PACKAGE);
 #endif
 
+  /* compile some regex patterns */
+  compile_regex ();
+
   /* set log level for app exit */
   g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
@@ -118,13 +121,12 @@
 
     fclose (fz_properties);
   }
-
   g_free (filename_properties);
 
   gtk_main ();
 
   free (gv.epath);
-  g_free (gv.glade_file);
+  g_free (gv.glade_file);  
 
   return 0;
 }
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/e16menuedit2.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- e16menuedit2.h      29 Dec 2004 11:25:42 -0000      1.10
+++ e16menuedit2.h      9 Jan 2005 20:53:51 -0000       1.11
@@ -35,6 +35,7 @@
 #include <popt.h>
 #include "nls.h"
 #include "libglade_support.h"
+#include "regex_func.h"
 
 #define to_utf8(String) g_locale_to_utf8(String,-1,0,0,0)
 #define from_utf8(String) g_locale_from_utf8(String,-1,0,0,0)
@@ -61,6 +62,12 @@
   char *glade_file;
   char *epath;
   int emenu;
+  regex_t re_mark;
+  regex_t re_char;
+  regex_t re_space;
+  char *pattern_mark;
+  char *pattern_char;
+  char *pattern_space;
 };
 
 /* app_errno codes */
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/file.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- file.c      20 Dec 2004 20:22:40 -0000      1.13
+++ file.c      9 Jan 2005 20:53:51 -0000       1.14
@@ -26,6 +26,8 @@
 
 #include "file.h"
 
+extern struct global_variables gv;
+
 char *homedir (int uid)
 {
   char *s;
@@ -52,96 +54,127 @@
           ((getenv ("TMPDIR") == NULL) ? "/tmp" : getenv ("TMPDIR")));
 }
 
-char *field (char *s, int field)
+int compile_regex ()
 {
-  char buf[4096];
+  int status;
 
-  buf[0] = 0;
-  fword (s, field + 1, buf);
-  if (buf[0])
-  {
-    if ((!strcmp (buf, "NULL")) || (!strcmp (buf, "(null)")))
-      return (NULL);
-    return (g_strdup (buf));
-  }
-  return NULL;
+  char pattern_mark[] = "\"([^\"]*)\"[[:space:]]*";
+  char pattern_char[] = "([^[[:space:]]*)[[:space:]]*";
+  char pattern_space[] = "[[:space:]]*(.*)";
+
+  status = regcomp (&gv.re_mark, pattern_mark, REG_EXTENDED);
+  status = regcomp (&gv.re_char, pattern_char, REG_EXTENDED);
+  status = regcomp (&gv.re_space, pattern_space, REG_EXTENDED);
+
+  gv.pattern_mark = strdup (pattern_mark);
+  gv.pattern_char = strdup (pattern_char);
+  gv.pattern_space = strdup (pattern_space);
 }
 
-void fword (char *s, int num, char *wd)
+int menu_regex (char *line, gchar ***data_ptr)
 {
-  char *cur, *start, *end;
-  int count, inword, inquote, len;
+  struct substrings *ss = NULL;
+  int numsub = 0;
+  int maxsub = 1;
+  int status;
+  char err_buf[1024];
+  char **data;
+  int i, n;
+
+  data = malloc (4 * sizeof (*data));
+
+  *data_ptr = data;
+
+  line = strdup (line);
+  printf ("%s\n", line);
+
+  /* cut spaces */
+  if (line[0] == ' ')
+  {
+    status = regex_sub2 (&gv.re_space, line, gv.pattern_space,
+                         &ss, maxsub, &numsub);
 
-  if (!s)
-    return;
-  if (!wd)
-    return;
-  *wd = 0;
-  if (num <= 0)
-    return;
-  cur = s;
-  count = 0;
-  inword = 0;
-  inquote = 0;
-  start = NULL;
-  end = NULL;
-  while ((*cur) && (count < num))
+    if (numsub >= 1)
+    {
+      free (line);
+      line = strdup (ss[1].match);
+    }
+
+    for (i = 0; i < numsub; i++)
+    {
+      free (ss[i].match);
+      free (ss[i].start);
+      free (ss[i].end);
+    }
+    free (ss);
+  }
+
+  /* parse data array */
+  for (n = 0; n < 4; n++)
   {
-    if (inword)
+    data[n] = strdup ("");
+
+    if (line[0] == '\"')
     {
-      if (inquote)
+      status = regex_sub2 (&gv.re_mark, line, gv.pattern_mark,
+                           &ss, maxsub, &numsub);
+      if (status != 0)
       {
-        if (*cur == '"')
-        {
-          inquote = 0;
-          inword = 0;
-          end = cur;
-          count++;
-        }
+        regerror (status, &gv.re_mark, err_buf, (size_t) 1024);
+        printf ("regex exec: %s\n", err_buf);
       }
-      else
+
+      if (numsub >= 1)
+      {
+        free (line);
+        line = strdup (ss[0].end);
+
+        free (data[n]);
+        data[n] = g_strdup (to_utf8 (ss[1].match));
+      }
+
+      for (i = 0; i < numsub; i++)
       {
-        if (isspace (*cur))
-        {
-          end = cur;
-          inword = 0;
-          count++;
-        }
+        free (ss[i].match);
+        free (ss[i].start);
+        free (ss[i].end);
       }
+      free (ss);
+
+      printf ("match \": %s\n", data[n]);
     }
-    else
+    else if (line[0] != ' ')
     {
-      if (!isspace (*cur))
+      status = regex_sub2 (&gv.re_char, line, gv.pattern_char,
+                           &ss, maxsub, &numsub);
+      if (status != 0)
+      {
+        regerror (status, &gv.re_char, err_buf, (size_t) 1024);
+        printf ("regex exec: %s\n", err_buf);
+      }
+
+      if (numsub >= 1)
+      {
+
+        free (line);
+        line = strdup (ss[0].end);
+        free (data[n]);
+        data[n] = g_strdup (to_utf8 (ss[1].match));
+      }
+
+      for (i = 0; i < numsub; i++)
       {
-        if (*cur == '"')
-        {
-          inquote = 1;
-          start = cur + 1;
-        }
-        else
-          start = cur;
-        inword = 1;
+        free (ss[i].match);
+        free (ss[i].start);
+        free (ss[i].end);
       }
+      free (ss);
+
+      printf ("match char: %s\n", data[n]);
     }
-    if (count == num)
-      break;
-    cur++;
   }
-  if (!start)
-    return;
-  if (!end)
-    end = cur;
-  if (end <= start)
-    return;
-  len = (int) (end - start);
-  if (len > 4000)
-    len = 4000;
-  if (len > 0)
-  {
-    strncpy (wd, start, len);
-    wd[len] = 0;
-  }
-  return;
+
+  return 0;
 }
 
 int mkdir_with_parent (const char *pathname, mode_t mode)
@@ -328,7 +361,7 @@
   g_free (argv_child[1]);
 
   ret_val = read (stdout_child, buf, buf_len);
-  
+
   sscanf (buf, "Enlightenment-Version: enlightenment-%s\n", buf2);
 
   if (ret_val == 0)
@@ -381,14 +414,14 @@
 
   /* Is there a better way to get the users current language? */
   locale = setlocale (LC_MESSAGES, NULL);
-  
+
   /* If no locale is available use 'C' and free it later */
   if (!locale)
   {
     locale_failed = TRUE;
     locale = g_strdup_printf ("C");
   }
-  
+
   params = g_strdup_printf ("%s/%s/%s", help_dir,
                             locale, help_file);
 #ifdef DEBUG
@@ -427,13 +460,13 @@
       if (help_missing)
       {
         locale_tmp = strdup (locale_fallback);
-       g_free (locale_fallback);
+        g_free (locale_fallback);
         locale_fallback = get_fallback_locale (locale_tmp);
         g_free (locale_tmp);
         g_free (params);
         params = g_strdup_printf ("%s/%s/%s", help_dir,
                                   locale_fallback, help_file);
-       g_free (locale_fallback);
+        g_free (locale_fallback);
        #ifdef DEBUG
         DEBUG_OUTPUT printf ("Try help fallback4: %s\n", params);
         #endif /* DEBUG */  
@@ -441,7 +474,7 @@
       }
       else
       {
-       g_free (locale_fallback);
+        g_free (locale_fallback);
       }
     }
   }
@@ -456,7 +489,7 @@
     argv_child[0] = help_app;
     argv_child[1] = params;
     argv_child[2] = NULL;
-  
+
     #ifdef DEBUG
     DEBUG_OUTPUT printf ("Try exec help: %s %s\n", help_app, params);
     #endif /* DEBUG */
===================================================================
RCS file: /cvsroot/enlightenment/e16/tools/e16menuedit2/src/file.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- file.h      20 Dec 2004 20:22:40 -0000      1.9
+++ file.h      9 Jan 2005 20:53:51 -0000       1.10
@@ -43,6 +43,7 @@
 #include <locale.h>
 #include <langinfo.h>
 #include "e16menuedit2.h"
+#include "regex_func.h"
 
 char *field (char *s, int field);
 void fword (char *s, int num, char *wd);
@@ -55,5 +56,7 @@
 char *e16_version ();
 char *get_fallback_locale (char *locale);
 int run_help (char *help_app, char* help_dir, char *help_file);
+int compile_regex ();
+int menu_regex (char *line, gchar ***data_ptr);
 
 #endif /* _FILE_H */




-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to