[Vorbis-dev] libvorbis: selective removal of vorbis comments

Marcel Müller mueller at maazl.de
Fri Feb 6 13:00:30 PST 2009


Hi,

I would recommend a function in vorbis/lib/info.c to allow the selective
removal of vorbis comments. Without such an interface one has to copy
all the other comment tags if only a single field should be removed.


The following function added to info.c will do the job:

/* Remove all comments with a certain field name.
  * Return the number of removed comments. */
int vorbis_comment_clear_tag(vorbis_comment *vc, const char *tag)
{ int i,count=0;
   int taglen = strlen(tag)+1; /* +1 for the = we append */
   char *fulltag = alloca(taglen+1);
   strcpy(fulltag,tag);
   strcat(fulltag, "=");

   for(i=vc->comments;i-->0;)
   { char** current = vc->user_comments+i;
     if(!tagcompare(*current, fulltag, taglen))
     { _ogg_free(*current);
       memmove(current, current+1,
         (vc->comments-i)*sizeof(*vc->user_comments));
       memmove(vc->comment_lengths+i, vc->comment_lengths+i+1,
         (vc->comments-i)*sizeof(*vc->comment_lengths));
       --vc->comments;
       count++;
     }
   }
   // reallocation required?
   if (count)
   { vc->user_comments=_ogg_realloc(vc->user_comments,
       (vc->comments+1)*sizeof(*vc->user_comments));
     vc->comment_lengths=_ogg_realloc(vc->comment_lengths,
       (vc->comments+1)*sizeof(*vc->comment_lengths));
   }

   return count;
}


Marcel



More information about the Vorbis-dev mailing list