1a35a7e76SEric Melville /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 2a35a7e76SEric Melville 3a35a7e76SEric Melville /*- 4*b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 5e58eb3c4SPedro F. Giffuni * 6a35a7e76SEric Melville * Copyright (c) 2000 The NetBSD Foundation, Inc. 7a35a7e76SEric Melville * All rights reserved. 8a35a7e76SEric Melville * 9a35a7e76SEric Melville * This code is derived from software contributed to The NetBSD Foundation 10a35a7e76SEric Melville * by Dieter Baron and Thomas Klausner. 11a35a7e76SEric Melville * 12a35a7e76SEric Melville * Redistribution and use in source and binary forms, with or without 13a35a7e76SEric Melville * modification, are permitted provided that the following conditions 14a35a7e76SEric Melville * are met: 15a35a7e76SEric Melville * 1. Redistributions of source code must retain the above copyright 16a35a7e76SEric Melville * notice, this list of conditions and the following disclaimer. 17a35a7e76SEric Melville * 2. Redistributions in binary form must reproduce the above copyright 18a35a7e76SEric Melville * notice, this list of conditions and the following disclaimer in the 19a35a7e76SEric Melville * documentation and/or other materials provided with the distribution. 20a35a7e76SEric Melville * 21a35a7e76SEric Melville * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22a35a7e76SEric Melville * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23a35a7e76SEric Melville * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24a35a7e76SEric Melville * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25a35a7e76SEric Melville * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26a35a7e76SEric Melville * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27a35a7e76SEric Melville * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28a35a7e76SEric Melville * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29a35a7e76SEric Melville * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30a35a7e76SEric Melville * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31a35a7e76SEric Melville * POSSIBILITY OF SUCH DAMAGE. 32a35a7e76SEric Melville */ 33a35a7e76SEric Melville 34a35a7e76SEric Melville #ifndef _GETOPT_H_ 35a35a7e76SEric Melville #define _GETOPT_H_ 36a35a7e76SEric Melville 37a35a7e76SEric Melville #include <sys/cdefs.h> 38a35a7e76SEric Melville 39a35a7e76SEric Melville /* 40f99a4b25SAndrey A. Chernov * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension. 4105efcb98SAndrey A. Chernov * getopt() is declared here too for GNU programs. 42a35a7e76SEric Melville */ 43a35a7e76SEric Melville #define no_argument 0 44a35a7e76SEric Melville #define required_argument 1 45a35a7e76SEric Melville #define optional_argument 2 46a35a7e76SEric Melville 47a35a7e76SEric Melville struct option { 48a35a7e76SEric Melville /* name of long option */ 49a35a7e76SEric Melville const char *name; 50a35a7e76SEric Melville /* 51a35a7e76SEric Melville * one of no_argument, required_argument, and optional_argument: 52a35a7e76SEric Melville * whether option takes an argument 53a35a7e76SEric Melville */ 54a35a7e76SEric Melville int has_arg; 55a35a7e76SEric Melville /* if not NULL, set *flag to val when option found */ 56a35a7e76SEric Melville int *flag; 57a35a7e76SEric Melville /* if flag not NULL, value to set *flag to; else return value */ 58a35a7e76SEric Melville int val; 59a35a7e76SEric Melville }; 60a35a7e76SEric Melville 61a35a7e76SEric Melville __BEGIN_DECLS 621919b885SAndrey A. Chernov int getopt_long(int, char * const *, const char *, 631919b885SAndrey A. Chernov const struct option *, int *); 64f99a4b25SAndrey A. Chernov int getopt_long_only(int, char * const *, const char *, 65f99a4b25SAndrey A. Chernov const struct option *, int *); 661919b885SAndrey A. Chernov #ifndef _GETOPT_DECLARED 671919b885SAndrey A. Chernov #define _GETOPT_DECLARED 681919b885SAndrey A. Chernov int getopt(int, char * const [], const char *); 691919b885SAndrey A. Chernov 701919b885SAndrey A. Chernov extern char *optarg; /* getopt(3) external variables */ 711919b885SAndrey A. Chernov extern int optind, opterr, optopt; 72de693dcbSAndrey A. Chernov #endif 73de693dcbSAndrey A. Chernov #ifndef _OPTRESET_DECLARED 74de693dcbSAndrey A. Chernov #define _OPTRESET_DECLARED 75de693dcbSAndrey A. Chernov extern int optreset; /* getopt(3) external variable */ 76de693dcbSAndrey A. Chernov #endif 77a35a7e76SEric Melville __END_DECLS 78a35a7e76SEric Melville 79a35a7e76SEric Melville #endif /* !_GETOPT_H_ */ 80