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 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
9 * Copyright (c) 2013 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
11 * Permission to use, copy, modify, and/or distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies.
15 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Copyright (c) 1980, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 #ifndef HAVE_AMALGAMATION
61 # include <readline/readline.h>
63 # include <readline/history.h>
65 #elif defined HAVE_EDITLINE
66 # include <histedit.h>
69 /* Shared history support macros */
71 # define _CL_HISTFILE(S) \
73 S = ok_vlook(NAIL_HISTFILE);\
75 S = fexpand(S, FEXP_LOCAL);\
78 # define _CL_HISTSIZE(V) \
80 char const *__sv = ok_vlook(NAIL_HISTSIZE);\
82 if (__sv == NULL || *__sv == '\0' || (__rv = strtol(__sv, NULL, 10)) == 0)\
90 # define _CL_CHECK_ADDHIST(S,NOACT) \
101 # define C_HISTORY_SHARED \
108 if (argv[1] != NULL)\
110 if (!asccasecmp(*argv, "show"))\
112 if (!asccasecmp(*argv, "clear"))\
114 if ((entry = strtol(*argv, argv, 10)) > 0 && **argv == '\0')\
117 fprintf(stderr, "Synopsis: history: %s\n", tr(431,\
118 "<show> (default), <clear> or select <NO> from editor history"));\
122 return (v == NULL ? !STOP : !OKAY); /* xxx 1:bad 0:good -- do some */
123 #endif /* HAVE_HISTORY */
125 /* fexpand() flags for expand-on-tab */
126 #define _CL_TAB_FEXP_FL (FEXP_FULL | FEXP_SILENT | FEXP_MULTIOK)
129 * Because we have multiple identical implementations, change file layout a bit
130 * and place the implementations one after the other below the other externals
133 static sigjmp_buf __tty_actjmp
; /* TODO someday, we won't need it no more */
135 __tty_acthdl(int s
) /* TODO someday, we won't need it no more */
137 NYD_X
; /* Signal handler */
138 termios_state_reset();
139 siglongjmp(__tty_actjmp
, s
);
143 getapproval(char const *prompt
, bool_t noninteract_default
)
148 if (!(options
& OPT_INTERACTIVE
)) {
149 rv
= noninteract_default
;
154 prompt
= tr(264, "Continue (y/n)? ");
157 if (readline_input(prompt
, FAL0
, &termios_state
.ts_linebuf
,
158 &termios_state
.ts_linesize
, NULL
) >= 0)
159 switch (termios_state
.ts_linebuf
[0]) {
167 termios_state_reset();
174 yorn(char const *msg
) /* TODO obsolete */
179 rv
= getapproval(msg
, TRU1
);
185 getuser(char const * volatile query
)
187 sighandler_type
volatile ohdl
;
189 bool_t hadsig
= FAL0
;
193 query
= tr(509, "User: ");
195 ohdl
= safe_signal(SIGINT
, SIG_IGN
);
196 if (sigsetjmp(__tty_actjmp
, 1) != 0) {
200 safe_signal(SIGINT
, &__tty_acthdl
);
202 if (readline_input(query
, FAL0
, &termios_state
.ts_linebuf
,
203 &termios_state
.ts_linesize
, NULL
) >= 0)
204 user
= termios_state
.ts_linebuf
;
206 termios_state_reset();
207 safe_signal(SIGINT
, ohdl
);
209 if (hadsig
&& ohdl
!= SIG_IGN
)
215 getpassword(char const *query
) /* FIXME encaps ttystate signal safe */
217 sighandler_type
volatile ohdl
;
220 bool_t hadsig
= FAL0
;
224 query
= tr(510, "Password: ");
225 fputs(query
, stdout
);
228 /* FIXME everywhere: tcsetattr() generates SIGTTOU when we're not in
229 * FIXME foreground pgrp, and can fail with EINTR!! also affects
230 * FIXME termios_state_reset() */
231 if (options
& OPT_TTYIN
) {
232 tcgetattr(STDIN_FILENO
, &termios_state
.ts_tios
);
233 memcpy(&tios
, &termios_state
.ts_tios
, sizeof tios
);
234 termios_state
.ts_needs_reset
= TRU1
;
235 tios
.c_iflag
&= ~(ISTRIP
);
236 tios
.c_lflag
&= ~(ECHO
| ECHOE
| ECHOK
| ECHONL
);
237 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &tios
);
240 ohdl
= safe_signal(SIGINT
, SIG_IGN
);
241 if (sigsetjmp(__tty_actjmp
, 1) != 0) {
245 safe_signal(SIGINT
, &__tty_acthdl
);
247 if (readline_restart(stdin
, &termios_state
.ts_linebuf
,
248 &termios_state
.ts_linesize
, 0) >= 0)
249 pass
= termios_state
.ts_linebuf
;
251 termios_state_reset();
252 safe_signal(SIGINT
, ohdl
);
253 if (options
& OPT_TTYIN
)
256 if (hadsig
&& ohdl
!= SIG_IGN
)
262 getcredentials(char **user
, char **pass
)
273 if ((u
= getuser(NULL
)) == NULL
)
281 if ((p
= getpassword(NULL
)) == NULL
)
294 static sighandler_type _rl_shup
;
295 static char * _rl_buf
; /* pre_input() hook: initial line */
296 static int _rl_buflen
; /* content, and its length */
298 static int _rl_pre_input(void);
304 /* Handle leftover data from \ escaped former line */
305 rl_extend_line_buffer(_rl_buflen
+ 10);
306 memcpy(rl_line_buffer
, _rl_buf
, _rl_buflen
+ 1);
307 rl_point
= rl_end
= _rl_buflen
;
308 rl_pre_input_hook
= (rl_hook_func_t
*)NULL
;
323 rl_readline_name
= UNCONST(uagent
);
327 stifle_history((int)hs
);
329 rl_read_init_file(NULL
);
331 /* Because rl_read_init_file() may have introduced yet a different
332 * history size limit, simply load and incorporate the history, leave
333 * it up to readline(3) to do the rest */
362 NYD_X
; /* Signal handler */
370 /* readline(3) doesn't catch it :( */
371 rl_free_line_state();
372 rl_cleanup_after_signal();
373 safe_signal(SIGHUP
, _rl_shup
);
375 sigaddset(&nset
, sig
);
376 sigprocmask(SIG_UNBLOCK
, &nset
, &oset
);
378 /* XXX When we come here we'll continue editing, so reestablish
379 * XXX cannot happen */
380 sigprocmask(SIG_BLOCK
, &oset
, NULL
);
381 _rl_shup
= safe_signal(SIGHUP
, &tty_signal
);
382 rl_reset_after_signal();
390 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
400 rl_pre_input_hook
= &_rl_pre_input
;
403 _rl_shup
= safe_signal(SIGHUP
, &tty_signal
);
404 line
= readline(prompt
!= NULL
? prompt
: "");
405 safe_signal(SIGHUP
, _rl_shup
);
413 if (n
>= *linesize
) {
414 *linesize
= LINESIZE
+ n
+1;
415 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
417 memcpy(*linebuf
, line
, n
);
419 (*linebuf
)[n
] = '\0';
427 tty_addhist(char const *s
)
432 _CL_CHECK_ADDHIST(s
, goto jleave
);
433 hold_all_sigs(); /* XXX too heavy */
434 add_history(s
); /* XXX yet we jump away! */
435 rele_all_sigs(); /* XXX remove jumps */
453 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
460 hs
= history_get_history_state();
462 for (i
= (ul_it
)hs
->length
, hl
= hs
->entries
+ i
, b
= 0; i
> 0; --i
) {
463 char *cp
= (*--hl
)->line
;
464 size_t sl
= strlen(cp
);
465 fprintf(fp
, "%4lu. %-50.50s (%4lu+%lu bytes)\n", i
, cp
, b
, sl
);
469 page_or_print(fp
, (size_t)hs
->length
);
479 HISTORY_STATE
*hs
= history_get_history_state();
481 if (UICMP(z
, entry
, <=, hs
->length
))
482 v
= temporary_arg_v_store
= hs
->entries
[entry
- 1]->line
;
488 # endif /* HAVE_HISTORY */
489 #endif /* HAVE_READLINE */
496 static EditLine
* _el_el
; /* editline(3) handle */
497 static char const * _el_prompt
; /* Current prompt */
499 static History
* _el_hcom
; /* History handle for commline */
502 static char const * _el_getprompt(void);
522 _el_hcom
= history_init();
523 history(_el_hcom
, &he
, H_SETSIZE
, (int)hs
);
524 /* We unroll our own one history(_el_hcom, &he, H_SETUNIQUE, 1);*/
527 _el_el
= el_init(uagent
, stdin
, stdout
, stderr
);
528 el_set(_el_el
, EL_SIGNAL
, 1);
529 el_set(_el_el
, EL_TERMINAL
, NULL
);
530 /* Need to set HIST before EDITOR, otherwise it won't work automatic */
532 el_set(_el_el
, EL_HIST
, &history
, _el_hcom
);
534 el_set(_el_el
, EL_EDITOR
, "emacs");
535 # ifdef EL_PROMPT_ESC
536 el_set(_el_el
, EL_PROMPT_ESC
, &_el_getprompt
, '\1');
538 el_set(_el_el
, EL_PROMPT
, &_el_getprompt
);
541 el_set(_el_el
, EL_ADDFN
, "tab_complete",
542 "editline(3) internal completion function", &_el_file_cpl
);
543 el_set(_el_el
, EL_BIND
, "^I", "tab_complete", NULL
);
546 el_set(_el_el
, EL_BIND
, "^R", "ed-search-prev-history", NULL
);
548 el_source(_el_el
, NULL
); /* Source ~/.editrc */
550 /* Because el_source() may have introduced yet a different history size
551 * limit, simply load and incorporate the history, leave it up to
552 * editline(3) to do the rest */
556 history(_el_hcom
, &he
, H_LOAD
, v
);
575 history(_el_hcom
, &he
, H_SAVE
, v
);
576 history_end(_el_hcom
);
584 NYD_X
; /* Signal handler */
597 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
604 _el_prompt
= (prompt
!= NULL
) ? prompt
: "";
606 el_push(_el_el
, *linebuf
);
607 line
= el_gets(_el_el
, &nn
);
615 if (n
> 0 && line
[n
- 1] == '\n')
618 if (n
>= *linesize
) {
619 *linesize
= LINESIZE
+ n
+ 1;
620 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
622 memcpy(*linebuf
, line
, n
);
623 (*linebuf
)[n
] = '\0';
630 tty_addhist(char const *s
)
633 /* Enlarge meaning of unique .. to something that rocks;
634 * xxx unfortunately this is expensive to do with editline(3)
635 * xxx maybe it would be better to hook the ptfs instead? */
643 _CL_CHECK_ADDHIST(s
, goto jleave
);
645 hold_all_sigs(); /* XXX too heavy, yet we jump away! */
646 for (i
= history(_el_hcom
, &he
, H_FIRST
); i
>= 0;
647 i
= history(_el_hcom
, &he
, H_NEXT
))
648 if (!strcmp(he
.str
, s
)) {
649 history(_el_hcom
, &he
, H_DEL
, he
.num
);
652 history(_el_hcom
, &he
, H_ENTER
, s
);
653 rele_all_sigs(); /* XXX remove jumps */
671 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
678 i
= (size_t)((history(_el_hcom
, &he
, H_GETSIZE
) >= 0) ? he
.num
: 0);
680 for (x
= history(_el_hcom
, &he
, H_FIRST
); x
>= 0;
681 x
= history(_el_hcom
, &he
, H_NEXT
)) {
682 size_t sl
= strlen(he
.str
);
683 fprintf(fp
, "%4lu. %-50.50s (%4lu+%lu bytes)\n",
684 (ul_it
)i
, he
.str
, (ul_it
)b
, (ul_it
)sl
);
689 page_or_print(fp
, i
);
696 history(_el_hcom
, &he
, H_CLEAR
);
705 i
= (size_t)((history(_el_hcom
, &he
, H_GETSIZE
) >= 0) ? he
.num
: 0);
706 if (UICMP(z
, entry
, <=, i
)) {
707 entry
= (long)i
- entry
;
708 for (x
= history(_el_hcom
, &he
, H_FIRST
); x
>= 0;
709 x
= history(_el_hcom
, &he
, H_NEXT
))
711 v
= temporary_arg_v_store
= UNCONST(he
.str
);
719 # endif /* HAVE_HISTORY */
720 #endif /* HAVE_EDITLINE */
723 * NCL: our homebrew version (inspired from NetBSD sh(1) / dash(1)s hetio.c).
725 * Only used in interactive mode, simply use STDIN_FILENO as point of interest.
726 * We do not handle character widths because the terminal must deal with that
727 * anyway on the one hand, and also wcwidth(3) doesn't support zero-width
728 * characters by definition on the other. We're addicted.
730 * To avoid memory leaks etc. with the current codebase that simply longjmp(3)s
731 * we're forced to use the very same buffer--the one that is passed through to
732 * us from the outside--to store anything we need, i.e., a `struct cell[]', and
733 * convert that on-the-fly back to the plain char* result once we're done.
734 * To simplify our live, use savestr() buffers for all other needed memory
738 * TODO NCL: don't use that stupid .sint=-1 stuff, but simply block all signals
739 * TODO NCL: during handler de-/installation handling.
744 # define MAX_INPUT 255 /* (_POSIX_MAX_INPUT = 255 as of Issue 7 TC1) */
747 /* Since we simply fputs(3) the prompt, assume each character requires two
748 * visual cells -- and we need to restrict the maximum prompt size because
749 * of MAX_INPUT and our desire to have room for some error message left */
750 # define _PROMPT_VLEN(P) (strlen(P) * 2)
751 # define _PROMPT_MAX ((MAX_INPUT / 2) + (MAX_INPUT / 4))
754 sighandler_type shdl
; /* Try avoid races by setting */
755 sl_it sint
; /* .sint=-1 when inactive */
757 CTA(sizeof(sl_it
) >= sizeof(sighandler_type
));
767 char cbuf
[MB_LEN_MAX
* 2]; /* .. plus reset shift sequence */
771 size_t cursor
; /* Current cursor position */
772 size_t topins
; /* Outermost cursor col set */
774 char * cbuf
; /* *x_buf */
777 struct str defc
; /* Current default content */
778 struct str savec
; /* Saved default content */
780 struct hist
* hist
; /* History cursor */
783 char const * nd
; /* Cursor right */
784 char ** x_buf
; /* Caller pointers */
791 struct hist
* younger
;
793 char dat
[VFIELD_SIZE(sizeof(size_t))];
797 static union xsighdl _ncl_oint
;
798 static union xsighdl _ncl_oquit
;
799 static union xsighdl _ncl_oterm
;
800 static union xsighdl _ncl_ohup
;
801 static union xsighdl _ncl_otstp
;
802 static union xsighdl _ncl_ottin
;
803 static union xsighdl _ncl_ottou
;
804 static struct xtios _ncl_tios
;
806 static struct hist
* _ncl_hist
;
807 static struct hist
* _ncl_hist_tail
;
808 static size_t _ncl_hist_size
;
809 static size_t _ncl_hist_size_max
;
810 static bool_t _ncl_hist_load
;
813 static void _ncl_sigs_up(void);
814 static void _ncl_sigs_down(void);
816 static void _ncl_term_mode(bool_t raw
);
818 static void _ncl_check_grow(struct line
*l
, size_t no SMALLOC_DEBUG_ARGS
);
819 static void _ncl_bs_eof_dvup(struct cell
*cap
, size_t i
);
820 static ssize_t
_ncl_wboundary(struct line
*l
, ssize_t dir
);
821 static ssize_t
_ncl_cell2dat(struct line
*l
);
822 # if defined HAVE_HISTORY || defined HAVE_TABEXPAND
823 static void _ncl_cell2save(struct line
*l
);
826 static void _ncl_khome(struct line
*l
, bool_t dobell
);
827 static void _ncl_kend(struct line
*l
);
828 static void _ncl_kbs(struct line
*l
);
829 static void _ncl_kkill(struct line
*l
, bool_t dobell
);
830 static ssize_t
_ncl_keof(struct line
*l
);
831 static void _ncl_kleft(struct line
*l
);
832 static void _ncl_kright(struct line
*l
);
833 static void _ncl_krefresh(struct line
*l
);
834 static void _ncl_kbwddelw(struct line
*l
);
835 static void _ncl_kgow(struct line
*l
, ssize_t dir
);
836 static void _ncl_kother(struct line
*l
, wchar_t wc
);
838 static size_t __ncl_khist_shared(struct line
*l
, struct hist
*hp
);
839 static size_t _ncl_khist(struct line
*l
, bool_t backwd
);
840 static size_t _ncl_krhist(struct line
*l
);
842 # ifdef HAVE_TABEXPAND
843 static size_t _ncl_kht(struct line
*l
);
845 static ssize_t
_ncl_readline(char const *prompt
, char **buf
, size_t *bufsize
,
846 size_t len SMALLOC_DEBUG_ARGS
);
852 if (_ncl_oint
.sint
== -1)
853 _ncl_oint
.shdl
= safe_signal(SIGINT
, &tty_signal
);
854 if (_ncl_oquit
.sint
== -1)
855 _ncl_oquit
.shdl
= safe_signal(SIGQUIT
, &tty_signal
);
856 if (_ncl_oterm
.sint
== -1)
857 _ncl_oterm
.shdl
= safe_signal(SIGTERM
, &tty_signal
);
858 if (_ncl_ohup
.sint
== -1)
859 _ncl_ohup
.shdl
= safe_signal(SIGHUP
, &tty_signal
);
860 if (_ncl_otstp
.sint
== -1)
861 _ncl_otstp
.shdl
= safe_signal(SIGTSTP
, &tty_signal
);
862 if (_ncl_ottin
.sint
== -1)
863 _ncl_ottin
.shdl
= safe_signal(SIGTTIN
, &tty_signal
);
864 if (_ncl_ottou
.sint
== -1)
865 _ncl_ottou
.shdl
= safe_signal(SIGTTOU
, &tty_signal
);
872 /* aaah.. atomic cas would be nice (but isn't it all redundant?) */
876 if (_ncl_ottou
.sint
!= -1) {
877 st
= _ncl_ottou
.shdl
, _ncl_ottou
.sint
= -1;
878 safe_signal(SIGTTOU
, st
);
880 if (_ncl_ottin
.sint
!= -1) {
881 st
= _ncl_ottin
.shdl
, _ncl_ottin
.sint
= -1;
882 safe_signal(SIGTTIN
, st
);
884 if (_ncl_otstp
.sint
!= -1) {
885 st
= _ncl_otstp
.shdl
, _ncl_otstp
.sint
= -1;
886 safe_signal(SIGTSTP
, st
);
888 if (_ncl_ohup
.sint
!= -1) {
889 st
= _ncl_ohup
.shdl
, _ncl_ohup
.sint
= -1;
890 safe_signal(SIGHUP
, st
);
892 if (_ncl_oterm
.sint
!= -1) {
893 st
= _ncl_oterm
.shdl
, _ncl_oterm
.sint
= -1;
894 safe_signal(SIGTERM
, st
);
896 if (_ncl_oquit
.sint
!= -1) {
897 st
= _ncl_oquit
.shdl
, _ncl_oquit
.sint
= -1;
898 safe_signal(SIGQUIT
, st
);
900 if (_ncl_oint
.sint
!= -1) {
901 st
= _ncl_oint
.shdl
, _ncl_oint
.sint
= -1;
902 safe_signal(SIGINT
, st
);
908 _ncl_term_mode(bool_t raw
)
910 struct termios
*tiosp
;
913 tiosp
= &_ncl_tios
.told
;
917 /* Always requery the attributes, in case we've been moved from background
918 * to foreground or however else in between sessions */
919 tcgetattr(STDIN_FILENO
, tiosp
);
920 memcpy(&_ncl_tios
.tnew
, tiosp
, sizeof *tiosp
);
921 tiosp
= &_ncl_tios
.tnew
;
922 tiosp
->c_cc
[VMIN
] = 1;
923 tiosp
->c_cc
[VTIME
] = 0;
924 tiosp
->c_iflag
&= ~(ISTRIP
);
925 tiosp
->c_lflag
&= ~(ECHO
/*| ECHOE | ECHONL */| ICANON
| IEXTEN
);
927 tcsetattr(STDIN_FILENO
, TCSADRAIN
, tiosp
);
932 _ncl_check_grow(struct line
*l
, size_t no SMALLOC_DEBUG_ARGS
)
937 i
= (l
->topins
+ no
) * sizeof(struct cell
) + 2 * sizeof(struct cell
);
938 if (i
> *l
->x_bufsize
) {
942 *l
->x_buf
= (srealloc
)(*l
->x_buf
, i SMALLOC_DEBUG_ARGSCALL
);
948 _ncl_bs_eof_dvup(struct cell
*cap
, size_t i
)
954 memmove(cap
, cap
+ 1, i
* sizeof(*cap
));
956 /* And.. the (rest of the) visual update */
957 for (j
= 0; j
< i
; ++j
)
958 fwrite(cap
[j
].cbuf
, sizeof *cap
->cbuf
, cap
[j
].count
, stdout
);
959 fputs(" \b", stdout
);
960 for (j
= 0; j
< i
; ++j
)
966 _ncl_wboundary(struct line
*l
, ssize_t dir
)
983 --t
, --c
; /* Unsigned wrapping may occur (twice), then */
985 for (i
= 0, cap
= l
->line
.cells
, anynon
= FAL0
;;) {
986 wchar_t wc
= cap
[c
+ dir
].wc
;
987 if (iswblank(wc
) || iswpunct(wc
)) {
1006 _ncl_cell2dat(struct line
*l
)
1012 for (i
= 0; i
< l
->topins
; ++i
) {
1013 struct cell
*cap
= l
->line
.cells
+ i
;
1014 memcpy(l
->line
.cbuf
+ len
, cap
->cbuf
, cap
->count
);
1017 l
->line
.cbuf
[len
] = '\0';
1019 return (ssize_t
)len
;
1022 # if defined HAVE_HISTORY || defined HAVE_TABEXPAND
1024 _ncl_cell2save(struct line
*l
)
1030 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1034 for (cap
= l
->line
.cells
, len
= i
= 0; i
< l
->topins
; ++cap
, ++i
)
1038 l
->savec
.s
= salloc(len
+ 1);
1040 for (cap
= l
->line
.cells
, len
= i
= 0; i
< l
->topins
; ++cap
, ++i
) {
1041 memcpy(l
->savec
.s
+ len
, cap
->cbuf
, cap
->count
);
1044 l
->savec
.s
[len
] = '\0';
1051 _ncl_khome(struct line
*l
, bool_t dobell
)
1067 _ncl_kend(struct line
*l
)
1072 i
= (ssize_t
)(l
->topins
- l
->cursor
);
1075 l
->cursor
= l
->topins
;
1077 fputs(l
->nd
, stdout
);
1084 _ncl_kbs(struct line
*l
)
1097 _ncl_bs_eof_dvup(l
->line
.cells
+ c
, t
);
1104 _ncl_kkill(struct line
*l
, bool_t dobell
)
1110 i
= (size_t)(l
->topins
- c
);
1114 for (j
= i
; j
!= 0; --j
)
1116 for (j
= i
; j
!= 0; --j
)
1124 _ncl_keof(struct line
*l
)
1132 i
= (ssize_t
)(t
- c
);
1136 _ncl_bs_eof_dvup(l
->line
.cells
+ c
, --i
);
1137 } else if (t
== 0 && !ok_blook(ignoreeof
)) {
1138 fputs("^D", stdout
);
1150 _ncl_kleft(struct line
*l
)
1153 if (l
->cursor
> 0) {
1162 _ncl_kright(struct line
*l
)
1165 if (l
->cursor
< l
->topins
) {
1167 fputs(l
->nd
, stdout
);
1174 _ncl_krefresh(struct line
*l
)
1181 if (l
->prompt
!= NULL
&& *l
->prompt
!= '\0')
1182 fputs(l
->prompt
, stdout
);
1183 for (cap
= l
->line
.cells
, i
= l
->topins
; i
> 0; ++cap
, --i
)
1184 fwrite(cap
->cbuf
, sizeof *cap
->cbuf
, cap
->count
, stdout
);
1185 for (i
= l
->topins
- l
->cursor
; i
> 0; --i
)
1191 _ncl_kbwddelw(struct line
*l
)
1198 i
= _ncl_wboundary(l
, -1);
1209 cap
= l
->line
.cells
+ c
;
1211 if (t
!= l
->cursor
) {
1213 memmove(cap
, cap
+ i
, j
* sizeof(*cap
));
1216 for (j
= i
; j
> 0; --j
)
1218 for (j
= l
->topins
- c
; j
> 0; ++cap
, --j
)
1219 fwrite(cap
[0].cbuf
, sizeof *cap
->cbuf
, cap
[0].count
, stdout
);
1220 for (j
= i
; j
> 0; --j
)
1222 for (j
= t
- c
; j
> 0; --j
)
1229 _ncl_kgow(struct line
*l
, ssize_t dir
)
1234 i
= _ncl_wboundary(l
, dir
);
1248 fputs(l
->nd
, stdout
);
1255 _ncl_kother(struct line
*l
, wchar_t wc
)
1257 /* Append if at EOL, insert otherwise;
1258 * since we may move around character-wise, always use a fresh ps */
1260 struct cell cell
, *cap
;
1264 /* First init a cell and see wether we'll really handle this wc */
1266 memset(&ps
, 0, sizeof ps
);
1267 i
= wcrtomb(cell
.cbuf
, wc
, &ps
);
1270 cell
.count
= (ui_it
)i
;
1271 if (enc_has_state
) {
1272 i
= wcrtomb(cell
.cbuf
+ i
, L
'\0', &ps
);
1275 else if (--i
< MB_LEN_MAX
)
1276 cell
.count
+= (ui_it
)i
;
1281 /* Yes, we will! Place it in the array */
1283 i
= l
->topins
++ - c
;
1284 cap
= l
->line
.cells
+ c
;
1286 memmove(cap
+ 1, cap
, i
* sizeof(cell
));
1287 memcpy(cap
, &cell
, sizeof cell
);
1289 /* And update visual */
1292 fwrite(cap
->cbuf
, sizeof *cap
->cbuf
, cap
->count
, stdout
);
1293 while ((++cap
, i
-- != 0));
1300 # ifdef HAVE_HISTORY
1302 __ncl_khist_shared(struct line
*l
, struct hist
*hp
)
1307 if ((l
->hist
= hp
) != NULL
) {
1308 l
->defc
.s
= savestrbuf(hp
->dat
, hp
->len
);
1310 l
->defc
.l
= hp
->len
;
1311 if (l
->topins
> 0) {
1312 _ncl_khome(l
, FAL0
);
1313 _ncl_kkill(l
, FAL0
);
1324 _ncl_khist(struct line
*l
, bool_t backwd
)
1330 /* If we're not in history mode yet, save line content;
1331 * also, disallow forward search, then, and, of course, bail unless we
1332 * do have any history at all */
1333 if ((hp
= l
->hist
) == NULL
) {
1336 if ((hp
= _ncl_hist
) == NULL
)
1342 hp
= backwd
? hp
->older
: hp
->younger
;
1344 rv
= __ncl_khist_shared(l
, hp
);
1350 _ncl_krhist(struct line
*l
)
1352 struct str orig_savec
;
1353 struct hist
*hp
= NULL
;
1357 /* We cannot complete an empty line */
1358 if (l
->topins
== 0) {
1359 /* XXX The upcoming hard reset would restore a set savec buffer,
1360 * XXX so forcefully reset that. A cleaner solution would be to
1361 * XXX reset it whenever a restore is no longer desired */
1362 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1365 if ((hp
= l
->hist
) == NULL
) {
1366 if ((hp
= _ncl_hist
) == NULL
)
1368 orig_savec
.s
= NULL
;
1369 orig_savec
.l
= 0; /* silence CC */
1370 } else if ((hp
= hp
->older
) == NULL
)
1373 orig_savec
= l
->savec
;
1375 if (orig_savec
.s
== NULL
)
1377 for (; hp
!= NULL
; hp
= hp
->older
)
1378 if (is_prefix(l
->savec
.s
, hp
->dat
))
1380 if (orig_savec
.s
!= NULL
)
1381 l
->savec
= orig_savec
;
1383 rv
= __ncl_khist_shared(l
, hp
);
1389 # ifdef HAVE_TABEXPAND
1391 _ncl_kht(struct line
*l
)
1393 struct str orig
, bot
, topp
, sub
, exp
;
1394 struct cell
*cword
, *ctop
, *cx
;
1395 bool_t set_savec
= FAL0
;
1399 /* We cannot expand an empty line */
1403 /* Get plain line data; if this is the first expansion/xy, update the
1404 * very original content so that ^G gets the origin back */
1414 cword
= l
->line
.cells
;
1415 ctop
= cword
+ l
->cursor
;
1417 /* topp: separate data right of cursor */
1418 if ((cx
= cword
+ l
->topins
) != ctop
) {
1419 for (rv
= 0; cx
> ctop
; --cx
)
1422 topp
.s
= orig
.s
+ orig
.l
- rv
;
1424 topp
.s
= NULL
, topp
.l
= 0;
1426 /* bot, sub: we cannot expand the entire data left of cursor, but only
1427 * the last "word", so separate them */
1428 while (cx
> cword
&& !iswspace(cx
[-1].wc
))
1430 for (rv
= 0; cword
< cx
; ++cword
)
1439 /* Leave room for "implicit asterisk" expansion, as below */
1441 sub
.s
= UNCONST("*");
1444 exp
.s
= salloc(sub
.l
+ 1 +1);
1445 memcpy(exp
.s
, sub
.s
, sub
.l
);
1446 exp
.s
[sub
.l
] = '\0';
1450 /* TODO there is a TODO note upon fexpand() with multi-return;
1451 * TODO if that will change, the if() below can be simplified */
1452 /* Super-Heavy-Metal: block all sigs, avoid leaks on jump */
1455 exp
.s
= fexpand(sub
.s
, _CL_TAB_FEXP_FL
);
1458 if (exp
.s
== NULL
|| (exp
.l
= strlen(exp
.s
)) == 0)
1460 /* If the expansion equals the original string, assume the user wants what
1461 * is usually known as tab completion, append `*' and restart */
1462 if (exp
.l
== sub
.l
&& !strcmp(exp
.s
, sub
.s
)) {
1463 if (sub
.s
[sub
.l
- 1] == '*')
1465 sub
.s
[sub
.l
++] = '*';
1466 sub
.s
[sub
.l
] = '\0';
1470 /* Cramp expansion length to MAX_INPUT, or 255 if not defined.
1471 * Take care to take *prompt* into account, since we don't know
1472 * anything about it's visual length (fputs(3) is used), simply
1473 * assume each character requires two columns */
1474 /* TODO the problem is that we loose control otherwise; in the best
1475 * TODO case the user can control via ^A and ^K etc., but be safe;
1476 * TODO we cannot simply adjust fexpand() because we don't know how
1477 * TODO that is implemented... The real solution would be to check
1478 * TODO wether we fit on a line, and start a pager if not.
1479 * TODO However, that should be part of a real tab-COMPLETION, then,
1480 * TODO i.e., don't EXPAND, but SHOW COMPLETIONS, page-wise if needed.
1481 * TODO And: MAX_INPUT is dynamic: pathconf(2), _SC_MAX_INPUT */
1482 rv
= (l
->prompt
!= NULL
) ? _PROMPT_VLEN(l
->prompt
) : 0;
1483 if (rv
+ bot
.l
+ exp
.l
+ topp
.l
>= MAX_INPUT
) {
1484 char const e1
[] = "[ERR_TOO_LONG]";
1485 exp
.s
= UNCONST(e1
);
1486 exp
.l
= sizeof(e1
) - 1;
1488 if (rv
+ bot
.l
+ exp
.l
>= MAX_INPUT
)
1490 if (rv
+ exp
.l
>= MAX_INPUT
) {
1491 char const e2
[] = "[ERR]";
1492 exp
.s
= UNCONST(e2
);
1493 exp
.l
= sizeof(e2
) - 1;
1497 orig
.l
= bot
.l
+ exp
.l
+ topp
.l
;
1498 orig
.s
= salloc(orig
.l
+ 5 +1);
1499 if ((rv
= bot
.l
) > 0)
1500 memcpy(orig
.s
, bot
.s
, rv
);
1501 memcpy(orig
.s
+ rv
, exp
.s
, exp
.l
);
1504 memcpy(orig
.s
+ rv
, topp
.s
, topp
.l
);
1510 _ncl_khome(l
, FAL0
);
1511 _ncl_kkill(l
, FAL0
);
1516 /* If we've provided a default content, but failed to expand, there is
1517 * nothing we can "revert to": drop that default again */
1519 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1523 # endif /* HAVE_TABEXPAND */
1526 _ncl_readline(char const *prompt
, char **buf
, size_t *bufsize
, size_t len
1529 /* We want to save code, yet we may have to incorporate a lines'
1530 * default content and / or default input to switch back to after some
1531 * history movement; let "len > 0" mean "have to display some data
1532 * buffer", and only otherwise read(2) it */
1535 char cbuf_base
[MB_LEN_MAX
* 2], *cbuf
, *cbufp
;
1538 ui32_t maybe_cursor
;
1541 memset(&l
, 0, sizeof l
);
1544 l
.defc
.s
= savestrbuf(*buf
, len
);
1547 if ((l
.prompt
= prompt
) != NULL
&& _PROMPT_VLEN(prompt
) > _PROMPT_MAX
)
1548 l
.prompt
= prompt
= "?ERR?";
1549 /* TODO *l.nd=='\0' : instead adjust acmava.c to disallow empty vals */
1550 if ((l
.nd
= ok_vlook(line_editor_cursor_right
)) == NULL
|| *l
.nd
== '\0')
1551 l
.nd
= "\033[C"; /* XXX no "magic" constant */
1553 l
.x_bufsize
= bufsize
;
1555 if (prompt
!= NULL
&& *prompt
!= '\0') {
1556 fputs(prompt
, stdout
);
1560 memset(ps
, 0, sizeof ps
);
1562 /* TODO: NCL: we should output the reset sequence when we jrestart:
1563 * TODO: NCL: if we are using a stateful encoding? !
1564 * TODO: NCL: in short: this is not yet well understood */
1566 _ncl_check_grow(&l
, len SMALLOC_DEBUG_ARGSCALL
);
1568 /* Normal read(2)? Else buffer-takeover: speed this one up */
1573 assert(l
.defc
.l
> 0 && l
.defc
.s
!= NULL
);
1575 cbuf
= l
.defc
.s
+ (l
.defc
.l
- len
);
1579 /* Read in the next complete multibyte character */
1582 if ((rv
= read(STDIN_FILENO
, cbufp
, 1)) < 1) {
1583 if (errno
== EINTR
) /* xxx #if !SA_RESTART ? */
1590 /* Ach! the ISO C multibyte handling!
1591 * Encodings with locking shift states cannot really be helped, since
1592 * it is impossible to only query the shift state, as opposed to the
1593 * entire shift state + character pair (via ISO C functions) */
1594 rv
= (ssize_t
)mbrtowc(&wc
, cbuf
, PTR2SIZE(cbufp
- cbuf
), ps
+ 0);
1596 /* Any error during take-over can only result in a hard reset;
1597 * Otherwise, if it's a hard error, or if too many redundant shift
1598 * sequences overflow our buffer, also perform a hard reset */
1599 if (len
!= 0 || rv
== -1 ||
1600 sizeof cbuf_base
== PTR2SIZE(cbufp
- cbuf
)) {
1601 l
.savec
.s
= l
.defc
.s
= NULL
,
1602 l
.savec
.l
= l
.defc
.l
= len
= 0;
1607 /* Otherwise, due to the way we deal with the buffer, we need to
1608 * restore the mbstate_t from before this conversion */
1613 if (len
!= 0 && (len
-= (size_t)rv
) == 0)
1614 l
.defc
.s
= NULL
, l
.defc
.l
= 0;
1619 /* Don't interpret control bytes during buffer take-over */
1620 if (cbuf
!= cbuf_base
)
1623 case 'A' ^ 0x40: /* cursor home */
1624 _ncl_khome(&l
, TRU1
);
1627 case 'B' ^ 0x40: /* backward character */
1630 /* 'C': interrupt (CTRL-C) */
1631 case 'D' ^ 0x40: /* delete char forward if any, else EOF */
1632 if ((rv
= _ncl_keof(&l
)) < 0)
1635 case 'E' ^ 0x40: /* end of line */
1639 case 'F' ^ 0x40: /* forward character */
1643 case 'H' ^ 0x40: /* backspace */
1647 case 'I' ^ 0x40: /* horizontal tab */
1648 # ifdef HAVE_TABEXPAND
1649 if ((len
= _ncl_kht(&l
)) > 0)
1653 case 'J' ^ 0x40: /* NL (\n) */
1655 case 'G' ^ 0x40: /* full reset */
1658 case 'U' ^ 0x40: /* ^U: ^A + ^K */
1659 _ncl_khome(&l
, FAL0
);
1661 case 'K' ^ 0x40: /* kill from cursor to end of line */
1662 _ncl_kkill(&l
, (wc
== ('K' ^ 0x40) || l
.topins
== 0));
1663 /* (Handle full reset?) */
1664 if (wc
== ('G' ^ 0x40)) {
1665 # ifdef HAVE_HISTORY
1668 if ((len
= l
.savec
.l
) != 0) {
1670 l
.savec
.s
= NULL
, l
.savec
.l
= 0;
1676 case 'L' ^ 0x40: /* repaint line */
1681 case 'N' ^ 0x40: /* history next */
1682 # ifdef HAVE_HISTORY
1685 if ((len
= _ncl_khist(&l
, FAL0
)) > 0)
1694 case 'P' ^ 0x40: /* history previous */
1695 # ifdef HAVE_HISTORY
1696 if ((len
= _ncl_khist(&l
, TRU1
)) > 0)
1704 case 'R' ^ 0x40: /* reverse history search */
1705 # ifdef HAVE_HISTORY
1706 if ((len
= _ncl_krhist(&l
)) > 0)
1715 /*case 'V' ^ 0x40: TODO*/ /* forward delete "word" */
1716 case 'W' ^ 0x40: /* backward delete "word" */
1719 case 'X' ^ 0x40: /* move cursor forward "word" */
1722 case 'Y' ^ 0x40: /* move cursor backward "word" */
1725 /* 'Z': suspend (CTRL-Z) */
1727 if (maybe_cursor
++ != 0)
1731 /* XXX Handle usual ^[[[ABCD] cursor keys -- UGLY, "MAGIC", INFLEX */
1732 if (maybe_cursor
> 0) {
1733 if (++maybe_cursor
== 2) {
1740 case L
'A': goto j_p
;
1741 case L
'B': goto j_n
;
1742 case L
'C': goto j_f
;
1743 case L
'D': goto j_b
;
1745 _ncl_kother(&l
, L
'[');
1750 _ncl_kother(&l
, wc
);
1751 /* Don't clear the history during takeover..
1752 * ..and also avoid fflush()ing unless we've worked entire buffer */
1755 # ifdef HAVE_HISTORY
1756 if (cbuf
== cbuf_base
)
1768 /* We have a completed input line, convert the struct cell data to its
1769 * plain character equivalent */
1773 len
= _ncl_cell2dat(&l
);
1783 # ifdef HAVE_HISTORY
1787 size_t lsize
, cnt
, llen
;
1791 _ncl_oint
.sint
= _ncl_oquit
.sint
= _ncl_oterm
.sint
=
1792 _ncl_ohup
.sint
= _ncl_otstp
.sint
= _ncl_ottin
.sint
=
1793 _ncl_ottou
.sint
= -1;
1795 # ifdef HAVE_HISTORY
1798 _ncl_hist_size_max
= hs
;
1806 hold_all_sigs(); /* TODO too heavy, yet we may jump even here!? */
1807 f
= fopen(v
, "r"); /* TODO HISTFILE LOAD: use linebuf pool */
1810 fcntl_lock(fileno(f
), FLOCK_READ
); /* TODO ouch, retval check, etc. */
1815 while (fgetline(&lbuf
, &lsize
, &cnt
, &llen
, f
, FAL0
) != NULL
) {
1816 if (llen
> 0 && lbuf
[llen
- 1] == '\n')
1817 lbuf
[--llen
] = '\0';
1818 if (llen
== 0 || lbuf
[0] == '#') /* xxx comments? noone! */
1820 _ncl_hist_load
= TRU1
;
1822 _ncl_hist_load
= FAL0
;
1829 rele_all_sigs(); /* XXX remove jumps */
1831 # endif /* HAVE_HISTORY */
1838 # ifdef HAVE_HISTORY
1846 # ifdef HAVE_HISTORY
1855 if ((hp
= _ncl_hist
) != NULL
)
1856 while (hp
->older
!= NULL
&& hs
-- != 0)
1859 hold_all_sigs(); /* TODO too heavy, yet we may jump even here!? */
1860 f
= fopen(v
, "w"); /* TODO temporary + rename?! */
1863 fcntl_lock(fileno(f
), FLOCK_WRITE
); /* TODO ouch, retval check, etc. */
1864 if (fchmod(fileno(f
), S_IRUSR
| S_IWUSR
) != 0)
1867 for (; hp
!= NULL
; hp
= hp
->younger
) {
1868 fwrite(hp
->dat
, sizeof *hp
->dat
, hp
->len
, f
);
1874 rele_all_sigs(); /* XXX remove jumps */
1876 # endif /* HAVE_HISTORY */
1883 sigset_t nset
, oset
;
1884 NYD_X
; /* Signal handler */
1888 /* We don't deal with SIGWINCH, yet get called from main.c */
1891 _ncl_term_mode(FAL0
);
1894 sigaddset(&nset
, sig
);
1895 sigprocmask(SIG_UNBLOCK
, &nset
, &oset
);
1897 /* When we come here we'll continue editing, so reestablish */
1898 sigprocmask(SIG_BLOCK
, &oset
, (sigset_t
*)NULL
);
1900 _ncl_term_mode(TRU1
);
1906 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
1912 /* Of course we have races here, but they cannot be avoided on POSIX
1913 * (except by even *more* actions) */
1915 _ncl_term_mode(TRU1
);
1916 nn
= _ncl_readline(prompt
, linebuf
, linesize
, n SMALLOC_DEBUG_ARGSCALL
);
1917 _ncl_term_mode(FAL0
);
1924 tty_addhist(char const *s
)
1926 # ifdef HAVE_HISTORY
1927 /* Super-Heavy-Metal: block all sigs, avoid leaks+ on jump */
1929 struct hist
*h
, *o
, *y
;
1934 # ifdef HAVE_HISTORY
1937 if (_ncl_hist_size_max
== 0)
1939 _CL_CHECK_ADDHIST(s
, goto j_leave
);
1941 /* Eliminating duplicates is expensive, but simply inacceptable so
1942 * during the load of a potentially large history file! */
1943 if (!_ncl_hist_load
)
1944 for (h
= _ncl_hist
; h
!= NULL
; h
= h
->older
)
1945 if (h
->len
== l
&& !strcmp(h
->dat
, s
)) {
1946 hold_all_sigs(); /* TODO */
1962 if (!_ncl_hist_load
&& _ncl_hist_size
> _ncl_hist_size_max
) {
1964 if ((h
= _ncl_hist_tail
) != NULL
) {
1965 if ((_ncl_hist_tail
= h
->younger
) == NULL
)
1968 _ncl_hist_tail
->older
= NULL
;
1973 h
= smalloc((sizeof(struct hist
) - VFIELD_SIZEOF(struct hist
, dat
)) + l
+1);
1975 memcpy(h
->dat
, s
, l
+1);
1977 if ((h
->older
= _ncl_hist
) != NULL
)
1978 _ncl_hist
->younger
= h
;
1990 # ifdef HAVE_HISTORY
2001 if (_ncl_hist
== NULL
)
2004 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
2013 for (h
= _ncl_hist
; h
!= NULL
; --i
, b
+= h
->len
, h
= h
->older
)
2014 fprintf(fp
, "%4lu. %-50.50s (%4lu+%lu bytes)\n",
2015 (ul_it
)i
, h
->dat
, (ul_it
)b
, (ul_it
)h
->len
);
2017 page_or_print(fp
, i
);
2024 while ((h
= _ncl_hist
) != NULL
) {
2025 _ncl_hist
= h
->older
;
2028 _ncl_hist_tail
= NULL
;
2034 struct hist
*h
= _ncl_hist
;
2035 if (UICMP(z
, entry
, <=, _ncl_hist_size
)) {
2036 entry
= (long)_ncl_hist_size
- entry
;
2037 for (h
= _ncl_hist
;; h
= h
->older
)
2040 else if (entry
-- != 0)
2043 v
= temporary_arg_v_store
= h
->dat
;
2051 # endif /* HAVE_HISTORY */
2052 #endif /* HAVE_NCL */
2055 * The really-nothing-at-all implementation
2058 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
2076 NYD_X
; /* Signal handler */
2081 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
2084 /* TODO The nothing-at-all tty layer even forces re-entering all the
2085 * TODO original data when re-editing a field */
2086 bool_t doffl
= FAL0
;
2090 if (prompt
!= NULL
&& *prompt
!= '\0') {
2091 fputs(prompt
, stdout
);
2095 fprintf(stdout
, tr(511, "{former content: %.*s} "), (int)n
, *linebuf
);
2101 rv
= (readline_restart
)(stdin
, linebuf
, linesize
,n SMALLOC_DEBUG_ARGSCALL
);
2107 tty_addhist(char const *s
)
2113 #endif /* nothing at all */
2115 /* vim:set fenc=utf-8:s-it-mode */