xref: /dflybsd-src/contrib/gdb-7/gdb/mi/mi-getopt.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* MI Option Parser.
2*ef5ccd6cSJohn Marino    Copyright (C) 2000-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert    Contributed by Cygnus Solutions (a Red Hat company).
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #ifndef MI_GETOPT_H
215796c8dcSSimon Schubert #define MI_GETOPT_H
225796c8dcSSimon Schubert 
23*ef5ccd6cSJohn Marino /* The option list.  Terminated by NAME==NULL.  ARG_P that the option
24*ef5ccd6cSJohn Marino    requires an argument.  INDEX is returned to identify the option.  */
25*ef5ccd6cSJohn Marino 
26*ef5ccd6cSJohn Marino struct mi_opt
27*ef5ccd6cSJohn Marino   {
28*ef5ccd6cSJohn Marino     const char *name;
29*ef5ccd6cSJohn Marino     int index;
30*ef5ccd6cSJohn Marino     int arg_p;
31*ef5ccd6cSJohn Marino   };
32*ef5ccd6cSJohn Marino 
335796c8dcSSimon Schubert /* Like getopt() but with simpler semantics.
345796c8dcSSimon Schubert 
355796c8dcSSimon Schubert    An option has the form ``-<name>''. The special option ``--''
365796c8dcSSimon Schubert    denotes the end of the option list. An option can be followed by a
375796c8dcSSimon Schubert    separate argument (on a per option basis).
385796c8dcSSimon Schubert 
395796c8dcSSimon Schubert    On entry OPTIND contains the index of the next element of ARGV that
405796c8dcSSimon Schubert    needs parsing.  OPTIND is updated to indicate the index of the next
415796c8dcSSimon Schubert    argument before mi_getopt() returns.
425796c8dcSSimon Schubert 
435796c8dcSSimon Schubert    If ARGV[OPTIND] is an option, that options INDEX is returned.
445796c8dcSSimon Schubert    OPTARG is set to the options argument or NULL.  OPTIND is updated.
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert    If ARGV[OPTIND] is not an option, -1 is returned and OPTIND updated
475796c8dcSSimon Schubert    to specify the non-option argument.  OPTARG is set to NULL.
485796c8dcSSimon Schubert 
495796c8dcSSimon Schubert    mi_getopt() calls ``error("%s: Unknown option %c", prefix,
505796c8dcSSimon Schubert    option)'' if an unknown option is encountered.  */
515796c8dcSSimon Schubert 
525796c8dcSSimon Schubert extern int mi_getopt (const char *prefix, int argc, char **argv,
53a45ae5f8SJohn Marino 		      const struct mi_opt *opt, int *optind, char **optarg);
545796c8dcSSimon Schubert 
55*ef5ccd6cSJohn Marino /* mi_valid_noargs determines if ARGC/ARGV are a valid set of
56*ef5ccd6cSJohn Marino    parameters to satisfy an MI function that is not supposed to
57*ef5ccd6cSJohn Marino    recieve any arguments.
585796c8dcSSimon Schubert 
59*ef5ccd6cSJohn Marino    An MI function that should not receive arguments can still be
605796c8dcSSimon Schubert    passed parameters after the special option '--' such as below.
615796c8dcSSimon Schubert 
625796c8dcSSimon Schubert    Example: The MI function -exec-run takes no args.
635796c8dcSSimon Schubert    However, the client may pass '-exec-run -- -a ...'
645796c8dcSSimon Schubert    See PR-783
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert    PREFIX is passed to mi_getopt for an error message.
675796c8dcSSimon Schubert 
685796c8dcSSimon Schubert    This function Returns 1 if the parameter pair ARGC/ARGV are valid
695796c8dcSSimon Schubert    for an MI function that takes no arguments. Otherwise, it returns 0
705796c8dcSSimon Schubert    and the appropriate error message is displayed by mi_getopt.  */
715796c8dcSSimon Schubert 
725796c8dcSSimon Schubert extern int mi_valid_noargs (const char *prefix, int argc, char **argv);
735796c8dcSSimon Schubert 
745796c8dcSSimon Schubert #endif
75