getopt.h revision 126155
1219019Sgabor/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 2219019Sgabor/* $FreeBSD: head/include/getopt.h 126155 2004-02-23 08:14:18Z ache $ */ 3219019Sgabor 4219019Sgabor/*- 5219019Sgabor * Copyright (c) 2000 The NetBSD Foundation, Inc. 6219019Sgabor * All rights reserved. 7219019Sgabor * 8219019Sgabor * This code is derived from software contributed to The NetBSD Foundation 9219019Sgabor * by Dieter Baron and Thomas Klausner. 10219019Sgabor * 11219019Sgabor * Redistribution and use in source and binary forms, with or without 12219019Sgabor * modification, are permitted provided that the following conditions 13219019Sgabor * are met: 14219019Sgabor * 1. Redistributions of source code must retain the above copyright 15219019Sgabor * notice, this list of conditions and the following disclaimer. 16219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 17219019Sgabor * notice, this list of conditions and the following disclaimer in the 18219019Sgabor * documentation and/or other materials provided with the distribution. 19219019Sgabor * 3. All advertising materials mentioning features or use of this software 20219019Sgabor * must display the following acknowledgement: 21219019Sgabor * This product includes software developed by the NetBSD 22219019Sgabor * Foundation, Inc. and its contributors. 23219019Sgabor * 4. Neither the name of The NetBSD Foundation nor the names of its 24219019Sgabor * contributors may be used to endorse or promote products derived 25219019Sgabor * from this software without specific prior written permission. 26219019Sgabor * 27219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28219019Sgabor * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29219019Sgabor * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30219019Sgabor * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31219019Sgabor * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32219019Sgabor * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33219019Sgabor * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34219019Sgabor * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35219019Sgabor * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36219019Sgabor * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37219019Sgabor * POSSIBILITY OF SUCH DAMAGE. 38219019Sgabor */ 39219019Sgabor 40219019Sgabor#ifndef _GETOPT_H_ 41219019Sgabor#define _GETOPT_H_ 42219019Sgabor 43219019Sgabor#include <sys/cdefs.h> 44219019Sgabor 45219019Sgabor/* 46219019Sgabor * GNU-like getopt_long() with 4.4BSD optreset extension. 47219019Sgabor * getopt() is declared here too for GNU programs. 48219019Sgabor */ 49219019Sgabor#define no_argument 0 50219019Sgabor#define required_argument 1 51219019Sgabor#define optional_argument 2 52219019Sgabor 53219019Sgaborstruct option { 54219019Sgabor /* name of long option */ 55219019Sgabor const char *name; 56219019Sgabor /* 57219019Sgabor * one of no_argument, required_argument, and optional_argument: 58219019Sgabor * whether option takes an argument 59219019Sgabor */ 60219019Sgabor int has_arg; 61219019Sgabor /* if not NULL, set *flag to val when option found */ 62219019Sgabor int *flag; 63219019Sgabor /* if flag not NULL, value to set *flag to; else return value */ 64219019Sgabor int val; 65219019Sgabor}; 66219019Sgabor 67219019Sgabor__BEGIN_DECLS 68219019Sgaborint getopt_long(int, char * const *, const char *, 69219019Sgabor const struct option *, int *); 70219019Sgabor#ifndef _GETOPT_DECLARED 71219019Sgabor#define _GETOPT_DECLARED 72219019Sgaborint getopt(int, char * const [], const char *); 73219019Sgabor 74219019Sgaborextern char *optarg; /* getopt(3) external variables */ 75219019Sgaborextern int optind, opterr, optopt; 76219019Sgabor#endif 77219019Sgabor#ifndef _OPTRESET_DECLARED 78219019Sgabor#define _OPTRESET_DECLARED 79219019Sgaborextern int optreset; /* getopt(3) external variable */ 80219019Sgabor#endif 81219019Sgabor__END_DECLS 82219019Sgabor 83219019Sgabor#endif /* !_GETOPT_H_ */ 84219019Sgabor