1 /* $NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #if !defined(lint) && !defined(SCCSID)
38 static char sccsid
[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
40 __RCSID("$NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $");
42 #endif /* not lint && not SCCSID */
45 * terminal.c: Editor/termcap-curses interface
46 * We have to declare a static variable here, since the
47 * termcap putchar routine does not take an argument!
49 #include <sys/types.h>
50 #include <sys/ioctl.h>
66 /* Solaris's term.h does horrid things. */
67 #if defined(HAVE_TERM_H) && !defined(__sun) && !defined(HAVE_TERMCAP_H)
79 * IMPORTANT NOTE: these routines are allowed to look at the current screen
80 * and the current position assuming that it is correct. If this is not
81 * true, then the update will be WRONG! This is (should be) a valid
85 #define TC_BUFSIZE ((size_t)2048)
87 #define GoodStr(a) (el->el_terminal.t_str[a] != NULL && \
88 el->el_terminal.t_str[a][0] != '\0')
89 #define Str(a) el->el_terminal.t_str[a]
90 #define Val(a) el->el_terminal.t_val[a]
92 static const struct termcapstr
{
94 const char *long_name
;
97 { "al", "add new blank line" },
99 { "bl", "audible bell" },
101 { "cd", "clear to bottom" },
103 { "ce", "clear to end of line" },
105 { "ch", "cursor to horiz pos" },
107 { "cl", "clear screen" },
109 { "dc", "delete a character" },
111 { "dl", "delete a line" },
113 { "dm", "start delete mode" },
115 { "ed", "end delete mode" },
117 { "ei", "end insert mode" },
119 { "fs", "cursor from status line" },
121 { "ho", "home cursor" },
123 { "ic", "insert character" },
125 { "im", "start insert mode" },
127 { "ip", "insert padding" },
129 { "kd", "sends cursor down" },
131 { "kl", "sends cursor left" },
133 { "kr", "sends cursor right" },
135 { "ku", "sends cursor up" },
137 { "md", "begin bold" },
139 { "me", "end attributes" },
141 { "nd", "non destructive space" },
143 { "se", "end standout" },
145 { "so", "begin standout" },
147 { "ts", "cursor to status line" },
149 { "up", "cursor up one" },
151 { "us", "begin underline" },
153 { "ue", "end underline" },
155 { "vb", "visible bell" },
157 { "DC", "delete multiple chars" },
159 { "DO", "cursor down multiple" },
161 { "IC", "insert multiple chars" },
163 { "LE", "cursor left multiple" },
165 { "RI", "cursor right multiple" },
167 { "UP", "cursor up multiple" },
169 { "kh", "send cursor home" },
171 { "@7", "send cursor end" },
173 { "kD", "send cursor delete" },
178 static const struct termcapval
{
180 const char *long_name
;
183 { "am", "has automatic margins" },
185 { "pt", "has physical tabs" },
187 { "li", "Number of lines" },
189 { "co", "Number of columns" },
191 { "km", "Has meta key" },
193 { "xt", "Tab chars destructive" },
195 { "xn", "newline ignored at right margin" },
197 { "MT", "Has meta key" }, /* XXX? */
201 /* do two or more of the attributes use me */
203 static void terminal_setflags(EditLine
*);
204 static int terminal_rebuffer_display(EditLine
*);
205 static void terminal_free_display(EditLine
*);
206 static int terminal_alloc_display(EditLine
*);
207 static void terminal_alloc(EditLine
*, const struct termcapstr
*,
209 static void terminal_init_arrow(EditLine
*);
210 static void terminal_reset_arrow(EditLine
*);
211 static int terminal_putc(int);
212 static void terminal_tputs(EditLine
*, const char *, int);
215 static pthread_mutex_t terminal_mutex
= PTHREAD_MUTEX_INITIALIZER
;
217 static FILE *terminal_outfile
= NULL
;
220 /* provide a stub curses which fails all calls if we have no tgetent et al */
221 #define tgoto(x, y, z) (char *)0
222 #define tgetstr(x, y) (char *)0
223 #define tgetent(x, y) -1;
224 #define tputs(x, y, z) -1
225 #define tgetflag(x) -1
226 #define tgetnum(x) -1
229 /* terminal_setflags():
230 * Set the terminal capability flags
233 terminal_setflags(EditLine
*el
)
236 if (el
->el_tty
.t_tabs
)
237 EL_FLAGS
|= (Val(T_pt
) && !Val(T_xt
)) ? TERM_CAN_TAB
: 0;
239 EL_FLAGS
|= (Val(T_km
) || Val(T_MT
)) ? TERM_HAS_META
: 0;
240 EL_FLAGS
|= GoodStr(T_ce
) ? TERM_CAN_CEOL
: 0;
241 EL_FLAGS
|= (GoodStr(T_dc
) || GoodStr(T_DC
)) ? TERM_CAN_DELETE
: 0;
242 EL_FLAGS
|= (GoodStr(T_im
) || GoodStr(T_ic
) || GoodStr(T_IC
)) ?
244 EL_FLAGS
|= (GoodStr(T_up
) || GoodStr(T_UP
)) ? TERM_CAN_UP
: 0;
245 EL_FLAGS
|= Val(T_am
) ? TERM_HAS_AUTO_MARGINS
: 0;
246 EL_FLAGS
|= Val(T_xn
) ? TERM_HAS_MAGIC_MARGINS
: 0;
248 if (GoodStr(T_me
) && GoodStr(T_ue
))
249 EL_FLAGS
|= (strcmp(Str(T_me
), Str(T_ue
)) == 0) ?
252 EL_FLAGS
&= ~TERM_CAN_ME
;
253 if (GoodStr(T_me
) && GoodStr(T_se
))
254 EL_FLAGS
|= (strcmp(Str(T_me
), Str(T_se
)) == 0) ?
260 (void) fprintf(el
->el_errfile
,
261 "WARNING: Your terminal cannot move up.\n");
262 (void) fprintf(el
->el_errfile
,
263 "Editing may be odd for long lines.\n");
266 (void) fprintf(el
->el_errfile
, "no clear EOL capability.\n");
268 (void) fprintf(el
->el_errfile
, "no delete char capability.\n");
270 (void) fprintf(el
->el_errfile
, "no insert char capability.\n");
271 #endif /* DEBUG_SCREEN */
275 * Initialize the terminal stuff
278 terminal_init(EditLine
*el
)
281 el
->el_terminal
.t_buf
= el_malloc(TC_BUFSIZE
*
282 sizeof(*el
->el_terminal
.t_buf
));
283 if (el
->el_terminal
.t_buf
== NULL
)
285 el
->el_terminal
.t_cap
= el_malloc(TC_BUFSIZE
*
286 sizeof(*el
->el_terminal
.t_cap
));
287 if (el
->el_terminal
.t_cap
== NULL
)
289 el
->el_terminal
.t_fkey
= el_malloc(A_K_NKEYS
*
290 sizeof(*el
->el_terminal
.t_fkey
));
291 if (el
->el_terminal
.t_fkey
== NULL
)
293 el
->el_terminal
.t_loc
= 0;
294 el
->el_terminal
.t_str
= el_malloc(T_str
*
295 sizeof(*el
->el_terminal
.t_str
));
296 if (el
->el_terminal
.t_str
== NULL
)
298 (void) memset(el
->el_terminal
.t_str
, 0, T_str
*
299 sizeof(*el
->el_terminal
.t_str
));
300 el
->el_terminal
.t_val
= el_malloc(T_val
*
301 sizeof(*el
->el_terminal
.t_val
));
302 if (el
->el_terminal
.t_val
== NULL
)
304 (void) memset(el
->el_terminal
.t_val
, 0, T_val
*
305 sizeof(*el
->el_terminal
.t_val
));
306 (void) terminal_set(el
, NULL
);
307 terminal_init_arrow(el
);
310 free(el
->el_terminal
.t_str
);
311 el
->el_terminal
.t_str
= NULL
;
313 free(el
->el_terminal
.t_fkey
);
314 el
->el_terminal
.t_fkey
= NULL
;
316 free(el
->el_terminal
.t_cap
);
317 el
->el_terminal
.t_cap
= NULL
;
319 free(el
->el_terminal
.t_buf
);
320 el
->el_terminal
.t_buf
= NULL
;
326 * Clean up the terminal stuff
329 terminal_end(EditLine
*el
)
332 el_free(el
->el_terminal
.t_buf
);
333 el
->el_terminal
.t_buf
= NULL
;
334 el_free(el
->el_terminal
.t_cap
);
335 el
->el_terminal
.t_cap
= NULL
;
336 el
->el_terminal
.t_loc
= 0;
337 el_free(el
->el_terminal
.t_str
);
338 el
->el_terminal
.t_str
= NULL
;
339 el_free(el
->el_terminal
.t_val
);
340 el
->el_terminal
.t_val
= NULL
;
341 el_free(el
->el_terminal
.t_fkey
);
342 el
->el_terminal
.t_fkey
= NULL
;
343 terminal_free_display(el
);
348 * Maintain a string pool for termcap strings
351 terminal_alloc(EditLine
*el
, const struct termcapstr
*t
, const char *cap
)
353 char termbuf
[TC_BUFSIZE
];
355 char **tlist
= el
->el_terminal
.t_str
;
356 char **tmp
, **str
= &tlist
[t
- tstr
];
358 (void) memset(termbuf
, 0, sizeof(termbuf
));
359 if (cap
== NULL
|| *cap
== '\0') {
365 tlen
= *str
== NULL
? 0 : strlen(*str
);
368 * New string is shorter; no need to allocate space
372 (void) strcpy(*str
, cap
); /* XXX strcpy is safe */
376 * New string is longer; see if we have enough space to append
378 if (el
->el_terminal
.t_loc
+ 3 < TC_BUFSIZE
) {
379 /* XXX strcpy is safe */
380 (void) strcpy(*str
= &el
->el_terminal
.t_buf
[
381 el
->el_terminal
.t_loc
], cap
);
382 el
->el_terminal
.t_loc
+= clen
+ 1; /* one for \0 */
386 * Compact our buffer; no need to check compaction, cause we know it
390 for (tmp
= tlist
; tmp
< &tlist
[T_str
]; tmp
++)
391 if (*tmp
!= NULL
&& **tmp
!= '\0' && *tmp
!= *str
) {
394 for (ptr
= *tmp
; *ptr
!= '\0'; termbuf
[tlen
++] = *ptr
++)
396 termbuf
[tlen
++] = '\0';
398 memcpy(el
->el_terminal
.t_buf
, termbuf
, TC_BUFSIZE
);
399 el
->el_terminal
.t_loc
= tlen
;
400 if (el
->el_terminal
.t_loc
+ 3 >= TC_BUFSIZE
) {
401 (void) fprintf(el
->el_errfile
,
402 "Out of termcap string space.\n");
405 /* XXX strcpy is safe */
406 (void) strcpy(*str
= &el
->el_terminal
.t_buf
[el
->el_terminal
.t_loc
],
408 el
->el_terminal
.t_loc
+= (size_t)clen
+ 1; /* one for \0 */
413 /* terminal_rebuffer_display():
414 * Rebuffer the display after the screen changed size
417 terminal_rebuffer_display(EditLine
*el
)
419 coord_t
*c
= &el
->el_terminal
.t_size
;
421 terminal_free_display(el
);
426 if (terminal_alloc_display(el
) == -1)
432 /* terminal_alloc_display():
433 * Allocate a new display.
436 terminal_alloc_display(EditLine
*el
)
440 coord_t
*c
= &el
->el_terminal
.t_size
;
442 b
= el_malloc(sizeof(*b
) * (size_t)(c
->v
+ 1));
445 for (i
= 0; i
< c
->v
; i
++) {
446 b
[i
] = el_malloc(sizeof(**b
) * (size_t)(c
->h
+ 1));
457 b
= el_malloc(sizeof(*b
) * (size_t)(c
->v
+ 1));
460 for (i
= 0; i
< c
->v
; i
++) {
461 b
[i
] = el_malloc(sizeof(**b
) * (size_t)(c
->h
+ 1));
473 terminal_free_display(el
);
478 /* terminal_free_display():
479 * Free the display buffers
482 terminal_free_display(EditLine
*el
)
488 el
->el_display
= NULL
;
490 for (bufp
= b
; *bufp
!= NULL
; bufp
++)
495 el
->el_vdisplay
= NULL
;
497 for (bufp
= b
; *bufp
!= NULL
; bufp
++)
504 /* terminal_move_to_line():
505 * move to line <where> (first line == 0)
506 * as efficiently as possible
509 terminal_move_to_line(EditLine
*el
, int where
)
513 if (where
== el
->el_cursor
.v
)
516 if (where
> el
->el_terminal
.t_size
.v
) {
518 (void) fprintf(el
->el_errfile
,
519 "%s: where is ridiculous: %d\r\n", __func__
, where
);
520 #endif /* DEBUG_SCREEN */
523 if ((del
= where
- el
->el_cursor
.v
) > 0) {
525 if (EL_HAS_AUTO_MARGINS
&&
526 el
->el_display
[el
->el_cursor
.v
][0] != '\0') {
528 (el
->el_terminal
.t_size
.h
- 1);
530 el
->el_display
[el
->el_cursor
.v
][h
] ==
534 /* move without newline */
535 terminal_move_to_char(el
, (int)h
);
536 terminal_overwrite(el
, &el
->el_display
537 [el
->el_cursor
.v
][el
->el_cursor
.h
],
538 (size_t)(el
->el_terminal
.t_size
.h
-
543 if ((del
> 1) && GoodStr(T_DO
)) {
544 terminal_tputs(el
, tgoto(Str(T_DO
), del
,
548 for (; del
> 0; del
--)
549 terminal__putc(el
, '\n');
550 /* because the \n will become \r\n */
555 } else { /* del < 0 */
556 if (GoodStr(T_UP
) && (-del
> 1 || !GoodStr(T_up
)))
557 terminal_tputs(el
, tgoto(Str(T_UP
), -del
, -del
), -del
);
560 for (; del
< 0; del
++)
561 terminal_tputs(el
, Str(T_up
), 1);
564 el
->el_cursor
.v
= where
;/* now where is here */
568 /* terminal_move_to_char():
569 * Move to the character position specified
572 terminal_move_to_char(EditLine
*el
, int where
)
577 if (where
== el
->el_cursor
.h
)
580 if (where
> el
->el_terminal
.t_size
.h
) {
582 (void) fprintf(el
->el_errfile
,
583 "%s: where is ridiculous: %d\r\n", __func__
, where
);
584 #endif /* DEBUG_SCREEN */
587 if (!where
) { /* if where is first column */
588 terminal__putc(el
, '\r'); /* do a CR */
592 del
= where
- el
->el_cursor
.h
;
594 if ((del
< -4 || del
> 4) && GoodStr(T_ch
))
595 /* go there directly */
596 terminal_tputs(el
, tgoto(Str(T_ch
), where
, where
), where
);
598 if (del
> 0) { /* moving forward */
599 if ((del
> 4) && GoodStr(T_RI
))
600 terminal_tputs(el
, tgoto(Str(T_RI
), del
, del
),
603 /* if I can do tabs, use them */
605 if ((el
->el_cursor
.h
& 0370) !=
608 el
->el_cursor
.v
][where
& 0370] !=
611 /* if not within tab stop */
613 (el
->el_cursor
.h
& 0370);
619 el
->el_cursor
.h
= where
& ~0x7;
623 * it's usually cheaper to just write the
627 * NOTE THAT terminal_overwrite() WILL CHANGE
630 terminal_overwrite(el
, &el
->el_display
[
631 el
->el_cursor
.v
][el
->el_cursor
.h
],
632 (size_t)(where
- el
->el_cursor
.h
));
635 } else { /* del < 0 := moving backward */
636 if ((-del
> 4) && GoodStr(T_LE
))
637 terminal_tputs(el
, tgoto(Str(T_LE
), -del
, -del
),
639 else { /* can't go directly there */
641 * if the "cost" is greater than the "cost"
645 ((unsigned int)-del
>
646 (((unsigned int) where
>> 3) +
649 terminal__putc(el
, '\r');/* do a CR */
651 goto mc_again
; /* and try again */
653 for (i
= 0; i
< -del
; i
++)
654 terminal__putc(el
, '\b');
658 el
->el_cursor
.h
= where
; /* now where is here */
662 /* terminal_overwrite():
663 * Overstrike num characters
664 * Assumes MB_FILL_CHARs are present to keep the column count correct
667 terminal_overwrite(EditLine
*el
, const wchar_t *cp
, size_t n
)
672 if (n
> (size_t)el
->el_terminal
.t_size
.h
) {
674 (void) fprintf(el
->el_errfile
,
675 "%s: n is ridiculous: %zu\r\n", __func__
, n
);
676 #endif /* DEBUG_SCREEN */
681 /* terminal__putc() ignores any MB_FILL_CHARs */
682 terminal__putc(el
, *cp
++);
686 if (el
->el_cursor
.h
>= el
->el_terminal
.t_size
.h
) { /* wrap? */
687 if (EL_HAS_AUTO_MARGINS
) { /* yes */
690 if (EL_HAS_MAGIC_MARGINS
) {
691 /* force the wrap to avoid the "magic"
694 if ((c
= el
->el_display
[el
->el_cursor
.v
]
695 [el
->el_cursor
.h
]) != '\0') {
696 terminal_overwrite(el
, &c
, (size_t)1);
697 while (el
->el_display
[el
->el_cursor
.v
]
698 [el
->el_cursor
.h
] == MB_FILL_CHAR
)
701 terminal__putc(el
, ' ');
705 } else /* no wrap, but cursor stays on screen */
706 el
->el_cursor
.h
= el
->el_terminal
.t_size
.h
- 1;
711 /* terminal_deletechars():
712 * Delete num characters
715 terminal_deletechars(EditLine
*el
, int num
)
720 if (!EL_CAN_DELETE
) {
722 (void) fprintf(el
->el_errfile
, " ERROR: cannot delete \n");
723 #endif /* DEBUG_EDIT */
726 if (num
> el
->el_terminal
.t_size
.h
) {
728 (void) fprintf(el
->el_errfile
,
729 "%s: num is ridiculous: %d\r\n", __func__
, num
);
730 #endif /* DEBUG_SCREEN */
733 if (GoodStr(T_DC
)) /* if I have multiple delete */
734 if ((num
> 1) || !GoodStr(T_dc
)) { /* if dc would be more
736 terminal_tputs(el
, tgoto(Str(T_DC
), num
, num
), num
);
739 if (GoodStr(T_dm
)) /* if I have delete mode */
740 terminal_tputs(el
, Str(T_dm
), 1);
742 if (GoodStr(T_dc
)) /* else do one at a time */
744 terminal_tputs(el
, Str(T_dc
), 1);
746 if (GoodStr(T_ed
)) /* if I have delete mode */
747 terminal_tputs(el
, Str(T_ed
), 1);
751 /* terminal_insertwrite():
752 * Puts terminal in insert character mode or inserts num
753 * characters in the line
754 * Assumes MB_FILL_CHARs are present to keep column count correct
757 terminal_insertwrite(EditLine
*el
, wchar_t *cp
, int num
)
761 if (!EL_CAN_INSERT
) {
763 (void) fprintf(el
->el_errfile
, " ERROR: cannot insert \n");
764 #endif /* DEBUG_EDIT */
767 if (num
> el
->el_terminal
.t_size
.h
) {
769 (void) fprintf(el
->el_errfile
,
770 "%s: num is ridiculous: %d\r\n", __func__
, num
);
771 #endif /* DEBUG_SCREEN */
774 if (GoodStr(T_IC
)) /* if I have multiple insert */
775 if ((num
> 1) || !GoodStr(T_ic
)) {
776 /* if ic would be more expensive */
777 terminal_tputs(el
, tgoto(Str(T_IC
), num
, num
), num
);
778 terminal_overwrite(el
, cp
, (size_t)num
);
779 /* this updates el_cursor.h */
782 if (GoodStr(T_im
) && GoodStr(T_ei
)) { /* if I have insert mode */
783 terminal_tputs(el
, Str(T_im
), 1);
785 el
->el_cursor
.h
+= num
;
787 terminal__putc(el
, *cp
++);
790 if (GoodStr(T_ip
)) /* have to make num chars insert */
791 terminal_tputs(el
, Str(T_ip
), 1);
793 terminal_tputs(el
, Str(T_ei
), 1);
797 if (GoodStr(T_ic
)) /* have to make num chars insert */
798 terminal_tputs(el
, Str(T_ic
), 1);
800 terminal__putc(el
, *cp
++);
804 if (GoodStr(T_ip
)) /* have to make num chars insert */
805 terminal_tputs(el
, Str(T_ip
), 1);
806 /* pad the inserted char */
812 /* terminal_clear_EOL():
813 * clear to end of line. There are num characters to clear
816 terminal_clear_EOL(EditLine
*el
, int num
)
820 if (EL_CAN_CEOL
&& GoodStr(T_ce
))
821 terminal_tputs(el
, Str(T_ce
), 1);
823 for (i
= 0; i
< num
; i
++)
824 terminal__putc(el
, ' ');
825 el
->el_cursor
.h
+= num
; /* have written num spaces */
830 /* terminal_clear_screen():
834 terminal_clear_screen(EditLine
*el
)
835 { /* clear the whole screen and home */
838 /* send the clear screen code */
839 terminal_tputs(el
, Str(T_cl
), Val(T_li
));
840 else if (GoodStr(T_ho
) && GoodStr(T_cd
)) {
841 terminal_tputs(el
, Str(T_ho
), Val(T_li
)); /* home */
842 /* clear to bottom of screen */
843 terminal_tputs(el
, Str(T_cd
), Val(T_li
));
845 terminal__putc(el
, '\r');
846 terminal__putc(el
, '\n');
852 * Beep the way the terminal wants us
855 terminal_beep(EditLine
*el
)
858 /* what termcap says we should use */
859 terminal_tputs(el
, Str(T_bl
), 1);
861 terminal__putc(el
, '\007'); /* an ASCII bell; ^G */
866 terminal_get(EditLine
*el
, const char **term
)
868 *term
= el
->el_terminal
.t_name
;
873 * Read in the terminal capabilities from the requested terminal
876 terminal_set(EditLine
*el
, const char *term
)
879 char buf
[TC_BUFSIZE
];
881 const struct termcapstr
*t
;
885 (void) sigemptyset(&nset
);
886 (void) sigaddset(&nset
, SIGWINCH
);
887 (void) sigprocmask(SIG_BLOCK
, &nset
, &oset
);
893 term
= getenv("TERM");
895 if (!term
|| !term
[0])
898 if (strcmp(term
, "emacs") == 0)
899 el
->el_flags
|= EDIT_DISABLED
;
901 (void) memset(el
->el_terminal
.t_cap
, 0, TC_BUFSIZE
);
903 i
= tgetent(el
->el_terminal
.t_cap
, term
);
907 (void) fprintf(el
->el_errfile
,
908 "Cannot read termcap database;\n");
910 (void) fprintf(el
->el_errfile
,
911 "No entry for terminal type \"%s\";\n", term
);
912 (void) fprintf(el
->el_errfile
,
913 "using dumb terminal settings.\n");
914 Val(T_co
) = 80; /* do a dumb terminal */
915 Val(T_pt
) = Val(T_km
) = Val(T_li
) = 0;
916 Val(T_xt
) = Val(T_MT
);
917 for (t
= tstr
; t
->name
!= NULL
; t
++)
918 terminal_alloc(el
, t
, NULL
);
920 /* auto/magic margins */
921 Val(T_am
) = tgetflag("am");
922 Val(T_xn
) = tgetflag("xn");
924 Val(T_pt
) = tgetflag("pt");
925 Val(T_xt
) = tgetflag("xt");
926 /* do we have a meta? */
927 Val(T_km
) = tgetflag("km");
928 Val(T_MT
) = tgetflag("MT");
930 Val(T_co
) = tgetnum("co");
931 Val(T_li
) = tgetnum("li");
932 for (t
= tstr
; t
->name
!= NULL
; t
++) {
933 /* XXX: some systems' tgetstr needs non const */
934 terminal_alloc(el
, t
, tgetstr(strchr(t
->name
, *t
->name
),
940 Val(T_co
) = 80; /* just in case */
944 el
->el_terminal
.t_size
.v
= Val(T_co
);
945 el
->el_terminal
.t_size
.h
= Val(T_li
);
947 terminal_setflags(el
);
949 /* get the correct window size */
950 (void) terminal_get_size(el
, &lins
, &cols
);
951 if (terminal_change_size(el
, lins
, cols
) == -1)
953 (void) sigprocmask(SIG_SETMASK
, &oset
, NULL
);
954 terminal_bind_arrow(el
);
955 el
->el_terminal
.t_name
= term
;
956 return i
<= 0 ? -1 : 0;
960 /* terminal_get_size():
961 * Return the new window size in lines and cols, and
962 * true if the size was changed.
965 terminal_get_size(EditLine
*el
, int *lins
, int *cols
)
974 if (ioctl(el
->el_infd
, TIOCGWINSZ
, &ws
) != -1) {
985 if (ioctl(el
->el_infd
, TIOCGSIZE
, &ts
) != -1) {
993 return Val(T_co
) != *cols
|| Val(T_li
) != *lins
;
997 /* terminal_change_size():
998 * Change the size of the terminal
1001 terminal_change_size(EditLine
*el
, int lins
, int cols
)
1006 Val(T_co
) = (cols
< 2) ? 80 : cols
;
1007 Val(T_li
) = (lins
< 1) ? 24 : lins
;
1009 /* re-make display buffers */
1010 if (terminal_rebuffer_display(el
) == -1)
1012 re_clear_display(el
);
1017 /* terminal_init_arrow():
1018 * Initialize the arrow key bindings from termcap
1021 terminal_init_arrow(EditLine
*el
)
1023 funckey_t
*arrow
= el
->el_terminal
.t_fkey
;
1025 arrow
[A_K_DN
].name
= L
"down";
1026 arrow
[A_K_DN
].key
= T_kd
;
1027 arrow
[A_K_DN
].fun
.cmd
= ED_NEXT_HISTORY
;
1028 arrow
[A_K_DN
].type
= XK_CMD
;
1030 arrow
[A_K_UP
].name
= L
"up";
1031 arrow
[A_K_UP
].key
= T_ku
;
1032 arrow
[A_K_UP
].fun
.cmd
= ED_PREV_HISTORY
;
1033 arrow
[A_K_UP
].type
= XK_CMD
;
1035 arrow
[A_K_LT
].name
= L
"left";
1036 arrow
[A_K_LT
].key
= T_kl
;
1037 arrow
[A_K_LT
].fun
.cmd
= ED_PREV_CHAR
;
1038 arrow
[A_K_LT
].type
= XK_CMD
;
1040 arrow
[A_K_RT
].name
= L
"right";
1041 arrow
[A_K_RT
].key
= T_kr
;
1042 arrow
[A_K_RT
].fun
.cmd
= ED_NEXT_CHAR
;
1043 arrow
[A_K_RT
].type
= XK_CMD
;
1045 arrow
[A_K_HO
].name
= L
"home";
1046 arrow
[A_K_HO
].key
= T_kh
;
1047 arrow
[A_K_HO
].fun
.cmd
= ED_MOVE_TO_BEG
;
1048 arrow
[A_K_HO
].type
= XK_CMD
;
1050 arrow
[A_K_EN
].name
= L
"end";
1051 arrow
[A_K_EN
].key
= T_at7
;
1052 arrow
[A_K_EN
].fun
.cmd
= ED_MOVE_TO_END
;
1053 arrow
[A_K_EN
].type
= XK_CMD
;
1055 arrow
[A_K_DE
].name
= L
"delete";
1056 arrow
[A_K_DE
].key
= T_kD
;
1057 arrow
[A_K_DE
].fun
.cmd
= ED_DELETE_NEXT_CHAR
;
1058 arrow
[A_K_DE
].type
= XK_CMD
;
1062 /* terminal_reset_arrow():
1063 * Reset arrow key bindings
1066 terminal_reset_arrow(EditLine
*el
)
1068 funckey_t
*arrow
= el
->el_terminal
.t_fkey
;
1069 static const wchar_t strA
[] = L
"\033[A";
1070 static const wchar_t strB
[] = L
"\033[B";
1071 static const wchar_t strC
[] = L
"\033[C";
1072 static const wchar_t strD
[] = L
"\033[D";
1073 static const wchar_t strH
[] = L
"\033[H";
1074 static const wchar_t strF
[] = L
"\033[F";
1075 static const wchar_t stOA
[] = L
"\033OA";
1076 static const wchar_t stOB
[] = L
"\033OB";
1077 static const wchar_t stOC
[] = L
"\033OC";
1078 static const wchar_t stOD
[] = L
"\033OD";
1079 static const wchar_t stOH
[] = L
"\033OH";
1080 static const wchar_t stOF
[] = L
"\033OF";
1082 keymacro_add(el
, strA
, &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
1083 keymacro_add(el
, strB
, &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
1084 keymacro_add(el
, strC
, &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
1085 keymacro_add(el
, strD
, &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
1086 keymacro_add(el
, strH
, &arrow
[A_K_HO
].fun
, arrow
[A_K_HO
].type
);
1087 keymacro_add(el
, strF
, &arrow
[A_K_EN
].fun
, arrow
[A_K_EN
].type
);
1088 keymacro_add(el
, stOA
, &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
1089 keymacro_add(el
, stOB
, &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
1090 keymacro_add(el
, stOC
, &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
1091 keymacro_add(el
, stOD
, &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
1092 keymacro_add(el
, stOH
, &arrow
[A_K_HO
].fun
, arrow
[A_K_HO
].type
);
1093 keymacro_add(el
, stOF
, &arrow
[A_K_EN
].fun
, arrow
[A_K_EN
].type
);
1095 if (el
->el_map
.type
!= MAP_VI
)
1097 keymacro_add(el
, &strA
[1], &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
1098 keymacro_add(el
, &strB
[1], &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
1099 keymacro_add(el
, &strC
[1], &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
1100 keymacro_add(el
, &strD
[1], &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
1101 keymacro_add(el
, &strH
[1], &arrow
[A_K_HO
].fun
, arrow
[A_K_HO
].type
);
1102 keymacro_add(el
, &strF
[1], &arrow
[A_K_EN
].fun
, arrow
[A_K_EN
].type
);
1103 keymacro_add(el
, &stOA
[1], &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
1104 keymacro_add(el
, &stOB
[1], &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
1105 keymacro_add(el
, &stOC
[1], &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
1106 keymacro_add(el
, &stOD
[1], &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
1107 keymacro_add(el
, &stOH
[1], &arrow
[A_K_HO
].fun
, arrow
[A_K_HO
].type
);
1108 keymacro_add(el
, &stOF
[1], &arrow
[A_K_EN
].fun
, arrow
[A_K_EN
].type
);
1112 /* terminal_set_arrow():
1113 * Set an arrow key binding
1116 terminal_set_arrow(EditLine
*el
, const wchar_t *name
, keymacro_value_t
*fun
,
1119 funckey_t
*arrow
= el
->el_terminal
.t_fkey
;
1122 for (i
= 0; i
< A_K_NKEYS
; i
++)
1123 if (wcscmp(name
, arrow
[i
].name
) == 0) {
1124 arrow
[i
].fun
= *fun
;
1125 arrow
[i
].type
= type
;
1132 /* terminal_clear_arrow():
1133 * Clear an arrow key binding
1136 terminal_clear_arrow(EditLine
*el
, const wchar_t *name
)
1138 funckey_t
*arrow
= el
->el_terminal
.t_fkey
;
1141 for (i
= 0; i
< A_K_NKEYS
; i
++)
1142 if (wcscmp(name
, arrow
[i
].name
) == 0) {
1143 arrow
[i
].type
= XK_NOD
;
1150 /* terminal_print_arrow():
1151 * Print the arrow key bindings
1153 libedit_private
void
1154 terminal_print_arrow(EditLine
*el
, const wchar_t *name
)
1157 funckey_t
*arrow
= el
->el_terminal
.t_fkey
;
1159 for (i
= 0; i
< A_K_NKEYS
; i
++)
1160 if (*name
== '\0' || wcscmp(name
, arrow
[i
].name
) == 0)
1161 if (arrow
[i
].type
!= XK_NOD
)
1162 keymacro_kprint(el
, arrow
[i
].name
,
1163 &arrow
[i
].fun
, arrow
[i
].type
);
1167 /* terminal_bind_arrow():
1168 * Bind the arrow keys
1170 libedit_private
void
1171 terminal_bind_arrow(EditLine
*el
)
1174 const el_action_t
*dmap
;
1177 funckey_t
*arrow
= el
->el_terminal
.t_fkey
;
1179 /* Check if the components needed are initialized */
1180 if (el
->el_terminal
.t_buf
== NULL
|| el
->el_map
.key
== NULL
)
1183 map
= el
->el_map
.type
== MAP_VI
? el
->el_map
.alt
: el
->el_map
.key
;
1184 dmap
= el
->el_map
.type
== MAP_VI
? el
->el_map
.vic
: el
->el_map
.emacs
;
1186 terminal_reset_arrow(el
);
1188 for (i
= 0; i
< A_K_NKEYS
; i
++) {
1189 wchar_t wt_str
[VISUAL_WIDTH_MAX
];
1193 p
= el
->el_terminal
.t_str
[arrow
[i
].key
];
1196 for (n
= 0; n
< VISUAL_WIDTH_MAX
&& p
[n
]; ++n
)
1198 while (n
< VISUAL_WIDTH_MAX
)
1201 j
= (unsigned char) *p
;
1203 * Assign the arrow keys only if:
1205 * 1. They are multi-character arrow keys and the user
1206 * has not re-assigned the leading character, or
1207 * has re-assigned the leading character to be
1208 * ED_SEQUENCE_LEAD_IN
1209 * 2. They are single arrow keys pointing to an
1212 if (arrow
[i
].type
== XK_NOD
)
1213 keymacro_clear(el
, map
, px
);
1215 if (p
[1] && (dmap
[j
] == map
[j
] ||
1216 map
[j
] == ED_SEQUENCE_LEAD_IN
)) {
1217 keymacro_add(el
, px
, &arrow
[i
].fun
,
1219 map
[j
] = ED_SEQUENCE_LEAD_IN
;
1220 } else if (map
[j
] == ED_UNASSIGNED
) {
1221 keymacro_clear(el
, map
, px
);
1222 if (arrow
[i
].type
== XK_CMD
)
1223 map
[j
] = arrow
[i
].fun
.cmd
;
1225 keymacro_add(el
, px
, &arrow
[i
].fun
,
1236 terminal_putc(int c
)
1238 if (terminal_outfile
== NULL
)
1240 return fputc(c
, terminal_outfile
);
1244 terminal_tputs(EditLine
*el
, const char *cap
, int affcnt
)
1247 pthread_mutex_lock(&terminal_mutex
);
1249 terminal_outfile
= el
->el_outfile
;
1250 (void)tputs(cap
, affcnt
, terminal_putc
);
1252 pthread_mutex_unlock(&terminal_mutex
);
1256 /* terminal__putc():
1260 terminal__putc(EditLine
*el
, wint_t c
)
1262 char buf
[MB_LEN_MAX
+1];
1264 if (c
== (wint_t)MB_FILL_CHAR
)
1266 i
= ct_encode_char(buf
, (size_t)MB_LEN_MAX
, c
);
1270 return fputs(buf
, el
->el_outfile
);
1273 /* terminal__flush():
1276 libedit_private
void
1277 terminal__flush(EditLine
*el
)
1280 (void) fflush(el
->el_outfile
);
1283 /* terminal_writec():
1284 * Write the given character out, in a human readable form
1286 libedit_private
void
1287 terminal_writec(EditLine
*el
, wint_t c
)
1289 wchar_t visbuf
[VISUAL_WIDTH_MAX
+1];
1290 ssize_t vcnt
= ct_visual_char(visbuf
, VISUAL_WIDTH_MAX
, c
);
1293 visbuf
[vcnt
] = '\0';
1294 terminal_overwrite(el
, visbuf
, (size_t)vcnt
);
1295 terminal__flush(el
);
1299 /* terminal_telltc():
1300 * Print the current termcap characteristics
1304 terminal_telltc(EditLine
*el
, int argc
__attribute__((__unused__
)),
1305 const wchar_t **argv
__attribute__((__unused__
)))
1307 const struct termcapstr
*t
;
1310 (void) fprintf(el
->el_outfile
, "\n\tYour terminal has the\n");
1311 (void) fprintf(el
->el_outfile
, "\tfollowing characteristics:\n\n");
1312 (void) fprintf(el
->el_outfile
, "\tIt has %d columns and %d lines\n",
1313 Val(T_co
), Val(T_li
));
1314 (void) fprintf(el
->el_outfile
,
1315 "\tIt has %s meta key\n", EL_HAS_META
? "a" : "no");
1316 (void) fprintf(el
->el_outfile
,
1317 "\tIt can%suse tabs\n", EL_CAN_TAB
? " " : "not ");
1318 (void) fprintf(el
->el_outfile
, "\tIt %s automatic margins\n",
1319 EL_HAS_AUTO_MARGINS
? "has" : "does not have");
1320 if (EL_HAS_AUTO_MARGINS
)
1321 (void) fprintf(el
->el_outfile
, "\tIt %s magic margins\n",
1322 EL_HAS_MAGIC_MARGINS
? "has" : "does not have");
1324 for (t
= tstr
, ts
= el
->el_terminal
.t_str
; t
->name
!= NULL
; t
++, ts
++) {
1327 ub
= ct_encode_string(ct_visual_string(
1328 ct_decode_string(*ts
, &el
->el_scratch
),
1329 &el
->el_visual
), &el
->el_scratch
);
1333 (void) fprintf(el
->el_outfile
, "\t%25s (%s) == %s\n",
1334 t
->long_name
, t
->name
, ub
);
1336 (void) fputc('\n', el
->el_outfile
);
1341 /* terminal_settc():
1342 * Change the current terminal characteristics
1346 terminal_settc(EditLine
*el
, int argc
__attribute__((__unused__
)),
1347 const wchar_t **argv
)
1349 const struct termcapstr
*ts
;
1350 const struct termcapval
*tv
;
1351 char what
[8], how
[8];
1353 if (argv
== NULL
|| argv
[1] == NULL
|| argv
[2] == NULL
)
1356 strncpy(what
, ct_encode_string(argv
[1], &el
->el_scratch
), sizeof(what
));
1357 what
[sizeof(what
) - 1] = '\0';
1358 strncpy(how
, ct_encode_string(argv
[2], &el
->el_scratch
), sizeof(how
));
1359 how
[sizeof(how
) - 1] = '\0';
1362 * Do the strings first
1364 for (ts
= tstr
; ts
->name
!= NULL
; ts
++)
1365 if (strcmp(ts
->name
, what
) == 0)
1368 if (ts
->name
!= NULL
) {
1369 terminal_alloc(el
, ts
, how
);
1370 terminal_setflags(el
);
1374 * Do the numeric ones second
1376 for (tv
= tval
; tv
->name
!= NULL
; tv
++)
1377 if (strcmp(tv
->name
, what
) == 0)
1380 if (tv
->name
!= NULL
)
1383 if (tv
== &tval
[T_pt
] || tv
== &tval
[T_km
] ||
1384 tv
== &tval
[T_am
] || tv
== &tval
[T_xn
]) {
1385 if (strcmp(how
, "yes") == 0)
1386 el
->el_terminal
.t_val
[tv
- tval
] = 1;
1387 else if (strcmp(how
, "no") == 0)
1388 el
->el_terminal
.t_val
[tv
- tval
] = 0;
1390 (void) fprintf(el
->el_errfile
,
1391 "%ls: Bad value `%s'.\n", argv
[0], how
);
1394 terminal_setflags(el
);
1395 if (terminal_change_size(el
, Val(T_li
), Val(T_co
)) == -1)
1402 i
= strtol(how
, &ep
, 10);
1404 (void) fprintf(el
->el_errfile
,
1405 "%ls: Bad value `%s'.\n", argv
[0], how
);
1408 el
->el_terminal
.t_val
[tv
- tval
] = (int) i
;
1409 el
->el_terminal
.t_size
.v
= Val(T_co
);
1410 el
->el_terminal
.t_size
.h
= Val(T_li
);
1411 if (tv
== &tval
[T_co
] || tv
== &tval
[T_li
])
1412 if (terminal_change_size(el
, Val(T_li
), Val(T_co
))
1420 /* terminal_gettc():
1421 * Get the current terminal characteristics
1425 terminal_gettc(EditLine
*el
, int argc
__attribute__((__unused__
)), char **argv
)
1427 const struct termcapstr
*ts
;
1428 const struct termcapval
*tv
;
1432 if (argv
== NULL
|| argv
[1] == NULL
|| argv
[2] == NULL
)
1439 * Do the strings first
1441 for (ts
= tstr
; ts
->name
!= NULL
; ts
++)
1442 if (strcmp(ts
->name
, what
) == 0)
1445 if (ts
->name
!= NULL
) {
1446 *(char **)how
= el
->el_terminal
.t_str
[ts
- tstr
];
1450 * Do the numeric ones second
1452 for (tv
= tval
; tv
->name
!= NULL
; tv
++)
1453 if (strcmp(tv
->name
, what
) == 0)
1456 if (tv
->name
== NULL
)
1459 if (tv
== &tval
[T_pt
] || tv
== &tval
[T_km
] ||
1460 tv
== &tval
[T_am
] || tv
== &tval
[T_xn
]) {
1461 static char yes
[] = "yes";
1462 static char no
[] = "no";
1463 if (el
->el_terminal
.t_val
[tv
- tval
])
1464 *(char **)how
= yes
;
1469 *(int *)how
= el
->el_terminal
.t_val
[tv
- tval
];
1474 /* terminal_echotc():
1475 * Print the termcap string out with variable substitution
1479 terminal_echotc(EditLine
*el
, int argc
__attribute__((__unused__
)),
1480 const wchar_t **argv
)
1484 int arg_need
, arg_cols
, arg_rows
;
1485 int verbose
= 0, silent
= 0;
1487 static const char fmts
[] = "%s\n", fmtd
[] = "%d\n";
1488 const struct termcapstr
*t
;
1489 char buf
[TC_BUFSIZE
];
1494 if (argv
== NULL
|| argv
[1] == NULL
)
1498 if (argv
[0][0] == '-') {
1499 switch (argv
[0][1]) {
1507 /* stderror(ERR_NAME | ERR_TCUSAGE); */
1512 if (!*argv
|| *argv
[0] == '\0')
1514 if (wcscmp(*argv
, L
"tabs") == 0) {
1515 (void) fprintf(el
->el_outfile
, fmts
, EL_CAN_TAB
? "yes" : "no");
1517 } else if (wcscmp(*argv
, L
"meta") == 0) {
1518 (void) fprintf(el
->el_outfile
, fmts
, Val(T_km
) ? "yes" : "no");
1520 } else if (wcscmp(*argv
, L
"xn") == 0) {
1521 (void) fprintf(el
->el_outfile
, fmts
, EL_HAS_MAGIC_MARGINS
?
1524 } else if (wcscmp(*argv
, L
"am") == 0) {
1525 (void) fprintf(el
->el_outfile
, fmts
, EL_HAS_AUTO_MARGINS
?
1528 } else if (wcscmp(*argv
, L
"baud") == 0) {
1529 (void) fprintf(el
->el_outfile
, fmtd
, (int)el
->el_tty
.t_speed
);
1531 } else if (wcscmp(*argv
, L
"rows") == 0 ||
1532 wcscmp(*argv
, L
"lines") == 0) {
1533 (void) fprintf(el
->el_outfile
, fmtd
, Val(T_li
));
1535 } else if (wcscmp(*argv
, L
"cols") == 0) {
1536 (void) fprintf(el
->el_outfile
, fmtd
, Val(T_co
));
1540 * Try to use our local definition first
1543 for (t
= tstr
; t
->name
!= NULL
; t
++)
1545 ct_encode_string(*argv
, &el
->el_scratch
)) == 0) {
1546 scap
= el
->el_terminal
.t_str
[t
- tstr
];
1549 if (t
->name
== NULL
) {
1550 /* XXX: some systems' tgetstr needs non const */
1551 scap
= tgetstr(ct_encode_string(*argv
, &el
->el_scratch
), &area
);
1553 if (!scap
|| scap
[0] == '\0') {
1555 (void) fprintf(el
->el_errfile
,
1556 "echotc: Termcap parameter `%ls' not found.\n",
1561 * Count home many values we need for this capability.
1563 for (cap
= scap
, arg_need
= 0; *cap
; cap
++)
1583 * hpux has lot's of them...
1586 (void) fprintf(el
->el_errfile
,
1587 "echotc: Warning: unknown termcap %% `%c'.\n",
1589 /* This is bad, but I won't complain */
1596 if (*argv
&& *argv
[0]) {
1598 (void) fprintf(el
->el_errfile
,
1599 "echotc: Warning: Extra argument `%ls'.\n",
1603 terminal_tputs(el
, scap
, 1);
1607 if (!*argv
|| *argv
[0] == '\0') {
1609 (void) fprintf(el
->el_errfile
,
1610 "echotc: Warning: Missing argument.\n");
1614 i
= wcstol(*argv
, &ep
, 10);
1615 if (*ep
!= '\0' || i
< 0) {
1617 (void) fprintf(el
->el_errfile
,
1618 "echotc: Bad value `%ls' for rows.\n",
1624 if (*argv
&& *argv
[0]) {
1626 (void) fprintf(el
->el_errfile
,
1627 "echotc: Warning: Extra argument `%ls"
1631 terminal_tputs(el
, tgoto(scap
, arg_cols
, arg_rows
), 1);
1634 /* This is wrong, but I will ignore it... */
1636 (void) fprintf(el
->el_errfile
,
1637 "echotc: Warning: Too many required arguments (%d).\n",
1642 if (!*argv
|| *argv
[0] == '\0') {
1644 (void) fprintf(el
->el_errfile
,
1645 "echotc: Warning: Missing argument.\n");
1648 i
= wcstol(*argv
, &ep
, 10);
1649 if (*ep
!= '\0' || i
< 0) {
1651 (void) fprintf(el
->el_errfile
,
1652 "echotc: Bad value `%ls' for cols.\n",
1658 if (!*argv
|| *argv
[0] == '\0') {
1660 (void) fprintf(el
->el_errfile
,
1661 "echotc: Warning: Missing argument.\n");
1664 i
= wcstol(*argv
, &ep
, 10);
1665 if (*ep
!= '\0' || i
< 0) {
1667 (void) fprintf(el
->el_errfile
,
1668 "echotc: Bad value `%ls' for rows.\n",
1675 (void) fprintf(el
->el_errfile
,
1676 "echotc: Bad value `%ls'.\n", *argv
);
1680 if (*argv
&& *argv
[0]) {
1682 (void) fprintf(el
->el_errfile
,
1683 "echotc: Warning: Extra argument `%ls"
1687 terminal_tputs(el
, tgoto(scap
, arg_cols
, arg_rows
), arg_rows
);