Made Editor Config global
This commit is contained in:
+27
-26
@@ -3,6 +3,8 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
int editorRowCxToRx(erow *row, int cursor_x) {
|
||||
int render_x = 0;
|
||||
int i;
|
||||
@@ -53,25 +55,25 @@ void editorUpdateRow(erow *row) {
|
||||
row->rsize = i_render;
|
||||
}
|
||||
|
||||
void editorInsertRow(struct editorConfig *E, int at, char *s, size_t len) {
|
||||
if (at < 0 || at > E->numrows) {
|
||||
void editorInsertRow(int at, char *s, size_t len) {
|
||||
if (at < 0 || at > E.numrows) {
|
||||
return;
|
||||
}
|
||||
|
||||
E->row = realloc(E->row, sizeof(erow) * (E->numrows + 1));
|
||||
memmove(&E->row[at + 1], &E->row[at], sizeof(erow) * (E->numrows - at));
|
||||
E.row = realloc(E.row, sizeof(erow) * (E.numrows + 1));
|
||||
memmove(&E.row[at + 1], &E.row[at], sizeof(erow) * (E.numrows - at));
|
||||
|
||||
E->row[at].size = len;
|
||||
E->row[at].chars = malloc(len + 1);
|
||||
memcpy(E->row[at].chars, s, len);
|
||||
E->row[at].chars[len] = '\0';
|
||||
E.row[at].size = len;
|
||||
E.row[at].chars = malloc(len + 1);
|
||||
memcpy(E.row[at].chars, s, len);
|
||||
E.row[at].chars[len] = '\0';
|
||||
|
||||
E->row[at].rsize = 0;
|
||||
E->row[at].render = NULL;
|
||||
editorUpdateRow(&E->row[at]);
|
||||
E.row[at].rsize = 0;
|
||||
E.row[at].render = NULL;
|
||||
editorUpdateRow(&E.row[at]);
|
||||
|
||||
++E->numrows;
|
||||
++E->dirty;
|
||||
++E.numrows;
|
||||
++E.dirty;
|
||||
}
|
||||
|
||||
void editorFreeRow(erow *row) {
|
||||
@@ -79,21 +81,21 @@ void editorFreeRow(erow *row) {
|
||||
free(row->chars);
|
||||
}
|
||||
|
||||
void editorDelRow(struct editorConfig *E, int at) {
|
||||
if (at < 0 || at >= E->numrows) {
|
||||
void editorDelRow(int at) {
|
||||
if (at < 0 || at >= E.numrows) {
|
||||
return;
|
||||
}
|
||||
editorFreeRow(&E->row[at]);
|
||||
memmove(&E->row[at], &E->row[at + 1], sizeof(erow) * (E->numrows - at - 1));
|
||||
--E->numrows;
|
||||
++E->dirty;
|
||||
editorFreeRow(&E.row[at]);
|
||||
memmove(&E.row[at], &E.row[at + 1], sizeof(erow) * (E.numrows - at - 1));
|
||||
--E.numrows;
|
||||
++E.dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorRowInsertChar(erow *row, int at, int c)
|
||||
* \param at Index of where we want to insert the char */
|
||||
|
||||
void editorRowInsertChar(struct editorConfig *E, erow *row, int at, int c) {
|
||||
void editorRowInsertChar(erow *row, int at, int c) {
|
||||
if (at < 0 || at > row->size) {
|
||||
at = row->size;
|
||||
}
|
||||
@@ -102,17 +104,16 @@ void editorRowInsertChar(struct editorConfig *E, erow *row, int at, int c) {
|
||||
++row->size;
|
||||
row->chars[at] = c;
|
||||
editorUpdateRow(row);
|
||||
++E->dirty;
|
||||
++E.dirty;
|
||||
}
|
||||
|
||||
void editorRowAppendString(struct editorConfig *E, erow *row, char *s,
|
||||
size_t len) {
|
||||
void editorRowAppendString(erow *row, char *s, size_t len) {
|
||||
row->chars = realloc(row->chars, row->size + len + 1);
|
||||
memcpy(&row->chars[row->size], s, len);
|
||||
row->size += len;
|
||||
row->chars[row->size] = '\0';
|
||||
editorUpdateRow(row);
|
||||
++E->dirty;
|
||||
++E.dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,12 +121,12 @@ void editorRowAppendString(struct editorConfig *E, erow *row, char *s,
|
||||
* \brief Delete the a char at the chosen position on the given row
|
||||
* \param at Index of the char to delete
|
||||
* \param row Row on operation is made */
|
||||
void editorRowDelchar(struct editorConfig *E, erow *row, int at) {
|
||||
void editorRowDelchar(erow *row, int at) {
|
||||
if (at < 0 || at >= row->size) {
|
||||
return;
|
||||
}
|
||||
memmove(&row->chars[at], &row->chars[at + 1], row->size - at);
|
||||
--row->size;
|
||||
editorUpdateRow(row);
|
||||
++E->dirty;
|
||||
++E.dirty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user