Compare commits

..

6 commits

Author SHA1 Message Date
8573bc1c5c
Resolve compiler warnings and udpate CFLAGS 2024-11-05 00:02:09 +00:00
6f5904ecf6
Fix indentation 2024-10-27 01:37:40 +00:00
81581b1905
Weirdly alternate buffer works 2024-10-27 01:28:30 +00:00
f6eaf81d8c
Fix makefile 2024-10-27 01:46:50 +01:00
df3059f120
Update Makefile 2024-10-22 01:29:49 +01:00
2bc1fbe8d2
Update Makefile 2024-10-22 01:29:13 +01:00
9 changed files with 45 additions and 52 deletions

View file

@ -1,20 +1,17 @@
.POSIX:
.SUFFIXES:
CC = cc
VERSION = 1.0
TARGET = vip
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man1
# Flags
CFLAGS = -O3 -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
CFLAGS = -Os -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE
SRC = src/*.c config.h
SRC != find src -name *.c
INCLUDE = include
$(TARGET): $(SRC)
$(TARGET): $(SRC) config.h
$(CC) $(SRC) -o $@ $(CFLAGS) -I$(INCLUDE) -I.
dist:
@ -26,15 +23,14 @@ dist:
install: $(TARGET)
mkdir -p $(DESTDIR)$(BINDIR)
mkdir -p $(DESTDIR)$(MANDIR)
cp -p $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
chmod 755 $(DESTDIR)$(BINDIR)/$(TARGET)
uninstall:
$(RM) $(DESTDIR)$(BINDIR)/$(TARGET)
rm $(DESTDIR)$(BINDIR)/$(TARGET)
clean:
$(RM) $(TARGET)
rm $(TARGET)
all: $(TARGET)

View file

@ -1,16 +1,16 @@
#ifndef EDITOR_H_
#define EDITOR_H_
void refresh_screen();
void refresh_screen(void);
void move_cursor(int key);
void scroll();
void scroll(void);
void insert_char(int c);
void insert_new_line();
void shift_new_line();
void del_char();
void init_editor();
void insert_new_line(void);
void shift_new_line(void);
void del_char(void);
void init_editor(void);
void open_editor(char *filename);
char *prompt_editor(char *prompt, void (*callback)(char *, int));
void find_editor();
void find_editor(void);
#endif

View file

@ -1,9 +1,9 @@
#ifndef IO_H_
#define IO_H_
int read_key();
void save_file();
void process_key();
int read_key(void);
void save_file(void);
void process_key(void);
void draw_rows(struct abuf *ab);
#endif

View file

@ -21,6 +21,6 @@ typedef struct language {
int is_separator(int c);
void update_highlight(row *row);
char *syntax_to_color(int hl, size_t *len);
void select_syntax_highlight();
void select_syntax_highlight(void);
#endif

View file

@ -4,8 +4,8 @@
#define CTRL_KEY(k) ((k) & 0x1f)
void die(const char *s);
void reset_term();
void setup_term();
void reset_term(void);
void setup_term(void);
int get_cursor_position(int *rows, int *cols);
int get_window_size(int *rows, int *cols);

View file

@ -12,7 +12,7 @@
extern editor vip;
void refresh_screen()
void refresh_screen(void)
{
scroll();
@ -68,7 +68,7 @@ void move_cursor(int key)
}
}
void scroll()
void scroll(void)
{
vip.rx = 0;
if (vip.cy < vip.rows) {
@ -97,7 +97,7 @@ void insert_char(int c)
vip.cx++;
}
void insert_new_line()
void insert_new_line(void)
{
if (vip.cx == 0) {
insert_row(vip.cy, "", 0);
@ -116,14 +116,14 @@ void insert_new_line()
/*
* 'o' in vim
*/
void shift_new_line()
void shift_new_line(void)
{
insert_row(vip.cy + 1, "", 0);
vip.cy++;
vip.cx = 0;
}
void del_char()
void del_char(void)
{
if (vip.cy == vip.rows) return;
if (vip.cx == 0 && vip.cy == 0) return;
@ -140,7 +140,7 @@ void del_char()
}
}
void init_editor()
void init_editor(void)
{
vip.cx = 0;
vip.cy = 0;
@ -280,7 +280,7 @@ void find_callback(char *query, int key)
}
}
void find_editor()
void find_editor(void)
{
int tmp_cx = vip.cx;
int tmp_cy = vip.cy;

View file

@ -10,7 +10,7 @@
#include "vip.h"
#include "bar.h"
int read_key()
int read_key(void)
{
int nread;
char c;
@ -65,7 +65,7 @@ int read_key()
}
}
void save_file()
void save_file(void)
{
if (vip.filename == NULL) {
vip.filename = prompt_editor("Save as: %s", NULL);
@ -94,9 +94,8 @@ void save_file()
set_status_bar_message("Error saving: %s", strerror(errno));
}
void process_key()
void process_key(void)
{
int c = read_key();
switch (c) {
case '\r':
@ -172,8 +171,6 @@ void process_key()
switch (cmd[0]) {
case 'q':
if (cmd[1] == '!') {
write(STDOUT_FILENO, "\x1b[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3);
exit(0);
break;
} else {
@ -182,8 +179,7 @@ void process_key()
vip.mode = NORMAL;
return;
}
write(STDOUT_FILENO, "\x1b[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3);
exit(0);
break;

View file

@ -185,7 +185,7 @@ char *syntax_to_color(int hl, size_t *len)
}
}
void select_syntax_highlight()
void select_syntax_highlight(void)
{
vip.syntax = NULL;
if (vip.filename == NULL) return;

View file

@ -10,24 +10,25 @@ extern editor vip;
void die(const char *s)
{
write(STDOUT_FILENO, "\x1b[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3);
write(STDOUT_FILENO, "\x1b[2J\x1b[H", 7);
perror(s);
exit(1);
}
void reset_term()
void reset_term(void)
{
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &vip.termios) == -1) {
die("tcsetattr");
}
write(STDOUT_FILENO, "\x1b[2J\x1b[?1049l", 12);
}
/*
* Setup terminal
*/
void setup_term()
void setup_term(void)
{
write(STDOUT_FILENO, "\x1b[?1049h\x1b[2J", 12);
if (tcgetattr(STDIN_FILENO, &vip.termios) == -1) {
die("tcgetattr");
}