From 2c5e4c97e1d28e80c47acb26dca66c5332724081 Mon Sep 17 00:00:00 2001 From: raffitz Date: Sat, 23 Mar 2019 18:44:24 +0000 Subject: [PATCH] Add random initialisation and improve frontend --- index.html | 24 ++++++++++++++++++++---- js-api.c | 11 +++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 728dd3a..59f5ef7 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ -
-
- - +
+
+
+ + +
diff --git a/js-api.c b/js-api.c index a1978c4..c4af0b5 100644 --- a/js-api.c +++ b/js-api.c @@ -1,5 +1,7 @@ #include "emscripten.h" #include +#include +#include #include #include "expression.h" #include "parser.tab.h" @@ -25,13 +27,16 @@ void EMSCRIPTEN_KEEPALIVE webdice(char* str){ int length; char* in_block; char* out_block; + static char seeded = 0; - yydebug = 1; + if (!seeded){ + seeded = 1; + srand(time(NULL)); + } in_block = (char*) malloc((2 + strlen(str)) * sizeof(char)); sprintf(in_block,"%s\n",str); - yyscan_t scanner; yylex_init(&scanner); yy_scan_string (in_block, scanner); @@ -46,6 +51,8 @@ void EMSCRIPTEN_KEEPALIVE webdice(char* str){ output_print(out_block); free(out_block); + free(result.text); + free_expression(root); }else{ output_print("

Error!

"); }