On Saturday 2008-03-29 18:05, H. Peter Anvin wrote:No backwards searching, just forwards. In UTF-8 this is simple. You know you are in a character when the highest two bits are 10, and you can skip bytes until the start of the next character, whose highest bits are either 00 or 11. With the VTxxx escape codes, this is hardly possible. Given a broken code of ^[43m, echo -e '\x1B[43m wonderful \x1B[0m' | cosmicrays | cat 3m wonderful ^[[0m There is no way to check whether you are in the escape code. And there is no way to find its end. If a heuristic were to be used (which is certainly a possibility), you would end up killing text up until the next ^[. Hence the proposal of using definite start and end markers: echo -e '\x1B43m\x1D wonderful \x1B0m\x1D' | cosmicrays | cat 3m^] wonderful ^[0m^] Ok, finding out whether we are in an escape code is not as easy as with UTF-8 (the latter of which looks at the current character only), but still very viable. Prerequisite to this simple model is that the user does not use an overly long dumb escape sequence like ^[[43;43;43;43;43;43m, i.e. that the end marker is in the buffer if we really are in an escape sequence: static bool in_an_escape_seq(const char *buf) { const char *e = strchr(buf, 0x1D); return e != NULL && e < strchr(buf, 0x1B); } If so, skipping parts of a faulty write() is easy: static const char *get_out_of_esc(const char *buf) { if (in_an_escape_seq(buf)) return strchr(buf, 0x1D) + 1; else return buf; } -- make boldconfig -- to boldly select what no one has selected before --
| Michal Piotrowski | Re: 2.6.23-rc3-mm1 |
| Tarkan Erimer | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| Fred Tyler | Slow, persistent memory leak in 2.6.20 |
| Roland Dreier | Re: Integration of SCST in the mainstream Linux kernel |
git: | |
| David Miller | [GIT]: Networking |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| Antonio Almeida | HTB accuracy for high speed |
