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