Richard Stevens' sock program, based on http://www.icir.org/christian/sock.html