Introduction
Introduction Statistics Contact Development Disclaimer Help
tMove row operations into separate file - ve - a minimal text editor (work in p…
git clone git://src.adamsgaard.dk/ve
Log
Files
Refs
README
LICENSE
---
commit 0ebc6405b29708897e7f73c3216dbabaef92e852
parent 6facf1866e50a80e078ed47197370901453d9e74
Author: Anders Damsgaard <[email protected]>
Date: Tue, 6 Aug 2019 15:44:40 +0200
Move row operations into separate file
Diffstat:
M io.c | 52 +----------------------------…
M output.c | 15 +--------------
A row.c | 71 +++++++++++++++++++++++++++++…
A row.h | 9 +++++++++
4 files changed, 82 insertions(+), 65 deletions(-)
---
diff --git a/io.c b/io.c
t@@ -9,57 +9,7 @@
#include <string.h>
#include "byote.h"
#include "terminal.h"
-
-/* translate tabs before display */
-void
-editor_update_row(eRow* row)
-{
- int j, idx, tabs;
-
- free(row->rchars);
- row->rchars = malloc(row->size + 1);
-
- tabs = 0;
- for (j=0; j<row->size; ++j)
- if (row->chars[j] == '\t')
- tabs++;
-
- free(row->rchars);
- row->rchars = malloc(row->size + tabs*(TAB_WIDTH - 1) + 1);
-
- idx = 0;
- for (j=0; j<row->size; ++j) {
- if (row->chars[j] == '\t') {
- row->rchars[idx++] = '>';
- while (idx % TAB_WIDTH != 0)
- row->rchars[idx++] = ' ';
- } else {
- row->rchars[idx++] = row->chars[j];
- }
- }
- row->rchars[idx] = '\0';
- row->rsize = idx;
-}
-
-/* add row to buffer */
-void
-editor_append_row(char *s, size_t len)
-{
- int i;
-
- E.row = realloc(E.row, sizeof(eRow) * (E.num_rows + 1));
- i = E.num_rows;
- E.row[i].size = len;
- E.row[i].chars = malloc(len + 1);
- memcpy(E.row[i].chars, s, len);
- E.row[i].chars[len] = '\0';
-
- E.row[i].rsize = 0;
- E.row[i].rchars = NULL;
- editor_update_row(&E.row[i]);
-
- ++E.num_rows;
-}
+#include "row.h"
void
file_open(char *filename)
diff --git a/output.c b/output.c
t@@ -6,6 +6,7 @@
#include <time.h>
#include "terminal.h"
#include "output.h"
+#include "row.h"
#include "byote.h"
/* reallocate append buffer to hold string s */
t@@ -107,20 +108,6 @@ editor_draw_status_message(struct abuf *ab)
ab_append(ab, E.status_msg, msglen);
}
-/* navigate over tab-representative string as one character */
-int
-editor_row_cursor_x_to_rx(eRow *row, int cursor_x)
-{
- int rx, j;
- rx = 0;
- for (j=0; j<cursor_x; ++j) {
- if (row->chars[j] == '\t')
- rx += (TAB_WIDTH - 1) - (rx % TAB_WIDTH);
- rx++;
- }
- return rx;
-}
-
/* set vertical offset between file and screen when hitting the boundaries */
void
editor_scroll()
diff --git a/row.c b/row.c
t@@ -0,0 +1,71 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <string.h>
+#include "byote.h"
+#include "terminal.h"
+
+/* navigate over tab-representative string as one character */
+int
+editor_row_cursor_x_to_rx(eRow *row, int cursor_x)
+{
+ int rx, j;
+ rx = 0;
+ for (j=0; j<cursor_x; ++j) {
+ if (row->chars[j] == '\t')
+ rx += (TAB_WIDTH - 1) - (rx % TAB_WIDTH);
+ rx++;
+ }
+ return rx;
+}
+
+/* translate tabs before display */
+void
+editor_update_row(eRow* row)
+{
+ int j, idx, tabs;
+
+ free(row->rchars);
+ row->rchars = malloc(row->size + 1);
+
+ tabs = 0;
+ for (j=0; j<row->size; ++j)
+ if (row->chars[j] == '\t')
+ tabs++;
+
+ free(row->rchars);
+ row->rchars = malloc(row->size + tabs*(TAB_WIDTH - 1) + 1);
+
+ idx = 0;
+ for (j=0; j<row->size; ++j) {
+ if (row->chars[j] == '\t') {
+ row->rchars[idx++] = '>';
+ while (idx % TAB_WIDTH != 0)
+ row->rchars[idx++] = ' ';
+ } else {
+ row->rchars[idx++] = row->chars[j];
+ }
+ }
+ row->rchars[idx] = '\0';
+ row->rsize = idx;
+}
+
+/* add row to buffer */
+void
+editor_append_row(char *s, size_t len)
+{
+ int i;
+
+ E.row = realloc(E.row, sizeof(eRow) * (E.num_rows + 1));
+ i = E.num_rows;
+ E.row[i].size = len;
+ E.row[i].chars = malloc(len + 1);
+ memcpy(E.row[i].chars, s, len);
+ E.row[i].chars[len] = '\0';
+
+ E.row[i].rsize = 0;
+ E.row[i].rchars = NULL;
+ editor_update_row(&E.row[i]);
+
+ ++E.num_rows;
+}
diff --git a/row.h b/row.h
t@@ -0,0 +1,9 @@
+#ifndef ROW_H_
+#define ROW_H_
+
+#include "byote.h"
+
+int editor_row_cursor_x_to_rx(eRow *row, int cursor_x);
+void editor_append_row(char *s, size_t len);
+
+#endif
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.