xref: /illumos-gate/usr/src/grub/grub-0.97/lib/getopt.h (revision 1b8adde7)
17c478bd9Sstevel@tonic-gate /* Declarations for getopt.
27c478bd9Sstevel@tonic-gate    Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate    NOTE: The canonical source of this file is maintained with the GNU C Library.
57c478bd9Sstevel@tonic-gate    Bugs can be reported to bug-glibc@gnu.org.
67c478bd9Sstevel@tonic-gate 
77c478bd9Sstevel@tonic-gate    This program is free software; you can redistribute it and/or modify it
87c478bd9Sstevel@tonic-gate    under the terms of the GNU General Public License as published by the
97c478bd9Sstevel@tonic-gate    Free Software Foundation; either version 2, or (at your option) any
107c478bd9Sstevel@tonic-gate    later version.
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate    This program is distributed in the hope that it will be useful,
137c478bd9Sstevel@tonic-gate    but WITHOUT ANY WARRANTY; without even the implied warranty of
147c478bd9Sstevel@tonic-gate    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
157c478bd9Sstevel@tonic-gate    GNU General Public License for more details.
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate    You should have received a copy of the GNU General Public License
187c478bd9Sstevel@tonic-gate    along with this program; if not, write to the Free Software
197c478bd9Sstevel@tonic-gate    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
207c478bd9Sstevel@tonic-gate    USA.  */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate #ifndef _GETOPT_H
237c478bd9Sstevel@tonic-gate #define _GETOPT_H 1
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
267c478bd9Sstevel@tonic-gate extern "C" {
277c478bd9Sstevel@tonic-gate #endif
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /* For communication from `getopt' to the caller.
307c478bd9Sstevel@tonic-gate    When `getopt' finds an option that takes an argument,
317c478bd9Sstevel@tonic-gate    the argument value is returned here.
327c478bd9Sstevel@tonic-gate    Also, when `ordering' is RETURN_IN_ORDER,
337c478bd9Sstevel@tonic-gate    each non-option ARGV-element is returned here.  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate extern char *optarg;
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /* Index in ARGV of the next element to be scanned.
387c478bd9Sstevel@tonic-gate    This is used for communication to and from the caller
397c478bd9Sstevel@tonic-gate    and for communication between successive calls to `getopt'.
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate    On entry to `getopt', zero means this is the first call; initialize.
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate    When `getopt' returns -1, this is the index of the first of the
447c478bd9Sstevel@tonic-gate    non-option elements that the caller should itself scan.
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate    Otherwise, `optind' communicates from one call to the next
477c478bd9Sstevel@tonic-gate    how much of ARGV has been scanned so far.  */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate extern int optind;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* Callers store zero here to inhibit the error message `getopt' prints
527c478bd9Sstevel@tonic-gate    for unrecognized options.  */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate extern int opterr;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /* Set to an option character which was unrecognized.  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate extern int optopt;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* Describe the long-named options requested by the application.
617c478bd9Sstevel@tonic-gate    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
627c478bd9Sstevel@tonic-gate    of `struct option' terminated by an element containing a name which is
637c478bd9Sstevel@tonic-gate    zero.
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate    The field `has_arg' is:
667c478bd9Sstevel@tonic-gate    no_argument		(or 0) if the option does not take an argument,
677c478bd9Sstevel@tonic-gate    required_argument	(or 1) if the option requires an argument,
687c478bd9Sstevel@tonic-gate    optional_argument 	(or 2) if the option takes an optional argument.
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate    If the field `flag' is not NULL, it points to a variable that is set
717c478bd9Sstevel@tonic-gate    to the value given in the field `val' when the option is found, but
727c478bd9Sstevel@tonic-gate    left unchanged if the option is not found.
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate    To have a long-named option do something other than set an `int' to
757c478bd9Sstevel@tonic-gate    a compiled-in constant, such as set a value from `optarg', set the
767c478bd9Sstevel@tonic-gate    option's `flag' field to zero and its `val' field to a nonzero
777c478bd9Sstevel@tonic-gate    value (the equivalent single-letter option character, if there is
787c478bd9Sstevel@tonic-gate    one).  For long options that have a zero `flag' field, `getopt'
797c478bd9Sstevel@tonic-gate    returns the contents of the `val' field.  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate struct option
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate #if defined (__STDC__) && __STDC__
847c478bd9Sstevel@tonic-gate   const char *name;
857c478bd9Sstevel@tonic-gate #else
867c478bd9Sstevel@tonic-gate   char *name;
877c478bd9Sstevel@tonic-gate #endif
887c478bd9Sstevel@tonic-gate   /* has_arg can't be an enum because some compilers complain about
897c478bd9Sstevel@tonic-gate      type mismatches in all the code that assumes it is an int.  */
907c478bd9Sstevel@tonic-gate   int has_arg;
917c478bd9Sstevel@tonic-gate   int *flag;
927c478bd9Sstevel@tonic-gate   int val;
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* Names for the values of the `has_arg' field of `struct option'.  */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	no_argument		0
987c478bd9Sstevel@tonic-gate #define required_argument	1
997c478bd9Sstevel@tonic-gate #define optional_argument	2
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #if defined (__STDC__) && __STDC__
1027c478bd9Sstevel@tonic-gate #ifdef __GNU_LIBRARY__
1037c478bd9Sstevel@tonic-gate /* Many other libraries have conflicting prototypes for getopt, with
1047c478bd9Sstevel@tonic-gate    differences in the consts, in stdlib.h.  To avoid compilation
1057c478bd9Sstevel@tonic-gate    errors, only prototype getopt for the GNU C library.  */
1067c478bd9Sstevel@tonic-gate extern int getopt (int argc, char *const *argv, const char *shortopts);
1077c478bd9Sstevel@tonic-gate #else /* not __GNU_LIBRARY__ */
1087c478bd9Sstevel@tonic-gate extern int getopt ();
1097c478bd9Sstevel@tonic-gate #endif /* __GNU_LIBRARY__ */
1107c478bd9Sstevel@tonic-gate extern int getopt_long (int argc, char *const *argv, const char *shortopts,
1117c478bd9Sstevel@tonic-gate 		        const struct option *longopts, int *longind);
1127c478bd9Sstevel@tonic-gate extern int getopt_long_only (int argc, char *const *argv,
1137c478bd9Sstevel@tonic-gate 			     const char *shortopts,
1147c478bd9Sstevel@tonic-gate 		             const struct option *longopts, int *longind);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /* Internal only.  Users should not call this directly.  */
1177c478bd9Sstevel@tonic-gate extern int _getopt_internal (int argc, char *const *argv,
1187c478bd9Sstevel@tonic-gate 			     const char *shortopts,
1197c478bd9Sstevel@tonic-gate 		             const struct option *longopts, int *longind,
1207c478bd9Sstevel@tonic-gate 			     int long_only);
1217c478bd9Sstevel@tonic-gate #else /* not __STDC__ */
1227c478bd9Sstevel@tonic-gate extern int getopt ();
1237c478bd9Sstevel@tonic-gate extern int getopt_long ();
1247c478bd9Sstevel@tonic-gate extern int getopt_long_only ();
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate extern int _getopt_internal ();
1277c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #endif /* getopt.h */
134