OSDN Git Service

Import vorbiscomment
authorStarg <starg@users.osdn.me>
Thu, 6 Feb 2020 20:38:38 +0000 (05:38 +0900)
committerStarg <starg@users.osdn.me>
Thu, 6 Feb 2020 20:54:43 +0000 (05:54 +0900)
vorbis-tools/AUTHORS [new file with mode: 0644]
vorbis-tools/COPYING [new file with mode: 0644]
vorbis-tools/README [new file with mode: 0644]
vorbis-tools/include/i18n.h [new file with mode: 0644]
vorbis-tools/vorbiscomment/vcedit.c [new file with mode: 0644]
vorbis-tools/vorbiscomment/vcedit.h [new file with mode: 0644]
vorbis-tools/vorbiscomment/vceditaux.h [new file with mode: 0644]

diff --git a/vorbis-tools/AUTHORS b/vorbis-tools/AUTHORS
new file mode 100644 (file)
index 0000000..ec3cf6e
--- /dev/null
@@ -0,0 +1,22 @@
+oggenc:
+Michael Smith <msmith@xiph.org>
+
+oggdec:
+Michael Smith <msmith@xiph.org>
+
+ogg123:
+Kenneth Arnold <kcarnold-xiph@arnoldnet.net>
+Stan Seibert <volsung@xiph.org>
+Segher Boessenkool <segher@xiph.org>
+
+ogginfo:
+Michael Smith <msmith@xiph.org>
+
+vcut:
+Michael Smith <msmith@xiph.org>
+Michael Gold <mgold@ncf.ca>
+
+vorbiscomment:
+Michael Smith <msmith@xiph.org>
+
+and the rest of the Xiph.Org Foundation and its contributors.
\ No newline at end of file
diff --git a/vorbis-tools/COPYING b/vorbis-tools/COPYING
new file mode 100644 (file)
index 0000000..d60c31a
--- /dev/null
@@ -0,0 +1,340 @@
+                   GNU GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+\f
+                   GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+\f
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+\f
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+\f
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                           NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+           How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year  name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/vorbis-tools/README b/vorbis-tools/README
new file mode 100644 (file)
index 0000000..53488c1
--- /dev/null
@@ -0,0 +1,102 @@
+WHAT'S HERE:
+
+This source distribution includes the vorbis-tools and nothing else.
+The audio codec libraries for use with Ogg bitstreams are contained in
+other modules: vorbis, speex and flac.
+
+
+DIRECTORIES:
+
+debian/                debian packaging stuff
+include/       header files shared between the tools
+intl/          GNU gettext library from gettext-0.10.40 (for i18n support)
+ogg123/                an ogg vorbis command line audio player
+oggenc/                the ogg vorbis encoder
+oggdec/                a simple, portable command line decoder (to wav and raw)
+ogginfo/       provides information (tags, bitrate, length, etc.) about
+               an ogg vorbis file
+po/            translations for non-English languages
+share/         code shared between the tools
+vcut/          cuts an ogg vorbis file into two parts at a particular point
+vorbiscomment/ edits the comments in an ogg vorbis file
+win32/         Win32 build stuff
+
+
+DEPENDENCIES:
+
+All of the tools require libogg and libvorbis to be installed (along
+with the header files).  Additionally, ogg123 requires libao, libcurl,
+and a POSIX-compatible thread library.  Ogg123 can optionally compiled
+to use libFLAC, and libspeex.  Oggenc can be optionally compiled with
+libFLAC, and libkate.  The libraries libogg, libvorbis, and libao are
+all available at
+  http://www.vorbis.com/download.psp
+
+The libcurl library is packaged with most Linux distributions.  The
+source code can also be downloaded from:
+  http://curl.haxx.se/libcurl/
+
+FLAC is available at:
+  http://flac.sourceforge.net
+
+Speex is available at:
+  http://www.speex.org/
+
+libkate is available at:
+  http://libkate.googlecode.com/
+
+
+CONTACT:
+
+The Ogg Vorbis homepage is located at 'http://www.vorbis.com'. Up to
+date technical documents, contact information, source code and
+pre-built utilities may be found there.
+
+Developer information is available from http://www.xiph.org/. Check
+there for bug reporting information, mailing lists and other resources.
+
+
+BUILDING FROM SUBVERSION (see the file HACKING for details):
+
+./autogen.sh
+make 
+
+and as root if desired :
+
+make install
+
+This will install the tools into /usr/local/bin and manpages into
+/usr/local/man.
+
+
+BUILDING FROM TARBALL DISTRIBUTIONS:
+
+./configure
+make
+
+and as root if desired :
+
+make install
+
+BUILDING RPMS:
+
+RPMs may be built by:
+
+after autogen.sh or configure
+
+make dist
+rpm -ta vorbis-tools-<version>.tar.gz
+
+
+KNOWN BUGS:
+
+#1321
+  First noticed in non-English versions of the application, ogg123 has a major
+  bug when it comes to status messages in the shell: any output bigger than
+  the console's width will break and start spamming that message infinitely
+  until the console is resized.
+
+  Different attempts to fix this bug have ended up causing bigger problems,
+  leading to the conclusion that it simply can't be fixed without a large
+  re-write of the application, which will not happen any time soon.  If you
+  come across this issue, please augment your terminal window size.
\ No newline at end of file
diff --git a/vorbis-tools/include/i18n.h b/vorbis-tools/include/i18n.h
new file mode 100644 (file)
index 0000000..8624830
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef VORBIS_TOOLS_I18N_H
+#define VORBIS_TOOLS_I18N_H
+
+#ifdef ENABLE_NLS
+#include <libintl.h>
+#define _(X) gettext(X)
+#else
+#define _(X) (X)
+#define textdomain(X)
+#define bindtextdomain(X, Y)
+#endif
+#ifdef gettext_noop
+#define N_(X) gettext_noop(X)
+#else
+#define N_(X) (X)
+#endif
+
+#endif
diff --git a/vorbis-tools/vorbiscomment/vcedit.c b/vorbis-tools/vorbiscomment/vcedit.c
new file mode 100644 (file)
index 0000000..d6b9bce
--- /dev/null
@@ -0,0 +1,881 @@
+/* This program is licensed under the GNU Library General Public License, version 2,
+ * a copy of which is included with this program (LICENCE.LGPL).
+ *
+ * (c) 2000-2001 Michael Smith <msmith@xiph.org>
+ *
+ *
+ * Comment editing backend, suitable for use by nice frontend interfaces.
+ *
+ * last modified: $Id: vcedit.c 16826 2010-01-27 04:16:24Z xiphmont $
+ */
+
+/* Handle muxed streams and the Vorbis renormalization without having
+ * to understand remuxing:
+ * Linked list of buffers (buffer_chain).  Start a link and whenever
+ * you encounter an unknown page from the current stream (ie we found
+ * its bos in the bos section) push it onto the current buffer.  Whenever
+ * you encounter the stream being renormalized create a new link in the
+ * chain.
+ * On writing, write the contents of the first link before every Vorbis
+ * page written, and move to the next link.  Assuming the Vorbis pages
+ * in match vorbis pages out, the order of pages from different logical
+ * streams will be unchanged.
+ * Special case: header. After writing the vorbis headers, and before
+ * starting renormalization, flush accumulated links (takes care of
+ * situations where number of secondary vorbis header pages changes due
+ * to remuxing.  Similarly flush links at the end of renormalization
+ * and before the start of the next chain is written.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <ogg/ogg.h>
+#include <vorbis/codec.h>
+
+#include "vcedit.h"
+#include "vceditaux.h"
+#include "i18n.h"
+
+
+#define CHUNKSIZE 4096
+#define BUFFERCHUNK CHUNKSIZE
+
+/* Helper function, shouldn't need to call directly */
+static int page_buffer_push(vcedit_buffer_chain *bufferlink, ogg_page *og) {
+       int result=0;
+       char *tmp;
+       vcedit_page_buffer *buffer;
+       
+       buffer = &bufferlink->buffer;
+       tmp = realloc(buffer->data,
+                     buffer->data_len + og->header_len + og->body_len);
+       if(tmp) {
+               buffer->data = tmp;
+               memcpy(buffer->data + buffer->data_len, og->header,
+                      og->header_len);
+               buffer->data_len += og->header_len;
+               memcpy(buffer->data + buffer->data_len, og->body,
+              og->body_len);
+               result = 1;
+               buffer->data_len += og->body_len;
+       } else {
+               result = -1;
+       }
+       
+       return result;
+}
+
+/* Write and free the first link using callbacks */
+static int buffer_chain_writelink(vcedit_state *state, void *out) {
+       int result = 0;
+       vcedit_buffer_chain *tmpchain;
+       vcedit_page_buffer *tmpbuffer;
+
+       tmpchain = state->sidebuf;
+       tmpbuffer = &tmpchain->buffer;
+       if(tmpbuffer->data_len)
+       {
+               if(state->write(tmpbuffer->data,1,tmpbuffer->data_len, out) !=
+                  (size_t) tmpbuffer->data_len)
+                       result = -1;
+               else 
+                       result = 1;
+       }
+
+       free(tmpbuffer->data);
+       state->sidebuf = tmpchain->next;
+       free(tmpchain);
+       return result;
+}
+
+
+static int buffer_chain_newlink(vcedit_state *state) {
+       int result = 1;
+       vcedit_buffer_chain *bufferlink;
+       
+       if(!state->sidebuf) {
+               state->sidebuf = malloc (sizeof *state->sidebuf);
+               if(state->sidebuf) {
+                       bufferlink = state->sidebuf;
+               } else {
+                       result = -1;
+               }
+       } else {
+               bufferlink=state->sidebuf;
+               while(bufferlink->next) {
+                       bufferlink = bufferlink->next;
+               }
+               bufferlink->next =  malloc (sizeof *bufferlink->next);
+               if(bufferlink->next) {
+                       bufferlink = bufferlink->next;
+               } else {
+                       result = -1;
+               }
+       }
+
+       if(result > 0 ) {
+               bufferlink->next = 0;
+               bufferlink->buffer.data = 0;
+               bufferlink->buffer.data_len = 0;
+       }
+       else 
+               state->lasterror =
+                       _("Couldn't get enough memory for input buffering.");
+
+  return result;
+}
+
+
+/* Push page onto the end of the buffer chain */
+static int buffer_chain_push(vcedit_state *state, ogg_page *og) {
+       /* If there is no sidebuffer yet we need to create one, otherwise
+        * traverse to the last buffer and push the new page onto it. */
+       int result=1;
+       vcedit_buffer_chain *bufferlink;
+       if(!state->sidebuf) {
+               result = buffer_chain_newlink(state);
+       }
+       
+       if(result > 0) {
+               bufferlink = state->sidebuf;
+               while(bufferlink->next) {
+                       bufferlink = bufferlink->next;
+       }
+               result = page_buffer_push(bufferlink, og);
+       }
+
+       if(result < 0)
+               state->lasterror =
+                       _("Couldn't get enough memory for input buffering.");
+
+       return result;
+}
+
+
+
+static int vcedit_supported_stream(vcedit_state *state, ogg_page *og) {
+       ogg_stream_state os;
+       vorbis_info vi;
+       vorbis_comment vc;
+       ogg_packet header;
+       int result = 0;
+       
+       ogg_stream_init(&os, ogg_page_serialno(og));
+       vorbis_info_init(&vi);
+       vorbis_comment_init(&vc);
+       
+       if( !ogg_page_bos(og) )
+                result = -1;
+
+       if(result >= 0 && ogg_stream_pagein(&os, og) < 0)
+       {
+               state->lasterror =
+                       _("Error reading first page of Ogg bitstream.");
+               result = -1;
+       }
+
+       if(result >= 0 && ogg_stream_packetout(&os, &header) != 1)
+       {
+               state->lasterror = _("Error reading initial header packet.");
+               result = -1;
+       }
+
+       if(result >= 0 && vorbis_synthesis_headerin(&vi, &vc, &header) >= 0)
+       {
+                result = 1;
+       } else {
+               /* Not vorbis, may eventually become a chain of checks (Speex,
+                * Theora), but for the moment return 0, bos scan will push
+                 * the current page onto the buffer.
+                */
+       }
+
+       ogg_stream_clear(&os);
+       vorbis_info_clear(&vi);
+       vorbis_comment_clear(&vc);
+        return result;
+}
+
+
+static int vcedit_contains_serial (vcedit_state *state, int serialno) {
+       int result = 0;
+       size_t count;
+       for( count=0; count < state->serials.streams_len; count++ ) {
+               if ( *(state->serials.streams + count ) == serialno )
+                       result = 1;
+       }
+       
+       return result;
+}
+
+
+static int vcedit_add_serial (vcedit_state *state, long serial) {
+        int result = 0;
+        long *tmp;
+       
+       
+       if( vcedit_contains_serial(state, serial) )
+        {
+               result = 1;
+       } else {
+               tmp   = realloc(state->serials.streams,
+                               (state->serials.streams_len + 1) * sizeof *tmp);
+               if(tmp) {
+                       state->serials.streams = tmp;
+                       *(state->serials.streams +
+                         state->serials.streams_len) = serial;
+                       state->serials.streams_len += 1;
+                       result = 1;
+               } else {
+                       state->lasterror =
+                               _("Couldn't get enough memory to register new stream serial number.");
+                       result = -1;
+               }
+       } 
+       return result;
+}
+
+
+/* For the benefit of the secondary header read only.  Quietly creates
+ * newlinks and pushes pages onto the buffer in the right way */
+static int vcedit_target_pageout (vcedit_state *state, ogg_page *og) {
+       int result = 0;
+       int pageout_result;
+       pageout_result = ogg_sync_pageout(state->oy, og);
+       if(pageout_result > 0)
+       {
+               if(state->serial == ogg_page_serialno(og))
+                       result = buffer_chain_newlink(state);
+               else
+                       result = buffer_chain_push(state, og);
+       } else if (pageout_result < 0) {
+               /* Vorbis comment traditionally ignores the not-synced
+                * error from pageout, so give it a different code. */
+               result = -2;
+       }
+       return result;
+}
+
+
+/* (I'm paranoid about memset(x,0,len) not giving null pointers */
+vcedit_state *vcedit_new_state(void) {
+       vcedit_state *state = malloc(sizeof(vcedit_state));
+       if(state) {
+               memset(state, 0, sizeof(vcedit_state));
+               state->sidebuf = 0;
+               state->serials.streams = 0;
+               state->serials.streams_len = 0;
+       }
+       return state;
+}
+
+char *vcedit_error(vcedit_state *state) {
+       return state->lasterror;
+}
+
+vorbis_comment *vcedit_comments(vcedit_state *state) {
+       return state->vc;
+}
+
+static void vcedit_clear_internals(vcedit_state *state) {
+    char *tmp;
+       if(state->vc) {
+               vorbis_comment_clear(state->vc);
+               free(state->vc);
+       }
+       if(state->os) {
+               ogg_stream_clear(state->os);
+               free(state->os);
+       }
+       if(state->oy) {
+               ogg_sync_clear(state->oy);
+               free(state->oy);
+       }
+       if(state->serials.streams_len) {
+               free(state->serials.streams);
+               state->serials.streams_len = 0;
+               state->serials.streams = 0;
+       }
+       while(state->sidebuf) {
+               vcedit_buffer_chain *tmpbuffer;
+               tmpbuffer = state->sidebuf;
+               state->sidebuf = tmpbuffer->next;
+               free(tmpbuffer->buffer.data);
+               free(tmpbuffer);
+       }
+       if(state->vendor)
+               free(state->vendor);
+    if(state->mainbuf)
+        free(state->mainbuf);
+    if(state->bookbuf)
+        free(state->bookbuf);
+    if(state->vi) {
+               vorbis_info_clear(state->vi);
+        free(state->vi);
+    }
+
+    tmp = state->lasterror;
+    memset(state, 0, sizeof(*state));
+    state->lasterror = tmp;
+}
+
+void vcedit_clear(vcedit_state *state)
+{
+       if(state)
+       {
+               vcedit_clear_internals(state);
+               free(state);
+       }
+}
+
+/* Next two functions pulled straight from libvorbis, apart from one change
+ * - we don't want to overwrite the vendor string.
+ */
+static void _v_writestring(oggpack_buffer *o,char *s, int len)
+{
+       while(len--)
+       {
+               oggpack_write(o,*s++,8);
+       }
+}
+
+static int _commentheader_out(vorbis_comment *vc, char *vendor, ogg_packet *op)
+{
+       oggpack_buffer opb;
+
+       oggpack_writeinit(&opb);
+
+       /* preamble */  
+       oggpack_write(&opb,0x03,8);
+       _v_writestring(&opb,"vorbis", 6);
+
+       /* vendor */
+       oggpack_write(&opb,strlen(vendor),32);
+       _v_writestring(&opb,vendor, strlen(vendor));
+
+       /* comments */
+       oggpack_write(&opb,vc->comments,32);
+       if(vc->comments){
+               int i;
+               for(i=0;i<vc->comments;i++){
+                       if(vc->user_comments[i]){
+                               oggpack_write(&opb,vc->comment_lengths[i],32);
+                               _v_writestring(&opb,vc->user_comments[i], 
+                        vc->comment_lengths[i]);
+                       }else{
+                               oggpack_write(&opb,0,32);
+                       }
+               }
+       }
+       oggpack_write(&opb,1,1);
+
+       op->packet = malloc(oggpack_bytes(&opb));
+       memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
+
+       op->bytes=oggpack_bytes(&opb);
+       op->b_o_s=0;
+       op->e_o_s=0;
+       op->granulepos=0;
+
+       oggpack_writeclear(&opb);
+       return 0;
+}
+
+static int _blocksize(vcedit_state *s, ogg_packet *p)
+{
+       int this = vorbis_packet_blocksize(s->vi, p);
+       int ret = (this + s->prevW)/4;
+
+       if(!s->prevW)
+       {
+               s->prevW = this;
+               return 0;
+       }
+
+       s->prevW = this;
+       return ret;
+}
+
+static int _fetch_next_packet(vcedit_state *s, ogg_packet *p, ogg_page *page)
+{
+       int result;
+       char *buffer;
+       int bytes;
+       int serialno;
+
+       result = ogg_stream_packetout(s->os, p);
+
+       if(result > 0)
+               return 1;
+       else {
+               while(1) {
+                       if(s->eosin)
+                               return 0;
+
+                       while(ogg_sync_pageout(s->oy, page) <= 0)
+                       {
+                               buffer = ogg_sync_buffer(s->oy, CHUNKSIZE);
+                               bytes = s->read(buffer,1, CHUNKSIZE, s->in);
+                               ogg_sync_wrote(s->oy, bytes);
+                               if(bytes == 0)
+                               return 0;
+                       }
+
+                       serialno = ogg_page_serialno(page);
+                       if(ogg_page_serialno(page) != s->serial)
+                       {
+                               if(vcedit_contains_serial(s, serialno)) {
+                                       result = buffer_chain_push(s, page);
+                                       if(result < 0)
+                                               return result;
+                               }
+                               else
+                               {
+                                       s->eosin = 1;
+                                       s->extrapage = 1;
+                                       return 0;
+                               }
+                       } 
+                       else
+                       {
+                         ogg_stream_pagein(s->os, page);
+                         result = buffer_chain_newlink(s);
+                         if (result < 0)
+                                 return result;
+
+                         if(ogg_page_eos(page))
+                               s->eosin = 1;
+                       }
+                       result = ogg_stream_packetout(s->os, p);
+                       if(result > 0)
+                               return 1;
+               }
+               /* Here == trouble */
+               return 0;
+       }
+}
+
+int vcedit_open(vcedit_state *state, FILE *in)
+{
+       return vcedit_open_callbacks(state, (void *)in, 
+                       (vcedit_read_func)fread, (vcedit_write_func)fwrite);
+}
+
+int vcedit_open_callbacks(vcedit_state *state, void *in,
+               vcedit_read_func read_func, vcedit_write_func write_func)
+{
+
+       char *buffer;
+       int bytes,i;
+       int chunks = 0;
+       int read_bos, test_supported, page_pending;
+       int have_vorbis;
+       ogg_packet *header;
+       ogg_packet      header_main;
+       ogg_packet  header_comments;
+       ogg_packet      header_codebooks;
+       ogg_page    og;
+
+       state->in = in;
+       state->read = read_func;
+       state->write = write_func;
+
+       state->oy = malloc(sizeof(ogg_sync_state));
+       ogg_sync_init(state->oy);
+
+    while(1)
+    {
+       buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
+           bytes = state->read(buffer, 1, CHUNKSIZE, state->in);
+
+       ogg_sync_wrote(state->oy, bytes);
+
+        if(ogg_sync_pageout(state->oy, &og) == 1)
+            break;
+
+        if(chunks++ >= 10) /* Bail if we don't find data in the first 40 kB */
+        {
+                   if(bytes<CHUNKSIZE)
+                           state->lasterror = _("Input truncated or empty.");
+               else
+                       state->lasterror = _("Input is not an Ogg bitstream.");
+           goto err;
+       }
+    }
+
+    /* BOS loop, starting with a loaded ogg page. */
+    if(buffer_chain_newlink(state) < 0)
+           goto err;
+
+    for( read_bos = 1, have_vorbis = 0 ; read_bos; )
+    {
+           test_supported = vcedit_supported_stream(state, &og);
+           if(test_supported < 0)
+           {
+                   goto err;
+           }
+           else if (test_supported == 0 || have_vorbis )
+           {
+                   if(vcedit_add_serial ( state, ogg_page_serialno(&og)) < 0)
+                           goto err;
+                   if( buffer_chain_push(state, &og) < 0)
+                           goto err;
+           }
+           else if (test_supported > 0)
+           {
+                   if(buffer_chain_newlink(state) < 0)
+                           goto err;
+                   state->serial = ogg_page_serialno(&og);
+                   if(vcedit_add_serial ( state, ogg_page_serialno(&og)) < 0)
+                      goto err;
+                   state->os = malloc(sizeof(ogg_stream_state));
+                   ogg_stream_init(state->os, state->serial);
+
+                   state->vi = malloc(sizeof(vorbis_info));
+                   vorbis_info_init(state->vi);
+
+                   state->vc = malloc(sizeof(vorbis_comment));
+                   vorbis_comment_init(state->vc);
+
+                   if(ogg_stream_pagein(state->os, &og) < 0)
+                   {
+                           state->lasterror = 
+                                   _("Error reading first page of Ogg bitstream.");
+                           goto err;
+                   }
+
+                   if(ogg_stream_packetout(state->os, &header_main) != 1)
+                   {
+                           state->lasterror =
+                                   _("Error reading initial header packet.");
+                           goto err;
+                   }
+
+                   if(vorbis_synthesis_headerin(state->vi, state->vc,
+                                                &header_main) < 0)
+                   {
+                           state->lasterror =
+                                   _("Ogg bitstream does not contain Vorbis data.");
+                           goto err;
+                   }
+                   have_vorbis = 1;
+           }
+           while(1)
+           {
+                   buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
+                   bytes = state->read(buffer, 1, CHUNKSIZE, state->in);
+
+                   if(bytes == 0)
+                   {
+                           state->lasterror =
+                                   _("EOF before recognised stream.");
+                           goto err;
+                   }
+
+                   ogg_sync_wrote(state->oy, bytes);
+
+                   if(ogg_sync_pageout(state->oy, &og) == 1)
+                           break;
+           }
+           if(!ogg_page_bos(&og)) {
+                   read_bos = 0;
+                   page_pending = 1;
+           }
+    }
+
+        if(!state->os) {
+               state->lasterror = _("Ogg bitstream does not contain a supported data-type.");
+               goto err;
+       }
+
+       state->mainlen = header_main.bytes;
+       state->mainbuf = malloc(state->mainlen);
+       memcpy(state->mainbuf, header_main.packet, header_main.bytes);
+
+       if(ogg_page_serialno(&og) == state->serial)
+       {
+               if(buffer_chain_newlink(state) < 0)
+                       goto err;
+       }
+
+       else
+       {
+               if(buffer_chain_push(state, &og) < 0)
+                       goto err;
+               page_pending = 0;
+       }
+
+       i = 0;
+       header = &header_comments;
+       while(i<2) {
+               while(i<2) {
+                       int result;
+                       if(!page_pending)
+                               result = vcedit_target_pageout(state, &og);
+                       else
+                       {
+                               result = 1;
+                               page_pending = 0;
+                       }
+                       if(result == 0 || result == -2) break; /* Too little data so far */
+                       else if(result == -1) goto err;
+                       else if(result == 1)
+                       {
+                               ogg_stream_pagein(state->os, &og);
+                               while(i<2)
+                               {
+                                       result = ogg_stream_packetout(state->os, header);
+                                       if(result == 0) break;
+                                       if(result == -1)
+                                       {
+                                               state->lasterror = _("Corrupt secondary header.");
+                                               goto err;
+                                       }
+                                       vorbis_synthesis_headerin(state->vi, state->vc, header);
+                                       if(i==1)
+                                       {
+                                               state->booklen = header->bytes;
+                                               state->bookbuf = malloc(state->booklen);
+                                               memcpy(state->bookbuf, header->packet, 
+                                                               header->bytes);
+                                       }
+                                       i++;
+                                       header = &header_codebooks;
+                               }
+                       }
+               }
+
+               buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
+               bytes = state->read(buffer, 1, CHUNKSIZE, state->in);
+               if(bytes == 0 && i < 2)
+               {
+                       state->lasterror = _("EOF before end of Vorbis headers.");
+                       goto err;
+               }
+               ogg_sync_wrote(state->oy, bytes);
+       }
+
+       /* Copy the vendor tag */
+       state->vendor = malloc(strlen(state->vc->vendor) +1);
+       strcpy(state->vendor, state->vc->vendor);
+
+       /* Headers are done! */
+       return 0;
+
+err:
+       vcedit_clear_internals(state);
+       return -1;
+}
+
+int vcedit_write(vcedit_state *state, void *out)
+{
+       ogg_stream_state streamout;
+       ogg_packet header_main;
+       ogg_packet header_comments;
+       ogg_packet header_codebooks;
+
+       ogg_page ogout, ogin;
+       ogg_packet op;
+       ogg_int64_t granpos = 0;
+       int result;
+       char *buffer;
+       int bytes;
+       int needflush=0, needout=0;
+
+       state->eosin = 0;
+       state->extrapage = 0;
+
+       header_main.bytes = state->mainlen;
+       header_main.packet = state->mainbuf;
+       header_main.b_o_s = 1;
+       header_main.e_o_s = 0;
+       header_main.granulepos = 0;
+
+       header_codebooks.bytes = state->booklen;
+       header_codebooks.packet = state->bookbuf;
+       header_codebooks.b_o_s = 0;
+       header_codebooks.e_o_s = 0;
+       header_codebooks.granulepos = 0;
+
+       ogg_stream_init(&streamout, state->serial);
+
+       _commentheader_out(state->vc, state->vendor, &header_comments);
+
+       ogg_stream_packetin(&streamout, &header_main);
+       ogg_stream_packetin(&streamout, &header_comments);
+       ogg_stream_packetin(&streamout, &header_codebooks);
+
+       while((result = ogg_stream_flush(&streamout, &ogout)))
+       {
+               if(state->sidebuf && buffer_chain_writelink(state, out) < 0)
+                       goto cleanup;
+               if(state->write(ogout.header,1,ogout.header_len, out) !=
+                               (size_t) ogout.header_len)
+                       goto cleanup;
+               if(state->write(ogout.body,1,ogout.body_len, out) != 
+                               (size_t) ogout.body_len)
+                       goto cleanup;
+       }
+
+       while(state->sidebuf) {
+         if(buffer_chain_writelink(state, out) < 0)
+           goto cleanup;
+       }
+       if(buffer_chain_newlink(state) < 0)
+               goto cleanup;
+
+       while(_fetch_next_packet(state, &op, &ogin))
+       {
+               int size;
+               size = _blocksize(state, &op);
+               granpos += size;
+
+               if(needflush)
+               {
+                       if(ogg_stream_flush(&streamout, &ogout))
+                       {
+                               if(state->sidebuf &&
+                                  buffer_chain_writelink(state, out) < 0)
+                                       goto cleanup;
+                               if(state->write(ogout.header,1,ogout.header_len, 
+                                                       out) != (size_t) ogout.header_len)
+                                       goto cleanup;
+                               if(state->write(ogout.body,1,ogout.body_len, 
+                                                       out) != (size_t) ogout.body_len)
+                                       goto cleanup;
+                       }
+               }
+               else if(needout)
+               {
+                       if(ogg_stream_pageout(&streamout, &ogout))
+                       {
+                               if(state->sidebuf &&
+                                  buffer_chain_writelink(state, out) < 0)
+                                       goto cleanup;
+                               if(state->write(ogout.header,1,ogout.header_len, 
+                                                       out) != (size_t) ogout.header_len)
+                                       goto cleanup;
+                               if(state->write(ogout.body,1,ogout.body_len, 
+                                                       out) != (size_t) ogout.body_len)
+                                       goto cleanup;
+                       }
+               }
+
+               needflush=needout=0;
+
+               if(op.granulepos == -1)
+               {
+                       op.granulepos = granpos;
+                       ogg_stream_packetin(&streamout, &op);
+               }
+               else /* granulepos is set, validly. Use it, and force a flush to 
+                               account for shortened blocks (vcut) when appropriate */ 
+               {
+                       if(granpos > op.granulepos)
+                       {
+                               granpos = op.granulepos;
+                               ogg_stream_packetin(&streamout, &op);
+                               needflush=1;
+                       }
+                       else 
+                       {
+                               ogg_stream_packetin(&streamout, &op);
+                               needout=1;
+                       }
+               }               
+       }
+
+       streamout.e_o_s = 1;
+       while(ogg_stream_flush(&streamout, &ogout))
+       {
+               if(state->sidebuf && buffer_chain_writelink(state, out) < 0)
+                       goto cleanup;
+               if(state->write(ogout.header,1,ogout.header_len, 
+                                       out) != (size_t) ogout.header_len)
+                       goto cleanup;
+               if(state->write(ogout.body,1,ogout.body_len, 
+                                       out) != (size_t) ogout.body_len)
+                       goto cleanup;
+       }
+
+       if (state->extrapage)
+       {
+               /* This is the first page of a new chain, get rid of the
+                * sidebuffer */
+               while(state->sidebuf)
+                       if(buffer_chain_writelink(state, out) < 0)
+                               goto cleanup;
+               if(state->write(ogin.header,1,ogin.header_len,
+                               out) != (size_t) ogin.header_len)
+                       goto cleanup;
+               if (state->write(ogin.body,1,ogin.body_len, out) !=
+                               (size_t) ogin.body_len)
+                       goto cleanup;
+       }
+
+       state->eosin=0; /* clear it, because not all paths to here do */
+       while(!state->eosin) /* We reached eos, not eof */
+       {
+               /* We copy the rest of the stream (other logical streams)
+                * through, a page at a time. */
+               while(1)
+               {
+                       result = ogg_sync_pageout(state->oy, &ogout);
+                       if(result==0)
+                break;
+                       if(result<0)
+                               state->lasterror = _("Corrupt or missing data, continuing...");
+                       else
+                       {
+                               /* Don't bother going through the rest, we can just 
+                                * write the page out now */
+                               if(state->write(ogout.header,1,ogout.header_len, 
+                                               out) != (size_t) ogout.header_len) {
+                                       goto cleanup;
+                }
+                               if(state->write(ogout.body,1,ogout.body_len, out) !=
+                                               (size_t) ogout.body_len) {
+                                       goto cleanup;
+                }
+                       }
+               }
+               buffer = ogg_sync_buffer(state->oy, CHUNKSIZE);
+               bytes = state->read(buffer,1, CHUNKSIZE, state->in);
+               ogg_sync_wrote(state->oy, bytes);
+               if(bytes == 0) 
+               {
+                       state->eosin = 1;
+                       break;
+               }
+       }
+
+
+cleanup:
+       ogg_stream_clear(&streamout);
+
+    /* We don't ogg_packet_clear() this, because the memory was allocated in
+       _commentheader_out(), so we mirror that here */
+    _ogg_free(header_comments.packet);
+
+       free(state->mainbuf);
+       free(state->bookbuf);
+    state->mainbuf = state->bookbuf = NULL;
+
+       if(!state->eosin)
+       {
+               state->lasterror =
+                       _("Error writing stream to output. "
+                       "Output stream may be corrupted or truncated.");
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/vorbis-tools/vorbiscomment/vcedit.h b/vorbis-tools/vorbiscomment/vcedit.h
new file mode 100644 (file)
index 0000000..173876f
--- /dev/null
@@ -0,0 +1,69 @@
+/* This program is licensed under the GNU Library General Public License, version 2,
+ * a copy of which is included with this program (with filename LICENSE.LGPL).
+ *
+ * (c) 2000-2001 Michael Smith <msmith@xiph.org>
+ *
+ * VCEdit header.
+ *
+ * last modified: $ID:$
+ */
+
+#ifndef __VCEDIT_H
+#define __VCEDIT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif 
+
+#include <stdio.h>
+#include <ogg/ogg.h>
+#include <vorbis/codec.h>
+
+typedef size_t (*vcedit_read_func)(void *, size_t, size_t, void *);
+typedef size_t (*vcedit_write_func)(const void *, size_t, size_t, void *);
+
+typedef struct {
+       long *streams;
+       size_t streams_len;
+} vcedit_serial_nos;
+
+typedef struct {
+       ogg_sync_state          *oy;
+       ogg_stream_state        *os;
+
+       vorbis_comment          *vc;
+       vorbis_info         *vi;
+
+       vcedit_read_func read;
+       vcedit_write_func write;
+
+       void              *in;
+       int serial;
+       vcedit_serial_nos serials;
+       unsigned char     *mainbuf;
+       unsigned char     *bookbuf;
+       int               mainlen;
+       int               booklen;
+       char   *lasterror;
+       char   *vendor;
+       int prevW;
+       int extrapage;
+       int eosin;
+        struct vcedit_buffer_chain *sidebuf;
+} vcedit_state;
+
+extern vcedit_state *  vcedit_new_state(void);
+extern void            vcedit_clear(vcedit_state *state);
+extern vorbis_comment *        vcedit_comments(vcedit_state *state);
+extern int             vcedit_open(vcedit_state *state, FILE *in);
+extern int             vcedit_open_callbacks(vcedit_state *state, void *in,
+               vcedit_read_func read_func, vcedit_write_func write_func);
+extern int             vcedit_write(vcedit_state *state, void *out);
+extern char *   vcedit_error(vcedit_state *state);
+
+#ifdef __cplusplus
+}
+#endif 
+
+#endif /* __VCEDIT_H */
+
diff --git a/vorbis-tools/vorbiscomment/vceditaux.h b/vorbis-tools/vorbiscomment/vceditaux.h
new file mode 100644 (file)
index 0000000..bb40eae
--- /dev/null
@@ -0,0 +1,9 @@
+typedef struct vcedit_page_buffer {
+       char *data;
+       size_t data_len;
+} vcedit_page_buffer;
+       
+typedef struct vcedit_buffer_chain {
+       struct vcedit_buffer_chain *next;
+       struct vcedit_page_buffer buffer;
+} vcedit_buffer_chain;