diff options
author | Thomas White <taw@bitwiz.org.uk> | 2014-09-09 21:35:13 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2014-09-09 21:35:13 +0200 |
commit | c04cb6fdd6da6d5a941440af87b1cec688e47c3e (patch) | |
tree | acd1d6d0761fabc8d34d61a5da3e30e5e93726e1 /src/sc_interp.c | |
parent | 5eaef1d4fcce1cfba848f081f06f3ec14a4e80a7 (diff) |
Run macro contents
Diffstat (limited to 'src/sc_interp.c')
-rw-r--r-- | src/sc_interp.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/sc_interp.c b/src/sc_interp.c index 896d3ef..87d58a7 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -58,6 +58,8 @@ struct sc_state int n_macros; int max_macros; struct macro *macros; /* Contents need to be copied on push */ + + SCBlock *macro_contents; }; @@ -267,6 +269,7 @@ SCInterpreter *sc_interp_new(PangoContext *pc, struct frame *top) free(scin); return NULL; } + st->macro_contents = NULL; /* FIXME: Determine proper language (somehow...) */ scin->lang = pango_language_from_string("en_GB"); @@ -603,11 +606,13 @@ static int check_macro(const char *name, SCInterpreter *scin) } -static void exec_macro(SCBlock *bl, SCInterpreter *scin) +static void exec_macro(SCBlock *bl, SCInterpreter *scin, SCBlock *child) { SCBlock *mchild; struct sc_state *st = &scin->state[scin->j]; + st->macro_contents = child; + mchild = sc_block_macro_child(bl); if ( mchild == NULL ) { @@ -629,6 +634,16 @@ static void exec_macro(SCBlock *bl, SCInterpreter *scin) } +static void run_macro_contents(SCInterpreter *scin) +{ + struct sc_state *st = &scin->state[scin->j]; + + sc_interp_save(scin); + sc_interp_add_blocks(scin, st->macro_contents); + sc_interp_restore(scin); +} + + int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) { printf("Running this --------->\n"); @@ -659,9 +674,12 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) maybe_recurse_after(scin, child); } else if ( check_macro(name, scin) ) { - maybe_recurse_before(scin, child); - exec_macro(bl, scin); - maybe_recurse_after(scin, child); + sc_interp_save(scin); + exec_macro(bl, scin, child); + sc_interp_restore(scin); + + } else if ( strcmp(name, "contents") == 0 ) { + run_macro_contents(scin); } else if ( strcmp(name, "pad") == 0 ) { maybe_recurse_before(scin, child); |