* Copyright (c) 1992 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University.
* %sccs.include.redist.c%
#if !defined(lint) && !defined(SCCSID)
static char sccsid
[] = "@(#)term.c 5.2 (Berkeley) %G%";
#endif /* not lint && not SCCSID */
* term.c: Editor/termcap-curses interface
* We have to declare a static variable here, since the
* termcap putchar routine does not take an argument!
#include "termcap.h" /* XXX: should be <termcap.h> */
* IMPORTANT NOTE: these routines are allowed to look at the current screen
* and the current possition assuming that it is correct. If this is not
* true, then the update will be WRONG! This is (should be) a valid
#define GoodStr(a) (el->el_term.t_str[a] != NULL && \
el->el_term.t_str[a][0] != '\0')
#define Str(a) el->el_term.t_str[a]
#define Val(a) el->el_term.t_val[a]
private struct termcapstr
{
{ "al", "add new blank line" },
{ "bl", "audible bell" },
{ "cd", "clear to bottom" },
{ "ce", "clear to end of line" },
{ "ch", "cursor to horiz pos" },
{ "cl", "clear screen" },
{ "dc", "delete a character" },
{ "dl", "delete a line" },
{ "dm", "start delete mode" },
{ "ed", "end delete mode" },
{ "ei", "end insert mode" },
{ "fs", "cursor from status line" },
{ "ic", "insert character" },
{ "im", "start insert mode" },
{ "ip", "insert padding" },
{ "kd", "sends cursor down" },
{ "kl", "sends cursor left" },
{ "kr", "sends cursor right" },
{ "ku", "sends cursor up" },
{ "me", "end attributes" },
{ "nd", "non destructive space" },
{ "se", "end standout" },
{ "so", "begin standout" },
{ "ts", "cursor to status line" },
{ "up", "cursor up one" },
{ "us", "begin underline" },
{ "ue", "end underline" },
{ "vb", "visible bell" },
{ "DC", "delete multiple chars" },
{ "DO", "cursor down multiple" },
{ "IC", "insert multiple chars" },
{ "LE", "cursor left multiple" },
{ "RI", "cursor right multiple" },
{ "UP", "cursor up multiple" },
private struct termcapval
{
{ "pt", "has physical tabs" },
{ "li", "Number of lines" },
{ "co", "Number of columns" },
{ "km", "Has meta key" },
{ "xt", "Tab chars destructive" },
{ "MT", "Has meta key" }, /* XXX? */
/* do two or more of the attributes use me */
private void term_rebuffer_display
__P((EditLine
*));
private void term_free_display
__P((EditLine
*));
private void term_alloc_display
__P((EditLine
*));
private void term_alloc
__P((EditLine
*,
struct termcapstr
*, char *));
private void term_init_arrow
__P((EditLine
*));
private void term_reset_arrow
__P((EditLine
*));
private FILE *term_outfile
= NULL
; /* XXX: How do we fix that? */
* Set the terminal capability flags
EL_FLAGS
|= (Val(T_pt
) && !Val(T_xt
)) ? TERM_CAN_TAB
: 0;
EL_FLAGS
|= (Val(T_km
) || Val(T_MT
)) ? TERM_HAS_META
: 0;
EL_FLAGS
|= GoodStr(T_ce
) ? TERM_CAN_CEOL
: 0;
EL_FLAGS
|= (GoodStr(T_dc
) || GoodStr(T_DC
)) ? TERM_CAN_DELETE
: 0;
EL_FLAGS
|= (GoodStr(T_im
) || GoodStr(T_ic
) || GoodStr(T_IC
)) ?
EL_FLAGS
|= (GoodStr(T_up
) || GoodStr(T_UP
)) ? TERM_CAN_UP
: 0;
if (GoodStr(T_me
) && GoodStr(T_ue
))
EL_FLAGS
|= (strcmp(Str(T_me
), Str(T_ue
)) == 0) ? TERM_CAN_ME
: 0;
EL_FLAGS
&= ~TERM_CAN_ME
;
if (GoodStr(T_me
) && GoodStr(T_se
))
EL_FLAGS
|= (strcmp(Str(T_me
), Str(T_se
)) == 0) ? TERM_CAN_ME
: 0;
(void) fprintf(el
->el_errfile
, "WARNING: Your terminal cannot move up.\n");
(void) fprintf(el
->el_errfile
, "Editing may be odd for long lines.\n");
(void) fprintf(el
->el_errfile
, "no clear EOL capability.\n");
(void) fprintf(el
->el_errfile
, "no delete char capability.\n");
(void) fprintf(el
->el_errfile
, "no insert char capability.\n");
#endif /* DEBUG_SCREEN */
* Initialize the terminal stuff
el
->el_term
.t_buf
= (char *) el_malloc(TC_BUFSIZE
);
el
->el_term
.t_cap
= (char *) el_malloc(TC_BUFSIZE
);
el
->el_term
.t_fkey
= (fkey_t
*) el_malloc(4 * sizeof(fkey_t
));
el
->el_term
.t_str
= (char **) el_malloc(T_str
* sizeof(char*));
(void) memset(el
->el_term
.t_str
, 0, T_str
* sizeof(char*));
el
->el_term
.t_val
= (int *) el_malloc(T_val
* sizeof(int));
(void) memset(el
->el_term
.t_val
, 0, T_val
* sizeof(char*));
term_outfile
= el
->el_outfile
;
(void) term_set(el
, NULL
);
* Clean up the terminal stuff
el_free((ptr_t
) el
->el_term
.t_buf
);
el
->el_term
.t_buf
= NULL
;
el_free((ptr_t
) el
->el_term
.t_cap
);
el
->el_term
.t_cap
= NULL
;
el_free((ptr_t
) el
->el_term
.t_str
);
el
->el_term
.t_str
= NULL
;
el_free((ptr_t
) el
->el_term
.t_val
);
el
->el_term
.t_val
= NULL
;
* Maintain a string pool for termcap strings
char termbuf
[TC_BUFSIZE
];
char **tlist
= el
->el_term
.t_str
;
char **tmp
, **str
= &tlist
[t
- tstr
];
if (cap
== NULL
|| *cap
== '\0') {
tlen
= *str
== NULL
? 0 : strlen(*str
);
* New string is shorter; no need to allocate space
(void) strcpy(*str
, cap
);
* New string is longer; see if we have enough space to append
if (el
->el_term
.t_loc
+ 3 < TC_BUFSIZE
) {
(void) strcpy(*str
= &el
->el_term
.t_buf
[el
->el_term
.t_loc
], cap
);
el
->el_term
.t_loc
+= clen
+ 1; /* one for \0 */
* Compact our buffer; no need to check compaction, cause we know it
for (tmp
= tlist
; tmp
< &tlist
[T_str
]; tmp
++)
if (*tmp
!= NULL
&& *tmp
!= '\0' && *tmp
!= *str
) {
for (ptr
= *tmp
; *ptr
!= '\0'; termbuf
[tlen
++] = *ptr
++)
memcpy(el
->el_term
.t_buf
, termbuf
, TC_BUFSIZE
);
el
->el_term
.t_loc
= tlen
;
if (el
->el_term
.t_loc
+ 3 >= TC_BUFSIZE
) {
(void) fprintf(el
->el_errfile
, "Out of termcap string space.\n");
(void) strcpy(*str
= &el
->el_term
.t_buf
[el
->el_term
.t_loc
], cap
);
el
->el_term
.t_loc
+= clen
+ 1; /* one for \0 */
/* term_rebuffer_display():
* Rebuffer the display after the screen changed size
term_rebuffer_display(el
)
coord_t
*c
= &el
->el_term
.t_size
;
/* make this public, -1 to avoid wraps */
c
->v
= (EL_BUFSIZ
* 4) / c
->h
+ 1;
} /* end term_rebuffer_display */
* Allocate a new display.
coord_t
*c
= &el
->el_term
.t_size
;
b
= (char **) el_malloc((size_t) (sizeof(char *) * (c
->v
+ 1)));
for (i
= 0; i
< c
->v
; i
++)
b
[i
] = (char *) el_malloc((size_t) (sizeof(char) * (c
->h
+ 1)));
b
= (char **) el_malloc((size_t) (sizeof(char *) * (c
->v
+ 1)));
for (i
= 0; i
< c
->v
; i
++)
b
[i
] = (char *) el_malloc((size_t) (sizeof(char) * (c
->h
+ 1)));
} /* end term_alloc_display */
* Free the display buffers
for (bufp
= b
; *bufp
!= NULL
; bufp
++)
for (bufp
= b
; *bufp
!= NULL
; bufp
++)
} /* end term_free_display */
* move to line <where> (first line == 0)
* as efficiently as possible
term_move_to_line(el
, where
)
if (where
== el
->el_cursor
.v
)
if (where
> el
->el_term
.t_size
.v
) {
(void) fprintf(el
->el_errfile
,
"term_move_to_line: where is ridiculous: %d\r\n", where
);
#endif /* DEBUG_SCREEN */
if ((del
= where
- el
->el_cursor
.v
) > 0) {
if ((del
> 1) && GoodStr(T_DO
))
(void) tputs(tgoto(Str(T_DO
), del
, del
), del
, term__putc
);
for (i
= 0; i
< del
; i
++)
el
->el_cursor
.h
= 0; /* because the \n will become \r\n */
if (GoodStr(T_UP
) && (-del
> 1 || !GoodStr(T_up
)))
(void) tputs(tgoto(Str(T_UP
), -del
, -del
), -del
, term__putc
);
for (i
= 0; i
< -del
; i
++)
(void) tputs(Str(T_up
), 1, term__putc
);
el
->el_cursor
.v
= where
; /* now where is here */
} /* end term_move_to_line */
* Move to the character position specified
term_move_to_char(el
, where
)
if (where
== el
->el_cursor
.h
)
if (where
> (el
->el_term
.t_size
.h
+ 1)) {
(void) fprintf(el
->el_errfile
,
"term_move_to_char: where is riduculous: %d\r\n", where
);
#endif /* DEBUG_SCREEN */
if (!where
) { /* if where is first column */
term__putc('\r'); /* do a CR */
del
= where
- el
->el_cursor
.h
;
if ((del
< -4 || del
> 4) && GoodStr(T_ch
))
(void) tputs(tgoto(Str(T_ch
), where
, where
), where
, term__putc
);
if (del
> 0) { /* moving forward */
if ((del
> 4) && GoodStr(T_RI
))
(void) tputs(tgoto(Str(T_RI
), del
, del
), del
, term__putc
);
if (EL_CAN_TAB
) { /* if I can do tabs, use them */
if ((el
->el_cursor
.h
& 0370) != (where
& 0370)) {
/* if not within tab stop */
for (i
= (el
->el_cursor
.h
& 0370);
i
< (where
& 0370); i
+= 8)
term__putc('\t'); /* then tab over */
el
->el_cursor
.h
= where
& 0370;
/* it's usually cheaper to just write the chars, so we do. */
/* NOTE THAT term_overwrite() WILL CHANGE el->el_cursor.h!!! */
&el
->el_display
[el
->el_cursor
.v
][el
->el_cursor
.h
],
where
- el
->el_cursor
.h
);
else { /* del < 0 := moving backward */
if ((-del
> 4) && GoodStr(T_LE
))
(void) tputs(tgoto(Str(T_LE
), -del
, -del
), -del
, term__putc
);
else { /* can't go directly there */
/* if the "cost" is greater than the "cost" from col 0 */
if (EL_CAN_TAB
? (-del
> ((where
>> 3) + (where
& 07)))
term__putc('\r'); /* do a CR */
goto mc_again
; /* and try again */
for (i
= 0; i
< -del
; i
++)
el
->el_cursor
.h
= where
; /* now where is here */
} /* end term_move_to_char */
* Overstrike num characters
term_overwrite(el
, cp
, n
)
if (n
> (el
->el_term
.t_size
.h
+ 1)) {
(void) fprintf(el
->el_errfile
, "term_overwrite: n is riduculous: %d\r\n", n
);
#endif /* DEBUG_SCREEN */
} /* end term_overwrite */
term_deletechars(el
, num
)
(void) fprintf(el
->el_errfile
, " ERROR: cannot delete \n");
if (num
> el
->el_term
.t_size
.h
) {
(void) fprintf(el
->el_errfile
,
"term_deletechars: num is riduculous: %d\r\n", num
);
#endif /* DEBUG_SCREEN */
if (GoodStr(T_DC
)) /* if I have multiple delete */
if ((num
> 1) || !GoodStr(T_dc
)) { /* if dc would be more expen. */
(void) tputs(tgoto(Str(T_DC
), num
, num
), num
, term__putc
);
if (GoodStr(T_dm
)) /* if I have delete mode */
(void) tputs(Str(T_dm
), 1, term__putc
);
if (GoodStr(T_dc
)) /* else do one at a time */
(void) tputs(Str(T_dc
), 1, term__putc
);
if (GoodStr(T_ed
)) /* if I have delete mode */
(void) tputs(Str(T_ed
), 1, term__putc
);
} /* end term_deletechars */
* Puts terminal in insert character mode or inserts num
term_insertwrite(el
, cp
, num
)
(void) fprintf(el
->el_errfile
, " ERROR: cannot insert \n");
if (num
> el
->el_term
.t_size
.h
) {
(void) fprintf(el
->el_errfile
, "StartInsert: num is riduculous: %d\r\n", num
);
#endif /* DEBUG_SCREEN */
if (GoodStr(T_IC
)) /* if I have multiple insert */
if ((num
> 1) || !GoodStr(T_ic
)) { /* if ic would be more expen. */
(void) tputs(tgoto(Str(T_IC
), num
, num
), num
, term__putc
);
term_overwrite(el
, cp
, num
); /* this updates el_cursor.h */
if (GoodStr(T_im
) && GoodStr(T_ei
)) { /* if I have insert mode */
(void) tputs(Str(T_im
), 1, term__putc
);
if (GoodStr(T_ip
)) /* have to make num chars insert */
(void) tputs(Str(T_ip
), 1, term__putc
);
(void) tputs(Str(T_ei
), 1, term__putc
);
if (GoodStr(T_ic
)) /* have to make num chars insert */
(void) tputs(Str(T_ic
), 1, term__putc
); /* insert a char */
if (GoodStr(T_ip
)) /* have to make num chars insert */
(void) tputs(Str(T_ip
), 1, term__putc
);/* pad the inserted char */
} /* end term_insertwrite */
* clear to end of line. There are num characters to clear
if (EL_CAN_CEOL
&& GoodStr(T_ce
))
(void) tputs(Str(T_ce
), 1, term__putc
);
for (i
= 0; i
< num
; i
++)
el
->el_cursor
.h
+= num
; /* have written num spaces */
} /* end term_clear_EOL */
{ /* clear the whole screen and home */
/* send the clear screen code */
(void) tputs(Str(T_cl
), Val(T_li
), term__putc
);
else if (GoodStr(T_ho
) && GoodStr(T_cd
)) {
(void) tputs(Str(T_ho
), Val(T_li
), term__putc
); /* home */
/* clear to bottom of screen */
(void) tputs(Str(T_cd
), Val(T_li
), term__putc
);
} /* end term_clear_screen */
* Beep the way the terminal wants us
(void) tputs(Str(T_vb
), 1, term__putc
); /* visible bell */
/* what termcap says we should use */
(void) tputs(Str(T_bl
), 1, term__putc
);
term__putc('\007'); /* an ASCII bell; ^G */
/* term_clear_to_bottom():
* Clear to the bottom of the screen
(void) tputs(Str(T_cd
), Val(T_li
), term__putc
);
(void) tputs(Str(T_ce
), Val(T_li
), term__putc
);
} /* end term_clear_to_bottom */
* Read in the terminal capabilities from the requested terminal
(void) sigemptyset(&nset
);
(void) sigaddset(&nset
, SIGWINCH
);
(void) sigprocmask(SIG_BLOCK
, &nset
, &oset
);
memset(el
->el_term
.t_cap
, 0, TC_BUFSIZE
);
i
= tgetent(el
->el_term
.t_cap
, term
);
(void) fprintf(el
->el_errfile
, "Cannot open /etc/termcap.\n");
(void) fprintf(el
->el_errfile
,
"No entry for terminal type \"%s\"\n", term
);
(void) fprintf(el
->el_errfile
, "using dumb terminal settings.\n");
Val(T_co
) = 80; /* do a dumb terminal */
Val(T_pt
) = Val(T_km
) = Val(T_li
) = 0;
for (t
= tstr
; t
->name
!= NULL
; t
++)
Val(T_pt
) = tgetflag("pt");
Val(T_xt
) = tgetflag("xt");
Val(T_km
) = tgetflag("km");
Val(T_MT
) = tgetflag("MT");
Val(T_co
) = tgetnum("co");
Val(T_li
) = tgetnum("li");
for (t
= tstr
; t
->name
!= NULL
; t
++)
term_alloc(el
, t
, tgetstr(t
->name
, &area
));
Val(T_co
) = 80; /* just in case */
el
->el_term
.t_size
.v
= Val(T_co
);
el
->el_term
.t_size
.h
= Val(T_li
);
(void) term_get_size(el
, &lins
, &cols
);/* get the correct window size */
term_change_size(el
, lins
, cols
);
(void) sigprocmask(SIG_SETMASK
, &oset
, NULL
);
* Return the new window size in lines and cols, and
* true if the size was changed.
term_get_size(el
, lins
, cols
)
if (ioctl(el
->el_infd
, TIOCGWINSZ
, (ioctl_t
) &ws
) != -1) {
if (ioctl(el
->el_infd
, TIOCGSIZE
, (ioctl_t
) &ts
) != -1) {
return (Val(T_co
) != *cols
|| Val(T_li
) != *lins
);
} /* end term_get_size */
* Change the size of the terminal
term_change_size(el
, lins
, cols
)
Val(T_co
) = (cols
< 2) ? 80 : cols
;
Val(T_li
) = (lins
< 1) ? 24 : lins
;
term_rebuffer_display(el
); /* re-make display buffers */
} /* end term_change_size */
* Initialize the arrow key bindings from termcap
fkey_t
*arrow
= el
->el_term
.t_fkey
;
arrow
[A_K_DN
].name
= "down";
arrow
[A_K_DN
].fun
.cmd
= ED_NEXT_HISTORY
;
arrow
[A_K_DN
].type
= XK_CMD
;
arrow
[A_K_UP
].name
= "up";
arrow
[A_K_UP
].fun
.cmd
= ED_PREV_HISTORY
;
arrow
[A_K_UP
].type
= XK_CMD
;
arrow
[A_K_LT
].name
= "left";
arrow
[A_K_LT
].fun
.cmd
= ED_PREV_CHAR
;
arrow
[A_K_LT
].type
= XK_CMD
;
arrow
[A_K_RT
].name
= "right";
arrow
[A_K_RT
].fun
.cmd
= ED_NEXT_CHAR
;
arrow
[A_K_RT
].type
= XK_CMD
;
* Reset arrow key bindings
fkey_t
*arrow
= el
->el_term
.t_fkey
;
static char strA
[] = {033, '[', 'A', '\0'};
static char strB
[] = {033, '[', 'B', '\0'};
static char strC
[] = {033, '[', 'C', '\0'};
static char strD
[] = {033, '[', 'D', '\0'};
static char stOA
[] = {033, 'O', 'A', '\0'};
static char stOB
[] = {033, 'O', 'B', '\0'};
static char stOC
[] = {033, 'O', 'C', '\0'};
static char stOD
[] = {033, 'O', 'D', '\0'};
key_add(el
, strA
, &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
key_add(el
, strB
, &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
key_add(el
, strC
, &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
key_add(el
, strD
, &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
key_add(el
, stOA
, &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
key_add(el
, stOB
, &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
key_add(el
, stOC
, &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
key_add(el
, stOD
, &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
if (el
->el_map
.type
== MAP_VI
) {
key_add(el
, &strA
[1], &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
key_add(el
, &strB
[1], &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
key_add(el
, &strC
[1], &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
key_add(el
, &strD
[1], &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
key_add(el
, &stOA
[1], &arrow
[A_K_UP
].fun
, arrow
[A_K_UP
].type
);
key_add(el
, &stOB
[1], &arrow
[A_K_DN
].fun
, arrow
[A_K_DN
].type
);
key_add(el
, &stOC
[1], &arrow
[A_K_RT
].fun
, arrow
[A_K_RT
].type
);
key_add(el
, &stOD
[1], &arrow
[A_K_LT
].fun
, arrow
[A_K_LT
].type
);
* Set an arrow key binding
term_set_arrow(el
, name
, fun
, type
)
fkey_t
*arrow
= el
->el_term
.t_fkey
;
for (i
= 0; i
< A_K_NKEYS
; i
++)
if (strcmp(name
, arrow
[i
].name
) == 0) {
* Clear an arrow key binding
term_clear_arrow(el
, name
)
fkey_t
*arrow
= el
->el_term
.t_fkey
;
for (i
= 0; i
< A_K_NKEYS
; i
++)
if (strcmp(name
, arrow
[i
].name
) == 0) {
* Print the arrow key bindings
term_print_arrow(el
, name
)
fkey_t
*arrow
= el
->el_term
.t_fkey
;
for (i
= 0; i
< A_K_NKEYS
; i
++)
if (*name
== '\0' || strcmp(name
, arrow
[i
].name
) == 0)
if (arrow
[i
].type
!= XK_NOD
)
key_kprint(el
, arrow
[i
].name
, &arrow
[i
].fun
, arrow
[i
].type
);
fkey_t
*arrow
= el
->el_term
.t_fkey
;
/* Check if the components needed are initialized */
if (el
->el_term
.t_buf
== NULL
|| el
->el_map
.key
== NULL
)
map
= el
->el_map
.type
== MAP_VI
? el
->el_map
.alt
: el
->el_map
.key
;
dmap
= el
->el_map
.type
== MAP_VI
? el
->el_map
.vic
: el
->el_map
.emacs
;
for (i
= 0; i
< 4; i
++) {
p
= el
->el_term
.t_str
[arrow
[i
].key
];
* Assign the arrow keys only if:
* 1. They are multi-character arrow keys and the user
* has not re-assigned the leading character, or
* has re-assigned the leading character to be
* 2. They are single arrow keys pointing to an unassigned key.
if (arrow
[i
].type
== XK_NOD
)
if (p
[1] && (dmap
[j
] == map
[j
] ||
map
[j
] == ED_SEQUENCE_LEAD_IN
)) {
key_add(el
, p
, &arrow
[i
].fun
, arrow
[i
].type
);
map
[j
] = ED_SEQUENCE_LEAD_IN
;
else if (map
[j
] == ED_UNASSIGNED
) {
if (arrow
[i
].type
== XK_CMD
)
map
[j
] = arrow
[i
].fun
.cmd
;
key_add(el
, p
, &arrow
[i
].fun
, arrow
[i
].type
);
(void) fputc(c
, term_outfile
);
(void) fflush(term_outfile
);
* Print the current termcap characteristics
term_telltc(el
, argc
, argv
)
(void) fprintf(el
->el_outfile
, "\n\tYour terminal has the\n");
(void) fprintf(el
->el_outfile
, "\tfollowing characteristics:\n\n");
(void) fprintf(el
->el_outfile
, "\tIt has %d columns and %d lines\n",
(void) fprintf(el
->el_outfile
,
"\tIt has %s meta key\n", EL_HAS_META
? "a" : "no");
(void) fprintf(el
->el_outfile
,
"\tIt can%suse tabs\n", EL_CAN_TAB
? " " : "not ");
(void) fprintf(el
->el_outfile
, "\tIt %s automatic margins\n",
(T_Margin
&MARGIN_AUTO
)? "has": "does not have");
if (T_Margin
& MARGIN_AUTO
)
(void) fprintf(el
->el_outfile
, "\tIt %s magic margins\n",
(T_Margin
&MARGIN_MAGIC
)?"has":"does not have");
for (t
= tstr
, ts
= el
->el_term
.t_str
; t
->name
!= NULL
; t
++, ts
++)
(void) fprintf(el
->el_outfile
, "\t%25s (%s) == %s\n", t
->long_name
,
key__decode_str(*ts
, upbuf
, "") : "(empty)");
(void) fputc('\n', el
->el_outfile
);
* Change the current terminal characteristics
term_settc(el
, argc
, argv
)
if (argv
== NULL
|| argv
[1] == NULL
|| argv
[2] == NULL
)
for (ts
= tstr
; ts
->name
!= NULL
; ts
++)
if (strcmp(ts
->name
, what
) == 0)
* Do the numeric ones second
for (tv
= tval
; tv
->name
!= NULL
; tv
++)
if (strcmp(tv
->name
, what
) == 0)
if (tv
== &tval
[T_pt
] || tv
== &tval
[T_km
]
|| tv
== &tval
[T_am
] || tv
== &tval
[T_xn
]
if (strcmp(how
, "yes") == 0)
el
->el_term
.t_val
[tv
- tval
] = 1;
else if (strcmp(how
, "no") == 0)
el
->el_term
.t_val
[tv
- tval
] = 0;
(void) fprintf(el
->el_errfile
, "settc: Bad value `%s'.\n", how
);
term_change_size(el
, Val(T_li
), Val(T_co
));
el
->el_term
.t_val
[tv
- tval
] = atoi(how
);
el
->el_term
.t_size
.v
= Val(T_co
);
el
->el_term
.t_size
.h
= Val(T_li
);
if (tv
== &tval
[T_co
] || tv
== &tval
[T_li
])
term_change_size(el
, Val(T_li
), Val(T_co
));
* Print the termcap string out with variable substitution
term_echotc(el
, argc
, argv
)
int arg_need
, arg_cols
, arg_rows
;
int verbose
= 0, silent
= 0;
static char *fmts
= "%s\n", *fmtd
= "%d\n";
if (argv
== NULL
|| argv
[1] == NULL
)
/* stderror(ERR_NAME | ERR_TCUSAGE); */
if (!*argv
|| *argv
[0] == '\0')
if (strcmp(*argv
, "tabs") == 0) {
(void) fprintf(el
->el_outfile
, fmts
, EL_CAN_TAB
? "yes" : "no");
else if (strcmp(*argv
, "meta") == 0) {
(void) fprintf(el
->el_outfile
, fmts
, Val(T_km
) ? "yes" : "no");
else if (strcmp(*argv
, "xn") == 0) {
(void) fprintf(el
->el_outfile
, fmts
, T_Margin
& MARGIN_MAGIC
?
else if (strcmp(*argv
, "am") == 0) {
(void) fprintf(el
->el_outfile
, fmts
, T_Margin
& MARGIN_AUTO
?
else if (strcmp(*argv
, "baud") == 0) {
for (i
= 0; baud_rate
[i
].b_name
!= NULL
; i
++)
if (el
->el_tty
.t_speed
== baud_rate
[i
].b_rate
) {
(void) fprintf(el
->el_outfile
, fmts
, baud_rate
[i
].b_name
);
(void) fprintf(el
->el_outfile
, fmtd
, 0);
else if (strcmp(*argv
, "rows") == 0 || strcmp(*argv
, "lines") == 0) {
(void) fprintf(el
->el_outfile
, fmtd
, Val(T_li
));
else if (strcmp(*argv
, "cols") == 0) {
(void) fprintf(el
->el_outfile
, fmtd
, Val(T_co
));
* Try to use our local definition first
for (t
= tstr
; t
->name
!= NULL
; t
++)
if (strcmp(t
->name
, *argv
) == 0) {
scap
= el
->el_term
.t_str
[t
- tstr
];
scap
= tgetstr(*argv
, &area
);
if (!scap
|| scap
[0] == '\0') {
(void) fprintf(el
->el_errfile
,
"echotc: Termcap parameter `%s' not found.\n", *argv
);
* Count home many values we need for this capability.
for (cap
= scap
, arg_need
= 0; *cap
; cap
++)
* hpux has lot's of them...
(void) fprintf(el
->el_errfile
,
"echotc: Warning: unknown termcap %% `%c'.\n", *cap
);
/* This is bad, but I won't complain */
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Extra argument `%s'.\n", *argv
);
(void) tputs(scap
, 1, term__putc
);
if (!*argv
|| *argv
[0] == '\0') {
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Missing argument.\n");
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Extra argument `%s'.\n", *argv
);
(void) tputs(tgoto(scap
, arg_cols
, arg_rows
), 1, term__putc
);
/* This is wrong, but I will ignore it... */
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Too many required arguments (%d).\n",
if (!*argv
|| *argv
[0] == '\0') {
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Missing argument.\n");
if (!*argv
|| *argv
[0] == '\0') {
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Missing argument.\n");
(void) fprintf(el
->el_errfile
,
"echotc: Warning: Extra argument `%s'.\n", *argv
);
(void) tputs(tgoto(scap
, arg_cols
, arg_rows
), arg_rows
, term__putc
);