aboutsummaryrefslogtreecommitdiff
path: root/scripts/kconfig/libcurses/getch.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/libcurses/getch.c')
-rw-r--r--scripts/kconfig/libcurses/getch.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/scripts/kconfig/libcurses/getch.c b/scripts/kconfig/libcurses/getch.c
index fa0c674b5..8719ca39c 100644
--- a/scripts/kconfig/libcurses/getch.c
+++ b/scripts/kconfig/libcurses/getch.c
@@ -93,14 +93,6 @@ getch
93 93
94#include <stdlib.h> 94#include <stdlib.h>
95 95
96#define _INBUFSIZ 512 /* size of terminal input buffer */
97#define NUNGETCH 256 /* max # chars to ungetch() */
98
99static int c_pindex = 0; /* putter index */
100static int c_gindex = 1; /* getter index */
101static int c_ungind = 0; /* ungetch() push index */
102static int c_ungch[NUNGETCH]; /* array of ungotten chars */
103
104static int _get_box(int *y_start, int *y_end, int *x_start, int *x_end) 96static int _get_box(int *y_start, int *y_end, int *x_start, int *x_end)
105{ 97{
106 int start, end; 98 int start, end;
@@ -166,7 +158,7 @@ static void _copy(void)
166 158
167#ifdef PDC_WIDE 159#ifdef PDC_WIDE
168 wtmp = malloc((len + 1) * sizeof(wchar_t)); 160 wtmp = malloc((len + 1) * sizeof(wchar_t));
169 len *= 3; 161 len *= 4;
170#endif 162#endif
171 tmp = malloc(len + 1); 163 tmp = malloc(len + 1);
172 164
@@ -204,7 +196,7 @@ static int _paste(void)
204# define PASTE paste 196# define PASTE paste
205#endif 197#endif
206 char *paste; 198 char *paste;
207 long len; 199 long len, newmax;
208 int key; 200 int key;
209 201
210 key = PDC_getclipboard(&paste, &len); 202 key = PDC_getclipboard(&paste, &len);
@@ -215,6 +207,14 @@ static int _paste(void)
215 wpaste = malloc(len * sizeof(wchar_t)); 207 wpaste = malloc(len * sizeof(wchar_t));
216 len = PDC_mbstowcs(wpaste, paste, len); 208 len = PDC_mbstowcs(wpaste, paste, len);
217#endif 209#endif
210 newmax = len + SP->c_ungind;
211 if (newmax > SP->c_ungmax)
212 {
213 SP->c_ungch = realloc(SP->c_ungch, newmax * sizeof(int));
214 if (!SP->c_ungch)
215 return -1;
216 SP->c_ungmax = newmax;
217 }
218 while (len > 1) 218 while (len > 1)
219 PDC_ungetch(PASTE[--len]); 219 PDC_ungetch(PASTE[--len]);
220 key = *PASTE; 220 key = *PASTE;
@@ -322,7 +322,6 @@ static int _mouse_key(void)
322 322
323int wgetch(WINDOW *win) 323int wgetch(WINDOW *win)
324{ 324{
325 static int buffer[_INBUFSIZ]; /* character buffer */
326 int key, waitcount; 325 int key, waitcount;
327 326
328 PDC_LOG(("wgetch() - called\n")); 327 PDC_LOG(("wgetch() - called\n"));
@@ -357,18 +356,18 @@ int wgetch(WINDOW *win)
357 356
358 /* if ungotten char exists, remove and return it */ 357 /* if ungotten char exists, remove and return it */
359 358
360 if (c_ungind) 359 if (SP->c_ungind)
361 return c_ungch[--c_ungind]; 360 return SP->c_ungch[--(SP->c_ungind)];
362 361
363 /* if normal and data in buffer */ 362 /* if normal and data in buffer */
364 363
365 if ((!SP->raw_inp && !SP->cbreak) && (c_gindex < c_pindex)) 364 if ((!SP->raw_inp && !SP->cbreak) && (SP->c_gindex < SP->c_pindex))
366 return buffer[c_gindex++]; 365 return SP->c_buffer[SP->c_gindex++];
367 366
368 /* prepare to buffer data */ 367 /* prepare to buffer data */
369 368
370 c_pindex = 0; 369 SP->c_pindex = 0;
371 c_gindex = 0; 370 SP->c_gindex = 0;
372 371
373 /* to get here, no keys are buffered. go and get one. */ 372 /* to get here, no keys are buffered. go and get one. */
374 373
@@ -453,17 +452,17 @@ int wgetch(WINDOW *win)
453 452
454 if (key == '\b') 453 if (key == '\b')
455 { 454 {
456 if (c_pindex > c_gindex) 455 if (SP->c_pindex > SP->c_gindex)
457 c_pindex--; 456 SP->c_pindex--;
458 } 457 }
459 else 458 else
460 if (c_pindex < _INBUFSIZ - 2) 459 if (SP->c_pindex < _INBUFSIZ - 2)
461 buffer[c_pindex++] = key; 460 SP->c_buffer[SP->c_pindex++] = key;
462 461
463 /* if we got a line */ 462 /* if we got a line */
464 463
465 if (key == '\n' || key == '\r') 464 if (key == '\n' || key == '\r')
466 return buffer[c_gindex++]; 465 return SP->c_buffer[SP->c_gindex++];
467 } 466 }
468} 467}
469 468
@@ -491,10 +490,10 @@ int PDC_ungetch(int ch)
491{ 490{
492 PDC_LOG(("ungetch() - called\n")); 491 PDC_LOG(("ungetch() - called\n"));
493 492
494 if (c_ungind >= NUNGETCH) /* pushback stack full */ 493 if (SP->c_ungind >= SP->c_ungmax) /* pushback stack full */
495 return ERR; 494 return ERR;
496 495
497 c_ungch[c_ungind++] = ch; 496 SP->c_ungch[SP->c_ungind++] = ch;
498 497
499 return OK; 498 return OK;
500} 499}
@@ -503,11 +502,14 @@ int flushinp(void)
503{ 502{
504 PDC_LOG(("flushinp() - called\n")); 503 PDC_LOG(("flushinp() - called\n"));
505 504
505 if (!SP)
506 return ERR;
507
506 PDC_flushinp(); 508 PDC_flushinp();
507 509
508 c_gindex = 1; /* set indices to kill buffer */ 510 SP->c_gindex = 1; /* set indices to kill buffer */
509 c_pindex = 0; 511 SP->c_pindex = 0;
510 c_ungind = 0; /* clear c_ungch array */ 512 SP->c_ungind = 0; /* clear SP->c_ungch array */
511 513
512 return OK; 514 return OK;
513} 515}