From cad9c7b7552dabd8248a903fa699d4764cb05723 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 27 Feb 2010 17:31:54 +0000 Subject: new package lua-alt-getopt 0.7.0 (26feb10) git-svn-id: svn://tug.org/texlive/trunk@17228 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/support/lua-alt-getopt/ChangeLog | 60 ++++++++ .../texmf-dist/doc/support/lua-alt-getopt/Makefile | 31 ++++ Master/texmf-dist/doc/support/lua-alt-getopt/NEWS | 23 +++ .../texmf-dist/doc/support/lua-alt-getopt/README | 36 +++++ .../doc/support/lua-alt-getopt/alt_getopt | 34 +++++ .../doc/support/lua-alt-getopt/tests/test.out | 130 ++++++++++++++++ .../doc/support/lua-alt-getopt/tests/test.sh | 48 ++++++ .../scripts/lua-alt-getopt/alt_getopt.lua | 166 +++++++++++++++++++++ 8 files changed, 528 insertions(+) create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/ChangeLog create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/Makefile create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/NEWS create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/README create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/alt_getopt create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.out create mode 100644 Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.sh create mode 100755 Master/texmf-dist/scripts/lua-alt-getopt/alt_getopt.lua (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/ChangeLog b/Master/texmf-dist/doc/support/lua-alt-getopt/ChangeLog new file mode 100644 index 00000000000..caf91e665f8 --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/ChangeLog @@ -0,0 +1,60 @@ +2009-10-18 Aleksey Cheusov + + * Makefile, NEWS: + version -> 0.7.0 + Release notes in NEWS + + * alt_getopt.lua, tests/test.out: + Do not use error() for exiting, use os.exit() instead + + * alt_getopt, tests/test.out, tests/test.sh: + Additional regression tests/examples + + * alt_getopt.lua, tests/test.out: + POSIX getopt("xo:") accepts './app -xoVVV' and './app -xo VVV' + treating them as './app -x -o VVV'. Now Lua alt_getopt does the same. + +2009-04-26 Aleksey Cheusov + + * Makefile, NEWS, alt_getopt.lua: + version -> 0.6.0 + NEWS: release notes + s/2008/2009/ + + * alt_getopt.lua: + Minor clean-ups and improvements suggested by Leo P.: + - package.seeall is removed + - gmatch instead of loop + - others + +2009-01-12 Aleksey Cheusov + + * Makefile: + renamed tarball to lua-alt-getopt + version -> 0.5.0 + +2009-01-11 Aleksey Cheusov + + * Makefile: + version -> 0.4.0 + + * alt_getopt.lua, tests/test.out, tests/test.sh: + os.exit --> error + + * README, alt_getopt.lua: + README added + minor code clean-ups + +2009-01-10 Aleksey Cheusov + + * Makefile: PROJECTNAME is set + + * tests/_test.res: + removed + + * Makefile, alt_getopt, alt_getopt.lua, tests/_test.res, tests/test.out, tests/test.sh: + Imported sources + + * Makefile, alt_getopt, alt_getopt.lua, tests/_test.res, tests/test.out, tests/test.sh: + New file. + diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/Makefile b/Master/texmf-dist/doc/support/lua-alt-getopt/Makefile new file mode 100644 index 00000000000..e68b3507363 --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/Makefile @@ -0,0 +1,31 @@ +PREFIX?=/usr/local +LUAVER?=5.1 +LUAMODDIR?=${PREFIX}/lib/lua/${LUAVER} + +################################################## + +VERSION= 0.7.0 +PROJECTNAME= lua-alt-getopt +BIRTHDATE= 2009-01-10 + +FILES= alt_getopt.lua +FILESDIR= ${LUAMODDIR} + +INST_DIR?= ${INSTALL} -d + +################################################## +.PHONY: install-dirs +install-dirs: + $(INST_DIR) ${DESTDIR}${LUAMODDIR} + +.PHONY: test +test: + @echo 'running tests...'; \ + ln -f -s ${.CURDIR}/alt_getopt.lua ${.CURDIR}/tests; \ + export OBJDIR=${.OBJDIR}; \ + if cd ${.CURDIR}/tests && ./test.sh; \ + then echo ' succeeded'; \ + else echo ' failed'; false; \ + fi + +.include diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/NEWS b/Master/texmf-dist/doc/support/lua-alt-getopt/NEWS new file mode 100644 index 00000000000..64195baf227 --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/NEWS @@ -0,0 +1,23 @@ +====================================================================== +Version 0.7.0, by Aleksey Cheusov, Sun, 18 Oct 2009 14:17:28 +0300 + + FIX: POSIX getopt("xo:") accepts './app -xoVVV' and './app -xo VVV' + treating them as './app -x -o VVV'. + Now Lua alt_getopt does the same. + + Additional regression tests/examples + + error() function is not used for exiting anymore. + os.exit() is used instead. + +====================================================================== +Version 0.6.0, by Aleksey Cheusov, Sun, 26 Apr 2009 19:52:38 +0300 + + FIXED: global variable 'optind'. Now it is local. + Minor improvements and code clean-ups. + Thanks to Leo P. for all this. + +====================================================================== +Version 0.5.0, by Aleksey Cheusov + + First publicly available release diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/README b/Master/texmf-dist/doc/support/lua-alt-getopt/README new file mode 100644 index 00000000000..91131baa030 --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/README @@ -0,0 +1,36 @@ +lua_altgetopt is a MIT-licenced module for Lua programming language +for processing application's arguments the same way +BSD/GNU getopt_long(3) functions do. + +Main features and goals: +1) compatibility to SUS "Utility Syntax Guidelines" +http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html#tag_12_02 +guidelines 3-13. +2) This module is for plain Lua +2) No extra dependencies +3) No hooks, no functional tricks ;-) +4) Support for long options, e.g. compatibility with getopt_long(3) C function + present in *BSD and GNU libc. +5) Long options may optionally have one-char synonym or other long synonym +6) Strict error checking (checks for an incorrect use of options) +7) alt_getopt.lua is a Lua module. + +In particular alt_getopt.lua supports the following + -kVALUE, -k VALUE, --key=VALUE, --key VALUE, + -abcd is equivalent to -a -b -c -d if neither of them accept value. +All options must be declared as accepting value or not. + +Two ways of options handling are provided. +See alt_getopt application which is a part of regression tests. + +Makefile: +It's probably useless for end users, you can copy alt_getopt.lua +to the destination yourself. Otherwise use BSD make, +NetBSD make is preferred because NetBSD is my development platform. + +If 'make test' fails on your platform/Lua, please let me know. +If you find a a bug, register it here +http://luaforge.net/project/lua_altgetopt +or send me bugreport directly. + +Author: Aleksey Cheusov diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/alt_getopt b/Master/texmf-dist/doc/support/lua-alt-getopt/alt_getopt new file mode 100644 index 00000000000..4a48bf4206b --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/alt_getopt @@ -0,0 +1,34 @@ +#!/usr/bin/env lua + +require "alt_getopt" + +local long_opts = { + verbose = "v", + help = "h", + fake = 0, + len = 1, + output = "o", + set_value = "S", + ["set-output"] = "o" +} + +local ret +local optarg +local optind +opts,optind,optarg = alt_getopt.get_ordered_opts (arg, "hVvo:n:S:", long_opts) +for i,v in ipairs (opts) do + if optarg [i] then + io.write ("option `" .. v .. "': " .. optarg [i] .. "\n") + else + io.write ("option `" .. v .. "'\n") + end +end + +optarg,optind = alt_getopt.get_opts (arg, "hVvo:n:S:", long_opts) +for k,v in pairs (optarg) do + io.write ("fin-option `" .. k .. "': " .. v .. "\n") +end + +for i = optind,#arg do + io.write (string.format ("ARGV [%s] = %s\n", i, arg [i])) +end diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.out b/Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.out new file mode 100644 index 00000000000..cdd2edb941a --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.out @@ -0,0 +1,130 @@ +================================================================= +======= args: ../alt_getopt -h - +option `h' +fin-option `h': 1 +ARGV [2] = - +================================================================= +======= args: ../alt_getopt --help +option `h' +fin-option `h': 1 +================================================================= +======= args: ../alt_getopt -h --help -v --verbose -V -o 123 -o234 +option `h' +option `h' +option `v' +option `v' +option `V' +option `o': 123 +option `o': 234 +fin-option `V': 1 +fin-option `h': 1 +fin-option `o': 234 +fin-option `v': 1 +================================================================= +======= args: ../alt_getopt --output 123 --output 234 -n 999 -n9999 --len 5 --fake /dev/null +option `o': 123 +option `o': 234 +option `n': 999 +option `n': 9999 +option `len': 5 +option `fake' +fin-option `len': 5 +fin-option `fake': 1 +fin-option `o': 234 +fin-option `n': 9999 +ARGV [11] = /dev/null +================================================================= +======= args: ../alt_getopt -hVv -- -1 -2 -3 +option `h' +option `V' +option `v' +fin-option `h': 1 +fin-option `v': 1 +fin-option `V': 1 +ARGV [3] = -1 +ARGV [4] = -2 +ARGV [5] = -3 +================================================================= +======= args: ../alt_getopt --fake -v -- -1 -2 -3 +option `fake' +option `v' +fin-option `fake': 1 +fin-option `v': 1 +ARGV [4] = -1 +ARGV [5] = -2 +ARGV [6] = -3 +================================================================= +======= args: ../alt_getopt - -1 -2 -3 +ARGV [1] = - +ARGV [2] = -1 +ARGV [3] = -2 +ARGV [4] = -3 +================================================================= +======= args: ../alt_getopt --fake -v - -1 -2 -3 +option `fake' +option `v' +fin-option `fake': 1 +fin-option `v': 1 +ARGV [3] = - +ARGV [4] = -1 +ARGV [5] = -2 +ARGV [6] = -3 +================================================================= +======= args: ../alt_getopt -1 -2 -3 +Unknown option `-1' +================================================================= +======= args: ../alt_getopt -hvV +option `h' +option `v' +option `V' +fin-option `h': 1 +fin-option `V': 1 +fin-option `v': 1 +================================================================= +======= args: ../alt_getopt -ho 123 +option `h' +option `o': 123 +fin-option `o': 123 +fin-option `h': 1 +================================================================= +======= args: ../alt_getopt -hoV 123 +option `h' +option `o': V +fin-option `o': V +fin-option `h': 1 +ARGV [2] = 123 +================================================================= +======= args: ../alt_getopt --unknown +Unknown option `--unknown' +================================================================= +======= args: ../alt_getopt --output=file.out -nNNN --len=LENGTH +option `o': file.out +option `n': NNN +option `len': LENGTH +fin-option `len': LENGTH +fin-option `o': file.out +fin-option `n': NNN +================================================================= +======= args: ../alt_getopt --output --file-- +option `o': --file-- +fin-option `o': --file-- +================================================================= +======= args: ../alt_getopt --output +Missed value for option `--output' +================================================================= +======= args: ../alt_getopt -ho +Missed value for option `-o' +================================================================= +======= args: ../alt_getopt --help -o +Missed value for option `-o' +================================================================= +======= args: ../alt_getopt --help=value +Bad usage of option `--help=value' +================================================================= +======= args: ../alt_getopt -ofile1 --set_value 111 --output file2 --set-output=file3 +option `o': file1 +option `S': 111 +option `o': file2 +option `o': file3 +fin-option `o': file3 +fin-option `S': 111 diff --git a/Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.sh b/Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.sh new file mode 100644 index 00000000000..8487a8e7e45 --- /dev/null +++ b/Master/texmf-dist/doc/support/lua-alt-getopt/tests/test.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +runtest (){ + printf '=================================================================\n' + printf '======= args: %s\n' "$*" + "$@" 2>&1 | awk '/stack traceback:/, /\[C\]: [?]/ {next} {print}' +} + +do_test_getopt (){ + runtest ../alt_getopt -h - + runtest ../alt_getopt --help + runtest ../alt_getopt -h --help -v --verbose -V -o 123 -o234 + runtest ../alt_getopt --output 123 --output 234 -n 999 -n9999 --len 5 --fake /dev/null + runtest ../alt_getopt -hVv -- -1 -2 -3 + runtest ../alt_getopt --fake -v -- -1 -2 -3 + runtest ../alt_getopt - -1 -2 -3 + runtest ../alt_getopt --fake -v - -1 -2 -3 + runtest ../alt_getopt -1 -2 -3 + runtest ../alt_getopt -hvV + runtest ../alt_getopt -ho 123 + runtest ../alt_getopt -hoV 123 + runtest ../alt_getopt --unknown + runtest ../alt_getopt --output='file.out' -nNNN --len=LENGTH + runtest ../alt_getopt --output --file-- + + runtest ../alt_getopt --output + runtest ../alt_getopt -ho + runtest ../alt_getopt --help -o + runtest ../alt_getopt --help=value + runtest ../alt_getopt -ofile1 --set_value 111 --output file2 \ + --set-output=file3 + + true +} + +do_test (){ + do_test_getopt +} + +OBJDIR=${OBJDIR:=.} + +do_test > $OBJDIR/_test.res 2>&1 + +if ! diff -u test.out $OBJDIR/_test.res; then + echo "rewrite fails" 1>&2 + exit 1 +fi + diff --git a/Master/texmf-dist/scripts/lua-alt-getopt/alt_getopt.lua b/Master/texmf-dist/scripts/lua-alt-getopt/alt_getopt.lua new file mode 100755 index 00000000000..7a6591a49a7 --- /dev/null +++ b/Master/texmf-dist/scripts/lua-alt-getopt/alt_getopt.lua @@ -0,0 +1,166 @@ +-- Copyright (c) 2009 Aleksey Cheusov +-- +-- Permission is hereby granted, free of charge, to any person obtaining +-- a copy of this software and associated documentation files (the +-- "Software"), to deal in the Software without restriction, including +-- without limitation the rights to use, copy, modify, merge, publish, +-- distribute, sublicense, and/or sell copies of the Software, and to +-- permit persons to whom the Software is furnished to do so, subject to +-- the following conditions: +-- +-- The above copyright notice and this permission notice shall be +-- included in all copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +-- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +-- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +-- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +local type, pairs, ipairs, io, os = type, pairs, ipairs, io, os + +module ("alt_getopt") + +local function convert_short2long (opts) + local i = 1 + local len = #opts + local ret = {} + + for short_opt, accept_arg in opts:gmatch("(%w)(:?)") do + ret[short_opt]=#accept_arg + end + + return ret +end + +local function exit_with_error (msg, exit_status) + io.stderr:write (msg) + os.exit (exit_status) +end + +local function err_unknown_opt (opt) + exit_with_error ("Unknown option `-" .. + (#opt > 1 and "-" or "") .. opt .. "'\n", 1) +end + +local function canonize (options, opt) + if not options [opt] then + err_unknown_opt (opt) + end + + while type (options [opt]) == "string" do + opt = options [opt] + + if not options [opt] then + err_unknown_opt (opt) + end + end + + return opt +end + +function get_ordered_opts (arg, sh_opts, long_opts) + local i = 1 + local count = 1 + local opts = {} + local optarg = {} + + local options = convert_short2long (sh_opts) + for k,v in pairs (long_opts) do + options [k] = v + end + + while i <= #arg do + local a = arg [i] + + if a == "--" then + i = i + 1 + break + + elseif a == "-" then + break + + elseif a:sub (1, 2) == "--" then + local pos = a:find ("=", 1, true) + + if pos then + local opt = a:sub (3, pos-1) + + opt = canonize (options, opt) + + if options [opt] == 0 then + exit_with_error ("Bad usage of option `" .. a .. "'\n", 1) + end + + optarg [count] = a:sub (pos+1) + opts [count] = opt + else + local opt = a:sub (3) + + opt = canonize (options, opt) + + if options [opt] == 0 then + opts [count] = opt + else + if i == #arg then + exit_with_error ("Missed value for option `" .. a .. "'\n", 1) + end + + optarg [count] = arg [i+1] + opts [count] = opt + i = i + 1 + end + end + count = count + 1 + + elseif a:sub (1, 1) == "-" then + local j + for j=2,a:len () do + local opt = canonize (options, a:sub (j, j)) + + if options [opt] == 0 then + opts [count] = opt + count = count + 1 + elseif a:len () == j then + if i == #arg then + exit_with_error ("Missed value for option `-" .. opt .. "'\n", 1) + end + + optarg [count] = arg [i+1] + opts [count] = opt + i = i + 1 + count = count + 1 + break + else + optarg [count] = a:sub (j+1) + opts [count] = opt + count = count + 1 + break + end + end + else + break + end + + i = i + 1 + end + + return opts,i,optarg +end + +function get_opts (arg, sh_opts, long_opts) + local ret = {} + + local opts,optind,optarg = get_ordered_opts (arg, sh_opts, long_opts) + for i,v in ipairs (opts) do + if optarg [i] then + ret [v] = optarg [i] + else + ret [v] = 1 + end + end + + return ret,optind +end -- cgit v1.2.3