mi-getopt.h revision 130804
1193326Sed/* MI Option Parser.
2193326Sed   Copyright 2000 Free Software Foundation, Inc.
3193326Sed   Contributed by Cygnus Solutions (a Red Hat company).
4193326Sed
5193326Sed   This file is part of GDB.
6193326Sed
7193326Sed   This program is free software; you can redistribute it and/or modify
8193326Sed   it under the terms of the GNU General Public License as published by
9193326Sed   the Free Software Foundation; either version 2 of the License, or
10193326Sed   (at your option) any later version.
11193326Sed
12193326Sed   This program is distributed in the hope that it will be useful,
13193326Sed   but WITHOUT ANY WARRANTY; without even the implied warranty of
14193326Sed   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15202379Srdivacky   GNU General Public License for more details.
16193326Sed
17193326Sed   You should have received a copy of the GNU General Public License
18193326Sed   along with this program; if not, write to the Free Software
19193326Sed   Foundation, Inc., 59 Temple Place - Suite 330,
20193326Sed   Boston, MA 02111-1307, USA.  */
21193326Sed
22193326Sed#ifndef MI_GETOPT_H
23193326Sed#define MI_GETOPT_H
24193326Sed
25193326Sed/* Like getopt() but with simpler semantics.
26193326Sed
27193326Sed   An option has the form ``-<name>''. The special option ``--''
28198092Srdivacky   denotes the end of the option list. An option can be followed by a
29193326Sed   separate argument (on a per option basis).
30193326Sed
31193326Sed   On entry OPTIND contains the index of the next element of ARGV that
32193326Sed   needs parsing.  OPTIND is updated to indicate the index of the next
33193326Sed   argument before mi_getopt() returns.
34193326Sed
35193326Sed   If ARGV[OPTIND] is an option, that options INDEX is returned.
36193326Sed   OPTARG is set to the options argument or NULL.  OPTIND is updated.
37193326Sed
38198092Srdivacky   If ARGV[OPTIND] is not an option, -1 is returned and OPTIND updated
39193326Sed   to specify the non-option argument.  OPTARG is set to NULL.
40193326Sed
41204643Srdivacky   mi_getopt() calls ``error("%s: Unknown option %c", prefix,
42204643Srdivacky   option)'' if an unknown option is encountered. */
43193326Sed
44193326Sedstruct mi_opt;
45193326Sedextern int mi_getopt (const char *prefix, int argc, char **argv,
46193326Sed		      struct mi_opt *opt, int *optind, char **optarg);
47193326Sed
48198092Srdivacky/* The option list.  Terminated by NAME==NULL.  ARG_P that the option
49193326Sed   requires an argument.  INDEX is returned to identify th option. */
50193326Sed
51193326Sedstruct mi_opt
52193326Sed  {
53193326Sed    const char *name;
54193326Sed    int index;
55193326Sed    int arg_p;
56193326Sed  };
57193326Sed
58193326Sedstruct mi_opt;
59193326Sed
60193326Sed/* mi_valid_noargs
61193326Sed
62193326Sed   Determines if ARGC/ARGV are a valid set of parameters to satisfy
63193326Sed   an MI function that is not supposed to recieve any arguments.
64202879Srdivacky
65193326Sed   An MI function that should not recieve arguments can still be
66193326Sed   passed parameters after the special option '--' such as below.
67198092Srdivacky
68193326Sed   Example: The MI function -exec-run takes no args.
69207619Srdivacky   However, the client may pass '-exec-run -- -a ...'
70207619Srdivacky   See PR-783
71193326Sed
72193326Sed   PREFIX is passed to mi_getopt for an error message.
73193326Sed
74193326Sed   This function Returns 1 if the parameter pair ARGC/ARGV are valid
75193326Sed   for an MI function that takes no arguments. Otherwise, it returns 0
76198092Srdivacky   and the appropriate error message is displayed by mi_getopt.  */
77193326Sed
78193326Sedextern int mi_valid_noargs (const char *prefix, int argc, char **argv);
79193326Sed
80193326Sed#endif
81193326Sed