kopia lustrzana https://gitlab.com/sane-project/backends
Added function sanei_check_value in addition to the existing
sanei_constrain_value. It checks if the value of a sane option fits into the constraint but doesn't try to do any fixing/rounding.merge-requests/1/head
rodzic
ca786b2c28
commit
df7d2cda19
|
@ -1,3 +1,10 @@
|
|||
2003-03-04 Henning Meier-Geinitz <henning@meier-geinitz.de>
|
||||
|
||||
* include/sane/sanei.h sanei/sanei_constrain_value.c: Added function
|
||||
sanei_check_value in addition to the existing sanei_constrain_value.
|
||||
It checks if the value of a sane option fits into the constraint but
|
||||
doesn't try to do any fixing/rounding.
|
||||
|
||||
2003-03-03 Gerhard Jaeger <gerhard@gjaeger.de>
|
||||
* doc/plustek/Plustek-USB-TODO.txt: update
|
||||
* backend/plustek-devs.c backend/plustek-usb.c backend/plustek-usbhw.c
|
||||
|
|
|
@ -15,28 +15,133 @@
|
|||
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 declares SANE internal routines that are provided to
|
||||
simplify backend implementation. */
|
||||
/** @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 ../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.mostang.com/sane/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.mostang.com/sane/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.mostang.com/sane/mail.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>
|
||||
|
||||
/* A few convenience macros: */
|
||||
/** @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)
|
||||
|
||||
#define NELEMS(a) ((int)(sizeof (a) / sizeof (a[0])))
|
||||
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 */
|
||||
|
|
|
@ -43,10 +43,67 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sane/sane.h"
|
||||
#include "sane/sanei.h"
|
||||
|
||||
SANE_Status
|
||||
sanei_check_value (const SANE_Option_Descriptor * opt, void * value)
|
||||
{
|
||||
const SANE_String_Const * string_list;
|
||||
const SANE_Word * word_list;
|
||||
int i;
|
||||
const SANE_Range * range;
|
||||
SANE_Word w, v;
|
||||
SANE_Bool b;
|
||||
size_t len;
|
||||
|
||||
switch (opt->constraint_type)
|
||||
{
|
||||
case SANE_CONSTRAINT_RANGE:
|
||||
w = *(SANE_Word *) value;
|
||||
range = opt->constraint.range;
|
||||
|
||||
if (w < range->min || w > range->max)
|
||||
return SANE_STATUS_INVAL;
|
||||
|
||||
w = *(SANE_Word *) value;
|
||||
|
||||
if (range->quant)
|
||||
{
|
||||
v = (w - range->min + range->quant/2) / range->quant;
|
||||
v = v * range->quant + range->min;
|
||||
if (v != w)
|
||||
return SANE_STATUS_INVAL;
|
||||
}
|
||||
break;
|
||||
|
||||
case SANE_CONSTRAINT_WORD_LIST:
|
||||
w = *(SANE_Word *) value;
|
||||
word_list = opt->constraint.word_list;
|
||||
for (i = 1; w != word_list[i]; ++i)
|
||||
if (i >= word_list[0])
|
||||
return SANE_STATUS_INVAL;
|
||||
break;
|
||||
|
||||
case SANE_CONSTRAINT_STRING_LIST:
|
||||
string_list = opt->constraint.string_list;
|
||||
len = strlen (value);
|
||||
|
||||
for (i = 0; string_list[i]; ++i)
|
||||
if (strncmp (value, string_list[i], len) == 0
|
||||
&& len == strlen (string_list[i]))
|
||||
return SANE_STATUS_GOOD;
|
||||
return SANE_STATUS_INVAL;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
||||
SANE_Status
|
||||
sanei_constrain_value (const SANE_Option_Descriptor * opt, void * value,
|
||||
SANE_Word * info)
|
||||
|
|
Ładowanie…
Reference in New Issue