[xiph-commits] r16422 - trunk/theora/examples

j at svn.xiph.org j at svn.xiph.org
Wed Aug 5 10:49:43 PDT 2009


Author: j
Date: 2009-08-05 10:49:42 -0700 (Wed, 05 Aug 2009)
New Revision: 16422

Modified:
   trunk/theora/examples/png2theora.c
Log:
make png2theora compile with mingw32:
 add local implementation of alphasort and scandir



Modified: trunk/theora/examples/png2theora.c
===================================================================
--- trunk/theora/examples/png2theora.c	2009-08-05 17:28:35 UTC (rev 16421)
+++ trunk/theora/examples/png2theora.c	2009-08-05 17:49:42 UTC (rev 16422)
@@ -143,6 +143,50 @@
   exit(0);
 }
 
+#ifdef WIN32
+int
+alphasort (const void *a, const void *b)
+{
+  return strcoll ((*(const struct dirent **) a)->d_name,
+                  (*(const struct dirent **) b)->d_name);
+}
+
+int
+scandir (const char *dir, struct dirent ***namelist,
+         int (*select)(const struct dirent *), int (*compar)(const void *, const void *))
+{
+  DIR *d;
+  struct dirent *entry;
+  register int i=0;
+  size_t entrysize;
+
+  if ((d=opendir(dir)) == NULL)
+    return(-1);
+
+  *namelist=NULL;
+  while ((entry=readdir(d)) != NULL)
+  {
+    if (select == NULL || (select != NULL && (*select)(entry)))
+    {
+      *namelist=(struct dirent **)realloc((void *)(*namelist),
+                 (size_t)((i+1)*sizeof(struct dirent *)));
+      if (*namelist == NULL) return(-1);
+      entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;
+      (*namelist)[i]=(struct dirent *)malloc(entrysize);
+      if ((*namelist)[i] == NULL) return(-1);
+        memcpy((*namelist)[i], entry, entrysize);
+      i++;
+    }
+  }
+  if (closedir(d)) return(-1);
+  if (i == 0) return(-1);
+  if (compar != NULL)
+    qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar);
+    
+  return(i);
+}
+#endif
+
 static int
 theora_write_frame(unsigned long w, unsigned long h, unsigned char *yuv, int last)
 {
@@ -605,7 +649,7 @@
 
 #ifdef DEBUG
   fprintf(stderr, "scanning %s with filter '%s'\n",
-	input_directory, input_filter);
+  input_directory, input_filter);
 #endif
   n = scandir (input_directory, &png_files, include_files, alphasort);
 



More information about the commits mailing list