~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/compat/getopt.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Libav.
 
3
 *
 
4
 * Libav is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * Libav is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with Libav; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 */
 
18
 
 
19
/*
 
20
 * This file was copied from the following newsgroup posting:
 
21
 *
 
22
 * Newsgroups: mod.std.unix
 
23
 * Subject: public domain AT&T getopt source
 
24
 * Date: 3 Nov 85 19:34:15 GMT
 
25
 *
 
26
 * Here's something you've all been waiting for:  the AT&T public domain
 
27
 * source for getopt(3).  It is the code which was given out at the 1985
 
28
 * UNIFORUM conference in Dallas.  I obtained it by electronic mail
 
29
 * directly from AT&T.  The people there assure me that it is indeed
 
30
 * in the public domain.
 
31
 */
 
32
 
 
33
#include <stdio.h>
 
34
#include <string.h>
 
35
 
 
36
static int opterr = 1;
 
37
static int optind = 1;
 
38
static int optopt;
 
39
static char *optarg;
 
40
 
 
41
#undef fprintf
 
42
 
 
43
static int getopt(int argc, char *argv[], char *opts)
 
44
{
 
45
    static int sp = 1;
 
46
    int c;
 
47
    char *cp;
 
48
 
 
49
    if (sp == 1)
 
50
        if (optind >= argc ||
 
51
            argv[optind][0] != '-' || argv[optind][1] == '\0')
 
52
            return EOF;
 
53
        else if (!strcmp(argv[optind], "--")) {
 
54
            optind++;
 
55
            return EOF;
 
56
        }
 
57
    optopt = c = argv[optind][sp];
 
58
    if (c == ':' || (cp = strchr(opts, c)) == NULL) {
 
59
        fprintf(stderr, ": illegal option -- %c\n", c);
 
60
        if (argv[optind][++sp] == '\0') {
 
61
            optind++;
 
62
            sp = 1;
 
63
        }
 
64
        return '?';
 
65
    }
 
66
    if (*++cp == ':') {
 
67
        if (argv[optind][sp+1] != '\0')
 
68
            optarg = &argv[optind++][sp+1];
 
69
        else if(++optind >= argc) {
 
70
            fprintf(stderr, ": option requires an argument -- %c\n", c);
 
71
            sp = 1;
 
72
            return '?';
 
73
        } else
 
74
            optarg = argv[optind++];
 
75
        sp = 1;
 
76
    } else {
 
77
        if (argv[optind][++sp] == '\0') {
 
78
            sp = 1;
 
79
            optind++;
 
80
        }
 
81
        optarg = NULL;
 
82
    }
 
83
 
 
84
    return c;
 
85
}