aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/getchar.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-07-22 23:37:20 -0400
committerDaniel Hahler <git@thequod.de>2019-07-23 05:37:20 +0200
commit0d5f629208bc916bdefaea690177846e9269b4fa (patch)
treee58bf58deef490cdfefedd539cdc4c531bd11b1f /src/nvim/getchar.c
parent4aabe4a0d58ca678fc4d33d6ece845c2eea0b781 (diff)
downloadrneovim-0d5f629208bc916bdefaea690177846e9269b4fa.tar.gz
rneovim-0d5f629208bc916bdefaea690177846e9269b4fa.tar.bz2
rneovim-0d5f629208bc916bdefaea690177846e9269b4fa.zip
Revert "vim-patch:8.0.1723: using one item array size declaration is misleading" (#10583)
This reverts commit 315076a26d225a3bdc34a2cbba1f124adf4e1087.
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r--src/nvim/getchar.c77
1 files changed, 35 insertions, 42 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index de6535dc78..28d37f3581 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -78,15 +78,15 @@ FileDescriptor *scriptin[NSCRIPT] = { NULL };
#define MINIMAL_SIZE 20 /* minimal size for b_str */
-static buffheader_T redobuff = { NULL, NULL, 0, 0 };
-static buffheader_T old_redobuff = { NULL, NULL, 0, 0 };
-static buffheader_T recordbuff = { NULL, NULL, 0, 0 };
+static buffheader_T redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
+static buffheader_T old_redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
+static buffheader_T recordbuff = { { NULL, { NUL } }, NULL, 0, 0 };
// 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.
-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 */
@@ -164,12 +164,11 @@ void free_buff(buffheader_T *buf)
{
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;
xfree(p);
}
- buf->bh_first = NULL;
- buf->bh_curr = NULL;
+ buf->bh_first.b_next = NULL;
}
/*
@@ -185,14 +184,15 @@ static char_u *get_buffcont(buffheader_T *buffer,
char_u *p2;
// 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);
}
if (count || dozero) {
p = xmalloc(count + 1);
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) {
for (const char_u *str = bp->b_str; *str;) {
*p2++ = *str++;
@@ -262,16 +262,16 @@ static void add_buff(buffheader_T *const buf, const char *const s,
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_curr = NULL;
+ buf->bh_curr = &(buf->bh_first);
} else if (buf->bh_curr == NULL) { // buffer has already been read
IEMSG(_("E222: Add to read buffer"));
return;
} else if (buf->bh_index != 0) {
- memmove(buf->bh_first->b_str,
- buf->bh_first->b_str + buf->bh_index,
- STRLEN(buf->bh_first->b_str + buf->bh_index) + 1);
+ memmove(buf->bh_first.b_next->b_str,
+ buf->bh_first.b_next->b_str + buf->bh_index,
+ STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
}
buf->bh_index = 0;
@@ -286,19 +286,13 @@ static void add_buff(buffheader_T *const buf, const char *const s,
} else {
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;
STRLCPY(p->b_str, s, slen + 1);
- if (buf->bh_curr == NULL) {
- p->b_next = NULL;
- buf->bh_first = p;
- buf->bh_curr = p;
- } else {
- p->b_next = buf->bh_curr->b_next;
- buf->bh_curr->b_next = p;
- buf->bh_curr = p;
- }
+ p->b_next = buf->bh_curr->b_next;
+ buf->bh_curr->b_next = p;
+ buf->bh_curr = p;
}
return;
}
@@ -368,16 +362,16 @@ static int read_readbuf(buffheader_T *buf, int advance)
{
char_u c;
- if (buf->bh_first == NULL) { // buffer is empty
+ if (buf->bh_first.b_next == NULL) { // buffer is empty
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];
if (advance) {
if (curr->b_str[++buf->bh_index] == NUL) {
- buf->bh_first = curr->b_next;
+ buf->bh_first.b_next = curr->b_next;
xfree(curr);
buf->bh_index = 0;
}
@@ -390,12 +384,12 @@ static int read_readbuf(buffheader_T *buf, int advance)
*/
static void start_stuff(void)
{
- if (readbuf1.bh_first != NULL) {
- readbuf1.bh_curr = readbuf1.bh_first;
+ if (readbuf1.bh_first.b_next != NULL) {
+ readbuf1.bh_curr = &(readbuf1.bh_first);
readbuf1.bh_space = 0;
}
- if (readbuf2.bh_first != NULL) {
- readbuf2.bh_curr = readbuf2.bh_first;
+ if (readbuf2.bh_first.b_next != NULL) {
+ readbuf2.bh_curr = &(readbuf2.bh_first);
readbuf2.bh_space = 0;
}
}
@@ -405,8 +399,7 @@ static void start_stuff(void)
*/
int stuff_empty(void)
{
- return (readbuf1.bh_first == NULL
- && readbuf2.bh_first == NULL);
+ return (readbuf1.bh_first.b_next == NULL && readbuf2.bh_first.b_next == NULL);
}
/*
@@ -415,7 +408,7 @@ int stuff_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) {
free_buff(&old_redobuff);
old_redobuff = redobuff;
- redobuff.bh_first = NULL;
+ redobuff.bh_first.b_next = NULL;
}
}
@@ -486,7 +479,7 @@ void CancelRedo(void)
if (!block_redo) {
free_buff(&redobuff);
redobuff = old_redobuff;
- old_redobuff.bh_first = NULL;
+ old_redobuff.bh_first.b_next = NULL;
start_stuff();
while (read_readbuffers(TRUE) != NUL) {
}
@@ -498,9 +491,9 @@ void CancelRedo(void)
void saveRedobuff(save_redo_T *save_redo)
{
save_redo->sr_redobuff = redobuff;
- redobuff.bh_first = NULL;
+ redobuff.bh_first.b_next = NULL;
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.
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;
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) {
return FAIL;
}
@@ -1218,9 +1211,9 @@ void save_typeahead(tasave_T *tp)
old_char = -1;
tp->save_readbuf1 = readbuf1;
- readbuf1.bh_first = NULL;
+ readbuf1.bh_first.b_next = NULL;
tp->save_readbuf2 = readbuf2;
- readbuf2.bh_first = NULL;
+ readbuf2.bh_first.b_next = NULL;
}
/*