basic search and naming

master
Alessandro Mauri 4 years ago
parent 8a94a7bcb8
commit 1c7d2a7621
  1. BIN
      .sconsign.dblite
  2. 8
      src/fbuffer.c
  3. 12
      src/fbuffer.h
  4. 67
      src/ste.c
  5. BIN
      src/ste.o
  6. 4
      syntax/stes-c.json

Binary file not shown.

@ -4,14 +4,14 @@
#include <string.h>
#include <ctype.h>
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;

@ -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);

@ -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 ------------------------------------*/

Binary file not shown.

@ -62,4 +62,8 @@
"signed", "unsigned",
"inline", "register"
]
}
{
"ignore" : ["(", ")", "[", "]", "{", "}"]
}
Loading…
Cancel
Save