[Mplayer-cvslog] CVS: main/libvo vo_jpeg.c,1.16,1.17

Ivo van Poorten CVS syncmail at mplayerhq.hu
Wed Sep 8 03:11:18 CEST 2004


CVS change done by Ivo van Poorten CVS

Update of /cvsroot/mplayer/main/libvo
In directory mail:/var2/tmp/cvs-serv2184/libvo

Modified Files:
	vo_jpeg.c 
Log Message:
This patch moves the directory creation code to a separate function. I have
tried to re-use as much code as possible, to reduce the size of the patch.
All duplicate code is removed, resulting in my first patch that actually
decreases the size of the binary by about 700 bytes :-)



Index: vo_jpeg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_jpeg.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- vo_jpeg.c	5 Sep 2004 17:54:09 -0000	1.16
+++ vo_jpeg.c	8 Sep 2004 01:11:16 -0000	1.17
@@ -80,18 +80,23 @@
 
 /* ------------------------------------------------------------------------- */
 
-static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
-                       uint32_t d_height, uint32_t fullscreen, char *title,
-                       uint32_t format)
-{
-    char buf[BUFLENGTH];
+/** \brief Create a directory.
+ *
+ *  This function creates a directory. If it already exists, it tests if
+ *  it's a directory and not something else, and if it is, it tests whether
+ *  the directory is writable or not.
+ *
+ * \param buf       Pointer to directory name.
+ * \param verbose   Verbose on success. If verbose is non-zero, it will print
+ *                  a message if it was successful in creating the directory.
+ *
+ * \return nothing  In case anything fails, the player will exit. If it
+ *                  returns, everything went well.
+ */
+
+void jpeg_mkdir(char *buf, int verbose) { 
     struct stat stat_p;
 
-    /* Create outdir.
-     * If it already exists, test if it's a writable directory */ 
-    
-    snprintf(buf, BUFLENGTH, "%s", jpeg_outdir);
- 
     if ( mkdir(buf, 0755) < 0 ) {
         switch (errno) { /* use switch in case other errors need to be caught
                             and handled in the future */
@@ -109,26 +114,42 @@
                     exit_player(MSGTR_Exit_error);
                 }
                 if ( !(stat_p.st_mode & S_IWUSR) ) {
-                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
-                            MSGTR_VO_JPEG_DirExistsButNotWritable);
+                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
+                            buf, MSGTR_VO_JPEG_DirExistsButNotWritable);
                     exit_player(MSGTR_Exit_error);
                 }
                 
-                mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
-                        MSGTR_VO_JPEG_DirExistsAndIsWritable);
+                mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
+                        buf, MSGTR_VO_JPEG_DirExistsAndIsWritable);
                 break;
 
             default:
                 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
                         MSGTR_VO_JPEG_GenericError, strerror(errno) );
-                mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
-                        MSGTR_VO_JPEG_CantCreateDirectory);
+                mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
+                        buf, MSGTR_VO_JPEG_CantCreateDirectory);
                 exit_player(MSGTR_Exit_error);
         } /* end switch */
-    } else {  
-        mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
-                MSGTR_VO_JPEG_DirectoryCreateSuccess);
+    } else if ( verbose ) {  
+        mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
+                buf, MSGTR_VO_JPEG_DirectoryCreateSuccess);
     } /* end if */
+}
+
+/* ------------------------------------------------------------------------- */
+
+static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
+                       uint32_t d_height, uint32_t fullscreen, char *title,
+                       uint32_t format)
+{
+    char buf[BUFLENGTH];
+
+    /* Create outdir. */
+    
+    snprintf(buf, BUFLENGTH, "%s", jpeg_outdir);
+ 
+    jpeg_mkdir(buf, 1); /* This function only returns if creation was
+                           successful. If not, the player will exit. */
 
     image_height = height;
     image_width = width;
@@ -210,48 +231,9 @@
         snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs,
                                                             ++subdircounter);
         snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname);
-        if ( mkdir(buf, 0755) < 0 ) {
-            switch (errno) { /* use switch in case other errors need to be
-                                caught and handled in the future */
-                case EEXIST:
-                    if ( stat(buf, &stat_p) < 0 ) {
-                        mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
-                                info.short_name, MSGTR_VO_JPEG_GenericError,
-                                strerror(errno) );
-                        mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n",
-                                info.short_name, MSGTR_VO_JPEG_UnableToAccess,
-                                buf);
-                        exit_player(MSGTR_Exit_error);
-                    }
-                    if ( !S_ISDIR(stat_p.st_mode) ) {
-                        mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n",
-                                info.short_name, buf,
-                                MSGTR_VO_JPEG_ExistsButNoDirectory);
-                        exit_player(MSGTR_Exit_error);
-                    }
-                    if ( !(stat_p.st_mode & S_IWUSR) ) {
-                        mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n",
-                                info.short_name, buf,
-                                MSGTR_VO_JPEG_DirExistsButNotWritable);
-                        exit_player(MSGTR_Exit_error);
-                    }
-                    
-                    mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n",
-                            info.short_name, buf,
-                            MSGTR_VO_JPEG_DirExistsAndIsWritable);
-                    break;
-                    
-                default:
-                    mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
-                            MSGTR_VO_JPEG_GenericError, strerror(errno) );
-                    mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n",
-                            info.short_name, buf,
-                            MSGTR_VO_JPEG_CantCreateDirectory);
-                    exit_player(MSGTR_Exit_error);
-                    break;
-            }
-        } /* switch */
-    } /* if !framecounter && jpeg_subdirs */
+        jpeg_mkdir(buf, 0); /* This function only returns if creation was
+                               successful. If not, the player will exit. */
+    }
     
     framenum++;
 




More information about the MPlayer-cvslog mailing list