inputstr.c (5940c9ab) inputstr.c (a8e38dc0)
1/*
1/*
2 * $Id: inputstr.c,v 1.90 2019/07/24 23:42:20 tom Exp $
2 * $Id: inputstr.c,v 1.95 2022/04/06 08:03:09 tom Exp $
3 *
4 * inputstr.c -- functions for input/display of a string
5 *
3 *
4 * inputstr.c -- functions for input/display of a string
5 *
6 * Copyright 2000-2018,2019 Thomas E. Dickey
6 * Copyright 2000-2021,2022 Thomas E. Dickey
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
22 */
23
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
22 */
23
24#include <dialog.h>
24#include <dlg_internals.h>
25#include <dlg_keys.h>
26
25#include <dlg_keys.h>
26
27#include <errno.h>
28
29#ifdef HAVE_SETLOCALE
30#include <locale.h>
31#endif
32
33#if defined(HAVE_SEARCH_H) && defined(HAVE_TSEARCH)
34#include <search.h>
35#else
36#undef HAVE_TSEARCH
37#endif
38
39#ifdef NEED_WCHAR_H
40#include <wchar.h>
41#endif
42
43#if defined(USE_WIDE_CURSES)
44#define USE_CACHING 1
45#elif defined(HAVE_XDIALOG)
46#define USE_CACHING 1 /* editbox really needs caching! */
47#else
48#define USE_CACHING 0
49#endif
50

--- 354 unchanged lines hidden (view full) ---

405 */
406const int *
407dlg_index_columns(const char *string)
408{
409 unsigned len = (unsigned) dlg_count_wchars(string);
410 CACHE *cache = load_cache(cInxCols, string);
411
412 if (!same_cache2(cache, string, len)) {
27#if defined(USE_WIDE_CURSES)
28#define USE_CACHING 1
29#elif defined(HAVE_XDIALOG)
30#define USE_CACHING 1 /* editbox really needs caching! */
31#else
32#define USE_CACHING 0
33#endif
34

--- 354 unchanged lines hidden (view full) ---

389 */
390const int *
391dlg_index_columns(const char *string)
392{
393 unsigned len = (unsigned) dlg_count_wchars(string);
394 CACHE *cache = load_cache(cInxCols, string);
395
396 if (!same_cache2(cache, string, len)) {
413 unsigned inx;
414
415 cache->list[0] = 0;
416#ifdef USE_WIDE_CURSES
417 if (have_locale()) {
397
398 cache->list[0] = 0;
399#ifdef USE_WIDE_CURSES
400 if (have_locale()) {
401 unsigned inx;
418 size_t num_bytes = strlen(string);
419 const int *inx_wchars = dlg_index_wchars(string);
420 mbstate_t state;
421
422 for (inx = 0; inx < len; ++inx) {
423 int result;
424
425 if (string[inx_wchars[inx]] == TAB) {

--- 23 unchanged lines hidden (view full) ---

449 }
450 cache->list[inx + 1] = result;
451 if (inx != 0)
452 cache->list[inx + 1] += cache->list[inx];
453 }
454 } else
455#endif /* USE_WIDE_CURSES */
456 {
402 size_t num_bytes = strlen(string);
403 const int *inx_wchars = dlg_index_wchars(string);
404 mbstate_t state;
405
406 for (inx = 0; inx < len; ++inx) {
407 int result;
408
409 if (string[inx_wchars[inx]] == TAB) {

--- 23 unchanged lines hidden (view full) ---

433 }
434 cache->list[inx + 1] = result;
435 if (inx != 0)
436 cache->list[inx + 1] += cache->list[inx];
437 }
438 } else
439#endif /* USE_WIDE_CURSES */
440 {
441 unsigned inx;
442
457 for (inx = 0; inx < len; ++inx) {
458 chtype ch = UCH(string[inx]);
459
460 if (ch == TAB)
461 cache->list[inx + 1] =
462 ((cache->list[inx] | 7) + 1) - cache->list[inx];
463 else if (isprint(UCH(ch)))
464 cache->list[inx + 1] = 1;

--- 54 unchanged lines hidden (view full) ---

519bool
520dlg_edit_string(char *string, int *chr_offset, int key, int fkey, bool force)
521{
522 int i;
523 int len = (int) strlen(string);
524 int limit = dlg_count_wchars(string);
525 const int *indx = dlg_index_wchars(string);
526 int offset = dlg_find_index(indx, limit, *chr_offset);
443 for (inx = 0; inx < len; ++inx) {
444 chtype ch = UCH(string[inx]);
445
446 if (ch == TAB)
447 cache->list[inx + 1] =
448 ((cache->list[inx] | 7) + 1) - cache->list[inx];
449 else if (isprint(UCH(ch)))
450 cache->list[inx + 1] = 1;

--- 54 unchanged lines hidden (view full) ---

505bool
506dlg_edit_string(char *string, int *chr_offset, int key, int fkey, bool force)
507{
508 int i;
509 int len = (int) strlen(string);
510 int limit = dlg_count_wchars(string);
511 const int *indx = dlg_index_wchars(string);
512 int offset = dlg_find_index(indx, limit, *chr_offset);
527 int max_len = dlg_max_input(MAX_LEN);
528 bool edit = TRUE;
529
530 /* transform editing characters into equivalent function-keys */
531 if (!fkey) {
532 fkey = TRUE; /* assume we transform */
533 switch (key) {
534 case 0:
535 break;

--- 86 unchanged lines hidden (view full) ---

622 default:
623 beep();
624 break;
625 }
626 } else {
627 if (key == ESC || key == ERR) {
628 edit = 0;
629 } else {
513 bool edit = TRUE;
514
515 /* transform editing characters into equivalent function-keys */
516 if (!fkey) {
517 fkey = TRUE; /* assume we transform */
518 switch (key) {
519 case 0:
520 break;

--- 86 unchanged lines hidden (view full) ---

607 default:
608 beep();
609 break;
610 }
611 } else {
612 if (key == ESC || key == ERR) {
613 edit = 0;
614 } else {
630 if (len < max_len) {
615 if (len < dlg_max_input(-1)) {
631 for (i = ++len; i > *chr_offset; i--)
632 string[i] = string[i - 1];
633 string[*chr_offset] = (char) key;
634 *chr_offset += 1;
635 } else {
636 (void) beep();
637 }
638 }

--- 168 unchanged lines hidden ---
616 for (i = ++len; i > *chr_offset; i--)
617 string[i] = string[i - 1];
618 string[*chr_offset] = (char) key;
619 *chr_offset += 1;
620 } else {
621 (void) beep();
622 }
623 }

--- 168 unchanged lines hidden ---