/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718/*19* This file was copied from the following newsgroup posting:20*21* Newsgroups: mod.std.unix22* Subject: public domain AT&T getopt source23* Date: 3 Nov 85 19:34:15 GMT24*25* Here's something you've all been waiting for: the AT&T public domain26* source for getopt(3). It is the code which was given out at the 198527* UNIFORUM conference in Dallas. I obtained it by electronic mail28* directly from AT&T. The people there assure me that it is indeed29* in the public domain.30*/3132#include <stdio.h>33#include <string.h>3435static int opterr = 1;36static int optind = 1;37static int optopt;38static char *optarg;3940static int getopt(int argc, char *argv[], char *opts)41{42static int sp = 1;43int c;44char *cp;4546if (sp == 1) {47if (optind >= argc ||48argv[optind][0] != '-' || argv[optind][1] == '\0')49return EOF;50else if (!strcmp(argv[optind], "--")) {51optind++;52return EOF;53}54}55optopt = c = argv[optind][sp];56if (c == ':' || !(cp = strchr(opts, c))) {57fprintf(stderr, ": illegal option -- %c\n", c);58if (argv[optind][++sp] == '\0') {59optind++;60sp = 1;61}62return '?';63}64if (*++cp == ':') {65if (argv[optind][sp+1] != '\0')66optarg = &argv[optind++][sp+1];67else if(++optind >= argc) {68fprintf(stderr, ": option requires an argument -- %c\n", c);69sp = 1;70return '?';71} else72optarg = argv[optind++];73sp = 1;74} else {75if (argv[optind][++sp] == '\0') {76sp = 1;77optind++;78}79optarg = NULL;80}8182return c;83}848586