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",\
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 * volatile prompt
, bool_t noninteract_default
)
145 sighandler_type
volatile ohdl
;
146 bool_t
volatile hadsig
= FAL0
, rv
;
149 if (!(options
& OPT_INTERACTIVE
)) {
150 rv
= noninteract_default
;
156 prompt
= _("Continue (y/n)? ");
158 ohdl
= safe_signal(SIGINT
, SIG_IGN
);
159 if (sigsetjmp(__tty_actjmp
, 1) != 0) {
163 safe_signal(SIGINT
, &__tty_acthdl
);
165 if (readline_input(prompt
, FAL0
, &termios_state
.ts_linebuf
,
166 &termios_state
.ts_linesize
, NULL
) >= 0)
167 switch (termios_state
.ts_linebuf
[0]) {
168 case 'N': case 'n': rv
= FAL0
; break ;
169 default: rv
= TRU1
; break;
172 termios_state_reset();
173 safe_signal(SIGINT
, ohdl
);
176 if (hadsig
&& ohdl
!= SIG_IGN
)
183 getuser(char const * volatile query
) /* TODO v15-compat obsolete */
185 sighandler_type
volatile ohdl
;
186 char * volatile user
= NULL
;
187 bool_t
volatile hadsig
= FAL0
;
193 ohdl
= safe_signal(SIGINT
, SIG_IGN
);
194 if (sigsetjmp(__tty_actjmp
, 1) != 0) {
198 safe_signal(SIGINT
, &__tty_acthdl
);
200 if (readline_input(query
, FAL0
, &termios_state
.ts_linebuf
,
201 &termios_state
.ts_linesize
, NULL
) >= 0)
202 user
= termios_state
.ts_linebuf
;
204 termios_state_reset();
205 safe_signal(SIGINT
, ohdl
);
207 if (hadsig
&& ohdl
!= SIG_IGN
)
213 getpassword(char const *query
)
215 sighandler_type
volatile ohdl
;
217 char * volatile pass
= NULL
;
219 bool_t hadsig
= FAL0
; /* TODO getpassword() no longer reraises SIGINT */
224 query
= _("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) {
247 safe_signal(SIGINT
, &__tty_acthdl
);
249 if (readline_restart(stdin
, &termios_state
.ts_linebuf
,
250 &termios_state
.ts_linesize
, 0) >= 0)
251 pass
= termios_state
.ts_linebuf
;
253 termios_state_reset();
254 safe_signal(SIGINT
, ohdl
);
255 if (options
& OPT_TTYIN
)
259 if (hadsig
&& ohdl
!= SIG_IGN
)
264 #endif /* HAVE_SOCKETS */
271 static sighandler_type _rl_shup
;
272 static char * _rl_buf
; /* pre_input() hook: initial line */
273 static int _rl_buflen
; /* content, and its length */
275 static int _rl_pre_input(void);
281 /* Handle leftover data from \ escaped former line */
282 rl_extend_line_buffer(_rl_buflen
+ 10);
283 memcpy(rl_line_buffer
, _rl_buf
, _rl_buflen
+ 1);
284 rl_point
= rl_end
= _rl_buflen
;
285 rl_pre_input_hook
= (rl_hook_func_t
*)NULL
;
300 rl_readline_name
= UNCONST(uagent
);
304 stifle_history((int)hs
);
306 rl_read_init_file(NULL
);
308 /* Because rl_read_init_file() may have introduced yet a different
309 * history size limit, simply load and incorporate the history, leave
310 * it up to readline(3) to do the rest */
339 NYD_X
; /* Signal handler */
347 /* readline(3) doesn't catch it :( */
348 rl_free_line_state();
349 rl_cleanup_after_signal();
350 safe_signal(SIGHUP
, _rl_shup
);
352 sigaddset(&nset
, sig
);
353 sigprocmask(SIG_UNBLOCK
, &nset
, &oset
);
355 /* XXX When we come here we'll continue editing, so reestablish
356 * XXX cannot happen */
357 sigprocmask(SIG_BLOCK
, &oset
, NULL
);
358 _rl_shup
= safe_signal(SIGHUP
, &tty_signal
);
359 rl_reset_after_signal();
367 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
377 rl_pre_input_hook
= &_rl_pre_input
;
380 _rl_shup
= safe_signal(SIGHUP
, &tty_signal
);
381 line
= readline(prompt
!= NULL
? prompt
: "");
382 safe_signal(SIGHUP
, _rl_shup
);
390 if (n
>= *linesize
) {
391 *linesize
= LINESIZE
+ n
+1;
392 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
394 memcpy(*linebuf
, line
, n
);
396 (*linebuf
)[n
] = '\0';
404 tty_addhist(char const *s
, bool_t isgabby
)
410 if (isgabby
&& !ok_blook(history_gabby
))
412 _CL_CHECK_ADDHIST(s
, goto jleave
);
413 hold_all_sigs(); /* XXX too heavy */
414 add_history(s
); /* XXX yet we jump away! */
415 rele_all_sigs(); /* XXX remove jumps */
433 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
440 hs
= history_get_history_state();
442 for (i
= (ul_it
)hs
->length
, hl
= hs
->entries
+ i
, b
= 0; i
> 0; --i
) {
443 char *cp
= (*--hl
)->line
;
444 size_t sl
= strlen(cp
);
445 fprintf(fp
, "%4lu. %-50.50s (%4lu+%2lu bytes)\n", i
, cp
, b
, sl
);
449 page_or_print(fp
, (size_t)hs
->length
);
459 HISTORY_STATE
*hs
= history_get_history_state();
461 if (UICMP(z
, entry
, <=, hs
->length
))
462 v
= temporary_arg_v_store
= hs
->entries
[entry
- 1]->line
;
468 # endif /* HAVE_HISTORY */
469 #endif /* HAVE_READLINE */
476 static EditLine
* _el_el
; /* editline(3) handle */
477 static char const * _el_prompt
; /* Current prompt */
479 static History
* _el_hcom
; /* History handle for commline */
482 static char const * _el_getprompt(void);
502 _el_hcom
= history_init();
503 history(_el_hcom
, &he
, H_SETSIZE
, (int)hs
);
504 /* We unroll our own one history(_el_hcom, &he, H_SETUNIQUE, 1);*/
507 _el_el
= el_init(uagent
, stdin
, stdout
, stderr
);
508 el_set(_el_el
, EL_SIGNAL
, 1);
509 el_set(_el_el
, EL_TERMINAL
, NULL
);
510 /* Need to set HIST before EDITOR, otherwise it won't work automatic */
512 el_set(_el_el
, EL_HIST
, &history
, _el_hcom
);
514 el_set(_el_el
, EL_EDITOR
, "emacs");
515 # ifdef EL_PROMPT_ESC
516 el_set(_el_el
, EL_PROMPT_ESC
, &_el_getprompt
, '\1');
518 el_set(_el_el
, EL_PROMPT
, &_el_getprompt
);
521 el_set(_el_el
, EL_ADDFN
, "tab_complete",
522 "editline(3) internal completion function", &_el_file_cpl
);
523 el_set(_el_el
, EL_BIND
, "^I", "tab_complete", NULL
);
526 el_set(_el_el
, EL_BIND
, "^R", "ed-search-prev-history", NULL
);
528 el_source(_el_el
, NULL
); /* Source ~/.editrc */
530 /* Because el_source() may have introduced yet a different history size
531 * limit, simply load and incorporate the history, leave it up to
532 * editline(3) to do the rest */
536 history(_el_hcom
, &he
, H_LOAD
, v
);
555 history(_el_hcom
, &he
, H_SAVE
, v
);
556 history_end(_el_hcom
);
564 NYD_X
; /* Signal handler */
577 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
584 _el_prompt
= (prompt
!= NULL
) ? prompt
: "";
586 el_push(_el_el
, *linebuf
);
587 line
= el_gets(_el_el
, &nn
);
595 if (n
> 0 && line
[n
- 1] == '\n')
598 if (n
>= *linesize
) {
599 *linesize
= LINESIZE
+ n
+ 1;
600 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
602 memcpy(*linebuf
, line
, n
);
603 (*linebuf
)[n
] = '\0';
610 tty_addhist(char const *s
, bool_t isgabby
)
613 /* Enlarge meaning of unique .. to something that rocks;
614 * xxx unfortunately this is expensive to do with editline(3)
615 * xxx maybe it would be better to hook the ptfs instead? */
624 if (isgabby
&& !ok_blook(history_gabby
))
626 _CL_CHECK_ADDHIST(s
, goto jleave
);
628 hold_all_sigs(); /* XXX too heavy, yet we jump away! */
629 for (i
= history(_el_hcom
, &he
, H_FIRST
); i
>= 0;
630 i
= history(_el_hcom
, &he
, H_NEXT
))
631 if (!strcmp(he
.str
, s
)) {
632 history(_el_hcom
, &he
, H_DEL
, he
.num
);
635 history(_el_hcom
, &he
, H_ENTER
, s
);
636 rele_all_sigs(); /* XXX remove jumps */
654 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
661 i
= (size_t)((history(_el_hcom
, &he
, H_GETSIZE
) >= 0) ? he
.num
: 0);
663 for (x
= history(_el_hcom
, &he
, H_FIRST
); x
>= 0;
664 x
= history(_el_hcom
, &he
, H_NEXT
)) {
665 size_t sl
= strlen(he
.str
);
666 fprintf(fp
, "%4lu. %-50.50s (%4lu+%2lu bytes)\n",
667 (ul_it
)i
, he
.str
, (ul_it
)b
, (ul_it
)sl
);
672 page_or_print(fp
, i
);
679 history(_el_hcom
, &he
, H_CLEAR
);
688 i
= (size_t)((history(_el_hcom
, &he
, H_GETSIZE
) >= 0) ? he
.num
: 0);
689 if (UICMP(z
, entry
, <=, i
)) {
690 entry
= (long)i
- entry
;
691 for (x
= history(_el_hcom
, &he
, H_FIRST
); x
>= 0;
692 x
= history(_el_hcom
, &he
, H_NEXT
))
694 v
= temporary_arg_v_store
= UNCONST(he
.str
);
702 # endif /* HAVE_HISTORY */
703 #endif /* HAVE_EDITLINE */
706 * NCL: our homebrew version (inspired from NetBSD sh(1) / dash(1)s hetio.c).
708 * Only used in interactive mode, simply use STDIN_FILENO as point of interest.
709 * We do not handle character widths because the terminal must deal with that
710 * anyway on the one hand, and also wcwidth(3) doesn't support zero-width
711 * characters by definition on the other. We're addicted.
713 * To avoid memory leaks etc. with the current codebase that simply longjmp(3)s
714 * we're forced to use the very same buffer--the one that is passed through to
715 * us from the outside--to store anything we need, i.e., a `struct cell[]', and
716 * convert that on-the-fly back to the plain char* result once we're done.
717 * To simplify our live, use savestr() buffers for all other needed memory
721 * TODO NCL: don't use that stupid .sint=-1 stuff, but simply block all signals
722 * TODO NCL: during handler de-/installation handling.
727 # define MAX_INPUT 255 /* (_POSIX_MAX_INPUT = 255 as of Issue 7 TC1) */
730 /* Since we simply fputs(3) the prompt, assume each character requires two
731 * visual cells -- and we need to restrict the maximum prompt size because
732 * of MAX_INPUT and our desire to have room for some error message left */
733 # define _PROMPT_VLEN(P) (strlen(P) * 2)
734 # define _PROMPT_MAX ((MAX_INPUT / 2) + (MAX_INPUT / 4))
737 sighandler_type shdl
; /* Try avoid races by setting */
738 sl_it sint
; /* .sint=-1 when inactive */
740 CTA(sizeof(sl_it
) >= sizeof(sighandler_type
));
750 char cbuf
[MB_LEN_MAX
* 2]; /* .. plus reset shift sequence */
754 size_t cursor
; /* Current cursor position */
755 size_t topins
; /* Outermost cursor col set */
757 char *cbuf
; /* *x_buf */
760 struct str defc
; /* Current default content */
761 struct str savec
; /* Saved default content */
763 struct hist
*hist
; /* History cursor */
766 char const *nd
; /* Cursor right */
767 char **x_buf
; /* Caller pointers */
774 struct hist
*younger
;
777 char dat
[VFIELD_SIZE(sizeof(ui32_t
))];
781 static union xsighdl _ncl_oint
;
782 static union xsighdl _ncl_oquit
;
783 static union xsighdl _ncl_oterm
;
784 static union xsighdl _ncl_ohup
;
785 static union xsighdl _ncl_otstp
;
786 static union xsighdl _ncl_ottin
;
787 static union xsighdl _ncl_ottou
;
788 static struct xtios _ncl_tios
;
790 static struct hist
*_ncl_hist
;
791 static struct hist
*_ncl_hist_tail
;
792 static size_t _ncl_hist_size
;
793 static size_t _ncl_hist_size_max
;
794 static bool_t _ncl_hist_load
;
797 static void _ncl_sigs_up(void);
798 static void _ncl_sigs_down(void);
800 static void _ncl_term_mode(bool_t raw
);
802 static void _ncl_check_grow(struct line
*l
, size_t no SMALLOC_DEBUG_ARGS
);
803 static void _ncl_bs_eof_dvup(struct cell
*cap
, size_t i
);
804 static ssize_t
_ncl_wboundary(struct line
*l
, ssize_t dir
);
805 static ssize_t
_ncl_cell2dat(struct line
*l
);
806 # if defined HAVE_HISTORY || defined HAVE_TABEXPAND
807 static void _ncl_cell2save(struct line
*l
);
810 static void _ncl_khome(struct line
*l
, bool_t dobell
);
811 static void _ncl_kend(struct line
*l
);
812 static void _ncl_kbs(struct line
*l
);
813 static void _ncl_kkill(struct line
*l
, bool_t dobell
);
814 static ssize_t
_ncl_keof(struct line
*l
);
815 static void _ncl_kleft(struct line
*l
);
816 static void _ncl_kright(struct line
*l
);
817 static void _ncl_krefresh(struct line
*l
);
818 static void _ncl_kbwddelw(struct line
*l
);
819 static void _ncl_kgow(struct line
*l
, ssize_t dir
);
820 static void _ncl_kother(struct line
*l
, wchar_t wc
);
822 static size_t __ncl_khist_shared(struct line
*l
, struct hist
*hp
);
823 static size_t _ncl_khist(struct line
*l
, bool_t backwd
);
824 static size_t _ncl_krhist(struct line
*l
);
826 # ifdef HAVE_TABEXPAND
827 static size_t _ncl_kht(struct line
*l
);
829 static ssize_t
_ncl_readline(char const *prompt
, char **buf
, size_t *bufsize
,
830 size_t len SMALLOC_DEBUG_ARGS
);
836 if (_ncl_oint
.sint
== -1)
837 _ncl_oint
.shdl
= safe_signal(SIGINT
, &tty_signal
);
838 if (_ncl_oquit
.sint
== -1)
839 _ncl_oquit
.shdl
= safe_signal(SIGQUIT
, &tty_signal
);
840 if (_ncl_oterm
.sint
== -1)
841 _ncl_oterm
.shdl
= safe_signal(SIGTERM
, &tty_signal
);
842 if (_ncl_ohup
.sint
== -1)
843 _ncl_ohup
.shdl
= safe_signal(SIGHUP
, &tty_signal
);
844 if (_ncl_otstp
.sint
== -1)
845 _ncl_otstp
.shdl
= safe_signal(SIGTSTP
, &tty_signal
);
846 if (_ncl_ottin
.sint
== -1)
847 _ncl_ottin
.shdl
= safe_signal(SIGTTIN
, &tty_signal
);
848 if (_ncl_ottou
.sint
== -1)
849 _ncl_ottou
.shdl
= safe_signal(SIGTTOU
, &tty_signal
);
856 /* aaah.. atomic cas would be nice (but isn't it all redundant?) */
860 if (_ncl_ottou
.sint
!= -1) {
861 st
= _ncl_ottou
.shdl
, _ncl_ottou
.sint
= -1;
862 safe_signal(SIGTTOU
, st
);
864 if (_ncl_ottin
.sint
!= -1) {
865 st
= _ncl_ottin
.shdl
, _ncl_ottin
.sint
= -1;
866 safe_signal(SIGTTIN
, st
);
868 if (_ncl_otstp
.sint
!= -1) {
869 st
= _ncl_otstp
.shdl
, _ncl_otstp
.sint
= -1;
870 safe_signal(SIGTSTP
, st
);
872 if (_ncl_ohup
.sint
!= -1) {
873 st
= _ncl_ohup
.shdl
, _ncl_ohup
.sint
= -1;
874 safe_signal(SIGHUP
, st
);
876 if (_ncl_oterm
.sint
!= -1) {
877 st
= _ncl_oterm
.shdl
, _ncl_oterm
.sint
= -1;
878 safe_signal(SIGTERM
, st
);
880 if (_ncl_oquit
.sint
!= -1) {
881 st
= _ncl_oquit
.shdl
, _ncl_oquit
.sint
= -1;
882 safe_signal(SIGQUIT
, st
);
884 if (_ncl_oint
.sint
!= -1) {
885 st
= _ncl_oint
.shdl
, _ncl_oint
.sint
= -1;
886 safe_signal(SIGINT
, st
);
892 _ncl_term_mode(bool_t raw
)
894 struct termios
*tiosp
;
897 tiosp
= &_ncl_tios
.told
;
901 /* Always requery the attributes, in case we've been moved from background
902 * to foreground or however else in between sessions */
903 tcgetattr(STDIN_FILENO
, tiosp
);
904 memcpy(&_ncl_tios
.tnew
, tiosp
, sizeof *tiosp
);
905 tiosp
= &_ncl_tios
.tnew
;
906 tiosp
->c_cc
[VMIN
] = 1;
907 tiosp
->c_cc
[VTIME
] = 0;
908 tiosp
->c_iflag
&= ~(ISTRIP
);
909 tiosp
->c_lflag
&= ~(ECHO
/*| ECHOE | ECHONL */| ICANON
| IEXTEN
);
911 tcsetattr(STDIN_FILENO
, TCSADRAIN
, tiosp
);
916 _ncl_check_grow(struct line
*l
, size_t no SMALLOC_DEBUG_ARGS
)
921 i
= (l
->topins
+ no
) * sizeof(struct cell
) + 2 * sizeof(struct cell
);
922 if (i
> *l
->x_bufsize
) {
926 *l
->x_buf
= (srealloc
)(*l
->x_buf
, i SMALLOC_DEBUG_ARGSCALL
);
932 _ncl_bs_eof_dvup(struct cell
*cap
, size_t i
)
938 memmove(cap
, cap
+ 1, i
* sizeof(*cap
));
940 /* And.. the (rest of the) visual update */
941 for (j
= 0; j
< i
; ++j
)
942 fwrite(cap
[j
].cbuf
, sizeof *cap
->cbuf
, cap
[j
].count
, stdout
);
943 fputs(" \b", stdout
);
944 for (j
= 0; j
< i
; ++j
)
950 _ncl_wboundary(struct line
*l
, ssize_t dir
)
967 --t
, --c
; /* Unsigned wrapping may occur (twice), then */
969 for (i
= 0, cap
= l
->line
.cells
, anynon
= FAL0
;;) {
970 wchar_t wc
= cap
[c
+ dir
].wc
;
971 if (iswblank(wc
) || iswpunct(wc
)) {
990 _ncl_cell2dat(struct line
*l
)
996 for (i
= 0; i
< l
->topins
; ++i
) {
997 struct cell
*cap
= l
->line
.cells
+ i
;
998 memcpy(l
->line
.cbuf
+ len
, cap
->cbuf
, cap
->count
);
1001 l
->line
.cbuf
[len
] = '\0';
1003 return (ssize_t
)len
;
1006 # if defined HAVE_HISTORY || defined HAVE_TABEXPAND
1008 _ncl_cell2save(struct line
*l
)
1014 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1018 for (cap
= l
->line
.cells
, len
= i
= 0; i
< l
->topins
; ++cap
, ++i
)
1022 l
->savec
.s
= salloc(len
+ 1);
1024 for (cap
= l
->line
.cells
, len
= i
= 0; i
< l
->topins
; ++cap
, ++i
) {
1025 memcpy(l
->savec
.s
+ len
, cap
->cbuf
, cap
->count
);
1028 l
->savec
.s
[len
] = '\0';
1035 _ncl_khome(struct line
*l
, bool_t dobell
)
1051 _ncl_kend(struct line
*l
)
1056 i
= (ssize_t
)(l
->topins
- l
->cursor
);
1059 l
->cursor
= l
->topins
;
1061 fputs(l
->nd
, stdout
);
1068 _ncl_kbs(struct line
*l
)
1081 _ncl_bs_eof_dvup(l
->line
.cells
+ c
, t
);
1088 _ncl_kkill(struct line
*l
, bool_t dobell
)
1094 i
= (size_t)(l
->topins
- c
);
1098 for (j
= i
; j
!= 0; --j
)
1100 for (j
= i
; j
!= 0; --j
)
1108 _ncl_keof(struct line
*l
)
1116 i
= (ssize_t
)(t
- c
);
1120 _ncl_bs_eof_dvup(l
->line
.cells
+ c
, --i
);
1121 } else if (t
== 0 && !ok_blook(ignoreeof
)) {
1122 fputs("^D", stdout
);
1134 _ncl_kleft(struct line
*l
)
1137 if (l
->cursor
> 0) {
1146 _ncl_kright(struct line
*l
)
1149 if (l
->cursor
< l
->topins
) {
1151 fputs(l
->nd
, stdout
);
1158 _ncl_krefresh(struct line
*l
)
1165 if (l
->prompt
!= NULL
&& *l
->prompt
!= '\0')
1166 fputs(l
->prompt
, stdout
);
1167 for (cap
= l
->line
.cells
, i
= l
->topins
; i
> 0; ++cap
, --i
)
1168 fwrite(cap
->cbuf
, sizeof *cap
->cbuf
, cap
->count
, stdout
);
1169 for (i
= l
->topins
- l
->cursor
; i
> 0; --i
)
1175 _ncl_kbwddelw(struct line
*l
)
1182 i
= _ncl_wboundary(l
, -1);
1193 cap
= l
->line
.cells
+ c
;
1195 if (t
!= l
->cursor
) {
1197 memmove(cap
, cap
+ i
, j
* sizeof(*cap
));
1200 for (j
= i
; j
> 0; --j
)
1202 for (j
= l
->topins
- c
; j
> 0; ++cap
, --j
)
1203 fwrite(cap
[0].cbuf
, sizeof *cap
->cbuf
, cap
[0].count
, stdout
);
1204 for (j
= i
; j
> 0; --j
)
1206 for (j
= t
- c
; j
> 0; --j
)
1213 _ncl_kgow(struct line
*l
, ssize_t dir
)
1218 i
= _ncl_wboundary(l
, dir
);
1232 fputs(l
->nd
, stdout
);
1239 _ncl_kother(struct line
*l
, wchar_t wc
)
1241 /* Append if at EOL, insert otherwise;
1242 * since we may move around character-wise, always use a fresh ps */
1244 struct cell cell
, *cap
;
1248 /* First init a cell and see wether we'll really handle this wc */
1250 memset(&ps
, 0, sizeof ps
);
1251 i
= wcrtomb(cell
.cbuf
, wc
, &ps
);
1254 cell
.count
= (ui_it
)i
;
1255 if (enc_has_state
) {
1256 i
= wcrtomb(cell
.cbuf
+ i
, L
'\0', &ps
);
1259 else if (--i
< MB_LEN_MAX
)
1260 cell
.count
+= (ui_it
)i
;
1265 /* Yes, we will! Place it in the array */
1267 i
= l
->topins
++ - c
;
1268 cap
= l
->line
.cells
+ c
;
1270 memmove(cap
+ 1, cap
, i
* sizeof(cell
));
1271 memcpy(cap
, &cell
, sizeof cell
);
1273 /* And update visual */
1276 fwrite(cap
->cbuf
, sizeof *cap
->cbuf
, cap
->count
, stdout
);
1277 while ((++cap
, i
-- != 0));
1284 # ifdef HAVE_HISTORY
1286 __ncl_khist_shared(struct line
*l
, struct hist
*hp
)
1291 if ((l
->hist
= hp
) != NULL
) {
1292 l
->defc
.s
= savestrbuf(hp
->dat
, hp
->len
);
1294 l
->defc
.l
= hp
->len
;
1295 if (l
->topins
> 0) {
1296 _ncl_khome(l
, FAL0
);
1297 _ncl_kkill(l
, FAL0
);
1308 _ncl_khist(struct line
*l
, bool_t backwd
)
1314 /* If we're not in history mode yet, save line content;
1315 * also, disallow forward search, then, and, of course, bail unless we
1316 * do have any history at all */
1317 if ((hp
= l
->hist
) == NULL
) {
1320 if ((hp
= _ncl_hist
) == NULL
)
1326 hp
= backwd
? hp
->older
: hp
->younger
;
1328 rv
= __ncl_khist_shared(l
, hp
);
1334 _ncl_krhist(struct line
*l
)
1336 struct str orig_savec
;
1337 struct hist
*hp
= NULL
;
1341 /* We cannot complete an empty line */
1342 if (l
->topins
== 0) {
1343 /* XXX The upcoming hard reset would restore a set savec buffer,
1344 * XXX so forcefully reset that. A cleaner solution would be to
1345 * XXX reset it whenever a restore is no longer desired */
1346 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1349 if ((hp
= l
->hist
) == NULL
) {
1350 if ((hp
= _ncl_hist
) == NULL
)
1352 orig_savec
.s
= NULL
;
1353 orig_savec
.l
= 0; /* silence CC */
1354 } else if ((hp
= hp
->older
) == NULL
)
1357 orig_savec
= l
->savec
;
1359 if (orig_savec
.s
== NULL
)
1361 for (; hp
!= NULL
; hp
= hp
->older
)
1362 if (is_prefix(l
->savec
.s
, hp
->dat
))
1364 if (orig_savec
.s
!= NULL
)
1365 l
->savec
= orig_savec
;
1367 rv
= __ncl_khist_shared(l
, hp
);
1373 # ifdef HAVE_TABEXPAND
1375 _ncl_kht(struct line
*l
)
1377 struct str orig
, bot
, topp
, sub
, exp
;
1378 struct cell
*cword
, *ctop
, *cx
;
1379 bool_t set_savec
= FAL0
;
1383 /* We cannot expand an empty line */
1387 /* Get plain line data; if this is the first expansion/xy, update the
1388 * very original content so that ^G gets the origin back */
1398 cword
= l
->line
.cells
;
1399 ctop
= cword
+ l
->cursor
;
1401 /* topp: separate data right of cursor */
1402 if ((cx
= cword
+ l
->topins
) != ctop
) {
1403 for (rv
= 0; cx
> ctop
; --cx
)
1406 topp
.s
= orig
.s
+ orig
.l
- rv
;
1408 topp
.s
= NULL
, topp
.l
= 0;
1410 /* bot, sub: we cannot expand the entire data left of cursor, but only
1411 * the last "word", so separate them */
1412 while (cx
> cword
&& !iswspace(cx
[-1].wc
))
1414 for (rv
= 0; cword
< cx
; ++cword
)
1423 /* Leave room for "implicit asterisk" expansion, as below */
1425 sub
.s
= UNCONST("*");
1428 exp
.s
= salloc(sub
.l
+ 1 +1);
1429 memcpy(exp
.s
, sub
.s
, sub
.l
);
1430 exp
.s
[sub
.l
] = '\0';
1434 /* TODO there is a TODO note upon fexpand() with multi-return;
1435 * TODO if that will change, the if() below can be simplified */
1436 /* Super-Heavy-Metal: block all sigs, avoid leaks on jump */
1439 exp
.s
= fexpand(sub
.s
, _CL_TAB_FEXP_FL
);
1442 if (exp
.s
== NULL
|| (exp
.l
= strlen(exp
.s
)) == 0)
1444 /* If the expansion equals the original string, assume the user wants what
1445 * is usually known as tab completion, append `*' and restart */
1446 if (exp
.l
== sub
.l
&& !strcmp(exp
.s
, sub
.s
)) {
1447 if (sub
.s
[sub
.l
- 1] == '*')
1449 sub
.s
[sub
.l
++] = '*';
1450 sub
.s
[sub
.l
] = '\0';
1454 /* Cramp expansion length to MAX_INPUT, or 255 if not defined.
1455 * Take care to take *prompt* into account, since we don't know
1456 * anything about it's visual length (fputs(3) is used), simply
1457 * assume each character requires two columns */
1458 /* TODO the problem is that we loose control otherwise; in the best
1459 * TODO case the user can control via ^A and ^K etc., but be safe;
1460 * TODO we cannot simply adjust fexpand() because we don't know how
1461 * TODO that is implemented... The real solution would be to check
1462 * TODO wether we fit on a line, and start a pager if not.
1463 * TODO However, that should be part of a real tab-COMPLETION, then,
1464 * TODO i.e., don't EXPAND, but SHOW COMPLETIONS, page-wise if needed.
1465 * TODO And: MAX_INPUT is dynamic: pathconf(2), _SC_MAX_INPUT */
1466 rv
= (l
->prompt
!= NULL
) ? _PROMPT_VLEN(l
->prompt
) : 0;
1467 if (rv
+ bot
.l
+ exp
.l
+ topp
.l
>= MAX_INPUT
) {
1468 char const e1
[] = "[ERR_TOO_LONG]";
1469 exp
.s
= UNCONST(e1
);
1470 exp
.l
= sizeof(e1
) - 1;
1472 if (rv
+ bot
.l
+ exp
.l
>= MAX_INPUT
)
1474 if (rv
+ exp
.l
>= MAX_INPUT
) {
1475 char const e2
[] = "[ERR]";
1476 exp
.s
= UNCONST(e2
);
1477 exp
.l
= sizeof(e2
) - 1;
1481 orig
.l
= bot
.l
+ exp
.l
+ topp
.l
;
1482 orig
.s
= salloc(orig
.l
+ 5 +1);
1483 if ((rv
= bot
.l
) > 0)
1484 memcpy(orig
.s
, bot
.s
, rv
);
1485 memcpy(orig
.s
+ rv
, exp
.s
, exp
.l
);
1488 memcpy(orig
.s
+ rv
, topp
.s
, topp
.l
);
1494 _ncl_khome(l
, FAL0
);
1495 _ncl_kkill(l
, FAL0
);
1500 /* If we've provided a default content, but failed to expand, there is
1501 * nothing we can "revert to": drop that default again */
1503 l
->savec
.s
= NULL
, l
->savec
.l
= 0;
1507 # endif /* HAVE_TABEXPAND */
1510 _ncl_readline(char const *prompt
, char **buf
, size_t *bufsize
, size_t len
1513 /* We want to save code, yet we may have to incorporate a lines'
1514 * default content and / or default input to switch back to after some
1515 * history movement; let "len > 0" mean "have to display some data
1516 * buffer", and only otherwise read(2) it */
1519 char cbuf_base
[MB_LEN_MAX
* 2], *cbuf
, *cbufp
, cursor_maybe
, cursor_store
;
1524 memset(&l
, 0, sizeof l
);
1527 l
.defc
.s
= savestrbuf(*buf
, len
);
1530 if ((l
.prompt
= prompt
) != NULL
&& _PROMPT_VLEN(prompt
) > _PROMPT_MAX
)
1531 l
.prompt
= prompt
= "?ERR?";
1532 /* TODO *l.nd=='\0' : instead adjust accmacvar.c to disallow empty vals */
1533 if ((l
.nd
= ok_vlook(line_editor_cursor_right
)) == NULL
|| *l
.nd
== '\0')
1534 l
.nd
= "\033[C"; /* XXX no "magic" constant */
1536 l
.x_bufsize
= bufsize
;
1538 if (prompt
!= NULL
&& *prompt
!= '\0') {
1539 fputs(prompt
, stdout
);
1543 memset(ps
, 0, sizeof ps
);
1544 cursor_maybe
= cursor_store
= 0;
1545 /* TODO: NCL: we should output the reset sequence when we jrestart:
1546 * TODO: NCL: if we are using a stateful encoding? !
1547 * TODO: NCL: in short: this is not yet well understood */
1549 _ncl_check_grow(&l
, len SMALLOC_DEBUG_ARGSCALL
);
1551 /* Normal read(2)? Else buffer-takeover: speed this one up */
1556 assert(l
.defc
.l
> 0 && l
.defc
.s
!= NULL
);
1558 cbuf
= l
.defc
.s
+ (l
.defc
.l
- len
);
1562 /* Read in the next complete multibyte character */
1565 if ((rv
= read(STDIN_FILENO
, cbufp
, 1)) < 1) {
1566 if (errno
== EINTR
) /* xxx #if !SA_RESTART ? */
1573 /* Ach! the ISO C multibyte handling!
1574 * Encodings with locking shift states cannot really be helped, since
1575 * it is impossible to only query the shift state, as opposed to the
1576 * entire shift state + character pair (via ISO C functions) */
1577 rv
= (ssize_t
)mbrtowc(&wc
, cbuf
, PTR2SIZE(cbufp
- cbuf
), ps
+ 0);
1579 /* Any error during take-over can only result in a hard reset;
1580 * Otherwise, if it's a hard error, or if too many redundant shift
1581 * sequences overflow our buffer, also perform a hard reset */
1582 if (len
!= 0 || rv
== -1 ||
1583 sizeof cbuf_base
== PTR2SIZE(cbufp
- cbuf
)) {
1584 l
.savec
.s
= l
.defc
.s
= NULL
,
1585 l
.savec
.l
= l
.defc
.l
= len
= 0;
1590 /* Otherwise, due to the way we deal with the buffer, we need to
1591 * restore the mbstate_t from before this conversion */
1596 if (len
!= 0 && (len
-= (size_t)rv
) == 0)
1597 l
.defc
.s
= NULL
, l
.defc
.l
= 0;
1602 /* Don't interpret control bytes during buffer take-over */
1603 if (cbuf
!= cbuf_base
)
1606 case 'A' ^ 0x40: /* cursor home */
1607 _ncl_khome(&l
, TRU1
);
1609 case 'B' ^ 0x40: /* backward character */
1613 /* 'C': interrupt (CTRL-C) */
1614 case 'D' ^ 0x40: /* delete char forward if any, else EOF */
1615 if ((rv
= _ncl_keof(&l
)) < 0)
1618 case 'E' ^ 0x40: /* end of line */
1621 case 'F' ^ 0x40: /* forward character */
1626 case 'H' ^ 0x40: /* backspace */
1630 case 'I' ^ 0x40: /* horizontal tab */
1631 # ifdef HAVE_TABEXPAND
1632 if ((len
= _ncl_kht(&l
)) > 0)
1636 case 'J' ^ 0x40: /* NL (\n) */
1638 case 'G' ^ 0x40: /* full reset */
1641 case 'U' ^ 0x40: /* ^U: ^A + ^K */
1642 _ncl_khome(&l
, FAL0
);
1644 case 'K' ^ 0x40: /* kill from cursor to end of line */
1645 _ncl_kkill(&l
, (wc
== ('K' ^ 0x40) || l
.topins
== 0));
1646 /* (Handle full reset?) */
1647 if (wc
== ('G' ^ 0x40)) {
1648 # ifdef HAVE_HISTORY
1651 if ((len
= l
.savec
.l
) != 0) {
1653 l
.savec
.s
= NULL
, l
.savec
.l
= 0;
1659 case 'L' ^ 0x40: /* repaint line */
1664 case 'N' ^ 0x40: /* history next */
1666 # ifdef HAVE_HISTORY
1669 if ((len
= _ncl_khist(&l
, FAL0
)) > 0)
1677 case 'O' ^ 0x40: /* `dp' */
1681 cbuf_base
[2] = '\0';
1683 execute(cbuf_base
, TRU1
, 2);
1685 case 'P' ^ 0x40: /* history previous */
1687 # ifdef HAVE_HISTORY
1688 if ((len
= _ncl_khist(&l
, TRU1
)) > 0)
1696 case 'R' ^ 0x40: /* reverse history search */
1697 # ifdef HAVE_HISTORY
1698 if ((len
= _ncl_krhist(&l
)) > 0)
1707 /*case 'V' ^ 0x40: TODO*/ /* forward delete "word" */
1708 case 'W' ^ 0x40: /* backward delete "word" */
1711 case 'X' ^ 0x40: /* move cursor forward "word" */
1714 case 'Y' ^ 0x40: /* move cursor backward "word" */
1717 /* 'Z': suspend (CTRL-Z) */
1719 if (cursor_maybe
++ != 0)
1723 /* XXX Handle usual ^[[[ABCD1456] cursor keys: UGLY,"MAGIC",INFLEX */
1724 if (cursor_maybe
> 0) {
1725 if (++cursor_maybe
== 2) {
1729 } else if (cursor_maybe
== 3) {
1733 case L
'A': goto j_p
;
1734 case L
'B': goto j_n
;
1735 case L
'C': goto j_f
;
1736 case L
'D': goto j_b
;
1747 cursor_store
= ((wc
== L
'1') ? '0' :
1748 (wc
== L
'4' ? '$' : (wc
== L
'5' ? '-' : '+')));
1752 _ncl_kother(&l
, L
'[');
1758 x
[0] = cursor_store
;
1765 _ncl_kother(&l
, L
'[');
1766 _ncl_kother(&l
, (wchar_t)cursor_store
);
1772 _ncl_kother(&l
, wc
);
1773 /* Don't clear the history during takeover..
1774 * ..and also avoid fflush()ing unless we've worked entire buffer */
1777 # ifdef HAVE_HISTORY
1778 if (cbuf
== cbuf_base
)
1790 /* We have a completed input line, convert the struct cell data to its
1791 * plain character equivalent */
1795 len
= _ncl_cell2dat(&l
);
1805 # ifdef HAVE_HISTORY
1809 size_t lsize
, cnt
, llen
;
1813 _ncl_oint
.sint
= _ncl_oquit
.sint
= _ncl_oterm
.sint
=
1814 _ncl_ohup
.sint
= _ncl_otstp
.sint
= _ncl_ottin
.sint
=
1815 _ncl_ottou
.sint
= -1;
1817 # ifdef HAVE_HISTORY
1820 _ncl_hist_size_max
= hs
;
1828 hold_all_sigs(); /* TODO too heavy, yet we may jump even here!? */
1829 f
= fopen(v
, "r"); /* TODO HISTFILE LOAD: use linebuf pool */
1832 fcntl_lock(fileno(f
), FLOCK_READ
); /* TODO ouch, retval check, etc. */
1837 while (fgetline(&lbuf
, &lsize
, &cnt
, &llen
, f
, FAL0
) != NULL
) {
1838 if (llen
> 0 && lbuf
[llen
- 1] == '\n')
1839 lbuf
[--llen
] = '\0';
1840 if (llen
== 0 || lbuf
[0] == '#') /* xxx comments? noone! */
1843 bool_t isgabby
= (lbuf
[0] == '*');
1844 _ncl_hist_load
= TRU1
;
1845 tty_addhist(lbuf
+ isgabby
, isgabby
);
1846 _ncl_hist_load
= FAL0
;
1854 rele_all_sigs(); /* XXX remove jumps */
1856 # endif /* HAVE_HISTORY */
1863 # ifdef HAVE_HISTORY
1872 # ifdef HAVE_HISTORY
1880 if ((hp
= _ncl_hist
) != NULL
)
1881 while (hp
->older
!= NULL
&& hs
-- != 0)
1883 dogabby
= ok_blook(history_gabby_persist
);
1885 hold_all_sigs(); /* TODO too heavy, yet we may jump even here!? */
1886 f
= fopen(v
, "w"); /* TODO temporary + rename?! */
1889 fcntl_lock(fileno(f
), FLOCK_WRITE
); /* TODO ouch, retval check, etc. */
1890 if (fchmod(fileno(f
), S_IRUSR
| S_IWUSR
) != 0)
1893 for (; hp
!= NULL
; hp
= hp
->younger
) {
1894 if (!hp
->isgabby
|| dogabby
) {
1897 fwrite(hp
->dat
, sizeof *hp
->dat
, hp
->len
, f
);
1904 rele_all_sigs(); /* XXX remove jumps */
1906 # endif /* HAVE_HISTORY */
1913 sigset_t nset
, oset
;
1914 NYD_X
; /* Signal handler */
1918 /* We don't deal with SIGWINCH, yet get called from main.c */
1921 _ncl_term_mode(FAL0
);
1924 sigaddset(&nset
, sig
);
1925 sigprocmask(SIG_UNBLOCK
, &nset
, &oset
);
1927 /* When we come here we'll continue editing, so reestablish */
1928 sigprocmask(SIG_BLOCK
, &oset
, (sigset_t
*)NULL
);
1930 _ncl_term_mode(TRU1
);
1936 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
1942 /* Of course we have races here, but they cannot be avoided on POSIX
1943 * (except by even *more* actions) */
1945 _ncl_term_mode(TRU1
);
1946 nn
= _ncl_readline(prompt
, linebuf
, linesize
, n SMALLOC_DEBUG_ARGSCALL
);
1947 _ncl_term_mode(FAL0
);
1954 tty_addhist(char const *s
, bool_t isgabby
)
1956 # ifdef HAVE_HISTORY
1957 /* Super-Heavy-Metal: block all sigs, avoid leaks+ on jump */
1959 struct hist
*h
, *o
, *y
;
1965 # ifdef HAVE_HISTORY
1966 if (isgabby
&& !ok_blook(history_gabby
))
1968 if (_ncl_hist_size_max
== 0)
1970 _CL_CHECK_ADDHIST(s
, goto j_leave
);
1972 l
= (ui32_t
)strlen(s
);
1974 /* Eliminating duplicates is expensive, but simply inacceptable so
1975 * during the load of a potentially large history file! */
1976 if (!_ncl_hist_load
)
1977 for (h
= _ncl_hist
; h
!= NULL
; h
= h
->older
)
1978 if (h
->len
== l
&& !strcmp(h
->dat
, s
)) {
1979 hold_all_sigs(); /* TODO */
1981 h
->isgabby
= !!isgabby
;
1997 if (!_ncl_hist_load
&& _ncl_hist_size
> _ncl_hist_size_max
) {
1999 if ((h
= _ncl_hist_tail
) != NULL
) {
2000 if ((_ncl_hist_tail
= h
->younger
) == NULL
)
2003 _ncl_hist_tail
->older
= NULL
;
2008 h
= smalloc((sizeof(struct hist
) - VFIELD_SIZEOF(struct hist
, dat
)) + l
+1);
2009 h
->isgabby
= !!isgabby
;
2011 memcpy(h
->dat
, s
, l
+1);
2013 if ((h
->older
= _ncl_hist
) != NULL
)
2014 _ncl_hist
->younger
= h
;
2026 # ifdef HAVE_HISTORY
2037 if (_ncl_hist
== NULL
)
2040 if ((fp
= Ftmp(NULL
, "hist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
2049 for (h
= _ncl_hist
; h
!= NULL
; --i
, b
+= h
->len
, h
= h
->older
)
2050 fprintf(fp
, "%c%4" ZFMT
". %-50.50s (%4" ZFMT
"+%2u bytes)\n",
2051 (h
->isgabby
? '*' : ' '), i
, h
->dat
, b
, h
->len
);
2053 page_or_print(fp
, i
);
2060 while ((h
= _ncl_hist
) != NULL
) {
2061 _ncl_hist
= h
->older
;
2064 _ncl_hist_tail
= NULL
;
2070 struct hist
*h
= _ncl_hist
;
2071 if (UICMP(z
, entry
, <=, _ncl_hist_size
)) {
2072 entry
= (long)_ncl_hist_size
- entry
;
2073 for (h
= _ncl_hist
;; h
= h
->older
)
2076 else if (entry
-- != 0)
2079 v
= temporary_arg_v_store
= h
->dat
;
2087 # endif /* HAVE_HISTORY */
2088 #endif /* HAVE_NCL */
2091 * The really-nothing-at-all implementation
2094 #if !defined HAVE_READLINE && !defined HAVE_EDITLINE && !defined HAVE_NCL
2112 NYD_X
; /* Signal handler */
2117 (tty_readline
)(char const *prompt
, char **linebuf
, size_t *linesize
, size_t n
2120 /* TODO The nothing-at-all tty layer even forces re-entering all the
2121 * TODO original data when re-editing a field */
2122 bool_t doffl
= FAL0
;
2126 if (prompt
!= NULL
&& *prompt
!= '\0') {
2127 fputs(prompt
, stdout
);
2131 fprintf(stdout
, _("{former content: %.*s} "), (int)n
, *linebuf
);
2137 rv
= (readline_restart
)(stdin
, linebuf
, linesize
,n SMALLOC_DEBUG_ARGSCALL
);
2143 tty_addhist(char const *s
, bool_t isgabby
)
2150 #endif /* nothing at all */