(Relatively) Painless Command Line Parsing With C

A pet peeve of mine has always been parsing command line arguments – I find it boring and painful. While tools like getopt offer some degree of help, they don’t offer much of a paradigm shift. I figured it should be possible to abuse the C pre-processor to have it convert a benign list of command line arguments and their type into real parsing code. Since I could not find something similar that already existed; and had a free afternoon; I wrote this: https://github.com/sanjoy/CmdArgs.

The README file with the (rather non-rigorous) test code should be enough to get you started. This is not a typical library (since it uses the pre-processor so heavily) – you cannot compile it to, say, libcmdrargs.so and dynamically link to it. You will always need to include the source in your project.

I have not focused much on code-efficiency; granted that you parse the command line arguments only once, this should not be much of a problem. Bugs, suggestions and flames welcome.

This entry was posted in Rest. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s