Version 1.2.2 2006/04/13
Download
Change log
Simple example
Full example

Aargh

Automated Argument Helper

Summary

Aargh generates C or C++ code to parse a command line, using the getopt() facility available in UNIX and UNIX-like environments. It supports command-line options with integer arguments, string arguments, and no arguments. The generated code is commented and carefully indented for readability. Aargh is written in C++ and licensed under the GNU General Public License (GPL).

Synopsis

aargh [-l language] [-v] [-x ext] [-X hdr_ext] [filename]
The -l option (that's a lower case L) specifies the language to be generated. Aargh currently supports "C" and "C++". If you don't specify a language, aargh defaults to C++.

The -v option requests verbose mode, in which aargh writes a serious of informational messages to standard output.

The -x option specifies the file name extension to be applied to the generated source code file, if not specified in the XML input file. If not specified in the XML input file nor on the aargh command line, the file name extension defaults to "c" for C and "C" for C++.

The -X option is similar to the -x option, except that it applies to the file name of the generated header. The file name extension for the header defaults to "h" if not otherwise specified.

The filename argument specifies an XML file defining the options that you want your program to support. If you don't specify an input file, aargh reads standard input.

Introduction

It's nice to have lots of command line options, but it's a real pain to code for them.

Not that it's difficult. It's just tedious, time-consuming, error prone, and no fun. I used to wince at the thought of adding command line options.

Not any more. All I have to do is define the options I want in a small XML file and run it through aargh. Instantly I have C or C++ source code that I can compile and link into my program. If I want to add another option or otherwise change the rules, I can edit the XML and regenerate the code. Now I can spend more time on the interesting parts of the project.

You can download aargh in the form of C++ source code and compile it yourself. It is licensed under the GNU General Public License (GPL).

Using Aargh

To use aargh, write an XML file to describe the options you want. Aargh reads the file and generates two source files.

One file is a header that declares a C struct or a C++ class to represent the options. By default this struct or class is named "Opts," but you can specify a different name. The other file is the implementation of Opts (or whatever you decide to call it), providing a function to parse the command line. For C, the results are available as members of the struct. For C++, member functions perform the parsing and make the results available.

In your own code, declare an instance of Opts and call the parsing function, passing it the argc and argv arguments from main(). The parsing function returns zero if the command line follows the rules that you have outlined in the XML file, or non-zero otherwise. If the parsing is successful, the Opts object stores the results.

This process is easier to visualize with a simple example. A full example demonstrates all the available features in greater detail.

What You Can and Can't Do With Aargh

Aargh can generate code to do most of what you ever need to do with a command line: If necessary, you can accept long double-hyphen options such as "--print". However aargh doesn't really work very well for this kind of option. You have to define a hyphen as the option letter, and treat the rest, such as "print", as the argument of the option. As a result, such an option cannot take an argument, because the generated code treats the option name as the argument of the hyphen option.

There are other situations that aargh can't handle:

Aargh is a simple tool for simple needs. You can use it to produce usable code in a hurry. If you need to do something fancier than what aargh will do for you, then you have several options:

Licensing

Aargh is licensed under the GNU General Public License, version 2, a copy of which is included in the distribution.

This license does not extend to the code generated by aargh, which belongs to whoever generates it. I claim no rights to the code you generate. You can license it under whatever terms you choose, or not license it at all.

Acknowledgements

Aargh uses the Tinyxml library to read the XML file. Thanks to Lee Thomason for TinyXml.


MailScott McKellar