sndfile-regtest.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. ** Copyright (C) 2005-2011 Erik de Castro Lopo
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ** GNU General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include "config.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <sndfile.h>
  23. #if HAVE_SQLITE3
  24. #include "regtest.h"
  25. enum
  26. { OPT_ADD_FILE = 0x0100,
  27. OPT_CREATE_DB = 0x0200,
  28. OPT_DEL_ENTRY = 0x0400,
  29. OPT_LIST_ALL = 0x0800,
  30. OPT_TEST_ALL = 0x1000,
  31. OPT_VERBOSE = 0x2000
  32. } ;
  33. static void print_libsndfile_version (void) ;
  34. int
  35. main (int argc, char * argv [])
  36. { const char *db_name = "./.sndfile-regtest.db" ;
  37. REG_DB *reg_db ;
  38. int k, retval ;
  39. if (argc < 2)
  40. { printf ("\nUsage message goes here.\n\n") ;
  41. exit (0) ;
  42. } ;
  43. if (argc == 2 && strcmp (argv [1], "--create-db") == 0)
  44. return db_create (db_name) ;
  45. reg_db = db_open (db_name) ;
  46. if (argc == 2)
  47. { if (strcmp (argv [1], "--list-all") == 0)
  48. return db_list_all (reg_db) ;
  49. if (strcmp (argv [1], "--check-all") == 0)
  50. { print_libsndfile_version () ;
  51. retval = db_check_all (reg_db) ;
  52. puts ("\nDone.\n") ;
  53. return retval ;
  54. } ;
  55. } ;
  56. if (argc == 3 && strcmp (argv [1], "--del-entry") == 0)
  57. { db_del_entry (reg_db, argv [2]) ;
  58. db_close (reg_db) ;
  59. return 0 ;
  60. } ;
  61. if (strcmp (argv [1], "--check-file") == 0)
  62. { print_libsndfile_version () ;
  63. for (k = 2 ; k < argc ; k++)
  64. db_check_file (reg_db, argv [k]) ;
  65. db_close (reg_db) ;
  66. return 0 ;
  67. } ;
  68. if (strcmp (argv [1], "--add-file") == 0)
  69. { print_libsndfile_version () ;
  70. for (k = 2 ; k < argc ; k++)
  71. db_add_file (reg_db, argv [k]) ;
  72. db_close (reg_db) ;
  73. return 0 ;
  74. } ;
  75. printf ("\nError : unhandled command line args :") ;
  76. for (k = 1 ; k < argc ; k++)
  77. printf (" %s", argv [k]) ;
  78. puts ("\n") ;
  79. return 1 ;
  80. } /* main */
  81. static void
  82. print_libsndfile_version (void)
  83. { char version [64] ;
  84. sf_command (NULL, SFC_GET_LIB_VERSION, version, sizeof (version)) ;
  85. printf ("\nsndfile-regtest : using %s\n\n", version) ;
  86. } /* print_lib_version */
  87. #else
  88. int
  89. main (void)
  90. {
  91. puts ("\nThis program was not compiled with libsqlite3 and hence doesn't work.\n") ;
  92. return 0 ;
  93. } /* main */
  94. #endif