[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: WANTED: POSIX compatible getopt
- From: David Given <dg@...>
- Date: Fri, 09 Jan 2009 16:08:39 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Aleksey Cheusov wrote:
[...]
> Most applications written in C use system getopt(3) or getopt_long(3)
> and therefore follow these guidelines. These guidelines show how
> applications usually work, not only standardized `cat', `cut', `grep'
> etc. and I think apps written in Lua shell follow these rules too
> _by default_ just like all C application. Unfortunately I don't see
> such module for Lua.
I have most of a long-options-processor written in pure Lua that I use
in most of my applications. It doesn't do -- and it takes a few
shortcuts, but it handles long options, short options, "-x VALUE",
"-xVALUE", and "--x VALUE", and non-option arguments, and is probably
about 100 lines of code. It's not a standalone module but could be
easily made so, and is BSD licensed. If you want it, look at line 129
onwards of:
http://wordgrinder.svn.sourceforge.net/viewvc/wordgrinder/wordgrinder-0.3.2/src/lua/main.lua?revision=147&view=markup
The do_() functions are called to process an argument, and return the
number of arguments consumed (0 or 1). argmap contains the mapping of
option names to functions. Non-option arguments are handled at the
bottom of the main loop. It's all quite crude, but should be easy to
modify to meet your requirements.
Also, happy Hogmanay.
- --
David Given
dg@cowlark.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFJZ3aCf9E0noFvlzgRAhytAJ0cOezY0VE0sMxYUmh3YoRRlUekHwCeP+3w
qN4SgGQiaDuXQT+2bO5BuTA=
=v/Z/
-----END PGP SIGNATURE-----
- References:
- WANTED: POSIX compatible getopt, Aleksey Cheusov
- Re: WANTED: POSIX compatible getopt, Javier Guerra
- Re: WANTED: POSIX compatible getopt, Aleksey Cheusov
- Re: WANTED: POSIX compatible getopt, Rob Kendrick
- Re: WANTED: POSIX compatible getopt, Aleksey Cheusov
- Re: WANTED: POSIX compatible getopt, Rob Kendrick
- Re: WANTED: POSIX compatible getopt, Aleksey Cheusov
- Re: WANTED: POSIX compatible getopt, Rob Kendrick
- Re: WANTED: POSIX compatible getopt, Aleksey Cheusov
- Re: WANTED: POSIX compatible getopt, Rob Kendrick
- Re: WANTED: POSIX compatible getopt, Aleksey Cheusov