Home   Introduction   Advanced   Man Page   Examples  


The Argtable Homepage

Argtable is an ANSI C command line parser.

Stewart Heitmann
sheitmann@users.sourceforge.net

Overview

Argtable is an ANSI C library for parsing GNU style command line options with a minimum of fuss. It enables a program's command line syntax to be defined in the source code as an array of argtable structs. The command line is then parsed according to that specification and the resulting values are returned in those same structs where they are accessible to the main program. Both tagged (-v, --verbose, --foo=bar) and untagged arguments are supported, as are multiple instances of each argument. Syntax error handling is automatic and the library also provides the means for generating a textual description of the command line syntax, as in the following example:

myprog [-lRv] [-k <int>] [-D MACRO]... [-o <output>] [--help] [--version] <file> [<file>]...

-l, -L

list files

-R

recurse through subdirectories

-k, --scalar=<int>

define scalar value k (default is 3)

-D, --define=MACRO

macro definitions

-o <output>

output file (default is "-")

-v, --verbose, --debug

verbose messages

--help

print this help and exit

--version

print version information and exit

<file>

input file(s)

The argtable parsing, validation, and error reporting routines may be replaced by user-defined callbacks if desired and new argtable data types may be created to parse user-defined argument types. The parsing itself is done using GNU getopt so the parser is 100% GNU compatible. Care has also been taken to make the internal command line buffer handling secure against buffer overun attacks, as might be attempted with maliciously long command lines.

It runs on Linux, FreeBSD, NetBSD, OpenBSD, Cygwin, Sun Solaris, IBM AIX, SGI IRIX, Apple Mac OS X and Microsoft Windows platforms. It is known to compile with GCC, DJGPP, Visual C++, Open Watcom, MinGW, Texas Instruments DSP Compiler and should compile with any standard ANSI C compiler.

Argtable is open-source software that is distributed under the terms of the GNU Library General Public License (LGPL). It is available from NetBSD ports (devel/argtable), FreeBSD ports (devel/argtable), OpenBSD ports (devel/argtable), MacPorts (devel/argtable), Mac OS X FinkProject (libargtable2-shlibs), Gentoo Linux (dev-libs/argtable), Debian Linux (libdevel/libargtable2-dev), Ubuntu Linux (libdevel/libargtable2-dev), and Sunfreeware www.sunfreeware.com. Precompiled Dev-C++ devpaks are available from http://devpaks.org.
Also check below for the latest version.


Documentation

"Introduction to Argtable-2.x" (html) (postscript) (pdf) (italiano)

A tutorial-style introduction to command line parsing using argtable-2.x.

"Advanced Argtable-2.x Topics" (html) (postscript) (pdf)

A collection of topics on advanced argtable-2.x parsing techniques.

"The Argtable-2.x Man Page" (html) (postscript) (pdf)

The argtable-2.x programmer's reference manual.

"Argtable Example Code" (html).

Source code examples showing how to parse the command line of a selection of common GNU utilities (echo, ls, mv, rm, uname) plus some generic examples demonstrating basic argtable features.


Downloads

Version 2.13 (ChangeLog), released Jan 10, 2011

This release includes improved parsing of filepaths and filenames and adds support for the CMake tool.

argtable2-13.tar.gz (source code, 3.2MB)

Version 1.4 (DEPRECATED 2003)

The argtable 1.x series has been long deprecated, but is still provided for backward compatibility as the argtable 2.x series does not support legacy code using the argtable 1.x series library. Both argtable 1.x and 2.x series libraries will happily coexist on the same system, so you may install them together if you wish. New users will not need this version at all.

argtable-1.4.tar.gz (source code, 442KB)

Rpm packages and previous releases are also available on the Sourceforge argtable downloads site.


History

Argtable debuted on sunsite.unc.edu in November 1998 and was relocated to sourceforge.net in December 2001. The argtable-1.x series was replaced by the argtable-2.x series in October 2003.


Thanks to

Nina Clemson for editing the original argtable-1.0 documentation.
Livio Bertacco for contributing bug fixes and the argtable-2.x Visual C++ Makefiles.
Justin Dearing for contributing bug fixes and Windows DLL support, plus code support for the Open Watcom compiler and help with the Mac OS X configuration.
Asa Packer for contributing bug fixes and upgrades to the Visual C++ Makefiles.
Danilo Cicerone for the Italian translation of "Introduction to Argtable-2x" and the argtable devpak.
Uli Fouquet for configuration patches and documentation related to cross-compiling argtable from Unix to Windows as well as providing the arg_print_glossary_gnu function.
Shachar Schemesh for integrating argtable into Debian Linux and kick-starting the migration to automake/autoconf.
Jasper Lievisse Adriaanse for maintaining the argtable package in OpenBSD ports.
Ulrich Mohr for bug fixes relating to Texas Instrument DSP platforms.
John Vickers and Steve O'Neil for bug fixes relating to Solaris/Motorola platforms.
Lori A. Pritchett-Sheats for fixing a makefile bug relating to "make dist".
Paolo Bormida for instructions on building argtable with date and regex support on Windows.
Michel Valin for bug fixes relating to the configure scripts on IBM AIX platforms and instructions on compiling the example code under AIX.
Steve Christensen for providing prebuilt packages for SPARC/Solaris and x86/Solaris platforms on www.sunfreeware.com.
Jess Portnoy for reworking the rpm package and integrating argtable into Fedora Linux.
Michael Brown for incorporating support for pkg-config into the autoconf scripts.
Alexander Lindert for extensions to the parser to support hex, octal and binary integer formats as well as KB/MB/GB suffixes.
Rob Zaborowski for providing build configuration files for the CMake tool.
Moczik Gabor for bug fixes relating to the parsing of filepaths and filename extensions.
Hanspeter Niederstrasser for including the argtable package in FinkProject for Mac OS X.


SourceForge Logo