input events and empty UNIX functions
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 29 Dec 2022 05:31:03 +0000 (07:31 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 29 Dec 2022 05:31:03 +0000 (07:31 +0200)
GNUmakefile [new file with mode: 0644]
Makefile
src/dos/input.c [new file with mode: 0644]
src/input.h [new file with mode: 0644]
src/main.c
src/unix/input.c [new file with mode: 0644]
src/unix/tgfx.c [new file with mode: 0644]

diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644 (file)
index 0000000..734fb67
--- /dev/null
@@ -0,0 +1,24 @@
+src = $(wildcard src/*.c) $(wildcard src/unix/*.c)
+obj = $(src:.c=.o)
+dep = $(src:.c=.d)
+bin = oftp
+
+warn = -pedantic -Wall
+dbg = -g
+incdir = -Isrc
+
+CFLAGS = $(warn) $(dbg) $(incdir) -MMD
+LDFLAGS = -lcurses
+
+$(bin): $(obj)
+       $(CC) -o $@ $(obj) $(LDFLAGS)
+
+-include $(dep)
+
+.PHONY: clean
+clean:
+       $(RM) $(obj) $(bin)
+
+.PHONY: cleandep
+cleandep:
+       $(RM) $(dep)
index dd0f1bf..05eac20 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-obj = main.obj tgfx.obj tui.obj darray.obj util.obj
+obj = main.obj tgfx.obj tui.obj darray.obj util.obj input.obj
 bin = oftp.exe
 
 !ifdef __UNIX__
diff --git a/src/dos/input.c b/src/dos/input.c
new file mode 100644 (file)
index 0000000..99a40de
--- /dev/null
@@ -0,0 +1,18 @@
+#include <conio.h>
+#include "input.h"
+
+int init_input(void)
+{
+       return 0;
+}
+
+void cleanup_input(void)
+{
+}
+
+int wait_input(union event *ev)
+{
+       ev->type = EV_KEY;
+       ev->key.key = getch();
+       return 1;
+}
diff --git a/src/input.h b/src/input.h
new file mode 100644 (file)
index 0000000..412b2a0
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef INPUT_H_
+#define INPUT_H_
+
+enum {
+       EV_KEY,
+       EV_MMOVE,
+       EV_MBUTTON
+};
+
+struct event_key {
+       int type;
+       int key;
+};
+
+struct event_mmove {
+       int type;
+       int x, y;
+};
+
+struct event_mbutton {
+       int type;
+       int x, y, bn, press;
+};
+
+union event {
+       int type;
+       struct event_key key;
+       struct event_mmove mmove;
+       struct event_mbutton mbutton;
+};
+
+
+int init_input(void);
+void cleanup_input(void);
+
+int wait_input(union event *ev);
+
+#endif /* INPUT_H_ */
index 5fb66a6..2323ea3 100644 (file)
@@ -1,8 +1,12 @@
-#include <conio.h>
 #include "tgfx.h"
+#include "input.h"
 
 int main(void)
 {
+       union event ev;
+
+       init_input();
+
        tg_bgchar(' ');
        tg_clear();
 
@@ -14,11 +18,23 @@ int main(void)
        tg_text(0, 24, "fooolalala bar");
 /*     tg_setcursor(2, 24);*/
 
-       while(getch() != 27);
+       while(wait_input(&ev)) {
+               switch(ev.type) {
+               case EV_KEY:
+                       if(ev.key.key == 27) goto done;
+                       break;
 
+               default:
+                       break;
+               }
+       }
+
+done:
        tg_bgchar(' ');
        tg_bgcolor(0);
        tg_fgcolor(7);
        tg_clear();
+
+       cleanup_input();
        return 0;
 }
diff --git a/src/unix/input.c b/src/unix/input.c
new file mode 100644 (file)
index 0000000..e1d689d
--- /dev/null
@@ -0,0 +1,15 @@
+#include "input.h"
+
+int init_input(void)
+{
+       return 0;
+}
+
+void cleanup_input(void)
+{
+}
+
+int wait_input(union event *ev)
+{
+       return 0;
+}
diff --git a/src/unix/tgfx.c b/src/unix/tgfx.c
new file mode 100644 (file)
index 0000000..4c8955d
--- /dev/null
@@ -0,0 +1,38 @@
+#include <curses.h>
+#include "tgfx.h"
+
+void tg_clear(void)
+{
+}
+
+
+void tg_fgcolor(int col)
+{
+}
+
+void tg_bgcolor(int col)
+{
+}
+
+void tg_color(int col)
+{
+}
+
+void tg_bgchar(int c)
+{
+}
+
+
+void tg_setcursor(int x, int y)
+{
+}
+
+
+void tg_text(int x, int y, const char *fmt, ...)
+{
+}
+
+
+void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags)
+{
+}