socsvn commit: r268920 - in soc2014/pedrosouza/lua_loader/head/sys/boot: common lua/src

pedrosouza at FreeBSD.org pedrosouza at FreeBSD.org
Sun Jun 1 17:39:25 UTC 2014


Author: pedrosouza
Date: Sun Jun  1 17:39:22 2014
New Revision: 268920
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268920

Log:
  Fix code style

Modified:
  soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c
  soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h
  soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c
  soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c
  soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/src/lstd.c

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c	Sun Jun  1 16:35:22 2014	(r268919)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c	Sun Jun  1 17:39:22 2014	(r268920)
@@ -1,37 +1,37 @@
 /*-
- * Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+* Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+*/
 
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
 /*
- * Simple commandline interpreter, toplevel and misc.
- *
- * XXX may be obsoleted by BootFORTH or some other, better, interpreter.
- */
+* Simple commandline interpreter, toplevel and misc.
+*
+* XXX may be obsoleted by BootFORTH or some other, better, interpreter.
+*/
 
 #include <stand.h>
 #include <string.h>
@@ -43,147 +43,147 @@
 
 struct interp	*interp = 
 #if defined(BOOT_LUA)
-    &boot_interp_lua;
+	&boot_interp_lua;
 #elif defined(BOOT_FORTH)
-    &boot_interp_forth;
+	&boot_interp_forth;
 #else
