diff options
| -rw-r--r-- | .idea/.gitignore | 8 | ||||
| -rw-r--r-- | .idea/kilo.iml | 2 | ||||
| -rw-r--r-- | .idea/misc.xml | 18 | ||||
| -rw-r--r-- | .idea/modules.xml | 8 | ||||
| -rw-r--r-- | .idea/vcs.xml | 6 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | README | 2 | ||||
| -rwxr-xr-x | kilo | bin | 0 -> 17136 bytes | |||
| -rw-r--r-- | kilo.c | 63 |
9 files changed, 111 insertions, 0 deletions
diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/kilo.iml b/.idea/kilo.iml new file mode 100644 index 0000000..d46e3a7 --- /dev/null +++ b/.idea/kilo.iml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module classpath="External" external.linked.project.id="kilo" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="Makefile" type="CPP_MODULE" version="4" />
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..53624c9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ExternalStorageConfigurationManager" enabled="true" /> + <component name="MakefileSettings"> + <option name="linkedExternalProjectsSettings"> + <MakefileProjectSettings> + <option name="externalProjectPath" value="$PROJECT_DIR$" /> + <option name="modules"> + <set> + <option value="$PROJECT_DIR$" /> + </set> + </option> + <option name="version" value="2" /> + </MakefileProjectSettings> + </option> + </component> + <component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> +</project>
\ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4d8f61b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/kilo.iml" filepath="$PROJECT_DIR$/.idea/kilo.iml" /> + </modules> + </component> +</project>
\ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project>
\ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1561364 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: kilo.c + $(CC) kilo.c -o kilo -Wall -Wextra -pedantic -std=c99 +clean: kilo.c + command rm kilo
\ No newline at end of file @@ -0,0 +1,2 @@ +Going through https://viewsourcecode.org/snaptoken/kilo/ + Binary files differ@@ -0,0 +1,63 @@ +/*** includes ***/ + +#include <stdlib.h> +#include <termios.h> +#include <unistd.h> +#include <ctype.h> +#include <stdio.h> +#include <errno.h> + +/*** data ***/ + +struct termios original_termios; + +/*** terminal ***/ + +void die(const char *s) { + perror(s); + exit(1); +} + +void disable_raw_mode() { + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &original_termios) == -1) { + die("tcsetattr"); + } +} + +void enable_raw_mode() { + if (tcgetattr(STDIN_FILENO, &original_termios) == -1) { + die("tcgetattr"); + } + atexit(disable_raw_mode); + + struct termios raw = original_termios; + raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); + raw.c_oflag &= ~(OPOST); + raw.c_cflag |= (CS8); + raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); + raw.c_cc[VMIN] = 0; + raw.c_cc[VTIME] = 1; + + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) == -1) { + die("tcsetattr"); + } +} + +/*** init ***/ + +int main() { + enable_raw_mode(); + while (1) { + char c = '\0'; + if (read(STDIN_FILENO, &c, 1) == -1 && errno != EAGAIN) { + die("read"); + } + if (iscntrl(c)) { + printf("%d\r\n", c); + } else { + printf("%d ('%c')\r\n", c, c); + } + if (c == 'q') break; + } + return 0; +} |
