Initial commit

added libraries:
opus
flac
libsndfile

updated:
libvorbis
libogg
openal

- Everything works as expected for now. Bare in mind libsndfile needed the check for whether or not it could find the xiph libraries removed in order for this to work.
This commit is contained in:
marauder2k7 2024-03-21 17:33:47 +00:00
parent 05a083ca6f
commit a745fc3757
1954 changed files with 431332 additions and 21037 deletions

View file

@ -0,0 +1,108 @@
sndfile-regtest
===============
The 'sndfile-regtest' program is a regression test-suite for libsndile.
This program is intended to allow anyone who has an interest in the
reliability and correctness of libsndfile to do their own regression
testing. From the point of view of the libsndfile developers, this
program now allows for distributed regression testing of libsndfile
which will make libsndfile better.
How Does it Work
----------------
Anyone who wishes to take part in the distributed regression testing of
libsndfile can download the regression test program and install it.
Once installed the user can start collecting files and adding them to
their own personal database. Then, as new versions of libsndfile come
out, the user should test the new library version against their database
of files (instructions below).
Any files which were successfully added to the database in the past but
now fail the check with the new library version represent a regression.
The user should then contact the libsndfile developers so that a copy
of the test file can be made available to the developers.
Requirements
------------
The regression test program uses sqlite3 as the database engine. On
Debian, the required packages are :
sqlite3
libsqlite3-0
libsqlite3-dev
but similar packages should be available on any other Linux style
system.
The regression test currently only compiles under Unix-like systems.
At some time in the future the regression test will distributed along
with the libsndfile source code distribution.
Organization of Files
---------------------
The regession test program keeps its database file in the directory it
is run from. In addition, the database only contains information about
the files, not the files themselves.
This means that database file should probably be kept in the same
directory (or a directory above) the test files.
Setting it Up for the First Time
--------------------------------
The sndfile-regtest program should be on your PATH. You can then cd into
the directory where you intend to keep you test files and
run the command:
sndfile-regtest --create-db
which creates a file named '.sndfile-regtest.db' in the current directory.
Files can then be added to the database using the command:
sndfile-regtest --add-file file1.wav
The --add-file option allows more than one file to be added at a time
using:
sndfile-regtest --add-file file1.wav file2.aif .....
Checking Files
--------------
One or more files that have already been added to the database can be
checked using:
sndfile-regtest --check-file file1.wav file2.aif .....
It is also possible to check all files in the database using:
sndfile-regtest --check-all
Running a Regression Test
-------------------------
Once you have a collection of files and a database it is possible to test
new versions of libsndfile before you install them. If for instance you
have just compiled a new version of libsndfile in the directory
/usr/src/libsndfile-X.Y.Z, then you can use an existing sndfile-regtest
binary with the new libsndfile using something like:
LD_PRELOAD=/usr/src/libsndfile-X.Y.Z/src/.libs/libsndfile.so.X.Y.Z \
sndfile-regtest --check-all
Reporting Regressions
---------------------
Any user who finds a file which was added to the regression database with
an earlier version of libsndfile and then fails the check with a later
version of the library should contact the author (erikd at mega dash nerd
dot com). If possible place the file on a web server and email the author
a link to it.

View file

