basename.go: Improve readability

Instead of having one giant glob of code in main, I have split the code into simple functions.