Fixed unsafe code in bin/print

Changes in this pull request:
- pulled apart functions from main so they can be unit tested
- added unit tests for two functions: `next_index` and `matrix_index`
- changed functions to check input and throw exception if the input is malformed

The added tests are in `src/test/command/print_test.cpp`.