-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
78 lines (67 loc) · 2.59 KB
/
main.c
File metadata and controls
78 lines (67 loc) · 2.59 KB
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 "marisa.h"
editorConfig E;
int
main (int argc, char *argv[])
{
setlocale(LC_CTYPE, ""); /* UTF-8 support */
setupTerm();
initEditor(&E);
/* TODO: use getopt */
if (argc >= 2)
{
editorOpen(argv[1]); /* open file in first frame */
editorRefreshScreen();
}
while(1)
{
if (BUFFER->flags.mode == NORMAL_MODE)
editorProcessKeypressNormal();
else if (BUFFER->flags.mode == VISUAL_MODE)
editorProcessKeypressVisual();
editorRefreshScreen();
}
killFrame();
/* need to free all memory the bufferArray and frameArray have */
die(L"Program has ended\n");
return 0;
}
/*
* TODO: editor message wont disappear after 3 secs
* TODO: Visual mode transition handled by pressing 'HOME', insert mode transition by pressing 'SPC SPC'
* TODO: redo and undo
*/
/*
* How does undo and redo work?
* pressing 'y' in visual mode will undo state until a different command is issued
* pressing 'y' again will redo state until a different command is issued
* state stack is cleaned after a save
*/
/*
* Look at mle cmd.c on how to implement external commands
*/
/*
* For example, if you need to shift the entire file down a few hundred bytes in
* order to insert an ID3 tag, one simple approach would be to expand the file
* with ftruncate(), mmap the file, then memmove() the contents down a bit. This,
* however, will destroy the file if your program crashes while it's running. You
* could also copy the contents of the file into a new file - this is another
* place where mmap() really shines; you can simply mmap() the old file, then
* copy all of its data into the new file with a single write().
*
* In short, mmap() is great if you're doing a large amount of IO in terms of total
* bytes transferred; this is because it reduces the number of copies needed, and
* can significantly reduce the number of kernel entries needed for reading cached
* data. However mmap() requires a minimum of two trips into the kernel (three if
* you clean up the mapping when you're done!) and does some complex internal
* kernel accounting, and so the fixed overhead can be high.
*
* read() on the other hand involves an extra memory-to-memory copy, and can thus
* be inefficient for large I/O operations, but is simple, and so the fixed
* overhead is relatively low. In short, use mmap() for large bulk I/O, and read()
* or pread() for one-off, small I/Os.
*
* https://stackoverflow.com/questions/45972/mmap-vs-reading-blocks
* https://stackoverflow.com/questions/5588605/mmap-vs-read
* https://www.sublimetext.com/blog/articles/use-mmap-with-care
* https://linuxhint.com/using_mmap_function_linux/
*/