OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [mi/] [mi-getopt.c] - Blame information for rev 107

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/* MI Command Set - MI Option Parser.
2
   Copyright (C) 2000, Free Software Foundation, Inc.
3
   Contributed by Cygnus Solutions (a Red Hat company).
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
#include "defs.h"
23
#include "mi-getopt.h"
24
#include "string.h"
25
 
26
int
27
mi_getopt (const char *prefix,
28
           int argc, char **argv,
29
           struct mi_opt *opts,
30
           int *optind, char **optarg)
31
{
32
  char *arg;
33
  struct mi_opt *opt;
34
  /* We assume that argv/argc are ok. */
35
  if (*optind > argc || *optind < 0)
36
    internal_error ("mi_getopt_long: optind out of bounds");
37
  if (*optind == argc)
38
    return -1;
39
  arg = argv[*optind];
40
  /* ``--''? */
41
  if (strcmp (arg, "--") == 0)
42
    {
43
      *optind += 1;
44
      *optarg = NULL;
45
      return -1;
46
    }
47
  /* End of option list. */
48
  if (arg[0] != '-')
49
    {
50
      *optarg = NULL;
51
      return -1;
52
    }
53
  /* Look the option up. */
54
  for (opt = opts; opt->name != NULL; opt++)
55
    {
56
      if (strcmp (opt->name, arg + 1) != 0)
57
        continue;
58
      if (opt->arg_p)
59
        {
60
          /* A non-simple optarg option. */
61
          if (argc < *optind + 2)
62
            error ("%s: Option %s requires an argument", prefix, arg);
63
          *optarg = argv[(*optind) + 1];
64
          *optind = (*optind) + 2;
65
          return opt->index;
66
        }
67
      else
68
        {
69
          *optarg = NULL;
70
          *optind = (*optind) + 1;
71
          return opt->index;
72
        }
73
    }
74
  error ("%s: Unknown option ``%s''", prefix, arg + 1);
75
}
76
 
77
 
78
/* Local variables: */
79
/* change-log-default-name: "ChangeLog-mi" */
80
/* End: */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.