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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [linux/] [getoptlong.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
#include <unistd.h>
2
#include <string.h>
3
#include <getopt.h>
4
 
5
/* Written 2000 by Werner Almesberger */
6
 
7
static const char *__resume;
8
 
9
 
10
int getopt_long(int argc,char *const argv[],const char *optstring,
11
  const struct option *longopts,int *longindex)
12
{
13
    char *here;
14
 
15
    optarg = NULL;
16
    if (!__resume) {
17
        if (argc == optind || *argv[optind] != '-') return -1;
18
        if (argv[optind][1] == '-') {
19
            const struct option *opt;
20
 
21
            optarg = strchr(argv[optind],'=');
22
            if (optarg) optarg++;
23
            for (opt = longopts; opt->name &&
24
              (optarg || strcmp(opt->name,argv[optind]+2)) &&
25
              (!optarg || strlen(opt->name) != optarg-argv[optind]-3 ||
26
              strncmp(opt->name,argv[optind]+2,optarg-argv[optind]-3));
27
              opt++);
28
            optind++;
29
            if (!opt->name) return '?';
30
            if ((opt->has_arg == no_argument && optarg) ||
31
              (opt->has_arg == required_argument && !optarg)) return ':';
32
            if (longindex) *longindex = opt-longopts;
33
            if (!opt->flag) return opt->val;
34
            *opt->flag = opt->val;
35
            return 0;
36
        }
37
        else {
38
            __resume = argv[optind]+1;
39
        }
40
    }
41
    here = strchr(optstring,*__resume);
42
    if (!here) {
43
        optind++;
44
        __resume = NULL;
45
        return '?';
46
    }
47
    if (here[1] != ':') {
48
        if (!*++__resume) __resume = NULL;
49
    }
50
    else {
51
        if (__resume[1]) optarg = (char *) __resume+1;
52
        else {
53
            optarg = (char *) argv[++optind];
54
            if (optind == argc || *argv[optind] == '-') {
55
                optind++;
56
                __resume = NULL;
57
                return ':';
58
            }
59
        }
60
        __resume = NULL;
61
    }
62
    if (!__resume) optind++;
63
    return *here;
64
}

powered by: WebSVN 2.1.0

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