comparison 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
comparison
equal deleted inserted replaced
222:03f7192fcd20 223:211fc8038b8d
28 #include <string.h> 28 #include <string.h>
29 29
30 #include "lwasm.h" 30 #include "lwasm.h"
31 #include "lw_alloc.h" 31 #include "lw_alloc.h"
32 32
33 static void print_urlencoding(FILE *stream, const char *string)
34 {
35 for ( ; *string; string++)
36 {
37 if (*string < 33 || *string > 126 || strchr("$&+,/:;=?@\"<>#%{}|\\^~[]`", *string))
38 {
39 fprintf(stream, "%%%02X", *string);
40 }
41 else
42 {
43 fputc(*string, stream);
44 }
45 }
46 }
47
33 void lwasm_do_unicorns(asmstate_t *as) 48 void lwasm_do_unicorns(asmstate_t *as)
34 { 49 {
35 char *n; 50 char *n;
36 macrotab_t *me; 51 macrotab_t *me;
37 52 structtab_t *se;
53 int i;
54
38 /* output file list */ 55 /* output file list */
39 while ((n = lw_stack_pop(as -> includelist))) 56 while ((n = lw_stack_pop(as -> includelist)))
40 { 57 {
41 fprintf(stdout, "RESOURCE: file:%s\n", n); 58 fputs("RESOURCE: type=file,filename=", stdout);
42 lw_free(n); 59 print_urlencoding(stdout, n);
60 fputc('\n', stdout);
61 lw_free(n);
43 } 62 }
44 63
45 /* output macro list */ 64 /* output macro list */
46 for (me = as -> macros; me; me = me -> next) 65 for (me = as -> macros; me; me = me -> next)
47 { 66 {
48 fprintf(stdout, "RESOURCE: macro:%s,%d,%s\n", me -> name, me -> definedat -> lineno, me -> definedat -> linespec); 67 fprintf(stdout, "RESOURCE: type=macro,name=%s,lineno=%d,filename=", me -> name, me -> definedat -> lineno);
68 print_urlencoding(stdout, me -> definedat -> linespec);
69 fputs(",flags=", stdout);
70 if (me -> flags & macro_noexpand)
71 fputs("noexpand", stdout);
72 fputs(",def=", stdout);
73 for (i = 0; i < me -> numlines; i++)
74 {
75 if (i)
76 fputc(';', stdout);
77 print_urlencoding(stdout, me -> lines[i]);
78 }
79 fputc('\n', stdout);
49 } 80 }
81
82 /* output structure list */
83 for (se = as -> structs; se; se = se -> next)
84 {
85 fprintf(stdout, "RESOURCE: type=struct,name=%s,lineno=%d,filename=", se -> name, se -> definedat -> lineno);
86 print_urlencoding(stdout, se -> definedat -> linespec);
87 fputc('\n', stdout);
88 }
89
50 } 90 }