Copy of r342 from http://svn.code.sf.net/p/jsqsh/code/trunk/