changeset 3704:fa3d2a62a066

use vtable functors for VFS access
author William Pitcock <nenolod@atheme.org>
date Sun, 07 Oct 2007 13:40:45 -0500
parents 2e1a1d734112
children 38259e9394a2
files src/libid3tag/Makefile src/libid3tag/file.c
diffstat 2 files changed, 61 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/libid3tag/Makefile	Sun Oct 07 01:06:50 2007 -0500
+++ b/src/libid3tag/Makefile	Sun Oct 07 13:40:45 2007 -0500
@@ -27,6 +27,6 @@
 include ../../buildsys.mk
 include ../../extra.mk
 
-CPPFLAGS += ${LIB_CPPFLAGS} -I.. ${GLIB_CFLAGS}
+CPPFLAGS += ${LIB_CPPFLAGS} -I.. ${GLIB_CFLAGS} ${GTK_CFLAGS} ${MOWGLI_CFLAGS}
 CFLAGS += ${LIB_CFLAGS}
-LIBS += ${IMPLIB_LIBS} ${GLIB_LIBS} -lz
+LIBS += ${IMPLIB_LIBS} ${GLIB_LIBS} ${GTK_LIBS} ${MOWGLI_LIBS} -lz
--- a/src/libid3tag/file.c	Sun Oct 07 01:06:50 2007 -0500
+++ b/src/libid3tag/file.c	Sun Oct 07 13:40:45 2007 -0500
@@ -46,19 +46,17 @@
 //#undef AUDACIOUS
 
 #ifdef AUDACIOUS
-  #undef G_BEGIN_DECLS
-  #undef G_END_DECLS
-  #include <audacious/vfs.h>
+  #include <audacious/plugin.h>
 #else
   #define VFSFile FILE
