Kate’s Programming Snippets

Some fragments of programs. Some of these I use as a sort of template to modify, which I keep around to remind me how I did something.

comment.c An example of identifying partial lines with fgets().
xstrrep.c In response to the stock reply it takes five minutes to write your own. It took me the best part of a day.
substr.c Substrings using either absolute offsets, or a start and a length. Negative ranges are permitted.
trim.c trimming whitespace.
lcm.c The LCM and GCD of two numbers.
log.c Things related to logarithms. These are the sorts of things I am bad at getting right.
bits.c Dealing with bits, which I am also bad at getting right.
temp.sql Support routines for creating temporary tables in PL/pgSQL, with their OID being cached.
sprintf.sql A minimal sprintf() for PL/pgSQL.
xmalloc.c xmalloc() and friends.
dburi.c Database URI parsing for libdbi, written in C99. This provides a URI scheme similar to Trac's Database Connection Strings. Its unit tests are separate.
regrep.c Substitute arrays of regmatch_t matches into a formatting string.
signal.c Fork a child and catch signals sent from the child to its parent.
tok.c Various forms of push-driven tokenisation.
csv.c CSV parsing as per RFC 4180. Here's the FSM as a diagram. Some states are duplicated in the code for ease of output; the grammar is equivalent.
css.js Javascript DOM manipulation for CSS classes in XHTML.
events.js Javascript DOM event manipulation.
urlalloc.c A particularly brutal implementation of URL parsing.
unescape.c Resolving C-style escape sequences for strings.
args.c Argument parsing to produce argv[]. I found this difficult to do neatly.

And some fragments of things:

Bit Twiddling My collection of little bit-related things, which I can never figure out very easily on the spot.

$Id: index.xhtml 551 2010-12-02 18:13:00Z kate $