aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-11-21 20:03:28 -0500
committerFranklin Wei <git@fwei.tk>2015-11-21 20:03:28 -0500
commit19ea4b064320d36ecd94aa05ef2156aeb5ed9170 (patch)
tree30fe3229b2893e24e2ab61c0b264300201ceb94e
parentf4e82feb2492b0bf466c3921b3e9fc9d056f3ea3 (diff)
downloadducky-19ea4b064320d36ecd94aa05ef2156aeb5ed9170.zip
ducky-19ea4b064320d36ecd94aa05ef2156aeb5ed9170.tar.gz
ducky-19ea4b064320d36ecd94aa05ef2156aeb5ed9170.tar.bz2
ducky-19ea4b064320d36ecd94aa05ef2156aeb5ed9170.tar.xz
pretty C output
-rw-r--r--src/emitc.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/emitc.c b/src/emitc.c
index 4e356d6..e3dab6a 100644
--- a/src/emitc.c
+++ b/src/emitc.c
@@ -67,16 +67,22 @@ void write_src_noindent(const char *fmt, ...)
va_end(ap);
}
+static bool possibly_oneline = false;
+static int indent_depth = 0;
+
void write_src(const char *fmt, ...)
{
- static bool possibly_oneline = false;
- static int indent_depth = 0;
-
if(fmt[0] == '}')
{
--indent_depth;
}
+ if(fmt[0] == '{' && possibly_oneline)
+ {
+ --indent_depth;
+ possibly_oneline = false;
+ }
+
char space = ' ';
for(int i = 0; i < INDENT_SPACES * indent_depth; ++i)
write(out_fd, &space, 1);
@@ -863,8 +869,8 @@ void write_stub_code(int num_lines)
write_src("{\n");
write_src("/* this uses labels as values, a GCC extension */\n");
- write_src("const void *jump_table[%d] = ", num_lines + 1);
- write_src("{\n");
+ write_src("const void *jump_table[%d] = {\n", num_lines + 1);
+ ++indent_depth;
write_src("NULL,\n");
for(int i = 1; i <= num_lines; ++i)
{
@@ -906,7 +912,7 @@ int ducky_to_c(int fd, int out)
else
error("invalid instruction %d", instr);
}
- write_src("}\n");
+ write_src("}");
return 0;
}
else