use nitems
An incremental improvement to the current argument parsing.
Welcome nopt, a simple table based argument parser using genget.

usage template for when no additional arguments are desired:

static struct nopts authopts[] = {
   { "ac",         req_arg,        'a' },
   { "dev",        req_arg,        'd' },
   { "svc",        req_arg,        's' },
   { NULL,         0,              0 }
};

/* parse */
noptind = 0;
while ((ch = nopt(argc, argv, authopts)) != -1)
	switch (ch) {
	case 'a':       /* ac */
		strlcpy(dst, argv[noptind - 1], sizeof(dst));
...
		break;
	case 'd':       /* dev */
...
		break;
	case 's':       /* svc */
...
		break;
	default:
		printf("%% nopt table error\n");
		return(0);
	}
	argc -= noptind;
	argv += noptind;

        if (argc != 0) {
                /* leftover salmon */
                printf("%% %s", nopterr);
                if (argv[noptind])
                        printf(": %s", argv[noptind]);
                printf("\n");
                usage();
                return(0);
        }
initial sppp, pppoe implementation
(this is a good example using nopt)
we may need to store the sppp secret in a database,
the kernel does not seem to want to give it up...
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]) {
...
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]) {
...
Merge branch 'master' of github.com:yellowman/nsh
Merge pull request #2 from yellowman/master

Update from main trunk