the end of the template for nopt should look like this:

if (argc - noptind != 0) {
	printf("%% %s", nopterr);
	if (argv[noptind])
		printf(": %s", argv[noptind]);
	printf("\n");
	myusage();
	return(0);
}

as this was obviously wrong:

argc -= noptind;
argv += noptind;
...
if (argv[noptind]) {
...