getopt(3) getopt(3) NNAAMMEE getopt - get option character from command line SSYYNNTTAAXX ##iinncclluuddee <> char *ooppttaarrgg; int ooppttiinndd; int ooppttppooss; int oopptteeooff; int ooppttpprroobblleemm; char *ooppttpprrooggnnaammee; int oopptteerrrr; int ggeettoopptt((_a_r_g_c_,_a_r_g_v_,_o_p_t_s)); int _a_r_g_c; char **_a_r_g_v; char *_o_p_t_s; DDEESSCCRRIIPPTTIIOONN This is a clone version of the standard ggeettoopptt library, built on top of ssuubbggeettoopptt((33)). See ssuubbggeettoopptt((33)) for a detailed description of ggeettoopptt processing. The main difference between ggeettoopptt and ssuubbggeettoopptt is that ggeettoopptt prints error messages in case of problems. To turn off these error messages, set oopptteerrrr (default nonzero) to zero. This clone version of ggeettoopptt also provides an ooppttpprrooggnnaammee variable. There are two uses for this variable: (1) By default ooppttpprrooggnnaammee is null. When ggeettoopptt sees this, it attempts to initialize ooppttpprrooggnnaammee from _a_r_g_v[[00]], stripping the directory name. The calling program can use ooppttpprrooggnnaammee after calling ggeettoopptt at least once. This is appropriate if the name of the program should be deter- mined from its command line. (2) ggeettoopptt prints ooppttpprrooggnnaammee at the beginning of any error messages. So the calling program can, before calling ggeettoopptt, initialize ooppttpprroogg-- nnaammee as desired. This is appropriate if the name of the program should not be determined from its command line. CCOOMMPPAATTIIBBIILLIITTYY Old versions of ggeettoopptt do not include oopptteerrrr. ooppttppooss, oopptteeooff, ooppttpprroobb-- lleemm, and ooppttpprrooggnnaammee are specific to this clone version of ggeettoopptt. Many features of this clone version of ggeettoopptt are poorly defined, if available at all, in most versions of ggeettoopptt. For example, the stan- dard ggeettoopptt interface does not define ooppttiinndd until the end of the option list. And ooppttaarrgg is not defined unless ggeettoopptt has just returned an option which takes an argument. In this clone version, ooppttiinndd and ooppttppooss always indicate the next character to be read, and ooppttaarrgg is null whenever the current option does not take an argument. See ssuubbggee-- ttoopptt((33)) for precise definitions of the parsing procedure. When it reaches the end of the option list, this version of ggeettoopptt always returns oopptteeooff, which is the same as ssuubbggeettooppttddoonnee, which is initialized to SSUUBBGGEETTOOPPTTDDOONNEE, which is defined as -1. The standard behavior is to return EOF from ssttddiioo((33)).. This is incompatible on any weird machine where EOF is different from -1. The calling program could set oopptteeooff to EOF to imitate the standard behavior. Like most versions of ggeettoopptt, this clone version allows, but does not demand, that option arguments be separated from the option by whites- pace, i.e., be in the next command-line argument. Some versions of ggeettoopptt provide an ooppttoopptt variable. ooppttoopptt is incom- patible across systems: for example, GNU ggeettoopptt uses it the same way that this clone version uses ooppttpprroobblleemm, while BSD ggeettoopptt uses it to indicate the last option character returned by ggeettoopptt. This clone ver- sion does not provide ooppttoopptt. The use of ooppttoopptt is strongly discour- aged. Some versions of ggeettoopptt do not recognize a double hyphen as the end of arguments. This version allows a double hyphen, or in fact any argu- ment beginning with two hyphens. A lone hyphen is always recognized as the end of arguments. Some ver- sions of ggeettoopptt allow lone hyphens as options. This practice is wrong and is strongly discouraged. SSYYNNTTAAXX NNOOTTEE ggeettoopptt is actually a macro abbreviation for ggeettooppttmmiinnee. The external oopptteerrrr and ooppttpprrooggnnaammee variables are macros for ggeettoopptteerrrr and ggeettoopptt-- pprrooggnnaammee. All the other oopptt variables are macros for ssuubbggeettoopptt. These macros are defined in <>, unless GGEETTOOPPTTNNOOSSHHOORRTT is defined. Further macros are defined in <>, which is included by <>, unless SSUUBBGGEETTOOPPTTNNOOSSHHOORRTT is defined. VVEERRSSIIOONN getopt version 1.9, 931129. AAUUTTHHOORR Placed into the public domain by Daniel J. Bernstein. getopt(3)