add new flacdiff util
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 11 May 2007 00:42:35 +0000 (00:42 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 11 May 2007 00:42:35 +0000 (00:42 +0000)
FLAC.dsw
FLAC.sln
src/utils/flacdiff/Makefile.lite [new file with mode: 0644]
src/utils/flacdiff/flacdiff.dsp [new file with mode: 0644]
src/utils/flacdiff/flacdiff.vcproj [new file with mode: 0644]
src/utils/flacdiff/main.cpp [new file with mode: 0644]

index 3b94b2c..6fc1405 100644 (file)
--- a/FLAC.dsw
+++ b/FLAC.dsw
@@ -45,6 +45,9 @@ Package=<4>
     Project_Dep_Name flac_ren\r
     End Project Dependency\r
     Begin Project Dependency\r
+    Project_Dep_Name flacdiff\r
+    End Project Dependency\r
+    Begin Project Dependency\r
     Project_Dep_Name grabbag_static\r
     End Project Dependency\r
     Begin Project Dependency\r
@@ -123,6 +126,9 @@ Package=<4>
     Project_Dep_Name flac_ren\r
     End Project Dependency\r
     Begin Project Dependency\r
+    Project_Dep_Name flacdiff\r
+    End Project Dependency\r
+    Begin Project Dependency\r
     Project_Dep_Name grabbag_static\r
     End Project Dependency\r
     Begin Project Dependency\r
@@ -513,6 +519,21 @@ Package=<4>
 \r
 ###############################################################################\r
 \r
+Project: "flacdiff"=".\src\utils\flacdiff\flacdiff.dsp" - Package Owner=<4>\r
+\r
+Package=<5>\r
+{{{\r
+}}}\r
+\r
+Package=<4>\r
+{{{\r
+    Begin Project Dependency\r
+    Project_Dep_Name libFLAC++_static\r
+    End Project Dependency\r
+}}}\r
+\r
+###############################################################################\r
+\r
 Global:\r
 \r
 Package=<5>\r
index 681281e..1d7f881 100644 (file)
--- a/FLAC.sln
+++ b/FLAC.sln
@@ -15,6 +15,11 @@ Project("{4cefbc7c-c215-11db-8314-0800200c9a66}") = "flac_mac", "src\monkeys_aud
 EndProject\r
 Project("{4cefbc7c-c215-11db-8314-0800200c9a66}") = "flac_ren", "src\monkeys_audio_utilities\flac_ren\flac_ren.vcproj", "{4cefbc7f-c215-11db-8314-0800200c9a66}"\r
 EndProject\r
+Project("{4cefbc7c-c215-11db-8314-0800200c9a66}") = "flacdiff", "src\utils\flacdiff\flacdiff.vcproj", "{4cefbc93-c215-11db-8314-0800200c9a66}"\r
+       ProjectSection(ProjectDependencies) = postProject\r
+               {4cefbc86-c215-11db-8314-0800200c9a66} = {4cefbc86-c215-11db-8314-0800200c9a66}\r
+       EndProjectSection\r
+EndProject\r
 Project("{4cefbc7c-c215-11db-8314-0800200c9a66}") = "getopt_static", "src\share\getopt\getopt_static.vcproj", "{4cefbc80-c215-11db-8314-0800200c9a66}"\r
 EndProject\r
 Project("{4cefbc7c-c215-11db-8314-0800200c9a66}") = "grabbag_static", "src\share\grabbag\grabbag_static.vcproj", "{4cefbc81-c215-11db-8314-0800200c9a66}"\r
@@ -196,6 +201,10 @@ Global
                {4cefbc92-c215-11db-8314-0800200c9a66}.Debug|Win32.Build.0 = Debug|Win32\r
                {4cefbc92-c215-11db-8314-0800200c9a66}.Release|Win32.ActiveCfg = Release|Win32\r
                {4cefbc92-c215-11db-8314-0800200c9a66}.Release|Win32.Build.0 = Release|Win32\r
+               {4cefbc93-c215-11db-8314-0800200c9a66}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {4cefbc93-c215-11db-8314-0800200c9a66}.Debug|Win32.Build.0 = Debug|Win32\r
+               {4cefbc93-c215-11db-8314-0800200c9a66}.Release|Win32.ActiveCfg = Release|Win32\r
+               {4cefbc93-c215-11db-8314-0800200c9a66}.Release|Win32.Build.0 = Release|Win32\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r
diff --git a/src/utils/flacdiff/Makefile.lite b/src/utils/flacdiff/Makefile.lite
new file mode 100644 (file)
index 0000000..f908015
--- /dev/null
@@ -0,0 +1,42 @@
+#  flacdiff - Displays where two FLAC streams differ
+#  Copyright (C) 2007  Josh Coalson
+#
+#  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.
+
+#
+# GNU makefile
+#
+
+topdir = ../../..
+libdir = $(topdir)/obj/$(BUILD)/lib
+
+PROGRAM_NAME = flacdiff
+
+INCLUDES = -I$(topdir)/include
+
+ifeq ($(DARWIN_BUILD),yes)
+EXPLICIT_LIBS = $(libdir)/libFLAC++.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm
+else
+LIBS = -lFLAC++ -lFLAC -L$(OGG_LIB_DIR) -logg -lm
+endif
+
+SRCS_CPP = \
+       main.cpp
+
+include $(topdir)/build/exe.mk
+
+LINK = $(CCC) $(LINKAGE)
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/src/utils/flacdiff/flacdiff.dsp b/src/utils/flacdiff/flacdiff.dsp
new file mode 100644 (file)
index 0000000..75c9a31
--- /dev/null
@@ -0,0 +1,100 @@
+# Microsoft Developer Studio Project File - Name="flacdiff" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=flacdiff - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "flacdiff.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "flacdiff.mak" CFG="flacdiff - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "flacdiff - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "flacdiff - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF  "$(CFG)" == "flacdiff - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\..\obj\release\bin"\r
+# PROP Intermediate_Dir "Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c\r
+# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "..\..\..\include" /D "NDEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c\r
+# SUBTRACT CPP /YX /Yc /Yu\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 ..\..\..\obj\release\lib\libFLAC++_static.lib ..\..\..\obj\release\lib\libFLAC_static.lib ..\..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386\r
+\r
+!ELSEIF  "$(CFG)" == "flacdiff - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "..\..\..\obj\debug\bin"\r
+# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "..\..\..\include" /D "_DEBUG" /D "DEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c\r
+# SUBTRACT CPP /YX /Yc /Yu\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 ..\..\..\obj\debug\lib\libFLAC++_static.lib ..\..\..\obj\debug\lib\libFLAC_static.lib ..\..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "flacdiff - Win32 Release"\r
+# Name "flacdiff - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\main.cpp\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# End Group\r
+# End Target\r
+# End Project\r
diff --git a/src/utils/flacdiff/flacdiff.vcproj b/src/utils/flacdiff/flacdiff.vcproj
new file mode 100644 (file)
index 0000000..4512c1e
--- /dev/null
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="flacdiff"\r
+       ProjectGUID="{4cefbc93-c215-11db-8314-0800200c9a66}"\r
+       RootNamespace="flacdiff"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="..\..\..\obj\debug\bin"\r
+                       IntermediateDirectory="Debug"\r
+                       ConfigurationType="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories=".;..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;FLAC__NO_DLL;DEBUG"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                               DisableSpecificWarnings="4267;4996"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="..\..\..\obj\release\lib\ogg_static.lib"\r
+                               LinkIncremental="2"\r
+                               IgnoreDefaultLibraryNames="uuid.lib"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="..\..\..\obj\release\bin"\r
+                       IntermediateDirectory="Release"\r
+                       ConfigurationType="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories=".;..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;FLAC__NO_DLL"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                               DisableSpecificWarnings="4267;4996"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="..\..\..\obj\release\lib\ogg_static.lib"\r
+                               LinkIncremental="2"\r
+                               IgnoreDefaultLibraryNames="uuid.lib"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+               </Filter>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\main.cpp"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/src/utils/flacdiff/main.cpp b/src/utils/flacdiff/main.cpp
new file mode 100644 (file)
index 0000000..a777a7e
--- /dev/null
@@ -0,0 +1,216 @@
+/* flacdiff - Displays where two FLAC streams differ
+ * Copyright (C) 2007  Josh Coalson
+ *
+ * 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.
+ */
+
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "FLAC++/decoder.h"
+
+class AutoFILE {
+protected:
+       ::FILE *f_;
+public:
+       inline AutoFILE(const char *path, const char *mode): f_(::fopen(path, mode)) { }
+       inline virtual ~AutoFILE() { if (f_) (void)::fclose(f_); }
+
+       inline operator bool() const { return 0 != f_; }
+       inline operator const ::FILE *() const { return f_; }
+       inline operator ::FILE *() { return f_; }
+private:
+       AutoFILE();
+       AutoFILE(const AutoFILE &);
+       void operator=(const AutoFILE &);
+};
+
+class Decoder: public FLAC::Decoder::Stream {
+public:
+       Decoder(AutoFILE &f, off_t tgt): tgtpos_((FLAC__uint64)tgt), curpos_(0), go_(true), err_(false), frame_(), f_(f) { memset(&frame_, 0, sizeof(::FLAC__Frame)); }
+       FLAC__uint64 tgtpos_, curpos_;
+       bool go_, err_;
+       ::FLAC__Frame frame_;
+protected:
+       AutoFILE &f_;
+       // from FLAC::Decoder::Stream
+       virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes)
+       {
+               *bytes = fread(buffer, 1, *bytes, f_);
+               if(ferror(f_))
+                       return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+               else if(*bytes == 0 && feof(f_))
+                       return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+               else
+                       return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+       }
+
+       virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset)
+       {
+               off_t off = ftello(f_);
+               if(off < 0)
+                       return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
+               *absolute_byte_offset = off;
+               return ::FLAC__STREAM_DECODER_TELL_STATUS_OK;
+       }
+
+       virtual bool eof_callback()
+       {
+               return feof(f_);
+       }
+
+       virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const /*buffer*/[])
+       {
+               FLAC__uint64 pos;
+               if(!get_decode_position(&pos)) {
+                       go_ = false;
+                       err_ = true;
+                       return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+               }
+               if(pos > tgtpos_) {
+                       go_ = false;
+                       frame_ = *frame;
+               }
+               else
+                       curpos_ = pos;
+               return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+       }
+
+       virtual void error_callback(::FLAC__StreamDecoderErrorStatus status)
+       {
+               fprintf(stderr, "get error %d:%s\n", status, ::FLAC__StreamDecoderErrorStatusString[status]);
+               go_ = false;
+               err_ = true;
+       }
+};
+
+static bool show_diff(AutoFILE &f1, AutoFILE &f2, off_t off)
+{
+       Decoder d1(f1, off), d2(f2, off);
+       if(!d1) {
+               fprintf(stderr, "ERROR: setting up decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1));
+               return false;
+       }
+       if(!d2) {
+               fprintf(stderr, "ERROR: setting up decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2));
+               return false;
+       }
+       ::FLAC__StreamDecoderInitStatus is;
+       if((is = d1.init()) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
+               fprintf(stderr, "ERROR: initializing decoder1, status=%s state=%s\n", FLAC__StreamDecoderInitStatusString[is], d1.get_state().resolved_as_cstring(d1));
+               return false;
+       }
+       if((is = d2.init()) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
+               fprintf(stderr, "ERROR: initializing decoder2, status=%s state=%s\n", FLAC__StreamDecoderInitStatusString[is], d2.get_state().resolved_as_cstring(d2));
+               return false;
+       }
+       if(!d1.process_until_end_of_metadata()) {
+               fprintf(stderr, "ERROR: skipping metadata in decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1));
+               return false;
+       }
+       if(!d2.process_until_end_of_metadata()) {
+               fprintf(stderr, "ERROR: skipping metadata in decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2));
+               return false;
+       }
+       while(d1.go_ && d2.go_) {
+               if(!d1.process_single()) {
+                       fprintf(stderr, "ERROR: decoding frame in decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1));
+                       return false;
+               }
+               if(!d2.process_single()) {
+                       fprintf(stderr, "ERROR: decoding frame in decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2));
+                       return false;
+               }
+       }
+       if(d1.err_) {
+               fprintf(stderr, "ERROR: got err_ in decoder1, state=%s\n", d1.get_state().resolved_as_cstring(d1));
+               return false;
+       }
+       if(d2.err_) {
+               fprintf(stderr, "ERROR: got err_ in decoder2, state=%s\n", d2.get_state().resolved_as_cstring(d2));
+               return false;
+       }
+       if(d1.go_ != d2.go_) {
+               fprintf(stderr, "ERROR: d1.go_(%s) != d2.go_(%s)\n", d1.go_?"true":"false", d2.go_?"true":"false");
+               return false;
+       }
+       fprintf(stdout, "pos1 = %llu  blocksize=%u sample#%llu frame#%llu\n", d1.curpos_, d1.frame_.header.blocksize, d1.frame_.header.number.sample_number, d1.frame_.header.number.sample_number / d1.frame_.header.blocksize);
+       fprintf(stdout, "pos2 = %llu  blocksize=%u sample#%llu frame#%llu\n", d2.curpos_, d2.frame_.header.blocksize, d2.frame_.header.number.sample_number, d2.frame_.header.number.sample_number / d2.frame_.header.blocksize);
+
+       return true;
+}
+
+static off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2)
+{
+       off_t off = 0;
+       while(1) {
+               if(feof((FILE*)f1) && feof((FILE*)f1)) {
+                       fprintf(stderr, "ERROR: files are identical\n");
+                       return -1;
+               }
+               if(feof((FILE*)f1)) {
+                       fprintf(stderr, "ERROR: file1 EOF\n");
+                       return -1;
+               }
+               if(feof((FILE*)f2)) {
+                       fprintf(stderr, "ERROR: file2 EOF\n");
+                       return -1;
+               }
+               if(fgetc(f1) != fgetc(f2))
+                       return off;
+               off++;
+       }
+}
+
+static bool run(const char *fn1, const char *fn2)
+{
+       off_t off;
+       AutoFILE f1(fn1, "rb"), f2(fn2, "rb");
+
+       if(!f1) {
+               fprintf(stderr, "ERROR: opening %s for reading\n", fn1);
+               return false;
+       }
+       if(!f2) {
+               fprintf(stderr, "ERROR: opening %s for reading\n", fn2);
+               return false;
+       }
+
+       if((off = get_diff_offset(f1, f2)) < 0)
+               return false;
+
+       fprintf(stdout, "got diff offset = %u\n", (unsigned)off); //@@@ 4G limit (what is % modifier for off_t?)
+
+       return show_diff(f1, f2, off);
+}
+
+int main(int argc, char *argv[])
+{
+       const char *usage = "usage: flacdiff flacfile1 flacfile2\n";
+
+       if(argc > 1 && 0 == strcmp(argv[1], "-h")) {
+               printf(usage);
+               return 0;
+       }
+       else if(argc != 3) {
+               fprintf(stderr, usage);
+               return 255;
+       }
+
+       return run(argv[1], argv[2])? 0 : 1;
+}