# HG changeset patch # User William Astle # Date 1342404891 21600 # Node ID 211fc8038b8d8318a6caac1fca0e6a33bc06f676 # Parent 03f7192fcd204abf96067d4d3c6cae4b8b91dc71 More unicorn stuff - structs and macros Settled on an output format for unicorn stuff and added structs and macros to that output. Format is: TYPE: =[,=]* Any which has special characters will use urlencoding. Values with multiple values use a semicolon as a separator. diff -r 03f7192fcd20 -r 211fc8038b8d lwasm/lwasm.h --- a/lwasm/lwasm.h Sun Jul 15 10:50:46 2012 -0600 +++ b/lwasm/lwasm.h Sun Jul 15 20:14:51 2012 -0600 @@ -253,6 +253,7 @@ int size; // number of bytes taken by struct structtab_field_t *fields; // fields in the structure structtab_t *next; // next structure + line_t *definedat; // line where structure is defined }; struct asmstate_s diff -r 03f7192fcd20 -r 211fc8038b8d lwasm/struct.c --- a/lwasm/struct.c Sun Jul 15 10:50:46 2012 -0600 +++ b/lwasm/struct.c Sun Jul 15 20:14:51 2012 -0600 @@ -63,6 +63,7 @@ s -> next = as -> structs; s -> fields = NULL; s -> size = 0; + s -> definedat = l; as -> structs = s; as -> cstruct = s; diff -r 03f7192fcd20 -r 211fc8038b8d lwasm/unicorns.c --- a/lwasm/unicorns.c Sun Jul 15 10:50:46 2012 -0600 +++ b/lwasm/unicorns.c Sun Jul 15 20:14:51 2012 -0600 @@ -30,21 +30,61 @@ #include "lwasm.h" #include "lw_alloc.h" +static void print_urlencoding(FILE *stream, const char *string) +{ + for ( ; *string; string++) + { + if (*string < 33 || *string > 126 || strchr("$&+,/:;=?@\"<>#%{}|\\^~[]`", *string)) + { + fprintf(stream, "%%%02X", *string); + } + else + { + fputc(*string, stream); + } + } +} + void lwasm_do_unicorns(asmstate_t *as) { char *n; macrotab_t *me; - + structtab_t *se; + int i; + /* output file list */ while ((n = lw_stack_pop(as -> includelist))) { - fprintf(stdout, "RESOURCE: file:%s\n", n); - lw_free(n); + fputs("RESOURCE: type=file,filename=", stdout); + print_urlencoding(stdout, n); + fputc('\n', stdout); + lw_free(n); } /* output macro list */ for (me = as -> macros; me; me = me -> next) { - fprintf(stdout, "RESOURCE: macro:%s,%d,%s\n", me -> name, me -> definedat -> lineno, me -> definedat -> linespec); + fprintf(stdout, "RESOURCE: type=macro,name=%s,lineno=%d,filename=", me -> name, me -> definedat -> lineno); + print_urlencoding(stdout, me -> definedat -> linespec); + fputs(",flags=", stdout); + if (me -> flags & macro_noexpand) + fputs("noexpand", stdout); + fputs(",def=", stdout); + for (i = 0; i < me -> numlines; i++) + { + if (i) + fputc(';', stdout); + print_urlencoding(stdout, me -> lines[i]); + } + fputc('\n', stdout); } + + /* output structure list */ + for (se = as -> structs; se; se = se -> next) + { + fprintf(stdout, "RESOURCE: type=struct,name=%s,lineno=%d,filename=", se -> name, se -> definedat -> lineno); + print_urlencoding(stdout, se -> definedat -> linespec); + fputc('\n', stdout); + } + }