summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-11 12:13:59 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-11 12:13:59 -0300
commite450b0d47e9d05a806769d096646d723845e0ba2 (patch)
tree68b43e458651ea393c7d0774907aec0200d234c6
parentf1ad05bb486ec49f576580cda8e6c9a9a8b92317 (diff)
downloadjet-e450b0d47e9d05a806769d096646d723845e0ba2.tar.gz
jet-e450b0d47e9d05a806769d096646d723845e0ba2.zip
Make client side ipc binary
-rw-r--r--Makefile4
-rw-r--r--buffer.cpp2
-rw-r--r--client.cpp2
-rw-r--r--ipc.cpp15
-rw-r--r--jet.cpp6
-rw-r--r--jet2.cpp14
-rw-r--r--page.cpp9
-rw-r--r--point.cpp1
8 files changed, 29 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index c4d3e50..661df70 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-FLAGS=-ggdb -O0 -lcurses $(shell ncursesw6-config --cflags --libs)
+FLAGS=-ggdb -O0
_PHONY=all
@@ -8,4 +8,4 @@ jet: Makefile *.cpp
g++ $(FLAGS) jet.cpp -o jet
jet2: Makefile *.cpp
- g++ $(FLAGS) jet2.cpp -o jet2
+ g++ $(FLAGS) -lcurses $(shell ncursesw6-config --cflags --libs) jet2.cpp -o jet2
diff --git a/buffer.cpp b/buffer.cpp
index 9dbf118..ba3f87c 100644
--- a/buffer.cpp
+++ b/buffer.cpp
@@ -1,5 +1,3 @@
-#include "page.cpp"
-
struct Buffer {
const char *name;
Page *storage;
diff --git a/client.cpp b/client.cpp
index 05d07a1..176aa80 100644
--- a/client.cpp
+++ b/client.cpp
@@ -1,5 +1,3 @@
-#include "point.cpp"
-
#define MAX_ARGS 16
#define pos(x, y) (x) + (y) * window_w
diff --git a/ipc.cpp b/ipc.cpp
new file mode 100644
index 0000000..7b6ea5d
--- /dev/null
+++ b/ipc.cpp
@@ -0,0 +1,15 @@
+enum Operation {
+ OP_I1,
+ OP_I2,
+ OP_I4,
+ OP_I8,
+ OP_U1,
+ OP_U2,
+ OP_U4,
+ OP_U8,
+ OP_STR,
+ OP_MOVE,
+ OP_INSERT,
+ OP_DELETE,
+ OP_SHOW
+};
diff --git a/jet.cpp b/jet.cpp
index 638d728..1ae3eeb 100644
--- a/jet.cpp
+++ b/jet.cpp
@@ -1,6 +1,7 @@
-#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -11,7 +12,10 @@
#include <unistd.h>
#include <sys/epoll.h>
+#include "ipc.cpp"
+#include "page.cpp"
#include "buffer.cpp"
+#include "point.cpp"
#include "client.cpp"
#define PORT 6969
diff --git a/jet2.cpp b/jet2.cpp
index 729fbc7..994ba14 100644
--- a/jet2.cpp
+++ b/jet2.cpp
@@ -1,5 +1,4 @@
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <curses.h>
@@ -9,6 +8,8 @@
#include <arpa/inet.h>
#include <unistd.h>
+#include "ipc.cpp"
+
#define NORMAL_MODE 0
#define INSERT_MODE 1
#define PORT 6969
@@ -27,7 +28,6 @@ int main(int argc, char *argv[]) {
char *view = new char[window_width * window_height];
for (int i = 0; i < window_width * window_height; view[i++] = 0);
-
int s = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in addr = { AF_INET, htons(PORT), htonl(INADDR_LOOPBACK)};
connect(s, (sockaddr *) &addr, sizeof(sockaddr_in));
@@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
clear();
char msg[32] = {};
- int len = sprintf(msg, " %d %d show ", window_width, window_height);
+ int len = sprintf(msg, "%d%d%d%d%d", OP_I4, window_width, OP_I4, window_height, OP_SHOW);
write(s, msg, len);
read(s, view, window_width * window_height);
for (int i = 0; i < window_width * window_height; i++) {
@@ -57,11 +57,11 @@ int main(int argc, char *argv[]) {
mode = INSERT_MODE;
break;
case 'h':
- len = sprintf(msg, " -1 move ");
+ len = sprintf(msg, "%d%d%d", OP_I1, -1, OP_MOVE);
write(s, msg, len);
break;
case 'l':
- len = sprintf(msg, " 1 move ");
+ len = sprintf(msg, "%d%d%d", OP_I1, 1, OP_MOVE);
write(s, msg, len);
break;
}
@@ -71,11 +71,11 @@ int main(int argc, char *argv[]) {
mode = NORMAL_MODE;
break;
case KEY_BACKSPACE:
- len = sprintf(msg, " pop ");
+ len = sprintf(msg, "%d", OP_DELETE);
write(s, msg, len);
break;
default:
- len = sprintf(msg, " %d push ", input);
+ len = sprintf(msg, "%d%d%d", OP_I1, input, OP_INSERT);
write(s, msg, len);
}
}
diff --git a/page.cpp b/page.cpp
index 6ded950..77cf686 100644
--- a/page.cpp
+++ b/page.cpp
@@ -1,8 +1,3 @@
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
@@ -59,28 +54,24 @@ struct Page {
}
void move_gap_forward() {
- assert(gap_end < PAGE_SIZE);
elements[gap_start] = elements[gap_end];
gap_start++;
gap_end++;
}
void move_gap_backward() {
- assert(gap_start > 0);
gap_end--;
gap_start--;
elements[gap_end] = elements[gap_start];
}
void push(uint8_t c) {
- assert(element_count < PAGE_SIZE);
elements[gap_start] = c;
gap_start++;
element_count++;
}
void pop() {
- assert(gap_start > 0);
gap_start--;
element_count--;
}
diff --git a/point.cpp b/point.cpp
index 5422350..ab9f70f 100644
--- a/point.cpp
+++ b/point.cpp
@@ -1,5 +1,4 @@
#include <stdint.h>
-#include <assert.h>
#include <stdbool.h>
struct Point {