summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2021-03-31 13:58:39 +0200
committerHans Ulrich Niedermann <github@n-dimensional.de>2021-04-01 20:07:08 +0200
commit4316f75ed4ce7a4ae5296264699665631c4e62d6 (patch)
tree47ac144172d161092c91b313d9eab907d3b65e61 /tests
parent84ddc4ec3b44bf81fbda16ca006cc27e1d345b41 (diff)
downloadlibgphoto2-4316f75ed4ce7a4ae5296264699665631c4e62d6.tar.gz
Remove obsolete gp2ddb (gphoto2 device database) idea
The gphoto2 device database (gp2ddb) was originally intended to replace the device lists in the camlib code by a device list maintained in a text file outside of the camlib C code. This device list file could then be changed without recompiling camlibs, at the cost of adding a simple gp2ddb to internal binary representation compiler to libgphoto2. This would have allowed a user to very easily add a new camera model to the list of camera models supported by a specific camlib, as long as that new camera model uses the same protocol as already supported camera models do. As the gp2ddb idea has never been developed any further in the 15 yearns since my initial commit from 2006, this idea appears to be obsolete and can thus be removed from the codebase.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/ddb/Makefile.am51
-rw-r--r--tests/ddb/README.ddb158
-rw-r--r--tests/ddb/check-ddb.sh.in38
-rw-r--r--tests/ddb/ddb-common.c25
-rw-r--r--tests/ddb/ddb-common.h86
-rw-r--r--tests/ddb/ddb-txt.l114
-rw-r--r--tests/ddb/ddb-txt.y467
-rw-r--r--tests/ddb/test-ddb.c218
9 files changed, 0 insertions, 1159 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6c3d4449c..cbbe9523f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,8 +2,6 @@
# Housekeeping
########################################################################
-SUBDIRS = ddb
-
EXTRA_PROGRAMS =
check_PROGRAMS =
TESTS =
diff --git a/tests/ddb/Makefile.am b/tests/ddb/Makefile.am
deleted file mode 100644
index 52e07ea42..000000000
--- a/tests/ddb/Makefile.am
+++ /dev/null
@@ -1,51 +0,0 @@
-if ENABLED_GP2DDB
-flexbison_PROGRAMS_ = test-ddb
-flexbison_check_SCRIPTS_ = check-ddb.sh
-flexbison_BUILT_SOURCES_ = ddb-txt.tab.c ddb-txt.tab.h ddb-txt.yy.c
-flexbison_CLEANFILES_ = ddb-txt.output
-endif
-
-check_PROGRAMS = $(flexbison_PROGRAMS_)
-
-check_SCRIPTS = \
- $(flexbison_check_SCRIPTS_)
-
-EXTRA_DIST = \
- README.ddb \
- check-ddb.sh.in \
- ddb-txt.l \
- ddb-txt.y
-
-INSTALL_TESTS = $(check_SCRIPTS)
-
-# TESTS = $(check_SCRIPTS)
-
-BUILT_SOURCES = $(flexbison_BUILT_SOURCES_)
-CLEANFILES = $(check_SCRIPTS) $(BUILT_SOURCES) $(flexbison_CLEANFILES_) gp2ddb.txt
-
-test_ddb_SOURCES = $(flexbison_BUILT_SOURCES_) test-ddb.c ddb-common.c ddb-common.h
-test_ddb_LDADD = \
- -lfl \
- $(top_builddir)/libgphoto2/libgphoto2.la \
- $(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la \
- $(LIBLTDL) \
- $(LIBEXIF_LIBS) \
- $(INTLLIBS)
-
-ddb-txt.yy.c: ddb-txt.l ddb-txt.tab.h
- $(FLEX) -o$@ $<
-
-ddb-txt.tab.h: ddb-txt.tab.c
-ddb-txt.tab.c ddb-txt.tab.h: ddb-txt.y
- $(BISON) -v $<
-
-check-ddb.sh: check-ddb.sh.in $(top_builddir)/packaging/generic/print-camera-list test-ddb
-
-clean-local:
- rm -f *.s *.i
-
-$(top_builddir)/packaging/generic/print-camera-list:
- cd $(top_builddir)/packaging/generic && $(MAKE) $(AM_MAKEFLAGS) print-camera-list
-
-include $(top_srcdir)/installcheck.mk
-
diff --git a/tests/ddb/README.ddb b/tests/ddb/README.ddb
deleted file mode 100644
index 83167385b..000000000
--- a/tests/ddb/README.ddb
+++ /dev/null
@@ -1,158 +0,0 @@
-========================================================================
-The gphoto2 device database (gp2ddb)
-========================================================================
-
-Important: This is a prototype the developers can play with. The final
- version will probably look much different, so don't invest
- too much in it (yet).
-
-References:
- [1] http://article.gmane.org/gmane.comp.multimedia.gphoto.devel/2262
- Hubert's posting from 2006-01-01 proposing storage in XML.
-
-
-Note: We try to talk of "devices" and "drivers" instead of "cameras"
- and "camlibs" since we also support digital audio players.
-
-
-=============================================
-The idea
-========
-
- * Maintain a device database (DDB) of cameras (and audio players),
- their abilities etc. independently from the libgphoto2 drivers.
-
- * Updates to the database are much easier to publish than updates to
- the drivers which need to be compiled.
-
- * libgphoto2 uses the DDB to find out which driver to load for a
- given device.
-
- * drivers use the DDB to read special driver specific information on
- that device.
-
- * Other software (HAL, udev, hotplug, etc.) is served by converters
- from DDB.
-
-
-=============================================
-The implementation
-==================
-
- * A flex/bison based parser for text based config.
-
- * The specific details of the text format is not completely ironed
- out yet.
-
- * It is possible to use some HAL device database instead, but do we
- really want to require HAL/XML/...? Depends whether we target
- embedded or desktop environments.
-
- * print-camera-list prints the current config in the new format
- (minus driver internal settings ?)
-
- * driver specific settings can be accommodated using the
- driver_options { ... }; section.
-
- * The binary code (stripped) for the test case is about 22KByte. I
- suppose we could implement this database in about 35 to 40 KByte.
- However, we can probably get rid of some code in the drivers to
- compensate.
- For comparison:
- * The current libgphoto2.so is about 120 KByte stripped.
- * libxml2.so is 1.2MB (stripped).
-
-
-=============================================
-The testcase
-============
-
- * The testcase check-ddb.sh checks that the CameraAbilitiesList read
- from the text database is the same one read from the drivers via
- gp_abilities_list_load() - for all 700something cameras.
-
-
-=============================================
-How to test it
-==============
-
- * Add --enable-gp2ddb to your ./configure parameters.
-
- * Run "make check".
-
- * Have a look into tests/ddb/.
-
-
-=============================================
-TODO
-====
-
-What would need to be done to go into production with this:
-
- * Find a way to integrate the gphoto2 DDB with the HAL device
- database, possibly using a sub/superset of the HAL device
- database. However, HAL does its stuff in XML, and we probably don't
- want libgphoto2 to depend on an XML parser.
-
- * Add driver specific parameters to DDB.
-
- * Rewrite gp_abilities_list_load() to read the data currently stored
- in the CameryAbilities records and all driver specific information
- from the DDB.
-
- This should probably use a caching approach, i.e. it should check
- the mtime of (the files in) /etc/libgphoto2.d/ and compare that to
- the mtime of a binary cache file in ~/.gphoto/ddb-cache.
-
- The compiler which creates this cache file needs to be embedded in
- libgphoto2 itself (so that libgphoto2 can "just work") but should
- also be available as a separate tool for embedded use cases. These
- embedded systems could then compile the ddb-cache at build time,
- just read in the cache, and not ship the parser/compiler at all.
-
- Another possibility would be to statically compile the binary
- version of the database into libgphoto2 for small-footprint
- applications.
-
- * Rewrite all drivers to read their device specific parameters from
- the new CameraAbilities record.
-
- * Maintain binary compatibility for applications.
-
- * Administration utilities convert the DDB to something HAL, udev, and
- other similar hotplug-device-management systems use to figure out
- the device type, what program to launch to handle such devices, and
- how to set up permissions. This is partly done in print-camera-list.
-
- * Administration utilities to maintain the DDB in the face of
-
- - updates from the gphoto project
- - updates by the user
- - update by third parties
-
- One solution to the problem could be a directory structure like
-
- /etc/libgphoto2.d/camlib-agfa.ddb # the devices from the agfa camlib
- /etc/libgphoto2.d/camlib-canon.ddb # the devices from the canon camlib
- /etc/libgphoto2.d/camlib-ptp2.ddb # the devices from the ptp2 camlib
- /etc/libgphoto2.d/foo.ddb # devices the user got from somewhere
- /etc/libgphoto2.d/bar.ddb # devices the user got from somewhere
-
- * Check whether there wouldn't be an XML parsing library with a much
- smaller footprint than the 1.2MB of libxml2.
-
- * The DDB device names should be Unicode strings.
-
- * There must be structured information on device names, e.g. the
- vendor must be readable without parsing strings.
-
- * Store other device information in the DDB which may be of interest
- for a libgphoto2 frontend, e.g.
- - thumbnail images of the devices themselves.
- - camera features like capture modes, can delete single files, can
- delete all files, can mark downloaded files, can upload files
-
-
-========================================================================
-End of file README.ddb.
-========================================================================
diff --git a/tests/ddb/check-ddb.sh.in b/tests/ddb/check-ddb.sh.in
deleted file mode 100644
index ba0ba260e..000000000
--- a/tests/ddb/check-ddb.sh.in
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-# "make installcheck" testcase:
-# Compares camera list printed by print-camera-list and parsed by
-#test-ddb with the camera list from gp_abilities_list_load().
-# Fails if differences are found.
-
-set -ex
-
-debug=:
-#debug=false
-
-PACKAGE_TARNAME="${PACKAGE_TARNAME-"@PACKAGE_TARNAME@"}"
-prefix="${prefix-"@prefix@"}"
-exec_prefix="${exec_prefix-"@exec_prefix@"}"
-libdir="${libdir-"@libdir@"}"
-libexecdir="${libexecdir-"@libexecdir@"}"
-camlibdir="${camlibdir-"@camlibdir@"}"
-utilsdir="${utilsdir-"@utilsdir@"}"
-CAMLIBS="${DESTDIR}${camlibdir}"
-export CAMLIBS
-LD_LIBRARY_PATH="${DESTDIR}/${libdir}${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}"
-export LD_LIBRARY_PATH
-
-if "$debug"; then
- echo "====================="
- pwd
- echo "camlibdir=$camlibdir"
- echo "libdir=$libdir"
- echo "utilsdir=$utilsdir"
- echo "DESTDIR=$DESTDIR"
- echo "CAMLIBS=$CAMLIBS"
- echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
- echo "#####################"
-fi
-
-${DESTDIR}${utilsdir}/print-camera-list gp2ddb > gp2ddb.txt
-
-./test-ddb --compare < gp2ddb.txt
diff --git a/tests/ddb/ddb-common.c b/tests/ddb/ddb-common.c
deleted file mode 100644
index 155da6958..000000000
--- a/tests/ddb/ddb-common.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/** \file ddb-common.y
- * \author Copyright (C) 2006 Hans Ulrich Niedermann
- *
- * \note
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * \note
- * This library 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
- * Lesser General Public License for more details.
- *
- * \note
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#include "ddb-common.h"
-
-YYSTYPE yylval;
diff --git a/tests/ddb/ddb-common.h b/tests/ddb/ddb-common.h
deleted file mode 100644
index dbb779271..000000000
--- a/tests/ddb/ddb-common.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/** \file ddb-common.h
- * \author Copyright (C) 2006 Hans Ulrich Niedermann
- *
- * \note
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * \note
- * This library 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
- * Lesser General Public License for more details.
- *
- * \note
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __DDB_TXT_H__
-#define __DDB_TXT_H__
-
-#include <stdio.h>
-#include <gphoto2/gphoto2-abilities-list.h>
-
-typedef union {
- char *str_val;
- unsigned int ui_val;
-} symtype;
-
-#define YYSTYPE symtype
-
-extern int yylineno;
-
-void
-yyerror (const char *filename, CameraAbilitiesList *al,
- const char *str);
-
-int
-yyparse (const char *filenname, CameraAbilitiesList *al);
-
-#define YYLTYPE my_yyltype
-
-typedef struct {
- int lineno;
- int column;
- const char *filename;
-} FilePosition;
-
-typedef struct YYLTYPE {
- FilePosition begin, end;
-} YYLTYPE;
-
-
-#define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).begin.lineno = YYRHSLOC(Rhs, 1).begin.lineno; \
- (Current).begin.column = YYRHSLOC(Rhs, 1).begin.column; \
- (Current).end.lineno = YYRHSLOC(Rhs, N).end.lineno; \
- (Current).end.lineno = YYRHSLOC(Rhs, N).end.column; \
- } \
- else \
- { \
- (Current).begin.lineno = (Current).end.lineno = \
- YYRHSLOC(Rhs, 0).end.lineno; \
- (Current).begin.column = (Current).end.column = \
- YYRHSLOC(Rhs, 0).end.column; \
- } \
- while (0)
-
-#define YY_DECL int yylex (void)
-YY_DECL;
-/* #define YYLEX_PARAM void */
-
-/* #define YYDEBUG 1 */
-
-extern FILE *yyin;
-
-void lexer_reset(const char *_filename);
-
-#endif /* !__DDB_TXT_H__ */
diff --git a/tests/ddb/ddb-txt.l b/tests/ddb/ddb-txt.l
deleted file mode 100644
index 72edfabff..000000000
--- a/tests/ddb/ddb-txt.l
+++ /dev/null
@@ -1,114 +0,0 @@
-/** \file ddb-txt.l
- * \author Copyright (C) 2006 Hans Ulrich Niedermann
- *
- * \note
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * \note
- * This library 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
- * Lesser General Public License for more details.
- *
- * \note
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-%option nounput
-%option noyywrap
-%option yylineno
-%option nobackup
-
-%{
-#include <stdlib.h>
-#include <errno.h>
-#define _GNU_SOURCE
-#include <string.h>
-#include "ddb-common.h"
-#include "ddb-txt.tab.h"
-
-//#if !(YYDEBUG)
-# define ECHO do {} while (0)
-//#endif
-
-extern char *strndup(const char *s, size_t n);
-
-static char *filename = NULL;
-
-YYSTYPE yylval = { str_val: NULL };
-
-static void lexer_error(const char *msg);
-
-%}
-
-%%
-\#.*$ { /* ignore comment */ }
-"interface" { ECHO; return TOK_INTERFACE; }
-"{" { ECHO; return TOK_BEGIN; }
-"driver" { ECHO; return TOK_DRIVER; }
-"device" { ECHO; return TOK_DEVICE; }
-"}" { ECHO; return TOK_END; }
-"serial" { ECHO; return TOK_SERIAL; }
-"usb" { ECHO; return TOK_USB; }
-"disk" { ECHO; return TOK_DISK; }
-"ptpip" { ECHO; return TOK_PTPIP; }
-"class" { ECHO; return TOK_CLASS; }
-"subclass" { ECHO; return TOK_SUBCLASS; }
-"protocol" { ECHO; return TOK_PROTOCOL; }
-"vendor" { ECHO; return TOK_VENDOR; }
-"product" { ECHO; return TOK_PRODUCT; }
-"speeds" { ECHO; return TOK_SPEEDS; }
-"operations" { ECHO; return TOK_OPERATIONS; }
-"driver_options" { ECHO; return TOK_DRIVER_OPTIONS; }
-"option" { ECHO; return TOK_OPTION; }
-"file_operations" { ECHO; return TOK_FILE_OPERATIONS; }
-"folder_operations" { ECHO; return TOK_FOLDER_OPERATIONS; }
-"driver_status" { ECHO; return TOK_DRIVER_STATUS; }
-"device_type" { ECHO; return TOK_DEVICE_TYPE; }
-("none"|"config"|"capture_image"|"capture_video"|"capture_audio"|"capture_preview"|"delete"|"preview"|"raw"|"audio"|"exif"|"delete_all"|"put_file"|"make_dir"|"remove_dir"|"production"|"testing"|"experimental"|"deprecated"|"still_camera"|"audio_player") {
- ECHO;
- yylval.str_val = strndup(yytext, yyleng);
- return VAL_FLAG;
- }
-";" { ECHO; return TOK_SEP; }
-"," { ECHO; return TOK_COMMA; }
-\"[A-Za-z0-9\.\+\-<>\|_/()!:,;=\\\$\'@&%\{\}\[\]+#~\* ]+\" { ECHO;
- yylval.str_val = strndup(yytext, yyleng);
- return TOK_STRING;
- }
-(0x)?[0-9a-fA-F]+ {ECHO;
- yylval.ui_val = strtoul(yytext, NULL, 0);
- if ((ERANGE == errno) &&
- (ULONG_MAX == yylval.ui_val)) {
- lexer_error("Number out of range");
- } else if (EINVAL == errno) {
- lexer_error("Invalid number");
- }
- return TOK_NUMBER;
- }
-\n { ECHO; /* ignore newlines */ }
-[ \t\r]+ { ECHO; /* ignore whitespace */ }
-. {
- static char msg[] = "unexpected character (in string?) '?'";
- msg[strlen(msg)-2] = yytext[0];
- lexer_error(msg);
- }
-%%
-
-void lexer_reset(const char *_filename)
-{
- filename = (char *) _filename;
-}
-
-static void lexer_error(const char *msg)
-{
- fprintf(stderr, "%s:%d: lexer error: %s\n",
- filename, yylineno, msg);
- exit(4);
-}
diff --git a/tests/ddb/ddb-txt.y b/tests/ddb/ddb-txt.y
deleted file mode 100644
index 85629f60e..000000000
--- a/tests/ddb/ddb-txt.y
+++ /dev/null
@@ -1,467 +0,0 @@
-/** \file ddb-txt.y
- * \author Copyright (C) 2006 Hans Ulrich Niedermann
- *
- * \note
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * \note
- * This library 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
- * Lesser General Public License for more details.
- *
- * \note
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-%{
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <gphoto2/gphoto2-abilities-list.h>
-
-#include "ddb-common.h"
-#include "ddb-txt.tab.h"
-
-
-extern char *yytext;
-
-
-char *current_driver = NULL;
-char *current_device_name = NULL;
-CameraAbilities ca;
-unsigned int speed_index = 0;
-
-char *alloc_parse_string(char *s);
-
-char *error_string = NULL;
-
-static void reset_ca(void);
-
-
-#ifdef __GNUC__
-#define __unused__ __attribute__((unused))
-#else
-#define __unused__
-#endif
-
-
-static int
-compare_camera_abilities(const CameraAbilities *a,
- const CameraAbilities *b);
-
-
-%}
-
-%defines
-
-/* This is supposed to track linenumbers and stuff, but I don't know how to
- * make it work. */
-%locations
-
-/* Pure yylex. */
-//%pure-parser
-
-/* More than "syntax error" */
-%error-verbose
-
-/* parameters to yyparse() and yyerror() */
-%parse-param { char const *file_name };
-%parse-param { CameraAbilitiesList *al };
-
-/* parameters to yylex() */
-/* %lex-param { CameraAbilitiesList *al }; */
-
-%initial-action
-{
- lexer_reset(file_name);
- yyloc.begin.filename = yyloc.end.filename = file_name;
- yyloc.begin.column = yyloc.end.column = -1;
- yyloc.begin.lineno = yyloc.end.lineno = -1;
- @$.begin.filename = @$.end.filename = file_name;
- error_string = NULL;
-};
-
-%token TOK_SEP TOK_COMMA
-%token TOK_WHITESPACE TOK_NEWLINE
-
-%token <ui_val> TOK_NUMBER
-%token <str_val> TOK_STRING
-
-%token TOK_INTERFACE
-%token TOK_DRIVER
-%token TOK_DEVICE
-%token TOK_BEGIN
-%token TOK_END
-
-%token TOK_SERIAL
-%token TOK_SPEEDS
-
-%token TOK_USB
-%token TOK_PRODUCT
-%token TOK_VENDOR
-%token TOK_CLASS
-%token TOK_SUBCLASS
-%token TOK_PROTOCOL
-
-%token TOK_DISK
-%token TOK_PTPIP
-
-%token TOK_DEVICE_TYPE
-%token TOK_DRIVER_STATUS
-%token TOK_OPERATIONS
-%token TOK_FILE_OPERATIONS
-%token TOK_FOLDER_OPERATIONS
-
-%token TOK_DRIVER_OPTIONS
-%token TOK_OPTION
-
-%token <str_val> VAL_FLAG
-
- /* %type <ui_val> interface_usb_vendor */
- /* %type <ui_val> interface_usb_product */
-
-%start devices
-
-%%
-
-devices:
- /* empty */
- | devices device
- ;
-
-device:
- TOK_DEVICE TOK_STRING TOK_BEGIN
- {
- current_device_name = alloc_parse_string($<str_val>2);
- /* printf("BEGIN_DEVICE <<%s>>\n", current_device_name); */
- reset_ca();
- strncpy(ca.model, current_device_name, sizeof(ca.model));
- ca.model[sizeof(ca.model)-1]='\0';
- }
- device_type
- driver_definition
- driver_status
- operations
- file_operations
- folder_operations
- interfaces
- driver_options
- TOK_END
- {
- //printf("END_DEVICE <<%s>>\n", current_device_name);
- free(current_device_name); current_device_name = NULL;
- if (current_driver != NULL) {
- free(current_driver); current_driver = NULL;
- }
- gp_abilities_list_append(al, ca);
- }
- TOK_SEP
- ;
-
-driver_options:
- /* empty */
- | TOK_DRIVER_OPTIONS TOK_BEGIN
- driver_option_list
- TOK_END TOK_SEP
- ;
-
-driver_option_list:
- /* empty */
- | driver_option_list driver_option_item
- ;
-
-driver_option_item:
- TOK_OPTION TOK_STRING TOK_SEP
- | TOK_OPTION TOK_STRING TOK_STRING TOK_SEP
- ;
-
-device_type:
- /* empty */
- | TOK_DEVICE_TYPE VAL_FLAG TOK_SEP
- {
- if (gpi_string_to_enum($<str_val>2, &ca.device_type,
- gpi_gphoto_device_type_map)) {
- error_string = $<str_val>2;
- yyerror(file_name, al,
- "illegal device_type value");
- }
- }
- ;
-
-driver_definition:
- TOK_DRIVER TOK_STRING TOK_SEP
- {
- const char *camlib_env = getenv(CAMLIBDIR_ENV);
- const char *camlibs = (camlib_env != NULL)?camlib_env:CAMLIBS;
- current_driver = alloc_parse_string($<str_val>2);
- strncpy(ca.library, camlibs, sizeof(ca.library));
- strncat(ca.library, "/", sizeof(ca.library)-strlen(ca.library)-1);
- strncat(ca.library, current_driver, sizeof(ca.library)-strlen(ca.library)-1);
- ca.library[sizeof(ca.library)-1] = '\0';
- //printf(" DRIVER <<%s>>\n", current_driver);
- }
- ;
-
-driver_status:
- /* empty */
- | TOK_DRIVER_STATUS VAL_FLAG TOK_SEP
- {
- if (gpi_string_to_enum($<str_val>2, &ca.status,
- gpi_camera_driver_status_map)) {
- error_string = $<str_val>2;
- yyerror(file_name, al,
- "illegal driver_status value");
- }
- }
- ;
-
-folder_operations:
- /* empty */
- | TOK_FOLDER_OPERATIONS folder_operations_list TOK_SEP
- ;
-
-file_operations:
- /* empty */
- | TOK_FILE_OPERATIONS file_operations_list TOK_SEP
- ;
-
-operations:
- /* empty */
- | TOK_OPERATIONS operations_list TOK_SEP
- ;
-
-folder_operations_list:
- folder_operations_list TOK_COMMA folder_operation
- | folder_operation
- ;
-
-file_operations_list:
- file_operations_list TOK_COMMA file_operation
- | file_operation
- ;
-
-operations_list:
- operations_list TOK_COMMA operation
- | operation
- ;
-
-folder_operation:
- VAL_FLAG
- {
- if (gpi_string_or_to_flags($<str_val>1, &ca.folder_operations,
- gpi_folder_operation_map)) {
- error_string = $<str_val>1;
- yyerror(file_name, al,
- "illegal folder_operation flag");
- }
- }
- ;
-
-file_operation:
- VAL_FLAG
- {
- if (gpi_string_or_to_flags($<str_val>1, &ca.file_operations,
- gpi_file_operation_map)) {
- error_string = $<str_val>1;
- yyerror(file_name, al,
- "illegal file_operation flag");
- }
- }
- ;
-
-operation:
- VAL_FLAG
- {
- if (gpi_string_or_to_flags($<str_val>1,
- &ca.operations,
- gpi_camera_operation_map)) {
- error_string = $<str_val>1;
- yyerror(file_name, al,
- "illegal operation flag");
- }
- }
- ;
-
-interfaces:
- /* empty */
- | interfaces interface TOK_SEP
- ;
-
-interface:
- interface_serial
- | interface_usb
- | TOK_INTERFACE TOK_DISK {
- ca.port |= GP_PORT_DISK;
- }
- | TOK_INTERFACE TOK_PTPIP {
- ca.port |= GP_PORT_PTPIP;
- }
- ;
-
-interface_serial:
- TOK_INTERFACE TOK_SERIAL
- {
- ca.port |= GP_PORT_SERIAL;
- /* Ideally: Prepare serial entry. */
- }
- TOK_BEGIN
- interface_serial_internal
- TOK_END
- {
- /* Ideally: Add serial entry to database. */
- }
- ;
-
-interface_serial_internal:
- /* empty */
- | TOK_SPEEDS speed_number_list TOK_SEP
- {
- if (speed_index < (sizeof(ca.speed)/sizeof(ca.speed[0]))) {
- ca.speed[speed_index++] = 0;
- } else {
- ca.speed[(sizeof(ca.speed)/sizeof(ca.speed[0]))-1] = 0;
- }
- }
- ;
-
-speed_number_list:
- speed_number_list TOK_COMMA speed_list_number
- | speed_list_number
- ;
-
-speed_list_number:
- TOK_NUMBER
- {
- if (speed_index < (sizeof(ca.speed)/sizeof(ca.speed[0]))) {
- ca.speed[speed_index++] = $<ui_val>1;
- }
- }
- ;
-
-/* FIXME: Make sure that the CameraAbilities usb_* fields are not
- * overwritten by multiple definitions
- */
-
-interface_usb:
- TOK_INTERFACE TOK_USB
- TOK_BEGIN
- {
- ca.port |= GP_PORT_USB;
- /* Ideally: Prepare USB entry for this camera */
- }
- interface_usb_internal
- TOK_END
- {
- /* Ideally: Commit prepared USB entry to database */
- }
- ;
-
-interface_usb_internal:
- interface_usb_vendprod_optional
- interface_usb_class_optional
- ;
-
-interface_usb_vendprod_optional:
- /* empty */
- | interface_usb_vendor
- interface_usb_product
- ;
-
-interface_usb_vendor:
- TOK_VENDOR TOK_NUMBER TOK_SEP
- {
- ca.usb_vendor = $<ui_val>2;
- }
- ;
-
-interface_usb_product:
- TOK_PRODUCT TOK_NUMBER TOK_SEP
- {
- ca.usb_product = $<ui_val>2;
- }
- ;
-
-interface_usb_class_optional:
- /* empty */
- | TOK_CLASS TOK_NUMBER TOK_SEP
- {
- ca.usb_class = $<ui_val>2;
- }
- interface_usb_subclass_optional
- ;
-
-interface_usb_subclass_optional:
- /* empty */
- | TOK_SUBCLASS TOK_NUMBER TOK_SEP
- {
- ca.usb_subclass = $<ui_val>2;
- }
- interface_usb_protocol_optional
- ;
-
-interface_usb_protocol_optional:
- /* empty */
- | TOK_PROTOCOL TOK_NUMBER TOK_SEP
- {
- ca.usb_protocol = $<ui_val>2;
- }
- ;
-
-%%
-
-
-char *alloc_parse_string(char *s)
- {
- if (s[0] == '"') {
- int len = strlen(s);
- if (s[len-1] == '"') {
- char *ret = malloc(len-2+1);
- strncpy(ret, &s[1], len-2);
- ret[len-2] = '\0';
- free(s);
- return ret;
- } else {
- fprintf(stderr, "Error: string does not end with quote: <<%s>>\n", s);
- exit(2);
- }
- } else {
- fprintf(stderr, "Error: string does not start with quote: <<%s>>\n", s);
- exit(2);
- }
- }
-
-
-void yyerror(const char *filename,
- CameraAbilitiesList __unused__ *al,
- const char *str)
-{
- fprintf(stderr, "%s:%d: parse error: %s\n",
- filename, yylineno, str);
- fprintf(stderr, "%s:%d- near: `%s'\n",
- filename, yylineno, yytext);
- if (NULL != error_string) {
- fprintf(stderr, "%s:%d- <<%s>>\n",
- filename, yylineno, error_string);
- error_string = NULL;
- }
- exit(4);
-}
-
-
-static void
-reset_ca(void)
-{
- memset(&ca, 0, sizeof(ca));
- speed_index = 0;
- /* FIXME: These defaults are of dubious quality. */
- ca.usb_subclass = -1;
- ca.usb_protocol = -1;
-}
diff --git a/tests/ddb/test-ddb.c b/tests/ddb/test-ddb.c
deleted file mode 100644
index 72ba73c60..000000000
--- a/tests/ddb/test-ddb.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/** \file test-ddb.c
- * \author Copyright (C) 2006 Hans Ulrich Niedermann
- *
- * \note
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * \note
- * This library 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
- * Lesser General Public License for more details.
- *
- * \note
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <gphoto2/gphoto2-abilities-list.h>
-
-#include "ddb-common.h"
-#include "ddb-txt.tab.h"
-
-static int
-compare_camera_abilities(const CameraAbilities *a,
- const CameraAbilities *b);
-
-CameraAbilitiesList *
-read_abilities_list(const char *filename);
-CameraAbilitiesList *
-read_abilities_list(const char *filename)
-{
- CameraAbilitiesList *al = NULL;
- int retval;
- if (0!=(retval = gp_abilities_list_new(&al))) { return NULL; }
- if (0!=(retval = yyparse(filename, al))) { goto error; }
- return al;
- error:
- if (al!=NULL)
- gp_abilities_list_free(al);
- return NULL;
-}
-
-
-static int
-compare_lists (void)
-{
- unsigned int errors = 0;
- CameraAbilitiesList *ddb = read_abilities_list(NULL);
- CameraAbilitiesList *clb;
- unsigned int i, j, n_ddb, n_clb;
- gp_abilities_list_new(&clb);
- gp_abilities_list_load(clb, NULL);
- n_ddb = gp_abilities_list_count(ddb);
- n_clb = gp_abilities_list_count(clb);
- fprintf(stderr, "## Comparing ddb with clb ##\n");
- for (i=0, j=0; (i<n_ddb) && (j<n_clb); ) {
- CameraAbilities a, b;
- gp_abilities_list_get_abilities(ddb, i, &a);
- gp_abilities_list_get_abilities(clb, j, &b);
- if ((b.port & GP_PORT_USB) && (b.usb_class == 666)) {
- /* ignore this camera */
- j++;
- continue;
- }
- if (compare_camera_abilities(&a, &b)) {
- errors++;
- }
- i++, j++;
- }
- gp_abilities_list_free(clb);
- gp_abilities_list_free(ddb);
- return (errors == 0)? 0 : 1;
-}
-
-
-int main(int argc, char *argv[])
-{
- int i;
- int retval;
- CameraAbilitiesList *al;
-#if YYDEBUG
- yydebug = 1;
-#endif
- if (0!=(retval=gp_abilities_list_new(&al))) {
- fprintf(stderr, "Could not create CameraAbilitiesList\n");
- return 6;
- }
- if (argc > 1) {
- for (i=1; i<argc; i++) {
- if (0==strcmp("--compare", argv[i])) {
- return compare_lists();
- } else {
- const char *filename = argv[i];
- yyin = fopen(filename, "r");
- if (NULL == yyin) {
- fprintf(stderr, "File %s does not exist. Aborting.\n", filename);
- return 5;
- }
- retval = yyparse(filename, al);
- fclose(yyin);
- if (retval != 0) {
- return retval;
- }
- }
- }
- return 0;
- } else {
- yyin = stdin;
- return yyparse("<stdin>", al);
- }
-}
-
-
-
-
-#define CMP_RET_S(cmp_func, field) \
- do { \
- int retval = cmp_func(a->field, b->field); \
- if (retval != 0) { \
- fprintf(stderr, " difference in .%s: <<%s>> vs <<%s>>\n", \
- #field, a->field, b->field); \
- errors++; \
- } \
- } while (0)
-
-#define CMP_RET_UI(cmp_func, field) \
- do { \
- int retval = cmp_func((unsigned int) (a->field), \
- (unsigned int) (b->field)); \
- if (retval != 0) { \
- fprintf(stderr, " difference in .%s: 0x%x vs 0x%x\n", \
- #field, (unsigned int) (a->field), \
- (unsigned int) (b->field)); \
- errors++; \
- } \
- } while (0)
-
-
-static int
-uicmp(unsigned int a, unsigned int b)
-{
- if (a < b) return -1;
- else if (a > b) return 1;
- else return 0;
-}
-
-static int
-strcmp_colon(const char *a, const char *b)
-{
- unsigned int i = 0;
- while (1) {
- if ((a[i] == '\0') && (b[i] == '\0'))
- return 0;
- if (a[i] == '\0')
- return -1;
- if (b[i] == '\0')
- return 1;
- if (a[i] == b[i])
- goto next;
- if (((a[i] == ' ') && (b[i] == ':')) ||
- ((a[i] == ':') && (a[i] == ' ')))
- goto next;
- if (a[i] < b[i])
- return -1;
- if (a[i] > b[i])
- return 1;
- fprintf(stderr, "Internal error in strcmp_colon\n");
- exit(13);
- next:
- ++i;
- }
-}
-
-
-static int
-compare_camera_abilities(const CameraAbilities *a,
- const CameraAbilities *b)
-{
- unsigned int errors = 0;
- int i;
- CMP_RET_S(strcmp_colon, model);
- CMP_RET_S(strcmp, library);
- /* CMP_RET_S(strcmp, id); */
- CMP_RET_UI(uicmp, port);
- if ((a->port & GP_PORT_SERIAL)) {
- for (i=0; (a->speed[i] != 0) && (a->speed[i] != 0); i++) {
- CMP_RET_UI(uicmp, speed[i]);
- }
- }
- CMP_RET_UI(uicmp, operations);
- CMP_RET_UI(uicmp, file_operations);
- CMP_RET_UI(uicmp, folder_operations);
- if ((a->port & GP_PORT_USB)) {
- CMP_RET_UI(uicmp, usb_vendor);
- CMP_RET_UI(uicmp, usb_product);
- CMP_RET_UI(uicmp, usb_class);
- if (a->usb_class != 0) {
- CMP_RET_UI(uicmp, usb_subclass);
- CMP_RET_UI(uicmp, usb_protocol);
- }
- }
- CMP_RET_UI(uicmp, device_type);
- if (errors == 0) {
- return 0;
- } else {
- fprintf(stderr, "Difference for <<%s>>\n", a->model);
- return 1;
- }
-}