Enlightenment CVS committal

Author  : devilhorns
Project : e17
Module  : apps/emprint

Dir     : e17/apps/emprint/src/bin


Modified Files:
        main.c 


Log Message:
Add trap in case user only passes in a directory without a filename.

===================================================================
RCS file: /cvs/e/e17/apps/emprint/src/bin/main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- main.c      29 Dec 2007 18:02:16 -0000      1.2
+++ main.c      29 Dec 2007 18:37:33 -0000      1.3
@@ -257,59 +257,71 @@
      strftime(buf, sizeof(buf), "%Y-%m-%d-%H%M%S.png", loctime);
    else 
      {
-       /* filename was given, check for '%' signs to 
-        * format based on strftime */
-       if (strstr(opts->filename, "%")) 
-         strftime(buf, sizeof(buf), opts->filename, loctime);
+       if (ecore_file_is_dir(opts->filename)) 
+         {
+            strftime(buf, sizeof(buf), "%Y-%m-%d-%H%M%S.png", loctime);
+            /* set the new filename */
+            snprintf(buf, sizeof(buf), "%s/%s", opts->filename, strdup(buf));
+            if (opts->filename) evas_stringshare_del(opts->filename);
+            opts->filename = evas_stringshare_add(buf);
+            return;
+         }
        else 
          {
-            /* no '%' signs, check for files existing in the directory */
-            if (ecore_file_exists(opts->filename)) 
+            /* filename was given, check for '%' signs to 
+             * format based on strftime */
+            if (strstr(opts->filename, "%")) 
+              strftime(buf, sizeof(buf), opts->filename, loctime);
+            else 
               {
-                 /* get the directory */
-                 dir = ecore_file_dir_get(opts->filename);
-
-                 /* get the filename */
-                 f = ecore_file_file_get(opts->filename);
-
-                 /* if these two match, then no dir was passed in,
-                  * use current dir */
-                 if (!strcmp(dir, f)) dir = getenv("PWD");
-
-                 /* strip the extension for searches */
-                 ext = ecore_file_strip_ext(opts->filename);
-
-                 /* list files in this directory & count them */
-                 fl = ecore_file_ls(dir);
-                 ecore_list_first_goto(fl);
-                 while ((file = ecore_list_next(fl)) != NULL) 
-                   {
-                      /* skip "thumb" files in the count */
-                      if (strstr(file, "thumb")) continue;
-                      if (strstr(file, ext)) c++;
-                   }
-
-                 /* destroy the file list */
-                 if (fl) ecore_list_destroy(fl);
-
-                 /* assemble new filename based on count */
-                 if (c > 0) 
+                 /* no '%' signs, check for files existing in the directory */
+                 if (ecore_file_exists(opts->filename)) 
                    {
-                      c++;
-
-                      /* strip the extension from filename */
-                      file = ecore_file_strip_ext(opts->filename);
+                      /* get the directory */
+                      dir = ecore_file_dir_get(opts->filename);
 
-                      /* get the actual extension */
-                      ext = strrchr(opts->filename, '.');
-                      if (!ext) ext = strdup(".png");
+                      /* get the filename */
+                      f = ecore_file_file_get(opts->filename);
 
-                      /* assemble new filename */
-                      snprintf(buf, sizeof(buf), "%s%i%s", file, c, ext);
+                      /* if these two match, then no dir was passed in,
+                       * use current dir */
+                      if (!strcmp(dir, f)) dir = getenv("PWD");
+
+                      /* strip the extension for searches */
+                      ext = ecore_file_strip_ext(opts->filename);
+
+                      /* list files in this directory & count them */
+                      fl = ecore_file_ls(dir);
+                      ecore_list_first_goto(fl);
+                      while ((file = ecore_list_next(fl)) != NULL) 
+                        {
+                           /* skip "thumb" files in the count */
+                           if (strstr(file, "thumb")) continue;
+                           if (strstr(file, ext)) c++;
+                        }
+
+                      /* destroy the file list */
+                      if (fl) ecore_list_destroy(fl);
+
+                      /* assemble new filename based on count */
+                      if (c > 0) 
+                        {
+                           c++;
+
+                           /* strip the extension from filename */
+                           file = ecore_file_strip_ext(opts->filename);
+
+                           /* get the actual extension */
+                           ext = strrchr(opts->filename, '.');
+                           if (!ext) ext = strdup(".png");
+
+                           /* assemble new filename */
+                           snprintf(buf, sizeof(buf), "%s%i%s", file, c, ext);
+                        }
+                      else return;
                    }
                  else return;
               }
-            else return;
          }
      }
    /* set the new filename */



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to