1*86d7f5d3SJohn Marino /* $NetBSD: getopt.h,v 1.5 2003/04/28 23:16:13 bjh21 Exp $ */ 2*86d7f5d3SJohn Marino /* $DragonFly: src/include/getopt.h,v 1.2 2005/01/10 16:45:15 joerg Exp $ */ 3*86d7f5d3SJohn Marino 4*86d7f5d3SJohn Marino /*- 5*86d7f5d3SJohn Marino * Copyright (c) 2000 The NetBSD Foundation, Inc. 6*86d7f5d3SJohn Marino * All rights reserved. 7*86d7f5d3SJohn Marino * 8*86d7f5d3SJohn Marino * This code is derived from software contributed to The NetBSD Foundation 9*86d7f5d3SJohn Marino * by Dieter Baron and Thomas Klausner. 10*86d7f5d3SJohn Marino * 11*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 12*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 13*86d7f5d3SJohn Marino * are met: 14*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 15*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 16*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 17*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 18*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 19*86d7f5d3SJohn Marino * 3. All advertising materials mentioning features or use of this software 20*86d7f5d3SJohn Marino * must display the following acknowledgement: 21*86d7f5d3SJohn Marino * This product includes software developed by the NetBSD 22*86d7f5d3SJohn Marino * Foundation, Inc. and its contributors. 23*86d7f5d3SJohn Marino * 4. Neither the name of The NetBSD Foundation nor the names of its 24*86d7f5d3SJohn Marino * contributors may be used to endorse or promote products derived 25*86d7f5d3SJohn Marino * from this software without specific prior written permission. 26*86d7f5d3SJohn Marino * 27*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28*86d7f5d3SJohn Marino * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29*86d7f5d3SJohn Marino * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30*86d7f5d3SJohn Marino * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31*86d7f5d3SJohn Marino * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32*86d7f5d3SJohn Marino * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33*86d7f5d3SJohn Marino * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34*86d7f5d3SJohn Marino * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35*86d7f5d3SJohn Marino * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36*86d7f5d3SJohn Marino * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37*86d7f5d3SJohn Marino * POSSIBILITY OF SUCH DAMAGE. 38*86d7f5d3SJohn Marino */ 39*86d7f5d3SJohn Marino 40*86d7f5d3SJohn Marino #ifndef _GETOPT_H_ 41*86d7f5d3SJohn Marino #define _GETOPT_H_ 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino #include <sys/cdefs.h> 44*86d7f5d3SJohn Marino #include <unistd.h> 45*86d7f5d3SJohn Marino 46*86d7f5d3SJohn Marino /* 47*86d7f5d3SJohn Marino * GNU like getopt_long() and BSD4.4 getsubopt()/optreset extensions 48*86d7f5d3SJohn Marino */ 49*86d7f5d3SJohn Marino #define no_argument 0 50*86d7f5d3SJohn Marino #define required_argument 1 51*86d7f5d3SJohn Marino #define optional_argument 2 52*86d7f5d3SJohn Marino 53*86d7f5d3SJohn Marino struct option { 54*86d7f5d3SJohn Marino /* name of long option */ 55*86d7f5d3SJohn Marino const char *name; 56*86d7f5d3SJohn Marino /* 57*86d7f5d3SJohn Marino * one of no_argument, required_argument, and optional_argument: 58*86d7f5d3SJohn Marino * whether option takes an argument 59*86d7f5d3SJohn Marino */ 60*86d7f5d3SJohn Marino int has_arg; 61*86d7f5d3SJohn Marino /* if not NULL, set *flag to val when option found */ 62*86d7f5d3SJohn Marino int *flag; 63*86d7f5d3SJohn Marino /* if flag not NULL, value to set *flag to; else return value */ 64*86d7f5d3SJohn Marino int val; 65*86d7f5d3SJohn Marino }; 66*86d7f5d3SJohn Marino 67*86d7f5d3SJohn Marino __BEGIN_DECLS 68*86d7f5d3SJohn Marino int getopt_long(int, char * const *, const char *, 69*86d7f5d3SJohn Marino const struct option *, int *); 70*86d7f5d3SJohn Marino int getopt_long_only(int, char * const *, const char *, 71*86d7f5d3SJohn Marino const struct option *, int *); 72*86d7f5d3SJohn Marino __END_DECLS 73*86d7f5d3SJohn Marino 74*86d7f5d3SJohn Marino #endif /* !_GETOPT_H_ */ 75