summaryrefslogtreecommitdiff
path: root/jet2.cpp
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 /jet2.cpp
parentf1ad05bb486ec49f576580cda8e6c9a9a8b92317 (diff)
downloadjet-e450b0d47e9d05a806769d096646d723845e0ba2.tar.gz
jet-e450b0d47e9d05a806769d096646d723845e0ba2.zip
Make client side ipc binary
Diffstat (limited to 'jet2.cpp')
-rw-r--r--jet2.cpp14
1 files changed, 7 insertions, 7 deletions
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);
}
}