1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Copyright (c) 1980, 1993
22 * The Regents of the University of California. All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in the
31 * documentation and/or other materials provided with the distribution.
32 * 3. Neither the name of the University nor the names of its contributors
33 * may be used to endorse or promote products derived from this software
34 * without specific prior written permission.
36 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 #ifndef HAVE_AMALGAMATION
56 # include <readline/readline.h>
58 # include <readline/history.h>
60 #elif defined HAVE_EDITLINE
61 # include <histedit.h>
64 /* Shared history support macros */
66 # define _CL_HISTFILE(S) \
68 S = ok_vlook(NAIL_HISTFILE);\
70 S = fexpand(S, FEXP_LOCAL);\
73 # define _CL_HISTSIZE(V) \
75 char const *__sv = ok_vlook(NAIL_HISTSIZE);\
77 if (__sv == NULL || *__sv == '\0' || (__rv = strtol(__sv, NULL, 10)) == 0)\
85 # define _CL_CHECK_ADDHIST(S,NOACT) \
96 # define C_HISTORY_SHARED \
103 if (argv[1] != NULL)\
105 if (!asccasecmp(*argv, "show"))\
107 if (!asccasecmp(*argv, "clear"))\
109 if ((entry = strtol(*argv, argv, 10)) > 0 && **argv == '\0')\
112 n_err(_("Synopsis: history: %s\n" \
113 "<show> (default), <clear> or select <NO> from editor history"));\
117 return (v == NULL ? !STOP : !OKAY); /* xxx 1:bad 0:good -- do some */
118 #endif /* HAVE_HISTORY */
120 /* fexpand() flags for expand-on-tab */
121 #define _CL_TAB_FEXP_FL (FEXP_FULL | FEXP_SILENT | FEXP_MULTIOK)
124 * Because we have multiple identical implementations, change file layout a bit
125 * and place the implementations one after the other below the other externals
128 static sigjmp_buf __tty_actjmp
; /* TODO someday, we won't need it no more */
130 __tty_acthdl(int s
) /* TODO someday, we won't need it no more */
132 NYD_X
; /* Signal handler */
133 termios_state_reset();
134 siglongjmp(__tty_actjmp
, s
);
138 getapproval(char const * volatile prompt
, bool_t noninteract_default
)
140 sighandler_type
volatile oint
, ohup
;
145 if (!(options
& OPT_INTERACTIVE
)) {
147 rv
= noninteract_default
;
153 prompt
= noninteract_default
? _(" ([yes]/no)? ") : _(" ([no]/yes)? ");
155 oint
= safe_signal(SIGINT
, SIG_IGN
);
156 ohup
= safe_signal(SIGHUP
, SIG_IGN
);
157 if ((sig
= sigsetjmp(__tty_actjmp
, 1)) != 0)
159 safe_signal(SIGINT
, &__tty_acthdl
);
160 safe_signal(SIGHUP
, &__tty_acthdl
);
162 if (readline_input(prompt
, FAL0
, &termios_state
.ts_linebuf
,
163 &termios_state
.ts_linesize
, NULL
) >= 0)
164 rv
= (boolify(termios_state
.ts_linebuf
, UIZ_MAX
,
165 noninteract_default
) > 0);
167 termios_state_reset();
169 safe_signal(SIGHUP
, ohup
);
170 safe_signal(SIGINT
, oint
);
180 getuser(char const * volatile query
) /* TODO v15-compat obsolete */
182 sighandler_type
volatile oint
, ohup
;
183 char * volatile user
= NULL
;
190 oint
= safe_signal(SIGINT
, SIG_IGN
);
191 ohup
= safe_signal(SIGHUP
, SIG_IGN
);
192 if ((sig
= sigsetjmp(__tty_actjmp
, 1)) != 0)
194 safe_signal(SIGINT
, &__tty_acthdl
);
195 safe_signal(SIGHUP
, &__tty_acthdl
);
197 if (readline_input(query
, FAL0
, &termios_state
.ts_linebuf
,
198 &termios_state
.ts_linesize
, NULL
) >= 0)
199 user
= termios_state
.ts_linebuf
;
201 termios_state_reset();
203 safe_signal(SIGHUP
, ohup
);
204 safe_signal(SIGINT
, oint
);
212 getpassword(char const *query
)
214 sighandler_type
volatile oint
, ohup
;
216 char * volatile pass
= NULL
;
221 query
= _("Password: ");
222 fputs(query
, stdout
);
225 /* FIXME everywhere: tcsetattr() generates SIGTTOU when we're not in
226 * FIXME foreground pgrp, and can fail with EINTR!! also affects
227 * FIXME termios_state_reset() */
228 if (options
& OPT_TTYIN
) {
229 tcgetattr(STDIN_FILENO
, &termios_state
.ts_tios
);
230 memcpy(&tios
, &termios_state
.ts_tios
, sizeof tios
);
231 termios_state
.ts_needs_reset
= TRU1
;
232 tios
.c_iflag
&= ~(ISTRIP
);
233 tios
.c_lflag
&= ~(ECHO
| ECHOE
| ECHOK
| ECHONL
);
236 oint
= safe_signal(SIGINT
, SIG_IGN
);
237 ohup
= safe_signal(SIGHUP
, SIG_IGN
);
238 if ((sig
= sigsetjmp(__tty_actjmp
, 1)) != 0)
240 safe_signal(SIGINT
, &__tty_acthdl
);
241 safe_signal(SIGHUP
, &__tty_acthdl
);
243 if (options
& OPT_TTYIN
)
244 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &tios
);
246 if (readline_restart(stdin
, &termios_state
.ts_linebuf
,
247 &termios_state
.ts_linesize
, 0) >= 0)
248 pass
= termios_state
.ts_linebuf
;
250 termios_state_reset();
251 if (options
& OPT_TTYIN
)
254 safe_signal(SIGHUP
, ohup
);
255 safe_signal(SIGINT
, oint
);
261 #endif /* HAVE_SOCKETS */
268 static sighandler_type _rl_shup
;
269 static char * _rl_buf
; /* pre_input() hook: initial line */
270 static int _rl_buflen
; /* content, and its length */
272 static int _rl_pre_input(void);
278 /* Handle leftover data from \ escaped former line */
279 rl_extend_line_buffer(_rl_buflen
+ 10);
280 memcpy(rl_line_buffer
, _rl_buf
, _rl_buflen
+ 1);
281 rl_point
= rl_end
= _rl_buflen
;
282 rl_pre_input_hook
= (rl_hook_func_t
*)NULL
;
297 rl_readline_name
= UNCONST(uagent
);
301 stifle_history((int)hs
);
303 rl_read_init_file(NULL
);
305 /* Because rl_read_init_file() may have introduced yet a different
306 * history size limit, simply load and incorporate the history, leave
307 * it up to readline(3) to do the rest */
336 NYD_X
; /* Signal handler */
344 /* readline(3) doesn't catch it :( */
345 rl_free_line_state();
346 rl_cleanup_after_signal();
347 safe_signal(SIGHUP
, _rl_shup
);
349 sigaddset(&nset
, sig
);
350 sigprocmask(SIG_UNBLOCK
, &nset
, &oset
);
352 /* XXX When we come here we'll continue editing, so reestablish
353 * XXX cannot happen */
354 sigprocmask(SIG_BLOCK
, &oset
, NULL
);
355 _rl_shup
= safe_signal(SIGHUP
, &tty_signal
);
356 rl_reset_after_signal();
364 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
374 rl_pre_input_hook
= &_rl_pre_input
;
377 _rl_shup
= safe_signal(SIGHUP
, &tty_signal
);
378 line
= readline(prompt
!= NULL
? prompt
: "");
379 safe_signal(SIGHUP
, _rl_shup
);
387 if (n
>= *linesize
) {
388 *linesize
= LINESIZE
+ n
+1;
389 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
391 memcpy(*linebuf
, line
, n
);
393 (*linebuf
)[n
] = '\0';
401 tty_addhist(char const *s
, bool_t isgabby
)
407 if (isgabby
&& !ok_blook(history_gabby
))
409 _CL_CHECK_ADDHIST(s
, goto jleave
);
410 hold_all_sigs(); /* XXX too heavy */
411 add_history(s
); /* XXX yet we jump away! */
412 rele_all_sigs(); /* XXX remove jumps */
430 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
432 n_perr(_("tmpfile"), 0);
437 hs
= history_get_history_state();
439 for (i
= (ul_i
)hs
->length
, hl
= hs
->entries
+ i
, b
= 0; i
> 0; --i
) {
440 char *cp
= (*--hl
)->line
;
441 size_t sl
= strlen(cp
);
442 fprintf(fp
, "%4lu. %-50.50s (%4lu+%2lu bytes)\n", i
, cp
, b
, sl
);
446 page_or_print(fp
, (size_t)hs
->length
);
456 HISTORY_STATE
*hs
= history_get_history_state();
458 if (UICMP(z
, entry
, <=, hs
->length
))
459 v
= temporary_arg_v_store
= hs
->entries
[entry
- 1]->line
;
465 # endif /* HAVE_HISTORY */
466 #endif /* HAVE_READLINE */
473 static EditLine
* _el_el
; /* editline(3) handle */
474 static char const * _el_prompt
; /* Current prompt */
476 static History
* _el_hcom
; /* History handle for commline */
479 static char const * _el_getprompt(void);
499 _el_hcom
= history_init();
500 history(_el_hcom
, &he
, H_SETSIZE
, (int)hs
);
501 /* We unroll our own one history(_el_hcom, &he, H_SETUNIQUE, 1);*/
504 _el_el
= el_init(uagent
, stdin
, stdout
, stderr
);
505 el_set(_el_el
, EL_SIGNAL
, 1);
506 el_set(_el_el
, EL_TERMINAL
, NULL
);
507 /* Need to set HIST before EDITOR, otherwise it won't work automatic */
509 el_set(_el_el
, EL_HIST
, &history
, _el_hcom
);
511 el_set(_el_el
, EL_EDITOR
, "emacs");
512 # ifdef EL_PROMPT_ESC
513 el_set(_el_el
, EL_PROMPT_ESC
, &_el_getprompt
, '\1');
515 el_set(_el_el
, EL_PROMPT
, &_el_getprompt
);
518 el_set(_el_el
, EL_ADDFN
, "tab_complete",
519 "editline(3) internal completion function", &_el_file_cpl
);
520 el_set(_el_el
, EL_BIND
, "^I", "tab_complete", NULL
);
523 el_set(_el_el
, EL_BIND
, "^R", "ed-search-prev-history", NULL
);
525 el_source(_el_el
, NULL
); /* Source ~/.editrc */
527 /* Because el_source() may have introduced yet a different history size
528 * limit, simply load and incorporate the history, leave it up to
529 * editline(3) to do the rest */
533 history(_el_hcom
, &he
, H_LOAD
, v
);
552 history(_el_hcom
, &he
, H_SAVE
, v
);
553 history_end(_el_hcom
);
561 NYD_X
; /* Signal handler */
574 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
581 _el_prompt
= (prompt
!= NULL
) ? prompt
: "";
583 el_push(_el_el
, *linebuf
);
584 line
= el_gets(_el_el
, &nn
);
592 if (n
> 0 && line
[n
- 1] == '\n')
595 if (n
>= *linesize
) {
596 *linesize
= LINESIZE
+ n
+ 1;
597 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
599 memcpy(*linebuf
, line
, n
);
600 (*linebuf
)[n
] = '\0';
607 tty_addhist(char const *s
, bool_t isgabby
)
610 /* Enlarge meaning of unique .. to something that rocks;
611 * xxx unfortunately this is expensive to do with editline(3)
612 * xxx maybe it would be better to hook the ptfs instead? */
621 if (isgabby
&& !ok_blook(history_gabby
))
623 _CL_CHECK_ADDHIST(s
, goto jleave
);
625 hold_all_sigs(); /* XXX too heavy, yet we jump away! */
626 for (i
= history(_el_hcom
, &he
, H_FIRST
); i
>= 0;
627 i
= history(_el_hcom
, &he
, H_NEXT
))
628 if (!strcmp(he
.str
, s
)) {
629 history(_el_hcom
, &he
, H_DEL
, he
.num
);
632 history(_el_hcom
, &he
, H_ENTER
, s
);
633 rele_all_sigs(); /* XXX remove jumps */
651 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
653 n_perr(_("tmpfile"), 0);
658 i
= (size_t)((history(_el_hcom
, &he
, H_GETSIZE
) >= 0) ? he
.num
: 0);
660 for (x
= history(_el_hcom
, &he
, H_FIRST
); x
>= 0;
661 x
= history(_el_hcom
, &he
, H_NEXT
)) {
662 size_t sl
= strlen(he
.str
);
663 fprintf(fp
, "%4lu. %-50.50s (%4lu+%2lu bytes)\n",
664 (ul_i
)i
, he
.str
, (ul_i
)b
, (ul_i
)sl
);
669 page_or_print(fp
, i
);
676 history(_el_hcom
, &he
, H_CLEAR
);
685 i
= (size_t)((history(_el_hcom
, &he
, H_GETSIZE
) >= 0) ? he
.num
: 0);
686 if (UICMP(z
, entry
, <=, i
)) {
687 entry
= (long)i
- entry
;
688 for (x
= history(_el_hcom
, &he
, H_FIRST
); x
>= 0;
689 x
= history(_el_hcom
, &he
, H_NEXT
))
691 v
= temporary_arg_v_store
= UNCONST(he
.str
);
699 # endif /* HAVE_HISTORY */
700 #endif /* HAVE_EDITLINE */
703 * NCL: our homebrew version (inspired from NetBSD sh(1) / dash(1)s hetio.c).
705 * Only used in interactive mode, simply use STDIN_FILENO as point of interest.
706 * We do not handle character widths because the terminal must deal with that
707 * anyway on the one hand, and also wcwidth(3) doesn't support zero-width
708 * characters by definition on the other. We're addicted.
710 * To avoid memory leaks etc. with the current codebase that simply longjmp(3)s
711 * we're forced to use the very same buffer--the one that is passed through to
712 * us from the outside--to store anything we need, i.e., a `struct cell[]', and
713 * convert that on-the-fly back to the plain char* result once we're done.
714 * To simplify our live, use savestr() buffers for all other needed memory
719 # define MAX_INPUT 255 /* (_POSIX_MAX_INPUT = 255 as of Issue 7 TC1) */
722 /* Since we simply fputs(3) the prompt, assume each character requires two
723 * visual cells -- and we need to restrict the maximum prompt size because
724 * of MAX_INPUT and our desire to have room for some error message left */
725 # define _PROMPT_VLEN(P) (strlen(P) * 2)
726 # define _PROMPT_MAX ((MAX_INPUT / 2) + (MAX_INPUT / 4))
736 char cbuf
[MB_LEN_MAX
* 2]; /* .. plus reset shift sequence */
740 size_t cursor
; /* Current cursor position */
741 size_t topins
; /* Outermost cursor col set */
743 char *cbuf
; /* *x_buf */
746 struct str defc
; /* Current default content */
747 struct str savec
; /* Saved default content */
749 struct hist
*hist
; /* History cursor */
752 char const *nd
; /* Cursor right */
753 char **x_buf
; /* Caller pointers */
760 struct hist
*younger
;
763 char dat
[VFIELD_SIZE(sizeof(ui32_t
))];
767 static sighandler_type _ncl_oint
;
768 static sighandler_type _ncl_oquit
;
769 static sighandler_type _ncl_oterm
;
770 static sighandler_type _ncl_ohup
;
771 static sighandler_type _ncl_otstp
;
772 static sighandler_type _ncl_ottin
;
773 static sighandler_type _ncl_ottou
;
774 static struct xtios _ncl_tios
;
776 static struct hist
*_ncl_hist
;
777 static struct hist
*_ncl_hist_tail
;
778 static size_t _ncl_hist_size
;
779 static size_t _ncl_hist_size_max
;
780 static bool_t _ncl_hist_load
;
783 static void _ncl_sigs_up(void);
784 static void _ncl_sigs_down(void);
786 static void _ncl_term_mode(bool_t raw
);
788 static void _ncl_check_grow(struct line
*l
, size_t no SMALLOC_DEBUG_ARGS
);
789 static void _ncl_bs_eof_dvup(struct cell
*cap
, size_t i
);
790 static ssize_t
_ncl_wboundary(struct line
*l
, ssize_t dir
);
791 static ssize_t
_ncl_cell2dat(struct line
*l
);
792 # if defined HAVE_HISTORY || defined HAVE_TABEXPAND
793 static void _ncl_cell2save(struct line
*l
);
796 static void _ncl_khome(struct line
*l
, bool_t dobell
);
797 static void _ncl_kend(struct line
*l
);
798 static void _ncl_kbs(struct line
*l
);
799 static void _ncl_kkill(struct line
*l
, bool_t dobell
);
800 static ssize_t
_ncl_keof(struct line
*l
);
801 static void _ncl_kleft(struct line
*l
);
802 static void _ncl_kright(struct line
*l
);
803 static void _ncl_krefresh(struct line
*l
);
804 static void _ncl_kbwddelw(struct line
*l
);
805 static void _ncl_kgow(struct line
*l
, ssize_t dir
);
806 static void _ncl_kother(struct line
*l
, wchar_t wc
);
808 static size_t __ncl_khist_shared(struct line
*l
, struct hist
*hp
);
809 static size_t _ncl_khist(struct line
*l
, bool_t backwd
);
810 static size_t _ncl_krhist(struct line
*l
);
812 # ifdef HAVE_TABEXPAND
813 static size_t _ncl_kht(struct line
*l
);
815 static ssize_t
_ncl_readline(char const *prompt
, char **buf
, size_t *bufsize
,
816 size_t len SMALLOC_DEBUG_ARGS
);
826 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
827 _ncl_oint
= safe_signal(SIGINT
, &tty_signal
);
828 _ncl_oquit
= safe_signal(SIGQUIT
, &tty_signal
);
829 _ncl_oterm
= safe_signal(SIGTERM
, &tty_signal
);
830 _ncl_ohup
= safe_signal(SIGHUP
, &tty_signal
);
831 _ncl_otstp
= safe_signal(SIGTSTP
, &tty_signal
);
832 _ncl_ottin
= safe_signal(SIGTTIN
, &tty_signal
);
833 _ncl_ottou
= safe_signal(SIGTTOU
, &tty_signal
);
834 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
846 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
847 safe_signal(SIGINT
, _ncl_oint
);
848 safe_signal(SIGQUIT
, _ncl_oquit
);
849 safe_signal(SIGTERM
, _ncl_oterm
);
850 safe_signal(SIGHUP
, _ncl_ohup
);
851 safe_signal(SIGTSTP
, _ncl_otstp
);
852 safe_signal(SIGTTIN
, _ncl_ottin
);
853 safe_signal(SIGTTOU
, _ncl_ottou
);
854 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
859 _ncl_term_mode(bool_t raw
)
861 struct termios
*tiosp
;
864 tiosp
= &_ncl_tios
.told
;
868 /* Always requery the attributes, in case we've been moved from background
869 * to foreground or however else in between sessions */
870 /* XXX Always enforce ECHO and ICANON in the OLD attributes - do so as long
871 * XXX as we don't handle terminal stuff when starting commands and don't
872 * XXX properly deal with TTIN and TTOU from all that */
873 tcgetattr(STDIN_FILENO
, tiosp
);
874 tiosp
->c_lflag
|= ECHO
| ICANON
;
876 memcpy(&_ncl_tios
.tnew
, tiosp
, sizeof *tiosp
);
877 tiosp
= &_ncl_tios
.tnew
;
878 tiosp
->c_cc
[VMIN
] = 1;
879 tiosp
->c_cc
[VTIME
] = 0;
880 tiosp
->c_iflag
&= ~(ISTRIP
);
881 tiosp
->c_lflag
&= ~(ECHO
/*| ECHOE | ECHONL */| ICANON
| IEXTEN
);
883 tcsetattr(STDIN_FILENO
, TCSADRAIN
, tiosp
);
888 _ncl_check_grow(struct line
*l
, size_t no SMALLOC_DEBUG_ARGS
)
893 i
= (l
->topins
+ no
) * sizeof(struct cell
) + 2 * sizeof(struct cell
);
894 if (i
>= *l
->x_bufsize
) {
898 *l
->x_buf
= (srealloc
)(*l
->x_buf
, i SMALLOC_DEBUG_ARGSCALL
);
904 _ncl_bs_eof_dvup(struct cell
*cap
, size_t i
)
910 memmove(cap
, cap
+ 1, i
* sizeof(*cap
));
912 /* And.. the (rest of the) visual update */
913 for (j
= 0; j
< i
; ++j
)
914 fwrite(cap
[j
].cbuf
, sizeof *cap
->cbuf
, cap
[j
].count
, stdout
);
915 fputs(" \b", stdout
);
916 for (j
= 0; j
< i
; ++j
)
922 _ncl_wboundary(struct line
*l
, ssize_t dir
)
939 --t
, --c
; /* Unsigned wrapping may occur (twice), then */
941 for (i
= 0, cap
= l
->line
.cells
, anynon
= FAL0
;;) {
942 wchar_t wc
= cap
[c
+ dir
].wc
;
943 if (iswblank(wc
) || iswpunct(wc
)) {
962 _ncl_cell2dat(struct line
*l
)
968 for (i
= 0; i
< l
->topins
; ++i
) {
969 struct cell
*cap
= l
->line
.cells
+ i
;
970 memcpy(l
->line
.cbuf
+ len
, cap
->cbuf
, cap
->count
);
973 l
->line
.cbuf
[len
] = '\0';
978 # if defined HAVE_HISTORY || defined HAVE_TABEXPAND
980 _ncl_cell2save(struct line
*l
)
986 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
990 for (cap
= l
->line
.cells
, len
= i
= 0; i
< l
->topins
; ++cap
, ++i
)
994 l
->savec
.s
= salloc(len
+ 1);
996 for (cap
= l
->line
.cells
, len
= i
= 0; i
< l
->topins
; ++cap
, ++i
) {
997 memcpy(l
->savec
.s
+ len
, cap
->cbuf
, cap
->count
);
1000 l
->savec
.s
[len
] = '\0';
1007 _ncl_khome(struct line
*l
, bool_t dobell
)
1023 _ncl_kend(struct line
*l
)
1028 i
= (ssize_t
)(l
->topins
- l
->cursor
);
1031 l
->cursor
= l
->topins
;
1033 fputs(l
->nd
, stdout
);
1040 _ncl_kbs(struct line
*l
)
1053 _ncl_bs_eof_dvup(l
->line
.cells
+ c
, t
);
1060 _ncl_kkill(struct line
*l
, bool_t dobell
)
1066 i
= (size_t)(l
->topins
- c
);
1070 for (j
= i
; j
!= 0; --j
)
1072 for (j
= i
; j
!= 0; --j
)
1080 _ncl_keof(struct line
*l
)
1088 i
= (ssize_t
)(t
- c
);
1092 _ncl_bs_eof_dvup(l
->line
.cells
+ c
, --i
);
1093 } else if (t
== 0 /*&& !ok_blook(ignoreeof)*/) {
1094 /*fputs("^D", stdout);
1106 _ncl_kleft(struct line
*l
)
1109 if (l
->cursor
> 0) {
1118 _ncl_kright(struct line
*l
)
1121 if (l
->cursor
< l
->topins
) {
1123 fputs(l
->nd
, stdout
);
1130 _ncl_krefresh(struct line
*l
)
1137 if (l
->prompt
!= NULL
&& *l
->prompt
!= '\0')
1138 fputs(l
->prompt
, stdout
);
1139 for (cap
= l
->line
.cells
, i
= l
->topins
; i
> 0; ++cap
, --i
)
1140 fwrite(cap
->cbuf
, sizeof *cap
->cbuf
, cap
->count
, stdout
);
1141 for (i
= l
->topins
- l
->cursor
; i
> 0; --i
)
1147 _ncl_kbwddelw(struct line
*l
)
1154 i
= _ncl_wboundary(l
, -1);
1165 cap
= l
->line
.cells
+ c
;
1167 if (t
!= l
->cursor
) {
1169 memmove(cap
, cap
+ i
, j
* sizeof(*cap
));
1172 for (j
= i
; j
> 0; --j
)
1174 for (j
= l
->topins
- c
; j
> 0; ++cap
, --j
)
1175 fwrite(cap
[0].cbuf
, sizeof *cap
->cbuf
, cap
[0].count
, stdout
);
1176 for (j
= i
; j
> 0; --j
)
1178 for (j
= t
- c
; j
> 0; --j
)
1185 _ncl_kgow(struct line
*l
, ssize_t dir
)
1190 i
= _ncl_wboundary(l
, dir
);
1204 fputs(l
->nd
, stdout
);
1211 _ncl_kother(struct line
*l
, wchar_t wc
)
1213 /* Append if at EOL, insert otherwise;
1214 * since we may move around character-wise, always use a fresh ps */
1216 struct cell cell
, *cap
;
1220 /* First init a cell and see wether we'll really handle this wc */
1222 memset(&ps
, 0, sizeof ps
);
1223 i
= wcrtomb(cell
.cbuf
, wc
, &ps
);
1226 cell
.count
= (ui32_t
)i
;
1227 if (options
& OPT_ENC_MBSTATE
) {
1228 i
= wcrtomb(cell
.cbuf
+ i
, L
'\0', &ps
);
1231 else if (--i
< MB_LEN_MAX
)
1232 cell
.count
+= (ui32_t
)i
;
1237 /* Yes, we will! Place it in the array */
1239 i
= l
->topins
++ - c
;
1240 cap
= l
->line
.cells
+ c
;
1242 memmove(cap
+ 1, cap
, i
* sizeof(cell
));
1243 memcpy(cap
, &cell
, sizeof cell
);
1245 /* And update visual */
1248 fwrite(cap
->cbuf
, sizeof *cap
->cbuf
, cap
->count
, stdout
);
1249 while ((++cap
, i
-- != 0));
1256 # ifdef HAVE_HISTORY
1258 __ncl_khist_shared(struct line
*l
, struct hist
*hp
)
1263 if ((l
->hist
= hp
) != NULL
) {
1264 l
->defc
.s
= savestrbuf(hp
->dat
, hp
->len
);
1266 l
->defc
.l
= hp
->len
;
1267 if (l
->topins
> 0) {
1268 _ncl_khome(l
, FAL0
);
1269 _ncl_kkill(l
, FAL0
);
1280 _ncl_khist(struct line
*l
, bool_t backwd
)
1286 /* If we're not in history mode yet, save line content;
1287 * also, disallow forward search, then, and, of course, bail unless we
1288 * do have any history at all */
1289 if ((hp
= l
->hist
) == NULL
) {
1292 if ((hp
= _ncl_hist
) == NULL
)
1298 hp
= backwd
? hp
->older
: hp
->younger
;
1300 rv
= __ncl_khist_shared(l
, hp
);
1306 _ncl_krhist(struct line
*l
)
1308 struct str orig_savec
;
1309 struct hist
*hp
= NULL
;
1313 /* We cannot complete an empty line */
1314 if (l
->topins
== 0) {
1315 /* XXX The upcoming hard reset would restore a set savec buffer,
1316 * XXX so forcefully reset that. A cleaner solution would be to
1317 * XXX reset it whenever a restore is no longer desired */
1318 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1321 if ((hp
= l
->hist
) == NULL
) {
1322 if ((hp
= _ncl_hist
) == NULL
)
1324 orig_savec
.s
= NULL
;
1325 orig_savec
.l
= 0; /* silence CC */
1326 } else if ((hp
= hp
->older
) == NULL
)
1329 orig_savec
= l
->savec
;
1331 if (orig_savec
.s
== NULL
)
1333 for (; hp
!= NULL
; hp
= hp
->older
)
1334 if (is_prefix(l
->savec
.s
, hp
->dat
))
1336 if (orig_savec
.s
!= NULL
)
1337 l
->savec
= orig_savec
;
1339 rv
= __ncl_khist_shared(l
, hp
);
1345 # ifdef HAVE_TABEXPAND
1347 _ncl_kht(struct line
*l
)
1349 struct str orig
, bot
, topp
, sub
, exp
;
1350 struct cell
*cword
, *ctop
, *cx
;
1351 bool_t set_savec
= FAL0
;
1355 /* We cannot expand an empty line */
1359 /* Get plain line data; if this is the first expansion/xy, update the
1360 * very original content so that ^G gets the origin back */
1370 cword
= l
->line
.cells
;
1371 ctop
= cword
+ l
->cursor
;
1373 /* topp: separate data right of cursor */
1374 if ((cx
= cword
+ l
->topins
) != ctop
) {
1375 for (rv
= 0; cx
> ctop
; --cx
)
1378 topp
.s
= orig
.s
+ orig
.l
- rv
;
1380 topp
.s
= NULL
, topp
.l
= 0;
1382 /* bot, sub: we cannot expand the entire data left of cursor, but only
1383 * the last "word", so separate them */
1384 while (cx
> cword
&& !iswspace(cx
[-1].wc
))
1386 for (rv
= 0; cword
< cx
; ++cword
)
1395 /* Leave room for "implicit asterisk" expansion, as below */
1397 sub
.s
= UNCONST("*");
1400 exp
.s
= salloc(sub
.l
+ 1 +1);
1401 memcpy(exp
.s
, sub
.s
, sub
.l
);
1402 exp
.s
[sub
.l
] = '\0';
1406 /* TODO there is a TODO note upon fexpand() with multi-return;
1407 * TODO if that will change, the if() below can be simplified */
1408 /* Super-Heavy-Metal: block all sigs, avoid leaks on jump */
1411 exp
.s
= fexpand(sub
.s
, _CL_TAB_FEXP_FL
);
1414 if (exp
.s
== NULL
|| (exp
.l
= strlen(exp
.s
)) == 0)
1416 /* If the expansion equals the original string, assume the user wants what
1417 * is usually known as tab completion, append `*' and restart */
1418 if (exp
.l
== sub
.l
&& !strcmp(exp
.s
, sub
.s
)) {
1419 if (sub
.s
[sub
.l
- 1] == '*')
1421 sub
.s
[sub
.l
++] = '*';
1422 sub
.s
[sub
.l
] = '\0';
1426 /* Cramp expansion length to MAX_INPUT, or 255 if not defined.
1427 * Take care to take *prompt* into account, since we don't know
1428 * anything about it's visual length (fputs(3) is used), simply
1429 * assume each character requires two columns */
1430 /* TODO the problem is that we loose control otherwise; in the best
1431 * TODO case the user can control via ^A and ^K etc., but be safe;
1432 * TODO we cannot simply adjust fexpand() because we don't know how
1433 * TODO that is implemented... The real solution would be to check
1434 * TODO wether we fit on a line, and start a pager if not.
1435 * TODO However, that should be part of a real tab-COMPLETION, then,
1436 * TODO i.e., don't EXPAND, but SHOW COMPLETIONS, page-wise if needed.
1437 * TODO And: MAX_INPUT is dynamic: pathconf(2), _SC_MAX_INPUT */
1438 rv
= (l
->prompt
!= NULL
) ? _PROMPT_VLEN(l
->prompt
) : 0;
1439 if (rv
+ bot
.l
+ exp
.l
+ topp
.l
>= MAX_INPUT
) {
1440 exp
.s
= UNCONST("[ERR_TOO_LONG]");
1441 exp
.l
= sizeof("[ERR_TOO_LONG]") - 1;
1443 if (rv
+ bot
.l
+ exp
.l
>= MAX_INPUT
)
1445 if (rv
+ exp
.l
>= MAX_INPUT
) {
1446 exp
.s
= UNCONST("[ERR]");
1447 exp
.l
= sizeof("[ERR]") - 1;
1451 orig
.l
= bot
.l
+ exp
.l
+ topp
.l
;
1452 orig
.s
= salloc(orig
.l
+ 5 +1);
1453 if ((rv
= bot
.l
) > 0)
1454 memcpy(orig
.s
, bot
.s
, rv
);
1455 memcpy(orig
.s
+ rv
, exp
.s
, exp
.l
);
1458 memcpy(orig
.s
+ rv
, topp
.s
, topp
.l
);
1464 _ncl_khome(l
, FAL0
);
1465 _ncl_kkill(l
, FAL0
);
1470 /* If we've provided a default content, but failed to expand, there is
1471 * nothing we can "revert to": drop that default again */
1473 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1477 # endif /* HAVE_TABEXPAND */
1480 _ncl_readline(char const *prompt
, char **buf
, size_t *bufsize
, size_t len
1483 /* We want to save code, yet we may have to incorporate a lines'
1484 * default content and / or default input to switch back to after some
1485 * history movement; let "len > 0" mean "have to display some data
1486 * buffer", and only otherwise read(2) it */
1489 char cbuf_base
[MB_LEN_MAX
* 2], *cbuf
, *cbufp
, cursor_maybe
, cursor_store
;
1494 memset(&l
, 0, sizeof l
);
1497 l
.defc
.s
= savestrbuf(*buf
, len
);
1500 if ((l
.prompt
= prompt
) != NULL
&& _PROMPT_VLEN(prompt
) > _PROMPT_MAX
)
1501 l
.prompt
= prompt
= "?ERR?";
1502 /* TODO *l.nd=='\0' : instead adjust accmacvar.c to disallow empty vals */
1503 if ((l
.nd
= ok_vlook(line_editor_cursor_right
)) == NULL
|| *l
.nd
== '\0')
1504 l
.nd
= "\033[C"; /* XXX no "magic" constant */
1506 l
.x_bufsize
= bufsize
;
1508 if (prompt
!= NULL
&& *prompt
!= '\0')
1509 fputs(prompt
, stdout
);
1513 memset(ps
, 0, sizeof ps
);
1514 cursor_maybe
= cursor_store
= 0;
1515 /* TODO: NCL: we should output the reset sequence when we jrestart:
1516 * TODO: NCL: if we are using a stateful encoding? !
1517 * TODO: NCL: in short: this is not yet well understood */
1519 _ncl_check_grow(&l
, len SMALLOC_DEBUG_ARGSCALL
);
1521 /* Normal read(2)? Else buffer-takeover: speed this one up */
1526 assert(l
.defc
.l
> 0 && l
.defc
.s
!= NULL
);
1528 cbuf
= l
.defc
.s
+ (l
.defc
.l
- len
);
1532 /* Read in the next complete multibyte character */
1535 if ((rv
= read(STDIN_FILENO
, cbufp
, 1)) < 1) {
1536 if (errno
== EINTR
) /* xxx #if !SA_RESTART ? */
1543 /* Ach! the ISO C multibyte handling!
1544 * Encodings with locking shift states cannot really be helped, since
1545 * it is impossible to only query the shift state, as opposed to the
1546 * entire shift state + character pair (via ISO C functions) */
1547 rv
= (ssize_t
)mbrtowc(&wc
, cbuf
, PTR2SIZE(cbufp
- cbuf
), ps
+ 0);
1549 /* Any error during take-over can only result in a hard reset;
1550 * Otherwise, if it's a hard error, or if too many redundant shift
1551 * sequences overflow our buffer, also perform a hard reset */
1552 if (len
!= 0 || rv
== -1 ||
1553 sizeof cbuf_base
== PTR2SIZE(cbufp
- cbuf
)) {
1554 l
.savec
.s
= l
.defc
.s
= NULL
,
1555 l
.savec
.l
= l
.defc
.l
= len
= 0;
1560 /* Otherwise, due to the way we deal with the buffer, we need to
1561 * restore the mbstate_t from before this conversion */
1566 if (len
!= 0 && (len
-= (size_t)rv
) == 0)
1567 l
.defc
.s
= NULL
, l
.defc
.l
= 0;
1572 /* Don't interpret control bytes during buffer take-over */
1573 if (cbuf
!= cbuf_base
)
1576 case 'A' ^ 0x40: /* cursor home */
1577 _ncl_khome(&l
, TRU1
);
1579 case 'B' ^ 0x40: /* backward character */
1583 /* 'C': interrupt (CTRL-C) */
1584 case 'D' ^ 0x40: /* delete char forward if any, else EOF */
1585 if ((rv
= _ncl_keof(&l
)) < 0)
1588 case 'E' ^ 0x40: /* end of line */
1591 case 'F' ^ 0x40: /* forward character */
1596 case 'H' ^ 0x40: /* backspace */
1600 case 'I' ^ 0x40: /* horizontal tab */
1601 # ifdef HAVE_TABEXPAND
1602 if ((len
= _ncl_kht(&l
)) > 0)
1606 case 'J' ^ 0x40: /* NL (\n) */
1608 case 'G' ^ 0x40: /* full reset */
1611 case 'U' ^ 0x40: /* ^U: ^A + ^K */
1612 _ncl_khome(&l
, FAL0
);
1614 case 'K' ^ 0x40: /* kill from cursor to end of line */
1615 _ncl_kkill(&l
, (wc
== ('K' ^ 0x40) || l
.topins
== 0));
1616 /* (Handle full reset?) */
1617 if (wc
== ('G' ^ 0x40)) {
1618 # ifdef HAVE_HISTORY
1621 if ((len
= l
.savec
.l
) != 0) {
1623 l
.savec
.s
= NULL
, l
.savec
.l
= 0;
1629 case 'L' ^ 0x40: /* repaint line */
1634 case 'N' ^ 0x40: /* history next */
1636 # ifdef HAVE_HISTORY
1639 if ((len
= _ncl_khist(&l
, FAL0
)) > 0)
1647 case 'O' ^ 0x40: /* `dp' */
1651 cbuf_base
[2] = '\0';
1652 pstate
&= ~PS_HOOK_MASK
;
1653 execute(cbuf_base
, 2);
1655 case 'P' ^ 0x40: /* history previous */
1657 # ifdef HAVE_HISTORY
1658 if ((len
= _ncl_khist(&l
, TRU1
)) > 0)
1666 case 'R' ^ 0x40: /* reverse history search */
1667 # ifdef HAVE_HISTORY
1668 if ((len
= _ncl_krhist(&l
)) > 0)
1677 /*case 'V' ^ 0x40: TODO*/ /* forward delete "word" */
1678 case 'W' ^ 0x40: /* backward delete "word" */
1681 case 'X' ^ 0x40: /* move cursor forward "word" */
1684 case 'Y' ^ 0x40: /* move cursor backward "word" */
1687 /* 'Z': suspend (CTRL-Z) */
1689 if (cursor_maybe
++ != 0)
1693 /* XXX Handle usual ^[[[ABCD1456] cursor keys: UGLY,"MAGIC",INFLEX */
1694 if (cursor_maybe
> 0) {
1695 if (++cursor_maybe
== 2) {
1699 } else if (cursor_maybe
== 3) {
1703 case L
'A': goto j_p
;
1704 case L
'B': goto j_n
;
1705 case L
'C': goto j_f
;
1706 case L
'D': goto j_b
;
1717 cursor_store
= ((wc
== L
'1') ? '0' :
1718 (wc
== L
'4' ? '$' : (wc
== L
'5' ? '-' : '+')));
1722 _ncl_kother(&l
, L
'[');
1728 x
[0] = cursor_store
;
1735 _ncl_kother(&l
, L
'[');
1736 _ncl_kother(&l
, (wchar_t)cursor_store
);
1742 _ncl_kother(&l
, wc
);
1743 /* Don't clear the history during takeover..
1744 * ..and also avoid fflush()ing unless we've worked entire buffer */
1747 # ifdef HAVE_HISTORY
1748 if (cbuf
== cbuf_base
)
1760 /* We have a completed input line, convert the struct cell data to its
1761 * plain character equivalent */
1765 len
= _ncl_cell2dat(&l
);
1775 # ifdef HAVE_HISTORY
1779 size_t lsize
, cnt
, llen
;
1783 # ifdef HAVE_HISTORY
1786 _ncl_hist_size_max
= hs
;
1794 hold_all_sigs(); /* TODO too heavy, yet we may jump even here!? */
1795 f
= fopen(v
, "r"); /* TODO HISTFILE LOAD: use linebuf pool */
1798 (void)file_lock(fileno(f
), FLT_READ
, 0,0, 500);
1803 while (fgetline(&lbuf
, &lsize
, &cnt
, &llen
, f
, FAL0
) != NULL
) {
1804 if (llen
> 0 && lbuf
[llen
- 1] == '\n')
1805 lbuf
[--llen
] = '\0';
1806 if (llen
== 0 || lbuf
[0] == '#') /* xxx comments? noone! */
1809 bool_t isgabby
= (lbuf
[0] == '*');
1810 _ncl_hist_load
= TRU1
;
1811 tty_addhist(lbuf
+ isgabby
, isgabby
);
1812 _ncl_hist_load
= FAL0
;
1820 rele_all_sigs(); /* XXX remove jumps */
1822 # endif /* HAVE_HISTORY */
1829 # ifdef HAVE_HISTORY
1838 # ifdef HAVE_HISTORY
1846 dogabby
= ok_blook(history_gabby_persist
);
1848 if ((hp
= _ncl_hist
) != NULL
)
1849 for (; hp
->older
!= NULL
; hp
= hp
->older
)
1850 if ((dogabby
|| !hp
->isgabby
) && --hs
== 0)
1853 hold_all_sigs(); /* TODO too heavy, yet we may jump even here!? */
1854 f
= fopen(v
, "w"); /* TODO temporary + rename?! */
1857 (void)file_lock(fileno(f
), FLT_WRITE
, 0,0, 500);
1858 if (fchmod(fileno(f
), S_IRUSR
| S_IWUSR
) != 0)
1861 for (; hp
!= NULL
; hp
= hp
->younger
) {
1862 if (!hp
->isgabby
|| dogabby
) {
1865 fwrite(hp
->dat
, sizeof *hp
->dat
, hp
->len
, f
);
1872 rele_all_sigs(); /* XXX remove jumps */
1874 # endif /* HAVE_HISTORY */
1881 sigset_t nset
, oset
;
1882 NYD_X
; /* Signal handler */
1886 /* We don't deal with SIGWINCH, yet get called from main.c */
1889 _ncl_term_mode(FAL0
);
1892 sigaddset(&nset
, sig
);
1893 sigprocmask(SIG_UNBLOCK
, &nset
, &oset
);
1895 /* When we come here we'll continue editing, so reestablish */
1896 sigprocmask(SIG_BLOCK
, &oset
, (sigset_t
*)NULL
);
1898 _ncl_term_mode(TRU1
);
1904 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
1910 /* Of course we have races here, but they cannot be avoided on POSIX
1911 * (except by even *more* actions) */
1913 _ncl_term_mode(TRU1
);
1914 nn
= _ncl_readline(prompt
, linebuf
, linesize
, n SMALLOC_DEBUG_ARGSCALL
);
1915 _ncl_term_mode(FAL0
);
1922 tty_addhist(char const *s
, bool_t isgabby
)
1924 # ifdef HAVE_HISTORY
1925 /* Super-Heavy-Metal: block all sigs, avoid leaks+ on jump */
1927 struct hist
*h
, *o
, *y
;
1933 # ifdef HAVE_HISTORY
1934 if (isgabby
&& !ok_blook(history_gabby
))
1936 if (_ncl_hist_size_max
== 0)
1938 _CL_CHECK_ADDHIST(s
, goto j_leave
);
1940 l
= (ui32_t
)strlen(s
);
1942 /* Eliminating duplicates is expensive, but simply inacceptable so
1943 * during the load of a potentially large history file! */
1944 if (!_ncl_hist_load
)
1945 for (h
= _ncl_hist
; h
!= NULL
; h
= h
->older
)
1946 if (h
->len
== l
&& !strcmp(h
->dat
, s
)) {
1947 hold_all_sigs(); /* TODO */
1949 h
->isgabby
= !!isgabby
;
1965 if (!_ncl_hist_load
&& _ncl_hist_size
> _ncl_hist_size_max
) {
1967 if ((h
= _ncl_hist_tail
) != NULL
) {
1968 if ((_ncl_hist_tail
= h
->younger
) == NULL
)
1971 _ncl_hist_tail
->older
= NULL
;
1976 h
= smalloc((sizeof(struct hist
) - VFIELD_SIZEOF(struct hist
, dat
)) + l
+1);
1977 h
->isgabby
= !!isgabby
;
1979 memcpy(h
->dat
, s
, l
+1);
1981 if ((h
->older
= _ncl_hist
) != NULL
)
1982 _ncl_hist
->younger
= h
;
1994 # ifdef HAVE_HISTORY
2005 if (_ncl_hist
== NULL
)
2008 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
2010 n_perr(_("tmpfile"), 0);
2017 for (h
= _ncl_hist
; h
!= NULL
; --i
, b
+= h
->len
, h
= h
->older
)
2019 "%c%4" PRIuZ
". %-50.50s (%4" PRIuZ
"+%2" PRIu32
" bytes)\n",
2020 (h
->isgabby
? '*' : ' '), i
, h
->dat
, b
, h
->len
);
2022 page_or_print(fp
, i
);
2030 while ((h
= _ncl_hist
) != NULL
) {
2031 _ncl_hist
= h
->older
;
2034 _ncl_hist_tail
= NULL
;
2042 if (UICMP(z
, entry
, <=, _ncl_hist_size
)) {
2043 entry
= (long)_ncl_hist_size
- entry
;
2044 for (h
= _ncl_hist
;; h
= h
->older
)
2047 else if (entry
-- != 0)
2050 v
= temporary_arg_v_store
= h
->dat
;
2058 # endif /* HAVE_HISTORY */
2059 #endif /* HAVE_NCL */
2062 * The really-nothing-at-all implementation
2065 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
2083 NYD_X
; /* Signal handler */
2088 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
2094 if (prompt
!= NULL
) {
2095 if (*prompt
!= '\0')
2096 fputs(prompt
, stdout
);
2099 rv
= (readline_restart
)(stdin
, linebuf
, linesize
,n SMALLOC_DEBUG_ARGSCALL
);
2105 tty_addhist(char const *s
, bool_t isgabby
)
2112 #endif /* nothing at all */