diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Makefile.in | 71 | ||||
-rw-r--r-- | include/getopt.h | 129 | ||||
-rw-r--r-- | include/lalloca.h | 47 | ||||
-rw-r--r-- | include/sane/config.h.in | 219 | ||||
-rw-r--r-- | include/sane/sanei.h | 173 | ||||
-rw-r--r-- | include/sane/sanei_codec_ascii.h | 62 | ||||
-rw-r--r-- | include/sane/sanei_codec_bin.h | 61 | ||||
-rw-r--r-- | include/sane/sanei_debug.h | 176 | ||||
-rw-r--r-- | include/sane/sanei_wire.h | 132 |
9 files changed, 1070 insertions, 0 deletions
diff --git a/include/Makefile.in b/include/Makefile.in new file mode 100644 index 0000000..7ef48dd --- /dev/null +++ b/include/Makefile.in @@ -0,0 +1,71 @@ +SHELL = /bin/sh + +VPATH = @srcdir@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = .. + +PACKAGE = @PACKAGE@ +VERSION = @VERSION@ +distdir = $(top_srcdir)/$(PACKAGE)-$(VERSION) + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +configdir = ${sysconfdir}/sane.d +sanedatadir = ${datadir}/sane +docdir=$(prefix)/doc/sane-@VERSION@ + +MKDIR = $(top_srcdir)/mkinstalldirs +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +LN_S = @LN_S@ + +@SET_MAKE@ + +SANE_INCLUDES = $(addprefix $(top_srcdir)/include/sane/,config.h.in sanei.h \ + sanei_codec_ascii.h sanei_codec_bin.h sanei_debug.h sanei_wire.h) +OTHER_INCLUDES = $(addprefix $(top_srcdir)/include/,Makefile.in getopt.h \ + lalloca.h) + +DISTFILES = $(SANE_INCLUDES) $(OTHER_INCLUDES) + +.PHONY: all clean depend dist install uninstall + +all: + +dist: $(DISTFILES) + $(MKDIR) $(distdir)/include/sane + for file in $(OTHER_INCLUDES); do \ + ln $$file $(distdir)/include 2> /dev/null \ + || cp -p $$file $(distdir)/include; \ + done + for file in $(SANE_INCLUDES); do \ + ln $$file $(distdir)/include/sane 2> /dev/null \ + || cp -p $$file $(distdir)/include/sane; \ + done + +install: + +uninstall: + +clean: + +depend: + +distclean: clean + rm -f *~ sane/*~ + rm -f sane/config.h + rm -f Makefile diff --git a/include/getopt.h b/include/getopt.h new file mode 100644 index 0000000..aa7877f --- /dev/null +++ b/include/getopt.h @@ -0,0 +1,129 @@ +/* Declarations for getopt. + Copyright (C) 1989, 90, 91, 92, 93, 94 Free Software Foundation, Inc. + + 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef _GETOPT_H +#define _GETOPT_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ +#if defined (__STDC__) && __STDC__ + const char *name; +#else + char *name; +#endif + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +#if defined (__STDC__) && __STDC__ +#ifdef __GNU_LIBRARY__ +/* Many other libraries have conflicting prototypes for getopt, with + differences in the consts, in stdlib.h. To avoid compilation + errors, only prototype getopt for the GNU C library. */ +extern int getopt (int argc, char *const *argv, const char *shortopts); +#else /* not __GNU_LIBRARY__ */ +extern int getopt (); +#endif /* __GNU_LIBRARY__ */ +extern int getopt_long (int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind); +extern int getopt_long_only (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind); + +/* Internal only. Users should not call this directly. */ +extern int _getopt_internal (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind, + int long_only); +#else /* not __STDC__ */ +extern int getopt (); +extern int getopt_long (); +extern int getopt_long_only (); + +extern int _getopt_internal (); +#endif /* __STDC__ */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GETOPT_H */ diff --git a/include/lalloca.h b/include/lalloca.h new file mode 100644 index 0000000..0fd4fc1 --- /dev/null +++ b/include/lalloca.h @@ -0,0 +1,47 @@ +/* sane - Scanner Access Now Easy. + Copyright (C) 1997 The Free Software Foundation + This file is part of the SANE package. + + SANE 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. + + SANE 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 sane; see the file COPYING. If not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + This file implements a dynamic linking based SANE meta backend. It + allows managing an arbitrary number of SANE backends by using + dynamic linking to load backends on demand. */ + +#ifndef lalloca_h +#define lalloca_h + +/* AIX requires this to be the first thing in the file. */ +#ifdef __GNUC__ +# define alloca __builtin_alloca +#else +# if HAVE_ALLOCA_H +# include <alloca.h> +# else +# ifdef _AIX +#pragma alloca +# else +# ifndef alloca /* predefined by HP cc +Olibcalls */ +# if __STDC__ +void *alloca (); +# else +char *alloca (); +# endif +# endif +# endif +# endif +#endif + +#endif /* lalloca_h */ diff --git a/include/sane/config.h.in b/include/sane/config.h.in new file mode 100644 index 0000000..baf35be --- /dev/null +++ b/include/sane/config.h.in @@ -0,0 +1,219 @@ +/* include/sane/config.h.in. Generated from configure.in by autoheader. */ + +/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP + systems. This function is required for `alloca.c' support on those systems. + */ +#undef CRAY_STACKSEG_END + +/* Define to 1 if using `alloca.c'. */ +#undef C_ALLOCA + +/* Define to 1 if GIMP 1.2 support wanted */ +#undef ENABLE_GIMP_1_2 + +/* Define to 1 if you have `alloca', as a function or macro. */ +#undef HAVE_ALLOCA + +/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix). + */ +#undef HAVE_ALLOCA_H + +/* Define to 1 if you have the `atexit' function. */ +#undef HAVE_ATEXIT + +/* Define to 1 if you have the <fcntl.h> header file. */ +#undef HAVE_FCNTL_H + +/* Define to 1 if you have the `getenv' function. */ +#undef HAVE_GETENV + +/* Define to 1 if you have the `getpagesize' function. */ +#undef HAVE_GETPAGESIZE + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `isfdtype' function. */ +#undef HAVE_ISFDTYPE + +/* Define to 1 if you have the <libc.h> header file. */ +#undef HAVE_LIBC_H + +/* Define to 1 if you have the <libgimp/gimpfeatures.h> header file. */ +#undef HAVE_LIBGIMP_GIMPFEATURES_H + +/* Define to 1 if you have the <libgimp/gimp.h> header file. */ +#undef HAVE_LIBGIMP_GIMP_H + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the `socket' library (-lsocket). */ +#undef HAVE_LIBSOCKET + +/* Define to 1 if you have the `syslog' library (-lsyslog). */ +#undef HAVE_LIBSYSLOG + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `mkdir' function. */ +#undef HAVE_MKDIR + +/* Define to 1 if you have a working `mmap' system call. */ +#undef HAVE_MMAP + +/* Define to 1 if you have the <os2.h> header file. */ +#undef HAVE_OS2_H + +/* Define to 1 if you have the `sigprocmask' function. */ +#undef HAVE_SIGPROCMASK + +/* Define to 1 if you have the `snprintf' function. */ +#undef HAVE_SNPRINTF + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#undef HAVE_STRCASECMP + +/* Define to 1 if you have the `strdup' function. */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the `strftime' function. */ +#undef HAVE_STRFTIME + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strncasecmp' function. */ +#undef HAVE_STRNCASECMP + +/* Define to 1 if you have the `strndup' function. */ +#undef HAVE_STRNDUP + +/* Define to 1 if you have the `strsep' function. */ +#undef HAVE_STRSEP + +/* Define to 1 if you have the `strstr' function. */ +#undef HAVE_STRSTR + +/* Define to 1 if you have the `strtod' function. */ +#undef HAVE_STRTOD + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/time.h> header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the `usleep' function. */ +#undef HAVE_USLEEP + +/* Define to 1 if you have the `vsyslog' function. */ +#undef HAVE_VSYSLOG + +/* Define to the name of the distribution. */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the name and the version of the distribution. */ +#undef PACKAGE_VERSION + +/* Define as the return type of signal handlers (`int' or `void'). */ +#undef RETSIGTYPE + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at run-time. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +#undef STACK_DIRECTION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to the version of the distribution. */ +#undef VERSION + +/* Define to 1 if on AIX 3. + System headers sometimes define this. + We just want to avoid a redefinition error message. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif + +/* Define to 1 if on MINIX. */ +#undef _MINIX + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#undef _POSIX_1_SOURCE + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#undef _POSIX_SOURCE + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define as `__inline' if that's what the C compiler calls it, or to nothing + if it is not supported. */ +#undef inline + +/* Define to `int' if <sys/types.h> does not define. */ +#undef pid_t + +/* Define to `unsigned' if <sys/types.h> does not define. */ +#undef size_t + +/* Define to `long' if <sys/types.h> does not define. */ +#undef ssize_t + +/* Define for OS/2 only */ +#undef strcasecmp + +/* Define for OS/2 only */ +#undef strncasecmp + +/* Define to `unsigned char' if <sys/types.h> does not define. */ +#undef u_char + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +#undef u_int + +/* Define to `unsigned short' if <sys/types.h> does not define. */ +#undef u_int16_t + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +#undef u_int32_t + +/* Define to `unsigned char' if <sys/types.h> does not define. */ +#undef u_int8_t + +/* Define to `unsigned long' if <sys/types.h> does not define. */ +#undef u_long diff --git a/include/sane/sanei.h b/include/sane/sanei.h new file mode 100644 index 0000000..d736b17 --- /dev/null +++ b/include/sane/sanei.h @@ -0,0 +1,173 @@ +/* sane - Scanner Access Now Easy. + Copyright (C) 1996 David Mosberger-Tang and Andreas Beck + Copyright (C) 2002, 2003 Henning Meier-Geinitz + + This file is part of the SANE package. + + SANE 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. + + SANE 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 sane; see the file COPYING. If not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. +*/ + +/** @file sanei.h + * Convenience macros and function declarations for backends + * @sa sanei_backend.h sanei_thread.h + */ + +/* Doxygen documentation */ + +/** @mainpage SANEI (SANE internal routines) documentation + * + * @image html ../images/sane-logo2.jpg + * @section intro Introduction + * + * The header files in the include/sane/ directory named sanei_*.h provide + * function declarations and macros that can be used by every SANE backend. + * Their implementations can be found in the sanei/ directory. The code aims + * to be platform-independent to avoid lots of \#ifdef code in the backends. + * Please use the SANEI functions wherever possible. + * + * This documentation was created by the use of doxygen, the + * doc/doxygen-sanei.conf configuration file and dcoumentation in the sanei_*.h + * files. + * + * This documenation is far from complete. Any help is appreciated. + * + * @section additional Additional documentation + * - The SANE standard can be found at <a + * href="http://www.sane-project.org/html/">the SANE webserver</a>. + * - Information on how to write a backend: <a + * href="../backend-writing.txt">backend-writing.txt</a>. + * - General SANE documentation is on <a + * href="http://www.sane-project.org/docs.html>the SANE documentation + * page</a>. + * + * @section contact Contact + * + * The common way to contact the developers of SANE is the sane-devel + * mailing list. See the <a + * href="http://www.sane-project.org/mailing-lists.html">mailing list webpage</a> + * for details. That's the place to ask questions, report bugs, or announce + * a new backend. + * + */ + +#ifndef sanei_h +#define sanei_h + +#include <sane/sane.h> + +/** @name Public macros and functions + * @{ + */ +/** @def STRINGIFY(x) + * Turn parameter into string. + */ +/** @def PASTE(x,y) + * Concatenate parameters. + * + */ +/** @def NELEMS(a) + * Return number of elements of an array. + * + */ + +/** @fn extern SANE_Status sanei_check_value (const SANE_Option_Descriptor * opt, void * value); + * Check the constraints of a SANE option. + * + * @param opt option to check + * @param value value of the option + * + * @return + * - SANE_STATUS_GOOD - on success + * - SANE_STATUS_INVAL - if the value doesn't fit inside the constraint + * or any other error occured + * @sa sanei_constrain_value() + */ + +/** @fn extern SANE_Status sanei_constrain_value (const SANE_Option_Descriptor * opt, void * value, SANE_Word * info); + * Check the constraints of a SANE option and adjust its value if necessary. + * + * Depending on the type of the option and constraint, value is modified + * to fit inside constraint. + * + * @param opt option to check + * @param value value of the option + * @param info info is set to SANE_INFO_INEXACT if value was changed + * + * @return + * - SANE_STATUS_GOOD - on success + * - SANE_STATUS_INVAL - if the function wasn't able to fit value into the + * constraint or any other error occured + * @sa sanei_check_value() + */ + +/* @} */ + +/** @name Private macros + * @{ + */ +/** @def STRINGIFY1(x) + * Internal use only. + */ +/** @def PASTE1(x,y) + * Internal use only. + */ +/* @} */ + +/* A few convenience macros: */ +/** @hideinitializer */ +#define NELEMS(a) ((int)(sizeof (a) / sizeof (a[0]))) + +/** @hideinitializer */ +#define STRINGIFY1(x) #x +/** @hideinitializer */ +#define STRINGIFY(x) STRINGIFY1(x) + +/** @hideinitializer */ +#define PASTE1(x,y) x##y +/** @hideinitializer */ +#define PASTE(x,y) PASTE1(x,y) + +extern SANE_Status sanei_check_value (const SANE_Option_Descriptor * opt, + void * value); + +extern SANE_Status sanei_constrain_value (const SANE_Option_Descriptor * opt, + void * value, SANE_Word * info); + + +extern int sanei_save_values (int fd, SANE_Handle device); +extern int sanei_load_values (int fd, SANE_Handle device); + +#endif /* sanei_h */ diff --git a/include/sane/sanei_codec_ascii.h b/include/sane/sanei_codec_ascii.h new file mode 100644 index 0000000..991499a --- /dev/null +++ b/include/sane/sanei_codec_ascii.h @@ -0,0 +1,62 @@ +/* sane - Scanner Access Now Easy. + Copyright (C) 1996 David Mosberger-Tang and Andreas Beck + This file is part of the SANE package. + + SANE 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. + + SANE 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 sane; see the file COPYING. If not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. +*/ + +/** @file sanei_codec_ascii.h + * ASCII codec for network and file transmissions + * + * Instead translating data to a byte stream this codec uses ASCII hex numbers. + * Therefore it can be used for streams that are not 8-bit clean or which can + * only use printable characters. It's currently used for saving/restoring + * data to/from disk. + * + * @sa sanei_codec_bin.h sanei_net.h sanei_wire.h + */ +#ifndef sanei_codec_ascii_h +#define sanei_codec_ascii_h + +/** Initialize the ascii codec + * + * Set the i/o functions of the Wire to those of the ASCII codec. + * + * @param w Wire + */ +extern void sanei_codec_ascii_init (Wire *w); + +#endif /* sanei_codec_ascii_h */ diff --git a/include/sane/sanei_codec_bin.h b/include/sane/sanei_codec_bin.h new file mode 100644 index 0000000..ba17bac --- /dev/null +++ b/include/sane/sanei_codec_bin.h @@ -0,0 +1,61 @@ +/* sane - Scanner Access Now Easy. + Copyright (C) 1996 David Mosberger-Tang and Andreas Beck + This file is part of the SANE package. + + SANE 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. + + SANE 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 sane; see the file COPYING. If not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. +*/ + +/** @file sanei_codec_bin.h + * Binary codec for network transmissions + * + * Transtale data to a byte stream while taking byte order problems into + * account. This codec is currently used for saned and the network backend. + * + * @sa sanei_codec_ascii.h sanei_net.h sanei_wire.h + */ + +#ifndef sanei_codec_bin_h +#define sanei_codec_bin_h + +/** Initialize the binary codec + * + * Set the i/o functions of the Wire to those of the binary codec. + * + * @param w Wire + */ +extern void sanei_codec_bin_init (Wire *w); + +#endif /* sanei_codec_bin_h */ diff --git a/include/sane/sanei_debug.h b/include/sane/sanei_debug.h new file mode 100644 index 0000000..5cf2e45 --- /dev/null +++ b/include/sane/sanei_debug.h @@ -0,0 +1,176 @@ +/** @file sanei_debug.h + * Support for printing debug messages. + * + * Use the functions of this header file to print debug or warning messages. + */ + +#ifndef _SANEI_DEBUG_H +#define _SANEI_DEBUG_H + +#include <sane/sanei.h> + +/** @name Public macros + * These macros can be used in backends and other SANE-related + * code. + * + * Before including sanei_debug.h, the following macros must be set: + * + * - BACKEND_NAME - The name of your backend without double-quotes (must be set in any case) + * - STUBS - If this is defined, no macros will be included. Used in + * backends consisting of more than one .c file. + * - DEBUG_DECLARE_ONLY - Generates prototypes instead of functions. Used in + * backends consisting of more than one .c file. + * - DEBUG_NOT_STATIC - Doesn't generate static functions. Used in header files if + * they are include in more than one .c file. + * + * @{ + */ + +/** @def DBG_INIT() + * Initialize sanei_debug. + * + * Call this function before you use any DBG function. + */ + +/** @def DBG(level, fmt, ...) + * Print a message at debug level `level' or higher using a printf-like + * function. Example: DBG(1, "sane_open: opening fd \%d\\n", fd). + * + * @param level debug level + * @param fmt format (see man 3 printf for details) + * @param ... additional arguments + */ + +/** @def IF_DBG(x) + * Compile code only if debugging is enabled. + * + * Expands to x if debug support is enabled at compile-time. If NDEBUG is + * defined at compile-time this macro expands to nothing. + * + * @param x code to expand when debugging is enabled + */ + +/** + * @def DBG_LEVEL + * Current debug level. + * + * You can only read this "variable". + */ + +/** @def ENTRY(name) + * Expands to sane_BACKEND_NAME_name. + * + * Example: ENTRY(init) in mustek.c will expand to sane_mustek_init. + */ + +/* @} */ + +/** @name Internal macros and functions + * Do not use in your own code. + * @{ + */ + +/** @def DBG_LOCAL + * Do not use in backends directly. + * + * Internal wrapper for printing function. + */ + +/** @fn extern void sanei_init_debug (const char * backend, int * debug_level_var); + * Do not use in backends directly. + * + * Actual init function. + */ + +/** @fn extern void sanei_debug_msg (int level, int max_level, const char *be, const char *fmt, va_list ap); + * Do not use in backends directly. + * + * Actual printing function. + */ +/* @} */ + + /** @hideinitializer*/ +#define ENTRY(name) PASTE(PASTE(PASTE(sane_,BACKEND_NAME),_),name) + +#ifdef NDEBUG + +extern void sanei_debug_ndebug (int level, const char *msg, ...); + +# define DBG_LEVEL (0) +# define DBG_INIT() +# define DBG sanei_debug_ndebug +# define IF_DBG(x) + +#else /* !NDEBUG */ + + /** @hideinitializer*/ +# define DBG_LEVEL PASTE(sanei_debug_,BACKEND_NAME) + +# if defined(BACKEND_NAME) && !defined(STUBS) +# ifdef DEBUG_DECLARE_ONLY +extern int DBG_LEVEL; +# else /* !DEBUG_DECLARE_ONLY */ +int DBG_LEVEL = 0; +# endif /* DEBUG_DECLARE_ONLY */ +# endif /* BACKEND_NAME && !STUBS */ + + /** @hideinitializer*/ +# define DBG_INIT() \ + sanei_init_debug (STRINGIFY(BACKEND_NAME), &DBG_LEVEL) + + /** @hideinitializer*/ +# define DBG_LOCAL PASTE(DBG_LEVEL,_call) + + +# ifndef STUBS + +# ifdef DEBUG_DECLARE_ONLY + +extern void DBG_LOCAL (int level, const char *msg, ...) +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +; + +# else /* !DEBUG_DECLARE_ONLY */ + +# include <stdarg.h> + +extern void sanei_debug_msg + (int level, int max_level, const char *be, const char *fmt, va_list ap); + +#ifdef __GNUC__ +# ifndef DEBUG_NOT_STATIC +static +# endif /* !DEBUG_NOT_STATIC */ +void DBG_LOCAL (int level, const char *msg, ...) __attribute__ ((format (printf, 2, 3))); +#endif /* __GNUC__ */ + +# ifndef DEBUG_NOT_STATIC +static +# endif /* !DEBUG_NOT_STATIC */ +void +DBG_LOCAL (int level, const char *msg, ...) +{ + va_list ap; + + va_start (ap, msg); + sanei_debug_msg (level, DBG_LEVEL, STRINGIFY(BACKEND_NAME), msg, ap); + va_end (ap); +} + +# endif /* DEBUG_DECLARE_ONLY */ + +# endif /* !STUBS */ + + /** @hideinitializer*/ +# define DBG DBG_LOCAL + +extern void sanei_init_debug (const char * backend, int * debug_level_var); + + /** @hideinitializer*/ +# define IF_DBG(x) x + +#endif /* NDEBUG */ + +#endif /* _SANEI_DEBUG_H */ diff --git a/include/sane/sanei_wire.h b/include/sane/sanei_wire.h new file mode 100644 index 0000000..95be5cf --- /dev/null +++ b/include/sane/sanei_wire.h @@ -0,0 +1,132 @@ +/* sane - Scanner Access Now Easy. + Copyright (C) 1997 David Mosberger-Tang + This file is part of the SANE package. + + SANE 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. + + SANE 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 sane; see the file COPYING. If not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. + + Support routines to translate internal datatypes into a wire-format + (used for RPCs and to save/restore options). */ + +#ifndef sanei_wire_h +#define sanei_wire_h + +#include <sys/types.h> + +#define MAX_MEM (1024 * 1024) + +typedef enum + { + WIRE_ENCODE = 0, + WIRE_DECODE, + WIRE_FREE + } +WireDirection; + +struct Wire; + +typedef void (*WireCodecFunc) (struct Wire *w, void *val_ptr); +typedef ssize_t (*WireReadFunc) (int fd, void * buf, size_t len); +typedef ssize_t (*WireWriteFunc) (int fd, const void * buf, size_t len); + +typedef struct Wire + { + int version; /* protocol version in use */ + WireDirection direction; + int status; + int allocated_memory; + struct + { + WireCodecFunc w_byte; + WireCodecFunc w_char; + WireCodecFunc w_word; + WireCodecFunc w_string; + } + codec; + struct + { + size_t size; + char *curr; + char *start; + char *end; + } + buffer; + struct + { + int fd; + WireReadFunc read; + WireWriteFunc write; + } + io; + } +Wire; + +extern void sanei_w_init (Wire *w, void (*codec_init)(Wire *)); +extern void sanei_w_exit (Wire *w); +extern void sanei_w_space (Wire *w, size_t howmuch); +extern void sanei_w_void (Wire *w); +extern void sanei_w_byte (Wire *w, SANE_Byte *v); +extern void sanei_w_char (Wire *w, SANE_Char *v); +extern void sanei_w_word (Wire *w, SANE_Word *v); +extern void sanei_w_bool (Wire *w, SANE_Bool *v); +extern void sanei_w_ptr (Wire *w, void **v, WireCodecFunc w_value, + size_t value_size); +extern void sanei_w_string (Wire *w, SANE_String *v); +extern void sanei_w_status (Wire *w, SANE_Status *v); +extern void sanei_w_constraint_type (Wire *w, SANE_Constraint_Type *v); +extern void sanei_w_value_type (Wire *w, SANE_Value_Type *v); +extern void sanei_w_unit (Wire *w, SANE_Unit *v); +extern void sanei_w_action (Wire *w, SANE_Action *v); +extern void sanei_w_frame (Wire *w, SANE_Frame *v); +extern void sanei_w_range (Wire *w, SANE_Range *v); +extern void sanei_w_range_ptr (Wire *w, SANE_Range **v); +extern void sanei_w_device (Wire *w, SANE_Device *v); +extern void sanei_w_device_ptr (Wire *w, SANE_Device **v); +extern void sanei_w_option_descriptor (Wire *w, SANE_Option_Descriptor *v); +extern void sanei_w_option_descriptor_ptr (Wire *w, + SANE_Option_Descriptor **v); +extern void sanei_w_parameters (Wire *w, SANE_Parameters *v); + +extern void sanei_w_array (Wire *w, SANE_Word *len, void **v, + WireCodecFunc w_element, size_t element_size); + +extern void sanei_w_set_dir (Wire *w, WireDirection dir); +extern void sanei_w_call (Wire *w, SANE_Word proc_num, + WireCodecFunc w_arg, void *arg, + WireCodecFunc w_reply, void *reply); +extern void sanei_w_reply (Wire *w, WireCodecFunc w_reply, void *reply); +extern void sanei_w_free (Wire *w, WireCodecFunc w_reply, void *reply); + +#endif /* sanei_wire_h */ |