commit 55128841b0b84282c27239d9b0ec920f0546a2d5
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date: Fri, 23 Oct 2015 20:47:03 +0200
init project with a stub
Diffstat:
A | Makefile | | | 5 | +++++ |
A | lchat.c | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,5 @@
+CC=cc
+CFLAGS=-std=c99 -pedantic -Wall -Wextra
+
+lchat: lchat.c
+ $(CC) $(CFLAGS) -o $@ lchat.c
diff --git a/lchat.c b/lchat.c
@@ -0,0 +1,51 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+struct termios origin_term;
+
+void
+exit_handler(void)
+{
+ if (tcsetattr(STDIN_FILENO, TCSANOW, &origin_term) == -1)
+ err(EXIT_FAILURE, "tcsetattr");
+}
+
+int
+main(void)
+{
+ struct termios term;
+ int fd = STDIN_FILENO;
+ int c;
+
+ if (isatty(fd) == 0)
+ err(EXIT_FAILURE, "isatty");
+
+ if (tcgetattr(fd, &origin_term) == -1)
+ err(EXIT_FAILURE, "tcgetattr");
+
+ if (atexit(exit_handler) == -1)
+ err(EXIT_FAILURE, "atexit");
+
+ /* prepare terminal */
+ if (tcgetattr(fd, &term) == -1)
+ err(EXIT_FAILURE, "tcgetattr");
+
+ cfmakeraw(&term);
+
+ if (tcsetattr(fd, TCSANOW, &term) == -1)
+ err(EXIT_FAILURE, "tcsetattr");
+
+ setbuf(stdin, NULL);
+ setbuf(stdout, NULL);
+
+ while ((c = getchar()) != 13) {
+ //printf("c: %d\r\n", c);
+ if (c >= 32 && c < 127)
+ putchar(c);
+ }
+
+ return EXIT_SUCCESS;
+}