-  #define vfs_fopen fopen
-  #define vfs_fclose fclose
-  #define vfs_fseek fseek
-  #define vfs_ftell ftell
-  #define vfs_rewind rewind
-  #define vfs_fread fread
-  #define vfs_fwrite fwrite
-  #define vfs_truncate(x, y) ftruncate((fileno(x)), (y))
+  #define aud_vfs_fopen fopen
+  #define aud_vfs_fclose fclose
+  #define aud_vfs_fseek fseek
+  #define aud_vfs_ftell ftell
+  #define aud_vfs_rewind rewind
+  #define aud_vfs_fread fread
+  #define aud_vfs_fwrite fwrite
+  #define aud_vfs_truncate(x, y) ftruncate((fileno(x)), (y))
 #endif
 
 struct filetag {
@@ -95,13 +93,13 @@
   id3_byte_t query[ID3_TAG_QUERYSIZE];
   signed long size;
 
-  save_position = vfs_ftell(iofile);
+  save_position = aud_vfs_ftell(iofile);
   if (save_position == -1)
     return 0;
 
-  size = id3_tag_query(query, vfs_fread(query, 1, sizeof(query), iofile));
+  size = id3_tag_query(query, aud_vfs_fread(query, 1, sizeof(query), iofile));
 
-  if(vfs_fseek(iofile, save_position, SEEK_SET) == -1)
+  if(aud_vfs_fseek(iofile, save_position, SEEK_SET) == -1)
     return 0;
 
   return size;
@@ -119,7 +117,7 @@
 
   data = malloc(size);
   if (data) {
-    if (vfs_fread(data, size, 1, iofile) == 1)
+    if (aud_vfs_fread(data, size, 1, iofile) == 1)
       tag = id3_tag_parse(data, size);
 
     free(data);
@@ -224,7 +222,7 @@
   struct filetag filetag;
   struct id3_tag *tag;
 
-  location = vfs_ftell(file->iofile);
+  location = aud_vfs_ftell(file->iofile);
   if (location == -1)
     return 0;
 
@@ -287,14 +285,14 @@
 
 //  if (fgetpos(file->iofile, &save_position) == -1 ||
 //      fsetpos(file->iofile, &save_position) == -1)
-//  if (save_position = vfs_ftell(file->iofile) == -1 ||
-//      vfs_fseek(file->iofile, save_position, SEEK_SET) == -1)
-  if((save_position = vfs_ftell(file->iofile)) == -1)
+//  if (save_position = aud_vfs_ftell(file->iofile) == -1 ||
+//      aud_vfs_fseek(file->iofile, save_position, SEEK_SET) == -1)
+  if((save_position = aud_vfs_ftell(file->iofile)) == -1)
     return -1;
 
   /* look for an ID3v1 tag */
 
-  if (vfs_fseek(file->iofile, -128, SEEK_END) == 0) {
+  if (aud_vfs_fseek(file->iofile, -128, SEEK_END) == 0) {
     size = query_tag(file->iofile);
     if (size > 0) {
       struct id3_tag const *tag;
@@ -310,7 +308,7 @@
 
   /* look for a tag at the beginning of the file */
 
-  vfs_rewind(file->iofile);
+  aud_vfs_rewind(file->iofile);
 
   size = query_tag(file->iofile);
   if (size > 0) {
@@ -325,7 +323,7 @@
       long seek;
 
       seek = id3_field_getint(id3_frame_field(frame, 0));
-      if (seek < 0 || vfs_fseek(file->iofile, seek, SEEK_CUR) == -1)
+      if (seek < 0 || aud_vfs_fseek(file->iofile, seek, SEEK_CUR) == -1)
 	break;
 
       size = query_tag(file->iofile);
@@ -335,10 +333,10 @@
 
   /* look for a tag at the end of the file (before any ID3v1 tag) */
 
-  if (vfs_fseek(file->iofile, ((file->flags & ID3_FILE_FLAG_ID3V1) ? -128 : 0) +
+  if (aud_vfs_fseek(file->iofile, ((file->flags & ID3_FILE_FLAG_ID3V1) ? -128 : 0) +
 	    -10, SEEK_END) == 0) {
     size = query_tag(file->iofile);
-    if (size < 0 && vfs_fseek(file->iofile, size, SEEK_CUR) == 0) {
+    if (size < 0 && aud_vfs_fseek(file->iofile, size, SEEK_CUR) == 0) {
       size = query_tag(file->iofile);
       if (size > 0)
 	add_tag(file, size);
@@ -351,7 +349,7 @@
 
   /* restore seek position */
 
-  if (vfs_fseek(file->iofile, save_position, SEEK_SET) == -1)
+  if (aud_vfs_fseek(file->iofile, save_position, SEEK_SET) == -1)
     return -1;
 
   /* set primary tag options and target padded length for convenience */
@@ -460,7 +458,7 @@
 
   assert(path);
 
-  iofile = vfs_fopen(path, (mode == ID3_FILE_MODE_READWRITE) ? "r+b" : "rb");
+  iofile = aud_vfs_fopen(path, (mode == ID3_FILE_MODE_READWRITE) ? "r+b" : "rb");
   if (iofile == 0){
     printf("id3_file_open: iofile failed\n");
     return 0;
@@ -468,7 +466,7 @@
   file = new_file(iofile, mode, path);
   if (file == 0){
     printf("id3_file_open: file failed\n");
-    vfs_fclose(iofile);
+    aud_vfs_fclose(iofile);
   }
 
   return file;
@@ -488,17 +486,17 @@
   
   path = iofile->uri;
 
-  vfs_dup(iofile);
+  aud_vfs_dup(iofile);
 
-  curpos = vfs_ftell(iofile);
-  vfs_fseek(iofile, 0, SEEK_SET);
+  curpos = aud_vfs_ftell(iofile);
+  aud_vfs_fseek(iofile, 0, SEEK_SET);
 
   file = new_file(iofile, mode, path);
   if (file == 0){
-    printf("id3_vfs_open: file failed\n");
+    printf("id3_file_vfsopen: file failed\n");
   }
 
-  vfs_fseek(iofile, curpos, SEEK_SET);
+  aud_vfs_fseek(iofile, curpos, SEEK_SET);
 
   return file;
 }
@@ -549,7 +547,7 @@
 
   assert(file);
 
-  if (vfs_fclose(file->iofile) == EOF)
+  if (aud_vfs_fclose(file->iofile) == EOF)
     result = -1;
 
   finish_file(file);
@@ -581,13 +579,13 @@
   if (data) {
     long location;
 
-    if (vfs_fseek(file->iofile, (file->flags & ID3_FILE_FLAG_ID3V1) ? -128 : 0,
+    if (aud_vfs_fseek(file->iofile, (file->flags & ID3_FILE_FLAG_ID3V1) ? -128 : 0,
 	      SEEK_END) == -1 ||
-	(location = vfs_ftell(file->iofile)) == -1 ||
+	(location = aud_vfs_ftell(file->iofile)) == -1 ||
 #ifdef AUDACIOUS
-	vfs_fwrite(data, 128, 1, file->iofile) != 1 )
+	aud_vfs_fwrite(data, 128, 1, file->iofile) != 1 )
 #else
-	vfs_fwrite(data, 128, 1, file->iofile) != 1 ||
+	aud_vfs_fwrite(data, 128, 1, file->iofile) != 1 ||
 	fflush(file->iofile) == EOF) //XXX
 #endif
       return -1;
@@ -611,15 +609,15 @@
   else if (file->flags & ID3_FILE_FLAG_ID3V1) {
     long length;
 
-    if (vfs_fseek(file->iofile, 0, SEEK_END) == -1)
+    if (aud_vfs_fseek(file->iofile, 0, SEEK_END) == -1)
       return -1;
 
-    length = vfs_ftell(file->iofile);
+    length = aud_vfs_ftell(file->iofile);
     if (length == -1 ||
 	(length >= 0 && length < 128))
       return -1;
 
-    if (vfs_truncate(file->iofile, length - 128) == -1)
+    if (aud_vfs_truncate(file->iofile, length - 128) == -1)
       return -1;
 
     /* delete file tag reference */
@@ -650,20 +648,20 @@
         char *remainder;
 
         /* read in the remainder of the file */
-        vfs_fseek(file->iofile, 0, SEEK_END);
-        file_size = vfs_ftell(file->iofile);
+        aud_vfs_fseek(file->iofile, 0, SEEK_END);
+        file_size = aud_vfs_ftell(file->iofile);
         remainder_size = file_size - file->tags[0].location - file->tags[0].length;
         remainder = (char*)malloc(remainder_size);
 
-        if (vfs_fseek(file->iofile, file->tags[0].location + file->tags[0].length, SEEK_SET) == -1 ||
-            vfs_fread(remainder, remainder_size, 1, file->iofile) != 1) {
+        if (aud_vfs_fseek(file->iofile, file->tags[0].location + file->tags[0].length, SEEK_SET) == -1 ||
+            aud_vfs_fread(remainder, remainder_size, 1, file->iofile) != 1) {
             free(remainder);
             return -1;
         }
 
         /* write the remainder where the old tag was */
-        if (vfs_fseek(file->iofile, file->tags[0].location, SEEK_SET) == -1 ||
-            vfs_fwrite(remainder, remainder_size, 1, file->iofile) != 1) {
+        if (aud_vfs_fseek(file->iofile, file->tags[0].location, SEEK_SET) == -1 ||
+            aud_vfs_fwrite(remainder, remainder_size, 1, file->iofile) != 1) {
             free(remainder);
             return -1;
         }
@@ -676,8 +674,8 @@
             return -1;
 #endif
         /* truncate if required */
-        if (vfs_ftell(file->iofile) < file_size)
-            vfs_truncate(file->iofile, vfs_ftell(file->iofile));
+        if (aud_vfs_ftell(file->iofile) < file_size)
+            aud_vfs_truncate(file->iofile, aud_vfs_ftell(file->iofile));
 
     }
 
@@ -713,11 +711,11 @@
   if (file->tags[0].length == length) {
     /* easy special case: rewrite existing tag in-place */
 
-    if (vfs_fseek(file->iofile, file->tags[0].location, SEEK_SET) == -1 ||
+    if (aud_vfs_fseek(file->iofile, file->tags[0].location, SEEK_SET) == -1 ||
 #ifdef AUDACIOUS
-	vfs_fwrite(data, length, 1, file->iofile) != 1)
+	aud_vfs_fwrite(data, length, 1, file->iofile) != 1)
 #else
-	vfs_fwrite(data, length, 1, file->iofile) != 1 ||
+	aud_vfs_fwrite(data, length, 1, file->iofile) != 1 ||
 	fflush(file->iofile) == EOF)
 #endif
       return -1;
@@ -730,25 +728,25 @@
     char *remainder;
 
     /* read in the remainder of the file */
-    vfs_fseek(file->iofile, 0, SEEK_END);
-    file_size = vfs_ftell(file->iofile);
+    aud_vfs_fseek(file->iofile, 0, SEEK_END);
+    file_size = aud_vfs_ftell(file->iofile);
     remainder_size = file_size - file->tags[0].location - file->tags[0].length;
     remainder = (char*)malloc(remainder_size);
-    if (vfs_fseek(file->iofile, file->tags[0].location + file->tags[0].length, SEEK_SET) == -1 ||
-	vfs_fread(remainder, remainder_size, 1, file->iofile) != 1) {
+    if (aud_vfs_fseek(file->iofile, file->tags[0].location + file->tags[0].length, SEEK_SET) == -1 ||
+	aud_vfs_fread(remainder, remainder_size, 1, file->iofile) != 1) {
 	    free(remainder);
       return -1;
     }
 
     /* write the tag where the old one was */
-    if (vfs_fseek(file->iofile, file->tags[0].location, SEEK_SET) == -1 ||
-	vfs_fwrite(data, length, 1, file->iofile) != 1) {
+    if (aud_vfs_fseek(file->iofile, file->tags[0].location, SEEK_SET) == -1 ||
+	aud_vfs_fwrite(data, length, 1, file->iofile) != 1) {
 	    free(remainder);
       return -1;
     }
 
     /* write the reaminder */
-    if (vfs_fwrite(remainder, remainder_size, 1, file->iofile) != 1) {
+    if (aud_vfs_fwrite(remainder, remainder_size, 1, file->iofile) != 1) {
       free(remainder);
       return -1;
   }
@@ -761,8 +759,8 @@
       return -1;
 #endif
     /* truncate if required */
-    if (vfs_ftell(file->iofile) < file_size)
-      vfs_truncate(file->iofile, vfs_ftell(file->iofile));
+    if (aud_vfs_ftell(file->iofile) < file_size)
+      aud_vfs_truncate(file->iofile, aud_vfs_ftell(file->iofile));
   }
 
  done:
@@ -824,7 +822,7 @@
       v1_write(file, id3v1, v1size) == -1)
     goto fail;
 
-  vfs_rewind(file->iofile);
+  aud_vfs_rewind(file->iofile);
 
   /* update file tags array? ... */