Mercurial > hg > index.cgi
diff lwasm/input.c @ 108:9960e05cbe3a
Added *pragmapush and *pragmapop; still seems to be nonfunctional
author | lost@l-w.ca |
---|---|
date | Sun, 07 Aug 2011 00:58:00 -0600 |
parents | 5bf9edabd661 |
children | 38c1537857ce |
line wrap: on
line diff
--- a/lwasm/input.c Sat Aug 06 23:29:17 2011 -0600 +++ b/lwasm/input.c Sun Aug 07 00:58:00 2011 -0600 @@ -35,6 +35,7 @@ #include <lw_error.h> #include "lwasm.h" +#include "input.h" /* Data type for storing input buffers @@ -51,6 +52,12 @@ input_type_error // invalid input type }; +struct input_stack_node +{ + input_stack_entry *entry; + struct input_stack_node *next; +}; + struct input_stack { struct input_stack *next; @@ -58,6 +65,7 @@ void *data; int data2; char *filespec; + struct input_stack_node *stack; }; static char *make_filename(char *p, char *f) @@ -135,6 +143,7 @@ t -> data = lw_strdup(str); t -> data2 = 0; t -> next = IS; + t -> stack = NULL; as -> input_data = t; // t -> filespec = lw_strdup(s); } @@ -170,6 +179,7 @@ lw_free(ts); } t -> next = as -> input_data; + t -> stack = NULL; as -> input_data = t; switch (IS -> type) @@ -434,3 +444,39 @@ return IS -> filespec; return NULL; } + +void input_stack_push(asmstate_t *as, input_stack_entry *e) +{ + struct input_stack_node *n; + + n = lw_alloc(sizeof(struct input_stack_node)); + n -> next = IS -> stack; + n -> entry = e; +} + +input_stack_entry *input_stack_pop(asmstate_t *as, int magic, int (*fn)(input_stack_entry *e, void *data), void *data) +{ + struct input_stack_node *n, *n2; + input_stack_entry *e2; + + n2 = NULL; + for (n = IS -> stack; n; n = n -> next) + { + if (n -> entry -> magic == magic) + { + if ((*fn)(n -> entry, data)) + { + /* we have a match */ + e2 = n -> entry; + if (n2) + n2 -> next = n -> next; + else + IS -> stack = n -> next; + lw_free(n); + return e2; + } + } + n2 = n; + } + return NULL; +}