Thursday, December 09, 2004

gengetopt

http://www.gnu.org/software/gengetopt/gengetopt.html
If an option is given multiple times

If an option is specified as multiple, then it can be specified multiple times at command line. In this case, say the option is called foo, the generated foo_given field in the args structure contains the number of times it was specified and the generated field foo_arg is an array containing all the values that were specified for this option.

Notice that if a default value is specified for a multiple option, that value is assigned to the option only if no other value is specified on the command line (and the corresponding _given field will be set to 1), i.e., a default value IS NOT always part of the values of a multiple option.

for (i = 0; i < args_info.string_given; ++i)

printf ("passed string: %s\n", args_info.string_arg[i]);


Sunday, December 05, 2004

C++

http://www.stanford.edu/class/cs106b/winterhandouts/H06%20C++%20streams.pdf

fs.open(filename.c_str());

The above line attempts to open the file with the given filename (searching in the current directory). Note that open member function takes in a char* argument and not a C++-style string, so you must use c_str to convert it. (Sigh, this is just a weird artifact of the stream libraries being completed before the string library). Opening the file may or may not succeed (depending on whether the named file exists, what permissions it has, etc.), so before you proceed, you should check the state of the stream.

if (fs.fail()) return;

The call to fail checks if the state of the stream is unhappy, in this case, it will determine if the file was properly opened. This is essential before we start trying to output to the stream (in the same way that we check if a FILE* is NULL in C).

Thursday, December 02, 2004

Emacs

a few emacs shortcuts

M-/ autocompletion. It's based on the tokens in the currently open buffers.

ESC-u change a word into uppercase
ESC-c capitalise a word
C-x C-u upcase region