⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getopt.h

📁 KPIT GNU Tools is a set of GNU development tools for Renesas microcontrollers.
💻 H
字号:
/****************************************************************************getopt.h - Read command line optionsAUTHOR: Gregory PietschCREATED Thu Jan 09 22:37:00 1997DESCRIPTION:The getopt() function parses the command line arguments.  Its arguments argcand argv are the argument count and array as passed to the main() functionon program invocation.  The argument optstring is a list of available optioncharacters.  If such a character is followed by a colon (`:'), the optiontakes an argument, which is placed in optarg.  If such a character isfollowed by two colons, the option takes an optional argument, which isplaced in optarg.  If the option does not take an argument, optarg is NULL.The external variable optind is the index of the next array element of argvto be processed; it communicates from one call to the next which element toprocess.The getopt_long() function works like getopt() except that it also acceptslong options started by two dashes `--'.  If these take values, it is eitherin the form--arg=value or--arg valueIt takes the additional arguments longopts which is a pointer to the firstelement of an array of type GETOPT_LONG_OPTION_T, defined below.  The lastelement of the array has to be filled with NULL for the name field.The longind pointer points to the index of the current long option relativeto longopts if it is non-NULL.The getopt() function returns the option character if the option was foundsuccessfully, `:' if there was a missing parameter for one of the options,`?' for an unknown option character, and EOF for the end of the option list.The getopt_long() function's return value is described below.The function getopt_long_only() is identical to getopt_long(), except that aplus sign `+' can introduce long options as well as `--'.Describe how to deal with options that follow non-option ARGV-elements.If the caller did not specify anything, the default is REQUIRE_ORDER if theenvironment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.REQUIRE_ORDER means don't recognize them as options; stop option processingwhen the first non-option is seen.  This is what Unix does.  This mode ofoperation is selected by either setting the environment variablePOSIXLY_CORRECT, or using `+' as the first character of the optstringparameter.PERMUTE is the default.  We permute the contents of ARGV as we scan, so thateventually all the non-options are at the end.  This allows options to begiven in any order, even with programs that were not written to expect this.RETURN_IN_ORDER is an option available to programs that were written toexpect options and other ARGV-elements in any order and that care about theordering of the two.  We describe each non-option ARGV-element as if it werethe argument of an option with character code 1.  Using `-' as the firstcharacter of the optstring parameter selects this mode of operation.The special argument `--' forces an end of option-scanning regardless of thevalue of `ordering'.  In the case of RETURN_IN_ORDER, only `--' can causegetopt() and friends to return EOF with optind != argc.COPYRIGHT NOTICE AND DISCLAIMER:Copyright (C) 1997 Gregory PietschThis file and the accompanying getopt.c implementation file are hereby placed in the public domain without restrictions.  Just give the author credit, don't claim you wrote it or prevent anyone else from using it.Gregory Pietsch's current e-mail address:gpietsch@comcast.net****************************************************************************/#ifndef GETOPT_H#define GETOPT_H#include <_ansi.h>/* include files needed by this include file *//* macros defined by this include file */#define NO_ARG          0#define REQUIRED_ARG    1#define OPTIONAL_ARG    2/* types defined by this include file */struct option{  char *name;                   /* the name of the long option */  int has_arg;                  /* one of the above macros */  int *flag;                    /* determines if getopt_long() returns a                                 * value for a long option; if it is                                 * non-NULL, 0 is returned as a function                                 * value and the value of val is stored in                                 * the area pointed to by flag.  Otherwise,                                 * val is returned. */  int val;                      /* determines the value to return if flag is                                 * NULL. */};#ifdef __cplusplusextern "C"{#endif  /* externally-defined variables */  extern char *optarg;  extern int optind;  extern int opterr;  extern int optopt;  /* function prototypes */  int _EXFUN (getopt, (int __argc, char *const __argv[], const char *__optstring));  int _EXFUN (getopt_long, (int __argc, char *const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind));  int _EXFUN (getopt_long_only, (int __argc, char *const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind));#ifdef __cplusplus};#endif#endif /* GETOPT_H *//* END OF FILE getopt.h */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -