basic search and naming
This commit is contained in:
parent
8a94a7bcb8
commit
1c7d2a7621
BIN
.sconsign.dblite
BIN
.sconsign.dblite
Binary file not shown.
@ -4,14 +4,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
void bufInit (buf *b)
|
void bufInit (fbuffer *b)
|
||||||
{
|
{
|
||||||
b->rw = NULL;
|
b->rw = NULL;
|
||||||
b->rownum = 0;
|
b->rownum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a row to the file buffer */
|
/* 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 */
|
/* Extend the block of memory containing the lines */
|
||||||
row *newr = realloc(b->rw, (b->rownum + 1) * sizeof(row));
|
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;
|
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 */
|
/* MOVE THE ROWS AWAY */
|
||||||
/* add another line to the bottom containing the previous
|
/* add another line to the bottom containing the previous
|
||||||
@ -152,7 +152,7 @@ void rowAppendString (row *rw, char *s, int len)
|
|||||||
updateRender(rw);
|
updateRender(rw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rowDeleteRow (buf *b, int pos)
|
void rowDeleteRow (fbuffer *b, int pos)
|
||||||
{
|
{
|
||||||
if (b->rownum == 1) return;
|
if (b->rownum == 1) return;
|
||||||
if (pos >= b->rownum) return;
|
if (pos >= b->rownum) return;
|
||||||
|
@ -19,21 +19,21 @@ typedef struct row {
|
|||||||
|
|
||||||
/* Rows structure (or file buffer)
|
/* Rows structure (or file buffer)
|
||||||
* defines rows and teh number of rows */
|
* defines rows and teh number of rows */
|
||||||
typedef struct buf{
|
typedef struct fbuffer{
|
||||||
row *rw;
|
row *rw;
|
||||||
int rownum;
|
int rownum;
|
||||||
} buf;
|
} fbuffer;
|
||||||
|
|
||||||
void bufInit (buf *b);
|
void bufInit (fbuffer *b);
|
||||||
|
|
||||||
void rowAddChar (row *rw, char c, int pos);
|
void rowAddChar (row *rw, char c, int pos);
|
||||||
int rowDeleteChar (row *rw, int select, int pos);
|
int rowDeleteChar (row *rw, int select, int pos);
|
||||||
void rowCpy (row *to, row *from);
|
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 rowFree (row *rw);
|
||||||
void rowAppendString (row *rw, char *s, int len);
|
void rowAppendString (row *rw, char *s, int len);
|
||||||
void rowDeleteRow (buf *b, int pos);
|
void rowDeleteRow (fbuffer *b, int pos);
|
||||||
void rowAddLast (buf *b, char *s, int len);
|
void rowAddLast (fbuffer *b, char *s, int len);
|
||||||
|
|
||||||
void updateRender (row *rw);
|
void updateRender (row *rw);
|
||||||
|
|
||||||
|
55
src/ste.c
55
src/ste.c
@ -12,6 +12,13 @@
|
|||||||
#define STAT_SIZE 128
|
#define STAT_SIZE 128
|
||||||
#define _XOPEN_SOURCE_EXTENDED
|
#define _XOPEN_SOURCE_EXTENDED
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
#define SBUF_SIZE 2048
|
||||||
|
|
||||||
|
// Search buffer
|
||||||
|
typedef struct sbuf {
|
||||||
|
char c[SBUF_SIZE];
|
||||||
|
int num;
|
||||||
|
} sbuf;
|
||||||
|
|
||||||
/* main data structure containing:
|
/* main data structure containing:
|
||||||
* -cursor position
|
* -cursor position
|
||||||
@ -37,9 +44,11 @@ struct term {
|
|||||||
|
|
||||||
char statusbar[STAT_SIZE];
|
char statusbar[STAT_SIZE];
|
||||||
int pad;
|
int pad;
|
||||||
|
char mode_b;
|
||||||
|
sbuf search_buffer;
|
||||||
} t;
|
} t;
|
||||||
|
|
||||||
buf rows;
|
fbuffer rows;
|
||||||
|
|
||||||
const char *msg[] = {
|
const char *msg[] = {
|
||||||
"Find: ",
|
"Find: ",
|
||||||
@ -73,6 +82,9 @@ static void handleDel (int select);
|
|||||||
/* testing */
|
/* testing */
|
||||||
static void updateInfo (void);
|
static void updateInfo (void);
|
||||||
static int whatsThat (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 ------------------------------------ */
|
/* --------------------------------- main ------------------------------------ */
|
||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
@ -124,9 +136,19 @@ int main (int argc, char *argv[])
|
|||||||
case (KEY_ENTER):
|
case (KEY_ENTER):
|
||||||
case (10):
|
case (10):
|
||||||
case ('\r'):
|
case ('\r'):
|
||||||
|
if ((t.mode_b & 0x1) == 0x0) {
|
||||||
rowAddRow(&rows, t.cur.y, t.cur.x);
|
rowAddRow(&rows, t.cur.y, t.cur.x);
|
||||||
t.cur.y++;
|
t.cur.y++;
|
||||||
t.cur.x = 0;
|
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;
|
break;
|
||||||
|
|
||||||
case (KEY_END):
|
case (KEY_END):
|
||||||
@ -138,16 +160,25 @@ int main (int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case (CTRL('f')):
|
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;
|
t.cur.y = 0;
|
||||||
editorFind("for", &t.cur.y, &t.cur.x);
|
editorFind("for", &t.cur.y, &t.cur.x);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
// Toggle mode
|
||||||
|
t.mode_b ^= 0x1;
|
||||||
|
flush (&t.search_buffer);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
if ((t.mode_b & 0x1) == 0x0) {
|
||||||
if (c == KEY_STAB) c = '\t';
|
if (c == KEY_STAB) c = '\t';
|
||||||
rowAddChar(&rows.rw[t.cur.y], c, t.cur.x);
|
rowAddChar(&rows.rw[t.cur.y], c, t.cur.x);
|
||||||
t.cur.x++;
|
t.cur.x++;
|
||||||
|
} else {
|
||||||
|
insert(&t.search_buffer, c);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,4 +589,22 @@ int editorFind (const char* needle, int *y, int *x)
|
|||||||
*x = i;
|
*x = i;
|
||||||
return 1;
|
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 ------------------------------------*/
|
/*--------------------------------- testing ------------------------------------*/
|
||||||
|
@ -63,3 +63,7 @@
|
|||||||
"inline", "register"
|
"inline", "register"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
"ignore" : ["(", ")", "[", "]", "{", "}"]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user