summaryrefslogtreecommitdiff
path: root/regtest/sndfile-regtest.c
blob: a28caa2d8458091214d9fa063bf1b62ff537d03d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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