aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2015-11-07 13:55:47 -0500
committerFranklin Wei <git@fwei.tk>2015-11-07 13:55:47 -0500
commite1af2b39befe312ba9a289270f94b1766d4c14fb (patch)
tree83e20fb79581500661654167334feb1266fb5fe3
parent618eb70bff837150377f259853fbd1b3a05ad5af (diff)
downloadducky-e1af2b39befe312ba9a289270f94b1766d4c14fb.zip
ducky-e1af2b39befe312ba9a289270f94b1766d4c14fb.tar.gz
ducky-e1af2b39befe312ba9a289270f94b1766d4c14fb.tar.bz2
ducky-e1af2b39befe312ba9a289270f94b1766d4c14fb.tar.xz
fix some stuff
-rw-r--r--Makefile12
-rw-r--r--src/ducky.c44
-rw-r--r--sysdep/unix/main.c (renamed from sysdep/unix.c)9
-rw-r--r--sysdep/unix/platform.h11
4 files changed, 53 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index ff48041..34f6649 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,14 @@
CC = gcc
+PLATFORM = unix
DUCKY_OBJ = src/ducky.o
-CFLAGS = -lbsd -lm -O2 -g -I src/
+CFLAGS = -lbsd -lm -O2 -g -I src/ -I sysdep/$(PLATFORM)
-unix: $(DUCKY_OBJ) sysdep/unix.o
- $(CC) $(DUCKY_OBJ) sysdep/unix.o $(CFLAGS) -o unix.bin
+$(PLATFORM).bin: $(DUCKY_OBJ) sysdep/$(PLATFORM)/main.o
+ $(CC) $(DUCKY_OBJ) sysdep/$(PLATFORM)/main.o $(CFLAGS) -o $(PLATFORM).bin
+
+clean:
+ rm -f $(PLATFORM).bin
+ rm -f sysdep/$(PLATFORM)/main.o
+ rm -f $(DUCKY_OBJ)
diff --git a/src/ducky.c b/src/ducky.c
index 971ff0a..493aa8c 100644
--- a/src/ducky.c
+++ b/src/ducky.c
@@ -1,15 +1,4 @@
-#include <bsd/string.h>
-
-#include <fcntl.h>
-#include <math.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
+#include <platform.h>
/*******************************************************************************
* The scripting language implemented here is an extension of DuckyScript.
@@ -58,7 +47,6 @@ typedef int vartype;
/*** Globals ***/
off_t *line_offset = NULL;
-int default_delay = DEFAULT_DELAY, string_delay = STRING_DELAY;
unsigned lines_executed = 0, current_line = 0, num_lines;
@@ -67,8 +55,6 @@ unsigned stack_frame = 0;
int log_fd = -1, file_des = -1;
-int keys_sent = 0;
-
struct varnode_t {
char name[VARNAME_MAX + 1];
vartype val;
@@ -85,7 +71,7 @@ bool isValidVariable(const char *c);
/* variables are stored in a chained hash map */
/* collisions are manageable, but should be minimized */
-struct varnode_t *var_map[VARMAP_SIZE] = { 0 };
+struct varnode_t *var_map[VARMAP_SIZE];
/* simple DJB hash */
uint32_t var_hash(const char *str)
@@ -184,6 +170,19 @@ void exit_handler(void)
close(file_des);
if(log_fd >= 0)
close(log_fd);
+ if(line_offset)
+ free(line_offset);
+ /* free all our variables */
+ for(int i = 0; i < VARMAP_SIZE; ++i)
+ {
+ struct varnode_t *iter = var_map[i], *next;
+ while(iter)
+ {
+ next = iter->next;
+ free(iter);
+ iter = next;
+ }
+ }
}
void vid_write(const char *str)
@@ -1177,8 +1176,21 @@ void init_tokmap(void)
}
}
+void init_globals(void)
+{
+ line_offset = NULL;
+ log_fd = -1;
+ file_des = -1;
+ stack_frame = 0;
+ lines_executed = 0;
+ current_line = 0;
+ memset(var_map, 0, sizeof(var_map));
+}
+
void ducky_main(int fd)
{
+ init_globals();
+
vid_write("*** DS-2 INIT ***");
vid_write("QUACK AT YOUR OWN RISK!");
vid_write("The author assumes no liability for any damages caused by this program.");
diff --git a/sysdep/unix.c b/sysdep/unix/main.c
index 00f6017..a2db705 100644
--- a/sysdep/unix.c
+++ b/sysdep/unix/main.c
@@ -1,7 +1,5 @@
#include <ducky.h>
-
-#include <fcntl.h>
-#include <unistd.h>
+#include <platform.h>
int main(int argc, char *argv[])
{
@@ -11,6 +9,9 @@ int main(int argc, char *argv[])
ducky_main(fd);
close(fd);
}
-
+ else
+ {
+ printf("Usage: %s FILE\n", argv[0]);
+ }
return 0;
}
diff --git a/sysdep/unix/platform.h b/sysdep/unix/platform.h
new file mode 100644
index 0000000..ca331e2
--- /dev/null
+++ b/sysdep/unix/platform.h
@@ -0,0 +1,11 @@
+#include <bsd/string.h>
+
+#include <fcntl.h>
+#include <math.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>