Copy from: http://www.cs.princeton.edu/~rs/strings/tstdemo.c.