terminal_set(): * Read in the terminal capabilities from the requested terminal */
| 855 | * Read in the terminal capabilities from the requested terminal |
| 856 | */ |
| 857 | protected int |
| 858 | terminal_set(EditLine *el, const char *term) |
| 859 | { |
| 860 | int i; |
| 861 | char buf[TC_BUFSIZE]; |
| 862 | char *area; |
| 863 | const struct termcapstr *t; |
| 864 | sigset_t oset, nset; |
| 865 | int lins, cols; |
| 866 | |
| 867 | (void) sigemptyset(&nset); |
| 868 | (void) sigaddset(&nset, SIGWINCH); |
| 869 | (void) sigprocmask(SIG_BLOCK, &nset, &oset); |
| 870 | |
| 871 | area = buf; |
| 872 | |
| 873 | |
| 874 | if (term == NULL) |
| 875 | term = getenv("TERM"); |
| 876 | |
| 877 | if (!term || !term[0]) |
| 878 | term = "dumb"; |
| 879 | |
| 880 | if (strcmp(term, "emacs") == 0) |
| 881 | el->el_flags |= EDIT_DISABLED; |
| 882 | |
| 883 | (void) memset(el->el_terminal.t_cap, 0, TC_BUFSIZE); |
| 884 | |
| 885 | i = tgetent(el->el_terminal.t_cap, term); |
| 886 | |
| 887 | if (i <= 0) { |
| 888 | if (i == -1) |
| 889 | (void) fprintf(el->el_errfile, |
| 890 | "Cannot read termcap database;\n"); |
| 891 | else if (i == 0) |
| 892 | (void) fprintf(el->el_errfile, |
| 893 | "No entry for terminal type \"%s\";\n", term); |
| 894 | (void) fprintf(el->el_errfile, |
| 895 | "using dumb terminal settings.\n"); |
| 896 | Val(T_co) = 80; /* do a dumb terminal */ |
| 897 | Val(T_pt) = Val(T_km) = Val(T_li) = 0; |
| 898 | Val(T_xt) = Val(T_MT); |
| 899 | for (t = tstr; t->name != NULL; t++) |
| 900 | terminal_alloc(el, t, NULL); |
| 901 | } else { |
| 902 | /* auto/magic margins */ |
| 903 | Val(T_am) = tgetflag("am"); |
| 904 | Val(T_xn) = tgetflag("xn"); |
| 905 | /* Can we tab */ |
| 906 | Val(T_pt) = tgetflag("pt"); |
| 907 | Val(T_xt) = tgetflag("xt"); |
| 908 | /* do we have a meta? */ |
| 909 | Val(T_km) = tgetflag("km"); |
| 910 | Val(T_MT) = tgetflag("MT"); |
| 911 | /* Get the size */ |
| 912 | Val(T_co) = tgetnum("co"); |
| 913 | Val(T_li) = tgetnum("li"); |
| 914 | for (t = tstr; t->name != NULL; t++) { |
no test coverage detected