Refactor tsh for readability

Complete rewrite of the input reading and parsing code in the 'tsh'
shell.  For the most part the behaviour is the same.  One exception is
that the '&' character must occur at the end of input and be preceded by
whitespace, otherwise it will be treated as a program argument.