Blame dwarfdump/dwgetopt.h

Packit cdaae3
/* $NetBSD: getopt.c,v 1.1 2009/03/22 22:33:13 joerg Exp $*/
Packit cdaae3
/*  Modified by David Anderson to work with GNU/Linux and freebsd.
Packit cdaae3
    Added {} for clarity.
Packit cdaae3
    Switched to standard dwarfdump formatting.
Packit cdaae3
    Treatment of : modified so that :: gets dwoptarg NULL
Packit cdaae3
    if space follows the letter
Packit cdaae3
    (the dwoptarg is set to null).
Packit cdaae3
*/
Packit cdaae3
/*
Packit cdaae3
* Copyright (c) 1987, 1993, 1994
Packit cdaae3
* The Regents of the University of California.  All rights reserved.
Packit cdaae3
*
Packit cdaae3
* Redistribution and use in source and binary forms, with or without
Packit cdaae3
* modification, are permitted provided that the following conditions
Packit cdaae3
* are met:
Packit cdaae3
* 1. Redistributions of source code must retain the above copyright
Packit cdaae3
*    notice, this list of conditions and the following disclaimer.
Packit cdaae3
* 2. Redistributions in binary form must reproduce the above copyright
Packit cdaae3
*    notice, this list of conditions and the following disclaimer in the
Packit cdaae3
*    documentation and/or other materials provided with the distribution.
Packit cdaae3
* 3. Neither the name of the University nor the names of its contributors
Packit cdaae3
*    may be used to endorse or promote products derived from this software
Packit cdaae3
*    without specific prior written permission.
Packit cdaae3
*
Packit cdaae3
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit cdaae3
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit cdaae3
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit cdaae3
* ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit cdaae3
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit cdaae3
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit cdaae3
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit cdaae3
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit cdaae3
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit cdaae3
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit cdaae3
* SUCH DAMAGE.
Packit cdaae3
*/
Packit cdaae3
Packit cdaae3
#ifdef __cplusplus
Packit cdaae3
extern "C" {
Packit cdaae3
#endif /* __cplusplus */
Packit cdaae3
extern int  dwopterr;
Packit cdaae3
extern int  dwoptind;
Packit cdaae3
extern int  dwoptopt;
Packit cdaae3
extern int  dwoptreset;
Packit cdaae3
extern char *dwoptarg;
Packit cdaae3
Packit cdaae3
int dwgetopt(int nargc, char * const nargv[], const char *ostr);
Packit cdaae3
Packit cdaae3
/*  As of October 2017 it seems adviseable to allow
Packit cdaae3
    long option names.  So based on a reading of
Packit cdaae3
    'man 3 getopt' we reimplement a portion of GNU getopt_long().
Packit cdaae3
    It's a wonderfully sensible design and all the credit
Packit cdaae3
    should go to the original designers.
Packit cdaae3
    We are not implementing all the features of GNU/Linux
Packit cdaae3
    getopt_long(), just the features we wish to use.
Packit cdaae3
    Specifically, we require val be 0 and flag
Packit cdaae3
    be NULL and ignore those fields.
Packit cdaae3
    We do not implement GNU digit_optind at all.
Packit cdaae3
    Within these restrictions the interface behaves the same
Packit cdaae3
    as GNU getopt_long() (or so it appears from the
Packit cdaae3
    getopt documentation:
Packit cdaae3
    release 4.04 of the Linux man-pages project,
Packit cdaae3
    GETOPT(3),
Packit cdaae3
    http://www.kernel.org/doc/man-pages/).
Packit cdaae3
    */
Packit cdaae3
Packit cdaae3
struct dwoption {
Packit cdaae3
    const char *name;
Packit cdaae3
    int has_arg;
Packit cdaae3
    int *flag;
Packit cdaae3
    int val;
Packit cdaae3
};
Packit cdaae3
#define dwno_argument 0
Packit cdaae3
#define dwrequired_argument 1
Packit cdaae3
#define dwoptional_argument 2
Packit cdaae3
Packit cdaae3
int dwgetopt_long(int nargc, char *const nargv[],
Packit cdaae3
    const char *ostr,
Packit cdaae3
    const struct dwoption* longopts,
Packit cdaae3
    int *longindex);
Packit cdaae3
Packit cdaae3
Packit cdaae3
#ifdef __cplusplus
Packit cdaae3
}
Packit cdaae3
#endif /* __cplusplus */