ref: ba9a4254b691e9cdd6b06dcb33fd2f36eb4703cb
parent: a0bc995332afdd4b693347cfae94694e6c601aed
author: henesy <henesy.dev@gmail.com>
date: Fri Mar 11 01:01:32 EST 2022
draw screen logic ;; mk stuff
--- a/demo/Makefile
+++ b/demo/Makefile
@@ -3,5 +3,6 @@
main: main.c binheap.c monsters.c world.c printing.c
ape/cc main.c binheap.c monsters.c world.c printing.c -lm -o dungeon_generator
-clean: dungeon_generator
- rm dungeon_generator
+clean:
+ rm dungeon_generator *.o
+
binary files a/demo/dungeon_generator /dev/null differ
--- /dev/null
+++ b/demo/mkfile
@@ -1,0 +1,6 @@
+
+all:V:
+ ape/make
+
+clean:V:
+ ape/make clean
--- a/fs.h
+++ b/fs.h
@@ -4,11 +4,9 @@
// Represents a 9p file
typedef struct File9 File9;
-struct File9 {
- Ref;
- int id; // index in array; qid.path
- char *name; // of file
-};
// All available files on the 9p fs
extern File9 *files[Nfiles];
+
+// Init the draw screen
+void initscreen(void*);
--- a/main.c
+++ b/main.c
@@ -6,6 +6,12 @@
#include <9p.h>
#include "fs.h"
+struct File9 {
+ Ref;
+ int id; // index in array; qid.path
+ char *name; // of file
+};
+
// All active files in the fs
File9 *files[Nfiles];
@@ -44,46 +50,51 @@
}
// Push a message into the log
-void
+char*
handlecmd(char* str)
{
int maxtoks = 10;
char *cmd;
- char *toks[maxtoks];
+ char **toks = calloc(maxtoks, sizeof (char*));
int ntoks;
ntoks = tokenize(str, toks, maxtoks);
+ if(ntoks < 1)
+ return "fail: supply at least one command";
- if(cmdcmp(cmd, "clear") == 0){
+ cmd = toks[0];
+ if(strcmp(cmd, "clear") == 0){
- }else if(cmd, "newwin") == 0){
+ }else if(strcmp(cmd, "newwin") == 0){
- }else if(cmd, "delwin") == 0){
+ }else if(strcmp(cmd, "delwin") == 0){
- }else if(cmd, "endwin") == 0){
+ }else if(strcmp(cmd, "endwin") == 0){
- }else if(cmd, "mvprintw") == 0){
+ }else if(strcmp(cmd, "mvprintw") == 0){
- }else if(cmd, "mvaddch") == 0){
+ }else if(strcmp(cmd, "mvaddch") == 0){
- }else if(cmd, "getch") == 0){
+ }else if(strcmp(cmd, "getch") == 0){
- }else if(cmd, "initscr") == 0){
+ }else if(strcmp(cmd, "initscr") == 0){
- }else if(cmd, "raw") == 0){
+ }else if(strcmp(cmd, "raw") == 0){
- }else if(cmd, "noecho") == 0){
+ }else if(strcmp(cmd, "noecho") == 0){
- }else if(cmd, "cursset") == 0){
+ }else if(strcmp(cmd, "cursset") == 0){
- }else if(cmd, "setescdelay") == 0){
+ }else if(strcmp(cmd, "setescdelay") == 0){
- }else if(cmd, "refresh") == 0){
+ }else if(strcmp(cmd, "refresh") == 0){
- }else if(cmd, "wrefresh") == 0){
+ }else if(strcmp(cmd, "wrefresh") == 0){
- }else if(cmd, "keypad") == 0){
+ }else if(strcmp(cmd, "keypad") == 0){
}
+ free(toks);
+ return nil;
}
// Print the log
@@ -135,6 +146,8 @@
File9 log = (File9) { (Ref){ 0 }, 1, "screen" };
files[1] = &log;
+ threadcreate(initscreen, nil, 4096);
+
threadpostmountsrv(&srvfs, srv, mnt, MREPL|MCREATE);
threadexits(nil);
}
@@ -234,10 +247,13 @@
// At this point, str contains the written bytes
+ char *msg;
switch(q.path){
case 0:
// ctl file
- handlecmd(str);
+ msg = handlecmd(str);
+ if(msg != nil)
+ respond(r, msg);
break;
default:
respond(r, "only ctl may be written to");
--- a/mkfile
+++ b/mkfile
@@ -4,6 +4,7 @@
OFILES = \
main.$O \
+ screen.$O \
HFILES = \
fs.h
@@ -11,3 +12,8 @@
BIN = $home/bin/$objtype
</sys/src/cmd/mkone
+
+allclean:V:
+ mk clean
+ cd 9curses; mk clean; cd ..
+ cd demo; mk clean; cd ..
--- a/screen.c
+++ b/screen.c
@@ -9,8 +9,10 @@
#include <u.h>
#include <libc.h>
+#include <thread.h>
#include <draw.h>
#include <event.h>
+#include "fs.h"
void moveball(void);
void initball(void);
@@ -87,15 +89,13 @@
void
-initscreen(int argc, char *argv[])
+initscreen(void*)
{
- USED(argc, argv);
-
Event ev;
int e, timer;
/* Initiate graphics and mouse */
- if(initdraw(nil, nil, "bouncing ball demo") < 0)
+ if(initdraw(nil, nil, "cursedfs") < 0)
sysfatal("initdraw failed: %r");
einit(Emouse);
@@ -115,8 +115,7 @@
/* Main event loop */
- for(;;)
- {
+ for(;;){
e = event(&ev);
/* If there is a mouse event, the rightmost button
@@ -131,6 +130,4 @@
moveball();
}
}
-
-