Simplify autogen.sh
[platform/upstream/libvorbis.git] / examples / vorbisfile_example.c
index 835fd60..4c27fa4 100644 (file)
@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
- * by the XIPHOPHORUS Company http://www.xiph.org/                  *
-
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
  ********************************************************************
 
  function: simple example decoder using vorbisfile
- last mod: $Id: vorbisfile_example.c,v 1.6 2001/09/15 04:47:48 cwolf Exp $
+ last mod: $Id$
 
  ********************************************************************/
 
 
 char pcmout[4096]; /* take 4k out of the data segment, not the stack */
 
-int main(int argc, char **argv){
+int main(){
   OggVorbis_File vf;
   int eof=0;
   int current_section;
-  FILE *fpin=NULL;
-  FILE *fpout=NULL;
-  char msg[512];
 
 #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
   /* Beware the evil ifdef. We avoid these where we can, but this one we 
@@ -47,29 +44,7 @@ int main(int argc, char **argv){
   _setmode( _fileno( stdout ), _O_BINARY );
 #endif
 
-  if (argc == 3)
-  {
-    if ((fpin = fopen(argv[1], "rb")) == (FILE*)NULL)
-    {
-      (void)sprintf(msg, "Can't open %s for reading.", argv[1]);
-      perror(msg);
-      return 1;
-    }
-
-    if ((fpout = fopen(argv[2], "wb")) == (FILE*)NULL)
-    {
-      (void)sprintf(msg, "Can't open %s for writing.", argv[2]);
-      perror(msg);
-      return 1;
-    }
-  }
-  else
-  {
-    fpin = stdin;
-    fpout = stdout;
-  }
-
-  if(ov_open(fpin, &vf, NULL, 0) < 0) {
+  if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
       fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n");
       exit(1);
   }
@@ -85,7 +60,7 @@ int main(int argc, char **argv){
     }
     fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
     fprintf(stderr,"\nDecoded length: %ld samples\n",
-           (long)ov_pcm_total(&vf,-1));
+            (long)ov_pcm_total(&vf,-1));
     fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor);
   }
   
@@ -95,12 +70,17 @@ int main(int argc, char **argv){
       /* EOF */
       eof=1;
     } else if (ret < 0) {
-      /* error in the stream.  Not a problem, just reporting it in
-        case we (the app) cares.  In this case, we don't. */
+      if(ret==OV_EBADLINK){
+        fprintf(stderr,"Corrupt bitstream section! Exiting.\n");
+        exit(1);
+      }
+
+      /* some other error in the stream.  Not a problem, just reporting it in
+         case we (the app) cares.  In this case, we don't. */
     } else {
       /* we don't bother dealing with sample rate changes, etc, but
-        you'll have to*/
-      fwrite(pcmout,1,ret,fpout);
+         you'll have to*/
+      fwrite(pcmout,1,ret,stdout);
     }
   }
 
@@ -110,4 +90,3 @@ int main(int argc, char **argv){
   fprintf(stderr,"Done.\n");
   return(0);
 }
-