Replace getopt with manual argument parsing

This was done beacuse getopt is not cross-platform.