Only trim input in main
Fixes #28, Handle errors for closedir and getcwd.

strdup error checks was added in 7698b5a
Handle SPHIA_DB_FOREACH errors.
Add comments explaining types, functions, macros etc.
Single function for removing directories paths, excluding a list of
extensions.