]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor cleanup and added a selection to buffer. Selection in the view will be replaced...
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 2 Apr 2018 13:29:56 +0000 (09:29 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 2 Apr 2018 13:29:56 +0000 (09:29 -0400)
inc/edit.h
lib/buf.c

index 75632e9f8671d1a6e18414286246f4a403ff6933..96d5a9bff5dcaf4460db3c9517beba60c99c4dcb 100644 (file)
@@ -1,15 +1,8 @@
 /* Utility Functions
  *****************************************************************************/
-/* Memory-mapped file representation */
-typedef struct {
-    uint8_t* buf; /* memory mapped byte buffer */
-    size_t len;   /* length of the buffer */
-} FMap;
-
 size_t pagealign(size_t sz);
 uint64_t getmillis(void);
 char* stringdup(const char* str);
-char* chomp(char* in);
 uint64_t modtime(char* path);
 char* strmcat(char* first, ...);
 
@@ -33,21 +26,6 @@ typedef struct Log {
     } data;
 } Log;
 
-/* gap buffer main data structure */
-typedef struct {
-    char* path;           /* the path to the open file */
-    uint64_t modtime;     /* modification time of the opened file */
-    size_t bufsize;       /* size of the buffer in runes */
-    char* bufstart;       /* start of the data buffer */
-    char* bufend;         /* end of the data buffer */
-    char* gapstart;       /* start of the gap */
-    char* gapend;         /* end of the gap */
-    Log* undo;            /* undo list */
-    Log* redo;            /* redo list */
-    bool modified;        /* tracks whether the buffer has been modified */
-    uint transid;         /* tracks the last used transaction id for log entries */
-} Buf;
-
 /* cursor/selection representation */
 typedef struct {
     size_t beg;
@@ -55,6 +33,22 @@ typedef struct {
     size_t col;
 } Sel;
 
+/* gap buffer main data structure */
+typedef struct {
+    char* path;       /* the path to the open file */
+    uint64_t modtime; /* modification time of the opened file */
+    size_t bufsize;   /* size of the buffer in runes */
+    char* bufstart;   /* start of the data buffer */
+    char* bufend;     /* end of the data buffer */
+    char* gapstart;   /* start of the gap */
+    char* gapend;     /* end of the gap */
+    Log* undo;        /* undo list */
+    Log* redo;        /* redo list */
+    bool modified;    /* tracks whether the buffer has been modified */
+    uint transid;     /* tracks the last used transaction id for log entries */
+    Sel selection;    /* the currently selected text */
+} Buf;
+
 void buf_init(Buf* buf);
 size_t buf_load(Buf* buf, char* path);
 void buf_reload(Buf* buf);
@@ -103,14 +97,13 @@ typedef struct {
 } Row;
 
 typedef struct {
-    Buf buffer;         /* the buffer used to populate the view */
-    Sel selection;      /* range of currently selected text */
-    size_t nrows;       /* number of rows in the view */
-    size_t ncols;       /* number of columns in the view */
-    Row** rows;         /* array of row data structures */
-    int clrnor, clrsel; /* text color pairs for normal and selected text */
-    bool sync_needed;   /* whether the view needs to be synced with cursor */
-    bool sync_center;   /* cursor should be centered on screen if possible */
+    Buf buffer;          /* the buffer used to populate the view */
+    Sel selection;       /* range of currently selected text */
+    int clrnor, clrsel;  /* text color pairs for normal and selected text */
+    size_t nrows, ncols; /* number of rows and columns in the view */
+    Row** rows;          /* array of row data structures */
+    bool sync_needed;    /* whether the view needs to be synced with cursor */
+    bool sync_center;    /* cursor should be centered on screen if possible */
 } View;
 
 enum {
index 436281077cd03f285d710c9281990eeedb960bc6..8eda7155b9f8b90f2237d47be82acb98ff32cabc 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -30,14 +30,15 @@ void buf_init(Buf* buf) {
         buf_logclear(buf);
     }
     /* reset the state to defaults */
-    buf->modified    = false;
-    buf->bufsize     = 8192;
-    buf->bufstart    = (char*)malloc(buf->bufsize);
-    buf->bufend      = buf->bufstart + buf->bufsize;
-    buf->gapstart    = buf->bufstart;
-    buf->gapend      = buf->bufend;
-    buf->undo        = NULL;
-    buf->redo        = NULL;
+    buf->modified  = false;
+    buf->bufsize   = 8192;
+    buf->bufstart  = (char*)malloc(buf->bufsize);
+    buf->bufend    = buf->bufstart + buf->bufsize;
+    buf->gapstart  = buf->bufstart;
+    buf->gapend    = buf->bufend;
+    buf->undo      = NULL;
+    buf->redo      = NULL;
+    buf->selection = (Sel){0,0,0};
     assert(buf->bufstart);
 }