Added history expansion

See issue #7 .
`buf` can be NULL here (when the user types ^D == EOF) and then a segmentation fault occurs
 --> fix: move the `if (buf != NULL && *buf) {` condition upwards