13464ebd5Sriastradh/* $OpenBSD: getopt.h,v 1.2 2008/06/26 05:42:04 ray Exp $ */ 23464ebd5Sriastradh/* $NetBSD: getopt.h,v 1.1.1.1 2014/07/09 19:38:35 riastradh Exp $ */ 33464ebd5Sriastradh 43464ebd5Sriastradh/*- 53464ebd5Sriastradh * Copyright (c) 2000 The NetBSD Foundation, Inc. 63464ebd5Sriastradh * All rights reserved. 73464ebd5Sriastradh * 83464ebd5Sriastradh * This code is derived from software contributed to The NetBSD Foundation 93464ebd5Sriastradh * by Dieter Baron and Thomas Klausner. 103464ebd5Sriastradh * 113464ebd5Sriastradh * Redistribution and use in source and binary forms, with or without 123464ebd5Sriastradh * modification, are permitted provided that the following conditions 133464ebd5Sriastradh * are met: 143464ebd5Sriastradh * 1. Redistributions of source code must retain the above copyright 153464ebd5Sriastradh * notice, this list of conditions and the following disclaimer. 163464ebd5Sriastradh * 2. Redistributions in binary form must reproduce the above copyright 173464ebd5Sriastradh * notice, this list of conditions and the following disclaimer in the 183464ebd5Sriastradh * documentation and/or other materials provided with the distribution. 193464ebd5Sriastradh * 203464ebd5Sriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 213464ebd5Sriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 223464ebd5Sriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 233464ebd5Sriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 243464ebd5Sriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 253464ebd5Sriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 263464ebd5Sriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 273464ebd5Sriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 283464ebd5Sriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 293464ebd5Sriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 303464ebd5Sriastradh * POSSIBILITY OF SUCH DAMAGE. 313464ebd5Sriastradh */ 323464ebd5Sriastradh 333464ebd5Sriastradh#ifndef _GETOPT_H_ 343464ebd5Sriastradh#define _GETOPT_H_ 353464ebd5Sriastradh 363464ebd5Sriastradh/* 373464ebd5Sriastradh * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 383464ebd5Sriastradh */ 393464ebd5Sriastradh#define no_argument 0 403464ebd5Sriastradh#define required_argument 1 413464ebd5Sriastradh#define optional_argument 2 423464ebd5Sriastradh 433464ebd5Sriastradh#ifdef __cplusplus 443464ebd5Sriastradhextern "C" { 453464ebd5Sriastradh#endif 463464ebd5Sriastradh 473464ebd5Sriastradhstruct option { 483464ebd5Sriastradh /* name of long option */ 493464ebd5Sriastradh const char *name; 503464ebd5Sriastradh /* 513464ebd5Sriastradh * one of no_argument, required_argument, and optional_argument: 523464ebd5Sriastradh * whether option takes an argument 533464ebd5Sriastradh */ 543464ebd5Sriastradh int has_arg; 553464ebd5Sriastradh /* if not NULL, set *flag to val when option found */ 563464ebd5Sriastradh int *flag; 573464ebd5Sriastradh /* if flag not NULL, value to set *flag to; else return value */ 583464ebd5Sriastradh int val; 593464ebd5Sriastradh}; 603464ebd5Sriastradh 613464ebd5Sriastradhint getopt_long(int, char * const *, const char *, 623464ebd5Sriastradh const struct option *, int *); 633464ebd5Sriastradhint getopt_long_only(int, char * const *, const char *, 643464ebd5Sriastradh const struct option *, int *); 653464ebd5Sriastradh#ifndef _GETOPT_DEFINED_ 663464ebd5Sriastradh#define _GETOPT_DEFINED_ 673464ebd5Sriastradhint getopt(int, char * const *, const char *); 683464ebd5Sriastradhint getsubopt(char **, char * const *, char **); 693464ebd5Sriastradh 703464ebd5Sriastradhextern char *optarg; /* getopt(3) external variables */ 713464ebd5Sriastradhextern int opterr; 723464ebd5Sriastradhextern int optind; 733464ebd5Sriastradhextern int optopt; 743464ebd5Sriastradhextern int optreset; 753464ebd5Sriastradhextern char *suboptarg; /* getsubopt(3) external variable */ 763464ebd5Sriastradh#endif 773464ebd5Sriastradh 783464ebd5Sriastradh#ifdef __cplusplus 793464ebd5Sriastradh} 803464ebd5Sriastradh#endif 813464ebd5Sriastradh 823464ebd5Sriastradh#endif /* !_GETOPT_H_ */ 83