[xiph-cvs] cvs commit: vorbis-tools/oggenc encode.h oggenc.c platform.c

Michael Smith msmith at xiph.org
Sun Jan 27 22:29:23 PST 2002



msmith      02/01/27 22:29:23

  Modified:    oggenc   encode.h oggenc.c platform.c
  Log:
  Commit 'fix' for bug #140 (enhancement).
  oggenc can now (not on win32, yet) create subdirectories for the output file on the fly.

Revision  Changes    Path
1.16      +1 -0      vorbis-tools/oggenc/encode.h

Index: encode.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/encode.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- encode.h	2002/01/27 06:21:48	1.15
+++ encode.h	2002/01/28 06:29:22	1.16
@@ -19,6 +19,7 @@
 void *timer_start(void);
 double timer_time(void *);
 void timer_clear(void *);
+int create_directories(char *);
 
 void update_statistics_full(char *fn, long total, long done, double time);
 void update_statistics_notime(char *fn, long total, long done, double time);

<p><p>1.47      +10 -2     vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- oggenc.c	2002/01/28 05:38:14	1.46
+++ oggenc.c	2002/01/28 06:29:22	1.47
@@ -249,6 +249,15 @@
                 out_fn = strdup("default.ogg");
             }
 
+            /* Create any missing subdirectories, if possible */
+            if(create_directories(out_fn)) {
+                if(closein)
+                    fclose(in);
+				fprintf(stderr, _("ERROR: Could not create required subdirectories for output filename \"%s\"\n"), out_fn);
+				errors++;
+				free(out_fn);
+				continue;
+            }
 
                         out = fopen(out_fn, "wb");
                         if(out == NULL)
@@ -318,7 +327,7 @@
 static void usage(void)
 {
         fprintf(stdout, 
-		_("\n"
+		_("%s%s\n"
                 "Usage: oggenc [options] input.wav [...]\n"
                 "\n"
                 "OPTIONS:\n"
@@ -795,5 +804,4 @@
                 add_tag(vc, opt, "tracknumber", opt->tracknum[i]);
         }
 }
-
 

<p><p>1.6       +51 -0     vorbis-tools/oggenc/platform.c

Index: platform.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/platform.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- platform.c	2001/02/20 08:12:50	1.5
+++ platform.c	2002/01/28 06:29:22	1.6
@@ -14,6 +14,7 @@
 
 #include "platform.h"
 #include "encode.h"
+#include "i18n.h"
 #include <stdlib.h>
 #if defined(_WIN32) || defined(__EMX__) || defined(__WATCOMC__)
 #include <fcntl.h>
@@ -66,10 +67,20 @@
         free((time_t *)timer);
 }
 
+int create_directories(char *fn) 
+{
+    /* FIXME: Please implement me */
+    return 0;
+}
+
 #else /* unix. Or at least win32 */
 
 #include <sys/time.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
 
 void *timer_start(void)
 {
@@ -93,6 +104,46 @@
 {
         free((time_t *)timer);
 }
+
+int create_directories(char *fn)
+{
+    char *end, *start;
+    struct stat statbuf;
+    char segment[FILENAME_MAX];
+
+    start = fn;
+
+    while((end = strchr(start+1, '/')) != NULL)
+    {
+        memcpy(segment, fn, end-fn);
+        segment[end-fn+1] = 0;
+
+        if(stat(segment,&statbuf)) {
+            if(errno == ENOENT) {
+                if(mkdir(segment, 0777)) {
+                    fprintf(stderr, _("Couldn't create directory \"%s\": %s\n"),
+                                segment, strerror(errno));
+                    return -1;
+                }
+            }
+            else {
+                fprintf(stderr, _("Error checking for existence of directory %s: %s\n"), 
+                            segment, strerror(errno));
+                return -1;
+            }
+        }
+        else if(!S_ISDIR(statbuf.st_mode)) {
+            fprintf(stderr, _("Error: path segment \"%s\" is not a directory\n"),
+                    segment);
+        }
+
+        start = end+1;
+    }
+
+    return 0;
+
+}
+
 #endif
 
 

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list