diff --git a/.sconsign.dblite b/.sconsign.dblite index 3d0adeb..36752fa 100644 Binary files a/.sconsign.dblite and b/.sconsign.dblite differ diff --git a/src/fbuffer.c b/src/fbuffer.c index 8cbd05b..c3f6d92 100644 --- a/src/fbuffer.c +++ b/src/fbuffer.c @@ -4,14 +4,14 @@ #include #include -void bufInit (buf *b) +void bufInit (fbuffer *b) { b->rw = NULL; b->rownum = 0; } /* Add a row to the file buffer */ -void rowAddLast (buf *b, char *s, int len) +void rowAddLast (fbuffer *b, char *s, int len) { /* Extend the block of memory containing the lines */ row *newr = realloc(b->rw, (b->rownum + 1) * sizeof(row)); @@ -68,7 +68,7 @@ int rowDeleteChar (row *rw, int select, int pos) // WIP return 1; } -void rowAddRow (buf *b, int pos, int cur) // WIP; TO DOCUMENT +void rowAddRow (fbuffer *b, int pos, int cur) // WIP; TO DOCUMENT { /* MOVE THE ROWS AWAY */ /* add another line to the bottom containing the previous @@ -152,7 +152,7 @@ void rowAppendString (row *rw, char *s, int len) updateRender(rw); } -void rowDeleteRow (buf *b, int pos) +void rowDeleteRow (fbuffer *b, int pos) { if (b->rownum == 1) return; if (pos >= b->rownum) return; diff --git a/src/fbuffer.h b/src/fbuffer.h index 2bdfd8f..da423e7 100644 --- a/src/fbuffer.h +++ b/src/fbuffer.h @@ -19,21 +19,21 @@ typedef struct row { /* Rows structure (or file buffer) * defines rows and teh number of rows */ -typedef struct buf{ +typedef struct fbuffer{ row *rw; int rownum; -} buf; +} fbuffer; -void bufInit (buf *b); +void bufInit (fbuffer *b); void rowAddChar (row *rw, char c, int pos); int rowDeleteChar (row *rw, int select, int pos); void rowCpy (row *to, row *from); -void rowAddRow (buf *b, int pos, int cur); +void rowAddRow (fbuffer *b, int pos, int cur); void rowFree (row *rw); void rowAppendString (row *rw, char *s, int len); -void rowDeleteRow (buf *b, int pos); -void rowAddLast (buf *b, char *s, int len); +void rowDeleteRow (fbuffer *b, int pos); +void rowAddLast (fbuffer *b, char *s, int len); void updateRender (row *rw); diff --git a/src/ste.c b/src/ste.c index cc8faa3..3a14fa1 100644 --- a/src/ste.c +++ b/src/ste.c @@ -12,6 +12,13 @@ #define STAT_SIZE 128 #define _XOPEN_SOURCE_EXTENDED #define _GNU_SOURCE +#define SBUF_SIZE 2048 + +// Search buffer +typedef struct sbuf { + char c[SBUF_SIZE]; + int num; +} sbuf; /* main data structure containing: * -cursor position @@ -37,9 +44,11 @@ struct term { char statusbar[STAT_SIZE]; int pad; + char mode_b; + sbuf search_buffer; } t; -buf rows; +fbuffer rows; const char *msg[] = { "Find: ", @@ -73,6 +82,9 @@ static void handleDel (int select); /* testing */ static void updateInfo (void); static int whatsThat (void); +static void insert (sbuf *buf, int c); +static inline void flush (sbuf *buf); +static void toString (sbuf *buf, char *s); /* --------------------------------- main ------------------------------------ */ int main (int argc, char *argv[]) @@ -124,9 +136,19 @@ int main (int argc, char *argv[]) case (KEY_ENTER): case (10): case ('\r'): - rowAddRow(&rows, t.cur.y, t.cur.x); - t.cur.y++; - t.cur.x = 0; + if ((t.mode_b & 0x1) == 0x0) { + rowAddRow(&rows, t.cur.y, t.cur.x); + t.cur.y++; + t.cur.x = 0; + } else { + char *query = malloc(t.search_buffer.num + 1); + if (query == NULL) termDie("maloc in query allocation"); + toString(&t.search_buffer, query); + editorFind(query, &t.cur.y, &t.cur.x); + // Toggle mode + t.mode_b ^= 0x1; + flush (&t.search_buffer); + } break; case (KEY_END): @@ -138,16 +160,25 @@ int main (int argc, char *argv[]) break; case (CTRL('f')): - if (!editorFind("for", &t.cur.y, &t.cur.x)) { + /*if (!editorFind("for", &t.cur.y, &t.cur.x)) { t.cur.y = 0; editorFind("for", &t.cur.y, &t.cur.x); - } + }*/ + + // Toggle mode + t.mode_b ^= 0x1; + flush (&t.search_buffer); + break; default: - if (c == KEY_STAB) c = '\t'; - rowAddChar(&rows.rw[t.cur.y], c, t.cur.x); - t.cur.x++; + if ((t.mode_b & 0x1) == 0x0) { + if (c == KEY_STAB) c = '\t'; + rowAddChar(&rows.rw[t.cur.y], c, t.cur.x); + t.cur.x++; + } else { + insert(&t.search_buffer, c); + } break; } } @@ -558,4 +589,22 @@ int editorFind (const char* needle, int *y, int *x) *x = i; return 1; } + +void insert (sbuf *buf, int c) +{ + if (buf->num < SBUF_SIZE - 1) + buf->c[buf->num++] = c; +} + +void flush (sbuf *buf) +{ + buf->num = 0; +} + +void toString (sbuf *buf, char *s) +{ + for (int i = 0; i < buf->num; i++) + s[i] = buf->c[i]; + s[buf->num] = '\0'; +} /*--------------------------------- testing ------------------------------------*/ diff --git a/src/ste.o b/src/ste.o index 75c6d5d..e57b5f7 100644 Binary files a/src/ste.o and b/src/ste.o differ diff --git a/syntax/stes-c.json b/syntax/stes-c.json index 4d160b3..3648f98 100644 --- a/syntax/stes-c.json +++ b/syntax/stes-c.json @@ -62,4 +62,8 @@ "signed", "unsigned", "inline", "register" ] +} + +{ + "ignore" : ["(", ")", "[", "]", "{", "}"] } \ No newline at end of file