Hi folks,

in the good old days, before the edje file format rewrite, one was
able to create programs without name. If one needed to use that
program in an action or after clausule, one needed to declare the
name. But for programs that only reacts to signals so the name is not
relevant.

Sachiel says now we need a name. No matter what. So I created this
workaround. It let's edje create a random name if one wasn't
explicitly set. Just trying to make things easier and maintain
compatibility with edcs I already wrote.

Cheers,

Eduardo Felipe.
Index: bin/edje_cc_handlers.c
===================================================================
--- bin/edje_cc_handlers.c      (revision 51590)
+++ bin/edje_cc_handlers.c      (working copy)
@@ -891,7 +891,7 @@
    return result;
 }
 
-static void
+static Eina_Bool
 _edje_program_check(const char *name, Edje_Program *me, Edje_Program **pgrms, 
unsigned int count)
 {
    unsigned int i;
@@ -899,10 +899,9 @@
    for (i = 0; i < count; ++i)
      if (pgrms[i] != me && pgrms[i]->name && (!strcmp(name, pgrms[i]->name)))
        {
-         ERR("%s: Error. parse error %s:%i. There is already a program of the 
name %s\n",
-             progname, file_in, line - 1, name);
-         exit(-1);
+          return EINA_TRUE;
        }
+   return EINA_FALSE;
 }
 
 /*****/
@@ -6623,19 +6622,40 @@
 st_collections_group_programs_program_name(void)
 {
    Edje_Part_Collection *pc;
+   int priv_prefix_len = strlen("__in_program_");
 
    check_arg_count(1);
 
+   if (current_program->name)
+     {
+        ERR("%s: Error. parse error %s:%i. Name must be declared first or not 
at all.\n",
+          progname, file_in, line - 1);
+        exit(-1);
+     }
+
    pc = eina_list_data_get(eina_list_last(edje_collections));
    current_program->name = parse_str(0);
 
-   _edje_program_check(current_program->name, current_program, 
pc->programs.fnmatch, pc->programs.fnmatch_count);
-   _edje_program_check(current_program->name, current_program, 
pc->programs.strcmp, pc->programs.strcmp_count);
-   _edje_program_check(current_program->name, current_program, 
pc->programs.strncmp, pc->programs.strncmp_count);
-   _edje_program_check(current_program->name, current_program, 
pc->programs.strrncmp, pc->programs.strrncmp_count);
-   _edje_program_check(current_program->name, current_program, 
pc->programs.nocmp, pc->programs.nocmp_count);
+   if (_edje_program_check(current_program->name, current_program, 
pc->programs.fnmatch, pc->programs.fnmatch_count)
+    || _edje_program_check(current_program->name, current_program, 
pc->programs.strcmp, pc->programs.strcmp_count)
+    || _edje_program_check(current_program->name, current_program, 
pc->programs.strncmp, pc->programs.strncmp_count)
+    || _edje_program_check(current_program->name, current_program, 
pc->programs.strrncmp, pc->programs.strrncmp_count)
+    || _edje_program_check(current_program->name, current_program, 
pc->programs.nocmp, pc->programs.nocmp_count) )
+     {
+       ERR("%s: Error. parse error %s:%i. There is already a program of the 
name %s\n",
+         progname, file_in, line - 1, current_program->name);
+       exit(-1);
 }
 
+    if (strlen(current_program->name) > priv_prefix_len &&
+       strncmp(current_program->name, "__in_program_", priv_prefix_len) != 0)
+    {
+      ERR("%s: Error. parse error %s:%i. Cannot use protected prefix as name 
%s.\n",
+       progname, file_in, line - 1, current_program->name);
+      exit(-1);
+    }
+}
+
 /**
     @page edcref
     @property
@@ -7017,6 +7037,50 @@
      }
 }
 
+static char*
+gen_random_program_name(int len)
+{
+    static const char alphanum[] = "0123456789"
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+        "abcdefghijklmnopqrstuvwxyz";
+    static const char prog_prefix[] = "__in_program_";
+
+    len = len + sizeof(prog_prefix) + 1;
+    char* s = mem_alloc(len);
+    strncpy(s, prog_prefix, sizeof(prog_prefix));
+
+    for (int i = sizeof(prog_prefix); i < len; ++i)
+      {
+        s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
+      }
+    s[len] = 0;
+
+
+    return s;
+}
+
+static char*
+unique_random_program_name(const int len)
+{
+   Edje_Part_Collection *pc = 
eina_list_data_get(eina_list_last(edje_collections));
+   char* pname = NULL;
+   while (!pname)
+   {
+      pname = gen_random_program_name(len);
+      if (_edje_program_check(pname, current_program, pc->programs.fnmatch, 
pc->programs.fnmatch_count)
+       || _edje_program_check(pname, current_program, pc->programs.strcmp, 
pc->programs.strcmp_count)
+       || _edje_program_check(pname, current_program, pc->programs.strncmp, 
pc->programs.strncmp_count)
+       || _edje_program_check(pname, current_program, pc->programs.strrncmp, 
pc->programs.strrncmp_count)
+       || _edje_program_check(pname, current_program, pc->programs.nocmp, 
pc->programs.nocmp_count) )
+       {
+          free(pname);
+          pname = NULL;
+       }
+   }
+   return pname;
+}
+
+
 static void
 ob_collections_group_programs_program_script(void)
 {
@@ -7049,6 +7113,9 @@
               }
             cd->is_lua = 0;
             cd->programs = eina_list_append(cd->programs, cp);
+             if (!current_program->name)
+                current_program->name = unique_random_program_name(5);
+
             data_queue_program_lookup(pc, current_program->name, &(cp->id));
 
             set_verbatim(NULL, 0, 0);
@@ -7088,6 +7155,9 @@
               }
             cd->is_lua = 1;
             cd->programs = eina_list_append(cd->programs, cp);
+            if (!current_program->name)
+               current_program->name = unique_random_program_name(5);
+
             data_queue_program_lookup(pc, current_program->name, &(cp->id));
             set_verbatim(NULL, 0, 0);
             current_program->action = EDJE_ACTION_TYPE_LUA_SCRIPT;
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to