comparison src/getchar.c @ 13726:d35b1702a1da v8.0.1735

patch 8.0.1735: flexible array member feature not supported by HP-UX commit https://github.com/vim/vim/commit/285e3358696b1bc6296e5d4c53425680ce8fbd54 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Apr 18 23:01:13 2018 +0200 patch 8.0.1735: flexible array member feature not supported by HP-UX Problem: Flexible array member feature not supported by HP-UX. (John Marriott) Solution: Do not use the flexible array member feature of C99.
author Christian Brabandt <cb@256bit.org>
date Wed, 18 Apr 2018 23:15:06 +0200
parents c3bf339a9d2d
children 9de2b25932eb
comparison
equal deleted inserted replaced
13725:25ffa5f27874 13726:d35b1702a1da
38 * Un-escaping is done by vgetc(). 38 * Un-escaping is done by vgetc().
39 */ 39 */
40 40
41 #define MINIMAL_SIZE 20 /* minimal size for b_str */ 41 #define MINIMAL_SIZE 20 /* minimal size for b_str */
42 42
43 static buffheader_T redobuff = {NULL, NULL, 0, 0}; 43 static buffheader_T redobuff = {{NULL, {NUL}}, NULL, 0, 0};
44 static buffheader_T old_redobuff = {NULL, NULL, 0, 0}; 44 static buffheader_T old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
45 static buffheader_T recordbuff = {NULL, NULL, 0, 0}; 45 static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0};
46 46
47 static int typeahead_char = 0; /* typeahead char that's not flushed */ 47 static int typeahead_char = 0; /* typeahead char that's not flushed */
48 48
49 /* 49 /*
50 * when block_redo is TRUE redo buffer will not be changed 50 * when block_redo is TRUE redo buffer will not be changed
136 void 136 void
137 free_buff(buffheader_T *buf) 137 free_buff(buffheader_T *buf)
138 { 138 {
139 buffblock_T *p, *np; 139 buffblock_T *p, *np;
140 140
141 for (p = buf->bh_first; p != NULL; p = np) 141 for (p = buf->bh_first.b_next; p != NULL; p = np)
142 { 142 {
143 np = p->b_next; 143 np = p->b_next;
144 vim_free(p); 144 vim_free(p);
145 } 145 }
146 buf->bh_first = NULL; 146 buf->bh_first.b_next = NULL;
147 buf->bh_curr = NULL;
148 } 147 }
149 148
150 /* 149 /*
151 * Return the contents of a buffer as a single string. 150 * Return the contents of a buffer as a single string.
152 * K_SPECIAL and CSI in the returned string are escaped. 151 * K_SPECIAL and CSI in the returned string are escaped.
158 { 157 {
159 long_u count = 0; 158 long_u count = 0;
160 char_u *p = NULL; 159 char_u *p = NULL;
161 char_u *p2; 160 char_u *p2;
162 char_u *str; 161 char_u *str;
163 buffblock_T *bp; 162 buffblock_T *bp;
164 163
165 /* compute the total length of the string */ 164 /* compute the total length of the string */
166 for (bp = buffer->bh_first; bp != NULL; bp = bp->b_next) 165 for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
167 count += (long_u)STRLEN(bp->b_str); 166 count += (long_u)STRLEN(bp->b_str);
168 167
169 if ((count || dozero) && (p = lalloc(count + 1, TRUE)) != NULL) 168 if ((count || dozero) && (p = lalloc(count + 1, TRUE)) != NULL)
170 { 169 {
171 p2 = p; 170 p2 = p;
172 for (bp = buffer->bh_first; bp != NULL; bp = bp->b_next) 171 for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
173 for (str = bp->b_str; *str; ) 172 for (str = bp->b_str; *str; )
174 *p2++ = *str++; 173 *p2++ = *str++;
175 *p2 = NUL; 174 *p2 = NUL;
176 } 175 }
177 return (p); 176 return (p);
231 buffheader_T *buf, 230 buffheader_T *buf,
232 char_u *s, 231 char_u *s,
233 long slen) /* length of "s" or -1 */ 232 long slen) /* length of "s" or -1 */
234 { 233 {
235 buffblock_T *p; 234 buffblock_T *p;
236 long_u len; 235 long_u len;
237 236
238 if (slen < 0) 237 if (slen < 0)
239 slen = (long)STRLEN(s); 238 slen = (long)STRLEN(s);
240 if (slen == 0) /* don't add empty strings */ 239 if (slen == 0) /* don't add empty strings */
241 return; 240 return;
242 241
243 if (buf->bh_first == NULL) /* first add to list */ 242 if (buf->bh_first.b_next == NULL) /* first add to list */
244 { 243 {
245 buf->bh_space = 0; 244 buf->bh_space = 0;
246 buf->bh_curr = NULL; 245 buf->bh_curr = &(buf->bh_first);
247 } 246 }
248 else if (buf->bh_curr == NULL) /* buffer has already been read */ 247 else if (buf->bh_curr == NULL) /* buffer has already been read */
249 { 248 {
250 IEMSG(_("E222: Add to read buffer")); 249 IEMSG(_("E222: Add to read buffer"));
251 return; 250 return;
252 } 251 }
253 else if (buf->bh_index != 0) 252 else if (buf->bh_index != 0)
254 mch_memmove(buf->bh_first->b_str, 253 mch_memmove(buf->bh_first.b_next->b_str,
255 buf->bh_first->b_str + buf->bh_index, 254 buf->bh_first.b_next->b_str + buf->bh_index,
256 STRLEN(buf->bh_first->b_str + buf->bh_index) + 1); 255 STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
257 buf->bh_index = 0; 256 buf->bh_index = 0;
258 257
259 if (buf->bh_space >= (int)slen) 258 if (buf->bh_space >= (int)slen)
260 { 259 {
261 len = (long_u)STRLEN(buf->bh_curr->b_str); 260 len = (long_u)STRLEN(buf->bh_curr->b_str);
266 { 265 {
267 if (slen < MINIMAL_SIZE) 266 if (slen < MINIMAL_SIZE)
268 len = MINIMAL_SIZE; 267 len = MINIMAL_SIZE;
269 else 268 else
270 len = slen; 269 len = slen;
271 p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len + 1), 270 p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len),
272 TRUE); 271 TRUE);
273 if (p == NULL) 272 if (p == NULL)
274 return; /* no space, just forget it */ 273 return; /* no space, just forget it */
275 buf->bh_space = (int)(len - slen); 274 buf->bh_space = (int)(len - slen);
276 vim_strncpy(p->b_str, s, (size_t)slen); 275 vim_strncpy(p->b_str, s, (size_t)slen);
277 276
278 if (buf->bh_curr == NULL) 277 p->b_next = buf->bh_curr->b_next;
279 { 278 buf->bh_curr->b_next = p;
280 p->b_next = NULL; 279 buf->bh_curr = p;
281 buf->bh_first = p;
282 buf->bh_curr = p;
283 }
284 else
285 {
286 p->b_next = buf->bh_curr->b_next;
287 buf->bh_curr->b_next = p;
288 buf->bh_curr = p;
289 }
290 } 280 }
291 return; 281 return;
292 } 282 }
293 283
294 /* 284 /*
356 } 346 }
357 #endif 347 #endif
358 } 348 }
359 349
360 /* First read ahead buffer. Used for translated commands. */ 350 /* First read ahead buffer. Used for translated commands. */
361 static buffheader_T readbuf1 = {NULL, NULL, 0, 0}; 351 static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0};
362 352
363 /* Second read ahead buffer. Used for redo. */ 353 /* Second read ahead buffer. Used for redo. */
364 static buffheader_T readbuf2 = {NULL, NULL, 0, 0}; 354 static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0};
365 355
366 /* 356 /*
367 * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2 357 * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2
368 * if that one is empty. 358 * if that one is empty.
369 * If advance == TRUE go to the next char. 359 * If advance == TRUE go to the next char.
384 read_readbuf(buffheader_T *buf, int advance) 374 read_readbuf(buffheader_T *buf, int advance)
385 { 375 {
386 char_u c; 376 char_u c;
387 buffblock_T *curr; 377 buffblock_T *curr;
388 378
389 if (buf->bh_first == NULL) /* buffer is empty */ 379 if (buf->bh_first.b_next == NULL) /* buffer is empty */
390 return NUL; 380 return NUL;
391 381
392 curr = buf->bh_first; 382 curr = buf->bh_first.b_next;
393 c = curr->b_str[buf->bh_index]; 383 c = curr->b_str[buf->bh_index];
394 384
395 if (advance) 385 if (advance)
396 { 386 {
397 if (curr->b_str[++buf->bh_index] == NUL) 387 if (curr->b_str[++buf->bh_index] == NUL)
398 { 388 {
399 buf->bh_first = curr->b_next; 389 buf->bh_first.b_next = curr->b_next;
400 vim_free(curr); 390 vim_free(curr);
401 buf->bh_index = 0; 391 buf->bh_index = 0;
402 } 392 }
403 } 393 }
404 return c; 394 return c;
408 * Prepare the read buffers for reading (if they contain something). 398 * Prepare the read buffers for reading (if they contain something).
409 */ 399 */
410 static void 400 static void
411 start_stuff(void) 401 start_stuff(void)
412 { 402 {
413 if (readbuf1.bh_first != NULL) 403 if (readbuf1.bh_first.b_next != NULL)
414 { 404 {
415 readbuf1.bh_curr = readbuf1.bh_first; 405 readbuf1.bh_curr = &(readbuf1.bh_first);
416 readbuf1.bh_space = 0; 406 readbuf1.bh_space = 0;
417 } 407 }
418 if (readbuf2.bh_first != NULL) 408 if (readbuf2.bh_first.b_next != NULL)
419 { 409 {
420 readbuf2.bh_curr = readbuf2.bh_first; 410 readbuf2.bh_curr = &(readbuf2.bh_first);
421 readbuf2.bh_space = 0; 411 readbuf2.bh_space = 0;
422 } 412 }
423 } 413 }
424 414
425 /* 415 /*
426 * Return TRUE if the stuff buffer is empty. 416 * Return TRUE if the stuff buffer is empty.
427 */ 417 */
428 int 418 int
429 stuff_empty(void) 419 stuff_empty(void)
430 { 420 {
431 return (readbuf1.bh_first == NULL 421 return (readbuf1.bh_first.b_next == NULL
432 && readbuf2.bh_first == NULL); 422 && readbuf2.bh_first.b_next == NULL);
433 } 423 }
434 424
435 /* 425 /*
436 * Return TRUE if readbuf1 is empty. There may still be redo characters in 426 * Return TRUE if readbuf1 is empty. There may still be redo characters in
437 * redbuf2. 427 * redbuf2.
438 */ 428 */
439 int 429 int
440 readbuf1_empty(void) 430 readbuf1_empty(void)
441 { 431 {
442 return (readbuf1.bh_first == NULL); 432 return (readbuf1.bh_first.b_next == NULL);
443 } 433 }
444 434
445 /* 435 /*
446 * Set a typeahead character that won't be flushed. 436 * Set a typeahead character that won't be flushed.
447 */ 437 */
502 { 492 {
503 if (!block_redo) 493 if (!block_redo)
504 { 494 {
505 free_buff(&old_redobuff); 495 free_buff(&old_redobuff);
506 old_redobuff = redobuff; 496 old_redobuff = redobuff;
507 redobuff.bh_first = NULL; 497 redobuff.bh_first.b_next = NULL;
508 } 498 }
509 } 499 }
510 500
511 /* 501 /*
512 * Discard the contents of the redo buffer and restore the previous redo 502 * Discard the contents of the redo buffer and restore the previous redo
517 { 507 {
518 if (!block_redo) 508 if (!block_redo)
519 { 509 {
520 free_buff(&redobuff); 510 free_buff(&redobuff);
521 redobuff = old_redobuff; 511 redobuff = old_redobuff;
522 old_redobuff.bh_first = NULL; 512 old_redobuff.bh_first.b_next = NULL;
523 start_stuff(); 513 start_stuff();
524 while (read_readbuffers(TRUE) != NUL) 514 while (read_readbuffers(TRUE) != NUL)
525 ; 515 ;
526 } 516 }
527 } 517 }
534 saveRedobuff(save_redo_T *save_redo) 524 saveRedobuff(save_redo_T *save_redo)
535 { 525 {
536 char_u *s; 526 char_u *s;
537 527
538 save_redo->sr_redobuff = redobuff; 528 save_redo->sr_redobuff = redobuff;
539 redobuff.bh_first = NULL; 529 redobuff.bh_first.b_next = NULL;
540 save_redo->sr_old_redobuff = old_redobuff; 530 save_redo->sr_old_redobuff = old_redobuff;
541 old_redobuff.bh_first = NULL; 531 old_redobuff.bh_first.b_next = NULL;
542 532
543 /* Make a copy, so that ":normal ." in a function works. */ 533 /* Make a copy, so that ":normal ." in a function works. */
544 s = get_buffcont(&save_redo->sr_redobuff, FALSE); 534 s = get_buffcont(&save_redo->sr_redobuff, FALSE);
545 if (s != NULL) 535 if (s != NULL)
546 { 536 {
755 #endif 745 #endif
756 746
757 if (init) 747 if (init)
758 { 748 {
759 if (old_redo) 749 if (old_redo)
760 bp = old_redobuff.bh_first; 750 bp = old_redobuff.bh_first.b_next;
761 else 751 else
762 bp = redobuff.bh_first; 752 bp = redobuff.bh_first.b_next;
763 if (bp == NULL) 753 if (bp == NULL)
764 return FAIL; 754 return FAIL;
765 p = bp->b_str; 755 p = bp->b_str;
766 return OK; 756 return OK;
767 } 757 }
1380 tp->old_char = old_char; 1370 tp->old_char = old_char;
1381 tp->old_mod_mask = old_mod_mask; 1371 tp->old_mod_mask = old_mod_mask;
1382 old_char = -1; 1372 old_char = -1;
1383 1373
1384 tp->save_readbuf1 = readbuf1; 1374 tp->save_readbuf1 = readbuf1;
1385 readbuf1.bh_first = NULL; 1375 readbuf1.bh_first.b_next = NULL;
1386 tp->save_readbuf2 = readbuf2; 1376 tp->save_readbuf2 = readbuf2;
1387 readbuf2.bh_first = NULL; 1377 readbuf2.bh_first.b_next = NULL;
1388 # ifdef USE_INPUT_BUF 1378 # ifdef USE_INPUT_BUF
1389 tp->save_inputbuf = get_input_buf(); 1379 tp->save_inputbuf = get_input_buf();
1390 # endif 1380 # endif
1391 } 1381 }
1392 1382