Patch by Aidil, makes m_getopt a bit smarter in handling repeated options and
and fixes some small bugs.