2018-09-17 14:48:14 +02:00
|
|
|
#define _DEFAULT_SOURCE
|
|
|
|
#define _BSD_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
2018-09-17 09:07:22 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2018-10-05 11:50:02 +02:00
|
|
|
#include <fcntl.h>
|
2018-09-17 09:07:22 +02:00
|
|
|
#include <stdio.h>
|
2018-10-02 10:30:17 +02:00
|
|
|
#include <stdarg.h>
|
2018-09-17 09:07:22 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
2018-09-17 14:48:14 +02:00
|
|
|
#include <sys/types.h>
|
2018-09-17 09:07:22 +02:00
|
|
|
#include <termios.h>
|
2018-10-02 10:30:17 +02:00
|
|
|
#include <time.h>
|
2018-09-17 09:07:22 +02:00
|
|
|
#include <unistd.h>
|
2018-10-18 13:27:51 +02:00
|
|
|
#include <signal.h>
|
2018-09-17 09:07:22 +02:00
|
|
|
|
2018-10-18 12:00:56 +02:00
|
|
|
#include "fn.h"
|
|
|
|
#include "terminal.h"
|
2018-10-19 13:24:58 +02:00
|
|
|
#include "output.h"
|
|
|
|
#include "row.h"
|
|
|
|
#include "hl.h"
|
|
|
|
#include "search.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "input.h"
|
|
|
|
|
|
|
|
// TODO: Put this somewhere else?
|
|
|
|
void windowResizeCallback(int signum);
|
|
|
|
void initEditor();
|
2018-10-09 10:29:14 +02:00
|
|
|
|
2018-10-18 13:27:51 +02:00
|
|
|
void windowResizeCallback(int signum) {
|
|
|
|
if (signum != SIGWINCH) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setWindowSize(&E.screenrows, &E.screencols) == -1) {
|
|
|
|
die("setWindowSize");
|
|
|
|
}
|
|
|
|
E.screenrows -= 2;
|
|
|
|
editorRefreshScreen();
|
|
|
|
}
|
|
|
|
|
2018-09-17 09:07:22 +02:00
|
|
|
void initEditor() {
|
2018-09-17 13:27:19 +02:00
|
|
|
E.cx = 0;
|
|
|
|
E.cy = 0;
|
2018-10-02 10:30:17 +02:00
|
|
|
E.rx = 0;
|
2018-09-21 17:05:22 +02:00
|
|
|
E.rowoff = 0;
|
2018-10-01 17:03:40 +02:00
|
|
|
E.coloff = 0;
|
2018-09-17 14:48:14 +02:00
|
|
|
E.numrows = 0;
|
2018-09-21 09:10:15 +02:00
|
|
|
E.row = NULL;
|
2018-10-05 11:59:27 +02:00
|
|
|
E.dirty = 0;
|
2018-10-02 10:30:17 +02:00
|
|
|
E.filename = NULL;
|
|
|
|
E.statusmsg[0] = '\0';
|
|
|
|
E.statusmsg_time = 0;
|
2018-10-16 16:59:23 +02:00
|
|
|
E.syntax = NULL;
|
2018-09-17 13:27:19 +02:00
|
|
|
|
2018-10-18 13:27:51 +02:00
|
|
|
if (setWindowSize(&E.screenrows, &E.screencols) == -1) {
|
|
|
|
die("setWindowSize");
|
|
|
|
}
|
2018-10-02 10:30:17 +02:00
|
|
|
E.screenrows -= 2;
|
2018-09-17 09:07:22 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 14:48:14 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2018-10-18 13:27:51 +02:00
|
|
|
|
2018-09-17 09:07:22 +02:00
|
|
|
enableRawMode();
|
|
|
|
initEditor();
|
2018-09-17 14:48:14 +02:00
|
|
|
if (argc >= 2) {
|
|
|
|
editorOpen(argv[1]);
|
|
|
|
}
|
2018-09-17 09:07:22 +02:00
|
|
|
|
2018-10-09 10:29:14 +02:00
|
|
|
editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = Quit | Ctrl-F = find");
|
2018-10-02 10:30:17 +02:00
|
|
|
|
2018-10-18 13:27:51 +02:00
|
|
|
signal(SIGWINCH, windowResizeCallback);
|
|
|
|
|
2018-09-17 09:07:22 +02:00
|
|
|
while (1) {
|
|
|
|
editorRefreshScreen();
|
|
|
|
editorProcessKeypress();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|