16007Sthurlow /* 26007Sthurlow * Copyright (c) 2000, Boris Popov 36007Sthurlow * All rights reserved. 46007Sthurlow * 56007Sthurlow * Redistribution and use in source and binary forms, with or without 66007Sthurlow * modification, are permitted provided that the following conditions 76007Sthurlow * are met: 86007Sthurlow * 1. Redistributions of source code must retain the above copyright 96007Sthurlow * notice, this list of conditions and the following disclaimer. 106007Sthurlow * 2. Redistributions in binary form must reproduce the above copyright 116007Sthurlow * notice, this list of conditions and the following disclaimer in the 126007Sthurlow * documentation and/or other materials provided with the distribution. 136007Sthurlow * 3. All advertising materials mentioning features or use of this software 146007Sthurlow * must display the following acknowledgement: 156007Sthurlow * This product includes software developed by Boris Popov. 166007Sthurlow * 4. Neither the name of the author nor the names of any co-contributors 176007Sthurlow * may be used to endorse or promote products derived from this software 186007Sthurlow * without specific prior written permission. 196007Sthurlow * 206007Sthurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 216007Sthurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 226007Sthurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 236007Sthurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 246007Sthurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 256007Sthurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 266007Sthurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 276007Sthurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 286007Sthurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 296007Sthurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 306007Sthurlow * SUCH DAMAGE. 316007Sthurlow * 326007Sthurlow * $Id: cflib.h,v 1.1.1.1 2001/06/09 00:28:11 zarzycki Exp $ 336007Sthurlow */ 346007Sthurlow 35*10023SGordon.Ross@Sun.COM /* 36*10023SGordon.Ross@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 37*10023SGordon.Ross@Sun.COM * Use is subject to license terms. 38*10023SGordon.Ross@Sun.COM */ 396007Sthurlow 406007Sthurlow #ifndef _CFLIB_H_ 416007Sthurlow #define _CFLIB_H_ 426007Sthurlow 436007Sthurlow struct rcfile; 446007Sthurlow 456007Sthurlow /* 466007Sthurlow * A unified options parser 476007Sthurlow */ 486007Sthurlow enum opt_argtype {OPTARG_STR, OPTARG_INT, OPTARG_BOOL}; 496007Sthurlow 506007Sthurlow struct opt_args; 516007Sthurlow 526007Sthurlow typedef int opt_callback_t (struct opt_args *); 536007Sthurlow 546007Sthurlow #define OPTFL_NONE 0x0000 556007Sthurlow #define OPTFL_HAVEMIN 0x0001 566007Sthurlow #define OPTFL_HAVEMAX 0x0002 576007Sthurlow #define OPTFL_MINMAX NAFL_HAVEMIN | NAFL_HAVEMAX 586007Sthurlow 596007Sthurlow struct opt_args { 606007Sthurlow enum opt_argtype type; 616007Sthurlow int opt; /* command line option */ 626007Sthurlow char *name; /* rc file equiv */ 636007Sthurlow int flag; /* OPTFL_* */ 646007Sthurlow int ival; /* int/bool values, or max len for str value */ 656007Sthurlow char *str; /* string value */ 666007Sthurlow int min; /* min for ival */ 676007Sthurlow int max; /* max for ival */ 686007Sthurlow opt_callback_t *fn; /* call back to validate */ 696007Sthurlow }; 706007Sthurlow typedef struct opt_args opt_args_t; 716007Sthurlow 726007Sthurlow extern int cf_opterr, cf_optind, cf_optopt, cf_optreset; 736007Sthurlow extern const char *cf_optarg; 74*10023SGordon.Ross@Sun.COM extern struct rcfile *smb_rc; 756007Sthurlow 766007Sthurlow #ifdef __cplusplus 776007Sthurlow extern "C" { 786007Sthurlow #endif 796007Sthurlow 806007Sthurlow int opt_args_parse(struct rcfile *, struct opt_args *, const char *, 816007Sthurlow opt_callback_t *); 826007Sthurlow int opt_args_parseopt(struct opt_args *, int, char *, opt_callback_t *); 836007Sthurlow 846007Sthurlow int cf_getopt(int, char * const *, const char *); 85*10023SGordon.Ross@Sun.COM void cf_opt_lock(void); 86*10023SGordon.Ross@Sun.COM void cf_opt_unlock(void); 876007Sthurlow 886007Sthurlow int rc_getstringptr(struct rcfile *, const char *, const char *, char **); 896007Sthurlow int rc_getstring(struct rcfile *, const char *, const char *, size_t, char *); 906007Sthurlow int rc_getint(struct rcfile *, const char *, const char *, int *); 916007Sthurlow int rc_getbool(struct rcfile *, const char *, const char *, int *); 926007Sthurlow 93*10023SGordon.Ross@Sun.COM int smb_open_rcfile(char *); 94*10023SGordon.Ross@Sun.COM void smb_close_rcfile(void); 95*10023SGordon.Ross@Sun.COM 966007Sthurlow #ifdef __cplusplus 976007Sthurlow } 986007Sthurlow #endif 996007Sthurlow 1006007Sthurlow #endif /* _CFLIB_H_ */ 101