mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Revert "vim-patch:8.0.1723: using one item array size declaration is misleading" (#10583)
This reverts commit 315076a26d
.
This commit is contained in:
parent
4aabe4a0d5
commit
0d5f629208
@ -133,14 +133,14 @@ typedef struct buffheader buffheader_T;
|
|||||||
*/
|
*/
|
||||||
struct buffblock {
|
struct buffblock {
|
||||||
buffblock_T *b_next; // pointer to next buffblock
|
buffblock_T *b_next; // pointer to next buffblock
|
||||||
char_u b_str[]; // contents (flexible array)
|
char_u b_str[1]; // contents (actually longer)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* header used for the stuff buffer and the redo buffer
|
* header used for the stuff buffer and the redo buffer
|
||||||
*/
|
*/
|
||||||
struct buffheader {
|
struct buffheader {
|
||||||
buffblock_T *bh_first; // first block of the list
|
buffblock_T bh_first; // first (dummy) block of list
|
||||||
buffblock_T *bh_curr; // buffblock for appending
|
buffblock_T *bh_curr; // buffblock for appending
|
||||||
size_t bh_index; // index for reading
|
size_t bh_index; // index for reading
|
||||||
size_t bh_space; // space in bh_curr for appending
|
size_t bh_space; // space in bh_curr for appending
|
||||||
|
@ -78,15 +78,15 @@ FileDescriptor *scriptin[NSCRIPT] = { NULL };
|
|||||||
|
|
||||||
#define MINIMAL_SIZE 20 /* minimal size for b_str */
|
#define MINIMAL_SIZE 20 /* minimal size for b_str */
|
||||||
|
|
||||||
static buffheader_T redobuff = { NULL, NULL, 0, 0 };
|
static buffheader_T redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||||
static buffheader_T old_redobuff = { NULL, NULL, 0, 0 };
|
static buffheader_T old_redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||||
static buffheader_T recordbuff = { NULL, NULL, 0, 0 };
|
static buffheader_T recordbuff = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||||
|
|
||||||
// First read ahead buffer. Used for translated commands.
|
// First read ahead buffer. Used for translated commands.
|
||||||
static buffheader_T readbuf1 = { NULL, NULL, 0, 0 };
|
static buffheader_T readbuf1 = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||||
|
|
||||||
// Second read ahead buffer. Used for redo.
|
// Second read ahead buffer. Used for redo.
|
||||||
static buffheader_T readbuf2 = { NULL, NULL, 0, 0 };
|
static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||||
|
|
||||||
static int typeahead_char = 0; /* typeahead char that's not flushed */
|
static int typeahead_char = 0; /* typeahead char that's not flushed */
|
||||||
|
|
||||||
@ -164,12 +164,11 @@ void free_buff(buffheader_T *buf)
|
|||||||
{
|
{
|
||||||
buffblock_T *p, *np;
|
buffblock_T *p, *np;
|
||||||
|
|
||||||
for (p = buf->bh_first; p != NULL; p = np) {
|
for (p = buf->bh_first.b_next; p != NULL; p = np) {
|
||||||
np = p->b_next;
|
np = p->b_next;
|
||||||
xfree(p);
|
xfree(p);
|
||||||
}
|
}
|
||||||
buf->bh_first = NULL;
|
buf->bh_first.b_next = NULL;
|
||||||
buf->bh_curr = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -185,14 +184,15 @@ static char_u *get_buffcont(buffheader_T *buffer,
|
|||||||
char_u *p2;
|
char_u *p2;
|
||||||
|
|
||||||
// compute the total length of the string
|
// compute the total length of the string
|
||||||
for (const buffblock_T *bp = buffer->bh_first; bp != NULL; bp = bp->b_next) {
|
for (const buffblock_T *bp = buffer->bh_first.b_next;
|
||||||
|
bp != NULL; bp = bp->b_next) {
|
||||||
count += STRLEN(bp->b_str);
|
count += STRLEN(bp->b_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count || dozero) {
|
if (count || dozero) {
|
||||||
p = xmalloc(count + 1);
|
p = xmalloc(count + 1);
|
||||||
p2 = p;
|
p2 = p;
|
||||||
for (const buffblock_T *bp = buffer->bh_first;
|
for (const buffblock_T *bp = buffer->bh_first.b_next;
|
||||||
bp != NULL; bp = bp->b_next) {
|
bp != NULL; bp = bp->b_next) {
|
||||||
for (const char_u *str = bp->b_str; *str;) {
|
for (const char_u *str = bp->b_str; *str;) {
|
||||||
*p2++ = *str++;
|
*p2++ = *str++;
|
||||||
@ -262,16 +262,16 @@ static void add_buff(buffheader_T *const buf, const char *const s,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf->bh_first == NULL) { // first add to list
|
if (buf->bh_first.b_next == NULL) { // first add to list
|
||||||
buf->bh_space = 0;
|
buf->bh_space = 0;
|
||||||
buf->bh_curr = NULL;
|
buf->bh_curr = &(buf->bh_first);
|
||||||
} else if (buf->bh_curr == NULL) { // buffer has already been read
|
} else if (buf->bh_curr == NULL) { // buffer has already been read
|
||||||
IEMSG(_("E222: Add to read buffer"));
|
IEMSG(_("E222: Add to read buffer"));
|
||||||
return;
|
return;
|
||||||
} else if (buf->bh_index != 0) {
|
} else if (buf->bh_index != 0) {
|
||||||
memmove(buf->bh_first->b_str,
|
memmove(buf->bh_first.b_next->b_str,
|
||||||
buf->bh_first->b_str + buf->bh_index,
|
buf->bh_first.b_next->b_str + buf->bh_index,
|
||||||
STRLEN(buf->bh_first->b_str + buf->bh_index) + 1);
|
STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
|
||||||
}
|
}
|
||||||
buf->bh_index = 0;
|
buf->bh_index = 0;
|
||||||
|
|
||||||
@ -286,19 +286,13 @@ static void add_buff(buffheader_T *const buf, const char *const s,
|
|||||||
} else {
|
} else {
|
||||||
len = (size_t)slen;
|
len = (size_t)slen;
|
||||||
}
|
}
|
||||||
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len + 1);
|
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len);
|
||||||
buf->bh_space = len - (size_t)slen;
|
buf->bh_space = len - (size_t)slen;
|
||||||
STRLCPY(p->b_str, s, slen + 1);
|
STRLCPY(p->b_str, s, slen + 1);
|
||||||
|
|
||||||
if (buf->bh_curr == NULL) {
|
p->b_next = buf->bh_curr->b_next;
|
||||||
p->b_next = NULL;
|
buf->bh_curr->b_next = p;
|
||||||
buf->bh_first = p;
|
buf->bh_curr = p;
|
||||||
buf->bh_curr = p;
|
|
||||||
} else {
|
|
||||||
p->b_next = buf->bh_curr->b_next;
|
|
||||||
buf->bh_curr->b_next = p;
|
|
||||||
buf->bh_curr = p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -368,16 +362,16 @@ static int read_readbuf(buffheader_T *buf, int advance)
|
|||||||
{
|
{
|
||||||
char_u c;
|
char_u c;
|
||||||
|
|
||||||
if (buf->bh_first == NULL) { // buffer is empty
|
if (buf->bh_first.b_next == NULL) { // buffer is empty
|
||||||
return NUL;
|
return NUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffblock_T *const curr = buf->bh_first;
|
buffblock_T *const curr = buf->bh_first.b_next;
|
||||||
c = curr->b_str[buf->bh_index];
|
c = curr->b_str[buf->bh_index];
|
||||||
|
|
||||||
if (advance) {
|
if (advance) {
|
||||||
if (curr->b_str[++buf->bh_index] == NUL) {
|
if (curr->b_str[++buf->bh_index] == NUL) {
|
||||||
buf->bh_first = curr->b_next;
|
buf->bh_first.b_next = curr->b_next;
|
||||||
xfree(curr);
|
xfree(curr);
|
||||||
buf->bh_index = 0;
|
buf->bh_index = 0;
|
||||||
}
|
}
|
||||||
@ -390,12 +384,12 @@ static int read_readbuf(buffheader_T *buf, int advance)
|
|||||||
*/
|
*/
|
||||||
static void start_stuff(void)
|
static void start_stuff(void)
|
||||||
{
|
{
|
||||||
if (readbuf1.bh_first != NULL) {
|
if (readbuf1.bh_first.b_next != NULL) {
|
||||||
readbuf1.bh_curr = readbuf1.bh_first;
|
readbuf1.bh_curr = &(readbuf1.bh_first);
|
||||||
readbuf1.bh_space = 0;
|
readbuf1.bh_space = 0;
|
||||||
}
|
}
|
||||||
if (readbuf2.bh_first != NULL) {
|
if (readbuf2.bh_first.b_next != NULL) {
|
||||||
readbuf2.bh_curr = readbuf2.bh_first;
|
readbuf2.bh_curr = &(readbuf2.bh_first);
|
||||||
readbuf2.bh_space = 0;
|
readbuf2.bh_space = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,8 +399,7 @@ static void start_stuff(void)
|
|||||||
*/
|
*/
|
||||||
int stuff_empty(void)
|
int stuff_empty(void)
|
||||||
{
|
{
|
||||||
return (readbuf1.bh_first == NULL
|
return (readbuf1.bh_first.b_next == NULL && readbuf2.bh_first.b_next == NULL);
|
||||||
&& readbuf2.bh_first == NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -415,7 +408,7 @@ int stuff_empty(void)
|
|||||||
*/
|
*/
|
||||||
int readbuf1_empty(void)
|
int readbuf1_empty(void)
|
||||||
{
|
{
|
||||||
return (readbuf1.bh_first == NULL);
|
return (readbuf1.bh_first.b_next == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -473,7 +466,7 @@ void ResetRedobuff(void)
|
|||||||
if (!block_redo) {
|
if (!block_redo) {
|
||||||
free_buff(&old_redobuff);
|
free_buff(&old_redobuff);
|
||||||
old_redobuff = redobuff;
|
old_redobuff = redobuff;
|
||||||
redobuff.bh_first = NULL;
|
redobuff.bh_first.b_next = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,7 +479,7 @@ void CancelRedo(void)
|
|||||||
if (!block_redo) {
|
if (!block_redo) {
|
||||||
free_buff(&redobuff);
|
free_buff(&redobuff);
|
||||||
redobuff = old_redobuff;
|
redobuff = old_redobuff;
|
||||||
old_redobuff.bh_first = NULL;
|
old_redobuff.bh_first.b_next = NULL;
|
||||||
start_stuff();
|
start_stuff();
|
||||||
while (read_readbuffers(TRUE) != NUL) {
|
while (read_readbuffers(TRUE) != NUL) {
|
||||||
}
|
}
|
||||||
@ -498,9 +491,9 @@ void CancelRedo(void)
|
|||||||
void saveRedobuff(save_redo_T *save_redo)
|
void saveRedobuff(save_redo_T *save_redo)
|
||||||
{
|
{
|
||||||
save_redo->sr_redobuff = redobuff;
|
save_redo->sr_redobuff = redobuff;
|
||||||
redobuff.bh_first = NULL;
|
redobuff.bh_first.b_next = NULL;
|
||||||
save_redo->sr_old_redobuff = old_redobuff;
|
save_redo->sr_old_redobuff = old_redobuff;
|
||||||
old_redobuff.bh_first = NULL;
|
old_redobuff.bh_first.b_next = NULL;
|
||||||
|
|
||||||
// Make a copy, so that ":normal ." in a function works.
|
// Make a copy, so that ":normal ." in a function works.
|
||||||
char *const s = (char *)get_buffcont(&save_redo->sr_redobuff, false);
|
char *const s = (char *)get_buffcont(&save_redo->sr_redobuff, false);
|
||||||
@ -680,7 +673,7 @@ static int read_redo(bool init, bool old_redo)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (init) {
|
if (init) {
|
||||||
bp = old_redo ? old_redobuff.bh_first : redobuff.bh_first;
|
bp = old_redo ? old_redobuff.bh_first.b_next : redobuff.bh_first.b_next;
|
||||||
if (bp == NULL) {
|
if (bp == NULL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -1218,9 +1211,9 @@ void save_typeahead(tasave_T *tp)
|
|||||||
old_char = -1;
|
old_char = -1;
|
||||||
|
|
||||||
tp->save_readbuf1 = readbuf1;
|
tp->save_readbuf1 = readbuf1;
|
||||||
readbuf1.bh_first = NULL;
|
readbuf1.bh_first.b_next = NULL;
|
||||||
tp->save_readbuf2 = readbuf2;
|
tp->save_readbuf2 = readbuf2;
|
||||||
readbuf2.bh_first = NULL;
|
readbuf2.bh_first.b_next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user