Project: hexed

Well the current project is hexed, a command line HEXadecimal file EDitor. The first update is a simple test for cmdargs, a command line argument parser. Cmdargs is released as public domain software so you can use it in other projects without restrictions. Cmdargs can handle both long and short arguments with options. For long arguments cmdargs can accept either ‘‐’ or ‘‐‐’ as the argument switch. Any short arguments that don’t require an option can be set in the same switch (-a -b -c  or -abc). Options can be set either by ‘:’, ‘=’ or with whitespace as in (-e:10 -b=100 -f filename). The accepted arguments are passed as a single struct array called Arglist with longer args listed before shorter ones in alphabetical order.

Arglist arglist[] = {
{"bar", 0},       // set the bar arg
{"b", 0},         // set the b arg
{"foobar", 0},    // set the foobar arg
{"foo", 0},       // set the foo arg
{"f", 0},         // set the f arg
{NULL, 0}         // must be the last entry

This struct and argv from main() are sent to parsecmdargs() in a loop until the end of the arguments are reached. parsecmdargs() returns a Cmdargs struct with the argument string, an options string, the arg ID, and some flags about the current arg. The source code is documented more in the comments for cmdargs.c

I also spent the last few days learning a bit about make and svn. Between them I’ve created a simple way to get the revision number for exported versions or on machines that don’t have svnversion installed. It uses bash to update a version make file when the working copy and the file $Rev$ revision numbers are different. This means that the version makefile is updated on every commit but it’s only for a single comment with the updated time and date at the top of the file.


Source: cmdargs.hcmdargs.c

Leave a Reply

Your email address will not be published. Required fields are marked *