For anyone that is interested, I just kludged up this yesterday. It will read the vendor string in a flac file and display it and exit with a code equal to the encoder level: i.e. version 1.1.3 would yield an exit code of 113. I'm using this in a script to conditionally re-encode my flacs using the newest version.
FlacGetV.c:
/*
FlacGetV.c -- displays the flac vendor string and returns an errorlevel.
*/
#include "FLAC/ordinals.h"
#include "FLAC/assert.h"
#include "FLAC/format.h"
#include "FLAC/metadata.h"
#include <stdio.h>
#include <string.h>
#define QUIET 0x00000001
#define MAXPATH 260
#define STRSIZE 260
void DispSyntax(void)
{
puts("FlacGetV: returns the encoder vendor string from a flac file. \n\n"
"Synatx: FlacGetV filename [-q]\n\n"
"The optional \"-q\" arg supresses output.\n\n"
"Returns: An errorlevel indicating the version of FLAC that encoded\n"
" the flac file. E.g.: FlacGetV returns errorlevel 113 for\n"
" flac files encoded with reference libFLAC 1.1.3 20061120.\n\n");
}
FLAC__bool GetOpts(int argc, char *argv[], unsigned int *pOpts, char *lpFileName)
{
int n;
if (argc < 2)
{
DispSyntax();
return false;
}
memset(lpFileName, '\0', MAXPATH);
*pOpts = 0;
for (n = 1; n < argc; n++)
{
if (argv[n][0] == '-' || argv[n][0] == '/')
{
switch (tolower(argv[n][1]))
{
case 'q':
*pOpts |= QUIET;
break;
}
}
else //this must be the filename..
strcpy(lpFileName, argv[n]);
}
if (*lpFileName)
return true;
return false;
}
FLAC__bool GetVendorString(char *lpVendorString, int nStrSize, char *lpFileName)
{
FLAC__bool bRet;
FLAC__StreamMetadata *pTags;
bRet = false;
memset(lpVendorString, '\0', nStrSize);
if (FLAC__metadata_get_tags(lpFileName, &pTags))
{
if (pTags->data.vorbis_comment.vendor_string.length)
{
strncpy(lpVendorString, (char *) pTags->data.vorbis_comment.vendor_string.entry, __min( pTags->data.vorbis_comment.vendor_string.length, (unsigned) nStrSize) );
bRet = true;
}
FLAC__metadata_object_delete(pTags);
}
return bRet;
}
int GetVendorInt(char *lpVendorString, int nStrSize, char *lpFileName)
{
char szReference[STRSIZE], szBuffer[STRSIZE];
int nVendorInt, nMajor, nMinor, nSub, nDate, nScanned;
nVendorInt = 0;
if (GetVendorString(lpVendorString, nStrSize, lpFileName))
{
//Parse this:
//"reference libFLAC 1.1.2 20050205"
nScanned = sscanf(lpVendorString, "%s %s %d.%d.%d %ld", szReference, szBuffer, &nMajor, &nMinor, &nSub, &nDate);
if (!(nScanned == EOF || nScanned < 5))
nVendorInt = (nMajor * 100) + (nMinor * 10) + nSub;
}
return nVendorInt;
}
int main(int argc, char *argv[])
{
char szFileName[MAXPATH];
char szVendorString[STRSIZE];
int nOpts, nVendor;
if (!GetOpts(argc, argv, &nOpts, szFileName))
return 0;
nVendor = 0;
nVendor = GetVendorInt(szVendorString, STRSIZE, szFileName);
if (nVendor && (! (nOpts & QUIET)))
printf("%s\n", szVendorString);
if (!nVendor)
{
if (!(nOpts & QUIET))
printf("Error: %s not found or contains no FLAC vendor string.\n", szFileName);
nVendor = 255;
}
return nVendor;
}
edit: code fix and added error check.
See http://www.hydrogenaudio.org/forums/index....showtopic=51084 for a win32 binary.