@ -0,0 +1,117 @@
/*
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
** A simple checksum for short, int and float data.
*/
#include "sfconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sndfile.h>
#include "regtest.h"
#define BIG_PRIME 999983
#define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0])))
static int short_checksum (SNDFILE * file, int start) ;
static int int_checksum (SNDFILE * file, int start) ;
static int float_checksum (SNDFILE * file, int start) ;
int
calc_checksum (SNDFILE * file, const SF_INFO * info)
{ int start ;
/* Seed the checksum with data from the SF_INFO struct. */
start = info->samplerate ;
start = start * BIG_PRIME + info->channels ;
start = start * BIG_PRIME + info->format ;
switch (info->format & SF_FORMAT_SUBMASK)
{ case SF_FORMAT_FLOAT :
case SF_FORMAT_DOUBLE :
return float_checksum (file, start) ;
case SF_FORMAT_PCM_24 :
case SF_FORMAT_PCM_32 :
return int_checksum (file, start) ;
default :
return short_checksum (file, start) ;
} ;
return 0 ;
} /* calc_checksum */
/*------------------------------------------------------------------------------
*/
static union
{ short s [1 << 16] ;
int i [1 << 15] ;
float f [1 << 15] ;
} data ;
static int
short_checksum (SNDFILE * file, int start)
{ int k, count ;
do
{ count = (int) sf_read_short (file, data.s, ARRAY_LEN (data.s)) ;
for (k = 0 ; k < count ; k++)
start = start * BIG_PRIME + data.s [k] ;
}
while (count > 0) ;
return start ;
} /* short_checksum */
static int
int_checksum (SNDFILE * file, int start)
{ int k, count ;
do
{ count = (int) sf_read_int (file, data.i, ARRAY_LEN (data.i)) ;
for (k = 0 ; k < count ; k++)
start = start * BIG_PRIME + data.i [k] ;
}
while (count > 0) ;
return start ;
} /* int_checksum */
static int
float_checksum (SNDFILE * file, int start)
{ int k, count ;
do
{ count = (int) sf_read_float (file, data.f, ARRAY_LEN (data.f)) ;
for (k = 0 ; k < count ; k++)
start = start * BIG_PRIME + lrintf (2147483648.0f * data.f [k]) ;
}
while (count > 0) ;
return start ;
} /* float_checksum */

View file

