Esempio n. 1
0
FICL_PLATFORM_EXTERN ficlCell    stackFetch    (ficlStack *stack, int n) { return ficlStackFetch(stack, n); }
Esempio n. 2
0
FICL_PLATFORM_EXTERN ficlCell    stackGetTop   (ficlStack *stack) { return ficlStackFetch(stack, 0); }
Esempio n. 3
0
/*
 * Shim for taking commands from BF and passing them out to 'standard'
 * argv/argc command functions.
 */
static void
bf_command(ficlVm *vm)
{
	char			*name, *line, *tail, *cp;
	size_t			len;
	struct bootblk_command	**cmdp;
	bootblk_cmd_t		*cmd;
	int			nstrings, i;
	int			argc, result;
	char			**argv;

	/* Get the name of the current word */
	name = vm->runningWord->name;

	/* Find our command structure */
	cmd = NULL;
	SET_FOREACH(cmdp, Xcommand_set) {
		if (((*cmdp)->c_name != NULL) &&
		    strcmp(name, (*cmdp)->c_name) == 0)
			cmd = (*cmdp)->c_fn;
	}
	if (cmd == NULL)
		panic("callout for unknown command '%s'", name);

	/* Check whether we have been compiled or are being interpreted */
	if (ficlStackPopInteger(ficlVmGetDataStack(vm))) {
		/*
		 * Get parameters from stack, in the format:
		 * an un ... a2 u2 a1 u1 n --
		 * Where n is the number of strings, a/u are pairs of
		 * address/size for strings, and they will be concatenated
		 * in LIFO order.
		 */
		nstrings = ficlStackPopInteger(ficlVmGetDataStack(vm));
		for (i = 0, len = 0; i < nstrings; i++) {
			ficlStack *stack = ficlVmGetDataStack(vm);
			len += ficlStackFetch(stack, i * 2).i + 1;
		}
		line = malloc(strlen(name) + len + 1);
		strcpy(line, name);

		if (nstrings)
			for (i = 0; i < nstrings; i++) {
				ficlStack *stack = ficlVmGetDataStack(vm);

				len = ficlStackPopInteger(stack);
				cp = ficlStackPopPointer(stack);
				strcat(line, " ");
				strncat(line, cp, len);
			}
	} else {
		/* Get remainder of invocation */
		tail = ficlVmGetInBuf(vm);

		len = 0;
		cp = tail;
		for (; cp != vm->tib.end && *cp != 0 && *cp != '\n'; cp++)
			len++;

		line = malloc(strlen(name) + len + 2);
		strcpy(line, name);
		if (len > 0) {
			strcat(line, " ");
			strncat(line, tail, len);
			ficlVmUpdateTib(vm, tail + len);
		}
	}
	DPRINTF("cmd '%s'", line);

	command_errmsg = command_errbuf;
	command_errbuf[0] = 0;
	if (!parse(&argc, &argv, line)) {
		result = (cmd)(argc, argv);
		free(argv);
	} else {
		result = BF_PARSE;
	}

	switch (result) {
	case CMD_CRIT:
		printf("%s\n", command_errmsg);
		command_errmsg = NULL;
		break;
	case CMD_FATAL:
		panic("%s", command_errmsg);
	}

	free(line);
	/*
	 * If there was error during nested ficlExec(), we may no longer have
	 * valid environment to return.  Throw all exceptions from here.
	 */
	if (result != CMD_OK)
		ficlVmThrow(vm, result);

	/* This is going to be thrown!!! */
	ficlStackPushInteger(ficlVmGetDataStack(vm), result);
}