|
|
@ -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'): |
|
|
|
rowAddRow(&rows, t.cur.y, t.cur.x); |
|
|
|
if ((t.mode_b & 0x1) == 0x0) { |
|
|
|
t.cur.y++; |
|
|
|
rowAddRow(&rows, t.cur.y, t.cur.x); |
|
|
|
t.cur.x = 0; |
|
|
|
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; |
|
|
|
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 (c == KEY_STAB) c = '\t'; |
|
|
|
if ((t.mode_b & 0x1) == 0x0) { |
|
|
|
rowAddChar(&rows.rw[t.cur.y], c, t.cur.x); |
|
|
|
if (c == KEY_STAB) c = '\t'; |
|
|
|
t.cur.x++; |
|
|
|
rowAddChar(&rows.rw[t.cur.y], c, 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 ------------------------------------*/ |
|
|
|