@ -0,0 +1,542 @@
/*
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#include "sf_unistd.h"
#endif
#include <string.h>
#include <fcntl.h>
#ifdef HAVE_DIRECT_H
#include <direct.h>
#endif
#include <sys/stat.h>
#include <sndfile.h>
#include "regtest.h"
#if HAVE_SQLITE3
#include <ctype.h>
#include <sqlite3.h>
typedef struct
{ sqlite3 *sql ;
int count ;
int ekey_max ;
/* Filename and pathname for file. */
char filename [256] ;
char pathname [512] ;
/* Storage for createding SQL commands. Must be larger than logbuf below. */
char cmdbuf [1 << 15] ;
/* Storage for log buffer retrieved from SNDFILE* .*/
char logbuf [1 << 14] ;
} REGTEST_DB ;
/* In checksum.c */
int calc_checksum (SNDFILE * file, const SF_INFO * info) ;
static void get_filename_pathname (REGTEST_DB * db, const char *filepath) ;
static void single_quote_replace (char * buf) ;
static int get_ekey_from_filename (REGTEST_DB * db, const char *filepath) ;
static int get_filename_pathname_by_ekey (REGTEST_DB * db, int ekey) ;
static int check_file_by_ekey (REGTEST_DB * db, int ekey) ;
static int count_callback (REGTEST_DB * db, int argc, char **argv, char **colname) ;
static int ekey_max_callback (REGTEST_DB * db, int argc, char **argv, char **colname) ;
static int callback (void *unused, int argc, char **argv, char **colname) ;
static const char *db_basename (const char *fname);
/* Windows accepts both '\\' and '/' in paths */
#ifdef _WIN32
#define IS_SLASH(c) ((c) == '\\' || (c) == '/')
#define HAS_DRIVELETTER(path) (isalpha ((int)(path[0])) && path[1] == ':' && IS_SLASH(path[2]))
#else
#define IS_SLASH(c) ((c) == '/')
#define HAS_DRIVELETTER(path) 0
#endif
REG_DB *
db_open (const char * db_name)
{ REGTEST_DB * db ;
int err ;
if ((db = malloc (sizeof (REGTEST_DB))) == NULL)
{ perror ("malloc") ;
exit (1) ;
} ;
if ((err = sqlite3_open (db_name, &(db->sql))) != 0)
{ printf ("Can't open database: %s\n", sqlite3_errmsg (db->sql)) ;
sqlite3_close (db->sql) ;
free (db) ;
exit (1) ;
} ;
return (REG_DB *) db ;
} /* db_open */
int
db_create (const char * db_name)
{ REGTEST_DB * db ;
const char *cmd ;
char * errmsg = NULL ;
int err ;
db = (REGTEST_DB *) db_open (db_name) ;
cmd = "create table sndfile (ekey INTEGER PRIMARY KEY,"
"fname VARCHAR(1),"
"fpath VARCHAR(1),"
"srate INTEGER,"
"frames VARCHAR(1),"
"channels INTEGER,"
"format VARCHAR(1),"
"checksum VARCHAR(1),"
"logbuf VARCHAR(1)"
");" ;
err = sqlite3_exec (db->sql, cmd, callback, 0, &errmsg) ;
if (err != SQLITE_OK)
printf ("Line %d : SQL error: %s\n", __LINE__, errmsg) ;
sqlite3_close (db->sql) ;
free (db) ;
return 0 ;
} /* db_create */
int
db_close (REG_DB * db_handle)
{ REGTEST_DB * db ;
db = (REGTEST_DB *) db_handle ;
sqlite3_close (db->sql) ;
free (db) ;
return 0 ;
} /* db_close */
/*==============================================================================
*/
int
db_file_exists (REG_DB * db_handle, const char * filename)
{ REGTEST_DB * db ;
char * errmsg ;
int err ;
db = (REGTEST_DB *) db_handle ;
filename = db_basename (filename);
snprintf (db->cmdbuf, sizeof (db->cmdbuf), "select fname from sndfile where fname='%s'", filename) ;
db->count = 0 ;
err = sqlite3_exec (db->sql, db->cmdbuf, (sqlite3_callback) count_callback, db, &errmsg) ;
if (err == 0 && db->count == 1)
return 1 ;
return 0 ;
} /* db_file_exists */
int
db_add_file (REG_DB * db_handle, const char * filepath)
{ REGTEST_DB * db ;
SNDFILE * sndfile ;
SF_INFO info ;
char * errmsg ;
int err, checksum ;
db = (REGTEST_DB *) db_handle ;
get_filename_pathname (db, filepath) ;
if (db_file_exists (db_handle, filepath))
{ printf (" %s : already in database\n", db->filename) ;
return 0 ;
} ;
memset (&info, 0, sizeof (info)) ;
sndfile = sf_open (db->pathname, SFM_READ, &info) ;
sf_command (sndfile, SFC_GET_LOG_INFO, db->logbuf, sizeof (db->logbuf)) ;
checksum = (sndfile == NULL) ? 0 : calc_checksum (sndfile, &info) ;
sf_close (sndfile) ;
if (sndfile == NULL)
{ printf (" %s : could not open : %s, filepath: '%s'\n", db->filename, sf_strerror (NULL), filepath) ;
puts (db->logbuf) ;
return 1 ;
} ;
single_quote_replace (db->logbuf) ;
snprintf (db->cmdbuf, sizeof (db->cmdbuf), "insert into sndfile "
"(fname, fpath, srate, frames, channels, format, checksum, logbuf) values"
"('%s','%s',%d,'%ld', %d, '0x%08x', '0x%08x', '%s');",
db->filename, db->pathname, info.samplerate, (long) info.frames, info.channels, info.format, checksum, db->logbuf) ;
if (strlen (db->cmdbuf) >= sizeof (db->cmdbuf) - 1)
{ printf ("strlen (db->cmdbuf) too long.\n") ;
exit (1) ;
} ;
err = sqlite3_exec (db->sql, db->cmdbuf, callback, 0, &errmsg) ;
if (err != SQLITE_OK)
{ printf ("Line %d : SQL error: %s\n", __LINE__, errmsg) ;
puts (db->cmdbuf) ;
} ;
return 0 ;
} /* db_add_file */
int
db_check_file (REG_DB * db_handle, const char * filepath)
{ REGTEST_DB * db ;
int ekey ;
if (db_file_exists (db_handle, filepath) == 0)
{ printf ("\nFile not in database.\n\n") ;
exit (0) ;
} ;
db = (REGTEST_DB *) db_handle ;
ekey = get_ekey_from_filename (db, filepath) ;
return check_file_by_ekey (db, ekey) ;
} /* db_check_file */
/*==============================================================================
*/
int
db_check_all (REG_DB * db_handle)
{ REGTEST_DB * db ;
char * errmsg ;
int err, ekey ;
db = (REGTEST_DB *) db_handle ;
db->ekey_max = 0 ;
snprintf (db->cmdbuf, sizeof (db->cmdbuf), "select ekey from sndfile") ;
err = sqlite3_exec (db->sql, db->cmdbuf, (sqlite3_callback) ekey_max_callback, db, &errmsg) ;
if (err != SQLITE_OK)
{ printf ("Line %d : SQL error: %s\n", __LINE__, errmsg) ;
puts (db->cmdbuf) ;
} ;
for (ekey = 1 ; ekey <= db->ekey_max ; ekey++)
if (get_filename_pathname_by_ekey (db, ekey) != 0)
check_file_by_ekey (db, ekey) ;
return 0 ;
} /* db_check_all */
int
db_list_all (REG_DB * db_handle)
{
printf ("%s : %p\n", __func__, (void *) db_handle) ;
return 0 ;
} /* db_list_all */
int
db_del_entry (REG_DB * db_handle, const char * entry)
{
printf ("%s : %p %s\n", __func__, (void *) db_handle, entry) ;
return 0 ;
} /* db_del_entry */
/*==============================================================================
*/
static int
get_ekey_from_filename (REGTEST_DB * db, const char *filepath)
{ char * errmsg, **result ;
int err, ekey = 0, rows, cols ;
get_filename_pathname (db, filepath) ;
snprintf (db->cmdbuf, sizeof (db->cmdbuf), "select ekey from sndfile where fname='%s'", db->filename) ;
err = sqlite3_get_table (db->sql, db->cmdbuf, &result, &rows, &cols, &errmsg) ;
if (err != SQLITE_OK)
{ printf ("Line %d : SQL error: %s\n", __LINE__, errmsg) ;
puts (db->cmdbuf) ;
} ;
if (cols != 1 || rows != 1)
{ printf ("Bad juju!! rows = %d cols = %d\n", rows, cols) ;
exit (1) ;
} ;
ekey = strtol (result [1], NULL, 10) ;
sqlite3_free_table (result) ;
return ekey ;
} /* get_ekey_from_filename */
static int
get_filename_pathname_by_ekey (REGTEST_DB * db, int ekey)
{ char *errmsg, **result ;
int err, rows, cols ;
snprintf (db->cmdbuf, sizeof (db->cmdbuf), "select fname,fpath from sndfile where ekey='%d'", ekey) ;
err = sqlite3_get_table (db->sql, db->cmdbuf, &result, &rows, &cols, &errmsg) ;
if (err != SQLITE_OK)
{ printf ("Line %d : SQL error: %s\n", __LINE__, errmsg) ;
puts (db->cmdbuf) ;
return 0 ;
} ;
if (cols != 2 || rows != 1)
{ printf ("\nError (%s %d) : rows = %d cols = %d\n", __func__, __LINE__, rows, cols) ;
exit (1) ;
} ;
snprintf (db->filename, sizeof (db->filename), "%s", result [2]) ;
snprintf (db->pathname, sizeof (db->pathname), "%s", result [3]) ;
sqlite3_free_table (result) ;
return 1 ;
} /* get_filename_pathname_by_ekey */
static int
check_file_by_ekey (REGTEST_DB * db, int ekey)
{ SNDFILE * sndfile ;
SF_INFO info ;
char * errmsg, **result ;
int err, k, rows, cols, checksum ;
printf (" %s : ", db->filename) ;
fflush (stdout) ;
memset (&info, 0, sizeof (info)) ;
sndfile = sf_open (db->pathname, SFM_READ, &info) ;
sf_command (sndfile, SFC_GET_LOG_INFO, db->logbuf, sizeof (db->logbuf)) ;
checksum = (sndfile == NULL) ? 0 : calc_checksum (sndfile, &info) ;
sf_close (sndfile) ;
if (sndfile == NULL)
{ printf ("\n\nError : Could not open '%s' : %s\n", db->pathname, sf_strerror (NULL)) ;
puts (db->logbuf) ;
exit (1) ;
} ;
single_quote_replace (db->logbuf) ;
snprintf (db->cmdbuf, sizeof (db->cmdbuf), "select fname,srate,frames,channels,format,"
"checksum,logbuf from sndfile where ekey='%d'", ekey) ;
err = sqlite3_get_table (db->sql, db->cmdbuf, &result, &rows, &cols, &errmsg) ;
if (err != SQLITE_OK)
{ printf ("Line %d : SQL error: %s\n", __LINE__, errmsg) ;
puts (db->cmdbuf) ;
} ;
for (k = 0 ; k < cols ; k++)
{ if (strcmp (result [k], "fname") == 0)
{ if (strcmp (result [k + cols], db->filename) == 0)
continue ;
printf ("\n\nError : fname doesn't match : %s != %s\n", result [k + cols], db->filename) ;
} ;
if (strcmp (result [k], "srate") == 0)
{ if (strtol (result [k + cols], NULL, 10) == info.samplerate)
continue ;
printf ("\n\nError : srate doesn't match : %s == %d\n", result [k + cols], info.samplerate) ;
} ;
if (strcmp (result [k], "frames") == 0)
{ if (strtoll (result [k + cols], NULL, 10) == info.frames)
continue ;
printf ("\n\nError : frames doesn't match : %s == %ld\n", result [k + cols], (long) info.frames) ;
} ;
if (strcmp (result [k], "channels") == 0)
{ if (strtol (result [k + cols], NULL, 10) == info.channels)
continue ;
printf ("\n\nError : channels doesn't match : %s == %d\n", result [k + cols], info.channels) ;
} ;
if (strcmp (result [k], "format") == 0)
{ if (strtol (result [k + cols], NULL, 16) == info.format)
continue ;
printf ("\n\nError : format doesn't match : %s == 0x%08x\n", result [k + cols], info.format) ;
} ;
if (strcmp (result [k], "checksum") == 0)
{ int db_val = (int) strtoll (result [k + cols], NULL, 16) ;
if (db_val == checksum)
continue ;
printf ("\n\nError : checksum doesn't match : 0x%08x == 0x%08x\n", db_val, checksum) ;
} ;
if (strcmp (result [k], "logbuf") == 0)
continue ;
printf ("\nHere is the old logubuffer :\n\n%s\n\nand the new :\n\n%s\n\n", result [2 * cols - 1], db->logbuf) ;
exit (1) ;
} ;
sqlite3_free_table (result) ;
puts ("ok") ;
return 0 ;
} /* check_file_by_ekey */
/*==============================================================================
*/
static void
get_filename_pathname (REGTEST_DB * db, const char *filepath)
{
const char * basename = db_basename (filepath) ;
size_t slen ;
/* Test for a relative path
*/
if (!IS_SLASH(filepath [0]) && !HAS_DRIVELETTER(filepath))
{ memset (db->pathname, 0, sizeof (db->pathname)) ;
if (getcwd (db->pathname, sizeof (db->pathname)) == NULL)
{ perror ("\ngetcwd failed") ;
exit (1) ;
} ;
slen = strlen (db->pathname) ;
/* a '/' is fine for Windows too */
snprintf (db->pathname + slen, sizeof (db->pathname) - slen, "/%s", filepath) ;
}
else
snprintf (db->pathname, sizeof (db->pathname), "%s", filepath) ;
snprintf (db->filename, sizeof (db->filename), "%s", basename) ;
basename = db_basename (db->pathname) ;
if (basename == db->pathname)
{ printf ("\nError : bad pathname %s\n", filepath) ;
exit (1) ;
} ;
} /* get filename_pathname */
static void
single_quote_replace (char * buf)
{ while ((buf = strchr (buf, '\'')) != 0)
buf [0] = '"' ;
} /* single_quote_replace */
static int
count_callback (REGTEST_DB * db, int argc, char **argv, char **colname)
{ db->count ++ ;
(void) argc ;
(void) argv ;
(void) colname ;
return 0 ;
} /* count_callback */
static int
ekey_max_callback (REGTEST_DB * db, int argc, char **argv, char **unused)
{ int ekey ;
(void) argc ;
(void) unused ;
ekey = strtol (argv [0], NULL, 10) ;
if (ekey > db->ekey_max)
db->ekey_max = ekey ;
return 0 ;
} /* ekey_max_callback */
static int
callback (void *unused, int argc, char **argv, char **colname)
{ int k ;
(void) unused ;
for (k = 0 ; k < argc ; k++)
printf ("%s = %s\n", colname [k], argv [k] ? argv [k] : "NULL") ;
printf ("\n") ;
return 0 ;
} /* callback */
/*
* Win32: Strip drive-letter and directory from a filename.
* non-Win32: Strip directory from a filename.
*/
static const char *db_basename (const char *fname)
{
const char *base = fname;
#if !defined(_WIN32)
const char *slash = strrchr (base, '/');
if (slash)
base = slash + 1 ;
#else
if (fname[0] && fname[1] == ':') {
fname += 2;
base = fname;
}
while (*fname) {
if (IS_SLASH(*fname))
base = fname + 1;
fname++;
}
#endif
return base ;
}
#else
int dummy (void) ;
int
dummy (void)
{ /*
** Empty dummy fnction so tha compiler doesn't winge about an
** empty file.
*/
return 0 ;
} /* dummy */
#endif

