• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1997 Jeffrey S. Freedman
3    This file is part of the SANE package.
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18    As a special exception, the authors of SANE give permission for
19    additional uses of the libraries contained in this release of SANE.
20 
21    The exception is that, if you link a SANE library with other files
22    to produce an executable, this does not by itself cause the
23    resulting executable to be covered by the GNU General Public
24    License.  Your use of that executable is in no way restricted on
25    account of linking the SANE library code into it.
26 
27    This exception does not, however, invalidate any other reasons why
28    the executable file might be covered by the GNU General Public
29    License.
30 
31    If you submit changes to SANE to the maintainers to be included in
32    a subsequent release, you agree by submitting the changes that
33    those changes may be distributed with this exception intact.
34 
35    If you write modifications of your own for SANE, it is your choice
36    whether to permit this exception to apply to your modifications.
37    If you do not wish that, delete this exception notice.
38 */
39 
40 /** @file sanei_config.h
41  * Generic configuration support.
42  *
43  * Use the functions of this header file if you want to read and analyze
44  * configuration files.
45 */
46 
47 #ifndef sanei_config_h
48 #define sanei_config_h 1
49 
50 #include <stdio.h>
51 #include <sane/sane.h>
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /** Search configuration file \a name along directory list and return file
58  * pointer if such a file exists.
59  *
60  * The following directory list is used:
61  *	1st: SANE_CONFIG_DIR environment variable.
62  *	2nd: PATH_SANE_CONFIG_DIR set during configuration.
63  *	3rd: Current directory.
64  * @param name filename with extension but without path (such as "mustek.conf")
65  *
66  * @return file pointer, or NULL if not found
67  *
68  */
69 extern FILE *sanei_config_open (const char *name);
70 
71 /** Read a line from configuration file.
72  *
73  * Strips all unwanted chars.  Use this instead of fgets() to remove
74  * line ending chars on all known platforms.
75  *
76  * @param str points to the buffer for the line
77  * @param n size of the buffer
78  * @param stream file pointer
79  *
80  * @return \a str on success and NULL on error
81 */
82 extern char *sanei_config_read (char *str, int n, FILE *stream);
83 
84 /** Remove all whitespace from the beginning of a string.
85  *
86  * @param str string
87  *
88  * @return string without leading whitespace
89  *
90  */
91 extern const char *sanei_config_skip_whitespace (const char *str);
92 
93 
94 /** Scan a string constant from a line of text and return a malloced copy
95  * of it.
96  *
97  * It's the responsibility of the caller to free the returned string constant
98  * at an appropriate time.  Whitespace in front of the string constant is
99  * ignored.  Whitespace can be included in the string constant by enclosing it
100  * in double-quotes.
101  *
102  * @param str line of text to scan for a string constant
103  * @param string_const copy of the string constant
104  *
105  * @return a pointer to the position in str where the scan stopped
106  */
107 extern const char *sanei_config_get_string (const char *str,
108 					    char **string_const);
109 
110 /** Expand device name patterns into a list of devices.
111  *
112  * Apart from a normal device name (such as /dev/sdb), this function currently
113  * supports SCSI device specifications of the form:
114  *
115  *	scsi VENDOR MODEL TYPE BUS CHANNEL ID LUN
116  *
117  * Where VENDOR is the desired vendor name.  MODEL is the desired model name.
118  * TYPE is the desired device type.  All of these can be set to * to match
119  * anything.  To include whitespace in these strings, enclose them in
120  * double-quotes (").  BUS, ID, and LUN are the desired SCSI bus, id, and
121  * logical-unit numbers.  These can be set to * or simply omitted to match
122  * anything.
123  *
124  * @param name device name pattern
125  * @param attach attach function
126  */
127 extern void sanei_config_attach_matching_devices (const char *name,
128 						  SANE_Status (*attach)
129 						  (const char *dev));
130 
131 /** this structure holds the description of configuration options. There is
132  * a list for options and another for their values.
133  * These lists are used when the configuration file is
134  * parsed. Read values are stored in Option_Value. Helpers functions are
135  * provided to access values easily */
136 typedef struct
137 {
138   /** number of options */
139   SANE_Int count;
140 
141   /** NULL terminated list of configuration option */
142   SANE_Option_Descriptor **descriptors;
143 
144   /** values for the configuration options */
145   void **values;
146 
147 } SANEI_Config;
148 
149 /** Parse configuration file, reading configuration options and trying to
150  * attach devices found in file.
151  *
152  * The option are gathered in a single configuration structure. Each time
153  * a line holds a value that is not an option, the attach function is called
154  * with the name found and the configuration structure with it's current values.
155  *
156  * @param config_file name of the configuration file to read
157  * @param config configuration structure to be filled during configuration
158  *  	  parsing and passed to the attach callback function
159  * @param config_attach attach with config callback function
160  *
161  * @return SANE_STATUS_GOOD if no errors
162  *         SANE_STATUS_ACCESS_DENIED if configuration file can't be opened
163  */
164 extern SANE_Status sanei_configure_attach (
165   const char *config_file,
166   SANEI_Config *config,
167   SANE_Status (*config_attach)(SANEI_Config *config, const char *devname,
168                                void *data),
169   void *data
170 );
171 
172 /** Return the list of config directories, extracted from the SANE_CONFIG_DIR
173  * environment variable and the default paths.
174  * @return a string containing the configuration paths, separated by the
175  *         operating system's path separator
176  */
177 extern const char *sanei_config_get_paths (void);
178 
179 #ifdef __cplusplus
180 } // extern "C"
181 #endif
182 
183 #endif	/* sanei_config_h */
184