NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/39883: tput support for setaf terminfo sequence is broken
tgetnum(3) and tgetstr(3) both say "setaf" is an unknown attribute,
but if you skip those and just call tgetstr(3) as tput(1) does, you
end up getting a string back!
-----
tstr.c
-----
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termcap.h>
int main(int argc, char **argv)
{
const char *attr;
const char *term;
char *tstr;
int id;
char termbuf[1024];
/*char attrbuf[1024];*/
char *attrbuf = malloc(1024);
char *oldattrbuf = attrbuf;
/*attr = "setaf";*/
if (argc < 2) {
fprintf(stderr, "Usage: tstr <attribute>\n");
exit(2);
}
attr = argv[1];
memset(attrbuf, 0, 1024);
term = getenv("TERM");
if (term == NULL) {
fprintf(stderr, "Cannot get TERM environment variable\n");
exit(1);
}
if (tgetent(termbuf, term) != 1) {
fprintf(stderr, "Cannot get termcap entry for %s\n", term);
exit(1);
}
id = tgetnum(attr);
if (id == -1) {
int flag;
flag = tgetflag(attr);
if (flag != 1) {
fprintf(stderr, "Warning: %s is not a known
attribute\n", attr);
}
else {
fprintf(stderr, "Can't happen: tgetnum and
tgetflag disagree\n");
exit(1);
}
}
tstr = tgetstr(attr, (char **)&attrbuf);
if (tstr == NULL) {
fprintf(stderr, "string is null\n");
exit(1);
}
fprintf(stdout, "%s", tstr);
exit(0);
}
-----
# cc -g -o tstr tstr.c -ltermcap
# ./tstr setaf | od -c
Warning: setaf is not a known attribute
0000000 033 [ m
0000003
Home |
Main Index |
Thread Index |
Old Index