view rvinterf/asyncshell/parse.c @ 995:74024eb17e04

fc-loadtool help: improve language regarding 16 MiB flash chips In FC project history, 16 MiB flash originally meant Pirelli DP-L10. Then we got FCDEV3B with the same flash (our own design), but now we are discovering more Calypso devices that used such large flash, both late Calypso era (Sony Ericsson K2x0) as well as much earlier ones (FIC FLUID devices.txt file with 2004 dates, Leonardo+ rev 5). Hence we need to migrate to more generic or neutral language in associated documentation, without giving elevated status to specific examples that drove our early project history.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 21:11:12 +0000
parents e7502631a0f9
children
line wrap: on
line source

/*
 * This module implements the parser helper function that allows
 * the same code to be reused between interactive and one-shot
 * versions of the same command.
 */

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>

parse_interactive_command_into_argv(argstr, argv, min_arg, max_arg, argcp)
	char *argstr, **argv;
	int min_arg, max_arg, *argcp;
{
	char *cp, **ap;

	cp = argstr;
	for (ap = argv; ; ) {
		while (isspace(*cp))
			cp++;
		if (!*cp || *cp == '#')
			break;
		if (ap - argv >= max_arg) {
			printf("error: too many arguments\n");
			return(-1);
		}
		if (*cp == '"') {
			*ap++ = ++cp;
			while (*cp && *cp != '"')
				cp++;
			if (*cp != '"') {
				printf("error: unterminated quoted string\n");
				return(-1);
			}
			*cp++ = '\0';
		} else {
			*ap++ = cp;
			while (*cp && !isspace(*cp))
				cp++;
			if (*cp)
				*cp++ = '\0';
		}
	}
	if (ap - argv < min_arg) {
		printf("error: too few arguments\n");
		return(-1);
	}
	*ap = 0;
	*argcp = ap - argv;
	return(0);
}