/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223#include <ast.h>2425#undef _lib_getopt /* we can satisfy the api */2627#if _lib_getopt2829NoN(getopt)3031#else3233#undef _BLD_ast /* enable ast imports since we're user static */3435#include <error.h>36#include <option.h>3738int opterr = 1;39int optind = 1;40int optopt = 0;41char* optarg = 0;4243static int lastoptind;4445extern int46getopt(int argc, char* const* argv, const char* optstring)47{48int n;4950NoP(argc);51opt_info.index = (optind > 1 || optind == lastoptind) ? optind : 0;52if (opt_info.index >= argc)53return -1;54switch (n = optget((char**)argv, optstring))55{56case ':':57n = '?';58/*FALLTHROUGH*/59case '?':60if (opterr && (!optstring || *optstring != ':'))61{62if (!error_info.id)63error_info.id = argv[0];64errormsg(NiL, 2, opt_info.arg);65}66optopt = opt_info.option[1];67break;68case 0:69n = -1;70break;71}72optarg = opt_info.arg;73lastoptind = optind = opt_info.index;74return n;75}7677#endif787980