-    &boot_interp_simple;
+	&boot_interp_simple;
 #endif
 
 /*
- * Interactive mode
- */
+* Interactive mode
+*/
 void
 interact(void)
 {
-    static char	input[256];			/* big enough? */
+	static char	input[256];			/* big enough? */
 
-    INTERP_INIT(interp);
+	INTERP_INIT(interp);
 
-    /*
-     * Read our default configuration
-     */
-    if (INTERP_INCL(interp, "/boot/loader.rc") != CMD_OK)
-	INTERP_INCL(interp, "/boot/boot.conf");
-    printf("\n");
-    /*
-     * Before interacting, we might want to autoboot.
-     */
-    autoboot_maybe();
-    
-    /*
-     * Not autobooting, go manual
-     */
-    printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
-    if (getenv("prompt") == NULL)
-	setenv("prompt", "${interpret}", 1);
-    if (getenv("interpret") == NULL)
-        setenv("interpret", "OK", 1);
-    
-
-    for (;;) {
-	input[0] = '\0';
-	prompt();
-	ngets(input, sizeof(input));
-    INTERP_RUN(interp, input);
-    }
+	/*
+	* Read our default configuration
+	*/
+	if (INTERP_INCL(interp, "/boot/loader.rc") != CMD_OK)
+		INTERP_INCL(interp, "/boot/boot.conf");
+	printf("\n");
+	/*
+	* Before interacting, we might want to autoboot.
+	*/
+	autoboot_maybe();
+
+	/*
+	* Not autobooting, go manual
+	*/
+	printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
+	if (getenv("prompt") == NULL)
+		setenv("prompt", "${interpret}", 1);
+	if (getenv("interpret") == NULL)
+		setenv("interpret", "OK", 1);
+
+
+	for (;;) {
+		input[0] = '\0';
+		prompt();
+		ngets(input, sizeof(input));
+		INTERP_RUN(interp, input);
+	}
 }
 
 /*
- * Read commands from a file, then execute them.
- *
- * We store the commands in memory and close the source file so that the media
- * holding it can safely go away while we are executing.
- *
- * Commands may be prefixed with '@' (so they aren't displayed) or '-' (so
- * that the script won't stop if they fail).
- */
+* Read commands from a file, then execute them.
+*
+* We store the commands in memory and close the source file so that the media
+* holding it can safely go away while we are executing.
+*
+* Commands may be prefixed with '@' (so they aren't displayed) or '-' (so
+* that the script won't stop if they fail).
+*/
 COMMAND_SET(include, "include", "read commands from a file", command_include);
 
 static int
 command_include(int argc, char *argv[])
 {
-    int		i;
-    int		res;
-    char	**argvbuf;
-
-    /* 
-     * Since argv is static, we need to save it here.
-     */
-    argvbuf = (char**) calloc((u_int)argc, sizeof(char*));
-    for (i = 0; i < argc; i++)
-	argvbuf[i] = strdup(argv[i]);
-
-    res=CMD_OK;
-    for (i = 1; (i < argc) && (res == CMD_OK); i++)
-	res = INTERP_INCL(interp, argvbuf[i]);
-
-    for (i = 0; i < argc; i++)
-	free(argvbuf[i]);
-    free(argvbuf);
+	int		i;
+	int		res;
+	char	**argvbuf;
+
+	/* 
+	* Since argv is static, we need to save it here.
+	*/
+	argvbuf = (char**) calloc((u_int)argc, sizeof(char*));
+	for (i = 0; i < argc; i++)
+		argvbuf[i] = strdup(argv[i]);
+
+	res=CMD_OK;
+	for (i = 1; (i < argc) && (res == CMD_OK); i++)
+		res = INTERP_INCL(interp, argvbuf[i]);
+
+	for (i = 0; i < argc; i++)
+		free(argvbuf[i]);
+	free(argvbuf);
 
-    return(res);
+	return(res);
 }
 
 /*
- * Perform the command
- */
+* Perform the command
+*/
 int
 perform(int argc, char *argv[])
 {
-    int				result;
-    struct bootblk_command	**cmdp;
-    bootblk_cmd_t		*cmd;
-
-    if (argc < 1)
-	return(CMD_OK);
-
-    /* set return defaults; a successful command will override these */
-    command_errmsg = command_errbuf;
-    strcpy(command_errbuf, "no error message");
-    cmd = NULL;
-    result = CMD_ERROR;
-
-    /* search the command set for the command */
-    SET_FOREACH(cmdp, Xcommand_set) {
-	if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name))
-	    cmd = (*cmdp)->c_fn;
-    }
-    if (cmd != NULL) {
-	result = (cmd)(argc, argv);
-    } else {
-	command_errmsg = "unknown command";
-    }
-    return result;
+	int				result;
+	struct bootblk_command	**cmdp;
+	bootblk_cmd_t		*cmd;
+
+	if (argc < 1)
+		return(CMD_OK);
+
+	/* set return defaults; a successful command will override these */
+	command_errmsg = command_errbuf;
+	strcpy(command_errbuf, "no error message");
+	cmd = NULL;
+	result = CMD_ERROR;
+
+	/* search the command set for the command */
+	SET_FOREACH(cmdp, Xcommand_set) {
+		if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name))
+			cmd = (*cmdp)->c_fn;
+	}
+	if (cmd != NULL) {
+		result = (cmd)(argc, argv);
+	} else {
+		command_errmsg = "unknown command";
+	}
+	return result;
 }
 
 /*
- * Emit the current prompt; use the same syntax as the parser
- * for embedding environment variables.
- */
+* Emit the current prompt; use the same syntax as the parser
+* for embedding environment variables.
+*/
 void
 prompt(void) 
 {
-    char	*pr, *p, *cp, *ev;
-    
-    if ((cp = getenv("prompt")) == NULL)
-	cp = ">";
-    pr = p = strdup(cp);
-
-    while (*p != 0) {
-	if ((*p == '$') && (*(p+1) == '{')) {
-	    for (cp = p + 2; (*cp != 0) && (*cp != '}'); cp++)
-		;
-	    *cp = 0;
-	    ev = getenv(p + 2);
-	    
-	    if (ev != NULL)
-		printf("%s", ev);
-	    p = cp + 1;
-	    continue;
+	char	*pr, *p, *cp, *ev;
+
+	if ((cp = getenv("prompt")) == NULL)
+		cp = ">";
+	pr = p = strdup(cp);
+
+	while (*p != 0) {
+		if ((*p == '$') && (*(p+1) == '{')) {
+			for (cp = p + 2; (*cp != 0) && (*cp != '}'); cp++)
+				;
+			*cp = 0;
+			ev = getenv(p + 2);
+
+			if (ev != NULL)
+				printf("%s", ev);
+			p = cp + 1;
+			continue;
+		}
+		putchar(*p++);
 	}
-	putchar(*p++);
-    }
-    putchar(' ');
-    free(pr);
+	putchar(' ');
+	free(pr);
 }

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h	Sun Jun  1 16:35:22 2014	(r268919)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h	Sun Jun  1 17:39:22 2014	(r268920)
@@ -25,7 +25,7 @@
  *
  */
 
-typedef void interp_init_t(void *ctx);
+typedef void	interp_init_t(void *ctx);
 typedef int	interp_run_t(void *ctx, const char *input);
 typedef int	interp_incl_t(void *ctx, const char *filename);
 
@@ -33,7 +33,7 @@
 	interp_init_t	*init;
 	interp_run_t	*run;
 	interp_incl_t	*incl;
-	void		 *context;
+	void		*context;
 };
 
 #define	INTERP_INIT(i)		do {			\

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c	Sun Jun  1 16:35:22 2014	(r268919)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c	Sun Jun  1 17:39:22 2014	(r268920)
@@ -77,81 +77,81 @@
 static void
 bf_command(FICL_VM *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))
-	    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 (stackPopINT(vm->pStack)) {
-	/*
-	 * 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 = stackPopINT(vm->pStack);
-	for (i = 0, len = 0; i < nstrings; i++)
-	    len += stackFetch(vm->pStack, i * 2).i + 1;
-	line = malloc(strlen(name) + len + 1);
-	strcpy(line, name);
-
-	if (nstrings)
-	    for (i = 0; i < nstrings; i++) {
-		len = stackPopINT(vm->pStack);
-		cp = stackPopPtr(vm->pStack);
-		strcat(line, " ");
-		strncat(line, cp, len);
-	    }
-    } else {
-	/* Get remainder of invocation */
-	tail = vmGetInBuf(vm);
-	for (cp = tail, len = 0; 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);
-	    vmUpdateTib(vm, tail + len);
+	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))
+			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 (stackPopINT(vm->pStack)) {
+		/*
+		* 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 = stackPopINT(vm->pStack);
+		for (i = 0, len = 0; i < nstrings; i++)
+			len += stackFetch(vm->pStack, i * 2).i + 1;
+		line = malloc(strlen(name) + len + 1);
+		strcpy(line, name);
+
+		if (nstrings)
+			for (i = 0; i < nstrings; i++) {
+				len = stackPopINT(vm->pStack);
+				cp = stackPopPtr(vm->pStack);
+				strcat(line, " ");
+				strncat(line, cp, len);
+			}
+	} else {
+		/* Get remainder of invocation */
+		tail = vmGetInBuf(vm);
+		for (cp = tail, len = 0; 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);
+			vmUpdateTib(vm, tail + len);
+		}
+	}
+	DEBUG("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;
 	}
-    }
-    DEBUG("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;
-    }
-    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 != 0)
-	vmThrow(vm, result);
-    /* This is going to be thrown!!! */
-    stackPushINT(vm->pStack,result);
+	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 != 0)
+		vmThrow(vm, result);
+	/* This is going to be thrown!!! */
+	stackPushINT(vm->pStack,result);
 }
 
 /*
@@ -248,48 +248,48 @@
 void
 interp_forth_init(void *ctx)
 {
-    struct interp_forth_softc   *softc;
-    struct bootblk_command	**cmdp;
-    char create_buf[41];	/* 31 characters-long builtins */
-    int fd;
-
-    softc = ctx;
-
-    assert((softc->bf_sys == NULL) && (softc->bf_vm == NULL) &&
-        (softc->pInterp == NULL));	/* No Forth context at this stage */
-
-    softc->bf_sys = ficlInitSystem(BF_DICTSIZE);
-    softc->bf_vm = ficlNewVM(softc->bf_sys);
-
-    /* Put all private definitions in a "builtins" vocabulary */
-    ficlExec(softc->bf_vm, "vocabulary builtins also builtins definitions");
-
-    /* Builtin constructor word  */
-    ficlExec(softc->bf_vm, BUILTIN_CONSTRUCTOR);
-
-    /* make all commands appear as Forth words */
-    SET_FOREACH(cmdp, Xcommand_set) {
-	ficlBuild(softc->bf_sys, (char *)(*cmdp)->c_name, bf_command, FW_DEFAULT);
-	ficlExec(softc->bf_vm, "forth definitions builtins");
-	sprintf(create_buf, "builtin: %s", (*cmdp)->c_name);
-	ficlExec(softc->bf_vm, create_buf);
-	ficlExec(softc->bf_vm, "builtins definitions");
-    }
-    ficlExec(softc->bf_vm, "only forth definitions");
-
-    /* Export some version numbers so that code can detect the loader/host version */
-    ficlSetEnv(softc->bf_sys, "FreeBSD_version", __FreeBSD_version);
-    ficlSetEnv(softc->bf_sys, "loader_version", 
-	       (bootprog_rev[0] - '0') * 10 + (bootprog_rev[2] - '0'));
-
-    /* try to load and run init file if present */
-    if ((fd = open("/boot/boot.4th", O_RDONLY)) != -1) {
-	(void)ficlExecFD(softc->bf_vm, fd);
-	close(fd);
-    }
+	struct interp_forth_softc   *softc;
+	struct bootblk_command	**cmdp;
+	char create_buf[41];	/* 31 characters-long builtins */
+	int fd;
+
+	softc = ctx;
+
+	assert((softc->bf_sys == NULL) && (softc->bf_vm == NULL) &&
+		(softc->pInterp == NULL));	/* No Forth context at this stage */
+
+	softc->bf_sys = ficlInitSystem(BF_DICTSIZE);
+	softc->bf_vm = ficlNewVM(softc->bf_sys);
 
-    /* Do this last, so /boot/boot.4th can change it */
-    softc->pInterp = ficlLookup(softc->bf_sys, "interpret");
+	/* Put all private definitions in a "builtins" vocabulary */
+	ficlExec(softc->bf_vm, "vocabulary builtins also builtins definitions");
+
+	/* Builtin constructor word  */
+	ficlExec(softc->bf_vm, BUILTIN_CONSTRUCTOR);
+
+	/* make all commands appear as Forth words */
+	SET_FOREACH(cmdp, Xcommand_set) {
+		ficlBuild(softc->bf_sys, (char *)(*cmdp)->c_name, bf_command, FW_DEFAULT);
+		ficlExec(softc->bf_vm, "forth definitions builtins");
+		sprintf(create_buf, "builtin: %s", (*cmdp)->c_name);
+		ficlExec(softc->bf_vm, create_buf);
+		ficlExec(softc->bf_vm, "builtins definitions");
+	}
+	ficlExec(softc->bf_vm, "only forth definitions");
+
+	/* Export some version numbers so that code can detect the loader/host version */
+	ficlSetEnv(softc->bf_sys, "FreeBSD_version", __FreeBSD_version);
+	ficlSetEnv(softc->bf_sys, "loader_version", 
+		(bootprog_rev[0] - '0') * 10 + (bootprog_rev[2] - '0'));
+
+	/* try to load and run init file if present */
+	if ((fd = open("/boot/boot.4th", O_RDONLY)) != -1) {
+		(void)ficlExecFD(softc->bf_vm, fd);
+		close(fd);
+	}
+
+	/* Do this last, so /boot/boot.4th can change it */
+	softc->pInterp = ficlLookup(softc->bf_sys, "interpret");
 }
 
 /*
@@ -298,39 +298,39 @@
 int
 interp_forth_run(void *ctx, const char *line)
 {
-    struct interp_forth_softc *softc;
-    int		result;
+	struct interp_forth_softc *softc;
+	int		result;
+
+	softc = ctx;
 
-    softc = ctx;
+	result = ficlExec(softc->bf_vm, (char*)line);
 
-    result = ficlExec(softc->bf_vm, (char*)line);
+	DEBUG("ficlExec '%s' = %d", line, result);
+	switch (result) {
+	case VM_OUTOFTEXT:
+	case VM_ABORTQ:
+	case VM_QUIT:
+	case VM_ERREXIT:
+		break;
+	case VM_USEREXIT:
+		printf("No where to leave to!\n");
+		break;
+	case VM_ABORT:
+		printf("Aborted!\n");
+		break;
+	case BF_PARSE:
+		printf("Parse error!\n");
+		break;
+	default:
+		/* Hopefully, all other codes filled this buffer */
+		printf("%s\n", command_errmsg);
+	}
 
-    DEBUG("ficlExec '%s' = %d", line, result);
-    switch (result) {
-    case VM_OUTOFTEXT:
-    case VM_ABORTQ:
-    case VM_QUIT:
-    case VM_ERREXIT:
-	break;
-    case VM_USEREXIT:
-	printf("No where to leave to!\n");
-	break;
-    case VM_ABORT:
-	printf("Aborted!\n");
-	break;
-    case BF_PARSE:
-	printf("Parse error!\n");
-	break;
-    default:
-        /* Hopefully, all other codes filled this buffer */
-	printf("%s\n", command_errmsg);
-    }
-    
-    if (result == VM_USEREXIT)
-	panic("interpreter exit");
-    setenv("interpret", softc->bf_vm->state ? "" : "OK", 1);
+	if (result == VM_USEREXIT)
+		panic("interpreter exit");
+	setenv("interpret", softc->bf_vm->state ? "" : "OK", 1);
 
-    return result;
+	return result;
 }
 
 int

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c	Sun Jun  1 16:35:22 2014	(r268919)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c	Sun Jun  1 17:39:22 2014	(r268920)
@@ -25,69 +25,74 @@
 } while (0)
 
 
-int lua_print(lua_State *L)
+int
+lua_print(lua_State *L)
 {
-    int i;
-    int n = lua_gettop(L);
-    for (i = 1; i <= n; ++i)
-        printf("%s", lua_tostring(L, i));
-    return 0;
+	int i;
+	int n = lua_gettop(L);
+	for (i = 1; i <= n; ++i)
+		printf("%s", lua_tostring(L, i));
+	return 0;
 }
 
-int lua_perform(lua_State *L)
+int
+lua_perform(lua_State *L)
 {
 
-    int argc, ret;
+	int argc, ret;
 	char **argv;
-    int res = -1;
-    int n = lua_gettop(L);
+	int res = -1;
+	int n = lua_gettop(L);
+
+	if (n >= 1)
+	{
+		parse(&argc, &argv, lua_tostring(L, 1));
+		res = perform(argc, argv);
+	}
+	lua_pushnumber(L, res);
+
+	return 1;
+}
 
-    if (n >= 1)
-    {
-	    parse(&argc, &argv, lua_tostring(L, 1));
-	    res = perform(argc, argv);
-    }
-    lua_pushnumber(L, res);
-
-    return 1;
-}
-
-void * lua_realloc(void *ud, void *ptr, size_t osize, size_t nsize)
-{
-    (void)ud; (void)osize;  /* not used */
-    if (nsize == 0) {
-        free(ptr);
-        return NULL;
-    }
-    else
-        return realloc(ptr, nsize);
+void *
+lua_realloc(void *ud, void *ptr, size_t osize, size_t nsize)
+{
+	(void)ud; (void)osize;  /* not used */
+	if (nsize == 0) {
+		free(ptr);
+		return NULL;
+	}
+	else
+		return realloc(ptr, nsize);
 }
 
 typedef struct data_chunk
 {
-    void * data;
-    size_t size;
+	void * data;
+	size_t size;
 } data_chunk;
 
-const char * read_chunk(lua_State *L, void * chunk, size_t *sz)
+const char *
+read_chunk(lua_State *L, void * chunk, size_t *sz)
 {
-    data_chunk * ds = (data_chunk *)chunk;
-    if (ds->size == 0) return NULL;
-    *sz = ds->size;
-    ds->size = 0;
-    return (const char*)ds->data;
+	data_chunk * ds = (data_chunk *)chunk;
+	if (ds->size == 0) return NULL;
+	*sz = ds->size;
+	ds->size = 0;
+	return (const char*)ds->data;
 }
 
 
-int do_string(lua_State *L, const char * str, size_t size)
+int
+do_string(lua_State *L, const char * str, size_t size)
 {
-    int res;
-    data_chunk ds;
-    ds.data = (void*)str;
-    ds.size = size;
-    res = lua_load(L, read_chunk, &ds, "do_string___", 0);
-    res = lua_pcall(L, 0, LUA_MULTRET, 0);
-    return res;
+	int res;
+	data_chunk ds;
+	ds.data = (void*)str;
+	ds.size = size;
+	res = lua_load(L, read_chunk, &ds, "do_string___", 0);
+	res = lua_pcall(L, 0, LUA_MULTRET, 0);
+	return res;
 }
 
 
@@ -107,8 +112,8 @@
 		LDBG("problem with initializing Lua interpreter\n");
 	}
 	softc->luap = luap;
-    lua_register(luap, "print", lua_print);
-    lua_register(luap, "perform", lua_perform);
+	lua_register(luap, "print", lua_print);
+	lua_register(luap, "perform", lua_perform);
 
 }
 
@@ -123,8 +128,8 @@
 	softc = data;
 	luap = softc->luap;
 
-    if (do_string(luap, line, strlen(line)) != 0)
-        printf("[LUA]Failed to execure \'%s\'\n", line);
+	if (do_string(luap, line, strlen(line)) != 0)
+		printf("[LUA]Failed to execure \'%s\'\n", line);
 
 	return (0);
 }
@@ -132,25 +137,25 @@
 int
 interp_lua_incl(void *ctx, const char *filename)
 {
-	lua_State *luap;
+	lua_State		*luap;
 	struct interp_lua_softc *softc;
-	struct stat st;
-	char *filebuf, *errstr;
-	int fd, filebufoff, i, rleft, rread;
+	struct stat		st;
+	char			*filebuf, *errstr;
+	int			fd, filebufoff, i, rleft, rread;
 
-    printf("[Lua] Including file %s.\n", filename);
+	printf("[Lua] Including file %s.\n", filename);
 	/*
-    if ((strcmp(filename, "/boot/loader.rc") == 0) ||
-	    (strcmp(filename, "/boot/boot.conf") == 0)) {
-		printf("Skipping loader.rc and boot.conf");
-		return (0);
+	if ((strcmp(filename, "/boot/loader.rc") == 0) ||
+		(strcmp(filename, "/boot/boot.conf") == 0)) {
+			printf("Skipping loader.rc and boot.conf");
+			return (0);
 	}
-    */
+
 	softc = ctx;
 	luap = softc->luap;
-	/*
-    
-    fd = open(filename, O_RDONLY);
+
+
+	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
 		printf("Couldn't open file %s\n", filename);
 		return (1);
@@ -160,13 +165,13 @@
 	filebuf = malloc(st.st_size);
 	assert(filebuf != NULL);
 	memset(filebuf, 0, st.st_size);
-    */
+	*/
 	/*
-	 * XX: Investigate stat() vs logic problem. I'm getting
-	 * more bytes that the file really has.
-	 */
+	* XX: Investigate stat() vs logic problem. I'm getting
+	* more bytes that the file really has.
+	*/
 
-    /*
+	/*
 	rleft = st.st_size - 1;
 	filebufoff = 0;
 	for (;;) {
@@ -190,7 +195,7 @@
 		printf("\t'%s'\n\n", errstr);
 		lua_pop(luap, 1);
 	}
-    */
+	*/
 	return (0);
 }
 

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c	Sun Jun  1 16:35:22 2014	(r268919)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c	Sun Jun  1 17:39:22 2014	(r268920)
@@ -1,29 +1,29 @@
 /*-
- * Copyright (c) 2014 Pedro Souza <pedrosouza at freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
+* Copyright (c) 2014 Pedro Souza <pedrosouza at freebsd.org>
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+*
+*/
 
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -55,11 +55,11 @@
 	(void)softc;	/* Currently unused */
 
 	if (!parse(&argc, &argv, input)) {
-	    if (perform(argc, argv))
-		printf("%s: %s\n", argv[0], command_errmsg);
-	    free(argv);
+		if (perform(argc, argv))
+			printf("%s: %s\n", argv[0], command_errmsg);
+		free(argv);
 	} else {
-	    printf("parse error\n");
+		printf("parse error\n");
 	}
 	return 0;
 }
@@ -67,110 +67,110 @@
 int
 interp_simple_incl(void *ctx, const char *filename)
 {
-    struct includeline	*script, *se, *sp;
-    char		input[256];			/* big enough? */
-    int			argc,res;
-    char		**argv, *cp;
-    int			fd, flags, line;
-
-    (void)ctx; /* Silent the compiler */
-
-    if (((fd = open(filename, O_RDONLY)) == -1)) {
-	sprintf(command_errbuf,"can't open '%s': %s\n", filename, strerror(errno));
-	return(CMD_ERROR);
-    }
-
-    /*
-     * Read the script into memory.
-     */
-    script = se = NULL;
-    line = 0;
-	
-    while (fgetstr(input, sizeof(input), fd) >= 0) {
-	line++;
-	flags = 0;
-	/* Discard comments */
-	if (strncmp(input+strspn(input, " "), "\\ ", 2) == 0)
-	    continue;
-	cp = input;
-	/* Echo? */
-	if (input[0] == '@') {
-	    cp++;
-	    flags |= SL_QUIET;
-	}
-	/* Error OK? */
-	if (input[0] == '-') {
-	    cp++;
-	    flags |= SL_IGNOREERR;
-	}
-	/* Allocate script line structure and copy line, flags */
-	if (*cp == '\0')
-		continue;	/* ignore empty line, save memory */
-	sp = malloc(sizeof(struct includeline) + strlen(cp) + 1);
-	/* On malloc failure (it happens!), free as much as possible and exit */
-	if (sp == NULL) {
-		while (script != NULL) {
-			se = script;
-			script = script->next;
-			free(se);
-		}
-		sprintf(command_errbuf, "file '%s' line %d: memory allocation "

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-soc-all mailing list