Enlightenment CVS committal

Author  : sebastid
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_desktop


Modified Files:
        ecore_desktop.c 


Log Message:
Bail early on error

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_desktop/ecore_desktop.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -3 -r1.40 -r1.41
--- ecore_desktop.c     23 Sep 2006 08:06:52 -0000      1.40
+++ ecore_desktop.c     23 Sep 2006 08:23:29 -0000      1.41
@@ -192,294 +192,266 @@
    if (!result)
      {
        result = calloc(1, sizeof(Ecore_Desktop));
-       if (result)
+       if (!result) goto error;
+       result->ondisk = 1;
+       result->original_path = strdup(file);
+       if (lang)
+         result->original_lang = strdup(lang);
+       result->data = ecore_desktop_ini_get(result->original_path);
+       if (!result->data)
          {
-            result->ondisk = 1;
-            result->original_path = strdup(file);
-            if (lang)
-               result->original_lang = strdup(lang);
-            result->data = ecore_desktop_ini_get(result->original_path);
-            /* Timestamp the cache, and no need to stat the file twice if the 
cache was stale. */
-            if ((stated) || (stat(result->original_path, &st) >= 0))
-               result->mtime = st.st_mtime;
-            if (result->data)
+            free(result);
+            result = NULL;
+            goto error;
+         }
+       /* Timestamp the cache, and no need to stat the file twice if the cache 
was stale. */
+       if ((stated) || (stat(result->original_path, &st) >= 0))
+         result->mtime = st.st_mtime;
+       result->group = ecore_hash_get(result->data, "Desktop Entry");
+       if (!result->group)
+         result->group = ecore_hash_get(result->data, "KDE Desktop Entry");
+       if (result->group)
+         {
+            char               *eap_name = NULL;
+            char               *exe = NULL;
+            char               *categories = NULL;
+            int                 size = 0;
+
+            value = ecore_file_get_file(result->original_path);
+            if (value)
+              {
+                 char *temp;
+
+                 temp = strrchr(value, '.');
+
+                 if (temp) *temp = '\0';
+                 result->eap_name = malloc(strlen(value) + 5);
+                 if (result->eap_name)
+                   sprintf(result->eap_name, "%s.edj", value);
+                 if (temp) *temp = '.';
+              }
+            eap_name = result->eap_name;
+
+            IFGETDUP(value, "Name", result->name);
+            IFGETDUP(value, "GenericName", result->generic);
+            IFGETDUP(value, "Comment", result->comment);
+            IFGETDUP(value, "Type", result->type);
+
+            IFGETDUP(value, "Path", result->path);
+            IFGETDUP(value, "URL", result->URL);
+            IFGETDUP(value, "File", result->file);
+
+            IFGETDUP(value, "Exec", result->exec);
+            if (result->exec)
               {
-                 result->group =
-                    (Ecore_Hash *) ecore_hash_get(result->data,
-                                                  "Desktop Entry");
-                 if (!result->group)
-                    result->group =
-                       (Ecore_Hash *) ecore_hash_get(result->data,
-                                                     "KDE Desktop Entry");
-                 if (result->group)
+                 exe = strchr(result->exec, ' ');
+                 if (exe)
                    {
-                      char               *eap_name = NULL;
-                      char               *exe = NULL;
-                      char               *categories = NULL;
-                      int                 size = 0;
-
-                      value =
-                         (char *)ecore_file_get_file(result->original_path);
-                      if (value)
-                        {
-                           char               *temp = strrchr(value, '.');
+                      *exe = '\0';
+                      result->exec_params = ++exe;
+                   }
+                 exe = result->exec;
+              }
 
-                           if (temp)
-                              *temp = '\0';
-                           result->eap_name = malloc(strlen(value) + 5);
-                           if (result->eap_name)
-                              sprintf(result->eap_name, "%s.edj", value);
-                           if (temp)
-                              *temp = '.';
-                        }
-                      eap_name = result->eap_name;
+            IFGETDUP(value, "StartupWMClass", result->window_class);
+            if ((!value) && (result->exec))
+              {
+                 char               *tmp;
 
-                      IFGETDUP(value, "Name", result->name);
-                      IFGETDUP(value, "GenericName", result->generic);
-                      IFGETDUP(value, "Comment", result->comment);
-                      IFGETDUP(value, "Type", result->type);
-
-                      IFGETDUP(value, "Path", result->path);
-                      IFGETDUP(value, "URL", result->URL);
-                      IFGETDUP(value, "File", result->file);
+                 /* Guess - exe name with first letter capitalized. */
+                 tmp = strdup(result->exec);
+                 if (tmp)
+                   {
+                      char               *p;
 
-                      IFGETDUP(value, "Exec", result->exec);
-                      if (result->exec)
+                      value = (char *)ecore_file_get_file(tmp);        /* In 
case the exe included a path. */
+                      p = value;
+                      while ((*p != '\0') && (*p != ' '))
                         {
-                           exe = strchr(result->exec, ' ');
-                           if (exe)
-                             {
-                                *exe = '\0';
-                                result->exec_params = ++exe;
-                             }
-                           exe = result->exec;
+                           *p = tolower(*p);
+                           p++;
                         }
+                      *p = '\0';
+                      *value = toupper(*value);
+                      result->window_class = strdup(value);
+                      free(tmp);
+                   }
+              }
+            IFGETDUP(value, "X-Enlightenment-WindowName", result->window_name);
+            IFGETDUP(value, "X-Enlightenment-WindowTitle", 
result->window_title);
+            IFGETDUP(value, "X-Enlightenment-WindowRole", result->window_role);
+
+            IFGETDUP(value, "Icon", result->icon);
+            IFGETDUP(value, "X-Enlightenment-IconTheme", result->icon_theme);
+            IFGETDUP(value, "X-Enlightenment-IconClass", result->icon_class);
+            IFGETDUP(value, "X-Enlightenment-IconPath", result->icon_path);
 
-                      IFGETDUP(value, "StartupWMClass", result->window_class);
-                      if ((!value) && (result->exec))
+            if ((result->icon != NULL) && (result->icon_path == NULL) &&
+                (strchr(result->icon, '/') != NULL))
+              {
+                 if (result->icon[0] == '/')
+                   {
+                      result->icon_path = strdup(result->icon);
+                   }
+                 else  /* It's a relative path. */
+                   {
+                      char               *temp;
+
+                      size =
+                         strlen(result->original_path) +
+                         strlen(result->icon) + 2;
+                      temp = malloc(size);
+                      if (temp)
                         {
-                           char               *tmp;
+                           char               *dir;
 
-                           /* Guess - exe name with first letter capitalized. 
*/
-                           tmp = strdup(result->exec);
-                           if (tmp)
+                           dir =
+                              ecore_file_get_dir(result->original_path);
+                           if (dir)
                              {
-                                char               *p;
-
-                                value = (char *)ecore_file_get_file(tmp);      
/* In case the exe included a path. */
-                                p = value;
-                                while ((*p != '\0') && (*p != ' '))
-                                  {
-                                     *p = tolower(*p);
-                                     p++;
-                                  }
-                                *p = '\0';
-                                *value = toupper(*value);
-                                result->window_class = strdup(value);
-                                free(tmp);
+                                sprintf(temp, "%s/%s", dir, result->icon);
+                                result->icon_path =
+                                   ecore_file_realpath(temp);
+                                free(dir);
                              }
+                           free(temp);
                         }
-                      IFGETDUP(value, "X-Enlightenment-WindowName",
-                               result->window_name);
-                      IFGETDUP(value, "X-Enlightenment-WindowTitle",
-                               result->window_title);
-                      IFGETDUP(value, "X-Enlightenment-WindowRole",
-                               result->window_role);
-
-                      IFGETDUP(value, "Icon", result->icon);
-                      IFGETDUP(value, "X-Enlightenment-IconTheme",
-                               result->icon_theme);
-                      IFGETDUP(value, "X-Enlightenment-IconClass",
-                               result->icon_class);
-                      IFGETDUP(value, "X-Enlightenment-IconPath",
-                               result->icon_path);
-
-                      if ((result->icon != NULL) && (result->icon_path == NULL)
-                          && (strchr(result->icon, '/') != NULL))
-                        {
-                           if (result->icon[0] == '/')
-                             {
-                                result->icon_path = strdup(result->icon);
-                             }
-                           else        /* It's a relative path. */
-                             {
-                                char               *temp;
+                   }
+              }
 
-                                size =
-                                   strlen(result->original_path) +
-                                   strlen(result->icon) + 2;
-                                temp = malloc(size);
-                                if (temp)
-                                  {
-                                     char               *dir;
+            IFGETDUP(value, "Categories", result->categories);
+            if (result->categories)
+              result->Categories =
+                 ecore_desktop_paths_to_hash(result->categories);
+            categories = result->categories;
+
+            value = ecore_hash_get(result->group, "OnlyShowIn");
+            if (value)
+              result->OnlyShowIn =
+                 ecore_desktop_paths_to_hash(value);
+            value = ecore_hash_get(result->group, "NotShowIn");
+            if (value)
+              result->NotShowIn =
+                 ecore_desktop_paths_to_hash(value);
+            value = ecore_hash_get(result->group, "X-KDE-StartupNotify");
+            if (value)
+              result->startup = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "StartupNotify");
+            if (value)
+              result->startup = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "X-Enlightenment-WaitExit");
+            if (value)
+              result->wait_exit = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "NoDisplay");
+            if (value)
+              result->no_display = (strcmp(value, "true") == 0);
+            value = ecore_hash_get(result->group, "Hidden");
+            if (value)
+              result->hidden = (strcmp(value, "true") == 0);
+
+            /*
+             *    icon/class is a list of standard icons from the theme that 
can override the icon created above.
+             *    Use (from .desktop) eap name,exe name,categories.  It's case 
sensitive, the reccomendation is to lowercase it.
+             *    It should be most specific to most generic.  
firefox,browser,internet for instance
+             */
+
+            /* If the icon in the file is not a full path, just put it first 
in the class, greatly simplifies things. 
+             * Otherwise, put that full path into the icon_path member.
+             */
+            if (!result->icon_class)
+              {
+                 size = 0;
+                 if ((result->icon) && (strchr(result->icon, '/') == NULL))
+                   size += strlen(result->icon) + 1;
+                 if (eap_name)
+                   size += strlen(eap_name) + 1;
+                 if (exe)
+                   size += strlen(exe) + 1;
+                 if (categories)
+                   size += strlen(categories) + 1;
+                 result->icon_class = malloc(size + 1);
+                 if (result->icon_class)
+                   {
+                      char               *p;
+                      int                 done = 0;
 
-                                     dir =
-                                        ecore_file_get_dir(result->
-                                                           original_path);
-                                     if (dir)
-                                       {
-                                          sprintf(temp, "%s/%s", dir,
-                                                  result->icon);
-                                          result->icon_path =
-                                             ecore_file_realpath(temp);
-                                          free(dir);
-                                       }
-                                     free(temp);
-                                  }
-                             }
+                      result->icon_class[0] = '\0';
+                      if ((result->icon) && (strchr(result->icon, '/') == 
NULL) &&
+                          (result->icon[0] != '\0'))
+                        {
+                           strcat(result->icon_class, result->icon);
+                           done = 1;
                         }
-
-                      IFGETDUP(value, "Categories", result->categories);
-                      if (result->categories)
-                         result->Categories =
-                            ecore_desktop_paths_to_hash(result->categories);
-                      categories = result->categories;
-
-                      value =
-                         (char *)ecore_hash_get(result->group, "OnlyShowIn");
-                      if (value)
-                         result->OnlyShowIn =
-                            ecore_desktop_paths_to_hash(value);
-                      value =
-                         (char *)ecore_hash_get(result->group, "NotShowIn");
-                      if (value)
-                         result->NotShowIn =
-                            ecore_desktop_paths_to_hash(value);
-                      value =
-                         (char *)ecore_hash_get(result->group,
-                                                "X-KDE-StartupNotify");
-                      if (value)
-                         result->startup = (strcmp(value, "true") == 0);
-                      value =
-                         (char *)ecore_hash_get(result->group,
-                                                "StartupNotify");
-                      if (value)
-                         result->startup = (strcmp(value, "true") == 0);
-                      value =
-                         (char *)ecore_hash_get(result->group,
-                                                "X-Enlightenment-WaitExit");
-                      if (value)
-                         result->wait_exit = (strcmp(value, "true") == 0);
-                      value =
-                         (char *)ecore_hash_get(result->group, "NoDisplay");
-                      if (value)
-                         result->no_display = (strcmp(value, "true") == 0);
-                      value = (char *)ecore_hash_get(result->group, "Hidden");
-                      if (value)
-                         result->hidden = (strcmp(value, "true") == 0);
-
-/*
- *    icon/class is a list of standard icons from the theme that can override 
the icon created above.
- *    Use (from .desktop) eap name,exe name,categories.  It's case sensitive, 
the reccomendation is to lowercase it.
- *    It should be most specific to most generic.  firefox,browser,internet 
for instance
-*/
-
-                      /* If the icon in the file is not a full path, just put 
it first in the class, greatly simplifies things. 
-                       * Otherwise, put that full path into the icon_path 
member.
-                       */
-                      if (!result->icon_class)
+                      /* We do this here coz we don't want to lower case the 
result->icon part later. */
+                      p = result->icon_class;
+                      p += strlen(result->icon_class);
+                      if ((eap_name) && (eap_name[0] != '\0'))
                         {
-                           size = 0;
-                           if ((result->icon) && (strchr(result->icon, '/') == 
NULL))
-                              size += strlen(result->icon) + 1;
-                           if (eap_name)
-                              size += strlen(eap_name) + 1;
-                           if (exe)
-                              size += strlen(exe) + 1;
-                           if (categories)
-                              size += strlen(categories) + 1;
-                           result->icon_class = malloc(size + 1);
-                           if (result->icon_class)
+                           if (done)
+                             strcat(result->icon_class, ",");
+                           strcat(result->icon_class, eap_name);
+                           done = 1;
+                        }
+                      if ((exe) && (exe[0] != '\0'))
+                        {
+                           char               *tmp;
+
+                           tmp = strdup(ecore_file_get_file(exe));
+                           if (tmp)
                              {
-                                char               *p;
-                                int                 done = 0;
+                                char               *p2;
 
-                                result->icon_class[0] = '\0';
-                                if ((result->icon) && (strchr(result->icon, 
'/') == NULL)
-                                    && (result->icon[0] != '\0'))
-                                  {
-                                     strcat(result->icon_class, result->icon);
-                                     done = 1;
-                                  }
-                                /* We do this here coz we don't want to lower 
case the result->icon part later. */
-                                p = result->icon_class;
-                                p += strlen(result->icon_class);
-                                if ((eap_name) && (eap_name[0] != '\0'))
+                                p2 = tmp;
+                                while (*p2 != '\0')
                                   {
-                                     if (done)
-                                        strcat(result->icon_class, ",");
-                                     strcat(result->icon_class, eap_name);
-                                     done = 1;
-                                  }
-                                if ((exe) && (exe[0] != '\0'))
-                                  {
-                                     char               *tmp;
-
-                                     tmp = strdup(ecore_file_get_file(exe));
-                                     if (tmp)
+                                     if (*p2 == ' ')
                                        {
-                                          char               *p2;
-
-                                          p2 = tmp;
-                                          while (*p2 != '\0')
-                                            {
-                                               if (*p2 == ' ')
-                                                 {
-                                                    *p2 = '\0';
-                                                    break;
-                                                 }
-                                               p2++;
-                                            }
-                                          if (done)
-                                             strcat(result->icon_class, ",");
-                                          strcat(result->icon_class, tmp);
-                                          done = 1;
-                                          free(tmp);
+                                          *p2 = '\0';
+                                          break;
                                        }
+                                     p2++;
                                   }
-                                if ((categories) && (categories[0] != '\0'))
-                                  {
-                                     if (done)
-                                        strcat(result->icon_class, ",");
-                                     strcat(result->icon_class, categories);
-                                     done = 1;
-                                  }
-                                while (*p != '\0')
-                                  {
-                                     if (*p == ';')
-                                        *p = ',';
-                                     else
-                                        *p = tolower(*p);
-                                     p++;
-                                  }
+                                if (done)
+                                  strcat(result->icon_class, ",");
+                                strcat(result->icon_class, tmp);
+                                done = 1;
+                                free(tmp);
                              }
                         }
-                   }
-                 else
-                   {
-                      /*Maybe it's a 'trash' file - which also follows the 
Desktop FDO spec */
-                      result->group =
-                         (Ecore_Hash *) ecore_hash_get(result->data,
-                                                       "Trash Info");
-                      if (result->group)
+                      if ((categories) && (categories[0] != '\0'))
+                        {
+                           if (done)
+                             strcat(result->icon_class, ",");
+                           strcat(result->icon_class, categories);
+                           done = 1;
+                        }
+                      while (*p != '\0')
                         {
-                           IFGETDUP(value, "Path", result->path);
-                           IFGETDUP(value, "DeletionDate",
-                                    result->deletiondate);
+                           if (*p == ';')
+                             *p = ',';
+                           else
+                             *p = tolower(*p);
+                           p++;
                         }
                    }
-
-                 ecore_hash_set(desktop_cache, strdup(result->original_path),
-                                result);
               }
-            else
+         }
+       else
+         {
+            /*Maybe it's a 'trash' file - which also follows the Desktop FDO 
spec */
+            result->group = ecore_hash_get(result->data, "Trash Info");
+            if (result->group)
               {
-                 free(result);
-                 result = NULL;
+                 IFGETDUP(value, "Path", result->path);
+                 IFGETDUP(value, "DeletionDate",
+                       result->deletiondate);
               }
          }
+
+       ecore_hash_set(desktop_cache, strdup(result->original_path), result);
      }
 
+error:
    if (result)
      {
         if (in_cache)



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to