187866Ssheldonh/* 287866Ssheldonh * Copyright (c) 2000, Boris Popov 387866Ssheldonh * All rights reserved. 487866Ssheldonh * 587866Ssheldonh * Redistribution and use in source and binary forms, with or without 687866Ssheldonh * modification, are permitted provided that the following conditions 787866Ssheldonh * are met: 887866Ssheldonh * 1. Redistributions of source code must retain the above copyright 987866Ssheldonh * notice, this list of conditions and the following disclaimer. 1087866Ssheldonh * 2. Redistributions in binary form must reproduce the above copyright 1187866Ssheldonh * notice, this list of conditions and the following disclaimer in the 1287866Ssheldonh * documentation and/or other materials provided with the distribution. 1387866Ssheldonh * 3. All advertising materials mentioning features or use of this software 1487866Ssheldonh * must display the following acknowledgement: 1587866Ssheldonh * This product includes software developed by Boris Popov. 1687866Ssheldonh * 4. Neither the name of the author nor the names of any co-contributors 1787866Ssheldonh * may be used to endorse or promote products derived from this software 1887866Ssheldonh * without specific prior written permission. 1987866Ssheldonh * 2087866Ssheldonh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2187866Ssheldonh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2287866Ssheldonh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2387866Ssheldonh * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2487866Ssheldonh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2587866Ssheldonh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2687866Ssheldonh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2787866Ssheldonh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2887866Ssheldonh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2987866Ssheldonh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3087866Ssheldonh * SUCH DAMAGE. 3187866Ssheldonh * 3287866Ssheldonh * $Id: cflib.h,v 1.3 2000/07/11 01:51:49 bp Exp $ 3387866Ssheldonh */ 3487866Ssheldonh#ifndef _zzzzzz_RCFILE_H_ 3587866Ssheldonh#define _zzzzzz_RCFILE_H_ 3687866Ssheldonh 3787866Ssheldonhstruct rcfile; 3887866Ssheldonh 3987866Ssheldonh/* 4087866Ssheldonh * A unified options parser 4187866Ssheldonh */ 4287866Ssheldonhenum opt_argtype {OPTARG_STR, OPTARG_INT, OPTARG_BOOL}; 4387866Ssheldonh 4487866Ssheldonhstruct opt_args; 4587866Ssheldonh 4687866Ssheldonhtypedef int opt_callback_t (struct opt_args*); 4787866Ssheldonh 4887866Ssheldonh#define OPTFL_NONE 0x0000 4987866Ssheldonh#define OPTFL_HAVEMIN 0x0001 5087866Ssheldonh#define OPTFL_HAVEMAX 0x0002 5187866Ssheldonh#define OPTFL_MINMAX NAFL_HAVEMIN | NAFL_HAVEMAX 5287866Ssheldonh 5387866Ssheldonhstruct opt_args { 5487866Ssheldonh enum opt_argtype type; 5587866Ssheldonh int opt; /* command line option */ 5687866Ssheldonh char * name; /* rc file equiv */ 5787866Ssheldonh int flag; /* OPTFL_* */ 5887866Ssheldonh int ival; /* int/bool values, or max len for str value */ 5987866Ssheldonh char * str; /* string value */ 6087866Ssheldonh int min; /* min for ival */ 6187866Ssheldonh int max; /* max for ival */ 6287866Ssheldonh opt_callback_t *fn; /* call back to validate */ 6387866Ssheldonh}; 6487866Ssheldonh 6587866Ssheldonhextern int cf_opterr, cf_optind, cf_optopt, cf_optreset; 6687866Ssheldonhextern const char *cf_optarg; 6787866Ssheldonh 6887866Ssheldonh__BEGIN_DECLS 6987866Ssheldonh 7087866Ssheldonhint opt_args_parse(struct rcfile *, struct opt_args *, const char *, 7187866Ssheldonh opt_callback_t *); 7287866Ssheldonhint opt_args_parseopt(struct opt_args *, int, char *, opt_callback_t *); 7387866Ssheldonh 7487866Ssheldonhint cf_getopt(int, char * const *, const char *); 7587866Ssheldonh 7687866Ssheldonhint rc_open(const char *, const char *, struct rcfile **); 7787866Ssheldonhint rc_close(struct rcfile *); 7887866Ssheldonhint rc_merge(const char *, struct rcfile **); 7987866Ssheldonhint rc_getstringptr(struct rcfile *, const char *, const char *, char **); 8087866Ssheldonhint rc_getstring(struct rcfile *, const char *, const char *, size_t, char *); 8187866Ssheldonhint rc_getint(struct rcfile *, const char *, const char *, int *); 8287866Ssheldonhint rc_getbool(struct rcfile *, const char *, const char *, int *); 8387866Ssheldonh 8487866Ssheldonh__END_DECLS 8587866Ssheldonh 8687866Ssheldonh#endif /* _zzzzzz_RCFILE_H_ */ 87