Exemplo n.º 1
0
int	secs_script_parse(const char *line) {
	char	*strbuf = NULL, *str = NULL;
	size_t	slen = 0;

	if ((line == NULL) || ((slen = strlen(line)) == 0))
		return(0);
	strbuf = secs_mem_alloc(slen+2);
	if (strbuf == NULL)
		return(0);
	strncpy(strbuf, line, slen+2);
	while ((str = strchr(strbuf, '\n')) != NULL)
		*str = ' ';
	while ((str = strrchr(strbuf, ';')) != NULL)
		*str = 0;
	str = strbuf;
	while ((str != NULL) && (*str != 0)) {
		char	*workstr = str,
			*word = NULL;

		str += strlen(str)+1;	// firstwhite() munges str, so we
					// have to do this before processing
		if (*workstr == '/') {
			while ((word = strchr(workstr, '\001')) != NULL)
				*word = ';';
			secs_handle(secs_script_expand(NULL, workstr+1));
			continue;
		}
		word = atom(workstr);
		workstr = firstwhite(workstr);
		if (strcasecmp(word, "ECHO") == 0)
			set_echof("%s\n", secs_script_expand(NULL, workstr));
		else if (strcasecmp(word, "SET") == 0) {
			word = atom(workstr);
			workstr = firstwhite(workstr);
			secs_setvar(word, workstr);
		} else if (strcasecmp(word, "IF") == 0) {
			if (*workstr == '(') {
				workstr++;
				if (secs_script_eval(&workstr) != 0)
					secs_script_parse(workstr);
			} else
				set_echof("secs_script_parse: You need to"
					" include parenthesis around"
					" control blocks for if (%s)\n",
					workstr);
		}
	}
	secs_mem_free(strbuf);
	return(1);
}
Exemplo n.º 2
0
int	script_parse(const char *script, const char *_arg) {
	char	*arg = NULL;
	int	a, b;

	if (script == NULL)
		return(0);

	if (_arg != NULL)
		_arg = arg = strdup(_arg);
	for (a = 0; (a < 50) && (arg != NULL); a++) {
		char	buf[1024], *tmp;

		tmp = atom(arg);
		snprintf(buf, sizeof(buf), "args%i*", a+1);
		secs_setvar(buf, tmp);
		arg = firstwhite(arg);
		snprintf(buf, sizeof(buf), "arg%i", a+1);
		secs_setvar(buf, tmp);
        }
	for (b = a; b < 50; b++) {
		char	buf[1024];

		snprintf(buf, sizeof(buf), "args%i*", b+1);
		secs_setvar(buf, "");
		snprintf(buf, sizeof(buf), "arg%i", b+1);
		secs_setvar(buf, "");
	}

	secs_script_parse(script);

	while (a > 0) {
		char	buf[1024];

		snprintf(buf, sizeof(buf), "arg%i", a);
		secs_setvar(buf, "");
		snprintf(buf, sizeof(buf), "args%i*", a);
		secs_setvar(buf, "");
		a--;
	}

	if (_arg != NULL)
		free((void *)_arg);
	return(1);
}
Exemplo n.º 3
0
static struct rpcent *interpret(register struct rpcdata *d)
{
	char *p;
	register char *cp, **q;

	p = d->line;
	d->line[strlen(p)-1] = '\n';
	if (*p == '#')
		return __get_next_rpcent(d);
	cp = strchr(p, '#');
	if (cp == NULL) {
		cp = strchr(p, '\n');
		if (cp == NULL)
			return __get_next_rpcent(d);
	}
	*cp = '\0';
#ifdef __linux__
	if ((cp = firstwhite(p)))
		*cp++ = 0;
	else
		return __get_next_rpcent(d);
#else
	cp = strchr(p, ' ');
	if (cp == NULL) {
		cp = strchr(p, '\t');
		if (cp == NULL)
			return __get_next_rpcent(d);
	}
	*cp++ = '\0';
#endif
	/* THIS STUFF IS INTERNET SPECIFIC */
	d->rpc.r_name = d->line;
	while (*cp == ' ' || *cp == '\t')
		cp++;
	d->rpc.r_number = atoi(cp);
	q = d->rpc.r_aliases = d->rpc_aliases;
#ifdef __linux__
	if ((cp = firstwhite(cp)))
		*cp++ = '\0';
#else
	cp = strchr(p, ' ');
	if (cp != NULL)
		*cp++ = '\0';
	else {
		cp = strchr(p, '\t');
		if (cp != NULL)
			*cp++ = '\0';
	}
#endif
	while (cp && *cp) {
		if (*cp == ' ' || *cp == '\t') {
			cp++;
			continue;
		}
		if (q < &(d->rpc_aliases[MAXALIASES - 1]))
			*q++ = cp;
#ifdef __linux__
		if ((cp = firstwhite(cp)))
			*cp++ = '\0';
#else
		cp = strchr(p, ' ');
		if (cp != NULL)
			*cp++ = '\0';
		else {
			cp = strchr(p, '\t');
			if (cp != NULL)
				*cp++ = '\0';
		}
#endif
	}
	*q = NULL;
	return &d->rpc;
}