Path: blob/devel/elmergrid/src/metis-5.1.0/GKlib/getopt.c
3206 views
/*************************************************************************/1/*! \file getopt.c2\brief Command line parsing34This file contains a implementation of GNU's Getopt facility. The purpose5for including it here is to ensure portability across different unix- and6windows-based systems.78\warning9The implementation provided here uses the \c gk_ prefix for all variables10used by the standard Getopt facility to communicate with the program.11So, do read the documentation here.1213\verbatim14Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,200115Free Software Foundation, Inc. This file is part of the GNU C Library.1617The GNU C Library is free software; you can redistribute it and/or18modify it under the terms of the GNU Lesser General Public19License as published by the Free Software Foundation; either20version 2.1 of the License, or (at your option) any later version.2122The GNU C Library is distributed in the hope that it will be useful,23but WITHOUT ANY WARRANTY; without even the implied warranty of24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU25Lesser General Public License for more details.2627You should have received a copy of the GNU Lesser General Public28License along with the GNU C Library; if not, write to the Free29Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA3002111-1307 USA.31\endverbatim32*/33/*************************************************************************/343536#include <GKlib.h>3738/*************************************************************************/39/* Local function prototypes */40/*************************************************************************/41static void exchange (char **);42static char *gk_getopt_initialize (int, char **, char *);43static int gk_getopt_internal(int argc, char **argv, char *optstring,44struct gk_option *longopts, int *longind, int long_only);45464748/*************************************************************************/49/*! \brief For communication arguments to the caller.5051This variable is set by getopt to point at the value of the option argument,52for those options that accept arguments.53*/54/*************************************************************************/55char *gk_optarg;565758/*************************************************************************/59/*! \brief Index in ARGV of the next element to be scanned.6061This variable is set by getopt to the index of the next element of the argv62array to be processed. Once getopt has found all of the option arguments,63you can use this variable to determine where the remaining non-option arguments64begin.65*/66/*************************************************************************/67int gk_optind = 1;686970/*************************************************************************/71/*! \brief Controls error reporting for unrecognized options.7273If the value of this variable is nonzero, then getopt prints an error74message to the standard error stream if it encounters an unknown option75character or an option with a missing required argument. This is the default76behavior. If you set this variable to zero, getopt does not print any messages,77but it still returns the character ? to indicate an error.78*/79/*************************************************************************/80int gk_opterr = 1;818283/*************************************************************************/84/*! \brief Stores unknown option characters8586When getopt encounters an unknown option character or an option with a87missing required argument, it stores that option character in this88variable. You can use this for providing your own diagnostic messages.89*/90/*************************************************************************/91int gk_optopt = '?';929394/*************************************************************************/95/*96Records that the getopt facility has been initialized.97*/98/*************************************************************************/99int gk_getopt_initialized;100101102/*************************************************************************/103/*104The next char to be scanned in the option-element in which the last option105character we returned was found. This allows us to pick up the scan where106we left off.107108If this is zero, or a null string, it means resume the scan by advancing109to the next ARGV-element.110*/111/*************************************************************************/112static char *nextchar;113114115/*************************************************************************/116/*117Value of POSIXLY_CORRECT environment variable.118*/119/*************************************************************************/120static char *posixly_correct;121122123/*************************************************************************/124/*125Describe how to deal with options that follow non-option ARGV-elements.126127If the caller did not specify anything, the default is REQUIRE_ORDER if128the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.129130REQUIRE_ORDER means don't recognize them as options; stop option processing131when the first non-option is seen. This is what Unix does. This mode of132operation is selected by either setting the environment variable133POSIXLY_CORRECT, or using `+' as the first character of the list of134option characters.135136PERMUTE is the default. We permute the contents of ARGV as we scan, so137that eventually all the non-options are at the end. This allows options138to be given in any order, even with programs that were not written to139expect this.140141RETURN_IN_ORDER is an option available to programs that were written142to expect options and other ARGV-elements in any order and that care143about the ordering of the two. We describe each non-option ARGV-element144as if it were the argument of an option with character code 1.145Using `-' as the first character of the list of option characters146selects this mode of operation.147148The special argument `--' forces an end of option-scanning regardless149of the value of `ordering'. In the case of RETURN_IN_ORDER, only150`--' can cause `getopt' to return -1 with `gk_optind' != ARGC.151*/152/*************************************************************************/153static enum154{155REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER156} ordering;157158159160/*************************************************************************/161/*162Describe the part of ARGV that contains non-options that have163been skipped. `first_nonopt' is the index in ARGV of the first of them;164`last_nonopt' is the index after the last of them.165*/166/*************************************************************************/167static int first_nonopt;168static int last_nonopt;169170171172173174/*************************************************************************/175/*176Handle permutation of arguments.177178Exchange two adjacent subsequences of ARGV.179One subsequence is elements [first_nonopt,last_nonopt)180which contains all the non-options that have been skipped so far.181The other is elements [last_nonopt,gk_optind), which contains all182the options processed since those non-options were skipped.183184`first_nonopt' and `last_nonopt' are relocated so that they describe185the new indices of the non-options in ARGV after they are moved.186*/187/*************************************************************************/188static void exchange (char **argv)189{190int bottom = first_nonopt;191int middle = last_nonopt;192int top = gk_optind;193char *tem;194195/* Exchange the shorter segment with the far end of the longer segment.196That puts the shorter segment into the right place.197It leaves the longer segment in the right place overall,198but it consists of two parts that need to be swapped next. */199200while (top > middle && middle > bottom) {201if (top - middle > middle - bottom) {202/* Bottom segment is the short one. */203int len = middle - bottom;204register int i;205206/* Swap it with the top part of the top segment. */207for (i = 0; i < len; i++) {208tem = argv[bottom + i];209argv[bottom + i] = argv[top - (middle - bottom) + i];210argv[top - (middle - bottom) + i] = tem;211}212/* Exclude the moved bottom segment from further swapping. */213top -= len;214}215else {216/* Top segment is the short one. */217int len = top - middle;218register int i;219220/* Swap it with the bottom part of the bottom segment. */221for (i = 0; i < len; i++) {222tem = argv[bottom + i];223argv[bottom + i] = argv[middle + i];224argv[middle + i] = tem;225}226/* Exclude the moved top segment from further swapping. */227bottom += len;228}229}230231/* Update records for the slots the non-options now occupy. */232233first_nonopt += (gk_optind - last_nonopt);234last_nonopt = gk_optind;235}236237238239/*************************************************************************/240/*241Initialize the internal data when the first call is made.242*/243/*************************************************************************/244static char *gk_getopt_initialize (int argc, char **argv, char *optstring)245{246/* Start processing options with ARGV-element 1 (since ARGV-element 0247is the program name); the sequence of previously skipped248non-option ARGV-elements is empty. */249250first_nonopt = last_nonopt = gk_optind;251252nextchar = NULL;253254posixly_correct = getenv("POSIXLY_CORRECT");255256/* Determine how to handle the ordering of options and nonoptions. */257if (optstring[0] == '-') {258ordering = RETURN_IN_ORDER;259++optstring;260}261else if (optstring[0] == '+') {262ordering = REQUIRE_ORDER;263++optstring;264}265else if (posixly_correct != NULL)266ordering = REQUIRE_ORDER;267else268ordering = PERMUTE;269270return optstring;271}272273274/*************************************************************************/275/*276Scan elements of ARGV (whose length is ARGC) for option characters277given in OPTSTRING.278279If an element of ARGV starts with '-', and is not exactly "-" or "--",280then it is an option element. The characters of this element281(aside from the initial '-') are option characters. If `getopt'282is called repeatedly, it returns successively each of the option characters283from each of the option elements.284285If `getopt' finds another option character, it returns that character,286updating `gk_optind' and `nextchar' so that the next call to `getopt' can287resume the scan with the following option character or ARGV-element.288289If there are no more option characters, `getopt' returns -1.290Then `gk_optind' is the index in ARGV of the first ARGV-element291that is not an option. (The ARGV-elements have been permuted292so that those that are not options now come last.)293294OPTSTRING is a string containing the legitimate option characters.295If an option character is seen that is not listed in OPTSTRING,296return '?' after printing an error message. If you set `gk_opterr' to297zero, the error message is suppressed but we still return '?'.298299If a char in OPTSTRING is followed by a colon, that means it wants an arg,300so the following text in the same ARGV-element, or the text of the following301ARGV-element, is returned in `gk_optarg'. Two colons mean an option that302wants an optional arg; if there is text in the current ARGV-element,303it is returned in `gk_optarg', otherwise `gk_optarg' is set to zero.304305If OPTSTRING starts with `-' or `+', it requests different methods of306handling the non-option ARGV-elements.307See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.308309Long-named options begin with `--' instead of `-'.310Their names may be abbreviated as long as the abbreviation is unique311or is an exact match for some defined option. If they have an312argument, it follows the option name in the same ARGV-element, separated313from the option name by a `=', or else the in next ARGV-element.314When `getopt' finds a long-named option, it returns 0 if that option's315`flag' field is nonzero, the value of the option's `val' field316if the `flag' field is zero.317318LONGOPTS is a vector of `struct gk_option' terminated by an319element containing a name which is zero.320321LONGIND returns the index in LONGOPT of the long-named option found.322It is only valid when a long-named option has been found by the most323recent call.324325If LONG_ONLY is nonzero, '-' as well as '--' can introduce326long-named options.327*/328/*************************************************************************/329static int gk_getopt_internal(int argc, char **argv, char *optstring,330struct gk_option *longopts, int *longind, int long_only)331{332int print_errors = gk_opterr;333if (optstring[0] == ':')334print_errors = 0;335336if (argc < 1)337return -1;338339gk_optarg = NULL;340341if (gk_optind == 0 || !gk_getopt_initialized) {342if (gk_optind == 0)343gk_optind = 1; /* Don't scan ARGV[0], the program name. */344optstring = gk_getopt_initialize (argc, argv, optstring);345gk_getopt_initialized = 1;346}347348/* Test whether ARGV[gk_optind] points to a non-option argument.349Either it does not have option syntax, or there is an environment flag350from the shell indicating it is not an option. The later information351is only used when the used in the GNU libc. */352# define NONOPTION_P (argv[gk_optind][0] != '-' || argv[gk_optind][1] == '\0')353354if (nextchar == NULL || *nextchar == '\0') {355/* Advance to the next ARGV-element. */356357/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been358moved back by the user (who may also have changed the arguments). */359if (last_nonopt > gk_optind)360last_nonopt = gk_optind;361if (first_nonopt > gk_optind)362first_nonopt = gk_optind;363364if (ordering == PERMUTE) {365/* If we have just processed some options following some non-options,366exchange them so that the options come first. */367368if (first_nonopt != last_nonopt && last_nonopt != gk_optind)369exchange ((char **) argv);370else if (last_nonopt != gk_optind)371first_nonopt = gk_optind;372373/* Skip any additional non-options374and extend the range of non-options previously skipped. */375376while (gk_optind < argc && NONOPTION_P)377gk_optind++;378379last_nonopt = gk_optind;380}381382/* The special ARGV-element `--' means premature end of options.383Skip it like a null option,384then exchange with previous non-options as if it were an option,385then skip everything else like a non-option. */386387if (gk_optind != argc && !strcmp (argv[gk_optind], "--")) {388gk_optind++;389390if (first_nonopt != last_nonopt && last_nonopt != gk_optind)391exchange ((char **) argv);392else if (first_nonopt == last_nonopt)393first_nonopt = gk_optind;394last_nonopt = argc;395396gk_optind = argc;397}398399/* If we have done all the ARGV-elements, stop the scan400and back over any non-options that we skipped and permuted. */401402if (gk_optind == argc) {403/* Set the next-arg-index to point at the non-options404that we previously skipped, so the caller will digest them. */405if (first_nonopt != last_nonopt)406gk_optind = first_nonopt;407return -1;408}409410/* If we have come to a non-option and did not permute it,411either stop the scan or describe it to the caller and pass it by. */412413if (NONOPTION_P) {414if (ordering == REQUIRE_ORDER)415return -1;416gk_optarg = argv[gk_optind++];417return 1;418}419420/* We have found another option-ARGV-element.421Skip the initial punctuation. */422423nextchar = (argv[gk_optind] + 1 + (longopts != NULL && argv[gk_optind][1] == '-'));424}425426/* Decode the current option-ARGV-element. */427428/* Check whether the ARGV-element is a long option.429430If long_only and the ARGV-element has the form "-f", where f is431a valid short option, don't consider it an abbreviated form of432a long option that starts with f. Otherwise there would be no433way to give the -f short option.434435On the other hand, if there's a long option "fubar" and436the ARGV-element is "-fu", do consider that an abbreviation of437the long option, just like "--fu", and not "-f" with arg "u".438439This distinction seems to be the most useful approach. */440441if (longopts != NULL && (argv[gk_optind][1] == '-' || (long_only && (argv[gk_optind][2] || !strchr(optstring, argv[gk_optind][1]))))) {442char *nameend;443struct gk_option *p;444struct gk_option *pfound = NULL;445int exact = 0;446int ambig = 0;447int indfound = -1;448int option_index;449450for (nameend = nextchar; *nameend && *nameend != '='; nameend++)451/* Do nothing. */ ;452453/* Test all long options for either exact match or abbreviated matches. */454for (p = longopts, option_index = 0; p->name; p++, option_index++) {455if (!strncmp (p->name, nextchar, nameend - nextchar)) {456if ((unsigned int) (nameend - nextchar) == (unsigned int) strlen (p->name)) {457/* Exact match found. */458pfound = p;459indfound = option_index;460exact = 1;461break;462}463else if (pfound == NULL) {464/* First nonexact match found. */465pfound = p;466indfound = option_index;467}468else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)469/* Second or later nonexact match found. */470ambig = 1;471}472}473474if (ambig && !exact) {475if (print_errors)476fprintf(stderr, "%s: option `%s' is ambiguous\n", argv[0], argv[gk_optind]);477478nextchar += strlen (nextchar);479gk_optind++;480gk_optopt = 0;481return '?';482}483484if (pfound != NULL) {485option_index = indfound;486gk_optind++;487if (*nameend) {488/* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */489if (pfound->has_arg)490gk_optarg = nameend + 1;491else {492if (print_errors) {493if (argv[gk_optind - 1][1] == '-')494/* --option */495fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", argv[0], pfound->name);496else497/* +option or -option */498fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", argv[0], argv[gk_optind - 1][0], pfound->name);499}500501nextchar += strlen (nextchar);502503gk_optopt = pfound->val;504return '?';505}506}507else if (pfound->has_arg == 1) {508if (gk_optind < argc)509gk_optarg = argv[gk_optind++];510else {511if (print_errors)512fprintf(stderr, "%s: option `%s' requires an argument\n", argv[0], argv[gk_optind - 1]);513nextchar += strlen (nextchar);514gk_optopt = pfound->val;515return optstring[0] == ':' ? ':' : '?';516}517}518nextchar += strlen (nextchar);519if (longind != NULL)520*longind = option_index;521if (pfound->flag) {522*(pfound->flag) = pfound->val;523return 0;524}525return pfound->val;526}527528/* Can't find it as a long option. If this is not getopt_long_only,529or the option starts with '--' or is not a valid short530option, then it's an error. Otherwise interpret it as a short option. */531if (!long_only || argv[gk_optind][1] == '-' || strchr(optstring, *nextchar) == NULL) {532if (print_errors) {533if (argv[gk_optind][1] == '-')534/* --option */535fprintf(stderr, "%s: unrecognized option `--%s'\n", argv[0], nextchar);536else537/* +option or -option */538fprintf(stderr, "%s: unrecognized option `%c%s'\n", argv[0], argv[gk_optind][0], nextchar);539}540nextchar = (char *) "";541gk_optind++;542gk_optopt = 0;543return '?';544}545}546547/* Look at and handle the next short option-character. */548{549char c = *nextchar++;550char *temp = strchr(optstring, c);551552/* Increment `gk_optind' when we start to process its last character. */553if (*nextchar == '\0')554++gk_optind;555556if (temp == NULL || c == ':') {557if (print_errors) {558if (posixly_correct)559/* 1003.2 specifies the format of this message. */560fprintf(stderr, "%s: illegal option -- %c\n", argv[0], c);561else562fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);563}564gk_optopt = c;565return '?';566}567568/* Convenience. Treat POSIX -W foo same as long option --foo */569if (temp[0] == 'W' && temp[1] == ';') {570char *nameend;571struct gk_option *p;572struct gk_option *pfound = NULL;573int exact = 0;574int ambig = 0;575int indfound = 0;576int option_index;577578/* This is an option that requires an argument. */579if (*nextchar != '\0') {580gk_optarg = nextchar;581/* If we end this ARGV-element by taking the rest as an arg,582we must advance to the next element now. */583gk_optind++;584}585else if (gk_optind == argc) {586if (print_errors) {587/* 1003.2 specifies the format of this message. */588fprintf(stderr, "%s: option requires an argument -- %c\n", argv[0], c);589}590gk_optopt = c;591if (optstring[0] == ':')592c = ':';593else594c = '?';595return c;596}597else598/* We already incremented `gk_optind' once; increment it again when taking next ARGV-elt as argument. */599gk_optarg = argv[gk_optind++];600601/* gk_optarg is now the argument, see if it's in the table of longopts. */602603for (nextchar = nameend = gk_optarg; *nameend && *nameend != '='; nameend++)604/* Do nothing. */ ;605606/* Test all long options for either exact match or abbreviated matches. */607for (p = longopts, option_index = 0; p->name; p++, option_index++) {608if (!strncmp (p->name, nextchar, nameend - nextchar)) {609if ((unsigned int) (nameend - nextchar) == strlen (p->name)) {610/* Exact match found. */611pfound = p;612indfound = option_index;613exact = 1;614break;615}616else if (pfound == NULL) {617/* First nonexact match found. */618pfound = p;619indfound = option_index;620}621else622/* Second or later nonexact match found. */623ambig = 1;624}625}626if (ambig && !exact) {627if (print_errors)628fprintf(stderr, "%s: option `-W %s' is ambiguous\n", argv[0], argv[gk_optind]);629nextchar += strlen (nextchar);630gk_optind++;631return '?';632}633if (pfound != NULL) {634option_index = indfound;635if (*nameend) {636/* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */637if (pfound->has_arg)638gk_optarg = nameend + 1;639else {640if (print_errors)641fprintf(stderr, "%s: option `-W %s' doesn't allow an argument\n", argv[0], pfound->name);642643nextchar += strlen (nextchar);644return '?';645}646}647else if (pfound->has_arg == 1) {648if (gk_optind < argc)649gk_optarg = argv[gk_optind++];650else {651if (print_errors)652fprintf(stderr, "%s: option `%s' requires an argument\n", argv[0], argv[gk_optind - 1]);653nextchar += strlen (nextchar);654return optstring[0] == ':' ? ':' : '?';655}656}657nextchar += strlen (nextchar);658if (longind != NULL)659*longind = option_index;660if (pfound->flag) {661*(pfound->flag) = pfound->val;662return 0;663}664return pfound->val;665}666nextchar = NULL;667return 'W'; /* Let the application handle it. */668}669670if (temp[1] == ':') {671if (temp[2] == ':') {672/* This is an option that accepts an argument optionally. */673if (*nextchar != '\0') {674gk_optarg = nextchar;675gk_optind++;676}677else678gk_optarg = NULL;679nextchar = NULL;680}681else {682/* This is an option that requires an argument. */683if (*nextchar != '\0') {684gk_optarg = nextchar;685/* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */686gk_optind++;687}688else if (gk_optind == argc) {689if (print_errors) {690/* 1003.2 specifies the format of this message. */691fprintf(stderr, "%s: option requires an argument -- %c\n", argv[0], c);692}693gk_optopt = c;694if (optstring[0] == ':')695c = ':';696else697c = '?';698}699else700/* We already incremented `gk_optind' once; increment it again when taking next ARGV-elt as argument. */701gk_optarg = argv[gk_optind++];702nextchar = NULL;703}704}705return c;706}707}708709710711/*************************************************************************/712/*! \brief Parse command-line arguments713714The gk_getopt() function gets the next option argument from the argument715list specified by the \c argv and \c argc arguments. Normally these values716come directly from the arguments received by main().717718\param argc is the number of command line arguments passed to main().719\param argv is an array of strings storing the above command line720arguments.721\param options is a string that specifies the option characters that722are valid for this program. An option character in this string723can be followed by a colon (`:') to indicate that it takes a724required argument. If an option character is followed by two725colons (`::'), its argument is optional; this is a GNU extension.726727\return728It returns the option character for the next command line option. When no729more option arguments are available, it returns -1. There may still be730more non-option arguments; you must compare the external variable731#gk_optind against the \c argc parameter to check this.732733\return734If the option has an argument, gk_getopt() returns the argument by storing735it in the variable #gk_optarg. You don't ordinarily need to copy the736#gk_optarg string, since it is a pointer into the original \c argv array,737not into a static area that might be overwritten.738739\return740If gk_getopt() finds an option character in \c argv that was not included741in options, or a missing option argument, it returns `?' and sets the742external variable #gk_optopt to the actual option character.743If the first character of options is a colon (`:'), then gk_getopt()744returns `:' instead of `?' to indicate a missing option argument.745In addition, if the external variable #gk_opterr is nonzero (which is746the default), gk_getopt() prints an error message. This variable is747set by gk_getopt() to point at the value of the option argument,748for those options that accept arguments.749750751gk_getopt() has three ways to deal with options that follow non-options752\c argv elements. The special argument <tt>`--'</tt> forces in all cases753the end of option scanning.754- The default is to permute the contents of \c argv while scanning it755so that eventually all the non-options are at the end. This allows756options to be given in any order, even with programs that were not757written to expect this.758- If the options argument string begins with a hyphen (`-'), this is759treated specially. It permits arguments that are not options to be760returned as if they were associated with option character `\\1'.761- POSIX demands the following behavior: The first non-option stops762option processing. This mode is selected by either setting the763environment variable POSIXLY_CORRECT or beginning the options764argument string with a plus sign (`+').765766*/767/*************************************************************************/768int gk_getopt(int argc, char **argv, char *options)769{770return gk_getopt_internal(argc, argv, options, NULL, NULL, 0);771}772773774/*************************************************************************/775/*! \brief Parse command-line arguments with long options776777This function accepts GNU-style long options as well as single-character778options.779780\param argc is the number of command line arguments passed to main().781\param argv is an array of strings storing the above command line782arguments.783\param options describes the short options to accept, just as it does784in gk_getopt().785\param long_options describes the long options to accept. See the786defintion of ::gk_option for more information.787\param opt_index this is a returned variable. For any long option,788gk_getopt_long() tells you the index in the array \c long_options789of the options definition, by storing it into <tt>*opt_index</tt>.790You can get the name of the option with <tt>longopts[*opt_index].name</tt>.791So you can distinguish among long options either by the values792in their val fields or by their indices. You can also distinguish793in this way among long options that set flags.794795796\return797When gk_getopt_long() encounters a short option, it does the same thing798that gk_getopt() would do: it returns the character code for the option,799and stores the options argument (if it has one) in #gk_optarg.800801\return802When gk_getopt_long() encounters a long option, it takes actions based803on the flag and val fields of the definition of that option.804805\return806If flag is a null pointer, then gk_getopt_long() returns the contents807of val to indicate which option it found. You should arrange distinct808values in the val field for options with different meanings, so you809can decode these values after gk_getopt_long() returns. If the long810option is equivalent to a short option, you can use the short option's811character code in val.812813\return814If flag is not a null pointer, that means this option should just set815a flag in the program. The flag is a variable of type int that you816define. Put the address of the flag in the flag field. Put in the817val field the value you would like this option to store in the flag.818In this case, gk_getopt_long() returns 0.819820\return821When a long option has an argument, gk_getopt_long() puts the argument822value in the variable #gk_optarg before returning. When the option has823no argument, the value in #gk_optarg is a null pointer. This is824how you can tell whether an optional argument was supplied.825826\return827When gk_getopt_long() has no more options to handle, it returns -1,828and leaves in the variable #gk_optind the index in argv of the next829remaining argument.830*/831/*************************************************************************/832int gk_getopt_long( int argc, char **argv, char *options,833struct gk_option *long_options, int *opt_index)834{835return gk_getopt_internal (argc, argv, options, long_options, opt_index, 0);836}837838839840/*************************************************************************/841/*! \brief Parse command-line arguments with only long options842843Like gk_getopt_long(), but '-' as well as '--' can indicate a long option.844If an option that starts with '-' (not '--') doesn't match a long option,845but does match a short option, it is parsed as a short option instead.846*/847/*************************************************************************/848int gk_getopt_long_only(int argc, char **argv, char *options,849struct gk_option *long_options, int *opt_index)850{851return gk_getopt_internal(argc, argv, options, long_options, opt_index, 1);852}853854855856