sim

the sim text editor
git clone git://ssnf.xyz/sim
Log | Files | Refs | README

commit 095ed2427f56c6876951af58fa745a308d13cd8b
Author: ssnf <ssnf@ssnf.xyz>
Date:   Tue, 22 Jun 2021 16:29:36 +0000

initial commit

Diffstat:
A.gitignore | 2++
AMakefile | 15+++++++++++++++
Aposix.c | 25+++++++++++++++++++++++++
Asim.c | 43+++++++++++++++++++++++++++++++++++++++++++
Asim.h | 12++++++++++++
5 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +sim +*.o diff --git a/Makefile b/Makefile @@ -0,0 +1,15 @@ +CC = c89 +CFLAGS = -Os -Wall -Wpedantic -Wno-deprecated-declarations +SRC = ${wildcard *.c} +OBJ = ${SRC:.c=.o} + +all: sim + +sim: ${OBJ} + ${CC} ${OBJ} -o $@ + +%.o: %.c + ${CC} ${CFLAGS} -c $< -o $@ + +clean: + rm -f sim *.o diff --git a/posix.c b/posix.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <termios.h> + +void raw_init(); +void raw_end(); + +static struct termios initial_state; + +void +raw_init() +{ + struct termios raw_state; + + tcgetattr(0, &initial_state); + raw_state = initial_state; + raw_state.c_lflag &= ~(ECHO|ICANON|ISIG); + tcsetattr(0, TCSAFLUSH, &raw_state); + setbuf(stdout, NULL); +} + +void +raw_end() +{ + tcsetattr(0, TCSAFLUSH, &initial_state); +} diff --git a/sim.c b/sim.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "sim.h" + +void file_open(char* name); + +char* file; + +void +file_open(char* name) +{ + FILE* f; + ulong l; + + f = fopen(name, "r"); + fseek(f, 0, SEEK_END); + l = ftell(f); + fseek(f, 0, SEEK_SET); + file = malloc(l); + fread(file, l, 1, f); + fclose(f); +} + + +int +main() +{ + char a[16]; + uint i, j; + ushort wx, wy; + + raw_init(); + file_open("sim.c"); + printf(CSRMAX DSR); + for (i = 0; fread(a + i, 1, 1, stdin), a[i] != '\x1b'; ++i); /*buffer the input, or expect hell*/ + for (j = i; fread(a + j, 1, 1, stdin), a[j++] != 'R';); + sscanf(a + i, "[%hu;%huR", &wy, &wx); + printf(ED CSI "%hu;H", wy/2); + puts(file); + raw_end(); + return 0; +} diff --git a/sim.h b/sim.h @@ -0,0 +1,12 @@ +#define ED "\x1b[2J" +#define DSR "\x1b[6n" +#define CSRMAX "\x1b[999C\x1b[999B" +#define CSI "\x1b[" + +typedef unsigned char uchar; +typedef unsigned int uint; +typedef unsigned short ushort; +typedef unsigned long ulong; + +void raw_init(); +void raw_end();