xref: /freebsd-src/contrib/smbfs/include/cflib.h (revision f1b9d12761de3c33754f03e6d2a5bf9f1b40aad9)
1*f1b9d127SSheldon Hearn /*
2*f1b9d127SSheldon Hearn  * Copyright (c) 2000, Boris Popov
3*f1b9d127SSheldon Hearn  * All rights reserved.
4*f1b9d127SSheldon Hearn  *
5*f1b9d127SSheldon Hearn  * Redistribution and use in source and binary forms, with or without
6*f1b9d127SSheldon Hearn  * modification, are permitted provided that the following conditions
7*f1b9d127SSheldon Hearn  * are met:
8*f1b9d127SSheldon Hearn  * 1. Redistributions of source code must retain the above copyright
9*f1b9d127SSheldon Hearn  *    notice, this list of conditions and the following disclaimer.
10*f1b9d127SSheldon Hearn  * 2. Redistributions in binary form must reproduce the above copyright
11*f1b9d127SSheldon Hearn  *    notice, this list of conditions and the following disclaimer in the
12*f1b9d127SSheldon Hearn  *    documentation and/or other materials provided with the distribution.
13*f1b9d127SSheldon Hearn  * 3. All advertising materials mentioning features or use of this software
14*f1b9d127SSheldon Hearn  *    must display the following acknowledgement:
15*f1b9d127SSheldon Hearn  *    This product includes software developed by Boris Popov.
16*f1b9d127SSheldon Hearn  * 4. Neither the name of the author nor the names of any co-contributors
17*f1b9d127SSheldon Hearn  *    may be used to endorse or promote products derived from this software
18*f1b9d127SSheldon Hearn  *    without specific prior written permission.
19*f1b9d127SSheldon Hearn  *
20*f1b9d127SSheldon Hearn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21*f1b9d127SSheldon Hearn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*f1b9d127SSheldon Hearn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*f1b9d127SSheldon Hearn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24*f1b9d127SSheldon Hearn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*f1b9d127SSheldon Hearn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*f1b9d127SSheldon Hearn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*f1b9d127SSheldon Hearn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*f1b9d127SSheldon Hearn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*f1b9d127SSheldon Hearn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*f1b9d127SSheldon Hearn  * SUCH DAMAGE.
31*f1b9d127SSheldon Hearn  *
32*f1b9d127SSheldon Hearn  * $Id: cflib.h,v 1.3 2000/07/11 01:51:49 bp Exp $
33*f1b9d127SSheldon Hearn  */
34*f1b9d127SSheldon Hearn #ifndef _zzzzzz_RCFILE_H_
35*f1b9d127SSheldon Hearn #define _zzzzzz_RCFILE_H_
36*f1b9d127SSheldon Hearn 
37*f1b9d127SSheldon Hearn struct rcfile;
38*f1b9d127SSheldon Hearn 
39*f1b9d127SSheldon Hearn /*
40*f1b9d127SSheldon Hearn  * A unified options parser
41*f1b9d127SSheldon Hearn  */
42*f1b9d127SSheldon Hearn enum opt_argtype {OPTARG_STR, OPTARG_INT, OPTARG_BOOL};
43*f1b9d127SSheldon Hearn 
44*f1b9d127SSheldon Hearn struct opt_args;
45*f1b9d127SSheldon Hearn 
46*f1b9d127SSheldon Hearn typedef int opt_callback_t (struct opt_args*);
47*f1b9d127SSheldon Hearn 
48*f1b9d127SSheldon Hearn #define	OPTFL_NONE	0x0000
49*f1b9d127SSheldon Hearn #define	OPTFL_HAVEMIN	0x0001
50*f1b9d127SSheldon Hearn #define	OPTFL_HAVEMAX	0x0002
51*f1b9d127SSheldon Hearn #define	OPTFL_MINMAX	NAFL_HAVEMIN | NAFL_HAVEMAX
52*f1b9d127SSheldon Hearn 
53*f1b9d127SSheldon Hearn struct opt_args {
54*f1b9d127SSheldon Hearn 	enum opt_argtype type;
55*f1b9d127SSheldon Hearn 	int	opt;		/* command line option */
56*f1b9d127SSheldon Hearn 	char *	name;		/* rc file equiv */
57*f1b9d127SSheldon Hearn 	int	flag;		/* OPTFL_* */
58*f1b9d127SSheldon Hearn 	int	ival;		/* int/bool values, or max len for str value */
59*f1b9d127SSheldon Hearn 	char *	str;		/* string value */
60*f1b9d127SSheldon Hearn 	int	min;		/* min for ival */
61*f1b9d127SSheldon Hearn 	int	max;		/* max for ival */
62*f1b9d127SSheldon Hearn 	opt_callback_t *fn;	/* call back to validate */
63*f1b9d127SSheldon Hearn };
64*f1b9d127SSheldon Hearn 
65*f1b9d127SSheldon Hearn extern int cf_opterr, cf_optind, cf_optopt, cf_optreset;
66*f1b9d127SSheldon Hearn extern const char *cf_optarg;
67*f1b9d127SSheldon Hearn 
68*f1b9d127SSheldon Hearn __BEGIN_DECLS
69*f1b9d127SSheldon Hearn 
70*f1b9d127SSheldon Hearn int  opt_args_parse(struct rcfile *, struct opt_args *, const char *,
71*f1b9d127SSheldon Hearn 	opt_callback_t *);
72*f1b9d127SSheldon Hearn int  opt_args_parseopt(struct opt_args *, int, char *, opt_callback_t *);
73*f1b9d127SSheldon Hearn 
74*f1b9d127SSheldon Hearn int  cf_getopt(int, char * const *, const char *);
75*f1b9d127SSheldon Hearn 
76*f1b9d127SSheldon Hearn int  rc_open(const char *, const char *, struct rcfile **);
77*f1b9d127SSheldon Hearn int  rc_close(struct rcfile *);
78*f1b9d127SSheldon Hearn int  rc_merge(const char *, struct rcfile **);
79*f1b9d127SSheldon Hearn int  rc_getstringptr(struct rcfile *, const char *, const char *, char **);
80*f1b9d127SSheldon Hearn int  rc_getstring(struct rcfile *, const char *, const char *, size_t, char *);
81*f1b9d127SSheldon Hearn int  rc_getint(struct rcfile *, const char *, const char *, int *);
82*f1b9d127SSheldon Hearn int  rc_getbool(struct rcfile *, const char *, const char *, int *);
83*f1b9d127SSheldon Hearn 
84*f1b9d127SSheldon Hearn __END_DECLS
85*f1b9d127SSheldon Hearn 
86*f1b9d127SSheldon Hearn #endif	/* _zzzzzz_RCFILE_H_ */
87