View file

@ -0,0 +1,38 @@
/*
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
typedef struct REG_DB_tag REG_DB ;
/* In database.c */
REG_DB * db_open (const char * db_name) ;
int db_create (const char * dbname) ;
int db_close (REG_DB * db_handle) ;
int db_file_exists (REG_DB * db_handle, const char * filename) ;
int db_add_file (REG_DB * db_handle, const char * filename) ;
int db_check_file (REG_DB * db_handle, const char * filename) ;
int db_list_all (REG_DB * db_handle) ;
int db_check_all (REG_DB * db_handle) ;
int db_del_entry (REG_DB * db_handle, const char * entry) ;
/* In checksum.c */
int calc_checksum (SNDFILE * file, const SF_INFO * info) ;

View file

@ -0,0 +1,121 @@
/*
** Copyright (C) 2005-2011 Erik de Castro Lopo
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sndfile.h>
#if HAVE_SQLITE3
#include "regtest.h"
enum
{ OPT_ADD_FILE = 0x0100,
OPT_CREATE_DB = 0x0200,
OPT_DEL_ENTRY = 0x0400,
OPT_LIST_ALL = 0x0800,
OPT_TEST_ALL = 0x1000,
OPT_VERBOSE = 0x2000
} ;
static void print_libsndfile_version (void) ;
int
main (int argc, char * argv [])
{ const char *db_name = "./.sndfile-regtest.db" ;
REG_DB *reg_db ;
int k, retval ;
if (argc < 2)
{ printf ("\nUsage message goes here.\n\n") ;
exit (0) ;
} ;
if (argc == 2 && strcmp (argv [1], "--create-db") == 0)
return db_create (db_name) ;
reg_db = db_open (db_name) ;
if (argc == 2)
{ if (strcmp (argv [1], "--list-all") == 0)
return db_list_all (reg_db) ;
if (strcmp (argv [1], "--check-all") == 0)
{ print_libsndfile_version () ;
retval = db_check_all (reg_db) ;
puts ("\nDone.\n") ;
return retval ;
} ;
} ;
if (argc == 3 && strcmp (argv [1], "--del-entry") == 0)
{ db_del_entry (reg_db, argv [2]) ;
db_close (reg_db) ;
return 0 ;
} ;
if (strcmp (argv [1], "--check-file") == 0)
{ print_libsndfile_version () ;
for (k = 2 ; k < argc ; k++)
db_check_file (reg_db, argv [k]) ;
db_close (reg_db) ;
return 0 ;
} ;
if (strcmp (argv [1], "--add-file") == 0)
{ print_libsndfile_version () ;
for (k = 2 ; k < argc ; k++)
db_add_file (reg_db, argv [k]) ;
db_close (reg_db) ;
return 0 ;
} ;
printf ("\nError : unhandled command line args :") ;
for (k = 1 ; k < argc ; k++)
printf (" %s", argv [k]) ;
puts ("\n") ;
return 1 ;
} /* main */
static void
print_libsndfile_version (void)
{ char version [64] ;
sf_command (NULL, SFC_GET_LIB_VERSION, version, sizeof (version)) ;
printf ("\nsndfile-regtest : using %s\n\n", version) ;
} /* print_lib_version */
#else
int
main (void)
{
puts ("\nThis program was not compiled with libsqlite3 and hence doesn't work.\n") ;
return 0 ;
} /* main */
#endif