vlc_getopt.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Declarations for getopt_long()
00003  *****************************************************************************
00004  * Copyright (C) 1987-1997 Free Software Foundation, Inc.
00005  * Copyright (C) 2005-2010 VLC authors and VideoLAN
00006  *
00007  * This program is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by
00009  * the Free Software Foundation; either version 2.1 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this program; if not, write to the Free Software Foundation,
00019  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00020  *****************************************************************************/
00021 
00022 #ifndef VLC_GETOPT_H
00023 #define VLC_GETOPT_H 1
00024 
00025 typedef struct vlc_getopt_s
00026 {
00027 /* For communication from `getopt' to the caller.
00028    When `getopt' finds an option that takes an argument,
00029    the argument value is returned here.  */
00030 
00031     char *arg;
00032 
00033 /* Index in ARGV of the next element to be scanned.
00034    This is used for communication to and from the caller
00035    and for communication between successive calls to `getopt'.
00036 
00037    On entry to `getopt', zero means this is the first call; initialize.
00038 
00039    When `getopt' returns -1, this is the index of the first of the
00040    non-option elements that the caller should itself scan.
00041 
00042    Otherwise, `optind' communicates from one call to the next
00043    how much of ARGV has been scanned so far.  */
00044 
00045     int ind;
00046 
00047 /* Set to an option character which was unrecognized.  */
00048 
00049     int opt;
00050 
00051 /* The next char to be scanned in the option-element
00052    in which the last option character we returned was found.
00053    This allows us to pick up the scan where we left off.
00054 
00055    If this is zero, or a null string, it means resume the scan
00056    by advancing to the next ARGV-element.  */
00057 
00058     char *nextchar;
00059 
00060 /* Handle permutation of arguments.  */
00061 
00062 /* Describe the part of ARGV that contains non-options that have
00063    been skipped.  `first_nonopt' is the index in ARGV of the first of them;
00064    `last_nonopt' is the index after the last of them.  */
00065 
00066     int first_nonopt;
00067     int last_nonopt;
00068 
00069 } vlc_getopt_t;
00070 
00071 /* Describe the long-named options requested by the application.
00072    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
00073    of `struct option' terminated by an element containing a name which is
00074    zero.
00075 
00076    The field `has_arg' is:
00077    false if the option does not take an argument,
00078    true if the option requires an argument.
00079 
00080    If the field `flag' is not NULL, it points to a variable that is set
00081    to the value given in the field `val' when the option is found, but
00082    left unchanged if the option is not found.
00083 
00084    To have a long-named option do something other than set an `int' to
00085    a compiled-in constant, such as set a value from `optarg', set the
00086    option's `flag' field to zero and its `val' field to a nonzero
00087    value (the equivalent single-letter option character, if there is
00088    one).  For long options that have a zero `flag' field, `getopt'
00089    returns the contents of the `val' field.  */
00090 
00091 struct vlc_option
00092 {
00093     const char *name;
00094     bool has_arg;
00095     int *flag;
00096     int val;
00097 };
00098 
00099 extern int vlc_getopt_long(int argc, char *const *argv, const char *shortopts,
00100                            const struct vlc_option *longopts, int *longind,
00101                            vlc_getopt_t *restrict state);
00102 
00103 #endif                /* VLC_GETOPT_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines