Date: Tue, 5 Aug 2014 20:09:13 GMT From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271958 - soc2014/pedrosouza/lua_loader/head/sys/boot/common Message-ID: <201408052009.s75K9DBk044301@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pedrosouza Date: Tue Aug 5 20:09:13 2014 New Revision: 271958 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271958 Log: Added load_config to interp struct which loads the dafault config file 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 Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c Tue Aug 5 19:43:44 2014 (r271957) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.c Tue Aug 5 20:09:13 2014 (r271958) @@ -50,6 +50,14 @@ &boot_interp_simple; #endif +int +default_load_config(void *ctx) +{ + if (INTERP_INCL(interp, "/boot/loader.rc") != CMD_OK) + return INTERP_INCL(interp, "/boot/boot.conf"); + return CMD_OK; +} + /* * Interactive mode */ @@ -63,8 +71,7 @@ /* * Read our default configuration */ - if (INTERP_INCL(interp, "/boot/loader.rc") != CMD_OK) - INTERP_INCL(interp, "/boot/boot.conf"); + INTERP_LOAD_DEF_CONFIG(interp); printf("\n"); /* * Before interacting, we might want to autoboot. Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h Tue Aug 5 19:43:44 2014 (r271957) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp.h Tue Aug 5 20:09:13 2014 (r271958) @@ -29,11 +29,13 @@ 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); +typedef int interp_load_def_t(void *ctx); // load default configuration files struct interp { interp_init_t *init; interp_run_t *run; interp_incl_t *incl; + interp_load_def_t *load_configs; void *context; }; @@ -49,6 +51,9 @@ #define INTERP_INCL(i, filename) \ ((i)->incl(((i)->context), filename)) +#define INTERP_LOAD_DEF_CONFIG(i) \ + ((i)->load_configs(((i)->context))) + extern struct interp boot_interp_simple; @@ -61,6 +66,15 @@ int perform(int argc, char *argv[]); void prompt(void); +/* + * Default config loader for interp_simple & intep_forth + * Use it if your interpreter does not use a custom config + * file. + * + * Calls interp->include with 'loader.rc' or 'boot.conf' + */ +int default_load_config(void *ctx); + struct includeline { struct includeline *next; Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c Tue Aug 5 19:43:44 2014 (r271957) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_forth.c Tue Aug 5 20:09:13 2014 (r271958) @@ -354,5 +354,6 @@ .init = interp_forth_init, .run = interp_forth_run, .incl = interp_forth_incl, - .context = &forth_softc, + .load_configs = default_load_config, + .context = &forth_softc }; Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c Tue Aug 5 19:43:44 2014 (r271957) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c Tue Aug 5 20:09:13 2014 (r271958) @@ -106,10 +106,21 @@ return ldo_file(softc->luap, filename); } +/* +* To avoid conflicts lua uses loader.lua instead of +* loader.rc/boot.conf to load its configurations. +*/ +int +interp_lua_load_config(void *ctx) +{ + return interp_lua_incl(ctx, "/boot/loader.lua"); +} + struct interp boot_interp_lua = { .init = interp_lua_init, .run = interp_lua_run, .incl = interp_lua_incl, - .context = &lua_softc, + .load_configs = interp_lua_load_config, + .context = &lua_softc }; Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c Tue Aug 5 19:43:44 2014 (r271957) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_simple.c Tue Aug 5 20:09:13 2014 (r271958) @@ -177,6 +177,7 @@ .init = interp_simple_init, .run = interp_simple_run, .incl = interp_simple_incl, - .context = NULL, + .load_configs = default_load_config, + .context = NULL };
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408052009.s75K9DBk044301>