Mercurial > hg > index.cgi
diff lwasm/unicorns.c @ 223:211fc8038b8d
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: <key>=<value>[,<key>=<value>]*
Any <value> which has special characters will use urlencoding. Values with
multiple values use a semicolon as a separator.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Jul 2012 20:14:51 -0600 |
parents | 03f7192fcd20 |
children | 3864d96ee8c7 |
line wrap: on
line diff
--- 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); + } + }