summaryrefslogtreecommitdiff
path: root/interliner.c
blob: 17937df98239b3a791be02e9858cf2ed3ef764c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
	//char *string = NULL;
	//size_t sz = 0;

	int fd = open("log.log", O_WRONLY | O_CREAT | O_APPEND, 0660);
	if (fd < 0) {
		return 1;
	}

	char msg[100] = "\nnew log =======\n";
	write(fd, &msg, sizeof(msg));

	char sstring[4096] = {};
	ssize_t pos = 0;

	int c = getchar();
	while (c != EOF) {
		switch (c) {
			case '\n':
				sstring[pos] = '\0';
				printf("\r%s", sstring);
				fflush(stdout);
				pos = 0;
				break;
			default:
				sstring[pos++] = c;
				break;
		}
		c = getchar();
	}

	putchar('\n');

	//while (getline(&string, &sz, stdin) > 0) {
	//	if (!sz) {
	//		continue;
	//	}

	//	char *reader = string;
	//	putchar(*reader);
	//	write(fd, reader, 1);
	//	fflush(stdout);
	//	char *writer = string;

	//	while ((reader - string) < sz) {
	//		if (*reader == '\n') {
	//			*reader = '\0';
	//			break;
	//		}

	//		write(fd, "<", 1);
	//		write(fd, reader, 1);
	//		write(fd, ">", 1);
	//		*(reader++) = *(writer++);
	//	}

	//	printf("\r%s", string);
	//	write(fd, "!", 1);

	//	free(string);
	//	string = NULL;
	//}

	close(fd);

	//free(string);

	return 0;
}