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
On Mar 31, 12:01pm, "Mikel Ward" wrote:
}
} 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!
Your program does not do what you think it does. If you look
closely, you'll see that you print the "unknown attribute" message is
printed before you call tgetstr(3), therefore it is not true that
tgetstr(3) is declaring it to be an unknown attribute. Also, if you
look closely at tput(1), you will see that it's algorithm is:
if (tgetstr() == NULL)
if (tgetnum() == -1)
if (tgetflag() != 1)
print("unknown attribute");
} -----
} 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
}-- End of excerpt from "Mikel Ward"
Home |
Main Index |
Thread Index |
Old Index