diff options
| author | cvs2svn <cvs2svn@FreeBSD.org> | 2001-11-02 23:41:30 +0000 |
|---|---|---|
| committer | cvs2svn <cvs2svn@FreeBSD.org> | 2001-11-02 23:41:30 +0000 |
| commit | ad5e68fb03a0d0cbbd4e8b86032221fc0cfbfdb0 (patch) | |
| tree | fef9f4f30565029af2552181255afdfe272602ec /contrib/awk/awklib/eg/lib/getopt.awk | |
| parent | 622bfc32f3a2fbac2e123fc14e3bc22a2f9de629 (diff) | |
Notes
Diffstat (limited to 'contrib/awk/awklib/eg/lib/getopt.awk')
| -rw-r--r-- | contrib/awk/awklib/eg/lib/getopt.awk | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/contrib/awk/awklib/eg/lib/getopt.awk b/contrib/awk/awklib/eg/lib/getopt.awk deleted file mode 100644 index 93753052eef1..000000000000 --- a/contrib/awk/awklib/eg/lib/getopt.awk +++ /dev/null @@ -1,80 +0,0 @@ -# getopt.awk --- do C library getopt(3) function in awk -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# -# Initial version: March, 1991 -# Revised: May, 1993 - -# External variables: -# Optind -- index in ARGV of first non-option argument -# Optarg -- string value of argument to current option -# Opterr -- if nonzero, print our own diagnostic -# Optopt -- current option letter - -# Returns: -# -1 at end of options -# ? for unrecognized option -# <c> a character representing the current option - -# Private Data: -# _opti -- index in multi-flag option, e.g., -abc -function getopt(argc, argv, options, thisopt, i) -{ - if (length(options) == 0) # no options given - return -1 - - if (argv[Optind] == "--") { # all done - Optind++ - _opti = 0 - return -1 - } else if (argv[Optind] !~ /^-[^: \t\n\f\r\v\b]/) { - _opti = 0 - return -1 - } - if (_opti == 0) - _opti = 2 - thisopt = substr(argv[Optind], _opti, 1) - Optopt = thisopt - i = index(options, thisopt) - if (i == 0) { - if (Opterr) - printf("%c -- invalid option\n", - thisopt) > "/dev/stderr" - if (_opti >= length(argv[Optind])) { - Optind++ - _opti = 0 - } else - _opti++ - return "?" - } - if (substr(options, i + 1, 1) == ":") { - # get option argument - if (length(substr(argv[Optind], _opti + 1)) > 0) - Optarg = substr(argv[Optind], _opti + 1) - else - Optarg = argv[++Optind] - _opti = 0 - } else - Optarg = "" - if (_opti == 0 || _opti >= length(argv[Optind])) { - Optind++ - _opti = 0 - } else - _opti++ - return thisopt -} -BEGIN { - Opterr = 1 # default is to diagnose - Optind = 1 # skip ARGV[0] - - # test program - if (_getopt_test) { - while ((_go_c = getopt(ARGC, ARGV, "ab:cd")) != -1) - printf("c = <%c>, optarg = <%s>\n", - _go_c, Optarg) - printf("non-option arguments:\n") - for (; Optind < ARGC; Optind++) - printf("\tARGV[%d] = <%s>\n", - Optind, ARGV[Optind]) - } -} |
