aboutsummaryrefslogtreecommitdiff
path: root/src/sc_parse.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-09-08 22:30:44 +0200
committerThomas White <taw@bitwiz.org.uk>2014-09-08 22:30:44 +0200
commit5eaef1d4fcce1cfba848f081f06f3ec14a4e80a7 (patch)
treefdb0a245de7fd44c6624bab5d9600bc4cd2a939e /src/sc_parse.c
parentcba13eb85af0714aa7ffa605773215baf5833612 (diff)
Copy SCBlocks when executing a macro
Diffstat (limited to 'src/sc_parse.c')
-rw-r--r--src/sc_parse.c64
1 files changed, 49 insertions, 15 deletions
diff --git a/src/sc_parse.c b/src/sc_parse.c
index f30d6b0..93a346e 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -43,6 +43,7 @@ struct _scblock
SCBlock *next;
SCBlock *prev;
SCBlock *child;
+ SCBlock *macro_child;
struct frame *fr;
};
@@ -55,6 +56,8 @@ SCBlock *sc_block_new()
bl = calloc(1, sizeof(SCBlock));
if ( bl == NULL ) return NULL;
+ bl->macro_child = NULL;
+
return bl;
}
@@ -71,6 +74,18 @@ SCBlock *sc_block_child(const SCBlock *bl)
}
+SCBlock *sc_block_macro_child(const SCBlock *bl)
+{
+ return bl->macro_child;
+}
+
+
+void sc_block_set_macro_child(SCBlock *bl, SCBlock *mchild)
+{
+ bl->macro_child = mchild;
+}
+
+
const char *sc_block_name(const SCBlock *bl)
{
return bl->name;
@@ -145,20 +160,7 @@ SCBlock *sc_block_append_end(SCBlock *bl, char *name, char *opt, char *contents)
bl = bl->next;
};
- bln->name = name;
- bln->options = opt;
- bln->contents = contents;
- bln->child = NULL;
- bln->next = NULL;
-
- if ( bl == NULL ) {
- bln->prev = NULL;
- } else {
- bl->next = bln;
- bln->prev = bl;
- }
-
- return bln;
+ return sc_block_append(bl, name, opt, contents, NULL);
}
@@ -286,7 +288,8 @@ void show_sc_block(const SCBlock *bl, const char *prefix)
printf("%s", prefix);
if ( bl->name != NULL ) printf("\\%s ", bl->name);
if ( bl->options != NULL ) printf("[%s] ", bl->options);
- if ( bl->contents != NULL ) printf("{%s}", bl->contents);
+ if ( bl->contents != NULL ) printf("{%s} ", bl->contents);
+ if ( bl->fr != NULL ) printf("-> frame %p", bl->fr);
printf("\n");
if ( bl->child != NULL ) {
@@ -581,3 +584,34 @@ void sc_delete_text(SCBlock *b1, int o1, SCBlock *b2, int o2)
}
}
}
+
+
+/* Create a deep copy of "bl", including all its children */
+SCBlock *sc_block_copy(const SCBlock *bl)
+{
+ SCBlock *copy;
+ SCBlock *first_copy;
+
+ first_copy = sc_block_new();
+
+ copy = first_copy;
+ do {
+
+ if ( bl->name != NULL ) copy->name = strdup(bl->name);
+ if ( bl->options != NULL ) copy->options = strdup(bl->options);
+ if ( bl->contents != NULL ) copy->contents = strdup(bl->contents);
+ if ( bl->child != NULL ) copy->child = sc_block_copy(bl->child);
+
+ bl = bl->next;
+
+ if ( bl != NULL ) {
+ SCBlock *nn;
+ nn = sc_block_new();
+ copy->next = nn;
+ copy = nn;
+ }
+
+ } while ( bl != NULL );
+
+ return first_copy;
+}