|
|
@ -4,17 +4,17 @@ |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
|
|
|
|
void bufInit (fbuffer *b) |
|
|
|
void bufInit (FileBuffer *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 (fbuffer *b, char *s, int len) |
|
|
|
void rowAddLast (FileBuffer *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)); |
|
|
|
//if (newr == NULL) termDie("realloc in rowAddLast");
|
|
|
|
//if (newr == NULL) termDie("realloc in rowAddLast");
|
|
|
|
b->rw = newr; |
|
|
|
b->rw = newr; |
|
|
|
|
|
|
|
|
|
|
@ -29,7 +29,7 @@ void rowAddLast (fbuffer *b, char *s, int len) |
|
|
|
b->rownum++; |
|
|
|
b->rownum++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rowAddChar (row *rw, char c, int pos) |
|
|
|
void rowAddChar (Row *rw, char c, int pos) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Check if char is valid */ |
|
|
|
/* Check if char is valid */ |
|
|
|
if (!c || (iscntrl(c) && c != '\t')) return; |
|
|
|
if (!c || (iscntrl(c) && c != '\t')) return; |
|
|
@ -49,7 +49,7 @@ void rowAddChar (row *rw, char c, int pos) |
|
|
|
updateRender(rw); |
|
|
|
updateRender(rw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int rowDeleteChar (row *rw, int select, int pos) // WIP
|
|
|
|
int rowDeleteChar (Row *rw, int select, int pos) // WIP
|
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Check if the character is valid */ |
|
|
|
/* Check if the character is valid */ |
|
|
|
if (rw->chars[pos - 1] == '\0' && pos) return 0; |
|
|
|
if (rw->chars[pos - 1] == '\0' && pos) return 0; |
|
|
@ -68,7 +68,7 @@ int rowDeleteChar (row *rw, int select, int pos) // WIP |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rowAddRow (fbuffer *b, int pos, int cur) // WIP; TO DOCUMENT |
|
|
|
void rowAddRow (FileBuffer *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
|
|
|
@ -83,7 +83,7 @@ void rowAddRow (fbuffer *b, int pos, int cur) // WIP; TO DOCUMENT |
|
|
|
/* Get the row length at position after the cursor */ |
|
|
|
/* Get the row length at position after the cursor */ |
|
|
|
int len = b->rw[pos].size - cur; |
|
|
|
int len = b->rw[pos].size - cur; |
|
|
|
/* create a dummy row as the new row souce */ |
|
|
|
/* create a dummy row as the new row souce */ |
|
|
|
row nex = EROW; |
|
|
|
Row nex = EROW; |
|
|
|
/* allocate a buffer */ |
|
|
|
/* allocate a buffer */ |
|
|
|
char *s = malloc(len + 1); |
|
|
|
char *s = malloc(len + 1); |
|
|
|
//if (s == NULL) termDie("malloc in rowAddRow s");
|
|
|
|
//if (s == NULL) termDie("malloc in rowAddRow s");
|
|
|
@ -111,7 +111,7 @@ void rowAddRow (fbuffer *b, int pos, int cur) // WIP; TO DOCUMENT |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rowFree (row *rw) // WIP
|
|
|
|
void rowFree (Row *rw) // WIP
|
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Free both render and memory strings */ |
|
|
|
/* Free both render and memory strings */ |
|
|
|
free(rw->render); |
|
|
|
free(rw->render); |
|
|
@ -122,7 +122,7 @@ void rowFree (row *rw) // WIP |
|
|
|
rw->utf = 0; |
|
|
|
rw->utf = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rowCpy (row *to, row *from) // WIP
|
|
|
|
void rowCpy (Row *to, Row *from) // WIP
|
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Free the destination row (without destroying it) */ |
|
|
|
/* Free the destination row (without destroying it) */ |
|
|
|
rowFree(to); |
|
|
|
rowFree(to); |
|
|
@ -138,7 +138,7 @@ void rowCpy (row *to, row *from) // WIP |
|
|
|
updateRender(to); |
|
|
|
updateRender(to); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rowAppendString (row *rw, char *s, int len) |
|
|
|
void rowAppendString (Row *rw, char *s, int len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* reallocate the row to accomodate for the added string */ |
|
|
|
/* reallocate the row to accomodate for the added string */ |
|
|
|
char *temp = realloc(rw->chars, rw->size + len + 1); |
|
|
|
char *temp = realloc(rw->chars, rw->size + len + 1); |
|
|
@ -152,7 +152,7 @@ void rowAppendString (row *rw, char *s, int len) |
|
|
|
updateRender(rw); |
|
|
|
updateRender(rw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void rowDeleteRow (fbuffer *b, int pos) |
|
|
|
void rowDeleteRow (FileBuffer *b, int pos) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (b->rownum == 1) return; |
|
|
|
if (b->rownum == 1) return; |
|
|
|
if (pos >= b->rownum) return; |
|
|
|
if (pos >= b->rownum) return; |
|
|
@ -163,12 +163,12 @@ void rowDeleteRow (fbuffer *b, int pos) |
|
|
|
} |
|
|
|
} |
|
|
|
b->rownum--; |
|
|
|
b->rownum--; |
|
|
|
rowFree(&b->rw[b->rownum]); |
|
|
|
rowFree(&b->rw[b->rownum]); |
|
|
|
row *temp = realloc(b->rw, sizeof(row) * b->rownum); |
|
|
|
Row *temp = realloc(b->rw, sizeof(Row) * b->rownum); |
|
|
|
//if (temp == NULL) termDie("realloc in rowDeleteRow");
|
|
|
|
//if (temp == NULL) termDie("realloc in rowDeleteRow");
|
|
|
|
b->rw = temp; |
|
|
|
b->rw = temp; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void updateRender (row *rw) |
|
|
|
void updateRender (Row *rw) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* count the special characters
|
|
|
|
/* count the special characters
|
|
|
|
* spaces, utf-8 continuation chars */ |
|
|
|
* spaces, utf-8 continuation chars */ |
|
|
|