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