Usage messages

Updated: April 19, 2023

QNX Neutrino lets an executable have a built-in usage message, a short reminder of the command-line options and some notes on what the executable does.

You can try this out right now at a command-line—type use cat to get information about the cat command. You'll see the following:

cat - concatenate and print files (POSIX)

cat [-cu] [file...]
Options:
 -c      Compress, do not display empty lines.
 -u      Unbuffered, for interactive use.
 -n      Print line numbers without restarting.
 -r      Print line numbers restarting count for each file.

You can add these messages into your own executables. My standard mkmain script generates the Makefile and main.use files required for this.

Note: If a usage message that's embedded in main.c has a line containing an odd number of single-quote characters ('), the compiler gives you grief, even though the offending line is walled-off in an #ifdef __USAGE section. The solution is to move the usage message out of main.c and into a separate file (usually main.use). To maintain the usage message within the C code, you can get around this by putting the usage message—including the #ifdef directive—in comments:
/*
#ifdef __USAGE
%C A utility that's using a single quote
#endif
*/

It's an ANSI C compiler thing. :-)