vlc_getopt.h 3.73 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * Declarations for getopt_long()
 *****************************************************************************
 * Copyright (C) 1987-1997 Free Software Foundation, Inc.
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
5
 * Copyright (C) 2005-2010 VLC authors and VideoLAN
6
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
7 8
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
9 10 11 12 13
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
14 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
16 17 18 19 20 21 22 23
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef VLC_GETOPT_H
#define VLC_GETOPT_H 1
24

25 26
typedef struct vlc_getopt_s
{
27 28
/* For communication from `getopt' to the caller.
   When `getopt' finds an option that takes an argument,
29
   the argument value is returned here.  */
30

31
    char *arg;
32 33 34 35 36 37 38 39 40 41 42 43 44

/* Index in ARGV of the next element to be scanned.
   This is used for communication to and from the caller
   and for communication between successive calls to `getopt'.

   On entry to `getopt', zero means this is the first call; initialize.

   When `getopt' returns -1, this is the index of the first of the
   non-option elements that the caller should itself scan.

   Otherwise, `optind' communicates from one call to the next
   how much of ARGV has been scanned so far.  */

45
    int ind;
46 47 48

/* Set to an option character which was unrecognized.  */

49
    int opt;
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

/* The next char to be scanned in the option-element
   in which the last option character we returned was found.
   This allows us to pick up the scan where we left off.

   If this is zero, or a null string, it means resume the scan
   by advancing to the next ARGV-element.  */

    char *nextchar;

/* Handle permutation of arguments.  */

/* Describe the part of ARGV that contains non-options that have
   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
   `last_nonopt' is the index after the last of them.  */

    int first_nonopt;
    int last_nonopt;

} vlc_getopt_t;
70 71 72 73 74 75 76

/* Describe the long-named options requested by the application.
   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
   of `struct option' terminated by an element containing a name which is
   zero.

   The field `has_arg' is:
77 78
   false if the option does not take an argument,
   true if the option requires an argument.
79 80 81 82 83 84 85 86 87 88 89 90

   If the field `flag' is not NULL, it points to a variable that is set
   to the value given in the field `val' when the option is found, but
   left unchanged if the option is not found.

   To have a long-named option do something other than set an `int' to
   a compiled-in constant, such as set a value from `optarg', set the
   option's `flag' field to zero and its `val' field to a nonzero
   value (the equivalent single-letter option character, if there is
   one).  For long options that have a zero `flag' field, `getopt'
   returns the contents of the `val' field.  */

91 92 93 94 95 96 97
struct vlc_option
{
    const char *name;
    bool has_arg;
    int *flag;
    int val;
};
98

99
extern int vlc_getopt_long(int argc, char *const *argv, const char *shortopts,
100 101
                           const struct vlc_option *longopts, int *longind,
                           vlc_getopt_t *restrict state);
102

103
#endif                /* VLC_GETOPT_H */